netlink

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPSET_CMD_CREATE  = 2
	IPSET_CMD_DESTROY = 3
	IPSET_CMD_FLUSH   = 4
	IPSET_CMD_ADD     = 9
	IPSET_CMD_DEL     = 10
)

Message types and commands.

View Source
const (
	IPSET_ATTR_PROTOCOL = 1 /* 1: Protocol version */
	IPSET_ATTR_SETNAME  = 2 /* 2: Name of the set */
	IPSET_ATTR_TYPENAME = 3 /* 3: Typename */
	IPSET_ATTR_REVISION = 4 /* 4: Settype revision */
	IPSET_ATTR_FAMILY   = 5 /* 5: Settype family */
	IPSET_ATTR_DATA     = 7 /* 7: Nested attributes */
)

Attributes at command level.

View Source
const (
	IPSET_ATTR_IP      = 1
	IPSET_ATTR_CIDR    = 3
	IPSET_ATTR_TIMEOUT = 6
)

CADT specific attributes.

View Source
const (
	IPSET_ATTR_IPADDR_IPV4 = 1
	IPSET_ATTR_IPADDR_IPV6 = 2
)

IP specific attributes.

View Source
const (
	NLA_F_NESTED        = (1 << 15)
	NLA_F_NET_BYTEORDER = (1 << 14)
)

ATTR flags.

View Source
const IPSET_MAXNAMELEN = 32

IPSET_MAXNAMELEN is the max length of strings including NUL: set and type identifiers.

View Source
const IPSET_PROTOCOL = 6

IPSET_PROTOCOL is the protocol version. http://git.netfilter.org/ipset/tree/include/libipset/linux_ip_set.h

View Source
const NFNL_SUBSYS_IPSET = 6

NFNL_SUBSYS_IPSET is netfilter netlink message type of ipset. https://github.com/torvalds/linux/blob/9e66317d3c92ddaab330c125dfe9d06eee268aff/include/uapi/linux/netfilter/nfnetlink.h#L56

Variables

This section is empty.

Functions

func NativeEndian

func NativeEndian() binary.ByteOrder

NativeEndian get native endianness for the system

func Uint16Attr

func Uint16Attr(v uint16) []byte

Uint16Attr .

func Uint32Attr

func Uint32Attr(v uint32) []byte

Uint32Attr .

func Uint8Attr

func Uint8Attr(v uint8) []byte

Uint8Attr .

func ZeroTerminated

func ZeroTerminated(s string) []byte

ZeroTerminated .

Types

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

NetLink struct.

func New

func New() (*NetLink, error)

New returns a new netlink socket.

func (*NetLink) CreateSet

func (nl *NetLink) CreateSet(setName string, opts ...Option) error

CreateSet create a ipset.

func (*NetLink) DestroySet added in v0.3.0

func (nl *NetLink) DestroySet(setName string) error

DestroySet destroys a ipset.

func (*NetLink) FlushSet

func (nl *NetLink) FlushSet(setName string) error

FlushSet flush a ipset.

func (*NetLink) HandleAddr added in v0.5.0

func (nl *NetLink) HandleAddr(cmd int, setName string, ip netip.Addr, cidr netip.Prefix, opts ...Option) error

type NetlinkRequest

type NetlinkRequest struct {
	syscall.NlMsghdr
	Data    []NetlinkRequestData
	RawData []byte
}

NetlinkRequest is a netlink request.

func NewNetlinkRequest

func NewNetlinkRequest(proto, flags int) *NetlinkRequest

NewNetlinkRequest create a new netlink request from proto and flags Note the Len value will be inaccurate once data is added until the message is serialized.

func (*NetlinkRequest) AddData

func (req *NetlinkRequest) AddData(data NetlinkRequestData)

AddData add data to request.

func (*NetlinkRequest) AddRawData

func (req *NetlinkRequest) AddRawData(data []byte)

AddRawData adds raw bytes to the end of the NetlinkRequest object during serialization.

func (*NetlinkRequest) Serialize

func (req *NetlinkRequest) Serialize() []byte

Serialize the Netlink Request into a byte array.

type NetlinkRequestData

type NetlinkRequestData interface {
	Len() int
	Serialize() []byte
}

NetlinkRequestData interface.

type NfGenMsg

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

NfGenMsg struct.

func NewNfGenMsg

func NewNfGenMsg(nfgenFamily, version, resID int) *NfGenMsg

NewNfGenMsg returns a new NfGenMsg.

func (*NfGenMsg) Len

func (m *NfGenMsg) Len() int

Len returns the length.

func (*NfGenMsg) Serialize

func (m *NfGenMsg) Serialize() []byte

Serialize serializes NfGenMsg to bytes.

type Option added in v0.4.0

type Option func(opts *Options)

Netlink Option func parameter

type Options added in v0.4.0

type Options struct {
	IPv6    bool
	Timeout uint32
}

Netlink Options

type RtAttr

type RtAttr struct {
	syscall.RtAttr
	Data []byte
	// contains filtered or unexported fields
}

RtAttr Extend RtAttr to handle data and children.

func NewRtAttr

func NewRtAttr(attrType int, data []byte) *RtAttr

NewRtAttr Create a new Extended RtAttr object.

func NewRtAttrChild

func NewRtAttrChild(parent *RtAttr, attrType int, data []byte) *RtAttr

NewRtAttrChild Create a new RtAttr obj anc add it as a child of an existing object.

func (*RtAttr) AddChild added in v0.4.0

func (a *RtAttr) AddChild(attr NetlinkRequestData)

AddChild adds an existing NetlinkRequestData as a child.

func (*RtAttr) Len

func (a *RtAttr) Len() int

Len returns the length of RtAttr.

func (*RtAttr) Serialize

func (a *RtAttr) Serialize() []byte

Serialize the RtAttr into a byte array. This can't just unsafe.cast because it must iterate through children.

type Uint32Attribute added in v0.4.0

type Uint32Attribute struct {
	Type  uint16
	Value uint32
}

Uint32Attribute .

func (*Uint32Attribute) Len added in v0.4.0

func (a *Uint32Attribute) Len() int

Len .

func (*Uint32Attribute) Serialize added in v0.4.0

func (a *Uint32Attribute) Serialize() []byte

Serialize .

Jump to

Keyboard shortcuts

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