nat

package
v0.0.0-...-21cfbab Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NATFlgExternalLocal = 0x1
	NATFlgInternalLocal = 0x2
)
View Source
const BlackHoleCount uint32 = 0xffffffff
View Source
const ZeroCIDRPrefixLen = 56

(sizeof(addr) + sizeof(port) + sizeof(proto)) in bits

Variables

View Source
var AffinityMapParameters = maps.MapParameters{
	Type:       "lru_hash",
	KeySize:    affinityKeySize,
	ValueSize:  affinityValueSize,
	MaxEntries: 64 * 1024,
	Name:       "cali_v4_nat_aff",
}

AffinityMapParameters describe the AffinityMap

View Source
var BackendMapParameters = maps.MapParameters{
	Type:       "hash",
	KeySize:    backendKeySize,
	ValueSize:  backendValueSize,
	MaxEntries: 256 * 1024,
	Name:       "cali_v4_nat_be",
	Flags:      unix.BPF_F_NO_PREALLOC,
}
View Source
var CTNATsMapParameters = maps.MapParameters{
	Type:       "lru_hash",
	KeySize:    ctNATsMsgKeySize,
	ValueSize:  sendRecvMsgValueSize,
	MaxEntries: 10000,
	Name:       "cali_v4_ct_nats",
}
View Source
var FrontendMapParameters = maps.MapParameters{
	Type:       "lpm_trie",
	KeySize:    frontendKeySize,
	ValueSize:  frontendValueSize,
	MaxEntries: 64 * 1024,
	Name:       "cali_v4_nat_fe",
	Flags:      unix.BPF_F_NO_PREALLOC,
	Version:    3,
}
View Source
var SendRecvMsgMapParameters = maps.MapParameters{
	Type:       "lru_hash",
	KeySize:    sendRecvMsgKeySize,
	ValueSize:  sendRecvMsgValueSize,
	MaxEntries: 510000,
	Name:       "cali_v4_srmsg",
}

SendRecvMsgMapParameters define SendRecvMsgMap

View Source
var ZeroCIDR = ip.MustParseCIDROrIP("0.0.0.0/0").(ip.V4CIDR)

Functions

func AffinityMap

func AffinityMap() maps.Map

AffinityMap returns an instance of an affinity map

func AffinityMapMemIter

func AffinityMapMemIter(m AffinityMapMem) func(k, v []byte)

AffinityMapMemIter returns maps.MapIter that loads the provided AffinityMapMem

func AllNATsMsgMap

func AllNATsMsgMap() maps.Map

func BackendMap

func BackendMap() maps.MapWithExistsCheck

func BackendMapMemIter

func BackendMapMemIter(m BackendMapMem) func(k, v []byte)

BackendMapMemIter returns maps.MapIter that loads the provided NATBackendMapMem

func FrontendMap

func FrontendMap() maps.MapWithExistsCheck

func InstallConnectTimeLoadBalancer

func InstallConnectTimeLoadBalancer(cgroupv2 string, logLevel string, udpNotSeen time.Duration, excludeUDP bool) error

func MapMemIter

func MapMemIter(m MapMem) func(k, v []byte)

MapMemIter returns maps.MapIter that loads the provided NATMapMem

func ProgFileName

func ProgFileName(logLevel string, ipver int) string

func RemoveConnectTimeLoadBalancer

func RemoveConnectTimeLoadBalancer(cgroupv2 string) error

func SendRecvMsgMap

func SendRecvMsgMap() maps.Map

SendRecvMsgMap tracks reverse translations for sendmsg/recvmsg of unconnected UDP

func SendRecvMsgMapMemIter

func SendRecvMsgMapMemIter(m SendRecvMsgMapMem) func(k, v []byte)

SendRecvMsgMapMemIter returns maps.MapIter that loads the provided SendRecvMsgMapMem

func SetMapSizes

func SetMapSizes(fsize, bsize, asize int)

Types

type AffinityKey

type AffinityKey [affinityKeySize]byte

AffinityKey is a key into the affinity table that consist of FrontendKey and the client's IP

func NewAffinityKey

func NewAffinityKey(clientIP net.IP, fEndKey FrontendKey) AffinityKey

NewAffinityKey create a new AffinityKey from a clientIP and FrontendKey

func (AffinityKey) AsBytes

func (k AffinityKey) AsBytes() []byte

AsBytes returns the key as []byte

func (AffinityKey) ClientIP

func (k AffinityKey) ClientIP() net.IP

ClientIP returns the ClientIP part of the key

func (AffinityKey) FrontendAffinityKey

func (k AffinityKey) FrontendAffinityKey() FrontEndAffinityKey

FrontendKey returns the FrontendKey part of the key

func (AffinityKey) String

func (k AffinityKey) String() string

type AffinityMapMem

type AffinityMapMem map[AffinityKey]AffinityValue

AffinityMapMem represents affinity map in memory

func LoadAffinityMap

func LoadAffinityMap(m maps.Map) (AffinityMapMem, error)

LoadAffinityMap loads affinity map into memory

type AffinityValue

type AffinityValue [affinityValueSize]byte

AffinityValue represents a backend picked by the affinity and the timestamp of its creating

func NewAffinityValue

func NewAffinityValue(ts uint64, backend BackendValue) AffinityValue

NewAffinityValue creates a value from a timestamp and a backend

func (AffinityValue) AsBytes

func (v AffinityValue) AsBytes() []byte

AsBytes returns the value as []byte

func (AffinityValue) Backend

func (v AffinityValue) Backend() BackendValue

Backend returns the backend the affinity ties the frontend + client to.

func (AffinityValue) String

func (v AffinityValue) String() string

func (AffinityValue) Timestamp

func (v AffinityValue) Timestamp() time.Duration

Timestamp returns the timestamp of the entry. It is generated by bpf_ktime_get_ns which returns the time since the system boot in nanoseconds - it is the monotonic clock reading, which is compatible with time operations in time package.

type BackendKey

type BackendKey [backendKeySize]byte

func BackendKeyFromBytes

func BackendKeyFromBytes(b []byte) BackendKey

func NewNATBackendKey

func NewNATBackendKey(id, ordinal uint32) BackendKey

func (BackendKey) AsBytes

func (k BackendKey) AsBytes() []byte

func (BackendKey) Count

func (v BackendKey) Count() uint32

func (BackendKey) ID

func (v BackendKey) ID() uint32

func (BackendKey) String

func (v BackendKey) String() string

type BackendMapMem

type BackendMapMem map[BackendKey]BackendValue

BackendMapMem represents a NATBackend loaded into memory

func LoadBackendMap

func LoadBackendMap(m maps.Map) (BackendMapMem, error)

LoadBackendMap loads the NATBackend map into a go map or returns an error

func (BackendMapMem) Equal

func (m BackendMapMem) Equal(cmp BackendMapMem) bool

Equal compares keys and values of the NATBackendMapMem

type BackendValue

type BackendValue [backendValueSize]byte

func BackendValueFromBytes

func BackendValueFromBytes(b []byte) BackendValue

func NewNATBackendValue

func NewNATBackendValue(addr net.IP, port uint16) BackendValue

func (BackendValue) Addr

func (k BackendValue) Addr() net.IP

func (BackendValue) AsBytes

func (k BackendValue) AsBytes() []byte

func (BackendValue) Port

func (k BackendValue) Port() uint16

func (BackendValue) String

func (k BackendValue) String() string

type FrontEndAffinityKey

type FrontEndAffinityKey [frontendAffKeySize]byte

func (FrontEndAffinityKey) Addr

func (k FrontEndAffinityKey) Addr() net.IP

func (FrontEndAffinityKey) AsBytes

func (k FrontEndAffinityKey) AsBytes() []byte

func (FrontEndAffinityKey) Port

func (k FrontEndAffinityKey) Port() uint16

func (FrontEndAffinityKey) Proto

func (k FrontEndAffinityKey) Proto() uint8

func (FrontEndAffinityKey) String

func (k FrontEndAffinityKey) String() string

type FrontendKey

type FrontendKey [frontendKeySize]byte

func FrontendKeyFromBytes

func FrontendKeyFromBytes(b []byte) FrontendKey

func NewNATKey

func NewNATKey(addr net.IP, port uint16, protocol uint8) FrontendKey

func NewNATKeySrc

func NewNATKeySrc(addr net.IP, port uint16, protocol uint8, cidr ip.V4CIDR) FrontendKey

func (FrontendKey) Addr

func (k FrontendKey) Addr() net.IP

func (FrontendKey) Affinitykey

func (k FrontendKey) Affinitykey() []byte

func (FrontendKey) AsBytes

func (k FrontendKey) AsBytes() []byte

func (FrontendKey) Port

func (k FrontendKey) Port() uint16

func (FrontendKey) PrefixLen

func (k FrontendKey) PrefixLen() uint32

func (FrontendKey) Proto

func (k FrontendKey) Proto() uint8

func (FrontendKey) SrcCIDR

func (k FrontendKey) SrcCIDR() ip.CIDR

func (FrontendKey) SrcPrefixLen

func (k FrontendKey) SrcPrefixLen() uint32

This function returns the Prefix length of the source CIDR

func (FrontendKey) String

func (k FrontendKey) String() string

type FrontendValue

type FrontendValue [frontendValueSize]byte

func FrontendValueFromBytes

func FrontendValueFromBytes(b []byte) FrontendValue

func NewNATValue

func NewNATValue(id uint32, count, local, affinityTimeo uint32) FrontendValue

func NewNATValueWithFlags

func NewNATValueWithFlags(id uint32, count, local, affinityTimeo, flags uint32) FrontendValue

func (FrontendValue) AffinityTimeout

func (v FrontendValue) AffinityTimeout() time.Duration

func (FrontendValue) AsBytes

func (v FrontendValue) AsBytes() []byte

func (FrontendValue) Count

func (v FrontendValue) Count() uint32

func (FrontendValue) Flags

func (v FrontendValue) Flags() uint32

func (FrontendValue) FlagsAsString

func (v FrontendValue) FlagsAsString() string

func (FrontendValue) ID

func (v FrontendValue) ID() uint32

func (FrontendValue) LocalCount

func (v FrontendValue) LocalCount() uint32

func (FrontendValue) String

func (v FrontendValue) String() string

type MapMem

type MapMem map[FrontendKey]FrontendValue

NATMapMem represents FrontendMap loaded into memory

func LoadFrontendMap

func LoadFrontendMap(m maps.Map) (MapMem, error)

LoadFrontendMap loads the NAT map into a go map or returns an error

func (MapMem) Equal

func (m MapMem) Equal(cmp MapMem) bool

Equal compares keys and values of the NATMapMem

type SendRecvMsgKey

type SendRecvMsgKey [sendRecvMsgKeySize]byte

SendRecvMsgKey is the key for SendRecvMsgMap

func (SendRecvMsgKey) Cookie

func (k SendRecvMsgKey) Cookie() uint64

Cookie returns the socket cookie part of the key that can be used to match the socket.

func (SendRecvMsgKey) IP

func (k SendRecvMsgKey) IP() net.IP

IP returns the IP address part of the key

func (SendRecvMsgKey) Port

func (k SendRecvMsgKey) Port() uint16

Port returns port converted to 16-bit host endianness

func (SendRecvMsgKey) String

func (k SendRecvMsgKey) String() string

type SendRecvMsgMapMem

type SendRecvMsgMapMem map[SendRecvMsgKey]SendRecvMsgValue

SendRecvMsgMapMem represents affinity map in memory

func LoadSendRecvMsgMap

func LoadSendRecvMsgMap(m maps.Map) (SendRecvMsgMapMem, error)

LoadSendRecvMsgMap loads affinity map into memory

type SendRecvMsgValue

type SendRecvMsgValue [sendRecvMsgValueSize]byte

SendRecvMsgValue is the value of SendRecvMsgMap

func (SendRecvMsgValue) IP

func (v SendRecvMsgValue) IP() net.IP

IP returns the IP address part of the key

func (SendRecvMsgValue) Port

func (v SendRecvMsgValue) Port() uint16

Port returns port converted to 16-bit host endianness

func (SendRecvMsgValue) String

func (v SendRecvMsgValue) String() string

Jump to

Keyboard shortcuts

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