vendor: bump github.com/mdlayher/wifi and dependencies (#1045)

Signed-off-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
Matt Layher 2018-08-14 15:15:07 -04:00 committed by Ben Kochie
commit d84873727f
10 changed files with 608 additions and 182 deletions

View file

@ -94,6 +94,25 @@ func bind(s socket, config *Config) (*conn, uint32, error) {
}, pid, nil
}
// SendMessages serializes multiple Messages and sends them to netlink.
func (c *conn) SendMessages(messages []Message) error {
var buf []byte
for _, m := range messages {
b, err := m.MarshalBinary()
if err != nil {
return err
}
buf = append(buf, b...)
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return c.s.Sendmsg(buf, nil, addr, 0)
}
// Send sends a single Message to netlink.
func (c *conn) Send(m Message) error {
b, err := m.MarshalBinary()
@ -112,7 +131,10 @@ func (c *conn) Send(m Message) error {
func (c *conn) Receive() ([]Message, error) {
b := make([]byte, os.Getpagesize())
for {
// Peek at the buffer to see how many bytes are available
// Peek at the buffer to see how many bytes are available.
//
// TODO(mdlayher): deal with OOB message data if available, such as
// when PacketInfo ConnOption is true.
n, _, _, _, err := c.s.Recvmsg(b, nil, unix.MSG_PEEK)
if err != nil {
return nil, err
@ -204,6 +226,58 @@ func (c *conn) SetBPF(filter []bpf.RawInstruction) error {
)
}
// RemoveBPF removes a BPF filter from a conn.
func (c *conn) RemoveBPF() error {
// dummy is ignored as argument to SO_DETACH_FILTER
// but SetSockopt requires it as an argument
var dummy uint32
return c.s.SetSockopt(
unix.SOL_SOCKET,
unix.SO_DETACH_FILTER,
unsafe.Pointer(&dummy),
uint32(unsafe.Sizeof(dummy)),
)
}
// SetOption enables or disables a netlink socket option for the Conn.
func (c *conn) SetOption(option ConnOption, enable bool) error {
o, ok := linuxOption(option)
if !ok {
// Return the typical Linux error for an unknown ConnOption.
return unix.ENOPROTOOPT
}
var v uint32
if enable {
v = 1
}
return c.s.SetSockopt(
unix.SOL_NETLINK,
o,
unsafe.Pointer(&v),
uint32(unsafe.Sizeof(v)),
)
}
// linuxOption converts a ConnOption to its Linux value.
func linuxOption(o ConnOption) (int, bool) {
switch o {
case PacketInfo:
return unix.NETLINK_PKTINFO, true
case BroadcastError:
return unix.NETLINK_BROADCAST_ERROR, true
case NoENOBUFS:
return unix.NETLINK_NO_ENOBUFS, true
case ListenAllNSID:
return unix.NETLINK_LISTEN_ALL_NSID, true
case CapAcknowledge:
return unix.NETLINK_CAP_ACK, true
default:
return 0, false
}
}
// sysToHeader converts a syscall.NlMsghdr to a Header.
func sysToHeader(r syscall.NlMsghdr) Header {
// NB: the memory layout of Header and syscall.NlMsgHdr must be
@ -247,10 +321,20 @@ func newSysSocket(lockThread bool) *sysSocket {
// But since this is very experimental, we'll leave it as a configurable at
// this point.
if lockThread {
// Never unlock the OS thread, so that the thread will terminate when
// the goroutine exits starting in Go 1.10:
// The intent is to never unlock the OS thread, so that the thread
// will terminate when the goroutine exits starting in Go 1.10:
// https://go-review.googlesource.com/c/go/+/46038.
//
// However, due to recent instability and a potential bad interaction
// with the Go runtime for threads which are not unlocked, we have
// elected to temporarily unlock the thread:
// https://github.com/golang/go/issues/25128#issuecomment-410764489.
//
// If we ever allow a Conn to set its own network namespace, we must
// either ensure that the namespace is restored on exit here or that
// the thread is properly terminated at some point in the future.
runtime.LockOSThread()
defer runtime.UnlockOSThread()
}
defer wg.Done()