No longer set SIOCGIFFLAGS, update README.md

This commit is contained in:
Kioubit 2022-01-07 07:20:32 -05:00
parent ede44e8426
commit a7eb52c0c5
3 changed files with 37 additions and 25 deletions

View File

@ -10,7 +10,7 @@
## Installing & Updating ## Installing & Updating
1) Download the latest release from the releases page and move the binary to the ``/usr/local/bin/`` directory under the filename ``pndpd``. 1) Download the latest release from the [releases page](https://github.com/Kioubit/pndpd/releases) and move the binary to the ``/usr/local/bin/`` directory under the filename ``pndpd``.
2) Allow executing the file by running ``chmod +x /usr/local/bin/pndpd`` 2) Allow executing the file by running ``chmod +x /usr/local/bin/pndpd``
3) **For systemd users:** Install the service unit file 3) **For systemd users:** Install the service unit file
```` ````

View File

@ -38,34 +38,46 @@ type iflags struct {
flags uint16 flags uint16
} }
func setPromisc(fd int, iface string, enable bool) { func setPromisc(fd int, iface string, enable bool, withInterfaceFlags bool) {
//TODO re-test ALLMULTI //TODO re-test ALLMULTI
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 { // -------------------------- Interface flags --------------------------
ifl.flags |= uint16(syscall.IFF_PROMISC) if withInterfaceFlags {
} else { tFD, err := syscall.Socket(syscall.AF_INET6, syscall.SOCK_DGRAM, 0)
ifl.flags &^= uint16(syscall.IFF_PROMISC) if err != nil {
} panic(err)
}
_, _, ep = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl))) var ifl iflags
if ep != 0 { copy(ifl.name[:], []byte(iface))
panic(ep) _, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(tFD), syscall.SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
} if ep != 0 {
panic(ep)
}
// Also set Sockopt to promisc if enable {
intf, err := net.InterfaceByName(iface) ifl.flags |= uint16(syscall.IFF_PROMISC)
} else {
ifl.flags &^= uint16(syscall.IFF_PROMISC)
}
_, _, ep = syscall.Syscall(syscall.SYS_IOCTL, uintptr(tFD), syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
if ep != 0 {
panic(ep)
}
_ = syscall.Close(tFD)
}
// ---------------------------------------------------------------------
// -------------------------- Socket Options ---------------------------
iFace, err := net.InterfaceByName(iface)
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }
mreq := unix.PacketMreq{ mReq := unix.PacketMreq{
Ifindex: int32(intf.Index), Ifindex: int32(iFace.Index),
Type: unix.PACKET_MR_PROMISC, Type: unix.PACKET_MR_PROMISC,
} }
@ -76,9 +88,9 @@ func setPromisc(fd int, iface string, enable bool) {
opt = unix.PACKET_DROP_MEMBERSHIP opt = unix.PACKET_DROP_MEMBERSHIP
} }
err = unix.SetsockoptPacketMreq(fd, unix.SOL_PACKET, opt, &mreq) err = unix.SetsockoptPacketMreq(fd, unix.SOL_PACKET, opt, &mReq)
if err != nil { if err != nil {
panic(err) panic(err)
} }
// ---------------------------------------------------------------------
} }

View File

@ -34,7 +34,7 @@ func listen(iface string, responder chan *ndpRequest, requestType ndpType, stopW
} }
go func() { go func() {
<-stopChan <-stopChan
setPromisc(fd, iface, false) setPromisc(fd, iface, false, false)
_ = syscall.Close(fd) _ = syscall.Close(fd)
stopWG.Done() // syscall.read does not release when the file descriptor is closed stopWG.Done() // syscall.read does not release when the file descriptor is closed
}() }()
@ -51,7 +51,7 @@ func listen(iface string, responder chan *ndpRequest, requestType ndpType, stopW
panic(err.Error()) panic(err.Error())
} }
setPromisc(fd, iface, true) setPromisc(fd, iface, true, false)
var protocolNo uint32 var protocolNo uint32
if requestType == ndp_SOL { if requestType == ndp_SOL {