ipset

package module
v2.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2021 License: MIT Imports: 8 Imported by: 0

README

go-ipset

CircleCI Codecov Go Report Card

Documentation

Index

Constants

View Source
const (

	// Message types and commands
	CmdProtocol messageType //  1: Return protocol version
	CmdCreate               //  2: Create a new (empty) set
	CmdDestroy              //  3: Destroy a (empty) set
	CmdFlush                //  4: Remove all elements from a set
	CmdRename               //  5: Rename a set
	CmdSwap                 //  6: Swap two sets
	CmdList                 //  7: List sets
	CmdSave                 //  8: Save sets
	CmdAdd                  //  9: Add an element to a set
	CmdDel                  // 10: Delete an element from a set
	CmdTest                 // 11: Test an element in a set
	CmdHeader               // 12: Get set header data only
	CmdType                 // 13: Get set type
)
View Source
const (
	SetAttrIPAddrIPV4 uint16
	SetAttrIPAddrIPV6
)
View Source
const (
	Protocol = 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributeType

type AttributeType int
const (

	// Attributes at command level
	AttrProtocol    AttributeType //  1: Protocol version
	AttrSetName                   //  2: Name of the set
	AttrTypeName                  //  3: Typename
	AttrRevision                  //  4: Settype revision
	AttrFamily                    //  5: Settype family
	AttrFlags                     //  6: Flags at command level
	AttrData                      //  7: Nested attributes
	AttrADT                       //  8: Multiple data containers
	AttrLineNo                    //  9: Restore lineno
	AttrProtocolMin               // 10: Minimal supported version number
	AttrMax

	AttrRevisionMin = AttrProtocolMin
	AttrSetName2    = AttrTypeName
)
const (

	// CADT specific attributes
	AttrIP         AttributeType //  1:
	AttrIPTo                     //  2:
	AttrCidr                     //  3:
	AttrPort                     //  4:
	AttrPortTo                   //  5:
	AttrTimeout                  //  6:
	AttrProto                    //  7:
	AttrCadtFlags                //  8:
	AttrCadtLineNo               //  9:
	AttrMark                     // 10:
	AttrMarkMask                 // 11:
	AttrCadtMax    = 16
)
const (

	// Create-only specific attributes.
	AttrGc       AttributeType // 17:
	AttrHashSize               // 18:
	AttrMaxElem                // 19:
	AttrNetmask                // 20:
	AttrProbes                 // 21:
	AttrResize                 // 22:
	AttrSize                   // 23:

	// Kernel-only
	AttrElements   // 24:
	AttrReferences // 25:
	AttrMemSize    // 26:
)
const (

	// ADT specific attributes
	AttrEther AttributeType
	AttrName
	AttrNameRef
	AttrIP2
	AttrCidr2
	AttrIP2To
	AttrIface
	AttrBytes
	AttrPackets
	AttrComment
	AttrSkbMark
	AttrSkbPrio
	AttrSkbQueue
)

type Attributes

type Attributes []netfilter.Attribute

type BasePolicy

type BasePolicy struct {
	Protocol *UInt8Box
}

type CadtFlags

type CadtFlags uint32
const (
	Before CadtFlags = 1 << iota
	PhysDev
	NoMatch
	WithCounters
	WithComment
	WithForceDdd
	WithSkbInfo
)

type CmdFlags

type CmdFlags uint32
const (
	FlagExist CmdFlags = 1 << iota
	FlagListSetName
	FlagListHeader
	FlagSkipCounterUpdate
	FlagSkipSubcounterUpdate
	FlagMatchCounters
	FlagReturnNoMatch
	FlagMapSkbMark
	FlagMapSkbPrio
	FlagMapSkbQueue
)

type Conn

type Conn struct {
	Family netfilter.ProtoFamily
	Conn   connector
}

Conn represents a Netlink connection to the Netfilter subsystem and implements all Ipset actions.

func Dial

func Dial(family netfilter.ProtoFamily, config *netlink.Config) (*Conn, error)

Dial opens a new Netfilter Netlink connection and returns it wrapped in a Conn structure that implements the Ipset API.

func (*Conn) Add

func (c *Conn) Add(name string, entries ...*Entry) error

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Create

func (c *Conn) Create(setName, typeName string, revision uint8, family netfilter.ProtoFamily, options ...CreateDataOption) error

Create creates a new set, returning an error if the set already exists.

func (*Conn) Delete

func (c *Conn) Delete(name string, entries ...*Entry) error

func (*Conn) Destroy

func (c *Conn) Destroy(name string) error

func (*Conn) DestroyAll

func (c *Conn) DestroyAll() error

func (*Conn) Flush

func (c *Conn) Flush(name string) error

func (*Conn) FlushAll

func (c *Conn) FlushAll() error

func (*Conn) Header

func (c *Conn) Header(name string) (p *HeaderPolicy, err error)

func (*Conn) ListAll

func (c *Conn) ListAll() ([]SetPolicy, error)

func (*Conn) ListHeader

func (c *Conn) ListHeader(name string) (*SetPolicy, error)

func (*Conn) Protocol

func (c *Conn) Protocol() (*ProtocolResponsePolicy, error)

func (*Conn) Rename

func (c *Conn) Rename(from, to string) error

func (*Conn) Replace

func (c *Conn) Replace(setName, typeName string, revision uint8, family netfilter.ProtoFamily, options ...CreateDataOption) error

Replace replaces a given set if it already exists, creating a new one otherwise.

func (*Conn) Swap

func (c *Conn) Swap(from, to string) error

func (*Conn) Test

func (c *Conn) Test(name string, options ...EntryOption) error

func (*Conn) Type

func (c *Conn) Type(name string, family netfilter.ProtoFamily) (*TypeResponsePolicy, error)

type CreateData

type CreateData struct {
	CadtFlags *NetUInt32Box
	HashSize  *NetUInt32Box
	MarkMask  *NetUInt32Box
	MaxElem   *NetUInt32Box
	NetMask   *UInt8Box
	Probes    *UInt8Box
	Proto     *UInt8Box
	Resize    *UInt8Box
	Size      *NetUInt32Box
	Timeout   *UInt32SecondsDurationBox

	// Kernel only (returned by List*)
	Elements   *UInt32Box
	References *UInt32Box
	MemSize    *UInt32Box
}

func (*CreateData) IsSet

func (d *CreateData) IsSet() bool

type CreateDataOption

type CreateDataOption func(d *CreateData)

func CreateDataCadtFlags

func CreateDataCadtFlags(v uint32) CreateDataOption

func CreateDataHashSize

func CreateDataHashSize(v uint32) CreateDataOption

func CreateDataMarkMask

func CreateDataMarkMask(v uint32) CreateDataOption

func CreateDataMaxElem

func CreateDataMaxElem(v uint32) CreateDataOption

func CreateDataNetMask

func CreateDataNetMask(v uint8) CreateDataOption

func CreateDataProbes

func CreateDataProbes(v uint8) CreateDataOption

func CreateDataProto

func CreateDataProto(v uint8) CreateDataOption

func CreateDataResize

func CreateDataResize(v uint8) CreateDataOption

func CreateDataSize

func CreateDataSize(v uint32) CreateDataOption

func CreateDataTimeout

func CreateDataTimeout(v time.Duration) CreateDataOption

type CreatePolicy

type CreatePolicy struct {
	HeaderPolicy

	Data *CreateData
}

type DumpPolicy added in v2.2.3

type DumpPolicy struct {
	NamePolicy *NamePolicy
	Flags      *UInt32Box
}

type Entries

type Entries []*Entry

func (Entries) IsSet

func (e Entries) IsSet() bool

type Entry

type Entry struct {
	Bytes     *NetUInt64Box
	CadtFlags *NetUInt32Box
	Cidr2     *UInt8Box
	Cidr      *UInt8Box
	Comment   *NullStringBox
	Ether     *HardwareAddrBox
	Iface     *NullStringBox
	IP2To     *IPAddrBox
	IP2       *IPAddrBox
	IPTo      *IPAddrBox
	IP        *IPAddrBox
	Lineno    *NetUInt32Box
	Mark      *NetUInt32Box
	Packets   *NetUInt64Box
	PortTo    *NetUInt16Box
	Port      *NetUInt16Box
	Proto     *UInt8Box
	Skbmark   *NetUInt64Box
	Skbprio   *NetUInt32Box
	Skbqueue  *NetUInt16Box
	Timeout   *UInt32SecondsDurationBox
}

func NewEntry

func NewEntry(setters ...EntryOption) *Entry

func (*Entry) IsSet

func (e *Entry) IsSet() bool

type EntryAddDelPolicy

type EntryAddDelPolicy struct {
	NamePolicy

	LineNo *NetUInt32Box

	Entries Entries
}

type EntryOption

type EntryOption func(*Entry)

func EntryBytes

func EntryBytes(v uint64) EntryOption

func EntryCadtFlags

func EntryCadtFlags(v uint32) EntryOption

func EntryCidr

func EntryCidr(v uint8) EntryOption

func EntryCidr2

func EntryCidr2(v uint8) EntryOption

func EntryComment

func EntryComment(v string) EntryOption

func EntryEther

func EntryEther(v net.HardwareAddr) EntryOption

func EntryIP

func EntryIP(v net.IP) EntryOption

func EntryIP2

func EntryIP2(v net.IP) EntryOption

func EntryIP2To

func EntryIP2To(v net.IP) EntryOption

func EntryIPTo

func EntryIPTo(v net.IP) EntryOption

func EntryIface

func EntryIface(v string) EntryOption

func EntryLineno

func EntryLineno(v uint32) EntryOption

func EntryMark

func EntryMark(v uint32) EntryOption

func EntryPackets

func EntryPackets(v uint64) EntryOption

func EntryPort

func EntryPort(v uint16) EntryOption

func EntryPortTo

func EntryPortTo(v uint16) EntryOption

func EntryProto

func EntryProto(v uint8) EntryOption

func EntrySkbMark

func EntrySkbMark(v uint64) EntryOption

func EntrySkbPrio

func EntrySkbPrio(v uint32) EntryOption

func EntrySkbQueue

func EntrySkbQueue(v uint16) EntryOption

func EntryTimeout

func EntryTimeout(v time.Duration) EntryOption

type HardwareAddrBox

type HardwareAddrBox struct{ Value net.HardwareAddr }

Hardware Address

func NewHardwareAddrBox

func NewHardwareAddrBox(v net.HardwareAddr) *HardwareAddrBox

func (*HardwareAddrBox) Get

func (b *HardwareAddrBox) Get() net.HardwareAddr

func (*HardwareAddrBox) IsSet

func (b *HardwareAddrBox) IsSet() bool

type HeaderPolicy

type HeaderPolicy struct {
	NamePolicy

	TypeName *NullStringBox
	Revision *UInt8Box
	Family   *UInt8Box
}

type IPAddrBox

type IPAddrBox struct{ Value net.IP }

IP Address

func NewIPAddrBox

func NewIPAddrBox(v net.IP) *IPAddrBox

func (*IPAddrBox) Get

func (b *IPAddrBox) Get() net.IP

func (*IPAddrBox) IsSet

func (b *IPAddrBox) IsSet() bool

type MovePolicy

type MovePolicy struct {
	NamePolicy

	To *NullStringBox
}

type NamePolicy

type NamePolicy struct {
	BasePolicy

	Name *NullStringBox
}

type NetUInt16Box added in v2.2.5

type NetUInt16Box struct{ UInt16Box }

Uint16 in Network Byte Order

func NewNetUInt16Box added in v2.2.5

func NewNetUInt16Box(v uint16) *NetUInt16Box

func (*NetUInt16Box) IsSet added in v2.2.5

func (b *NetUInt16Box) IsSet() bool

type NetUInt32Box

type NetUInt32Box struct{ UInt32Box }

Uint32 in Network Byte Order

func NewNetUInt32Box

func NewNetUInt32Box(v uint32) *NetUInt32Box

func (*NetUInt32Box) IsSet

func (b *NetUInt32Box) IsSet() bool

type NetUInt64Box added in v2.2.5

type NetUInt64Box struct{ UInt64Box }

Uint64 in Network Byte Order

func NewNetUInt64Box added in v2.2.5

func NewNetUInt64Box(v uint64) *NetUInt64Box

func (*NetUInt64Box) IsSet added in v2.2.5

func (b *NetUInt64Box) IsSet() bool

type NullStringBox

type NullStringBox struct{ Value string }

Null-Byte terminated string

func NewNullStringBox

func NewNullStringBox(v string) *NullStringBox

func (*NullStringBox) Get

func (b *NullStringBox) Get() string

func (*NullStringBox) IsSet

func (b *NullStringBox) IsSet() bool

func (*NullStringBox) String

func (b *NullStringBox) String() string

type ProtocolResponsePolicy

type ProtocolResponsePolicy struct {
	BasePolicy

	ProtocolMin *UInt8Box
}

type SetPolicy

type SetPolicy struct {
	HeaderPolicy
	CreateData *CreateData

	Entries Entries
}

type TestPolicy

type TestPolicy struct {
	NamePolicy

	Entry *Entry
}

type TypePolicy

type TypePolicy struct {
	BasePolicy

	TypeName *NullStringBox
	Family   *UInt8Box
}

type TypeResponsePolicy

type TypeResponsePolicy struct {
	TypePolicy

	Revision    *UInt8Box
	RevisionMin *UInt8Box
}

type UInt16Box

type UInt16Box struct{ Value uint16 }

Uint16

func NewUInt16Box

func NewUInt16Box(v uint16) *UInt16Box

func (*UInt16Box) Get

func (b *UInt16Box) Get() uint16

func (*UInt16Box) IsSet

func (b *UInt16Box) IsSet() bool

func (*UInt16Box) String

func (b *UInt16Box) String() string

type UInt32Box

type UInt32Box struct{ Value uint32 }

Uint32

func NewUInt32Box

func NewUInt32Box(v uint32) *UInt32Box

func (*UInt32Box) Get

func (b *UInt32Box) Get() uint32

func (*UInt32Box) IsSet

func (b *UInt32Box) IsSet() bool

func (*UInt32Box) String

func (b *UInt32Box) String() string

type UInt32SecondsDurationBox

type UInt32SecondsDurationBox struct{ time.Duration }

UInt32SecondsDurationBox implements a netlink field that stores a duration in seconds with network byte order and 32bit width.

func NewUInt32SecondsDurationBox

func NewUInt32SecondsDurationBox(d time.Duration) *UInt32SecondsDurationBox

func (*UInt32SecondsDurationBox) Get

func (*UInt32SecondsDurationBox) IsSet

func (b *UInt32SecondsDurationBox) IsSet() bool

type UInt64Box

type UInt64Box struct{ Value uint64 }

Uint64

func NewUInt64Box

func NewUInt64Box(v uint64) *UInt64Box

func (*UInt64Box) Get

func (b *UInt64Box) Get() uint64

func (*UInt64Box) IsSet

func (b *UInt64Box) IsSet() bool

func (*UInt64Box) String

func (b *UInt64Box) String() string

type UInt8Box

type UInt8Box struct{ Value uint8 }

Uint8

func NewUInt8Box

func NewUInt8Box(v uint8) *UInt8Box

func (*UInt8Box) Get

func (b *UInt8Box) Get() uint8

func (*UInt8Box) IsSet

func (b *UInt8Box) IsSet() bool

func (*UInt8Box) String

func (b *UInt8Box) String() string

Jump to

Keyboard shortcuts

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