Documentation
¶
Overview ¶
Package genetlink implements the Linux Kernel Generic Netlink protocol, for interacting with the systems network stack and related subsystems.
This package contains a low-level implementation of the protocol, you should use a higher-level abstraction contained within a subpackage.
References:
- linux/include/uapi/linux/netlink.h
- linux/include/uapi/linux/genetlink.h
- https://www.kernel.org/doc/html/latest/netlink/specs/nlctrl.html
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFamilyNotFound = errors.New("family not found")
ErrFamilyNotFound is returned by Controller.GetFamily when the requested Generic Netlink family does not exist.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v1.0.0
type Client interface {
// Close the client, underlying socket, and prevent further client
// exchanges.
Close() error
// Seq returns the last sequence number used by the client.
Seq() uint32
// Family returns the id of the Generic Netlink family resolved for the
// family name this client was opened with.
Family() uint16
// FamilyName returns the name of the Generic Netlink family this client
// was opened with.
FamilyName() string
// Version returns the Generic Netlink version this client was opened with.
Version() uint8
// Do executes a Generic Netlink request, marshaling the request from an
// [Marshaler], and does not expect a response other than an ERROR
// message type or an acknowledgement.
//
// The message will automatically have the Generic Netlink header added
// with the given command, and have the REQUEST, ACK and any additional
// flags set.
//
// On non-zero ERROR message types, the error will be unmarshaled
// automatically and returned as an [Error] type.
Do(cmd uint8, flags uint16, src netlink.Marshaler) error
// Dump executes a Generic Netlink request, marshaling the request from a
// [Marshaler], which may be nil, and unmarshaling the response(s) to an
// [Unmarshaler].
//
// The message will automatically have the Generic Netlink header added
// with the given command, and have the REQUEST, DUMP and any additional
// flags set.
//
// If the response contains multiple messages, dst will be unmarshaled to
// repeatedly until all messages have been consumed, not including the
// DONE message type.
//
// On non-zero ERROR message types, the error will be unmarshaled
// automatically and returned as an [Error] type.
Dump(cmd uint8, flags uint16, src netlink.Marshaler, dst netlink.Unmarshaler) error
// Get executes a Generic Netlink request, marshaling the request from a
// [Marshaler], which may be nil, and unmarshaling the response to an
// [Unmarshaler].
//
// The message will automatically have the Generic Netlink header added
// with the given command, and have the REQUEST, ACK and any additional
// flags set.
//
// On non-zero ERROR message types, the error will be unmarshaled
// automatically and returned as an [Error] type.
Get(cmd uint8, flags uint16, src netlink.Marshaler, dst netlink.Unmarshaler) error
}
Client is a wrapper around a netlink.Client for exchanging client requests and responses using Generic Netlink, where all messages will automatically be configured for the Generic Netlink header.
It is safe for concurrent use, the client will only ever have one request and response exchange in-flight at once.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller implements the API for the Generic Netlink Controller, used to register and discover Generic Netlink families available on a system.
References:
func NewController ¶
func NewController() (*Controller, error)
NewController establishes a Netlink socket connection for the netlink.GENERIC family, and returns a Controller client.
func (*Controller) Close ¶ added in v1.0.0
func (c *Controller) Close() error
Close the Netlink socket to the Controller client.
func (*Controller) GetFamily ¶
func (c *Controller) GetFamily(name string) (*Family, error)
GetFamily returns details of the named Generic Netlink family.
If the family does not exist, ErrFamilyNotFound is returned.
func (*Controller) ListFamilies ¶
func (c *Controller) ListFamilies() (Families, error)
ListFamilies lists the available Generic Netlink families.
type Families ¶
type Families []*Family
Families contains the Generic Netlink families available on the system.
References:
func (*Families) UnmarshalNetlink ¶
func (fs *Families) UnmarshalNetlink(msg netlink.MessageDecoder) error
UnmarshalNetlink unmarshals a Generic Netlink family dump from a message.
type Family ¶
type Family struct {
ID uint16
Name string
Version uint32
HdrSize uint32
MaxAttr uint32
Ops []*Op
Groups []*Group
}
Family contains information about a registered Generic Netlink family.
References:
func GetFamily ¶
GetFamily is a helper to resolve the the named Family with an established netlink.Client without initializing a whole Controller.
The client MUST be configured for the netlink.GENERIC family.
If the family does not exist, ErrFamilyNotFound is returned.
func (*Family) UnmarshalAttributes ¶ added in v1.0.0
func (f *Family) UnmarshalAttributes(attrs *netlink.AttributeDecoder) error
UnmarshalAttributes unmarshals the attributes for a Generic Netlink family.
func (*Family) UnmarshalNetlink ¶
func (f *Family) UnmarshalNetlink(msg netlink.MessageDecoder) error
UnmarshalNetlink unmarshals a Generic Netlink family from a message.
type Group ¶ added in v1.0.0
Group is one of the multicast groups a Family has defined.
References:
func (*Group) UnmarshalAttributes ¶ added in v1.0.0
func (g *Group) UnmarshalAttributes(attrs *netlink.AttributeDecoder) error
UnmarshalAttributes unmarshals a multicast group contained within Family.
type Header ¶
type Header struct {
netlink.MessageHeader
Cmd uint8
Version uint8
Reserved uint16
}
Header is the fixed-length preamble before each Generic Netlink message that describes the command.
References:
- linux/include/uapi/linux/genetlink.h
func (Header) AppendBinary ¶
AppendBinary appends a Generic Netlink header to bytes, in the host byteorder.
func (Header) MarshalBinary ¶
MarshalBinary marshals a Generic Netlink header to bytes, in the host byteorder.
func (Header) String ¶
String returns a string representation of the attribute header for debugging.
func (*Header) UnmarshalBinary ¶
UnmarshalBinary unmarshals a Generic Netlink header from bytes using the host byteorder.
It will ignore any additional bytes it is given.
type Op ¶ added in v1.0.0
Op is one of the Generic Netlink operations a Family has defined.
References:
- linux/include/uapi/linux/genetlink.h
func (*Op) UnmarshalAttributes ¶ added in v1.0.0
func (o *Op) UnmarshalAttributes(attrs *netlink.AttributeDecoder) error