set

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package set A library for managing IP and port nftables sets

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateElements

func GenerateElements(keyType nftables.SetDatatype, list []SetData) ([]nftables.SetElement, error)

func GenerateElementsFromIPv4Address

func GenerateElementsFromIPv4Address(ipAddresses []string, timeout ...time.Duration) ([]nftables.SetElement, error)

func GenerateElementsFromIPv6Address

func GenerateElementsFromIPv6Address(ipAddresses []string, timeout ...time.Duration) ([]nftables.SetElement, error)

func GenerateElementsFromPort

func GenerateElementsFromPort(ports []string, timeout ...time.Duration) ([]nftables.SetElement, error)

func NetipAddrPortToSetData

func NetipAddrPortToSetData(addrport netip.AddrPort, timeout ...time.Duration) (SetData, SetData, error)

Convert netip.AddrPort to SetData type, returns a address and a port

func NetipAddrPortsToSetData

func NetipAddrPortsToSetData(addrports []netip.AddrPort, timeout ...time.Duration) ([]SetData, []SetData, error)

Convert a list of netip.AddrPort to SetData type, returns a list of addresses and a list of ports

Types

type Set

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

Set represents an nftables a set on a given table

func New

func New(c *nftables.Conn, table *nftables.Table, name string, keyType nftables.SetDatatype) (Set, error)

Create a new set on a table with a given key type

func (*Set) ClearAndAddElements

func (s *Set) ClearAndAddElements(c *nftables.Conn, newSetData []SetData) error

Remove all elements from the set and then add a list of elements

func (*Set) GetSet

func (s *Set) GetSet() *nftables.Set

Get the nftables set associated with this Set

func (*Set) UpdateElements

func (s *Set) UpdateElements(c *nftables.Conn, newSetData []SetData) (bool, int, int, error)

Compares incoming set elements with existing set elements and adds/removes the differences.

First return value is true if the set was modified, false if there were no updates. The second and third return values indicate the number of values added and removed from the set, respectively.

type SetData

type SetData struct {
	Port              uint16
	PortRangeStart    uint16
	PortRangeEnd      uint16
	Address           netip.Addr
	AddressRangeStart netip.Addr
	AddressRangeEnd   netip.Addr
	Prefix            netip.Prefix
	Timeout           time.Duration
}

SetData is a struct that is used to create elements of a given set based on the key type of the set

func AddressRangeStringToSetData

func AddressRangeStringToSetData(startString string, endString string, timeout ...time.Duration) (SetData, error)

Convert a string address range to the SetData type

func AddressStringToSetData

func AddressStringToSetData(addressString string, timeout ...time.Duration) (SetData, error)

Convert a string address to the SetData type

func AddressStringsToSetData

func AddressStringsToSetData(addressStrings []string, timeout ...time.Duration) ([]SetData, error)

Convert a list of string addresses to the SetData type

func NetIPNetToSetData

func NetIPNetToSetData(net *net.IPNet, timeout ...time.Duration) (SetData, error)

Convert net.IPNet to the SetData type

func NetIPNetsToSetData

func NetIPNetsToSetData(nets []*net.IPNet, timeout ...time.Duration) ([]SetData, error)

Convert a list of net.IPNet to the SetData type

func NetIPToSetData

func NetIPToSetData(ip net.IP, timeout ...time.Duration) (SetData, error)

Convert net.IP to the SetData type

func NetIPsToSetData

func NetIPsToSetData(ips []net.IP, timeout ...time.Duration) ([]SetData, error)

Convert a list of net.IP to the SetData type

func NetipAddrToSetData

func NetipAddrToSetData(ip netip.Addr, timeout ...time.Duration) (SetData, error)

Convert netip.Addr to SetData type

func NetipAddrsToSetData

func NetipAddrsToSetData(ips []netip.Addr, timeout ...time.Duration) ([]SetData, error)

Convert a list of netip.Addr to SetData type

func NetipPrefixToSetData

func NetipPrefixToSetData(prefix netip.Prefix, timeout ...time.Duration) (SetData, error)

Convert netip.Prefix to SetData type

func NetipPrefixesToSetData

func NetipPrefixesToSetData(prefixes []netip.Prefix, timeout ...time.Duration) ([]SetData, error)

Convert a list of netip.Prefix to SetData type

func PortRangeStringToSetData

func PortRangeStringToSetData(startString string, endString string, timeout ...time.Duration) (SetData, error)

Convert a string port range to the SetData type

func PortStringToSetData

func PortStringToSetData(portString string, timeout ...time.Duration) (SetData, error)

Convert a string port to the SetData type

func PortStringsToSetData

func PortStringsToSetData(portStrings []string, timeout ...time.Duration) ([]SetData, error)

Convert a list string ports to the SetData type

func PrefixStringToSetData

func PrefixStringToSetData(prefixString string, timeout ...time.Duration) (SetData, error)

Convert a string prefix/CIDR to the SetData type

Jump to

Keyboard shortcuts

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