Selaa lähdekoodia

feat(ports): list every LLDP neighbour of a port, not only the first (#2182) (#2277)

Nacho 1 päivä sitten
vanhempi
sitoutus
ce4ee36772

+ 1 - 0
CHANGELOG.md

@@ -27,6 +27,7 @@ y este proyecto se adhiere a [Versionado Semántico](https://semver.org/lang/es/
 
 ### Fixed
 
+- A port that receives LLDP announcements from more than one neighbour now lists all of them instead of naming only the first, which is what an uplink towards a switch that speaks on several of its ports looks like. The tile names the main peer and marks the extra ones with a `+N`, and the hover lists the whole set with each management address and remote port. A port with zero or one neighbour answers exactly as before (#2182).
 - Neighbours that the client discovery rules leave out are no longer listed as offline devices when an older version stored them. They stay hidden while they are in the unit's ARP table and are never deleted, because an explicit Off must not erase a network's history (#2242).
 - A MAC that arrives from SNMP in more than six bytes is rejected instead of truncated into a plausible but wrong MAC, and the FDB index octets are parsed strictly (#2243).
 - The usteer kick and the device link and impostor routes accept any MAC form, like the rest of the API, and answer 400 with `invalid_mac` when the value is not one (#2244).

+ 1 - 0
app/public/locales/en/translation.json

@@ -1226,6 +1226,7 @@
       "wanPublicIp": "Public IP",
       "wanIpv6": "IPv6",
       "wanGateway": "Gateway",
+      "lldpPeers": "LLDP neighbours",
       "wanDns": "DNS",
       "deviceDetail": "Detail",
       "traffic": "Traffic",

+ 1 - 0
app/public/locales/es/translation.json

@@ -1226,6 +1226,7 @@
       "wanPublicIp": "IP pública",
       "wanIpv6": "IPv6",
       "wanGateway": "Puerta de enlace",
+      "lldpPeers": "Vecinos LLDP",
       "wanDns": "Servidor DNS",
       "deviceDetail": "Detalle",
       "traffic": "Tráfico",

+ 1 - 0
app/public/locales/ru/translation.json

@@ -1253,6 +1253,7 @@
       "wanPublicIp": "Публичный IP",
       "wanIpv6": "IPv6",
       "wanGateway": "Шлюз",
+      "lldpPeers": "Соседи LLDP",
       "wanDns": "DNS",
       "deviceDetail": "Подробнее",
       "traffic": "Трафик",

+ 1 - 0
app/public/locales/zh/translation.json

@@ -942,6 +942,7 @@
       "wanPublicIp": "公网 IP",
       "wanIpv6": "IPv6",
       "wanGateway": "网关",
+      "lldpPeers": "LLDP 邻居",
       "wanDns": "DNS",
       "deviceDetail": "详情",
       "traffic": "流量",

+ 33 - 1
app/src/components/routers/PortPanel.tsx

@@ -143,6 +143,11 @@ function Jack({ port, index, wan }: { port: EthPort; index: number; wan?: WanInf
                       t('routerDetail.ports.inUse')
                     )
                   })()}
+                  {port.lldpPeers && port.lldpPeers.length > 1 && (
+                    <span className="ml-1 shrink-0 font-mono text-[9px] text-text-muted">
+                      +{port.lldpPeers.length - 1}
+                    </span>
+                  )}
                 </div>
                 {port.speed && <div className="font-mono text-[10px] text-text-muted">{port.speed}</div>}
                 {(port.rxBps !== undefined || port.txBps !== undefined) && (
@@ -186,8 +191,35 @@ function Jack({ port, index, wan }: { port: EthPort; index: number; wan?: WanInf
                 {wan!.proto && <div className="mt-0.5 font-mono text-caption text-accent">{wan!.proto.toUpperCase()}</div>}
               </div>
             ) : (
-              /* Boca LAN: dispositivo conectado */
+              /* Boca LAN: dispositivo conectado. #2182: si LLDP anuncia a
+                 varios vecinos (uplink hacia un switch), se listan todos en
+                 vez de nombrar solo al primero. */
               (() => {
+                const peers = port.lldpPeers ?? []
+                if (peers.length > 1) {
+                  return (
+                    <div className="mt-1">
+                      <div className="text-[10px] uppercase tracking-[0.06em] text-text-muted">
+                        {t('routerDetail.ports.lldpPeers')}
+                      </div>
+                      <ul className="mt-0.5 space-y-0.5">
+                        {peers.map((peer, i) => {
+                          const name = peer.chassis || peer.portDesc || peer.mgmt
+                          if (!name) return null
+                          return (
+                            <li key={`${peer.chassis ?? ''}-${peer.portDesc ?? ''}-${i}`} className="text-caption text-text-primary">
+                              {name}
+                              {peer.mgmt && <span className="font-mono text-text-muted"> · {peer.mgmt}</span>}
+                              {peer.portDesc && peer.chassis && (
+                                <span className="text-text-muted"> · {peer.portDesc}</span>
+                              )}
+                            </li>
+                          )
+                        })}
+                      </ul>
+                    </div>
+                  )
+                }
                 const peer = portPeerLabel(port)
                 return peer ? (
                   <div className="mt-1 text-caption font-medium text-text-primary">

+ 5 - 1
app/src/components/routers/routerExtras.ts

@@ -10,7 +10,7 @@ import i18n, { dayAbbr } from '@/i18n'
 import type { Router } from '@/data/mock'
 import { adguard, routers } from '@/data/mock'
 import { fmtTemp, type TempUnit } from '@/lib/temperature'
-import type { DiscoveryIface } from '@/data/types'
+import type { DiscoveryIface, LldpInfo } from '@/data/types'
 
 // ---------------------------------------------------------------------------
 // Extras por router
@@ -98,6 +98,10 @@ export interface EthPort {
   peerKind?: string
   detail?: string // "192.168.8.10 · full duplex"
   health?: PortHealth // health score del puerto (#299)
+  /** #2182: todos los vecinos LLDP de la boca cuando son más de uno (un
+   * uplink hacia un switch anuncia por cada una de sus bocas). Ausente en
+   * el caso normal. `connectedTo` sigue siendo el par principal. */
+  lldpPeers?: LldpInfo[]
 }
 
 /**

+ 7 - 1
server-go/internal/adapters/demo_extras.go

@@ -110,7 +110,13 @@ func canonRouterExtras() map[string]*demoExtras {
 				{ID: "wan", Label: "WAN", Up: true, Speed: "1 Gbps", ConnectedTo: "Uplink → Gateway", Detail: "Gateway · LAN 1 (192.168.8.1)"},
 				{ID: "lan1", Label: "LAN 1", Up: true, Speed: "1 Gbps", ConnectedTo: "PS5", Detail: "192.168.8.31 · cable"},
 				{ID: "lan2", Label: "LAN 2", Up: false},
-				{ID: "lan3", Label: "LAN 3", Up: true, Speed: "1 Gbps", ConnectedTo: "GS308E", Detail: "Switch gestionado · 192.168.8.13 · LLDP"},
+				{ID: "lan3", Label: "LAN 3", Up: true, Speed: "1 Gbps", ConnectedTo: "GS308E", Detail: "Switch gestionado · 192.168.8.13 · LLDP",
+					// #2182: boca hacia un switch que anuncia por dos de sus
+					// puertos. La tarjeta nombra el principal y lista el resto.
+					LldpPeers: []LldpInfo{
+						{Chassis: "GS308E", Mgmt: "192.168.8.13", Caps: "Bridge", PortDesc: "ge5"},
+						{Chassis: "GS308E", Mgmt: "192.168.8.13", Caps: "Bridge", PortDesc: "ge6"},
+					}},
 			},
 		},
 		"estudio": {

+ 2 - 1
server-go/internal/adapters/live.go

@@ -5521,7 +5521,8 @@ func (l *Live) GetRouterDetail(ctx context.Context, id string) (*RouterDetail, e
 			enriched = append(enriched, port)
 			continue
 		}
-		enriched = append(enriched, enrichEthPort(port, portNetdev(port), deps))
+		e := withLldpPeers(enrichEthPort(port, portNetdev(port), deps), deps.lldp)
+		enriched = append(enriched, e)
 	}
 	// Per-port health score (issue #299): compute from recent series + flapping.
 	l.enrichPortHealth(id, enriched)

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

@@ -140,6 +140,42 @@ func lldpNeighborOnPort(neighbors []LldpNeighbor, port string) *LldpNeighbor {
 	return nil
 }
 
+// lldpNeighborsOnPort (#2182): TODOS los vecinos anunciados en un puerto
+// local, sin repetir el mismo chasis anunciado dos veces. Una boca hacia un
+// switch recibe un anuncio por cada puerto del switch que hable LLDP, y
+// quedarse con el primero esconde al resto.
+func lldpNeighborsOnPort(neighbors []LldpNeighbor, port string) []LldpNeighbor {
+	var out []LldpNeighbor
+	seen := map[string]bool{}
+	for _, n := range neighbors {
+		if n.Port != port {
+			continue
+		}
+		key := strings.ToUpper(n.ChassisMac) + "|" + n.Chassis + "|" + n.PortDesc
+		if seen[key] {
+			continue
+		}
+		seen[key] = true
+		out = append(out, n)
+	}
+	return out
+}
+
+// withLldpPeers (#2182): adjunta a la boca la lista completa de vecinos LLDP
+// cuando hay mas de uno. Con cero o uno el puerto sale igual que antes, asi
+// que el caso normal no cambia de forma en la respuesta.
+func withLldpPeers(p EthPort, neighbors []LldpNeighbor) EthPort {
+	nbs := lldpNeighborsOnPort(neighbors, portNetdev(p))
+	if len(nbs) < 2 {
+		return p
+	}
+	p.LldpPeers = make([]LldpInfo, 0, len(nbs))
+	for _, nb := range nbs {
+		p.LldpPeers = append(p.LldpPeers, *nb.info())
+	}
+	return p
+}
+
 // 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

+ 32 - 0
server-go/internal/adapters/lldp_test.go

@@ -291,3 +291,35 @@ func TestUplinkLldpIdentityFallback(t *testing.T) {
 		t.Fatal("uplink por nombre del chasis debería identificarse (fallback #252)")
 	}
 }
+
+// #2182: una boca que recibe varios anuncios LLDP (uplink hacia un switch)
+// conserva la lista completa, sin repetir el mismo chasis y sin mezclar
+// vecinos de otras bocas.
+func TestWithLldpPeersVariosVecinos(t *testing.T) {
+	port := EthPort{ID: "lan4", Iface: "lan4", Up: true}
+	nbs := []LldpNeighbor{
+		{Port: "lan4", ChassisMac: "AA:BB:CC:00:00:01", Chassis: "sw-patio", PortDesc: "ge1"},
+		{Port: "lan4", ChassisMac: "AA:BB:CC:00:00:02", Chassis: "sw-garaje", PortDesc: "ge7"},
+		{Port: "lan4", ChassisMac: "AA:BB:CC:00:00:01", Chassis: "sw-patio", PortDesc: "ge1"},
+		{Port: "lan1", ChassisMac: "AA:BB:CC:00:00:09", Chassis: "otro", PortDesc: "ge2"},
+	}
+	got := withLldpPeers(port, nbs)
+	if len(got.LldpPeers) != 2 {
+		t.Fatalf("lldpPeers=%+v, esperaba dos vecinos distintos de lan4", got.LldpPeers)
+	}
+	if got.LldpPeers[0].Chassis != "sw-patio" || got.LldpPeers[1].Chassis != "sw-garaje" {
+		t.Fatalf("orden o contenido inesperado: %+v", got.LldpPeers)
+	}
+}
+
+// Un solo vecino (o ninguno) deja la respuesta como estaba: sin campo.
+func TestWithLldpPeersCasoNormalNoCambia(t *testing.T) {
+	port := EthPort{ID: "lan1", Iface: "lan1", Up: true}
+	one := []LldpNeighbor{{Port: "lan1", Chassis: "sw-unico", PortDesc: "ge1"}}
+	if got := withLldpPeers(port, one); len(got.LldpPeers) != 0 {
+		t.Fatalf("con un vecino no debe aparecer la lista: %+v", got.LldpPeers)
+	}
+	if got := withLldpPeers(port, nil); len(got.LldpPeers) != 0 {
+		t.Fatalf("sin vecinos no debe aparecer la lista: %+v", got.LldpPeers)
+	}
+}

+ 5 - 0
server-go/internal/adapters/types.go

@@ -763,6 +763,11 @@ type EthPort struct {
 	// Health: per-port health score (issue #299). Ausente si no se ha
 	// calculado (demo sin datos, puertos sin muestras).
 	Health *PortHealth `json:"health,omitempty"`
+	// LldpPeers (#2182): todos los vecinos que anuncian por LLDP en esta
+	// boca, cuando son mas de uno. La etiqueta principal sigue siendo
+	// ConnectedTo; esto es lo que la tarjeta lista para no esconder al
+	// resto. Ausente en el caso normal (cero o un vecino).
+	LldpPeers []LldpInfo `json:"lldpPeers,omitempty"`
 }
 
 // Radio agrega una banda wifi ({name, channel, widthMhz, powerDbm, clients}).