Преглед изворни кода

fix(live): match FDB and LLDP by interface, not by port id (#943)

The enrichment that fills "connected to" looked up learned MACs as
portMacs[port.ID] and LLDP neighbours by port.ID, but both come indexed
by interface name. The id is not always the interface: a WAN boca is
called "wan" while its interface is "eth1", and after the previous
commit it can be "lan1" (a PPPoE uplink over a LAN socket). Any such
boca showed nothing in front of it, even with the neighbour learned.

Resolve the interface once per boca - iface when the boca carries
counters, id otherwise, which is exactly the previous behaviour for
every boca whose id already was its interface.

(cherry picked from commit 74b759379bc074870e21e849c3abbf920896e228)

Co-authored-by: borky-git <borky-git@protonmail.com>
Nacho пре 2 месеци
родитељ
комит
8ac829337f
2 измењених фајлова са 20 додато и 4 уклоњено
  1. 9 4
      server-go/internal/adapters/live.go
  2. 11 0
      server-go/internal/adapters/lldp.go

+ 9 - 4
server-go/internal/adapters/live.go

@@ -2926,7 +2926,11 @@ func (l *Live) GetRouterDetail(ctx context.Context, id string) (*RouterDetail, e
 			routerByMac[polled.brMac] = name
 		}
 	}
-	// Boca → MACs aprendidas (vecino inmediato)
+	// Boca → MACs aprendidas (vecino inmediato). Indexado por INTERFAZ: el
+	// FDB y los vecinos LLDP vienen con el nombre de la interfaz, y el id de
+	// la boca no siempre lo es (una boca WAN se llama "wan" aunque su
+	// interfaz sea "eth1", o "lan1" cuando el uplink es un PPPoE sobre esa
+	// boca). Sin esto, esa boca sale sin el dispositivo que tiene enfrente.
 	portMacs := map[string][]string{}
 	if p != nil {
 		for mac, portName := range p.fdb {
@@ -2943,7 +2947,8 @@ func (l *Live) GetRouterDetail(ctx context.Context, id string) (*RouterDetail, e
 			enriched = append(enriched, port)
 			continue
 		}
-		all := portMacs[port.ID]
+		netdev := portNetdev(port)
+		all := portMacs[netdev]
 		// 1) ¿Otro router al otro lado? (uplink router↔router)
 		neighbor := ""
 		for _, mac := range all {
@@ -2957,7 +2962,7 @@ func (l *Live) GetRouterDetail(ctx context.Context, id string) (*RouterDetail, e
 			port.Detail = "enlace entre routers"
 			// El vecino además se anuncia por LLDP → el frontend puede
 			// mostrar el sufijo "· LLDP" en la etiqueta del uplink (C2).
-			if nb := lldpNeighborOnPort(p.lldp, port.ID); nb != nil {
+			if nb := lldpNeighborOnPort(p.lldp, netdev); nb != nil {
 				port.Detail = "enlace entre routers · LLDP"
 			}
 			enriched = append(enriched, port)
@@ -3047,7 +3052,7 @@ func (l *Live) GetRouterDetail(ctx context.Context, id string) (*RouterDetail, e
 			}
 			// Si se anuncia por LLDP, esa identificación (chassis + mgmt-ip)
 			// es mejor pista que el hostname DHCP.
-			if nb := lldpNeighborOnPort(p.lldp, port.ID); nb != nil && nb.displayName() != "" {
+			if nb := lldpNeighborOnPort(p.lldp, netdev); nb != nil && nb.displayName() != "" {
 				port.ConnectedTo = nb.displayName()
 				if nb.Mgmt != "" {
 					port.Detail = nb.Mgmt + " · LLDP"

+ 11 - 0
server-go/internal/adapters/lldp.go

@@ -125,3 +125,14 @@ func lldpNeighborOnPort(neighbors []LldpNeighbor, port string) *LldpNeighbor {
 	}
 	return nil
 }
+
+// portNetdev: la interfaz de una boca. El id no siempre lo es -- una boca
+// WAN se llama "wan" aunque su interfaz sea "eth1" o "lan1" -- y tanto el
+// FDB como los vecinos LLDP vienen indexados por interfaz. Sin iface (boca
+// sin contadores) queda el id, que es lo que había antes.
+func portNetdev(p EthPort) string {
+	if p.Iface != "" {
+		return p.Iface
+	}
+	return p.ID
+}