github.com/cilium/cilium@v1.16.2/pkg/datapath/types/loader.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package types
     5  
     6  import (
     7  	"context"
     8  	"io"
     9  	"net"
    10  	"net/netip"
    11  
    12  	"github.com/cilium/cilium/pkg/datapath/loader/metrics"
    13  	"github.com/cilium/cilium/pkg/datapath/tunnel"
    14  )
    15  
    16  // Loader is an interface to abstract out loading of datapath programs.
    17  type Loader interface {
    18  	CallsMapPath(id uint16) string
    19  	CustomCallsMapPath(id uint16) string
    20  	ReloadDatapath(ctx context.Context, ep Endpoint, stats *metrics.SpanStat) (string, error)
    21  	ReinitializeXDP(ctx context.Context, extraCArgs []string) error
    22  	EndpointHash(cfg EndpointConfiguration) (string, error)
    23  	Unload(ep Endpoint)
    24  	Reinitialize(ctx context.Context, cfg LocalNodeConfiguration, tunnelConfig tunnel.Config, iptMgr IptablesManager, p Proxy) error
    25  	HostDatapathInitialized() <-chan struct{}
    26  	DetachXDP(iface string, bpffsBase, progName string) error
    27  
    28  	WriteEndpointConfig(w io.Writer, cfg EndpointConfiguration) error
    29  }
    30  
    31  // PreFilter an interface for an XDP pre-filter.
    32  type PreFilter interface {
    33  	Enabled() bool
    34  	WriteConfig(fw io.Writer)
    35  	Dump(to []string) ([]string, int64)
    36  	Insert(revision int64, cidrs []net.IPNet) error
    37  	Delete(revision int64, cidrs []net.IPNet) error
    38  }
    39  
    40  // Proxy is any type which installs rules related to redirecting traffic to
    41  // a proxy.
    42  type Proxy interface {
    43  	ReinstallRoutingRules() error
    44  }
    45  
    46  // IptablesManager manages iptables rules.
    47  type IptablesManager interface {
    48  	// InstallProxyRules creates the necessary datapath config (e.g., iptables
    49  	// rules for redirecting host proxy traffic on a specific ProxyPort)
    50  	InstallProxyRules(proxyPort uint16, name string)
    51  
    52  	// SupportsOriginalSourceAddr tells if the datapath supports
    53  	// use of original source addresses in proxy upstream
    54  	// connections.
    55  	SupportsOriginalSourceAddr() bool
    56  
    57  	// GetProxyPorts fetches the existing proxy ports configured in the
    58  	// datapath. Used early in bootstrap to reopen proxy ports.
    59  	GetProxyPorts() map[string]uint16
    60  
    61  	// InstallNoTrackRules is explicitly called when a pod has valid
    62  	// "policy.cilium.io/no-track-port" annotation.  When
    63  	// InstallNoConntrackIptRules flag is set, a super set of v4 NOTRACK
    64  	// rules will be automatically installed upon agent bootstrap (via
    65  	// function addNoTrackPodTrafficRules) and this function will be
    66  	// skipped.  When InstallNoConntrackIptRules is not set, this function
    67  	// will be executed to install NOTRACK rules.  The rules installed by
    68  	// this function is very specific, for now, the only user is
    69  	// node-local-dns pods.
    70  	InstallNoTrackRules(ip netip.Addr, port uint16)
    71  
    72  	// See comments for InstallNoTrackRules.
    73  	RemoveNoTrackRules(ip netip.Addr, port uint16)
    74  }
    75  
    76  // CompilationLock is a interface over a mutex, it is used by both the loader, daemon
    77  // and endpoint manager to lock the compilation process. This is a bit of a layer violation
    78  // since certain methods on the loader such as CompileAndLoad and CompileOrLoad expect the
    79  // lock to be taken before being called.
    80  //
    81  // Once we have moved header file generation from the endpoint manager into the loader, we can
    82  // remove this interface and have the loader manage the lock internally.
    83  type CompilationLock interface {
    84  	Lock()
    85  	Unlock()
    86  	RLock()
    87  	RUnlock()
    88  }