mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-16 19:49:56 +00:00
# Conflicts: # .github/workflows/golang-test-linux.yml # client/firewall/iptables/manager_linux_test.go # client/firewall/iptables/router_linux_test.go # client/firewall/nftables/manager_linux_test.go # client/firewall/nftables/router_linux_test.go
28 lines
577 B
Go
28 lines
577 B
Go
//go:build privileged
|
|
|
|
package iptables
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"net/netip"
|
|
)
|
|
|
|
func pfx(ip net.IP) []netip.Prefix {
|
|
if ip == nil {
|
|
return []netip.Prefix{netip.PrefixFrom(netip.IPv4Unspecified(), 0)}
|
|
}
|
|
if ip.IsUnspecified() {
|
|
if ip.To4() != nil {
|
|
return []netip.Prefix{netip.PrefixFrom(netip.IPv4Unspecified(), 0)}
|
|
}
|
|
return []netip.Prefix{netip.PrefixFrom(netip.IPv6Unspecified(), 0)}
|
|
}
|
|
a, ok := netip.AddrFromSlice(ip)
|
|
if !ok {
|
|
panic(fmt.Sprintf("invalid IP length: %d", len(ip)))
|
|
}
|
|
a = a.Unmap()
|
|
return []netip.Prefix{netip.PrefixFrom(a, a.BitLen())}
|
|
}
|