Documentation
¶
Index ¶
- Variables
- func CIDRsToPrefix(cidrs string) []netip.Prefix
- func EncodeWithAlignment(data any) []byte
- func FirstAndNextSubnetAddr(subnet netip.Prefix) (first, next netip.Addr, err error)
- func SetChecksumOffloading(ifName string, rxOn, txOn bool) error
- func SplitCIDRs(cidrs string) ([]string, []string)
- func SplitCIDRslice(cidrs []string) ([]string, []string)
- func TopLevelPrefixes(prefixes []netip.Prefix) ([]netip.Prefix, []netip.Prefix)
- type Packet
- type Tree
- func (t *Tree[T]) DeletePrefix(prefix netip.Prefix) bool
- func (t *Tree[T]) DepthFirstWalk(isIPv6 bool, fn WalkFn[T])
- func (t *Tree[T]) GetHostIPPrefixMatches(ip netip.Addr) map[netip.Prefix]T
- func (t *Tree[T]) GetPrefix(prefix netip.Prefix) (T, bool)
- func (t *Tree[T]) InsertPrefix(prefix netip.Prefix, v T) bool
- func (t *Tree[T]) Len(isV6 bool) int
- func (t *Tree[T]) LongestPrefixMatch(prefix netip.Prefix) (netip.Prefix, T, bool)
- func (t *Tree[T]) ShortestPrefixMatch(prefix netip.Prefix) (netip.Prefix, T, bool)
- func (t *Tree[T]) TopLevelPrefixes(isIPv6 bool) map[netip.Prefix]T
- func (t *Tree[T]) WalkPath(path netip.Prefix, fn WalkFn[T])
- func (t *Tree[T]) WalkPrefix(prefix netip.Prefix, fn WalkFn[T])
- type WalkFn
Constants ¶
This section is empty.
Variables ¶
var ErrorCorrupted = fmt.Errorf("packet corrupted")
var ErrorTooShort = fmt.Errorf("packet too short")
Functions ¶
func CIDRsToPrefix ¶ added in v1.8.2
CIDRsToPrefix given a comma separated list with CIDRS it returns a slice of netip.Prefixes and remove duplicates
func EncodeWithAlignment ¶ added in v1.8.1
func FirstAndNextSubnetAddr ¶ added in v1.8.1
FirstAndNextSubnetAddr takes the beginning address of an entire network in CIDR notation (e.g. 192.168.1.0/24) and returns the first addresses within the network and the first address of the next network (e.g. first 192.168.1.0, next 192.168.2.0).
Note: nftables needs half-open intervals [firstIP, lastIP) for prefixes e.g. 10.0.0.0/24 becomes [10.0.0.0, 10.0.1.0), 10.1.1.1/32 becomes [10.1.1.1, 10.1.1.2) etc
func SetChecksumOffloading ¶
SetChecksumOffloading enables/disables Rx/Tx checksum offloading for the given interface.
func SplitCIDRs ¶
SplitCIDRs given a comma separated list with CIDRS it returns 2 slice of strings per IP family
func SplitCIDRslice ¶
Types ¶
type Packet ¶ added in v1.8.1
type Packet struct {
ID uint32
Family v1.IPFamily
SrcIP net.IP
DstIP net.IP
Proto v1.Protocol
SrcPort int
DstPort int
Payload []byte
}
func ParsePacket ¶ added in v1.8.1
https://en.wikipedia.org/wiki/Internet_Protocol_version_4#Packet_structure https://en.wikipedia.org/wiki/IPv6_packet https://github.com/golang/net/blob/master/ipv4/header.go
func (Packet) MarshalLog ¶ added in v1.8.1
This function is used for JSON output (interface logr.Marshaler)
type Tree ¶ added in v1.8.2
type Tree[T any] struct { // contains filtered or unexported fields }
Tree is a radix tree for IPv4 and IPv6 networks.
func (*Tree[T]) DeletePrefix ¶ added in v1.8.2
DeletePrefix delete the exact prefix and return true if it existed.
func (*Tree[T]) DepthFirstWalk ¶ added in v1.8.2
DepthFirstWalk is used to walk the tree of the corresponding IP family
func (*Tree[T]) GetHostIPPrefixMatches ¶ added in v1.8.2
GetHostIPPrefixMatches returns the list of prefixes that contain the specified Host IP. An IP is considered a Host IP if is within the subnet range and is not the network address or, if IPv4, the broadcast address (RFC 1878).
func (*Tree[T]) GetPrefix ¶ added in v1.8.2
GetPrefix returns the stored value and true if the exact prefix exists in the tree.
func (*Tree[T]) InsertPrefix ¶ added in v1.8.2
InsertPrefix is used to add a new entry or update an existing entry. Returns true if updated.
func (*Tree[T]) LongestPrefixMatch ¶ added in v1.8.2
LongestPrefixMatch returns the longest prefix match, the stored value and true if exist. For example, considering the following prefixes 192.168.20.16/28 and 192.168.0.0/16, when the address 192.168.20.19/32 is looked up it will return 192.168.20.16/28.
func (*Tree[T]) ShortestPrefixMatch ¶ added in v1.8.2
ShortestPrefixMatch returns the shortest prefix match, the stored value and true if exist. For example, considering the following prefixes 192.168.20.16/28 and 192.168.0.0/16, when the address 192.168.20.19/32 is looked up it will return 192.168.0.0/16.
func (*Tree[T]) TopLevelPrefixes ¶ added in v1.8.2
TopLevelPrefixes is used to return a map with all the Top Level prefixes from the corresponding IP family and its values. For example, if the tree contains entries for 10.0.0.0/8, 10.1.0.0/16, and 192.168.0.0/16, this will return 10.0.0.0/8 and 192.168.0.0/16.