Support for multi proto tun device on NetBSD (#1492)

This commit is contained in:
Nate Brown
2025-10-07 21:17:50 -04:00
committed by GitHub
parent fb7f0c3657
commit eb89839d13
3 changed files with 407 additions and 88 deletions

View File

@@ -501,30 +501,6 @@ func (t *tun) deviceBytes() (o [16]byte) {
return
}
func flipBytes(b []byte) []byte {
for i := 0; i < len(b); i++ {
b[i] ^= 0xFF
}
return b
}
func orBytes(a []byte, b []byte) []byte {
ret := make([]byte, len(a))
for i := 0; i < len(a); i++ {
ret[i] = a[i] | b[i]
}
return ret
}
func getBroadcast(cidr netip.Prefix) netip.Addr {
broadcast, _ := netip.AddrFromSlice(
orBytes(
cidr.Addr().AsSlice(),
flipBytes(prefixToMask(cidr).AsSlice()),
),
)
return broadcast
}
func addRoute(prefix netip.Prefix, gateway netroute.Addr) error {
sock, err := unix.Socket(unix.AF_ROUTE, unix.SOCK_RAW, unix.AF_UNSPEC)
if err != nil {