net/interfaces: handle removed interfaces in State.Equal
This wasn't previously handling the case where an interface in s2 was removed and not present in s1, and would cause the Equal method to incorrectly return that the states were equal. Updates tailscale/corp#19124 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I3af22bc631015d1ddd0a1d01bfdf312161b9532d
This commit is contained in:
@ -286,6 +286,13 @@ func TestStateString(t *testing.T) {
|
||||
|
||||
// tests (*State).Equal
|
||||
func TestEqual(t *testing.T) {
|
||||
pfxs := func(addrs ...string) (ret []netip.Prefix) {
|
||||
for _, addr := range addrs {
|
||||
ret = append(ret, netip.MustParsePrefix(addr))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
s1, s2 *State
|
||||
@ -362,6 +369,29 @@ func TestEqual(t *testing.T) {
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
|
||||
// See tailscale/corp#19124
|
||||
{
|
||||
name: "interface-removed",
|
||||
s1: &State{
|
||||
InterfaceIPs: map[string][]netip.Prefix{
|
||||
"rmnet16": pfxs("2607:1111:2222:3333:4444:5555:6666:7777/64"),
|
||||
"rmnet17": pfxs("2607:9999:8888:7777:666:5555:4444:3333/64"),
|
||||
"tun0": pfxs("100.64.1.2/32", "fd7a:115c:a1e0::1/128"),
|
||||
"v4-rmnet16": pfxs("192.0.0.4/32"),
|
||||
"wlan0": pfxs("10.0.0.111/24"), // removed below
|
||||
},
|
||||
},
|
||||
s2: &State{
|
||||
InterfaceIPs: map[string][]netip.Prefix{
|
||||
"rmnet16": pfxs("2607:1111:2222:3333:4444:5555:6666:7777/64"),
|
||||
"rmnet17": pfxs("2607:9999:8888:7777:666:5555:4444:3333/64"),
|
||||
"tun0": pfxs("100.64.1.2/32", "fd7a:115c:a1e0::1/128"),
|
||||
"v4-rmnet16": pfxs("192.0.0.4/32"),
|
||||
},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user