config

package
v3.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CNIServerSocket      = "/var/run/calico/cni-server.sock"
	FelixDataplaneSocket = "/var/run/calico/felix-dataplane.sock"
	VppAPISocket         = "/var/run/vpp/vpp-api.sock"
	VppManagerInfoFile   = "/var/run/vpp/vppmanagerinfofile"
	CalicoVppPidFile     = "/var/run/vpp/calico_vpp.pid"
	CalicoVppVersionFile = "/etc/calicovppversion"

	DefaultVXLANVni      = 4096
	DefaultVXLANPort     = 4789
	DefaultWireguardPort = 51820

	VppConfigFile     = "/etc/vpp/startup.conf"
	VppConfigExecFile = "/etc/vpp/startup.exec"
	VppPath           = "/usr/bin/vpp"
	VppNetnsName      = "calico-vpp-ns"
	VppSigKillTimeout = 2
	DefaultEncapSize  = 60 // Used to lower the MTU of the routes to the cluster

	DefaultPhysicalNetworkName = ""

	// BaseVppSideHardwareAddress is the base hardware address of VPP side of the HostPunt
	// tap interface. It is used to generate hardware addresses for each uplink interface.
	BaseVppSideHardwareAddress = "02:ca:11:c0:fd:00"
	// CniServerStateFileVersion is the version of the CNI server state file
	// it is used to ensure compatibility when reloading data
	CniServerStateFileVersion = 10
	// MaxAPITagLen is the limit number of character allowed in VPP API tags
	MaxAPITagLen = 63
	// VrfTagHashLen is the number of hash charatecters (b64) of the name
	// to use in the tag prefix of VRFs
	VrfTagHashLen = 8

	MemifPortAnnotation string = "cni.projectcalico.org/vppExtraMemifPorts"
	VclAnnotation       string = "cni.projectcalico.org/vppVcl"
	IfSpecAnnotation    string = "cni.projectcalico.org/vppInterfacesSpec"
	IfSpecPBLAnnotation string = "cni.projectcalico.org/vppExtraMemifSpec"
	SpoofAnnotation     string = "cni.projectcalico.org/AllowedSourcePrefixes"

	KeepOriginalPacketAnnotation string = "cni.projectcalico.org/vppKeepOriginalPacket"
	HashConfigAnnotation         string = "cni.projectcalico.org/vppHashConfig"
	LBTypeAnnotation             string = "cni.projectcalico.org/vppLBType"
)
View Source
const (
	DriverUioPciGeneric = "uio_pci_generic"
	DriverVfioPci       = "vfio-pci"
	DriverVirtioPci     = "virtio-pci"
	DriverI40E          = "i40e"
	DriverICE           = "ice"
	DriverMLX5Core      = "mlx5_core"
	DriverVmxNet3       = "vmxnet3"
)
View Source
const (
	Ready    vppManagerStatus = "ready"
	Starting vppManagerStatus = "starting"
)

Variables

View Source
var (
	CniServerStateFilename = fmt.Sprintf(
		"/var/run/vpp/calicovpp_state.v%d.json",
		CniServerStateFileVersion,
	)
	// fake constants for place where we need a pointer to true or false
	True  = true
	False = false

	NodeName    = RequiredStringEnvVar("NODENAME")
	LogLevel    = EnvVar("CALICOVPP_LOG_LEVEL", logrus.InfoLevel, logrus.ParseLevel)
	BGPLogLevel = EnvVar("CALICOVPP_BGP_LOG_LEVEL", apipb.SetLogLevelRequest_INFO, BGPLogLevelParse)

	ServiceCIDRs                     = PrefixListEnvVar("SERVICE_PREFIX")
	IPSecIkev2Psk                    = StringEnvVar("CALICOVPP_IPSEC_IKEV2_PSK", "")
	CalicoVppDebug                   = JSONEnvVar("CALICOVPP_DEBUG", &CalicoVppDebugConfigType{})
	CalicoVppInterfaces              = JSONEnvVar("CALICOVPP_INTERFACES", &CalicoVppInterfacesConfigType{})
	CalicoVppFeatureGates            = JSONEnvVar("CALICOVPP_FEATURE_GATES", &CalicoVppFeatureGatesConfigType{})
	CalicoVppIpsec                   = JSONEnvVar("CALICOVPP_IPSEC", &CalicoVppIpsecConfigType{})
	CalicoVppSrv6                    = JSONEnvVar("CALICOVPP_SRV6", &CalicoVppSrv6ConfigType{})
	CalicoVppInitialConfig           = JSONEnvVar("CALICOVPP_INITIAL_CONFIG", &CalicoVppInitialConfigConfigType{})
	CalicoVppGracefulShutdownTimeout = EnvVar("CALICOVPP_GRACEFUL_SHUTDOWN_TIMEOUT", 10*time.Second, time.ParseDuration)
	LogFormat                        = StringEnvVar("CALICOVPP_LOG_FORMAT", "")

	/* Deprecated vars */
	/* linux name of the uplink interface to be used by VPP */
	InterfaceVar = StringEnvVar("CALICOVPP_INTERFACE", "")
	/* Driver to consume the uplink with. Leave empty for autoconf */
	NativeDriver = StringEnvVar("CALICOVPP_NATIVE_DRIVER", "")
	SwapDriver   = StringEnvVar("CALICOVPP_SWAP_DRIVER", "")

	/* Bash script template run before getting config
	   from $CALICOVPP_INTERFACE (same as
	   CALICOVPP_HOOK_BEFORE_IF_READ)*/
	InitScriptTemplate = StringEnvVar("CALICOVPP_INIT_SCRIPT_TEMPLATE", "")

	/* Template for VppConfigFile (/etc/vpp/startup.conf)
	   It contains the VPP startup configuration */
	ConfigTemplate = RequiredStringEnvVar("CALICOVPP_CONFIG_TEMPLATE")

	/* Template for VppConfigExecFile (/etc/vpp/startup.exec)
	   It contains the CLI to be executed in vppctl after startup */
	ConfigExecTemplate = StringEnvVar("CALICOVPP_CONFIG_EXEC_TEMPLATE", "")

	//go:embed default_hook.sh
	DefaultHookScript string

	/* Run this before getLinuxConfig() in case this is a script
	 * that's responsible for creating the interface */
	HookScriptBeforeIfRead = StringEnvVar("CALICOVPP_HOOK_BEFORE_IF_READ", DefaultHookScript) // InitScriptTemplate
	/* Bash script template run just after getting config
	   from $CALICOVPP_INTERFACE & before starting VPP */
	HookScriptBeforeVppRun = StringEnvVar("CALICOVPP_HOOK_BEFORE_VPP_RUN", DefaultHookScript) // InitPostIfScriptTemplate
	/* Bash script template run after VPP has started */
	HookScriptVppRunning = StringEnvVar("CALICOVPP_HOOK_VPP_RUNNING", DefaultHookScript) // FinalizeScriptTemplate
	/* Bash script template run when VPP stops gracefully */
	HookScriptVppDoneOk = StringEnvVar("CALICOVPP_HOOK_VPP_DONE_OK", DefaultHookScript)
	/* Bash script template run when VPP stops with an error */
	HookScriptVppErrored = StringEnvVar("CALICOVPP_HOOK_VPP_ERRORED", DefaultHookScript)

	AllHooks = []*string{
		HookScriptBeforeIfRead,
		HookScriptBeforeVppRun,
		HookScriptVppRunning,
		HookScriptVppDoneOk,
		HookScriptVppErrored,
	}

	Info = &VppManagerInfo{}

	// VppHostPuntFakeGatewayAddress is the fake gateway we use with a static neighbor
	// in the punt table to route punted packets to the host
	VppHostPuntFakeGatewayAddress = net.ParseIP("169.254.0.1")
)

Functions

func AddrEnvVar

func AddrEnvVar(varName string, defaultValue net.IP) *net.IP

func AddrListEnvVar

func AddrListEnvVar(varName string) *[]net.IP

func BGPLogLevelParse added in v3.26.0

func BGPLogLevelParse(lvl string) (apipb.SetLogLevelRequest_Level, error)

func BoolEnvVar

func BoolEnvVar(varName string, defaultValue bool) *bool

func DefaultToPtr added in v3.26.3

func DefaultToPtr[T any](ptr *T, defaultV T) *T

func EnvVar

func EnvVar[T any](varName string, defaultValue T, parser func(string) (T, error)) *T

func HandleUsr2Signal added in v3.31.0

func HandleUsr2Signal(ctx context.Context, log *logrus.Entry)

HandleUsr2Signal implements the USR2 signal that outputs the covarge data, provided the binary is compiled with -cover and GOCOVERDIR is set. This allows us to not require a proper binary termination in order to get coverage data.

func HashText added in v3.31.0

func HashText(text string) string

8 base64 character hash

func IntEnvVar

func IntEnvVar(varName string, defaultValue int) *int

func JSONEnvVar added in v3.29.1

func JSONEnvVar[T any](varName string, defaultValue T) *T

JSONEnvVar allows to declare envvars containing structs formatted as json * defaultValue should be a pointer to a SomeStructType * this returns a **SomeStructType * if SomeStructType implements Validable (pointer receiver) it will be run as part of the parsing process, allowing to set defaults.

func LoadConfig

func LoadConfig(log *logrus.Logger) (err error)

func LoadConfigSilent

func LoadConfigSilent(log *logrus.Logger) (err error)

func ParseAllEnvVars

func ParseAllEnvVars() []error

func ParseEnvVars

func ParseEnvVars(varNames ...string) []error

func PrefixEnvVar

func PrefixEnvVar(varName string) *net.IPNet

func PrefixListEnvVar

func PrefixListEnvVar(varName string) *[]*net.IPNet

func PrintAgentConfig

func PrintAgentConfig(log *logrus.Logger)

func PrintEnvVarConfig

func PrintEnvVarConfig(log *logrus.Logger)

func RequiredAddrEnvVar

func RequiredAddrEnvVar(varName string) *net.IP

func RequiredAddrListEnvVar

func RequiredAddrListEnvVar(varName string) *[]net.IP

func RequiredEnvVar

func RequiredEnvVar[T any](varName string, defaultValue T, parser func(string) (T, error)) *T

func RequiredPrefixEnvVar

func RequiredPrefixEnvVar(varName string) *net.IPNet

func RequiredPrefixListEnvVar

func RequiredPrefixListEnvVar(varName string) *[]*net.IPNet

func RequiredStringEnvVar

func RequiredStringEnvVar(varName string) *string

func RunHook added in v3.26.0

func RunHook(hookScript *string, hookName string, params *VppManagerParams, log *logrus.Logger)

func StringEnvVar

func StringEnvVar(varName string, defaultValue string) *string

func StringListEnvVar

func StringListEnvVar(varName string, defaultValue []string) *[]string

func TemplateScriptReplace

func TemplateScriptReplace(input string, params *VppManagerParams, conf []*LinuxInterfaceState) (template string, err error)

func TruncateStr added in v3.31.0

func TruncateStr(text string, size int) string

func Uint16EnvVar

func Uint16EnvVar(varName string, defaultValue uint16) *uint16

func Uint32EnvVar

func Uint32EnvVar(varName string, defaultValue uint32) *uint32

Types

type CalicoVppDebugConfigType

type CalicoVppDebugConfigType struct {
	ServicesEnabled         *bool `json:"servicesEnabled,omitempty"`
	GSOEnabled              *bool `json:"gsoEnabled,omitempty"`
	SpreadTxQueuesOnWorkers *bool `json:"spreadTxQueuesOnWorkers,omitempty"`
}

func GetCalicoVppDebug

func GetCalicoVppDebug() *CalicoVppDebugConfigType

func (*CalicoVppDebugConfigType) String

func (cfg *CalicoVppDebugConfigType) String() string

func (*CalicoVppDebugConfigType) Validate

func (cfg *CalicoVppDebugConfigType) Validate() (err error)

type CalicoVppFeatureGatesConfigType

type CalicoVppFeatureGatesConfigType struct {
	MemifEnabled      *bool `json:"memifEnabled,omitempty"`
	VCLEnabled        *bool `json:"vclEnabled,omitempty"`
	MultinetEnabled   *bool `json:"multinetEnabled,omitempty"`
	SRv6Enabled       *bool `json:"srv6Enabled,omitempty"`
	IPSecEnabled      *bool `json:"ipsecEnabled,omitempty"`
	PrometheusEnabled *bool `json:"prometheusEnabled,omitempty"`
}

func GetCalicoVppFeatureGates

func GetCalicoVppFeatureGates() *CalicoVppFeatureGatesConfigType

func (*CalicoVppFeatureGatesConfigType) String

func (*CalicoVppFeatureGatesConfigType) Validate

func (cfg *CalicoVppFeatureGatesConfigType) Validate() (err error)

type CalicoVppInitialConfigConfigType

type CalicoVppInitialConfigConfigType struct {
	VppStartupSleepSeconds int `json:"vppStartupSleepSeconds"`
	// CorePattern is the pattern to use for VPP corefiles.
	// Usually "/var/lib/vpp/vppcore.%e.%p"
	CorePattern      string `json:"corePattern"`
	ExtraAddrCount   int    `json:"extraAddrCount"`
	IfConfigSavePath string `json:"ifConfigSavePath"`
	// DefaultGWs Comma separated list of IPs to be
	// configured in VPP as default GW
	DefaultGWs string `json:"defaultGWs"`
	// RedirectToHostRules is a list of rules for redirecting
	// traffic to host. This is used for DNS support in kind
	RedirectToHostRules []RedirectToHostRulesConfigType `json:"redirectToHostRules"`
	// PrometheusListenEndpoint is the endpoint on which prometheus will
	// listen and report stats. By default curl http://localhost:8888/metrics
	PrometheusListenEndpoint string `json:"prometheusListenEndpoint"`
	// PrometheusRecordMetricInterval is the interval at which we update the
	// prometheus stats polling VPP stats segment. Default to 5 seconds
	PrometheusRecordMetricInterval *time.Duration `json:"prometheusRecordMetricInterval"`
	// IP4NeighborsMaxNumber is the maximum number of allowed IPv4 neighbors
	// VPP allows. Defaults to 50k
	IP4NeighborsMaxNumber *uint32 `json:"ip4NeighborsMaxNumber"`
	// IP6NeighborsMaxNumber is the maximum number of allowed IPv4 neighbors
	// VPP allows. Defaults to 50k
	IP6NeighborsMaxNumber *uint32 `json:"ip6NeighborsMaxNumber"`
	// IP4NeighborsMaxAge is the maximum age of IPv4 neighbors in seconds
	// ARPs will be issued after said interval. Be aware ARPs in VPP are
	// issued using a pre-existing vlib buffer hence dropping a packet
	// defaults to 30 seconds. Use 0 to disable.
	IP4NeighborsMaxAge *uint32 `json:"ip4NeighborsMaxAge"`
	// IP6NeighborsMaxAge is the maximum age of IPv4 neighbors in seconds
	// ARPs will be issued after said interval. Be aware ARPs in VPP are
	// issued using a pre-existing vlib buffer hence dropping a packet
	// defaults to 30 seconds. Use 0 to disable.
	IP6NeighborsMaxAge *uint32 `json:"ip6NeighborsMaxAge"`
	// PrometheusStatsPrefix is the prefix to use for Prometheus metrics
	// Defaults to "cni.projectcalico.vpp."
	PrometheusStatsPrefix string `json:"prometheusStatsPrefix"`
	// HealthCheckPort is the port on which the health check HTTP server listens
	// Defaults to 9090
	HealthCheckPort *uint32 `json:"healthCheckPort"`
}

func GetCalicoVppInitialConfig

func GetCalicoVppInitialConfig() *CalicoVppInitialConfigConfigType

func (*CalicoVppInitialConfigConfigType) GetDefaultGWs

func (cfg *CalicoVppInitialConfigConfigType) GetDefaultGWs() (gws []net.IP, err error)

func (*CalicoVppInitialConfigConfigType) String

func (*CalicoVppInitialConfigConfigType) Validate

func (cfg *CalicoVppInitialConfigConfigType) Validate() (err error)

type CalicoVppInterfacesConfigType

type CalicoVppInterfacesConfigType struct {
	DefaultPodIfSpec *InterfaceSpec        `json:"defaultPodIfSpec,omitempty"`
	MaxPodIfSpec     *InterfaceSpec        `json:"maxPodIfSpec,omitempty"`
	VppHostTapSpec   *InterfaceSpec        `json:"vppHostTapSpec,omitempty"`
	UplinkInterfaces []UplinkInterfaceSpec `json:"uplinkInterfaces,omitempty"`
}

func GetCalicoVppInterfaces

func GetCalicoVppInterfaces() *CalicoVppInterfacesConfigType

func (*CalicoVppInterfacesConfigType) String

func (cfg *CalicoVppInterfacesConfigType) String() string

func (*CalicoVppInterfacesConfigType) Validate

func (cfg *CalicoVppInterfacesConfigType) Validate() (err error)

type CalicoVppIpsecConfigType

type CalicoVppIpsecConfigType struct {
	CrossIpsecTunnels        *bool `json:"crossIPSecTunnels,omitempty"`
	IpsecNbAsyncCryptoThread int   `json:"nbAsyncCryptoThreads"`
	ExtraAddresses           int   `json:"extraAddresses"`
}

func GetCalicoVppIpsec

func GetCalicoVppIpsec() *CalicoVppIpsecConfigType

func (*CalicoVppIpsecConfigType) GetIpsecAddressCount

func (cfg *CalicoVppIpsecConfigType) GetIpsecAddressCount() int

func (*CalicoVppIpsecConfigType) GetIpsecNbAsyncCryptoThread

func (cfg *CalicoVppIpsecConfigType) GetIpsecNbAsyncCryptoThread() int

func (*CalicoVppIpsecConfigType) String

func (cfg *CalicoVppIpsecConfigType) String() string

func (*CalicoVppIpsecConfigType) Validate

func (cfg *CalicoVppIpsecConfigType) Validate() (err error)

type CalicoVppSrv6ConfigType

type CalicoVppSrv6ConfigType struct {
	LocalsidPool string `json:"localsidPool"`
	PolicyPool   string `json:"policyPool"`
}

func GetCalicoVppSrv6

func GetCalicoVppSrv6() *CalicoVppSrv6ConfigType

func (*CalicoVppSrv6ConfigType) String

func (cfg *CalicoVppSrv6ConfigType) String() string

func (*CalicoVppSrv6ConfigType) Validate

func (cfg *CalicoVppSrv6ConfigType) Validate() (err error)

type EnvVarParser

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

type InterfaceSpec

type InterfaceSpec struct {
	NumRxQueues int   `json:"rx"`
	NumTxQueues int   `json:"tx"`
	RxQueueSize int   `json:"rxqsz"`
	TxQueueSize int   `json:"txqsz"`
	IsL3        *bool `json:"isl3"`
	/* "interrupt" "adaptive" or "polling" mode */
	RxMode types.RxMode `json:"rxMode"`
}

func (*InterfaceSpec) GetBuffersNeeded

func (i *InterfaceSpec) GetBuffersNeeded() uint64

func (*InterfaceSpec) GetIsL3

func (i *InterfaceSpec) GetIsL3(isMemif bool) bool

func (*InterfaceSpec) GetRxModeWithDefault

func (i *InterfaceSpec) GetRxModeWithDefault(defaultRxMode types.RxMode) types.RxMode

func (*InterfaceSpec) String

func (i *InterfaceSpec) String() string

func (*InterfaceSpec) Validate

func (i *InterfaceSpec) Validate(maxIfSpec *InterfaceSpec) error

type KernelVersion

type KernelVersion struct {
	Kernel int
	Major  int
	Minor  int
	Patch  int
}

func (*KernelVersion) IsAtLeast

func (ver *KernelVersion) IsAtLeast(other *KernelVersion) bool

func (*KernelVersion) String

func (ver *KernelVersion) String() string

type LinuxInterfaceState

type LinuxInterfaceState struct {
	PciID         string
	Driver        string
	IsUp          bool
	Addresses     []netlink.Addr
	Routes        []netlink.Route
	HardwareAddr  net.HardwareAddr
	PromiscOn     bool
	NumTxQueues   int
	NumRxQueues   int
	DoSwapDriver  bool
	Hasv4         bool
	Hasv6         bool
	NodeIP4       string
	NodeIP6       string
	Mtu           int
	InterfaceName string
	IsTunTap      bool
	IsVeth        bool
}

func (*LinuxInterfaceState) AddressString

func (c *LinuxInterfaceState) AddressString() string

func (*LinuxInterfaceState) RouteString

func (c *LinuxInterfaceState) RouteString() string

func (*LinuxInterfaceState) SortRoutes

func (c *LinuxInterfaceState) SortRoutes()

SortRoutes sorts the route slice by dependency order, so we can then add them in the order of the slice without issues

type PhysicalNetwork added in v3.26.0

type PhysicalNetwork struct {
	VrfID    uint32
	PodVrfID uint32
}

type RedirectToHostRulesConfigType added in v3.26.2

type RedirectToHostRulesConfigType struct {
	Port uint16 `json:"port,omitempty"`
	IP   string `json:"ip,omitempty"`
	/* "tcp", "udp",... */
	Proto types.IPProto `json:"proto,omitempty"`
}

type UnsafeNoIommuMode added in v3.27.0

type UnsafeNoIommuMode string

UnsafeNoIommuMode represents the content of the /sys/module/vfio/parameters/enable_unsafe_noiommu_mode file. The 'disabled' value is used when no iommu is available in the environment.

const (
	VfioUnsafeNoIommuModeYES      UnsafeNoIommuMode = "Y"
	VfioUnsafeNoIommuModeNO       UnsafeNoIommuMode = "N"
	VfioUnsafeNoIommuModeDISABLED UnsafeNoIommuMode = "disabled"
)

type UplinkInterfaceSpec

type UplinkInterfaceSpec struct {
	InterfaceSpec
	IsMain              bool              `json:"isMain"`
	PhysicalNetworkName string            `json:"physicalNetworkName"`
	InterfaceName       string            `json:"interfaceName"`
	VppDriver           string            `json:"vppDriver"`
	NewDriverName       string            `json:"newDriver"`
	Annotations         map[string]string `json:"annotations"`
	// Mtu is the User specified MTU for uplink & the tap
	Mtu       int    `json:"mtu"`
	SwIfIndex uint32 `json:"-"`
	// contains filtered or unexported fields
}

func (*UplinkInterfaceSpec) GetVppSideHardwareAddress added in v3.27.0

func (u *UplinkInterfaceSpec) GetVppSideHardwareAddress() net.HardwareAddr

func (*UplinkInterfaceSpec) SetUplinkInterfaceIndex added in v3.27.0

func (u *UplinkInterfaceSpec) SetUplinkInterfaceIndex(uplinkInterfaceIndex int)

func (*UplinkInterfaceSpec) String

func (u *UplinkInterfaceSpec) String() string

func (*UplinkInterfaceSpec) Validate

func (u *UplinkInterfaceSpec) Validate(maxIfSpec *InterfaceSpec) (err error)

type UplinkStatus

type UplinkStatus struct {
	SwIfIndex           uint32
	TapSwIfIndex        uint32
	LinkIndex           int
	Name                string
	IsMain              bool
	Mtu                 int
	PhysicalNetworkName string

	// FakeNextHopIP4 is the computed next hop for v4 routes added
	// in linux to (ServiceCIDR, podCIDR, etc...) towards this interface
	FakeNextHopIP4 net.IP
	// FakeNextHopIP6 is the computed next hop for v6 routes added
	// in linux to (ServiceCIDR, podCIDR, etc...) towards this interface
	FakeNextHopIP6 net.IP
}

type Validable

type Validable interface {
	Validate() error
}

type VppManagerInfo

type VppManagerInfo struct {
	Status         vppManagerStatus
	UplinkStatuses map[string]UplinkStatus
	PhysicalNets   map[string]PhysicalNetwork
}

func (*VppManagerInfo) GetMainSwIfIndex

func (i *VppManagerInfo) GetMainSwIfIndex() uint32

type VppManagerParams

type VppManagerParams struct {
	UplinksSpecs []UplinkInterfaceSpec
	/* Capabilities */
	LoadedDrivers                      map[string]bool
	KernelVersion                      *KernelVersion
	AvailableHugePages                 int
	InitialVfioEnableUnsafeNoIommuMode UnsafeNoIommuMode

	NodeAnnotations map[string]string
}

Jump to

Keyboard shortcuts

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