infra: override default route when running in a netns#627
Conversation
When grout runs inside a k8s pod, the default route installed by k8s has priority over grout's own default route (which uses metric UINT32_MAX). This causes TCP connections to fail over grout. Detect when grout is running in a network namespace by comparing /proc/self/ns/net and /proc/1/ns/net inodes, and by checking if PID 1 is a known host init process (systemd, init, openrc-init). When a netns is detected (or forced via -n), install the default route with metric 0 and NLM_F_REPLACE to take over the existing one. Link: DPDK#625 Signed-off-by: Robin Jarry <rjarry@redhat.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR introduces a Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When grout runs inside a k8s pod, the default route installed by k8s has priority over grout's own default route (which uses metric UINT32_MAX). This causes TCP connections to fail over grout.
Detect when grout is running in a network namespace by comparing /proc/self/ns/net and /proc/1/ns/net inodes, and by checking if PID 1 is a known host init process (systemd, init, openrc-init). When a netns is detected (or forced via -n), install the default route with metric 0 and NLM_F_REPLACE to take over the existing one.
Link: #625
Overview
Adds automatic detection and handling of network namespaces to override the default route with metric 0 and
NLM_F_REPLACEflag, addressing TCP connection failures when grout runs in Kubernetes pods where the default route has higher priority than grout's UINT32_MAX metric default route.Changes
Network namespace detection (
main/main.c)is_in_netns()that compares inodes of/proc/self/ns/netand/proc/1/ns/net; if different, grout is in a distinct network namespace. When inodes match, further checks if PID 1's command name is one of the known host init processes (systemd, init, openrc-init); if not, assumes a network namespace.override_default_routewhenis_in_netns()returns true and the flag was not explicitly set via CLI.CLI option (
main/main.c,main/config.h,docs/grout.8.scdoc)-n/--override-default-routecommand-line option to force override behavior.Netlink behavior (
modules/infra/control/netlink.c)override_default_routeis enabled and adding routes toRT_TABLE_MAIN: usesNLM_F_CREATE | NLM_F_REPLACEflags (allows replacement of existing routes).override_default_routeis disabled: usesNLM_F_CREATE | NLM_F_EXCLflags (original behavior).override_default_routeis disabled; omitted when enabled to allow metric 0 to take precedence.