Răsfoiți Sursa

fix(probe): keep a bridged WAN port out of the WAN slot (#2181) (#2216)

Nacho 5 zile în urmă
părinte
comite
0e594c19cd
5 a modificat fișierele cu 83 adăugiri și 3 ștergeri
  1. 1 0
      CHANGELOG.md
  2. 1 1
      agent/VERSION
  3. 23 0
      agent/probe/probe.go
  4. 54 0
      agent/probe/probe_2181_bridged_test.go
  5. 4 2
      agent/probe/probe_test.go

+ 1 - 0
CHANGELOG.md

@@ -20,6 +20,7 @@ y este proyecto se adhiere a [Versionado Semántico](https://semver.org/lang/es/
 ### Fixed
 
 - The alert card of the home summary no longer lists read alerts and drops one as soon as it is marked read. When the filter leaves it empty it says so, offers one click back to the whole list and a link to the alert log, and its badge no longer subtracts the same read alert twice (#2217).
+- A WAN port that the user bridged into `br-lan` to run the unit as an access point stops being painted as the WAN port. The label already said LAN N, but the port kept the `wan` id and the panel draws every port with that id as the internet link, so a FRITZ!Box 4040 in AP mode showed its fifth bridged jack as "WAN" while the real uplink was another LAN port. The port now takes the id that matches its label, moves to the end of the chassis and keeps its traffic counters (#2181, reported by @fsolak47).
 - A NetGrip panel whose embedded agent carries an old token never recovered. The rearm restarted the panel and then rotated the token in the native agent's environment file, which NetGrip does not read, so the panel kept answering 401 every cycle and the supervisor kept restarting it on each cooldown. The token now goes into `/etc/netgrip/netpulse.env`, the file the embedded agent reads, and the panel is restarted after it (#2208).
 
 ## [2.55.1] - 2026-11-28

+ 1 - 1
agent/VERSION

@@ -1 +1 @@
-3.0.50
+3.0.51

+ 23 - 0
agent/probe/probe.go

@@ -1251,6 +1251,7 @@ func BuildEthPorts(layout []PortLayout, states []PortState, brMembers map[string
 				wanDeclared = true
 			}
 		}
+		bridgedWan := -1
 		for _, p := range layout {
 			st, ok := byName[p.Name]
 			if p.Role == "wan" && !isEthNetdev(st, ok) {
@@ -1269,6 +1270,21 @@ func BuildEthPorts(layout []PortLayout, states []PortState, brMembers map[string
 				}
 				id = p.Name
 				label = "LAN " + strconv.Itoa(lanCount+1)
+				if id == "wan" {
+					// #2181: un netdev llamado literalmente "wan" (FRITZ!Box
+					// 4040 y otros) conservaba el id, y la UI pinta como WAN
+					// todo puerto con id "wan" (jack, leyenda "Internet
+					// link") además de descartarlo del FDB como si fuera la
+					// WAN. Una boca puenteada no puede llevar ese id: usa el
+					// mismo que su etiqueta, sin pisar una boca LAN existente.
+					n := lanCount + 1
+					for lanNames["lan"+strconv.Itoa(n)] {
+						n++
+					}
+					id = "lan" + strconv.Itoa(n)
+					label = "LAN " + strconv.Itoa(n)
+				}
+				bridgedWan = len(ports)
 			}
 			ep := EthPort{ID: id, Label: label, Up: up}
 			if up {
@@ -1279,6 +1295,13 @@ func BuildEthPorts(layout []PortLayout, states []PortState, brMembers map[string
 			netdev[ep.ID] = p.Name
 			used[p.Name] = true
 		}
+		// #2181: la ex-WAN puenteada ya no es la primera boca del chasis. El
+		// layout la trae delante porque la WAN suele ir a la izquierda, así
+		// que se mueve al final para que el panel lea LAN 1..LAN N, LAN N+1.
+		if bridgedWan >= 0 && bridgedWan != len(ports)-1 {
+			ep := ports[bridgedWan]
+			ports = append(append(ports[:bridgedWan:bridgedWan], ports[bridgedWan+1:]...), ep)
+		}
 	} else {
 		// Fallback sin config. #1200: también "lan"/"wan" a secas (UniFi
 		// 6 Lite: la boca no se llama lan1 sino lan, y antes el panel

+ 54 - 0
agent/probe/probe_2181_bridged_test.go

@@ -0,0 +1,54 @@
+// probe_2181_bridged_test.go — AP multi-boca con todas las bocas en br-lan
+// (#2181): la boca WAN del board.json está puenteada, así que no es un enlace
+// a internet, aunque su netdev se llame literalmente "wan".
+package probe
+
+import "testing"
+
+// AVM FRITZ!Box 4040 como AP: board.json declara lan1..lan4 y la WAN en el
+// netdev "wan"; /etc/config/network mete las cinco bocas en br-lan. La WAN no
+// existe como enlace propio y el panel no puede pintarla como tal: con
+// id "wan" la UI la saca como puerto WAN y anuncia "Internet link".
+func TestBuildEthPortsBridgedWanIsNotTheWanPort(t *testing.T) {
+	layout, err := ParsePortLayout(`{"network":{"lan":{"ports":["lan1","lan2","lan3","lan4"]},"wan":{"device":"wan"}}}`)
+	if err != nil {
+		t.Fatalf("layout: %v", err)
+	}
+	if len(layout) != 5 {
+		t.Fatalf("layout: %+v", layout)
+	}
+	states := ParsePortStates("br-lan up 1000\nlan1 up 1000\nlan2 up 1000\nlan3 down -1\nlan4 up 100\nwan up 1000\n")
+	members := map[string]bool{"lan1": true, "lan2": true, "lan3": true, "lan4": true, "wan": true}
+	ifaces := map[string]IfRate{"wan": {IfCounters: IfCounters{Rx: 4242}}}
+	ports := BuildEthPorts(layout, states, members, ifaces, "br-lan.10")
+
+	if len(ports) != 5 {
+		t.Fatalf("bocas: %+v", ports)
+	}
+	for _, p := range ports {
+		if p.ID == "wan" {
+			t.Fatalf("una boca puenteada no puede llevar el id wan: %+v", p)
+		}
+	}
+	last := ports[len(ports)-1]
+	if last.Label != "LAN 5" || last.Iface != "wan" {
+		t.Fatalf("la ex-WAN va como última boca LAN: %+v", ports)
+	}
+	if !last.Up || last.Speed != "1 Gbps" || last.RxBytes != 4242 {
+		t.Fatalf("estado y estadísticas de la boca: %+v", last)
+	}
+}
+
+// Control: la WAN fuera del bridge sigue siendo la boca WAN y va primero.
+func TestBuildEthPortsWanOutsideBridgeStaysWan(t *testing.T) {
+	layout, err := ParsePortLayout(`{"network":{"lan":{"ports":["lan1","lan2","lan3","lan4"]},"wan":{"device":"wan"}}}`)
+	if err != nil {
+		t.Fatalf("layout: %v", err)
+	}
+	states := ParsePortStates("lan1 up 1000\nlan2 down -1\nlan3 down -1\nlan4 down -1\nwan up 1000\n")
+	members := map[string]bool{"lan1": true, "lan2": true, "lan3": true, "lan4": true}
+	ports := BuildEthPorts(layout, states, members, nil, "wan")
+	if len(ports) != 5 || ports[0].ID != "wan" || ports[0].Label != "WAN" {
+		t.Fatalf("WAN fuera del bridge: %+v", ports)
+	}
+}

+ 4 - 2
agent/probe/probe_test.go

@@ -411,9 +411,11 @@ func TestParsePortsYLayout(t *testing.T) {
 	if err != nil || len(layout) != 5 || layout[0].ID != "wan" || layout[1].Label != "LAN 1" {
 		t.Fatalf("layout: %v %+v", err, layout)
 	}
-	// AP en bridge: wan en br-lan → se re-etiqueta LAN 5
+	// AP en bridge: wan en br-lan → se re-etiqueta LAN 5 y va al final del
+	// chasis (#2181: el layout la trae delante porque la WAN suele ir a la
+	// izquierda; puenteada, el panel lee LAN 1..LAN 4, LAN 5).
 	ports := BuildEthPorts(layout, states, map[string]bool{"wan": true}, nil, "")
-	if len(ports) != 6 || ports[0].Label != "LAN 5" {
+	if len(ports) != 6 || ports[4].Label != "LAN 5" || ports[4].ID == "wan" {
 		t.Fatalf("ethports bridge: %+v", ports)
 	}
 	foundBridge := map[string]bool{}