Browse Source

fix(agent): do not show a bridge member as the WAN port (#1949) (#1959)

Nacho 4 tuần trước cách đây
mục cha
commit
80a5bdbc80

+ 1 - 1
agent/VERSION

@@ -1 +1 @@
-3.0.39
+3.0.40

+ 12 - 1
agent/probe/probe.go

@@ -1226,9 +1226,11 @@ func BuildEthPorts(layout []PortLayout, states []PortState, brMembers map[string
 
 
 	if len(layout) > 0 {
 	if len(layout) > 0 {
 		lanCount := 0
 		lanCount := 0
+		lanNames := map[string]bool{}
 		for _, p := range layout {
 		for _, p := range layout {
 			if p.Role == "lan" {
 			if p.Role == "lan" {
 				lanCount++
 				lanCount++
+				lanNames[p.Name] = true
 			}
 			}
 		}
 		}
 		for _, p := range layout {
 		for _, p := range layout {
@@ -1238,10 +1240,19 @@ func BuildEthPorts(layout []PortLayout, states []PortState, brMembers map[string
 			}
 			}
 			up := ok && st.Up
 			up := ok && st.Up
 			label := p.Label
 			label := p.Label
+			id := p.ID
 			if p.Role == "wan" && brMembers[p.Name] {
 			if p.Role == "wan" && brMembers[p.Name] {
+				// #1949: la "wan" del board.json de un AP de un solo puerto
+				// es un miembro del bridge LAN, no una boca WAN. La boca se
+				// queda como LAN y con su propio id: con id "wan" la UI la
+				// pintaba como enlace a internet aunque el texto dijera LAN.
+				if lanNames[p.Name] {
+					continue // ya declarada como LAN: no duplicar la boca
+				}
+				id = p.Name
 				label = "LAN " + strconv.Itoa(lanCount+1)
 				label = "LAN " + strconv.Itoa(lanCount+1)
 			}
 			}
-			ep := EthPort{ID: p.ID, Label: label, Up: up}
+			ep := EthPort{ID: id, Label: label, Up: up}
 			if up {
 			if up {
 				ep.Speed = st.Speed
 				ep.Speed = st.Speed
 			}
 			}

+ 54 - 0
agent/probe/probe_1949_test.go

@@ -0,0 +1,54 @@
+// probe_1949_test.go — AP de un solo puerto: la "wan" del board.json es un
+// miembro del bridge LAN y no debe salir como enlace a internet (#1949).
+package probe
+
+import "testing"
+
+// board.json declara eth0 como LAN y también como WAN (caso WAX220). La boca
+// es una sola y es LAN: ni id "wan" (la UI la pinta como Internet) ni boca
+// duplicada.
+func TestBuildEthPortsSinglePortApNoWan(t *testing.T) {
+	layout, err := ParsePortLayout(`{"network":{"lan":{"ports":["eth0"]},"wan":{"device":"eth0"}}}`)
+	if err != nil {
+		t.Fatalf("layout: %v", err)
+	}
+	ports := BuildEthPorts(layout, ParsePortStates("eth0 up 1000 - 1 -\n"), map[string]bool{"eth0": true}, nil, "br-lan")
+	if len(ports) != 1 {
+		t.Fatalf("una sola boca física, got %+v", ports)
+	}
+	if ports[0].ID == "wan" || ports[0].Label == "WAN" {
+		t.Fatalf("el único puerto del AP no es una WAN: %+v", ports[0])
+	}
+	if ports[0].ID != "eth0" {
+		t.Fatalf("la boca conserva su netdev, got %+v", ports[0])
+	}
+}
+
+// Si el board.json solo declara la WAN y esa boca cuelga del bridge, sale
+// como LAN con su netdev, no como WAN.
+func TestBuildEthPortsBridgeMemberWanBecomesLan(t *testing.T) {
+	layout, err := ParsePortLayout(`{"network":{"wan":{"device":"eth0"}}}`)
+	if err != nil {
+		t.Fatalf("layout: %v", err)
+	}
+	ports := BuildEthPorts(layout, ParsePortStates("eth0 up 1000 - 1 -\n"), map[string]bool{"eth0": true}, nil, "")
+	if len(ports) != 1 {
+		t.Fatalf("bocas: %+v", ports)
+	}
+	if ports[0].ID != "eth0" || ports[0].Label != "LAN 1" {
+		t.Fatalf("la boca del bridge debía salir como LAN 1 con su id: %+v", ports[0])
+	}
+}
+
+// Guard: un router de verdad, cuya WAN no es miembro del bridge, sigue
+// saliendo como WAN.
+func TestBuildEthPortsRealWanNotBridgeMember(t *testing.T) {
+	layout, err := ParsePortLayout(`{"network":{"lan":{"ports":["lan1"]},"wan":{"device":"eth0"}}}`)
+	if err != nil {
+		t.Fatalf("layout: %v", err)
+	}
+	ports := BuildEthPorts(layout, ParsePortStates("eth0 up 1000 - 1 -\nlan1 up 1000 - 1 -\n"), map[string]bool{"lan1": true}, nil, "eth0")
+	if len(ports) != 2 || ports[0].ID != "wan" {
+		t.Fatalf("la WAN real no se toca: %+v", ports)
+	}
+}