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 ¶
- func CidrToHex(cidr string) ([]string, error)
- func GetMockXDPTag(bytes []byte) string
- func MemberToIPMask(member string) (*net.IP, int, error)
- func SupportsXDP() error
- type BPFDataplane
- type BPFLib
- func (b *BPFLib) DumpCIDRMap(ifName string, family IPFamily) (map[CIDRMapKey]uint32, error)
- func (b *BPFLib) DumpFailsafeMap() ([]ProtoPort, error)
- func (b *BPFLib) GetBPFCalicoDir() string
- func (b *BPFLib) GetCIDRMapID(ifName string, family IPFamily) (int, error)
- func (b *BPFLib) GetFailsafeMapID() (int, error)
- func (b *BPFLib) GetMapsFromXDP(ifName string) ([]int, error)
- func (b *BPFLib) GetXDPID(ifName string) (int, error)
- func (b *BPFLib) GetXDPIfaces() ([]string, error)
- func (b *BPFLib) GetXDPMode(ifName string) (XDPMode, error)
- func (b *BPFLib) GetXDPObjTag(objPath string) (tag string, err error)
- func (b *BPFLib) GetXDPObjTagAuto() (string, error)
- func (b *BPFLib) GetXDPObjTagWithBytes(objBytes []byte) (string, error)
- func (b *BPFLib) GetXDPTag(ifName string) (string, error)
- func (b *BPFLib) IsValidMap(ifName string, family IPFamily) (bool, error)
- func (b *BPFLib) ListCIDRMaps(family IPFamily) ([]string, error)
- func (b *BPFLib) LoadXDP(objPath, ifName string, mode XDPMode) error
- func (b *BPFLib) LoadXDPAuto(ifName string, mode XDPMode) error
- func (b *BPFLib) LoadXDPWithBytes(objBytes []byte, ifName string, mode XDPMode) error
- func (b *BPFLib) LookupCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) (uint32, error)
- func (b *BPFLib) LookupFailsafeMap(proto uint8, port uint16) (bool, error)
- func (b *BPFLib) NewCIDRMap(ifName string, family IPFamily) (string, error)
- func (b *BPFLib) NewFailsafeMap() (string, error)
- func (b *BPFLib) RemoveCIDRMap(ifName string, family IPFamily) error
- func (b *BPFLib) RemoveFailsafeMap() error
- func (b *BPFLib) RemoveItemCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) error
- func (b *BPFLib) RemoveItemFailsafeMap(proto uint8, port uint16) error
- func (b *BPFLib) RemoveXDP(ifName string, mode XDPMode) error
- func (b *BPFLib) UpdateCIDRMap(ifName string, family IPFamily, ip net.IP, mask int, refCount uint32) error
- func (b *BPFLib) UpdateFailsafeMap(proto uint8, port uint16) error
- type CIDRMap
- type CIDRMapInfo
- type CIDRMapKey
- type CIDRMapsKey
- type CommonMapInfo
- type FailsafeMap
- type FailsafeMapInfo
- type IPFamily
- type IPv4Mask
- type MockBPFLib
- func (b *MockBPFLib) DumpCIDRMap(ifName string, family IPFamily) (map[CIDRMapKey]uint32, error)
- func (b *MockBPFLib) DumpFailsafeMap() ([]ProtoPort, error)
- func (b *MockBPFLib) GetBPFCalicoDir() string
- func (b *MockBPFLib) GetCIDRMapID(ifName string, family IPFamily) (int, error)
- func (b *MockBPFLib) GetFailsafeMapID() (int, error)
- func (b *MockBPFLib) GetMapsFromXDP(ifName string) ([]int, error)
- func (b *MockBPFLib) GetXDPID(ifName string) (int, error)
- func (b *MockBPFLib) GetXDPIfaces() ([]string, error)
- func (b *MockBPFLib) GetXDPMode(ifName string) (XDPMode, error)
- func (b *MockBPFLib) GetXDPObjTag(objPath string) (tag string, err error)
- func (b *MockBPFLib) GetXDPObjTagAuto() (string, error)
- func (b *MockBPFLib) GetXDPObjTagWithBytes(objBytes []byte) (string, error)
- func (b *MockBPFLib) GetXDPTag(ifName string) (string, error)
- func (b *MockBPFLib) IsValidMap(ifName string, family IPFamily) (bool, error)
- func (b *MockBPFLib) ListCIDRMaps(family IPFamily) ([]string, error)
- func (b *MockBPFLib) LoadXDP(objPath, ifName string, mode XDPMode) error
- func (b *MockBPFLib) LoadXDPAuto(ifName string, mode XDPMode) error
- func (b *MockBPFLib) LoadXDPWithBytes(objBytes []byte, ifName string, mode XDPMode) error
- func (b *MockBPFLib) LookupCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) (uint32, error)
- func (b *MockBPFLib) LookupFailsafeMap(proto uint8, port uint16) (bool, error)
- func (b *MockBPFLib) NewCIDRMap(ifName string, family IPFamily) (string, error)
- func (b *MockBPFLib) NewFailsafeMap() (string, error)
- func (b *MockBPFLib) RemoveCIDRMap(ifName string, family IPFamily) error
- func (b *MockBPFLib) RemoveFailsafeMap() error
- func (b *MockBPFLib) RemoveItemCIDRMap(ifName string, family IPFamily, ip net.IP, mask int) error
- func (b *MockBPFLib) RemoveItemFailsafeMap(proto uint8, port uint16) error
- func (b *MockBPFLib) RemoveXDP(ifName string, mode XDPMode) error
- func (b *MockBPFLib) UpdateCIDRMap(ifName string, family IPFamily, ip net.IP, mask int, refCount uint32) error
- func (b *MockBPFLib) UpdateFailsafeMap(proto uint8, port uint16) error
- type ProtoPort
- type XDPInfo
- type XDPMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CidrToHex ¶
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 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 // contains filtered or unexported methods }
type BPFLib ¶
type BPFLib struct {
// contains filtered or unexported fields
}
func (*BPFLib) DumpCIDRMap ¶
func (*BPFLib) DumpFailsafeMap ¶
func (*BPFLib) GetBPFCalicoDir ¶
func (*BPFLib) GetCIDRMapID ¶
func (*BPFLib) GetFailsafeMapID ¶
func (*BPFLib) GetXDPIfaces ¶
func (*BPFLib) GetXDPObjTagAuto ¶
func (*BPFLib) GetXDPObjTagWithBytes ¶
func (*BPFLib) IsValidMap ¶
func (*BPFLib) LoadXDPWithBytes ¶
func (*BPFLib) LookupCIDRMap ¶
func (*BPFLib) LookupFailsafeMap ¶
func (*BPFLib) NewCIDRMap ¶
func (*BPFLib) NewFailsafeMap ¶
func (*BPFLib) RemoveFailsafeMap ¶
func (*BPFLib) RemoveItemCIDRMap ¶
func (*BPFLib) RemoveItemFailsafeMap ¶
func (*BPFLib) UpdateCIDRMap ¶
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 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 MockBPFLib ¶
type MockBPFLib struct { XDPProgs map[string]XDPInfo // iface -> []maps CIDRMaps map[CIDRMapsKey]CIDRMap // iface -> map[ip]refCount FailsafeMap FailsafeMap }
func NewMockBPFLib ¶
func NewMockBPFLib() *MockBPFLib
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) 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) 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) IsValidMap ¶
func (b *MockBPFLib) IsValidMap(ifName string, family IPFamily) (bool, error)
func (*MockBPFLib) ListCIDRMaps ¶
func (b *MockBPFLib) ListCIDRMaps(family IPFamily) ([]string, 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 (*MockBPFLib) LookupFailsafeMap ¶
func (b *MockBPFLib) LookupFailsafeMap(proto uint8, port uint16) (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) RemoveCIDRMap ¶
func (b *MockBPFLib) RemoveCIDRMap(ifName string, family IPFamily) error
func (*MockBPFLib) RemoveFailsafeMap ¶
func (b *MockBPFLib) RemoveFailsafeMap() error
func (*MockBPFLib) RemoveItemCIDRMap ¶
func (*MockBPFLib) RemoveItemFailsafeMap ¶
func (b *MockBPFLib) RemoveItemFailsafeMap(proto uint8, port uint16) error
func (*MockBPFLib) UpdateCIDRMap ¶
func (*MockBPFLib) UpdateFailsafeMap ¶
func (b *MockBPFLib) UpdateFailsafeMap(proto uint8, port uint16) error
type ProtoPort ¶
type ProtoPort struct { Proto labelindex.IPSetPortProtocol Port uint16 }