fix local address population and snmp reverse port discovery
populate root node with local macs/ips at startup, excluding loopback addresses and permanent arp entries. detect when snmp finds parent node mac in child forwarding table and set child localport. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
48
snmp.go
48
snmp.go
@@ -207,6 +207,30 @@ func (t *Tendrils) queryBridgeMIB(snmp *gosnmp.GoSNMP, deviceIP net.IP) {
|
||||
if addToParent {
|
||||
t.nodes.Update([]net.IP{deviceIP}, []net.HardwareAddr{mac}, "", "", "snmp")
|
||||
} else {
|
||||
t.nodes.mu.RLock()
|
||||
deviceNodeID := -1
|
||||
if id, exists := t.nodes.ipIndex[deviceIP.String()]; exists {
|
||||
deviceNodeID = id
|
||||
}
|
||||
macNodeID := -1
|
||||
if id, exists := t.nodes.macIndex[mac.String()]; exists {
|
||||
macNodeID = id
|
||||
}
|
||||
|
||||
if deviceNodeID != -1 && macNodeID != -1 {
|
||||
deviceNode := t.nodes.nodes[deviceNodeID]
|
||||
if deviceNode.ParentID == macNodeID {
|
||||
t.nodes.mu.RUnlock()
|
||||
t.nodes.mu.Lock()
|
||||
if deviceNode.LocalPort == "" {
|
||||
deviceNode.LocalPort = ifName
|
||||
}
|
||||
t.nodes.mu.Unlock()
|
||||
continue
|
||||
}
|
||||
}
|
||||
t.nodes.mu.RUnlock()
|
||||
|
||||
t.nodes.UpdateWithParent(deviceIP, nil, []net.HardwareAddr{mac}, ifName, "", "snmp")
|
||||
}
|
||||
}
|
||||
@@ -280,6 +304,30 @@ func (t *Tendrils) queryARPTable(snmp *gosnmp.GoSNMP, deviceIP net.IP) {
|
||||
ifName = "??"
|
||||
}
|
||||
|
||||
t.nodes.mu.RLock()
|
||||
deviceNodeID := -1
|
||||
if id, exists := t.nodes.ipIndex[deviceIP.String()]; exists {
|
||||
deviceNodeID = id
|
||||
}
|
||||
macNodeID := -1
|
||||
if id, exists := t.nodes.macIndex[mac.String()]; exists {
|
||||
macNodeID = id
|
||||
}
|
||||
|
||||
if deviceNodeID != -1 && macNodeID != -1 {
|
||||
deviceNode := t.nodes.nodes[deviceNodeID]
|
||||
if deviceNode.ParentID == macNodeID {
|
||||
t.nodes.mu.RUnlock()
|
||||
t.nodes.mu.Lock()
|
||||
if deviceNode.LocalPort == "" {
|
||||
deviceNode.LocalPort = ifName
|
||||
}
|
||||
t.nodes.mu.Unlock()
|
||||
continue
|
||||
}
|
||||
}
|
||||
t.nodes.mu.RUnlock()
|
||||
|
||||
t.nodes.UpdateWithParent(deviceIP, ips, []net.HardwareAddr{mac}, ifName, "", "snmp")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user