Fix CodeRabbit findings: hasIPv6Changed restart loop, empty peerIPs panic, v6 validation

This commit is contained in:
Viktor Liu
2026-03-24 12:35:58 +01:00
parent 878dc45abf
commit baf2c03508
4 changed files with 28 additions and 22 deletions

View File

@@ -1728,7 +1728,7 @@ func TestEngine_hasIPv6Changed(t *testing.T) {
{
name: "no v6 before, v6 added",
current: v4Only,
confV6: netiputil.EncodeAddr(netip.MustParseAddr("fd00::1")),
confV6: netiputil.EncodePrefix(netip.MustParsePrefix("fd00::1/64")),
expected: true,
},
{
@@ -1740,13 +1740,19 @@ func TestEngine_hasIPv6Changed(t *testing.T) {
{
name: "had v6, same v6",
current: v4v6,
confV6: netiputil.EncodeAddr(netip.MustParseAddr("fd00::1")),
confV6: netiputil.EncodePrefix(netip.MustParsePrefix("fd00::1/64")),
expected: false,
},
{
name: "had v6, different v6",
current: v4v6,
confV6: netiputil.EncodeAddr(netip.MustParseAddr("fd00::2")),
confV6: netiputil.EncodePrefix(netip.MustParsePrefix("fd00::2/64")),
expected: true,
},
{
name: "same v6 addr, different prefix length",
current: v4v6,
confV6: netiputil.EncodePrefix(netip.MustParsePrefix("fd00::1/80")),
expected: true,
},
{
@@ -1760,9 +1766,7 @@ func TestEngine_hasIPv6Changed(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
engine := &Engine{
wgInterface: &MockWGIface{
AddressFunc: func() wgaddr.Address { return tt.current },
},
config: &EngineConfig{WgAddr: tt.current},
}
conf := &mgmtProto.PeerConfig{
AddressV6: tt.confV6,