bpf

package
Version: v3.8.9+incompatible Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: Apache-2.0 Imports: 22 Imported by: 24

Documentation

Overview

Package bpf provides primitives to manage Calico-specific XDP programs attached to network interfaces, along with the blacklist LPM map and the failsafe map.

It does not call the bpf() syscall itself but executes external programs like bpftool and ip.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CidrToHex

func CidrToHex(cidr string) ([]string, error)

CidrToHex takes a CIDR in string form (e.g. "192.168.0.0/16") and outputs a string slice of hex-encoded bytes ready to be passed to bpftool.

For example, for "192.168.0.0/16":

[

10, 00, 00, 00,   mask in little endian order
C0, A8, 00, 00    IP address

]

func GetMockXDPTag

func GetMockXDPTag(bytes []byte) string

func MemberToIPMask

func MemberToIPMask(member string) (*net.IP, int, error)

func SupportsSockmap

func SupportsSockmap() error

func SupportsXDP

func SupportsXDP() error

Types

type BPFDataplane

type BPFDataplane interface {
	DumpCIDRMap(ifName string, family IPFamily) (map[CIDRMapKey]uint32, error)
	DumpFailsafeMap() ([]ProtoPort, error)
	GetCIDRMapID(ifName string, family IPFamily) (int, error)
	GetFailsafeMapID() (int, error)
	GetMapsFromXDP(ifName string) ([]int, error)
	GetXDPID(ifName string) (int, error)
	GetXDPMode(ifName string) (XDPMode, error)
	GetXDPIfaces() ([]string, error)
	GetXDPObjTag(objPath string) (string, error)
	GetXDPObjTagAuto() (string, error)
	GetXDPObjTagWithBytes(objBytes []byte) (string, error)
	GetXDPTag(ifName string) (string, error)
	IsValidMap(ifName string, family IPFamily) (bool, error)
	ListCIDRMaps(family IPFamily) ([]string, error)
	LoadXDP(objPath, ifName string, mode XDPMode) error
	LoadXDPAuto(ifName string, mode XDPMode) error
	LoadXDPWithBytes(objBytes []byte, ifName string, mode XDPMode) error
	LookupCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) (uint32, error)
	LookupFailsafeMap(proto uint8, port uint16) (bool, error)
	NewCIDRMap(ifName string, family IPFamily) (string, error)
	NewFailsafeMap() (string, error)
	RemoveCIDRMap(ifName string, family IPFamily) error
	RemoveFailsafeMap() error
	RemoveItemCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) error
	RemoveItemFailsafeMap(proto uint8, port uint16) error
	RemoveXDP(ifName string, mode XDPMode) error
	UpdateCIDRMap(ifName string, family IPFamily, ip net.IP, mask int, refCount uint32) error
	UpdateFailsafeMap(proto uint8, port uint16) error

	GetBPFCalicoDir() string
	AttachToSockmap() error
	DetachFromSockmap(mode FindObjectMode) error
	RemoveSockmap(mode FindObjectMode) error

	LoadSockops(objPath string) error
	LoadSockopsWithBytes(objBytes []byte) error
	LoadSockopsAuto() error
	RemoveSockops() error
	LoadSkMsg(objPath string) error
	LoadSkMsgWithBytes(objBytes []byte) error
	LoadSkMsgAuto() error
	RemoveSkMsg() error
	AttachToCgroup() error
	DetachFromCgroup(mode FindObjectMode) error
	NewSockmapEndpointsMap() (string, error)
	NewSockmap() (string, error)
	UpdateSockmapEndpoints(ip net.IP, mask int) error
	DumpSockmapEndpointsMap(family IPFamily) ([]CIDRMapKey, error)
	LookupSockmapEndpointsMap(ip net.IP, mask int) (bool, error)
	RemoveItemSockmapEndpointsMap(ip net.IP, mask int) error
	RemoveSockmapEndpointsMap() error
	// contains filtered or unexported methods
}

type BPFLib

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

func NewBPFLib

func NewBPFLib() (*BPFLib, error)

func (*BPFLib) AttachToCgroup

func (b *BPFLib) AttachToCgroup() error

func (*BPFLib) AttachToSockmap

func (b *BPFLib) AttachToSockmap() error

func (*BPFLib) DetachFromCgroup

func (b *BPFLib) DetachFromCgroup(mode FindObjectMode) error

func (*BPFLib) DetachFromSockmap

func (b *BPFLib) DetachFromSockmap(mode FindObjectMode) error

func (*BPFLib) DumpCIDRMap

func (b *BPFLib) DumpCIDRMap(ifName string, family IPFamily) (map[CIDRMapKey]uint32, error)

func (*BPFLib) DumpFailsafeMap

func (b *BPFLib) DumpFailsafeMap() ([]ProtoPort, error)

func (*BPFLib) DumpSockmapEndpointsMap

func (b *BPFLib) DumpSockmapEndpointsMap(family IPFamily) ([]CIDRMapKey, error)

func (*BPFLib) GetBPFCalicoDir

func (b *BPFLib) GetBPFCalicoDir() string

func (*BPFLib) GetCIDRMapID

func (b *BPFLib) GetCIDRMapID(ifName string, family IPFamily) (int, error)

func (*BPFLib) GetFailsafeMapID

func (b *BPFLib) GetFailsafeMapID() (int, error)

func (*BPFLib) GetMapsFromXDP

func (b *BPFLib) GetMapsFromXDP(ifName string) ([]int, error)

func (*BPFLib) GetXDPID

func (b *BPFLib) GetXDPID(ifName string) (int, error)

func (*BPFLib) GetXDPIfaces

func (b *BPFLib) GetXDPIfaces() ([]string, error)

func (*BPFLib) GetXDPMode

func (b *BPFLib) GetXDPMode(ifName string) (XDPMode, error)

func (*BPFLib) GetXDPObjTag

func (b *BPFLib) GetXDPObjTag(objPath string) (tag string, err error)

func (*BPFLib) GetXDPObjTagAuto

func (b *BPFLib) GetXDPObjTagAuto() (string, error)

func (*BPFLib) GetXDPObjTagWithBytes

func (b *BPFLib) GetXDPObjTagWithBytes(objBytes []byte) (string, error)

func (*BPFLib) GetXDPTag

func (b *BPFLib) GetXDPTag(ifName string) (string, error)

func (*BPFLib) IsValidMap

func (b *BPFLib) IsValidMap(ifName string, family IPFamily) (bool, error)

func (*BPFLib) ListCIDRMaps

func (b *BPFLib) ListCIDRMaps(family IPFamily) ([]string, error)

func (*BPFLib) LoadSkMsg

func (b *BPFLib) LoadSkMsg(objPath string) error

func (*BPFLib) LoadSkMsgAuto

func (b *BPFLib) LoadSkMsgAuto() error

func (*BPFLib) LoadSkMsgWithBytes

func (b *BPFLib) LoadSkMsgWithBytes(objBytes []byte) error

func (*BPFLib) LoadSockops

func (b *BPFLib) LoadSockops(objPath string) error

func (*BPFLib) LoadSockopsAuto

func (b *BPFLib) LoadSockopsAuto() error

func (*BPFLib) LoadSockopsWithBytes

func (b *BPFLib) LoadSockopsWithBytes(objBytes []byte) error

func (*BPFLib) LoadXDP

func (b *BPFLib) LoadXDP(objPath, ifName string, mode XDPMode) error

func (*BPFLib) LoadXDPAuto

func (b *BPFLib) LoadXDPAuto(ifName string, mode XDPMode) error

func (*BPFLib) LoadXDPWithBytes

func (b *BPFLib) LoadXDPWithBytes(objBytes []byte, ifName string, mode XDPMode) error

func (*BPFLib) LookupCIDRMap

func (b *BPFLib) LookupCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) (uint32, error)

func (*BPFLib) LookupFailsafeMap

func (b *BPFLib) LookupFailsafeMap(proto uint8, port uint16) (bool, error)

func (*BPFLib) LookupSockmapEndpointsMap

func (b *BPFLib) LookupSockmapEndpointsMap(ip net.IP, mask int) (bool, error)

func (*BPFLib) NewCIDRMap

func (b *BPFLib) NewCIDRMap(ifName string, family IPFamily) (string, error)

func (*BPFLib) NewFailsafeMap

func (b *BPFLib) NewFailsafeMap() (string, error)

func (*BPFLib) NewSockmap

func (b *BPFLib) NewSockmap() (string, error)

func (*BPFLib) NewSockmapEndpointsMap

func (b *BPFLib) NewSockmapEndpointsMap() (string, error)

func (*BPFLib) RemoveCIDRMap

func (b *BPFLib) RemoveCIDRMap(ifName string, family IPFamily) error

func (*BPFLib) RemoveFailsafeMap

func (b *BPFLib) RemoveFailsafeMap() error

func (*BPFLib) RemoveItemCIDRMap

func (b *BPFLib) RemoveItemCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) error

func (*BPFLib) RemoveItemFailsafeMap

func (b *BPFLib) RemoveItemFailsafeMap(proto uint8, port uint16) error

func (*BPFLib) RemoveItemSockmapEndpointsMap

func (b *BPFLib) RemoveItemSockmapEndpointsMap(ip net.IP, mask int) error

func (*BPFLib) RemoveSkMsg

func (b *BPFLib) RemoveSkMsg() error

func (*BPFLib) RemoveSockmap

func (b *BPFLib) RemoveSockmap(mode FindObjectMode) error

func (*BPFLib) RemoveSockmapEndpointsMap

func (b *BPFLib) RemoveSockmapEndpointsMap() error

func (*BPFLib) RemoveSockops

func (b *BPFLib) RemoveSockops() error

func (*BPFLib) RemoveXDP

func (b *BPFLib) RemoveXDP(ifName string, mode XDPMode) error

func (*BPFLib) UpdateCIDRMap

func (b *BPFLib) UpdateCIDRMap(ifName string, family IPFamily, ip net.IP, mask int, refCount uint32) error

func (*BPFLib) UpdateFailsafeMap

func (b *BPFLib) UpdateFailsafeMap(proto uint8, port uint16) error

func (*BPFLib) UpdateSockmapEndpoints

func (b *BPFLib) UpdateSockmapEndpoints(ip net.IP, mask int) error

type CIDRMap

type CIDRMap struct {
	Info CIDRMapInfo
	M    map[IPv4Mask]uint32
}

func NewMockCIDRMap

func NewMockCIDRMap(mapID int) CIDRMap

type CIDRMapInfo

type CIDRMapInfo struct {
	CommonMapInfo

	Family IPFamily
}

type CIDRMapKey

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

func NewCIDRMapKey

func NewCIDRMapKey(n *net.IPNet) CIDRMapKey

func (*CIDRMapKey) ToIPNet

func (k *CIDRMapKey) ToIPNet() *net.IPNet

type CIDRMapsKey

type CIDRMapsKey struct {
	IfName string
	Family IPFamily
}

type CommonMapInfo

type CommonMapInfo struct {
	Id        int
	Type      string
	KeySize   int
	ValueSize int
}

type FailsafeMap

type FailsafeMap struct {
	Info FailsafeMapInfo
	M    map[ProtoPort]struct{} // (protocol, port) set
}

func NewMockFailsafeMap

func NewMockFailsafeMap(mapID int) FailsafeMap

type FailsafeMapInfo

type FailsafeMapInfo struct {
	CommonMapInfo
}

type FindObjectMode

type FindObjectMode uint32
const (
	FindInBPFFSOnly FindObjectMode = 1 << iota
	FindByID
)

type IPFamily

type IPFamily int

XXX maybe use ipsets.IPFamily

const (
	IPFamilyUnknown IPFamily = iota
	IPFamilyV4
	IPFamilyV6
)

func (IPFamily) Size

func (m IPFamily) Size() int

func (IPFamily) String

func (m IPFamily) String() string

type IPv4Mask

type IPv4Mask struct {
	Ip   [4]byte
	Mask int
}

type MockBPFLib

type MockBPFLib struct {
	XDPProgs            map[string]XDPInfo      // iface -> []maps
	CIDRMaps            map[CIDRMapsKey]CIDRMap // iface -> map[ip]refCount
	SockopsProg         *SockopsInfo
	SockMap             *SockMap
	SkMsgProg           *SkMsgInfo
	SockmapEndpointsMap *CIDRMap
	FailsafeMap         FailsafeMap
	CgroupV2Dir         string
}

func NewMockBPFLib

func NewMockBPFLib() *MockBPFLib

func (*MockBPFLib) AttachToCgroup

func (b *MockBPFLib) AttachToCgroup() error

func (*MockBPFLib) AttachToSockmap

func (b *MockBPFLib) AttachToSockmap() error

func (*MockBPFLib) DetachFromCgroup

func (b *MockBPFLib) DetachFromCgroup(mode FindObjectMode) error

func (*MockBPFLib) DetachFromSockmap

func (b *MockBPFLib) DetachFromSockmap(mode FindObjectMode) error

func (*MockBPFLib) DumpCIDRMap

func (b *MockBPFLib) DumpCIDRMap(ifName string, family IPFamily) (map[CIDRMapKey]uint32, error)

func (*MockBPFLib) DumpFailsafeMap

func (b *MockBPFLib) DumpFailsafeMap() ([]ProtoPort, error)

func (*MockBPFLib) DumpSockmapEndpointsMap

func (b *MockBPFLib) DumpSockmapEndpointsMap(family IPFamily) ([]CIDRMapKey, error)

func (*MockBPFLib) GetBPFCalicoDir

func (b *MockBPFLib) GetBPFCalicoDir() string

func (*MockBPFLib) GetCIDRMapID

func (b *MockBPFLib) GetCIDRMapID(ifName string, family IPFamily) (int, error)

func (*MockBPFLib) GetFailsafeMapID

func (b *MockBPFLib) GetFailsafeMapID() (int, error)

func (*MockBPFLib) GetMapsFromXDP

func (b *MockBPFLib) GetMapsFromXDP(ifName string) ([]int, error)

func (*MockBPFLib) GetXDPID

func (b *MockBPFLib) GetXDPID(ifName string) (int, error)

func (*MockBPFLib) GetXDPIfaces

func (b *MockBPFLib) GetXDPIfaces() ([]string, error)

func (*MockBPFLib) GetXDPMode

func (b *MockBPFLib) GetXDPMode(ifName string) (XDPMode, error)

func (*MockBPFLib) GetXDPObjTag

func (b *MockBPFLib) GetXDPObjTag(objPath string) (tag string, err error)

func (*MockBPFLib) GetXDPObjTagAuto

func (b *MockBPFLib) GetXDPObjTagAuto() (string, error)

func (*MockBPFLib) GetXDPObjTagWithBytes

func (b *MockBPFLib) GetXDPObjTagWithBytes(objBytes []byte) (string, error)

func (*MockBPFLib) GetXDPTag

func (b *MockBPFLib) GetXDPTag(ifName string) (string, error)

func (*MockBPFLib) IsValidMap

func (b *MockBPFLib) IsValidMap(ifName string, family IPFamily) (bool, error)

func (*MockBPFLib) ListCIDRMaps

func (b *MockBPFLib) ListCIDRMaps(family IPFamily) ([]string, error)

func (*MockBPFLib) LoadSkMsg

func (b *MockBPFLib) LoadSkMsg(objPath string) error

func (*MockBPFLib) LoadSkMsgAuto

func (b *MockBPFLib) LoadSkMsgAuto() error

func (*MockBPFLib) LoadSkMsgWithBytes

func (b *MockBPFLib) LoadSkMsgWithBytes(objBytes []byte) error

func (*MockBPFLib) LoadSockops

func (b *MockBPFLib) LoadSockops(objPath string) error

func (*MockBPFLib) LoadSockopsAuto

func (b *MockBPFLib) LoadSockopsAuto() error

func (*MockBPFLib) LoadSockopsWithBytes

func (b *MockBPFLib) LoadSockopsWithBytes(objBytes []byte) error

func (*MockBPFLib) LoadXDP

func (b *MockBPFLib) LoadXDP(objPath, ifName string, mode XDPMode) error

func (*MockBPFLib) LoadXDPAuto

func (b *MockBPFLib) LoadXDPAuto(ifName string, mode XDPMode) error

func (*MockBPFLib) LoadXDPWithBytes

func (b *MockBPFLib) LoadXDPWithBytes(objBytes []byte, ifName string, mode XDPMode) error

func (*MockBPFLib) LookupCIDRMap

func (b *MockBPFLib) LookupCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) (uint32, error)

func (*MockBPFLib) LookupFailsafeMap

func (b *MockBPFLib) LookupFailsafeMap(proto uint8, port uint16) (bool, error)

func (*MockBPFLib) LookupSockmapEndpointsMap

func (b *MockBPFLib) LookupSockmapEndpointsMap(ip net.IP, mask int) (bool, error)

func (*MockBPFLib) NewCIDRMap

func (b *MockBPFLib) NewCIDRMap(ifName string, family IPFamily) (string, error)

func (*MockBPFLib) NewFailsafeMap

func (b *MockBPFLib) NewFailsafeMap() (string, error)

func (*MockBPFLib) NewSockmap

func (b *MockBPFLib) NewSockmap() (string, error)

func (*MockBPFLib) NewSockmapEndpointsMap

func (b *MockBPFLib) NewSockmapEndpointsMap() (string, error)

func (*MockBPFLib) RemoveCIDRMap

func (b *MockBPFLib) RemoveCIDRMap(ifName string, family IPFamily) error

func (*MockBPFLib) RemoveFailsafeMap

func (b *MockBPFLib) RemoveFailsafeMap() error

func (*MockBPFLib) RemoveItemCIDRMap

func (b *MockBPFLib) RemoveItemCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) error

func (*MockBPFLib) RemoveItemFailsafeMap

func (b *MockBPFLib) RemoveItemFailsafeMap(proto uint8, port uint16) error

func (*MockBPFLib) RemoveItemSockmapEndpointsMap

func (b *MockBPFLib) RemoveItemSockmapEndpointsMap(ip net.IP, mask int) error

func (*MockBPFLib) RemoveSkMsg

func (b *MockBPFLib) RemoveSkMsg() error

func (*MockBPFLib) RemoveSockmap

func (b *MockBPFLib) RemoveSockmap(mode FindObjectMode) error

func (*MockBPFLib) RemoveSockmapEndpointsMap

func (b *MockBPFLib) RemoveSockmapEndpointsMap() error

func (*MockBPFLib) RemoveSockops

func (b *MockBPFLib) RemoveSockops() error

func (*MockBPFLib) RemoveXDP

func (b *MockBPFLib) RemoveXDP(ifName string, mode XDPMode) error

func (*MockBPFLib) UpdateCIDRMap

func (b *MockBPFLib) UpdateCIDRMap(ifName string, family IPFamily, ip net.IP, mask int, refCount uint32) error

func (*MockBPFLib) UpdateFailsafeMap

func (b *MockBPFLib) UpdateFailsafeMap(proto uint8, port uint16) error

func (*MockBPFLib) UpdateSockmapEndpoints

func (b *MockBPFLib) UpdateSockmapEndpoints(ip net.IP, mask int) error

type ProtoPort

type ProtoPort struct {
	Proto labelindex.IPSetPortProtocol
	Port  uint16
}

type SkMsgInfo

type SkMsgInfo struct {
}

type SockMap

type SockMap struct {
	Info SockMapInfo
	M    map[IPv4Mask]uint32
}

func NewMockSockMap

func NewMockSockMap(mapID int) SockMap

type SockMapInfo

type SockMapInfo struct {
	CommonMapInfo

	SkMsg *SkMsgInfo
}

type SockopsInfo

type SockopsInfo struct {
	CgroupPath string
}

type XDPInfo

type XDPInfo struct {
	Id    int
	Maps  []int
	Bytes []byte
	Mode  XDPMode
}

type XDPMode

type XDPMode int
const (
	XDPDriver XDPMode = iota
	XDPOffload
	XDPGeneric
)

func (XDPMode) String

func (m XDPMode) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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