No longer set SIOCGIFFLAGS, update README.md
This commit is contained in:
parent
ede44e8426
commit
a7eb52c0c5
@ -10,7 +10,7 @@
|
||||
|
||||
## 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``
|
||||
3) **For systemd users:** Install the service unit file
|
||||
````
|
||||
|
@ -38,34 +38,46 @@ type iflags struct {
|
||||
flags uint16
|
||||
}
|
||||
|
||||
func setPromisc(fd int, iface string, enable bool) {
|
||||
func setPromisc(fd int, iface string, enable bool, withInterfaceFlags bool) {
|
||||
//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 {
|
||||
ifl.flags |= uint16(syscall.IFF_PROMISC)
|
||||
} else {
|
||||
ifl.flags &^= uint16(syscall.IFF_PROMISC)
|
||||
}
|
||||
// -------------------------- Interface flags --------------------------
|
||||
if withInterfaceFlags {
|
||||
tFD, err := syscall.Socket(syscall.AF_INET6, syscall.SOCK_DGRAM, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, _, ep = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
|
||||
if ep != 0 {
|
||||
panic(ep)
|
||||
}
|
||||
var ifl iflags
|
||||
copy(ifl.name[:], []byte(iface))
|
||||
_, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(tFD), syscall.SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifl)))
|
||||
if ep != 0 {
|
||||
panic(ep)
|
||||
}
|
||||
|
||||
// Also set Sockopt to promisc
|
||||
intf, err := net.InterfaceByName(iface)
|
||||
if enable {
|
||||
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 {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
mreq := unix.PacketMreq{
|
||||
Ifindex: int32(intf.Index),
|
||||
mReq := unix.PacketMreq{
|
||||
Ifindex: int32(iFace.Index),
|
||||
Type: unix.PACKET_MR_PROMISC,
|
||||
}
|
||||
|
||||
@ -76,9 +88,9 @@ func setPromisc(fd int, iface string, enable bool) {
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func listen(iface string, responder chan *ndpRequest, requestType ndpType, stopW
|
||||
}
|
||||
go func() {
|
||||
<-stopChan
|
||||
setPromisc(fd, iface, false)
|
||||
setPromisc(fd, iface, false, false)
|
||||
_ = syscall.Close(fd)
|
||||
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())
|
||||
}
|
||||
|
||||
setPromisc(fd, iface, true)
|
||||
setPromisc(fd, iface, true, false)
|
||||
|
||||
var protocolNo uint32
|
||||
if requestType == ndp_SOL {
|
||||
|
Loading…
x
Reference in New Issue
Block a user