Skip to content

dhcp: allow suppressing default gateway from lease result - #1276

Open
locker95 wants to merge 2 commits into
containernetworking:mainfrom
locker95:fix/dhcp-suppress-gateway
Open

dhcp: allow suppressing default gateway from lease result#1276
locker95 wants to merge 2 commits into
containernetworking:mainfrom
locker95:fix/dhcp-suppress-gateway

Conversation

@locker95

Copy link
Copy Markdown

Summary

When Multus (or similar) attaches a secondary interface with the dhcp IPAM plugin, a DHCP-provided default gateway is written into the CNI result. That becomes a second default route in the pod and often breaks connectivity. Multus documents this failure mode, and skipDefault only changes the DHCP parameter request list — many servers still send option 3 (routers) unsolicited.

This adds an ipam.suppress list. With "suppress": ["gateway"]:

  • IPConfig.Gateway is left empty
  • default routes (0.0.0.0/0, ::/0) are dropped from Routes
  • non-default routes (static routes / option 121 classless static routes) are kept

This is intentionally narrower than the abandoned discardDhcpRoutes approach in #701, which dropped all DHCP routes (maintainers called that out).

Example

{
  "type": "macvlan",
  "master": "eth1",
  "mode": "bridge",
  "ipam": {
    "type": "dhcp",
    "suppress": ["gateway"]
  }
}

request / skipDefault remain unchanged for clients that want to avoid requesting the router option; suppress covers servers that send it anyway.

Test plan

  • Unit tests for parseSuppress, isDefaultRoute, filterDefaultRoutes
  • Linux CI: go test ./plugins/ipam/dhcp/ (package needs netns/root; pure helpers compile with GOOS=linux)

Fixes #1208

locker95 added 2 commits July 20, 2026 23:52
Some DHCP servers send a router option even when the client did not
request it (skipDefault only affects the parameter request list). With
Multus secondary attachments that installs a second default route and
breaks pod networking.

Add an ipam.suppress list; when it includes "gateway", clear
IPConfig.Gateway and drop default routes (0.0.0.0/0, ::/0) from the
result while keeping non-default routes such as option 121 classless
static routes.

Example:
  "ipam": { "type": "dhcp", "suppress": ["gateway"] }

Fixes containernetworking#1208

Signed-off-by: Dean Chen <862469039@qq.com>
nonamedreturns fails CI on the suppress helper.

Signed-off-by: Dean Chen <862469039@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dhcp plugin should support suppressing default gateway modification

1 participant