Change net.IP to netip.Addr

This commit is contained in:
Zoltán Papp
2025-01-24 15:03:38 +01:00
parent 4ad5c55795
commit 00b8f6ad8e
2 changed files with 11 additions and 6 deletions

View File

@@ -2,14 +2,14 @@ package manager
import (
"fmt"
"net"
"net/netip"
)
// ForwardRule todo figure out better place to this to avoid circular imports
type ForwardRule struct {
Protocol Protocol
DestinationPort Port
TranslatedAddress net.IP
TranslatedAddress netip.Addr
TranslatedPort Port
}

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net"
"net/netip"
firewallManager "github.com/netbirdio/netbird/client/firewall/manager"
mgmProto "github.com/netbirdio/netbird/management/proto"
@@ -46,14 +47,18 @@ func convertPortInfo(portInfo *mgmProto.PortInfo) *firewallManager.Port {
return nil
}
func convertToIP(rawIP []byte) (net.IP, error) {
func convertToIP(rawIP []byte) (netip.Addr, error) {
if rawIP == nil {
return nil, errors.New("input bytes cannot be nil")
return netip.Addr{}, errors.New("input bytes cannot be nil")
}
if len(rawIP) != net.IPv4len && len(rawIP) != net.IPv6len {
return nil, fmt.Errorf("invalid IP length: %d", len(rawIP))
return netip.Addr{}, fmt.Errorf("invalid IP length: %d", len(rawIP))
}
return rawIP, nil
if len(rawIP) == net.IPv4len {
return netip.AddrFrom4([4]byte(rawIP)), nil
}
return netip.AddrFrom16([16]byte(rawIP)), nil
}