Set Interface Allmulti flag

This commit is contained in:
Kioubit 2021-12-26 07:13:48 -05:00
parent de4d228950
commit 45b9ac5e86
2 changed files with 30 additions and 2 deletions

View File

@ -61,6 +61,7 @@ func listen(iface string, responder chan *ndpRequest, requestType ndpType, stopW
}
go func() {
<-stopChan
setAllMulti(fd, iface, false)
_ = syscall.Close(fd)
stopWG.Done() // syscall.read does not release when the file descriptor is closed
}()
@ -77,6 +78,8 @@ func listen(iface string, responder chan *ndpRequest, requestType ndpType, stopW
panic(err.Error())
}
setAllMulti(fd, iface, true)
var protocolNo uint32
if requestType == ndp_SOL {
//Neighbor Solicitation
@ -163,3 +166,28 @@ func listen(iface string, responder chan *ndpRequest, requestType ndpType, stopW
}
}
}
type iflags struct {
name [syscall.IFNAMSIZ]byte
flags uint16
}
func setAllMulti(fd int, iface string, enable bool) {
var ifl iflags
copy(ifl.name[:], []byte(iface))
_, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
if ep != 0 {
panic(ep)
}
if enable {
ifl.flags |= uint16(syscall.IFF_ALLMULTI)
} else {
ifl.flags &^= uint16(syscall.IFF_ALLMULTI)
}
_, _, ep = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
if ep != 0 {
panic(ep)
}
}

View File

@ -10,8 +10,8 @@ RestartSec=5s
ExecStart=/usr/bin/pndpd config /etc/pndpd/pndpd.conf
DynamicUser=yes
AmbientCapabilities=CAP_NET_RAW
CapabilityBoundingSet=
AmbientCapabilities=CAP_NET_RAW CAP_NET_ADMIN
CapabilityBoundingSet=CAP_NET_RAW CAP_NET_ADMIN
ProtectHome=yes
[Install]