Documentation
¶
Overview ¶
Package netlink provides core functionality for netlink sockets.
Index ¶
- func DumpAckMessage(hdr linux.NetlinkMessageHeader, ms *nlmsg.MessageSet)
- func DumpErrorMessage(hdr linux.NetlinkMessageHeader, ms *nlmsg.MessageSet, err *syserr.Error)
- func ExtractSockAddr(b []byte) (*linux.SockAddrNetlink, *syserr.Error)
- func RegisterProvider(protocol int, provider Provider)
- type Protocol
- type Provider
- type RouteProtocol
- type Socket
- func (s *Socket) Accept(t *kernel.Task, peerRequested bool, flags int, blocking bool) (int32, linux.SockAddr, uint32, *syserr.Error)
- func (s *Socket) Bind(t *kernel.Task, sockaddr []byte) *syserr.Error
- func (s *Socket) Connect(t *kernel.Task, sockaddr []byte, blocking bool) *syserr.Error
- func (s *Socket) ConnectedPasscred() bool
- func (s *Socket) Epollable() bool
- func (s *Socket) EventRegister(e *waiter.Entry) error
- func (s *Socket) EventUnregister(e *waiter.Entry)
- func (s *Socket) GetPeerCreds(t *kernel.Task) (marshal.Marshallable, *syserr.Error)
- func (s *Socket) GetPeerName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)
- func (s *Socket) GetPortID() int32
- func (s *Socket) GetSockName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)
- func (s *Socket) GetSockOpt(t *kernel.Task, level int, name int, outPtr hostarch.Addr, outLen int) (marshal.Marshallable, *syserr.Error)
- func (s *Socket) Groups() uint64
- func (s *Socket) HandleInterfaceChangeEvent(ctx context.Context, idx int32, i inet.Interface)
- func (s *Socket) HandleInterfaceDeleteEvent(ctx context.Context, idx int32, i inet.Interface)
- func (*Socket) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error)
- func (s *Socket) Listen(t *kernel.Task, backlog int) *syserr.Error
- func (s *Socket) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, ...) (int64, error)
- func (s *Socket) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, ...) (int64, error)
- func (s *Socket) Passcred() bool
- func (s *Socket) ProcessMessages(ctx context.Context, buf []byte) *syserr.Error
- func (s *Socket) Protocol() int
- func (s *Socket) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error)
- func (s *Socket) Readiness(mask waiter.EventMask) waiter.EventMask
- func (s *Socket) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags int, haveDeadline bool, ...) (int, int, linux.SockAddr, uint32, socket.ControlMessages, *syserr.Error)
- func (s *Socket) Release(ctx context.Context)
- func (s *Socket) SendMsg(t *kernel.Task, src usermem.IOSequence, to []byte, flags int, ...) (int, *syserr.Error)
- func (s *Socket) SendResponse(ctx context.Context, ms *nlmsg.MessageSet) *syserr.Error
- func (s *Socket) SetSockOpt(t *kernel.Task, level int, name int, opt []byte) *syserr.Error
- func (s *Socket) Shutdown(t *kernel.Task, how int) *syserr.Error
- func (s *Socket) Stack() inet.Stack
- func (s *Socket) State() uint32
- func (s *Socket) Type() (family int, skType linux.SockType, protocol int)
- func (s *Socket) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DumpAckMessage ¶
func DumpAckMessage(hdr linux.NetlinkMessageHeader, ms *nlmsg.MessageSet)
DumpAckMessage adds an ack message to the message set.
func DumpErrorMessage ¶
func DumpErrorMessage(hdr linux.NetlinkMessageHeader, ms *nlmsg.MessageSet, err *syserr.Error)
DumpErrorMessage adds an error message to the message set.
func ExtractSockAddr ¶
func ExtractSockAddr(b []byte) (*linux.SockAddrNetlink, *syserr.Error)
ExtractSockAddr extracts the SockAddrNetlink from b.
func RegisterProvider ¶
RegisterProvider registers the provider of a given address protocol so that netlink sockets of that type can be created via socket(2).
Preconditions: May only be called before any netlink sockets are created.
Types ¶
type Protocol ¶
type Protocol interface {
// Protocol returns the Linux netlink protocol value.
Protocol() int
// CanSend returns true if this protocol may ever send messages.
//
// TODO(gvisor.dev/issue/1119): This is a workaround to allow
// advertising support for otherwise unimplemented features on sockets
// that will never send messages, thus making those features no-ops.
CanSend() bool
// Receive receives an arbitrary message or batch of messages
// and processes them.
Receive(ctx context.Context, s *Socket, buf []byte) *syserr.Error
// ProcessMessage processes a single message from userspace.
//
// If err == nil, any messages added to ms will be sent back to the
// other end of the socket. Setting ms.Multi will cause an NLMSG_DONE
// message to be sent even if ms contains no messages.
ProcessMessage(ctx context.Context, s *Socket, msg *nlmsg.Message, ms *nlmsg.MessageSet) *syserr.Error
}
Protocol is the implementation of a netlink socket protocol.
type Provider ¶
Provider is a function that creates a new Protocol for a specific netlink protocol.
Note that this is distinct from socket.Provider, which is used for all socket families.
type RouteProtocol ¶
type RouteProtocol interface {
Protocol
// AddNewLinkMessage is called when an interface is mutated or created by the stack.
// It is the rough equivalent of Linux's rtnetlink_event().
AddNewLinkMessage(ms *nlmsg.MessageSet, idx int32, i inet.Interface)
// AddDelLinkMessage is called when an interface is deleted by the stack.
AddDelLinkMessage(ms *nlmsg.MessageSet, idx int32, i inet.Interface)
}
RouteProtocol corresponds to the NETLINK_ROUTE family.
type Socket ¶
type Socket struct {
vfs.FileDescriptionDefaultImpl
vfs.DentryMetadataFileDescriptionImpl
vfs.LockFD
socket.SendReceiveTimeout
// contains filtered or unexported fields
}
Socket is the base socket type for netlink sockets.
This implementation only supports userspace sending and receiving messages to/from the kernel.
Socket implements socket.Socket and transport.Credentialer.
+stateify savable
func (*Socket) Accept ¶
func (s *Socket) Accept(t *kernel.Task, peerRequested bool, flags int, blocking bool) (int32, linux.SockAddr, uint32, *syserr.Error)
Accept implements socket.Socket.Accept.
func (*Socket) ConnectedPasscred ¶
ConnectedPasscred implements transport.Credentialer.ConnectedPasscred.
func (*Socket) EventRegister ¶
EventRegister implements waiter.Waitable.EventRegister.
func (*Socket) EventUnregister ¶
EventUnregister implements waiter.Waitable.EventUnregister.
func (*Socket) GetPeerCreds ¶
GetPeerCreds implements socket.Socket.GetPeerCreds.
func (*Socket) GetPeerName ¶
GetPeerName implements socket.Socket.GetPeerName.
func (*Socket) GetSockName ¶
GetSockName implements socket.Socket.GetSockName.
func (*Socket) GetSockOpt ¶
func (s *Socket) GetSockOpt(t *kernel.Task, level int, name int, outPtr hostarch.Addr, outLen int) (marshal.Marshallable, *syserr.Error)
GetSockOpt implements socket.Socket.GetSockOpt.
func (*Socket) HandleInterfaceChangeEvent ¶
HandleInterfaceChangeEvent implements inet.NetlinkSocket.HandleInterfaceChangeEvent.
func (*Socket) HandleInterfaceDeleteEvent ¶
HandleInterfaceDeleteEvent implements inet.NetlinkSocket.HandleInterfaceDeleteEvent.
func (*Socket) Ioctl ¶
func (*Socket) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error)
Ioctl implements vfs.FileDescriptionImpl.
func (*Socket) PRead ¶
func (s *Socket) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error)
PRead implements vfs.FileDescriptionImpl.
func (*Socket) PWrite ¶
func (s *Socket) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error)
PWrite implements vfs.FileDescriptionImpl.
func (*Socket) ProcessMessages ¶
ProcessMessages handles each message in buf, passing it to the protocol handler for final handling.
func (*Socket) Read ¶
func (s *Socket) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error)
Read implements vfs.FileDescriptionImpl.
func (*Socket) RecvMsg ¶
func (s *Socket) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags int, haveDeadline bool, deadline ktime.Time, senderRequested bool, controlDataLen uint64) (int, int, linux.SockAddr, uint32, socket.ControlMessages, *syserr.Error)
RecvMsg implements socket.Socket.RecvMsg.
func (*Socket) SendMsg ¶
func (s *Socket) SendMsg(t *kernel.Task, src usermem.IOSequence, to []byte, flags int, haveDeadline bool, deadline ktime.Time, controlMessages socket.ControlMessages) (int, *syserr.Error)
SendMsg implements socket.Socket.SendMsg.
func (*Socket) SendResponse ¶
SendResponse sends the response messages in ms back to userspace.
func (*Socket) SetSockOpt ¶
SetSockOpt implements socket.Socket.SetSockOpt.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package netfilter provides a NETLINK_NETFILTER socket protocol.
|
Package netfilter provides a NETLINK_NETFILTER socket protocol. |
|
Package nlmsg provides helpers to parse and construct netlink messages.
|
Package nlmsg provides helpers to parse and construct netlink messages. |
|
Package port provides port ID allocation for netlink sockets.
|
Package port provides port ID allocation for netlink sockets. |
|
Package route provides a NETLINK_ROUTE socket protocol.
|
Package route provides a NETLINK_ROUTE socket protocol. |
|
Package uevent provides a NETLINK_KOBJECT_UEVENT socket protocol.
|
Package uevent provides a NETLINK_KOBJECT_UEVENT socket protocol. |