Documentation ¶
Index ¶
- Constants
- func Align(pos int) int
- func GetAttributeCString(af AttributeFinder, at AttributeType) (out string, err error)
- func GetAttributeString(af AttributeFinder, at AttributeType) (out string, err error)
- func GetAttributeUint32(af AttributeFinder, at AttributeType) (out uint32, err error)
- func MarshalAttributes(in []Attribute) (out []byte, err error)
- func Padded(in []byte) (out []byte)
- func SetAttributeCString(aw AttributeWriter, at AttributeType, s string)
- type Address
- type Attribute
- type AttributeFinder
- type AttributeType
- type AttributeWriter
- type Error
- type Handler
- type Header
- func (self Header) Len() int
- func (self Header) MarshalNetlink() (out []byte, err error)
- func (self Header) MessageFlags() MessageFlags
- func (self Header) MessageLength() uint32
- func (self Header) MessagePid() uint32
- func (self Header) MessageSequence() uint32
- func (self Header) MessageType() MessageType
- func (self *Header) SetMessageLength(in uint32)
- func (self *Header) SetMessageSequence(in uint32)
- func (self *Header) UnmarshalNetlink(in []byte) (err error)
- type Message
- type MessageFlags
- type MessageType
- type NetlinkFamily
- type NetlinkMarshaler
- type Socket
Constants ¶
const ( ALIGN_MINUS_ONE = 3 NOT_ALIGN_MINUS_ONE = ^3 )
Copyright (c) 2011, Abneptis LLC. All rights reserved. Copyright (c) 2013, Vishvananda Ishaya. All rights reserved. Original Author: James D. Nurmi <james@abneptis.com>
See LICENSE for details
const ERROR_LENGTH = HEADER_LENGTH + 4
Unlike other headers, errors MAY be longer than the minimum length.
const HEADER_LENGTH = 16
Variables ¶
This section is empty.
Functions ¶
func GetAttributeCString ¶
func GetAttributeCString(af AttributeFinder, at AttributeType) (out string, err error)
Same as GetAttributeString, but expects the string to be NULL terminated, the null terminator will be stripped..
func GetAttributeString ¶
func GetAttributeString(af AttributeFinder, at AttributeType) (out string, err error)
Gets an attribute value as a string. Note, for much of RTNetlink, you want GetAttributeCString, which will verify and chop the tailing NULL.
func GetAttributeUint32 ¶
func GetAttributeUint32(af AttributeFinder, at AttributeType) (out uint32, err error)
Returns the attribute as an uint32 (or an error if the attr size is not 32 bits.
func MarshalAttributes ¶
Returns the bytes of a marshalled list of attributes. Any marshalling error will cause the sequence to abort.
func SetAttributeCString ¶
func SetAttributeCString(aw AttributeWriter, at AttributeType, s string)
Sets the attribute value to the string specified by 's'.
s will be NULL terminated.
Types ¶
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
Implements net.Addr for netlink addresses.
type Attribute ¶
type Attribute struct { Type AttributeType Body []byte }
An attribute is used to hold an Netlink Attribute. An attribute is stored as a Length-Type-Value tuple. Length and Type are 16 bit integers, so values may not exceed 2^16.
func UnmarshalAttributes ¶
Unmarshals a netlink attribute.
func (Attribute) MarshalNetlink ¶
Marshals a netlink attribute as a full LTV tuple.
type AttributeFinder ¶
type AttributeFinder interface {
GetAttribute(AttributeType) (Attribute, error)
}
The attributeFinder interface should be used by READERS, Writers will need to use an AttributeWriter
type AttributeType ¶
type AttributeType uint16
A basic netlink type used for identifying nlattrs in a message.
type AttributeWriter ¶
type AttributeWriter interface {
SetAttribute(Attribute)
}
AttributeWriters allow attributes to be added/updated.
type Error ¶
type Error [ERROR_LENGTH]byte
Represents a netlink Error message.
func (Error) MarshalNetlink ¶
Marshals an error to the wire.
func (*Error) UnmarshalNetlink ¶
Unmarshals an error from a netlink message.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
A handler implements a simple Mux for netlink messages, ensuring each query gets a unique sequence number and a channel to collect responses.
func NewHandler ¶
func (*Handler) Query ¶
Send a message. If SequenceNumber is unset, Seq() will be used to generate one.
type Header ¶
type Header [HEADER_LENGTH]byte
Represents the header of a netlink.Message
func NewHeader ¶
func NewHeader(t MessageType, f MessageFlags, seq uint32) (h *Header)
func (Header) MarshalNetlink ¶
func (Header) MessageFlags ¶
func (self Header) MessageFlags() MessageFlags
func (Header) MessageLength ¶
func (Header) MessagePid ¶
func (Header) MessageSequence ¶
func (Header) MessageType ¶
func (self Header) MessageType() MessageType
func (*Header) SetMessageLength ¶
func (*Header) SetMessageSequence ¶
func (*Header) UnmarshalNetlink ¶
type Message ¶
A netlink message contains a Netlink header, and a body of bytes.
func NewMessage ¶
func NewMessage(t MessageType, f MessageFlags, u NetlinkMarshaler) (msg *Message, err error)
Creates a new message from a marshalable object
func ReadMessage ¶
Reads a message from an io.Reader, with attributes alinged to 4 bytes. NB: Netlink uses a very strict protocol, and it is encouraged that r be a bufio.Reader
func (Message) MarshalNetlink ¶
Marshals a message with aligned attributes..
type MessageFlags ¶
type MessageFlags uint16
const ( NLM_F_REQUEST MessageFlags = 1 << iota NLM_F_MULTI NLM_F_ACK NLM_F_ECHO )
include/linux/netlink.h ALL
const ( NLM_F_ROOT MessageFlags = 0x100 << iota NLM_F_MATCH NLM_F_ATOMIC NLM_F_DUMP MessageFlags = (NLM_F_ROOT | NLM_F_MATCH) )
Valid on Queries
const ( NLM_F_REPLACE MessageFlags = 0x100 << iota NLM_F_EXCL NLM_F_CREATE NLM_F_APPEND )
Valid on Updates
type MessageType ¶
type MessageType uint16
The MessageType consists of 5 fixed "Netlink" types that indicate message flow. All messageTypes above MIN_TYPE should be considered the 'property' of the individual netlink socket family.
const ( NLMSG_UNSPECIFIED MessageType = iota NLMSG_NOOP NLMSG_ERROR NLMSG_DONE NLMSG_OVERRUN MIN_TYPE = 0x10 )
include/linux/netlink.h
type NetlinkFamily ¶
type NetlinkFamily uint16 //?
const ( NETLINK_ROUTE NetlinkFamily = iota NETLINK_UNUSED NETLINK_USERSOCK NETLINK_FIREWALL NETLINK_INET_DIAG NETLINK_NFLOG NETLINK_XFRM NETLINK_SELINUX NETLINK_ISCSI NETLINK_AUDIT NETLINK_FIB_LOOKUP NETLINK_CONNECTOR NETLINK_NETFILTER NETLINK_IP6_FW NETLINK_DNRTMSG NETLINK_KOBJECT_UEVENT NETLINK_GENERIC NETLINK_RESERVED16 // WTF is NETLINK_DM ? NETLINK_SCSITRANSPORT NETLINK_ECRYPTFS )
The netlinkFamily is used for dialing a netlink socket. A single socket can only be bound to a single family, and thus a single Handler.
type NetlinkMarshaler ¶
NetlinkMarshaler's are used to format netlink data.
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
A netlink.Socket implements the lowest level of netlink communications.
func Dial ¶
func Dial(nlf NetlinkFamily) (rwc *Socket, err error)
Dials a netlink socket. Usually you do not need permissions for this, though specific commands may be rejected.