netlink

package
v0.0.0-...-522126a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package netlink provides core functionality for netlink sockets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractSockAddr

func ExtractSockAddr(b []byte) (*linux.SockAddrNetlink, *syserr.Error)

ExtractSockAddr extracts the SockAddrNetlink from b.

func RegisterProvider

func RegisterProvider(protocol int, provider Provider)

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 Message

type Message struct {
	// contains filtered or unexported fields
}

Message contains a complete serialized netlink message.

func NewMessage

func NewMessage(hdr linux.NetlinkMessageHeader) *Message

NewMessage creates a new Message containing the passed header.

The header length will be updated by Finalize.

func (*Message) Finalize

func (m *Message) Finalize() []byte

Finalize returns the []byte containing the entire message, with the total length set in the message header. The Message must not be modified after calling Finalize.

func (*Message) Put

func (m *Message) Put(v interface{})

Put serializes v into the message.

func (*Message) PutAttr

func (m *Message) PutAttr(atype uint16, v interface{})

PutAttr adds v to the message as a netlink attribute.

Preconditions: The serialized attribute (linux.NetlinkAttrHeaderSize + binary.Size(v) fits in math.MaxUint16 bytes.

func (*Message) PutAttrString

func (m *Message) PutAttrString(atype uint16, s string)

PutAttrString adds s to the message as a netlink attribute.

type MessageSet

type MessageSet struct {
	// Multi indicates that this a multi-part message, to be terminated by
	// NLMSG_DONE. NLMSG_DONE is sent even if the set contains only one
	// Message.
	//
	// If Multi is set, all added messages will have NLM_F_MULTI set.
	Multi bool

	// PortID is the destination port for all messages.
	PortID int32

	// Seq is the sequence counter for all messages in the set.
	Seq uint32

	// Messages contains the messages in the set.
	Messages []*Message
}

MessageSet contains a series of netlink messages.

func NewMessageSet

func NewMessageSet(portID int32, seq uint32) *MessageSet

NewMessageSet creates a new MessageSet.

portID is the destination port to set as PortID in all messages.

seq is the sequence counter to set as seq in all messages in the set.

func (*MessageSet) AddMessage

func (ms *MessageSet) AddMessage(hdr linux.NetlinkMessageHeader) *Message

AddMessage adds a new message to the set and returns it for further additions.

The passed header will have Seq, PortID and the multi flag set automatically.

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

	// 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, hdr linux.NetlinkMessageHeader, data []byte, ms *MessageSet) *syserr.Error
}

Protocol is the implementation of a netlink socket protocol.

type Provider

type Provider func(t *kernel.Task) (Protocol, *syserr.Error)

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 Socket

type Socket struct {
	fsutil.FilePipeSeek             `state:"nosave"`
	fsutil.FileNotDirReaddir        `state:"nosave"`
	fsutil.FileNoFsync              `state:"nosave"`
	fsutil.FileNoMMap               `state:"nosave"`
	fsutil.FileNoSplice             `state:"nosave"`
	fsutil.FileNoopFlush            `state:"nosave"`
	fsutil.FileUseInodeUnstableAttr `state:"nosave"`
	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 NewSocket

func NewSocket(t *kernel.Task, skType linux.SockType, protocol Protocol) (*Socket, *syserr.Error)

NewSocket creates a new Socket.

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) Bind

func (s *Socket) Bind(t *kernel.Task, sockaddr []byte) *syserr.Error

Bind implements socket.Socket.Bind.

func (*Socket) Connect

func (s *Socket) Connect(t *kernel.Task, sockaddr []byte, blocking bool) *syserr.Error

Connect implements socket.Socket.Connect.

func (*Socket) ConnectedPasscred

func (s *Socket) ConnectedPasscred() bool

ConnectedPasscred implements transport.Credentialer.ConnectedPasscred.

func (*Socket) EventRegister

func (s *Socket) EventRegister(e *waiter.Entry, mask waiter.EventMask)

EventRegister implements waiter.Waitable.EventRegister.

func (*Socket) EventUnregister

func (s *Socket) EventUnregister(e *waiter.Entry)

EventUnregister implements waiter.Waitable.EventUnregister.

func (*Socket) GetPeerName

func (s *Socket) GetPeerName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)

GetPeerName implements socket.Socket.GetPeerName.

func (*Socket) GetSockName

func (s *Socket) GetSockName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)

GetSockName implements socket.Socket.GetSockName.

func (*Socket) GetSockOpt

func (s *Socket) GetSockOpt(t *kernel.Task, level int, name int, outPtr usermem.Addr, outLen int) (interface{}, *syserr.Error)

GetSockOpt implements socket.Socket.GetSockOpt.

func (*Socket) Ioctl

Ioctl implements fs.FileOperations.Ioctl.

func (*Socket) Listen

func (s *Socket) Listen(t *kernel.Task, backlog int) *syserr.Error

Listen implements socket.Socket.Listen.

func (*Socket) Passcred

func (s *Socket) Passcred() bool

Passcred implements transport.Credentialer.Passcred.

func (*Socket) Read

func (s *Socket) Read(ctx context.Context, _ *fs.File, dst usermem.IOSequence, _ int64) (int64, error)

Read implements fs.FileOperations.Read.

func (*Socket) Readiness

func (s *Socket) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness implements waiter.Waitable.Readiness.

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) Release

func (s *Socket) Release()

Release implements fs.FileOperations.Release.

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) SetSockOpt

func (s *Socket) SetSockOpt(t *kernel.Task, level int, name int, opt []byte) *syserr.Error

SetSockOpt implements socket.Socket.SetSockOpt.

func (*Socket) Shutdown

func (s *Socket) Shutdown(t *kernel.Task, how int) *syserr.Error

Shutdown implements socket.Socket.Shutdown.

func (*Socket) State

func (s *Socket) State() uint32

State implements socket.Socket.State.

func (*Socket) Type

func (s *Socket) Type() (family int, skType linux.SockType, protocol int)

Type implements socket.Socket.Type.

func (*Socket) Write

func (s *Socket) Write(ctx context.Context, _ *fs.File, src usermem.IOSequence, _ int64) (int64, error)

Write implements fs.FileOperations.Write.

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL