Skip to content

fix(orchestrator): match the default route in both of netlink's Dst forms - #3146

Open
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/orchestrator-network-nil-route-dst
Open

AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/orchestrator-network-nil-route-dst

Conversation

@AdaAibaby

@AdaAibaby AdaAibaby commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

getDefaultGateway identified the IPv4 default route with route.Dst.String() == "0.0.0.0/0". The kernel reports the default route in one of two ways depending on kernel/netlink version:

  • Dst == nil — RTA_DST omitted from the netlink message, or
  • an explicit 0.0.0.0/0 Dst — RTA_DST sent with Dst_len == 0.

The string check only matched the second form and silently missed the first.

Fix

Match on the zero-length prefix via a new isDefaultRoute helper, so both forms work. The IPv4-only scope is preserved via route.Family (which netlink populates even when Dst is nil).

func isDefaultRoute(route netlink.Route) bool {
	if route.Family != netlink.FAMILY_V4 {
		return false
	}
	if route.Dst == nil {
		return true
	}
	ones, _ := route.Dst.Mask.Size()
	return ones == 0
}

On the "nil panic"

route.Dst.String() is actually nil-safe — net.IPNet.String() returns "<nil>" for a nil receiver, so the original code never panicked on the nil form; it just failed to find the gateway. Because the gateway is resolved at package init (var defaultGateway = utils.Must(getDefaultGateway(ctx))), that miss would panic the orchestrator on startup.

Checking only Dst == nil (instead of the string) would move that same startup failure to hosts whose kernel does send 0.0.0.0/0 — verified on a host running kernel 6.8 / util-linux 2.39.3, where the default route comes back with a non-nil 0.0.0.0/0 Dst. The zero-prefix check covers both forms and avoids the panic on either kind of host.

Verification

Truth table over the three predicates (old string check, Dst == nil, and this fix):

route old == "0.0.0.0/0" Dst == nil this fix
default, Dst == nil ❌ ✅ ✅
default, Dst == 0.0.0.0/0 ✅ ❌ ✅
default, Dst == ::/0 (v6) ❌ ❌ ❌ (v4-only)
normal, 10.0.0.0/8 ❌ ❌ ❌

Added a table-driven test (host_default_route_test.go) covering both default-route forms, a non-default prefix, and the IPv6 default. No root required.

/cc @ryan-sana @jakubno @dobrac @ValentaTomas Looking forward to your code review.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

No feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@ValentaTomas
ValentaTomas force-pushed the main branch 2 times, most recently from 5aad415 to d71980e Compare July 25, 2026 22:53
…orms

getDefaultGateway identified the IPv4 default route with
route.Dst.String() == "0.0.0.0/0". The kernel reports that route in one of
two ways depending on kernel/netlink version: with Dst == nil (RTA_DST
omitted) or with an explicit 0.0.0.0/0 Dst. The string check only matched the
second form and silently missed the first.

Match on the zero-length prefix via a new isDefaultRoute helper so both forms
work, keeping the IPv4-only scope via route.Family (which is populated even
when Dst is nil).

Note: route.Dst.String() is nil-safe (net.IPNet.String() returns "<nil>" for a
nil receiver), so the old code never panicked on the nil form; it just failed
to find the gateway, which at package init
(var defaultGateway = utils.Must(getDefaultGateway(ctx))) would panic the
orchestrator on startup. Checking only Dst == nil would move that failure to
hosts whose kernel sends 0.0.0.0/0 instead; the zero-prefix check covers both.

Add a table-driven test over both default-route forms, a non-default prefix,
and the IPv6 default; no root required.
@AdaAibaby
AdaAibaby force-pushed the fix/orchestrator-network-nil-route-dst branch from a2304dc to fbb12be Compare November 10, 2026 08:25
@AdaAibaby AdaAibaby changed the title fix(orchestrator): prevent nil panic when finding default gateway fix(orchestrator): match the default route in both of netlink's Dst forms Nov 10, 2026
@AdaAibaby
AdaAibaby force-pushed the fix/orchestrator-network-nil-route-dst branch from fbb12be to 6742058 Compare November 25, 2026 14:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants