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

This commit is contained in:
Viktor Liu
2026-03-25 10:06:55 +01:00
parent 878dc45abf
commit 3be5a5f230
4 changed files with 33 additions and 41 deletions
-20
View File
@@ -1,10 +1,7 @@
package wgaddr
import (
"fmt"
"net/netip"
"github.com/netbirdio/netbird/shared/netiputil"
)
// Address WireGuard parsed address
@@ -59,23 +56,6 @@ func (addr Address) IPv6Prefix() netip.Prefix {
return netip.PrefixFrom(addr.IPv6, addr.IPv6Net.Bits())
}
// SetIPv6FromCompact decodes a compact prefix (5 or 17 bytes) and sets the IPv6 fields.
// Returns an error if the bytes are invalid. A nil or empty input is a no-op.
//
//nolint:recvcheck
func (addr *Address) SetIPv6FromCompact(raw []byte) error {
if len(raw) == 0 {
return nil
}
prefix, err := netiputil.DecodePrefix(raw)
if err != nil {
return fmt.Errorf("decode v6 overlay address: %w", err)
}
addr.IPv6 = prefix.Addr()
addr.IPv6Net = prefix.Masked()
return nil
}
// ClearIPv6 removes the IPv6 overlay address, leaving only v4.
//
//nolint:recvcheck // ClearIPv6 is the only mutating method on this otherwise value-type struct.