lbmap

package
v1.5.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2019 License: Apache-2.0 Imports: 12 Imported by: 35

Documentation

Index

Constants

View Source
const (
	// Maximum number of entries in each hashtable
	MaxEntries = 65536

	// MaxSeq is used by daemon for generating bpf define LB_RR_MAX_SEQ.
	MaxSeq = 31
)

Variables

View Source
var (
	Service4Map = bpf.NewMap("cilium_lb4_services",
		bpf.MapTypeHash,
		int(unsafe.Sizeof(Service4Key{})),
		int(unsafe.Sizeof(Service4Value{})),
		MaxEntries,
		0, 0,
		func(key []byte, value []byte) (bpf.MapKey, bpf.MapValue, error) {
			svcKey, svcVal := Service4Key{}, Service4Value{}

			if err := bpf.ConvertKeyValue(key, value, &svcKey, &svcVal); err != nil {
				return nil, nil, err
			}

			return svcKey.ToNetwork(), svcVal.ToNetwork(), nil
		}).WithCache()
	RevNat4Map = bpf.NewMap("cilium_lb4_reverse_nat",
		bpf.MapTypeHash,
		int(unsafe.Sizeof(RevNat4Key{})),
		int(unsafe.Sizeof(RevNat4Value{})),
		MaxEntries,
		0, 0,
		func(key []byte, value []byte) (bpf.MapKey, bpf.MapValue, error) {
			var ukey uint16
			var revNat RevNat4Value

			if err := bpf.ConvertKeyValue(key, value, &ukey, &revNat); err != nil {
				return nil, nil, err
			}

			revKey := NewRevNat4Key(ukey)

			return revKey.ToNetwork(), revNat.ToNetwork(), nil
		}).WithCache()
	RRSeq4Map = bpf.NewMap("cilium_lb4_rr_seq",
		bpf.MapTypeHash,
		int(unsafe.Sizeof(Service4Key{})),
		int(unsafe.Sizeof(RRSeqValue{})),
		maxFrontEnds,
		0, 0,
		func(key []byte, value []byte) (bpf.MapKey, bpf.MapValue, error) {
			svcKey, svcVal := Service4Key{}, RRSeqValue{}

			if err := bpf.ConvertKeyValue(key, value, &svcKey, &svcVal); err != nil {
				return nil, nil, err
			}

			return svcKey.ToNetwork(), &svcVal, nil
		}).WithCache()
)
View Source
var (
	// Service6Map represents the BPF map for services in IPv6 load balancer
	Service6Map = bpf.NewMap("cilium_lb6_services",
		bpf.MapTypeHash,
		int(unsafe.Sizeof(Service6Key{})),
		int(unsafe.Sizeof(Service6Value{})),
		MaxEntries,
		0, 0,
		func(key []byte, value []byte) (bpf.MapKey, bpf.MapValue, error) {
			svcKey, svcVal := Service6Key{}, Service6Value{}

			if err := bpf.ConvertKeyValue(key, value, &svcKey, &svcVal); err != nil {
				return nil, nil, err
			}

			return svcKey.ToNetwork(), svcVal.ToNetwork(), nil
		}).WithCache()
	// RevNat6Map represents the BPF map for reverse NAT in IPv6 load balancer
	RevNat6Map = bpf.NewMap("cilium_lb6_reverse_nat",
		bpf.MapTypeHash,
		int(unsafe.Sizeof(RevNat6Key{})),
		int(unsafe.Sizeof(RevNat6Value{})),
		MaxEntries,
		0, 0,
		func(key []byte, value []byte) (bpf.MapKey, bpf.MapValue, error) {
			var ukey uint16
			var revNat RevNat6Value

			if err := bpf.ConvertKeyValue(key, value, &ukey, &revNat); err != nil {
				return nil, nil, err
			}

			revKey := NewRevNat6Key(ukey)

			return revKey.ToNetwork(), revNat.ToNetwork(), nil
		}).WithCache()
	// RRSeq6Map represents the BPF map for wrr sequences in IPv6 load balancer
	RRSeq6Map = bpf.NewMap("cilium_lb6_rr_seq",
		bpf.MapTypeHash,
		int(unsafe.Sizeof(Service6Key{})),
		int(unsafe.Sizeof(RRSeqValue{})),
		maxFrontEnds,
		0, 0,
		func(key []byte, value []byte) (bpf.MapKey, bpf.MapValue, error) {
			svcKey, svcVal := Service6Key{}, RRSeqValue{}

			if err := bpf.ConvertKeyValue(key, value, &svcKey, &svcVal); err != nil {
				return nil, nil, err
			}

			return svcKey.ToNetwork(), &svcVal, nil
		}).WithCache()
)

Functions

func DeleteRevNATBPF added in v1.5.0

func DeleteRevNATBPF(id loadbalancer.ServiceID, isIPv6 bool) error

DeleteRevNATBPF deletes the revNAT entry from its corresponding BPF map (IPv4 or IPv6) with ID id. Returns an error if the deletion operation failed.

func DeleteRevNat

func DeleteRevNat(key RevNatKey) error

func DeleteService

func DeleteService(key ServiceKey) error

DeleteService deletes a service from the lbmap. key should be the master (i.e., with backend set to zero).

func DumpRevNATMapsToUserspace added in v1.5.0

func DumpRevNATMapsToUserspace() (loadbalancer.RevNATMap, []error)

DumpRevNATMapsToUserspace dumps the contents of both the IPv6 and IPv4 revNAT BPF maps, and stores the contents of said dumps in a RevNATMap. Returns the errors that occurred while dumping the maps.

func DumpServiceMapsToUserspace added in v1.5.0

func DumpServiceMapsToUserspace(includeMasterBackend bool) (loadbalancer.SVCMap, []*loadbalancer.LBSVC, []error)

DumpServiceMapsToUserspace dumps the contents of both the IPv6 and IPv4 service / loadbalancer BPF maps, and converts them to a SVCMap and slice of LBSVC. IPv4 maps may not be dumped depending on if skipIPv4 is enabled. If includeMasterBackend is true, the returned values will also include services which correspond to "master" backend values in the BPF maps. Returns the errors that occurred while dumping the maps.

func L3n4Addr2RevNatKeynValue

func L3n4Addr2RevNatKeynValue(svcID loadbalancer.ServiceID, feL3n4Addr loadbalancer.L3n4Addr) (RevNatKey, RevNatValue)

L3n4Addr2RevNatKeynValue converts the given L3n4Addr to a RevNatKey and RevNatValue.

func LBSVC2ServiceKeynValue

func LBSVC2ServiceKeynValue(svc loadbalancer.LBSVC) (ServiceKey, []ServiceValue, error)

LBSVC2ServiceKeynValue transforms the SVC Cilium type into a bpf SVC type.

func RestoreService added in v1.5.0

func RestoreService(svc loadbalancer.LBSVC) error

RestoreService restores a single service in the cache. This is required to guarantee consistent backend ordering

func UpdateRevNat

func UpdateRevNat(key RevNatKey, value RevNatValue) error

func UpdateService

func UpdateService(fe ServiceKey, backends []ServiceValue, addRevNAT bool, revNATID int) error

UpdateService adds or updates the given service in the bpf maps

Types

type RRSeqValue

type RRSeqValue struct {
	// Length of Generated sequence
	Count uint16

	// Generated Sequence
	Idx [MaxSeq]uint16
}

func (*RRSeqValue) GetValuePtr

func (s *RRSeqValue) GetValuePtr() unsafe.Pointer

func (*RRSeqValue) String added in v1.5.0

func (s *RRSeqValue) String() string

type RevNat4Key

type RevNat4Key struct {
	Key uint16
}

func NewRevNat4Key

func NewRevNat4Key(value uint16) *RevNat4Key

func (*RevNat4Key) GetKey

func (k *RevNat4Key) GetKey() uint16

func (*RevNat4Key) GetKeyPtr

func (k *RevNat4Key) GetKeyPtr() unsafe.Pointer

func (*RevNat4Key) IsIPv6

func (k *RevNat4Key) IsIPv6() bool

func (*RevNat4Key) Map

func (k *RevNat4Key) Map() *bpf.Map

func (*RevNat4Key) NewValue

func (k *RevNat4Key) NewValue() bpf.MapValue

func (*RevNat4Key) String

func (k *RevNat4Key) String() string

func (*RevNat4Key) ToNetwork added in v0.10.0

func (k *RevNat4Key) ToNetwork() RevNatKey

ToNetwork converts RevNat4Key to network byte order.

type RevNat4Value

type RevNat4Value struct {
	Address types.IPv4
	Port    uint16
}

func NewRevNat4Value

func NewRevNat4Value(ip net.IP, port uint16) *RevNat4Value

func (*RevNat4Value) GetValuePtr

func (v *RevNat4Value) GetValuePtr() unsafe.Pointer

func (*RevNat4Value) String

func (v *RevNat4Value) String() string

func (*RevNat4Value) ToNetwork added in v0.10.0

func (v *RevNat4Value) ToNetwork() RevNatValue

ToNetwork converts RevNat4Value to network byte order.

type RevNat6Key

type RevNat6Key struct {
	Key uint16
}

func NewRevNat6Key

func NewRevNat6Key(value uint16) *RevNat6Key

func (*RevNat6Key) GetKey

func (v *RevNat6Key) GetKey() uint16

func (*RevNat6Key) GetKeyPtr

func (v *RevNat6Key) GetKeyPtr() unsafe.Pointer

func (*RevNat6Key) IsIPv6

func (v *RevNat6Key) IsIPv6() bool

func (*RevNat6Key) Map

func (v *RevNat6Key) Map() *bpf.Map

func (*RevNat6Key) NewValue

func (v *RevNat6Key) NewValue() bpf.MapValue

func (*RevNat6Key) String

func (v *RevNat6Key) String() string

func (*RevNat6Key) ToNetwork added in v0.10.0

func (v *RevNat6Key) ToNetwork() RevNatKey

ToNetwork converts RevNat6Key to network byte order.

type RevNat6Value

type RevNat6Value struct {
	Address types.IPv6
	Port    uint16
}

func NewRevNat6Value

func NewRevNat6Value(ip net.IP, port uint16) *RevNat6Value

func (*RevNat6Value) GetValuePtr

func (v *RevNat6Value) GetValuePtr() unsafe.Pointer

func (*RevNat6Value) String

func (v *RevNat6Value) String() string

func (*RevNat6Value) ToNetwork added in v0.10.0

func (v *RevNat6Value) ToNetwork() RevNatValue

ToNetwork converts RevNat6Value to network byte order.

type RevNatKey

type RevNatKey interface {
	bpf.MapKey

	// Returns true if the key is of type IPv6
	IsIPv6() bool

	// Returns the BPF map matching the key type
	Map() *bpf.Map

	// ToNetwork converts fields to network byte order.
	ToNetwork() RevNatKey

	// Returns the key value
	GetKey() uint16
}

type RevNatValue

type RevNatValue interface {
	bpf.MapValue

	// ToNetwork converts fields to network byte order.
	ToNetwork() RevNatValue
}

type Service4Key

type Service4Key struct {
	Address types.IPv4 `align:"address"`
	Port    uint16     `align:"dport"`
	Slave   uint16     `align:"slave"`
}

Service4Key must match 'struct lb4_key' in "bpf/lib/common.h".

func NewService4Key

func NewService4Key(ip net.IP, port uint16, slave uint16) *Service4Key

func (*Service4Key) GetBackend

func (k *Service4Key) GetBackend() int

func (*Service4Key) GetKeyPtr

func (k *Service4Key) GetKeyPtr() unsafe.Pointer

func (*Service4Key) GetPort

func (k *Service4Key) GetPort() uint16

func (Service4Key) IsIPv6

func (k Service4Key) IsIPv6() bool

func (Service4Key) Map

func (k Service4Key) Map() *bpf.Map

func (*Service4Key) MapDelete

func (k *Service4Key) MapDelete() error

func (Service4Key) NewValue

func (k Service4Key) NewValue() bpf.MapValue

func (Service4Key) RRMap

func (k Service4Key) RRMap() *bpf.Map

func (*Service4Key) RevNatValue

func (k *Service4Key) RevNatValue() RevNatValue

func (*Service4Key) SetBackend

func (k *Service4Key) SetBackend(backend int)

func (*Service4Key) SetPort

func (k *Service4Key) SetPort(port uint16)

func (*Service4Key) String

func (k *Service4Key) String() string

func (*Service4Key) ToHost added in v0.10.0

func (k *Service4Key) ToHost() ServiceKey

ToHost converts Service4Key port to network byte order.

func (*Service4Key) ToNetwork added in v0.10.0

func (k *Service4Key) ToNetwork() ServiceKey

ToNetwork converts Service4Key port to network byte order.

type Service4Value

type Service4Value struct {
	Address types.IPv4 `align:"target"`
	Port    uint16     `align:"port"`
	Count   uint16     `align:"count"`
	RevNat  uint16     `align:"rev_nat_index"`
	Weight  uint16     `align:"weight"`
}

Service4Value must match 'struct lb4_service' in "bpf/lib/common.h".

func NewService4Value

func NewService4Value(count uint16, target net.IP, port uint16, revNat uint16, weight uint16) *Service4Value

func (*Service4Value) GetCount

func (s *Service4Value) GetCount() int

func (*Service4Value) GetValuePtr

func (s *Service4Value) GetValuePtr() unsafe.Pointer

func (*Service4Value) GetWeight

func (s *Service4Value) GetWeight() uint16

func (*Service4Value) RevNatKey

func (s *Service4Value) RevNatKey() RevNatKey

func (*Service4Value) SetAddress

func (s *Service4Value) SetAddress(ip net.IP) error

func (*Service4Value) SetCount

func (s *Service4Value) SetCount(count int)

func (*Service4Value) SetPort

func (s *Service4Value) SetPort(port uint16)

func (*Service4Value) SetRevNat

func (s *Service4Value) SetRevNat(id int)

func (*Service4Value) SetWeight

func (s *Service4Value) SetWeight(weight uint16)

func (*Service4Value) String

func (s *Service4Value) String() string

func (*Service4Value) ToHost added in v0.10.0

func (s *Service4Value) ToHost() ServiceValue

ToHost converts Service4Value to host byte order.

func (*Service4Value) ToNetwork added in v0.10.0

func (s *Service4Value) ToNetwork() ServiceValue

ToNetwork converts Service4Value to network byte order.

type Service6Key

type Service6Key struct {
	Address types.IPv6 `align:"address"`
	Port    uint16     `align:"dport"`
	Slave   uint16     `align:"slave"`
}

Service6Key must match 'struct lb6_key' in "bpf/lib/common.h".

func NewService6Key

func NewService6Key(ip net.IP, port uint16, slave uint16) *Service6Key

func (*Service6Key) GetBackend

func (k *Service6Key) GetBackend() int

func (*Service6Key) GetKeyPtr

func (k *Service6Key) GetKeyPtr() unsafe.Pointer

func (*Service6Key) GetPort

func (k *Service6Key) GetPort() uint16

func (Service6Key) IsIPv6

func (k Service6Key) IsIPv6() bool

func (Service6Key) Map

func (k Service6Key) Map() *bpf.Map

func (Service6Key) NewValue

func (k Service6Key) NewValue() bpf.MapValue

func (Service6Key) RRMap

func (k Service6Key) RRMap() *bpf.Map

func (*Service6Key) RevNatValue

func (k *Service6Key) RevNatValue() RevNatValue

func (*Service6Key) SetBackend

func (k *Service6Key) SetBackend(backend int)

func (*Service6Key) SetPort

func (k *Service6Key) SetPort(port uint16)

func (*Service6Key) String

func (k *Service6Key) String() string

func (*Service6Key) ToHost added in v0.10.0

func (k *Service6Key) ToHost() ServiceKey

ToHost converts Service6Key to host byte order.

func (*Service6Key) ToNetwork added in v0.10.0

func (k *Service6Key) ToNetwork() ServiceKey

ToNetwork converts Service6Key to network byte order.

type Service6Value

type Service6Value struct {
	Address types.IPv6 `align:"target"`
	Port    uint16     `align:"port"`
	Count   uint16     `align:"count"`
	RevNat  uint16     `align:"rev_nat_index"`
	Weight  uint16     `align:"weight"`
}

Service6Value must match 'struct lb6_service' in "bpf/lib/common.h".

func NewService6Value

func NewService6Value(count uint16, target net.IP, port uint16, revNat uint16, weight uint16) *Service6Value

func (*Service6Value) GetCount

func (s *Service6Value) GetCount() int

func (*Service6Value) GetValuePtr

func (s *Service6Value) GetValuePtr() unsafe.Pointer

func (*Service6Value) GetWeight

func (s *Service6Value) GetWeight() uint16

func (*Service6Value) RevNatKey

func (s *Service6Value) RevNatKey() RevNatKey

func (*Service6Value) SetAddress

func (s *Service6Value) SetAddress(ip net.IP) error

func (*Service6Value) SetCount

func (s *Service6Value) SetCount(count int)

func (*Service6Value) SetPort

func (s *Service6Value) SetPort(port uint16)

func (*Service6Value) SetRevNat

func (s *Service6Value) SetRevNat(id int)

func (*Service6Value) SetWeight

func (s *Service6Value) SetWeight(weight uint16)

func (*Service6Value) String

func (s *Service6Value) String() string

func (*Service6Value) ToHost added in v0.10.0

func (s *Service6Value) ToHost() ServiceValue

ToHost converts Service6Value ports to host byte order.

func (*Service6Value) ToNetwork added in v0.10.0

func (s *Service6Value) ToNetwork() ServiceValue

ToNetwork converts Service6Value ports to network byte order.

type ServiceKey

type ServiceKey interface {
	bpf.MapKey

	// Returns true if the key is of type IPv6
	IsIPv6() bool

	// Returns the BPF map matching the key type
	Map() *bpf.Map

	// Returns the BPF Weighted Round Robin map matching the key type
	RRMap() *bpf.Map

	// Returns a RevNatValue matching a ServiceKey
	RevNatValue() RevNatValue

	// Returns the port set in the key or 0
	GetPort() uint16

	// Set the backend index (master: 0, backend: nth backend)
	SetBackend(int)

	// Return backend index
	GetBackend() int

	// ToNetwork converts fields to network byte order.
	ToNetwork() ServiceKey

	// ToHost converts fields to host byte order.
	ToHost() ServiceKey
}

ServiceKey is the interface describing protocol independent key for services map.

type ServiceValue

type ServiceValue interface {
	bpf.MapValue

	// Returns a RevNatKey matching a ServiceValue
	RevNatKey() RevNatKey

	// Set the number of backends
	SetCount(int)

	// Get the number of backends
	GetCount() int

	// Set address to map to (left blank for master)
	SetAddress(net.IP) error

	// Set port to map to (left blank for master)
	SetPort(uint16)

	// Set reverse NAT identifier
	SetRevNat(int)

	// Set Weight
	SetWeight(uint16)

	// Get Weight
	GetWeight() uint16

	// ToNetwork converts fields to network byte order.
	ToNetwork() ServiceValue

	// ToHost converts fields to host byte order.
	ToHost() ServiceValue
}

ServiceValue is the interface describing protocol independent value for services map.

Jump to

Keyboard shortcuts

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