From 7c0d4ad05a0f3ba58c891749fccbf94f663cbb6b Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 24 Jan 2026 11:48:24 -0800 Subject: [PATCH] Fix switch-to-switch link detection for downstream nodes --- link.go | 23 ++++++++++++++++++++++- static/index.html | 1 - 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/link.go b/link.go index e9efa70..bab3393 100644 --- a/link.go +++ b/link.go @@ -93,6 +93,13 @@ func (n *Nodes) findLastHop(target *Node, mac string, macToNode map[string]*Node } func (n *Nodes) hasCloserNode(node, target *Node, mac, port string, macToNode map[string]*Node) bool { + nodeMACs := map[string]bool{} + for _, iface := range node.Interfaces { + if iface.MAC != "" { + nodeMACs[string(iface.MAC)] = true + } + } + for otherMAC, otherPort := range node.MACTable { if otherPort != port { continue @@ -101,7 +108,21 @@ func (n *Nodes) hasCloserNode(node, target *Node, mac, port string, macToNode ma if otherNode == nil || otherNode == node || otherNode == target { continue } - if _, alsoSees := otherNode.MACTable[mac]; alsoSees { + + targetPort, alsoSees := otherNode.MACTable[mac] + if !alsoSees { + continue + } + + seesNodeOnSamePort := false + for nodeMAC := range nodeMACs { + if nodePort, seesNode := otherNode.MACTable[nodeMAC]; seesNode && nodePort == targetPort { + seesNodeOnSamePort = true + break + } + } + + if !seesNodeOnSamePort { return true } } diff --git a/static/index.html b/static/index.html index 7e14e30..49bc087 100644 --- a/static/index.html +++ b/static/index.html @@ -113,7 +113,6 @@ } fetchAndRender(); - setInterval(fetchAndRender, 30000);