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:
37
tendrils.go
37
tendrils.go
@@ -23,6 +23,8 @@ func (t *Tendrils) Run() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
t.populateLocalAddresses()
|
||||
|
||||
go t.pollARP(ctx)
|
||||
go t.pollSNMP(ctx)
|
||||
|
||||
@@ -36,6 +38,41 @@ func (t *Tendrils) Run() {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tendrils) populateLocalAddresses() {
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
t.nodes.mu.Lock()
|
||||
defer t.nodes.mu.Unlock()
|
||||
|
||||
root := t.nodes.nodes[0]
|
||||
|
||||
for _, iface := range interfaces {
|
||||
if len(iface.HardwareAddr) > 0 {
|
||||
macKey := iface.HardwareAddr.String()
|
||||
root.MACs[macKey] = iface.HardwareAddr
|
||||
t.nodes.macIndex[macKey] = 0
|
||||
}
|
||||
|
||||
addrs, err := iface.Addrs()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
if ipnet, ok := addr.(*net.IPNet); ok {
|
||||
if ipnet.IP.To4() != nil && !ipnet.IP.IsLoopback() {
|
||||
ipKey := ipnet.IP.String()
|
||||
root.IPs[ipKey] = ipnet.IP
|
||||
t.nodes.ipIndex[ipKey] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tendrils) listInterfaces() []net.Interface {
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user