[client] Add DNS and Exit Node collection configuration to Netflow (#3522)

[client] Add DNS and Exit Node collection configuration to Netflow (#3522)
This commit is contained in:
hakansa
2025-03-17 23:44:22 +08:00
committed by GitHub
parent 40d932e011
commit f88b93e53f
6 changed files with 75 additions and 32 deletions
+13 -5
View File
@@ -43,16 +43,22 @@ func (r *routeIDLookup) RemoveResolvedIP(route netip.Prefix) {
r.resolvedIPs.Delete(route.Addr())
}
func (r *routeIDLookup) Lookup(ip netip.Addr) string {
// Lookup returns the resource ID for the given IP address
// and a bool indicating if the IP is an exit node
func (r *routeIDLookup) Lookup(ip netip.Addr) (string, bool) {
var isExitNode bool
resId, ok := r.resolvedIPs.Load(ip)
if ok {
return resId.(string)
return resId.(string), false
}
var resourceID string
r.localMap.Range(func(key, value interface{}) bool {
if key.(netip.Prefix).Contains(ip) {
pref := key.(netip.Prefix)
if pref.Contains(ip) {
resourceID = value.(string)
isExitNode = pref.Bits() == 0
return false
}
@@ -61,13 +67,15 @@ func (r *routeIDLookup) Lookup(ip netip.Addr) string {
if resourceID == "" {
r.remoteMap.Range(func(key, value interface{}) bool {
if key.(netip.Prefix).Contains(ip) {
pref := key.(netip.Prefix)
if pref.Contains(ip) {
resourceID = value.(string)
isExitNode = pref.Bits() == 0
return false
}
return true
})
}
return resourceID
return resourceID, isExitNode
}
+4 -3
View File
@@ -364,11 +364,12 @@ func (d *Status) RemovePeerStateRoute(peer string, route string) error {
// CheckRoutes checks if the source and destination addresses are within the same route
// and returns the resource ID of the route that contains the addresses
func (d *Status) CheckRoutes(ip netip.Addr) (resId string) {
func (d *Status) CheckRoutes(ip netip.Addr) ([]byte, bool) {
if d == nil {
return
return nil, false
}
return d.routeIDLookup.Lookup(ip)
resId, isExitNode := d.routeIDLookup.Lookup(ip)
return []byte(resId), isExitNode
}
func (d *Status) UpdatePeerICEState(receivedState State) error {