瀏覽代碼

fix(agent): detect the LAN bridge when it is not br-lan/br0 (#1435) (#1437)

The agent's bridge detection in CmdBridgeFDB/CmdBrifMembers/CmdBridgeMAC only tried br-lan and then br0. On devices whose LAN bridge has another name (observed on OpenWrt on a Realtek rtl93xx switch, where the bridge is `switch`), the FDB section was collected empty and the bridge MAC never reported. On the server that cascades: the switch claims 0 wired clients, fleet uplink evidence anchors child units to the gateway instead of the switch, and links lose port/evidence.

Detection now tries br-lan and br0 first and falls back to the first real bridge present under /sys/class/net/*/bridge. Verified read-only on the affected device: the `switch` bridge resolves and 29 dynamic MACs are collected; br-lan devices resolve exactly as before.

Also: the weak-signal alert now uses the router display name (via routerDisplayName) in its description/vars instead of the raw router ID.

The agent carries a version bump to 3.0.19 so fleets pick the new probe up through their normal agent update channel.

Closes #1435
Nacho 1 月之前
父節點
當前提交
a1ae7428a7
共有 3 個文件被更改,包括 23 次插入 和 11 次删除
  1. 1 1
      agent/VERSION
  2. 16 8
      agent/probe/probe.go
  3. 6 2
      server-go/internal/adapters/live.go

+ 1 - 1
agent/VERSION

@@ -1 +1 @@
-3.0.18
+3.0.19

+ 16 - 8
agent/probe/probe.go

@@ -150,23 +150,30 @@ const (
 	// not confirmed since the device last spoke, and it survives long after
 	// the device is gone, so treating it as presence draws hosts that are no
 	// longer there. Falls back to /proc/net/arp when `ip` is missing.
-	CmdIpNeigh     = "ip -4 neigh show 2>/dev/null"
-	CmdBoardJSON   = "cat /etc/board.json 2>/dev/null"
-	CmdBrifMembers = "BR=br-lan; [ -d /sys/class/net/$BR ] || BR=br0; ls /sys/class/net/$BR/brif/ 2>/dev/null"
+	CmdIpNeigh   = "ip -4 neigh show 2>/dev/null"
+	CmdBoardJSON = "cat /etc/board.json 2>/dev/null"
+	// bridgeDetect: resuelve el nombre del bridge LAN en el router: br-lan,
+	// br0, o el primer bridge real presente en /sys/class/net (#1435: en
+	// switches OpenWrt con el bridge renombrado, p.ej. "switch", los dos
+	// candidatos clásicos no existen y la FDB salía vacía). Si no hay
+	// bridge, BR queda vacío y los comandos fallan en suave (mismo
+	// comportamiento que antes en equipos sin bridge).
+	bridgeDetect   = `BR=br-lan; [ -d /sys/class/net/$BR/bridge ] || BR=br0; [ -d /sys/class/net/$BR/bridge ] || { BR=; for d in /sys/class/net/*/bridge; do [ -d "$d" ] || continue; BR=${d%/bridge}; BR=${BR##*/}; break; done; }; `
+	CmdBrifMembers = bridgeDetect + `ls /sys/class/net/$BR/brif/ 2>/dev/null`
 	// CmdBridgeFDB: "==PORTS==" (port_no ifname) + "==MACS==" (port mac).
-	// No asume `br-lan` ni `brctl`: detecta el bridge real (br-lan o br0) y usa
-	// `bridge fdb show` como fallback cuando brctl no está (OpenWrt/GLuON
-	// modernos usan iproute2). Issue #253.
+	// No asume `brctl`: usa `bridge fdb show` como fallback cuando brctl no
+	// está (OpenWrt/GLuON modernos usan iproute2). Issue #253. El bridge lo
+	// resuelve bridgeDetect (#1435).
 	// La vía bridge excluye las entradas LOCALES (flag "permanent": la MAC del
 	// propio bridge registrada en cada puerto) para paridad con brctl ($3=="no"
 	// allí); sin esto el server ve la MAC propia aprendida en el puerto y lo
 	// clasifica como uplink, descartando TODOS sus clientes cableados (#506).
-	CmdBridgeFDB = `BR=br-lan; [ -d /sys/class/net/$BR ] || BR=br0; ` +
+	CmdBridgeFDB = bridgeDetect +
 		`echo "==PORTS=="; for d in /sys/class/net/$BR/brif/*; do [ -r "$d/port_no" ] && echo "$(cat $d/port_no) $(basename $d)"; done; ` +
 		`echo "==MACS=="; if command -v brctl >/dev/null 2>&1; then ` +
 		`brctl showmacs $BR 2>/dev/null | awk 'NR>1 && $3=="no" {print $1, $2}'; ` +
 		`else bridge fdb show br $BR 2>/dev/null | awk 'NF>=3 && $1!="01:" && $1!="33:33:" && $1!="ff:ff:" && $1!="00:00:00:00:00:00" && $0 !~ /permanent/ {for(i=1;i<=NF;i++) if($i=="dev"){print $(i+1), $1}}'; fi`
-	CmdBridgeMAC       = "cat /sys/class/net/br-lan/address 2>/dev/null || cat /sys/class/net/br0/address 2>/dev/null"
+	CmdBridgeMAC       = bridgeDetect + "cat /sys/class/net/$BR/address 2>/dev/null"
 	CmdUbusSystemBoard = "ubus call system board"
 	CmdUbusSystemInfo  = "ubus call system info"
 	CmdUbusWireless    = "ubus call network.wireless status"
@@ -538,6 +545,7 @@ func NetDevBps(prevRx, prevTx, rx, tx, dt float64) (rxBps, txBps *float64) {
 }
 
 var pingLossRe = regexp.MustCompile(`(\d+(?:\.\d+)?)% packet loss`)
+
 // #1281: GNU iputils imprime min/avg/max/MDEV (4 numeros) pero busybox
 // (OpenWrt) imprime min/avg/max (3): la regex exigia los 4 y en OpenWrt
 // la latencia salia nil siempre ("—" en Overview y Flota). El avg es el

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

@@ -3439,14 +3439,18 @@ func (l *Live) buildOverview(ctx context.Context) (*Overview, error) {
 			last := l.weakAlerted[d.MAC]
 			if time.Now().UnixMilli()-last > 24*3600e3 {
 				l.weakAlerted[d.MAC] = time.Now().UnixMilli()
+				routerName := l.routerDisplayName(d.RouterID)
+				if routerName == "" {
+					routerName = d.RouterID
+				}
 				l.engine.Emit(AlertEvent{
 					ID:       fmt.Sprintf("alert-weak-%s-%d", d.MAC, time.Now().UnixMilli()),
 					Category: alerts.CatSignal, Urgent: false,
 					Severity: "warn", Title: "Weak signal on " + d.Name,
-					Description: fmt.Sprintf("%d dBm on %s - check coverage or move closer to an AP", *d.SignalDbm, d.RouterID),
+					Description: fmt.Sprintf("%d dBm on %s - check coverage or move closer to an AP", *d.SignalDbm, routerName),
 					Hint:        alerts.HintFor(alerts.HintWifiWeak),
 					Type:        alerts.HintWifiWeak,
-					Vars:        map[string]string{"device": d.Name, "signal": strconv.Itoa(*d.SignalDbm), "router": d.RouterID},
+					Vars:        map[string]string{"device": d.Name, "signal": strconv.Itoa(*d.SignalDbm), "router": routerName},
 					Time:        "just now", RouterID: d.RouterID,
 				})
 			}