- .devcontainer
- .github
- .nvim
- .vscode
-
Documentation
-
_api
-
_exts
-
_static
-
_templates
-
bpf
-
cmdref
-
community
-
configuration
-
contributing
-
gettingstarted
-
images
-
installation
-
internals
-
network
-
observability
-
operations
-
overview
-
requirements-min
-
robots
-
security
- .dockerignore
- .gitignore
- .readthedocs.yaml
- Dockerfile
- Makefile
- api.rst
- beta.rst
- cheatsheet.rst
- check-build.sh
- check-cmdref.sh
- check-codeowners.sh
- check-crd-compat-table.sh
- check-crdlist.sh
- check-examples.sh
- check-flaggen.sh
- check-helmvalues.sh
- check-links.sh
- codeowners.rst
- conf.py
- crdlist.rst
- further_reading.rst
- glossary.rst
- grpcapi.rst
- helm-reference.rst
- helm-values.rst
- helm-values.tmp.tmpl
- index.rst
- kvstore.rst
- requirements.txt
- runtime.txt
- spelling_wordlist.txt
- update-cmdref.sh
- update-codeowners.sh
- update-docs-builder-image.sh
- update-spelling_wordlist.sh
- yaml.config
-
_api
- api
- bpf
- bugtool
- cilium-dbg
- cilium-health
- clustermesh-apiserver
- contrib
- daemon
-
examples
-
crds
-
hubble
-
kubernetes
-
kubernetes-cassandra
-
kubernetes-dns
-
kubernetes-egress-gateway
-
kubernetes-es
-
kubernetes-external-ips
-
kubernetes-grpc
-
kubernetes-ip-masq-agent
-
kubernetes-istio
-
kubernetes-kafka
-
kubernetes-local-redirect
-
kubernetes-memcached
-
kubernetes-tls-inspection
-
minikube
-
misc
-
policies
- valid-labels.lpc
-
crds
- hack
- hubble-relay
- images
- install
- operator
-
pkg
-
alibabacloud
-
alignchecker
-
allocator
-
annotation
-
api
-
auth
-
aws
-
azure
-
backoff
-
bgp
-
bgpv1
-
bpf
-
byteorder
-
cgroups
-
checker
-
cidr
-
ciliumenvoyconfig
-
cleanup
-
client
-
clustermesh
-
command
-
common
-
comparator
-
completion
-
components
-
container
-
controller
-
counter
-
crypto
-
datapath
-
debug
-
defaults
-
ebpf
-
egressgateway
-
elf
-
endpoint
-
endpointcleanup
-
endpointmanager
-
endpointstate
-
envoy
-
eventqueue
-
flowdebug
-
fqdn
-
fswatcher
-
gops
-
health
-
healthv2
-
hive
-
hubble
-
iana
-
identity
-
idpool
-
inctimer
-
ip
-
ipalloc
-
ipam
-
ipcache
-
ipmasq
-
k8s
-
kvstore
-
l2announcer
-
labels
-
labelsfilter
-
launcher
-
loadbalancer
-
loadinfo
-
lock
-
logging
-
mac
-
maglev
-
maps
-
math
-
mcastmanager
-
metrics
-
monitor
-
mountinfo
-
mtu
-
multicast
-
murmur3
-
netns
-
node
-
nodediscovery
-
option
-
pidfile
-
policy
-
pprof
-
promise
-
proxy
-
rand
-
rate
-
recorder
-
redirectpolicy
-
resiliency
-
revert
-
safeio
-
safetime
-
service
-
signal
-
slices
-
socketlb
-
source
-
spanstat
-
statedb
-
status
-
testutils
-
time
-
trigger
-
tuple
-
types
-
u8proto
-
version
-
versioncheck
-
wireguard
-
alibabacloud
- plugins
-
test
-
bigtcp
-
bpf
-
config
-
consul
-
controlplane
-
eks
-
envoy
-
fuzzing
-
ginkgo-ext
-
gke
-
helpers
-
k8s
-
l4lb
-
logger
-
nat46x64
-
packet
-
provision
-
runtime
-
standalone
-
verifier
-
vtep
- Makefile
- README.md
- Vagrantfile
- archive_test_results.sh
- archive_test_results_eks.sh
- get-gh-comment-info.py
- get-vagrant-kubeconfig.sh
- kubernetes-test.sh
- post_build_agent.sh
- print-node-ip.sh
- test_suite_test.go
- vagrant-ci-start.sh
- vagrant-local-create-box.sh
- vagrant-local-start-runtime.sh
- vagrant-local-start.sh
- vagrant_cleanup.sh
-
bigtcp
- tools
- vendor
- .authors.aux
- .clang-format
- .clomonitor.yml
- .gitattributes
- .gitignore
- .golangci.yaml
- .mailmap
- .openvex.json
- AUTHORS
- CODEOWNERS
- CODE_OF_CONDUCT.md
- CONTRIBUTING.md
- FURTHER_READINGS.rst
- LICENSE
- MAINTAINERS.md
- Makefile
- Makefile.defs
- Makefile.docker
- Makefile.kind
- Makefile.quiet
- README.rst
- SECURITY-INSIGHTS.yml
- SECURITY.md
- USERS.md
- VERSION
- Vagrantfile
- go.mod
- go.sum
- netlify.toml
- stable.txt
- vagrant_box_defaults.rb
Explanation
This code in routing.go
from the Cilium repository deals with configuring and deleting routing rules and routes for endpoints in an ENI or Azure IPAM environment. It’s primarily concerned with managing egress and ingress traffic for endpoints, directing it through the correct interfaces and routes.
Key Concepts:
- ENI (Elastic Network Interface): A virtual network interface in AWS, used for connecting instances to a VPC.
- IPAM (IP Address Management): A system for managing IP addresses within a network.
- Routing Table: A table that maps network destinations to the next hop for sending packets.
- Rule: A rule in the routing table that determines how packets are handled based on their source, destination, and other criteria.
- Nexthop: The next hop router or gateway that a packet should be sent to.
- Masquerade: A mechanism where the source IP of a packet is changed to the IP of the router before sending it out.
Configure
Function:
This function configures the routing rules and routes needed for an endpoint. It takes the endpoint’s IP address (ip
), the MTU of the interface (mtu
), a compatibility flag (compat
), and a flag indicating whether the IP is a host IP (host
).
- Validation: It checks if the provided IP is an IPv4 address.
- Interface Index: It retrieves the interface index (
ifindex
) for the interface corresponding to the provided MAC address (info.MasterIfMAC
). - Ingress Rule: If the IP is not a host IP, it creates an ingress rule in the
main
routing table, directing all traffic to the endpoint’s IP through the interface. - Egress Priority and Table: Determines the egress priority and routing table ID based on the
compat
flag. Ifcompat
is true, it uses the older egress priority (linux_defaults.RulePriorityEgress
) and the interface index as the table ID. Otherwise, it uses the newer egress priority (linux_defaults.RulePriorityEgressv2
) and a computed table ID based on the interface number. - Egress Rule: Based on the
Masquerade
flag and the IPAM mode, it creates egress rules in the specified routing table. For ENI IPAM, it creates a rule for each CIDR configured for the VPC. Otherwise, it creates a rule for all traffic from the endpoint. - Nexthop Routes: Creates two routes to the VPC or subnet gateway:
- A /32 route to ensure L2 traffic doesn’t get misdirected.
- A default route to the gateway for all other destinations.
Delete
Function:
This function removes the ingress and egress rules created by Configure
for an endpoint. It takes the endpoint’s IP address (ip
) and a compatibility flag (compat
).
- Validation: Checks if the provided IP is an IPv4 address.
- Ingress Rule Deletion: Deletes the ingress rule in the
main
routing table that matches the provided IP. - Egress Rule Deletion: Deletes the egress rules matching the provided IP and priority. It considers the compatibility flag for determining the correct priority.
- Unreachable Route (Optional): If
option.Config.EnableUnreachableRoutes
is enabled, it creates an unreachable route for the old IP to trigger ICMP error messages for clients trying to connect to it. This is meant to prevent blackholing traffic when the IP is reused.
deleteRule
Function:
This helper function deletes a routing rule. It takes a route.Rule
as input, retrieves rules matching the provided parameters, and deletes the rule if only one match is found. If more than one rule matches, it logs a warning and skips deletion.
Other Functions:
retrieveIfIndexFromMAC
: Finds the interface index for a given MAC address, excluding Linux slave devices. It also sets up the interface by setting its MTU and bringing it up.computeTableIDFromIfaceNumber
: Calculates the routing table ID for an ENI based on its interface number.
Overall: This code effectively manages routing rules and routes for endpoints in ENI and Azure IPAM environments, ensuring correct handling of egress and ingress traffic. It’s carefully designed to handle various configurations, including different IPAM modes, masquerading, and compatibility options for egress rule priorities.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph