API Endpoints for cilium/cilium
Documentation Page: Defined Routes in Cilium Codebase
This documentation addresses the routes defined within the Cilium codebase, examining the structures and functions relevant to routing, along with practical code examples that provide insights into the routing mechanisms configured.
Overview
Cilium incorporates various routing functionalities that enable the integration of networking services with the broader Kubernetes ecosystem. The routes managed in Cilium span BGP routes, egress routing, SRv6, and kernel-level routing configurations, and are primarily defined across different files in the codebase.
Identifying Defined Routes
Defined routes can be categorized based on their context and use-case scenarios. Below are some command references and code snippets illustrating the routes in the Cilium codebase.
Command Line References
The tool cilium-dbg
is used for inspecting various routing functionalities embedded within the Cilium environment:
- StateDB Routes To inspect routing information stored within StateDB:
cilium-dbg statedb routes [flags]
More detail can be found in the documentation:
- Source:
Documentation/cmdref/cilium-dbg_statedb_routes.md
- BGP Routes To list routes in the BGP Control Plane’s Routing Information Bases (RIBs):
cilium-dbg bgp routes [vrouter] [peer|neighbor] [flags]
Detailed usage is documented as follows:
- Source:
Documentation/cmdref/cilium-dbg_bgp_routes.md
- SRv6 Routing Rules To manage SRv6 routing rules:
cilium-dbg bpf srv6 [flags]
Refer to the detailed documentation:
- Source:
Documentation/cmdref/cilium-dbg_bpf_srv6.md
Code Examples
Routing Structures
- Routing Rules Specification
The
Rule
type in Cilium encapsulates the specifications for an IP routing rule:
type Rule struct {
Priority int
Mark int
Mask int
From *net.IPNet
To *net.IPNet
Table int
Protocol uint8
}
Source: pkg/datapath/linux/route/route_linux.go
- Route Filtering
Filtering mechanisms for routing can be observed through the function
listRulesAndRoutes
, which retrieves current routing rules and associated routes:
func listRulesAndRoutes(c *C, family int) ([]netlink.Rule, []netlink.Route) {
rules, err := route.ListRules(family, nil)
c.Assert(err, IsNil)
// Filter routes by table
var routes []netlink.Route
for _, r := range rules {
rr, err := netlink.RouteListFiltered(family, &netlink.Route{
Table: r.Table,
}, netlink.RT_FILTER_TABLE)
c.Assert(err, IsNil)
routes = append(routes, rr...)
}
return rules, routes
}
Source: pkg/datapath/linux/routing/routing_test.go
- BGP Route Representation
The
Route
type is used to represent a single route within the BGP RIB:
type Route struct {
Prefix string
Paths []*Path
}
Source: pkg/bgpv1/types/bgp.go
Defined Routes in Documentation
In certain scenarios, specific categories of routes are installed as shown in the kube-router documentation example. Three relevant categories are:
- Local PodCIDR: Directs traffic to local pods.
- BGP Route: Instructions for directing pod-to-pod traffic.
- IPIP Tunnel Route: Used when no direct routing path is available.
This information can be referenced from:
- Source:
Documentation/network/kube-router.rst
Conclusion
Understanding the routes defined in the Cilium codebase requires familiarity with various routing constructs and their operational context within the system. The snippet examples and commands provided serve as a guide to navigate and inspect the routing functionalities embedded within the Cilium environment. Further explorations of the source files support an in-depth understanding of how routes are formulated and managed.
Sources
- pkg/datapath/tables/route.go
- pkg/datapath/linux/routing/routing_test.go
- pkg/datapath/linux/route/route_linux.go
- pkg/datapath/linux/devices_controller.go
- pkg/bgpv1/types/bgp.go
- operator/pkg/ciliumenvoyconfig/annotations.go
- api/v1/models/routing.go
- Documentation/network/kube-router.rst
- pkg/datapath/linux/routing/routing.go