Skip to content

fix(netlink): flush stale addresses before applying the static config#111

Merged
Bugs5382 merged 2 commits into
mainfrom
fix/104-flush-dhcp-addr
Jul 3, 2026
Merged

fix(netlink): flush stale addresses before applying the static config#111
Bugs5382 merged 2 commits into
mainfrom
fix/104-flush-dhcp-addr

Conversation

@Bugs5382

@Bugs5382 Bugs5382 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

On installed nodes the kernel runs ip=dhcp (one cmdline serves both maintenance and installed boots) and acquires a DHCP address before init runs. init then applies the static machine config. The static address and default route are written with NLM_F_REPLACE, but REPLACE keys on the exact prefix — so a DHCP address on a different subnet than the static config would linger on the interface alongside the static one.

This flushes the interface's existing IPv4 addresses before applying the static address, so the static config is authoritative.

What changed

  • internal/init/netlink: configure now enumerates the interface's IPv4 addresses via an RTM_GETADDR dump and deletes each (RTM_DELADDR) before adding the static address. New pieces: a dump request builder, an RTM_DELADDR builder, an ifaddrmsg parser, and a multipart sendDump.
  • Deletes that fail with EADDRNOTAVAIL/ENOENT (address already gone) are skipped; any other error propagates.
  • The maintenance path is untouched — it only brings up loopback and relies on the kernel DHCP address; it never calls ConfigureInterface.

Testing

  • Unit tests for the dump request, the DELADDR builder, and the parser (ifindex + AF_INET discrimination, NLMSG_DONE handling).
  • Flow test: with two existing addresses, configure emits link-up → DELADDR → DELADDR → NEWADDR(static) → NEWROUTE, in order; plus the no-existing-address case and the EADDRNOTAVAIL-skipped case.
  • task ci (gofmt, golangci-lint, vet, test, build) and task license green locally.

Closes #104

Bugs5382 added 2 commits July 3, 2026 06:14
Before assigning the static IPv4 address, enumerate the interface's
existing addresses via RTM_GETADDR and delete each one with RTM_DELADDR.
This removes a leftover kernel ip=dhcp address that landed on a different
subnet before init ran; without the flush it would linger alongside the
static address.

New helpers: buildAddrDumpRequest, buildAddrDelRequest, parseAddrMessages,
sendDump (multipart recv loop), isAddrNotFound (EADDRNOTAVAIL/ENOENT
tolerance). configure gains a dumpFunc parameter; ConfigureInterface wires
in sendDump. The maintenance path (BringUpLoopback) is untouched.

Tests cover the new message builders, the parser (multi-ifindex + IPv6
filter + NLMSG_DONE), and three configure flow cases: flush-then-static,
no-existing-addrs (no DELADDRs emitted), and EADDRNOTAVAIL-skipped.

Closes #104
Review polish: drop the dead fakeSend variable and assert the static NEWADDR
still follows a skipped DELADDR; Unmap parsed addresses to pure IPv4 form for
consistency with the rest of the codebase.

Refs #104
@github-actions github-actions Bot added the fix Bug fix (fix). Patch. label Jul 3, 2026
@Bugs5382 Bugs5382 self-assigned this Jul 3, 2026
@Bugs5382 Bugs5382 merged commit 07c9e27 into main Jul 3, 2026
13 checks passed
@Bugs5382 Bugs5382 deleted the fix/104-flush-dhcp-addr branch July 3, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix (fix). Patch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(netlink): flush the DHCP-assigned address on the installed path

1 participant