Documentation ¶
Overview ¶
Package loader provides accessors to compilation and BPF load routines necessary for creating datapath objects and attaching them to links.
Index ¶
- Constants
- Variables
- func Compile(ctx context.Context, src string, out string) error
- func CompileWithOptions(ctx context.Context, src string, out string, opts []string) error
- func DetachXDP(iface netlink.Link, bpffsBase, progName string) error
- func DeviceHasTCProgramLoaded(hostInterface string, checkEgress bool) (bool, error)
- func ELFSubstitutions(ep datapath.Endpoint) (map[string]uint64, map[string]string)
- func GetBPFCPU() string
- func NewObjectCache(c datapath.ConfigWriter, nodeCfg *datapath.LocalNodeConfiguration) *objectCache
- func RestoreTemplates(stateDir string) error
- func SetXDPMode(mode string) error
- func SetupBaseDevice(mtu int) (netlink.Link, netlink.Link, error)
- type Loader
- func (l *Loader) CallsMapPath(id uint16) string
- func (l *Loader) CompileAndLoad(ctx context.Context, ep datapath.Endpoint, stats *metrics.SpanStat) error
- func (l *Loader) CompileOrLoad(ctx context.Context, ep datapath.Endpoint, stats *metrics.SpanStat) error
- func (l *Loader) CustomCallsMapPath(id uint16) string
- func (l *Loader) EndpointHash(cfg datapath.EndpointConfiguration) (string, error)
- func (l *Loader) HostDatapathInitialized() <-chan struct{}
- func (l *Loader) Reinitialize(ctx context.Context, o datapath.BaseProgramOwner, tunnelConfig tunnel.Config, ...) error
- func (l *Loader) ReinitializeXDP(ctx context.Context, o datapath.BaseProgramOwner, extraCArgs []string) error
- func (l *Loader) ReloadDatapath(ctx context.Context, ep datapath.Endpoint, stats *metrics.SpanStat) (err error)
- func (l *Loader) Unload(ep datapath.Endpoint)
- type OutputType
Constants ¶
const ( SecctxFromIpcacheDisabled = iota + 1 SecctxFromIpcacheEnabled )
const ( XDPAttachedNone uint32 = iota XDPAttachedDriver XDPAttachedGeneric )
These constant values are returned by the kernel when querying the XDP program attach mode. Important: they differ from constants that are used when attaching an XDP program to a netlink device.
const (
Subsystem = "datapath-loader"
)
Variables ¶
var ( // DatapathSHA256 is set during build to the SHA across all datapath BPF // code. See the definition of CILIUM_DATAPATH_SHA256 in Makefile.defs for // details. DatapathSHA256 string )
Functions ¶
func CompileWithOptions ¶
CompileWithOptions compiles a BPF program generating an object file, using a set of provided compiler options.
func DetachXDP ¶ added in v1.15.0
DetachXDP removes an XDP program from a network interface.
bpffsBase is typically /sys/fs/bpf/cilium, but can be overridden to a tempdir during tests.
func DeviceHasTCProgramLoaded ¶ added in v1.15.0
DeviceHasTCProgramLoaded checks whether a given device has tc filter/qdisc progs attached.
func ELFSubstitutions ¶
ELFSubstitutions fetches the set of variable and map substitutions that must be implemented against an ELF template to configure the datapath for the specified endpoint.
func NewObjectCache ¶
func NewObjectCache(c datapath.ConfigWriter, nodeCfg *datapath.LocalNodeConfiguration) *objectCache
NewObjectCache creates a new cache for datapath objects, basing the hash upon the configuration of the datapath and the specified node configuration.
func RestoreTemplates ¶
RestoreTemplates populates the object cache from templates on the filesystem at the specified path.
func SetXDPMode ¶
func SetupBaseDevice ¶
SetupBaseDevice decides which and what kind of interfaces should be set up as the first step of datapath initialization, then performs the setup (and creation, if needed) of those interfaces. It returns two links and an error. By default, it sets up the veth pair - cilium_host and cilium_net.
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is a wrapper structure around operations related to compiling, loading, and reloading datapath programs.
func (*Loader) CallsMapPath ¶
CallsMapPath gets the BPF Calls Map for the endpoint with the specified ID.
func (*Loader) CompileAndLoad ¶
func (l *Loader) CompileAndLoad(ctx context.Context, ep datapath.Endpoint, stats *metrics.SpanStat) error
CompileAndLoad compiles the BPF datapath programs for the specified endpoint and loads it onto the interface associated with the endpoint.
Expects the caller to have created the directory at the path ep.StateDir().
func (*Loader) CompileOrLoad ¶
func (l *Loader) CompileOrLoad(ctx context.Context, ep datapath.Endpoint, stats *metrics.SpanStat) error
CompileOrLoad loads the BPF datapath programs for the specified endpoint.
In contrast with CompileAndLoad(), it attempts to find a pre-compiled template datapath object to use, to avoid a costly compile operation. Only if there is no existing template that has the same configuration parameters as the specified endpoint, this function will compile a new template for this configuration.
This function will block if the cache does not contain an entry for the same EndpointConfiguration and multiple goroutines attempt to concurrently CompileOrLoad with the same configuration parameters. When the first goroutine completes compilation of the template, all other CompileOrLoad invocations will be released.
func (*Loader) CustomCallsMapPath ¶
CustomCallsMapPath gets the BPF Custom Calls Map for the endpoint with the specified ID.
func (*Loader) EndpointHash ¶
func (l *Loader) EndpointHash(cfg datapath.EndpointConfiguration) (string, error)
EndpointHash hashes the specified endpoint configuration with the current datapath hash cache and returns the hash as string.
func (*Loader) HostDatapathInitialized ¶
func (l *Loader) HostDatapathInitialized() <-chan struct{}
HostDatapathInitialized returns a channel which is closed when the host datapath has been loaded for the first time.
func (*Loader) Reinitialize ¶
func (l *Loader) Reinitialize(ctx context.Context, o datapath.BaseProgramOwner, tunnelConfig tunnel.Config, deviceMTU int, iptMgr datapath.IptablesManager, p datapath.Proxy) error
Reinitialize (re-)configures the base datapath configuration including global BPF programs, netfilter rule configuration and reserving routes in IPAM for locally detected prefixes. It may be run upon initial Cilium startup, after restore from a previous Cilium run, or during regular Cilium operation.
func (*Loader) ReinitializeXDP ¶
func (l *Loader) ReinitializeXDP(ctx context.Context, o datapath.BaseProgramOwner, extraCArgs []string) error
ReinitializeXDP (re-)configures the XDP datapath only. This includes recompilation and reinsertion of the object into the kernel as well as an atomic program replacement at the XDP hook. extraCArgs can be passed-in in order to alter BPF code defines.
type OutputType ¶
type OutputType string
OutputType determines the type to be generated by the compilation steps.