Update vendored packages
This commit is contained in:
parent
84eaa8fecd
commit
ce117d7a40
119 changed files with 2565 additions and 1524 deletions
79
vendor/github.com/mdlayher/netlink/conn_linux.go
generated
vendored
79
vendor/github.com/mdlayher/netlink/conn_linux.go
generated
vendored
|
|
@ -7,10 +7,13 @@ import (
|
|||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/bpf"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidSockaddr = errors.New("expected syscall.SockaddrNetlink but received different syscall.Sockaddr")
|
||||
errInvalidSockaddr = errors.New("expected unix.SockaddrNetlink but received different unix.Sockaddr")
|
||||
errInvalidFamily = errors.New("received invalid netlink family")
|
||||
)
|
||||
|
||||
|
|
@ -19,24 +22,24 @@ var _ osConn = &conn{}
|
|||
// A conn is the Linux implementation of a netlink sockets connection.
|
||||
type conn struct {
|
||||
s socket
|
||||
sa *syscall.SockaddrNetlink
|
||||
sa *unix.SockaddrNetlink
|
||||
}
|
||||
|
||||
// A socket is an interface over socket system calls.
|
||||
type socket interface {
|
||||
Bind(sa syscall.Sockaddr) error
|
||||
Bind(sa unix.Sockaddr) error
|
||||
Close() error
|
||||
Recvfrom(p []byte, flags int) (int, syscall.Sockaddr, error)
|
||||
Sendto(p []byte, flags int, to syscall.Sockaddr) error
|
||||
Recvmsg(p, oob []byte, flags int) (n int, oobn int, recvflags int, from unix.Sockaddr, err error)
|
||||
Sendmsg(p, oob []byte, to unix.Sockaddr, flags int) error
|
||||
SetSockopt(level, name int, v unsafe.Pointer, l uint32) error
|
||||
}
|
||||
|
||||
// dial is the entry point for Dial. dial opens a netlink socket using
|
||||
// system calls.
|
||||
func dial(family int, config *Config) (*conn, error) {
|
||||
fd, err := syscall.Socket(
|
||||
syscall.AF_NETLINK,
|
||||
syscall.SOCK_RAW,
|
||||
fd, err := unix.Socket(
|
||||
unix.AF_NETLINK,
|
||||
unix.SOCK_RAW,
|
||||
family,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
@ -53,8 +56,8 @@ func bind(s socket, config *Config) (*conn, error) {
|
|||
config = &Config{}
|
||||
}
|
||||
|
||||
addr := &syscall.SockaddrNetlink{
|
||||
Family: syscall.AF_NETLINK,
|
||||
addr := &unix.SockaddrNetlink{
|
||||
Family: unix.AF_NETLINK,
|
||||
Groups: config.Groups,
|
||||
}
|
||||
|
||||
|
|
@ -75,9 +78,11 @@ func (c *conn) Send(m Message) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return c.s.Sendto(b, 0, &syscall.SockaddrNetlink{
|
||||
Family: syscall.AF_NETLINK,
|
||||
})
|
||||
addr := &unix.SockaddrNetlink{
|
||||
Family: unix.AF_NETLINK,
|
||||
}
|
||||
|
||||
return c.s.Sendmsg(b, nil, addr, 0)
|
||||
}
|
||||
|
||||
// Receive receives one or more Messages from netlink.
|
||||
|
|
@ -85,7 +90,7 @@ func (c *conn) Receive() ([]Message, error) {
|
|||
b := make([]byte, os.Getpagesize())
|
||||
for {
|
||||
// Peek at the buffer to see how many bytes are available
|
||||
n, _, err := c.s.Recvfrom(b, syscall.MSG_PEEK)
|
||||
n, _, _, _, err := c.s.Recvmsg(b, nil, unix.MSG_PEEK)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -100,16 +105,16 @@ func (c *conn) Receive() ([]Message, error) {
|
|||
}
|
||||
|
||||
// Read out all available messages
|
||||
n, from, err := c.s.Recvfrom(b, 0)
|
||||
n, _, _, from, err := c.s.Recvmsg(b, nil, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
addr, ok := from.(*syscall.SockaddrNetlink)
|
||||
addr, ok := from.(*unix.SockaddrNetlink)
|
||||
if !ok {
|
||||
return nil, errInvalidSockaddr
|
||||
}
|
||||
if addr.Family != syscall.AF_NETLINK {
|
||||
if addr.Family != unix.AF_NETLINK {
|
||||
return nil, errInvalidFamily
|
||||
}
|
||||
|
||||
|
|
@ -136,16 +141,11 @@ func (c *conn) Close() error {
|
|||
return c.s.Close()
|
||||
}
|
||||
|
||||
const (
|
||||
// #define SOL_NETLINK 270
|
||||
solNetlink = 270
|
||||
)
|
||||
|
||||
// JoinGroup joins a multicast group by ID.
|
||||
func (c *conn) JoinGroup(group uint32) error {
|
||||
return c.s.SetSockopt(
|
||||
solNetlink,
|
||||
syscall.NETLINK_ADD_MEMBERSHIP,
|
||||
unix.SOL_NETLINK,
|
||||
unix.NETLINK_ADD_MEMBERSHIP,
|
||||
unsafe.Pointer(&group),
|
||||
uint32(unsafe.Sizeof(group)),
|
||||
)
|
||||
|
|
@ -154,13 +154,28 @@ func (c *conn) JoinGroup(group uint32) error {
|
|||
// LeaveGroup leaves a multicast group by ID.
|
||||
func (c *conn) LeaveGroup(group uint32) error {
|
||||
return c.s.SetSockopt(
|
||||
solNetlink,
|
||||
syscall.NETLINK_DROP_MEMBERSHIP,
|
||||
unix.SOL_NETLINK,
|
||||
unix.NETLINK_DROP_MEMBERSHIP,
|
||||
unsafe.Pointer(&group),
|
||||
uint32(unsafe.Sizeof(group)),
|
||||
)
|
||||
}
|
||||
|
||||
// SetBPF attaches an assembled BPF program to a conn.
|
||||
func (c *conn) SetBPF(filter []bpf.RawInstruction) error {
|
||||
prog := unix.SockFprog{
|
||||
Len: uint16(len(filter)),
|
||||
Filter: (*unix.SockFilter)(unsafe.Pointer(&filter[0])),
|
||||
}
|
||||
|
||||
return c.s.SetSockopt(
|
||||
unix.SOL_SOCKET,
|
||||
unix.SO_ATTACH_FILTER,
|
||||
unsafe.Pointer(&prog),
|
||||
uint32(unsafe.Sizeof(prog)),
|
||||
)
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
@ -181,13 +196,13 @@ type sysSocket struct {
|
|||
fd int
|
||||
}
|
||||
|
||||
func (s *sysSocket) Bind(sa syscall.Sockaddr) error { return syscall.Bind(s.fd, sa) }
|
||||
func (s *sysSocket) Close() error { return syscall.Close(s.fd) }
|
||||
func (s *sysSocket) Recvfrom(p []byte, flags int) (int, syscall.Sockaddr, error) {
|
||||
return syscall.Recvfrom(s.fd, p, flags)
|
||||
func (s *sysSocket) Bind(sa unix.Sockaddr) error { return unix.Bind(s.fd, sa) }
|
||||
func (s *sysSocket) Close() error { return unix.Close(s.fd) }
|
||||
func (s *sysSocket) Recvmsg(p, oob []byte, flags int) (int, int, int, unix.Sockaddr, error) {
|
||||
return unix.Recvmsg(s.fd, p, oob, flags)
|
||||
}
|
||||
func (s *sysSocket) Sendto(p []byte, flags int, to syscall.Sockaddr) error {
|
||||
return syscall.Sendto(s.fd, p, flags, to)
|
||||
func (s *sysSocket) Sendmsg(p, oob []byte, to unix.Sockaddr, flags int) error {
|
||||
return unix.Sendmsg(s.fd, p, oob, to, flags)
|
||||
}
|
||||
func (s *sysSocket) SetSockopt(level, name int, v unsafe.Pointer, l uint32) error {
|
||||
return setsockopt(s.fd, level, name, v, l)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue