fix(netlink): flush stale addresses before applying the static config#111
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On installed nodes the kernel runs
ip=dhcp(one cmdline serves both maintenance and installed boots) and acquires a DHCP address beforeinitruns.initthen applies the static machine config. The static address and default route are written withNLM_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:configurenow 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 multipartsendDump.EADDRNOTAVAIL/ENOENT(address already gone) are skipped; any other error propagates.ConfigureInterface.Testing
configureemits 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) andtask licensegreen locally.Closes #104