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:

  1. 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
  1. 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
  1. 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

  1. 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

  1. 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

  1. 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.