Просмотр исходного кода

fix(agent): drop Broadcom internal ghost interfaces from the port panel (#1539)

On Asuswrt/Broadcom routers without a board.json layout (RT-AX92U,
GT-BE98-PRO), BuildEthPorts falls back to enumerating /sys/class/net, which
exposes internal interfaces the driver never uses for user traffic. An
RT-AX92U reports eth5 (operstate dormant) and eth6/eth7 (unknown) with an
unreadable speed and a phantom carrier; they passed the physical-port regex
(type ethernet, no DSA/conduit marker) and appeared as empty panel ports, so
a 5-port device displayed 8.

Keep the raw sysfs operstate in PortState and, in the extras pass, skip a
non-up interface whose operstate is not "down". A real port is either up
(linked) or down (unplugged); dormant/unknown are internal ghosts. Guard on
Oper != "" so legacy three-field output is unchanged, and never hide an up
port. Adds TestBuildEthPortsDropsBroadcomGhosts.

Co-authored-by: Bann-DEV <bann.dev@gmail.com>
Co-authored-by: gnacho <gnacho@domatix.com>
Bann-DEV 1 месяц назад
Родитель
Сommit
0d0d1cde07
3 измененных файлов с 57 добавлено и 4 удалено
  1. 1 1
      agent/VERSION
  2. 17 3
      agent/probe/probe.go
  3. 39 0
      agent/probe/probe_test.go

+ 1 - 1
agent/VERSION

@@ -1 +1 @@
-3.0.29
+3.0.30

+ 17 - 3
agent/probe/probe.go

@@ -335,8 +335,13 @@ type WirelessClient struct {
 
 // PortState es {name, up, speed} de una interfaz (/sys operstate+speed).
 type PortState struct {
-	Name  string `json:"name"`
-	Up    bool   `json:"up"`
+	Name string `json:"name"`
+	Up   bool   `json:"up"`
+	// Oper is the raw sysfs operstate (up/down/dormant/unknown/...). Kept so
+	// the panel can tell a real port (up, or down when unplugged) from a
+	// Broadcom internal ghost interface that never carries user traffic
+	// (dormant/unknown) and must not be shown as a usable port.
+	Oper  string `json:"oper,omitempty"`
 	Speed string `json:"speed"` // "1 Gbps" | "2.5 Gbps" | "100 Mbps" | "—"
 	// DSA: la interfaz es un conduit DSA (puerto CPU interno del switch,
 	// /sys/class/net/<i>/dsa presente). No es una boca usable: se excluye
@@ -1022,7 +1027,7 @@ func ParsePortStates(out string) []PortState {
 		if mbps > 0 {
 			speed = fmtSpeedMbps(mbps)
 		}
-		st := PortState{Name: p[0], Up: p[1] == "up", Speed: speed}
+		st := PortState{Name: p[0], Up: p[1] == "up", Oper: p[1], Speed: speed}
 		if len(p) > 3 && p[3] == "dsa" {
 			st.DSA = true
 		}
@@ -1295,6 +1300,15 @@ func BuildEthPorts(layout []PortLayout, states []PortState, brMembers map[string
 		if conduits[st.Name] {
 			continue // puerto de CPU del switch, no una boca
 		}
+		// Broadcom/Asuswrt internal "ghost" interfaces (eth5/6/7 on an RT-AX92U)
+		// pass phyRe and carry no DSA/conduit marker, but their sysfs operstate
+		// is dormant/unknown and speed is unreadable: they are not front-panel
+		// ports and never carry user traffic. A real port is either "up" (kept
+		// here and everywhere) or "down" when unplugged. Oper=="" is legacy
+		// three-field output, so nothing is hidden for it.
+		if !st.Up && st.Oper != "" && st.Oper != "down" {
+			continue
+		}
 		// #1200: label centralizado en portPrettyLabel - sfp-lan/sfp-wan
 		// conservan su nombre (antes "SFP -lan"/"SFP -wan").
 		label := portPrettyLabel(st.Name)

+ 39 - 0
agent/probe/probe_test.go

@@ -1444,6 +1444,45 @@ func TestBuildEthPortsMantieneEthSinSwitch(t *testing.T) {
 	}
 }
 
+func TestBuildEthPortsDropsBroadcomGhosts(t *testing.T) {
+	// RT-AX92U (Asuswrt/Broadcom, no board.json layout): eth0 is the uplink to
+	// the core switch, eth1-4 are real LAN ports (unplugged, so down + speed 0),
+	// and eth5/6/7 are internal ghost interfaces the driver exposes with
+	// operstate dormant/unknown and unreadable speed. They are not front-panel
+	// ports and must not appear in the panel.
+	states := ParsePortStates(
+		"bcmsw down -1 - 1 -\n" +
+			"br0 up -1 - 1 eth0\n" +
+			"eth0 up 1000 - 1 -\n" +
+			"eth1 down 0 - 1 -\n" +
+			"eth2 down 0 - 1 -\n" +
+			"eth3 down 0 - 1 -\n" +
+			"eth4 down 0 - 1 -\n" +
+			"eth5 dormant -1 - 1 -\n" +
+			"eth6 unknown -1 - 1 -\n" +
+			"eth7 unknown -1 - 1 -\n")
+	ports := BuildEthPorts(nil, states, nil, nil, "eth0")
+	ids := map[string]bool{}
+	for _, p := range ports {
+		ids[p.ID] = true
+		ids[p.Iface] = true
+	}
+	for _, want := range []string{"eth1", "eth2", "eth3", "eth4"} {
+		if !ids[want] {
+			t.Fatalf("real unplugged port %s was dropped: %+v", want, ports)
+		}
+	}
+	for _, ghost := range []string{"eth5", "eth6", "eth7"} {
+		if ids[ghost] {
+			t.Fatalf("Broadcom ghost interface %s must not be a panel port: %+v", ghost, ports)
+		}
+	}
+	// eth0..eth4 → WAN(eth0) + ETH 1..ETH 4 = 5 entries.
+	if len(ports) != 5 {
+		t.Fatalf("want 5 ports, got %d: %+v", len(ports), ports)
+	}
+}
+
 // dumpUplinkNotNamedWan: forma de `ubus call network.interface dump` en una placa cuyo enlace
 // recortada a lo que mira el parser y con la IP pública cambiada. El uplink
 // vivo es un PPPoE llamado "isp" sobre la boca lan1; la interfaz que SÍ se