Derive the DHCP subnet from the FOG address, not the interface (GH-1747) - #1753
Merged
Conversation
On an interface with more than one IPv4 address, the installer wrote a DHCP subnet that was not a network. The report shows a saved mask of 255.255.0.0 on a /24, a Kea subnet of "10.0.45.2/24", a pool starting at .12, and "arithmetic syntax error ... /8" during interface selection. Each helper took "the interface" and read a different address from it: - input.sh took every inet address, link-local 169.254.x.x included. Listed first, a link-local address became the primary. - getCidr() printed the SECOND global address's prefix (head -n2 | tail -n1), through an unanchored grep, so eth1 also read eth10. A global 169.254.x.x/16 next to a /24 gave 255.255.0.0. - configureDHCP and writeKeaSample passed every global address, unquoted, to mask2network, so a second address became the mask. 10.0.45.2 with 10.0.45.14 gave the network 10.0.45.2. - interface2broadcast() took the first brd, whichever address it belonged to. Now everything derives from $ipaddress, the address FOG advertises as next-server: - input.sh takes global addresses only, and never 169.254.0.0/16. - getCidr IFACE [ADDR] prints the prefix of ADDR, or of the first global address. It reads only that interface. - interface2broadcast IFACE [ADDR] prints the brd of ADDR. - configureDHCP and writeKeaSample use $ipaddress for the network. Also: - cidr2mask with no prefix returns nothing instead of printing the /8 arithmetic error. - mask2cidr: "224)" had `let` and `nbits+=3` on separate lines, a string append, so a /27 mask came out as 243. Its error message went to stdout, where every caller takes the value as the prefix; it now goes to stderr. - The ifconfig fallback in input.sh is removed. It stored mask2cidr's prefix length in $submask, and ifconfig is not installed before the package step. An empty mask is derived again in configureDHCP. - With -y, an interface with no usable address now exits. It used to repeat the same answer forever, and the link-local filter adds a way to reach that path. tests/installer-subnet-detection.test.sh replays address layouts through the real functions and the real input.sh lines, with a fake `ip` built from real `ip -o` output. On the old code it fails 33 of 47 checks and reproduces the report: "10.0.45.2/24", pool "10.0.45.12 - 10.0.45.254", the saved 255.255.0.0, and the /8 error. It passes all 47 after. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012JsEqysRdWb914YC94Shvo
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.
Problem
On an interface with more than one IPv4 address, the installer writes a DHCP subnet that is not a network. #1747 shows a saved mask of
255.255.0.0on a /24, a Kea subnet of"10.0.45.2/24", a pool starting at.12, andarithmetic syntax error ... /8during interface selection.Cause
Each helper reads "the interface" and takes a different address from it:
input.sh169.254.x.xincluded, so a link-local address listed first became the primarygetCidr()head -n2 | tail -n1), through an unanchored grep, soeth1also readeth10configureDHCP,writeKeaSamplemask2network, so a second address became the maskinterface2broadcast()brd, whichever address it belonged toA second address in the same /24 gives exactly the reported config.
10.0.45.2with10.0.45.14gives the network10.0.45.2. A global169.254.x.x/16next to the /24 gives the saved255.255.0.0. A link-local-only NIC gives the/8error.Fix
Everything derives from
$ipaddress, the address FOG advertises as next-server.input.shtakes global addresses only, and never169.254.0.0/16.getCidr IFACE [ADDR]andinterface2broadcast IFACE [ADDR]read the named address on that interface only.configureDHCPandwriteKeaSamplecompute the network from$ipaddress.cidr2maskwith no prefix returns nothing, instead of printing the arithmetic error.mask2cidr: the224)case was a string append, so a /27 mask came out as243. Its error message now goes to stderr instead of into the caller's value.ifconfigfallback ininput.shis removed. It stored a prefix length in$submask, andifconfigis not installed before the package step.Behavior change: with
-y, an interface with no usable address now exits. It used to repeat the same answer forever.Test
tests/installer-subnet-detection.test.shreplays address layouts through the real functions and the realinput.shlines. The fakeipprints realip -ooutput.The same fix for
working-1.6is in a separate PR.Refs #1747
🤖 Generated with Claude Code
https://claude.ai/code/session_012JsEqysRdWb914YC94Shvo