networkutils

package
v1.22.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 25 Imported by: 24

Documentation

Overview

Package networkutils is a collection of iptables and netlink functions

Index

Constants

View Source
const (
	// Vlan rule priority
	VlanRulePriority = 10

	// Rule priority for traffic destined to pod IP
	ToContainerRulePriority = 512

	// From Interface priority for multi-homed pods
	FromInterfaceRulePriority = 1

	// Rule priority for traffic from pod
	FromPodRulePriority = 1536

	// Rule priority for traffic from primary IP on secondary ENI
	FromPrimaryIPofENIRulePriority = 32765
)
View Source
const BaseNumber = 10000

BaseNumber is the base offset for multi-NIC route table IDs. This value is chosen to match the logic in Amazon EC2 net utils: https://github.com/amazonlinux/amazon-ec2-net-utils/blob/v2.7.1/lib/lib.sh#L301

Variables

This section is empty.

Functions

func CalculateOldRouteTableId added in v1.20.3

func CalculateOldRouteTableId(deviceNumber int, networkCardIndex int, maxENIsPerNetworkCard int) int

func CalculatePodIPv4GatewayIP added in v1.20.0

func CalculatePodIPv4GatewayIP(index int) net.IP

func CalculatePodIPv6GatewayIP added in v1.20.0

func CalculatePodIPv6GatewayIP(index int) net.IP

func CalculateRouteTableId added in v1.20.0

func CalculateRouteTableId(deviceNumber int, networkCardIndex int) int

func ContainsNoSuchRule added in v1.13.0

func ContainsNoSuchRule(err error) bool

func GenerateContainerVethName added in v1.20.0

func GenerateContainerVethName(defaultIfName string, prefix string, index int) string

Generates the interface name inside the pod namespace

func GeneratePodHostVethName added in v1.12.0

func GeneratePodHostVethName(prefix string, podNamespace string, podName string, index int) string

GeneratePodHostVethName generates the name for Pod's host-side veth device. The veth name is generated in a way that aligns with the value expected by Calico for NetworkPolicy enforcement.

func GeneratePodHostVethNameSuffix added in v1.12.0

func GeneratePodHostVethNameSuffix(podNamespace string, podName string) string

GeneratePodHostVethNameSuffix generates the name suffix for Pod's hostVeth.

func GetConfigForDebug added in v1.2.0

func GetConfigForDebug() map[string]interface{}

GetConfigForDebug returns the active values of the configuration env vars (for debugging purposes).

func GetEthernetMTU added in v1.6.1

func GetEthernetMTU() int

GetEthernetMTU returns the MTU value to program for ENIs. Note that the value was already validated during container initialization.

func GetIPv4Gateway added in v1.16.0

func GetIPv4Gateway(eniSubnetCIDR *net.IPNet) net.IP

func GetIPv6Gateway added in v1.16.0

func GetIPv6Gateway() net.IP

On AWS/VPC, the subnet gateway can always be reached at FE80:EC2::1 https://aws.amazon.com/about-aws/whats-new/2022/11/ipv6-subnet-default-gateway-router-multiple-addresses/

func GetPodMTU added in v1.16.4

func GetPodMTU(podMTU string) int

GetPodMTU validates the pod MTU value. If an invalid value is passed, the default is used.

func IsIPv4 added in v1.20.0

func IsIPv4(ip net.IP) bool

func IsRuleExistsError added in v1.13.0

func IsRuleExistsError(err error) bool

func NetLinkRuleDelAll added in v1.13.0

func NetLinkRuleDelAll(nl netlinkwrapper.NetLink, rule *netlink.Rule) error

NetLinkRuleDelAll deletes all matching route rules (instead of only first instance).

Types

type NetworkAPIs

type NetworkAPIs interface {
	// SetupNodeNetwork performs node level network configuration
	SetupHostNetwork(vpcCIDRs []string, primaryMAC string, primaryAddr *net.IP, enablePodENI bool,
		v6Enabled bool) error
	// SetupENINetwork performs ENI level network configuration. Not needed on the primary ENI
	SetupENINetwork(eniIP string, eniMAC string, networkCard int, eniSubnetCIDR string, maxENIPerNIC int, isTrunkENI bool, routeTableID int, isRuleConfigured bool) error
	// UpdateHostIptablesRules updates the nat table iptables rules on the host
	UpdateHostIptablesRules(vpcCIDRs []string, primaryMAC string, primaryAddr *net.IP, v6Enabled bool) error
	CleanUpStaleAWSChains(v4Enabled, v6Enabled bool) error
	UseExternalSNAT() bool
	GetExcludeSNATCIDRs() []string
	GetExternalServiceCIDRs() []string
	GetRuleList(v6enabled bool) ([]netlink.Rule, error)
	GetRuleListBySrc(ruleList []netlink.Rule, src net.IPNet) ([]netlink.Rule, error)
	UpdateRuleListBySrc(ruleList []netlink.Rule, src net.IPNet) error
	UpdateExternalServiceIpRules(ruleList []netlink.Rule, externalIPs []string) error
	GetLinkByMac(mac string, retryInterval time.Duration) (netlink.Link, error)
	DeleteRulesBySrc(eniIP string, v6enabled bool) error
	GetRouteTableNumberForENI(networkCard int, eniIP string, deviceNumber int, maxENIsPerNetworkCard int, isV6 bool) (int, bool, error)
}

NetworkAPIs defines the host level and the ENI level network related operations

func New

func New() NetworkAPIs

New creates a linuxNetwork object

Directories

Path Synopsis
Package mock_networkutils is a generated GoMock package.
Package mock_networkutils is a generated GoMock package.

Jump to

Keyboard shortcuts

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