dhcp: decode and encode option 41 (NIS servers) - #1488
Open
dylanpulver wants to merge 1 commit into
Open
Conversation
dhcp4msg.options is an RFC 2132 ordered table of option code to wire format, and _register_options() turns it into the decode and encode maps. Option 41 is absent from it: the slot between NIS_DOMAIN (40) and NTP_SERVERS (42) holds NDS_SERVERS, which is code 85. RFC 2132 8.2: "This option specifies a list of IP addresses indicating NIS servers available to the client. [...] The code for this option is 41. Its minimum length is 4, and the length MUST be a multiple of 4." That is the same wire format as NTP_SERVERS in 8.3, so the two are a controlled comparison. Feeding the same eight bytes under codes 41, 42 and 85 into dhcp4msg().decode(): nds_servers ['192.168.1.10', '192.168.1.11'] nis_servers [192, 168, 1, 10, 192, 168, 1, 11] <- falls back to array8 ntp_servers ['192.168.1.10', '192.168.1.11'] and 'nis_servers' is not in the encode map at all, so it cannot be sent. The fix is additive. NDS_SERVERS is correct in its own right (RFC 2241 section 3 gives code 85 the same list-of-addresses format), so it stays.
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.
dhcp4msg.optionsis an RFC 2132 ordered table of option code → wire format, and_register_options()turns it into the decode and encode maps. Codes missing from it fall throughdhcpmsg.decode()toarray8.Option 41 is absent.
dhcp4msg.py:78-80runs 40 → 85 → 42: the slot betweenNIS_DOMAIN(40) andNTP_SERVERS(42) holdsNDS_SERVERS, which is code 85.RFC 2132 §8.2: "The code for this option is 41. Its minimum length is 4, and the length MUST be a multiple of 4." That is byte-for-byte the same shape as
NTP_SERVERSin §8.3, which makes 42 an exact control. Feeding the same eight bytes (192.168.1.10,192.168.1.11) under codes 41, 42 and 85 intodhcp4msg(buf=...).decode():The fix is additive:
NDS_SERVERSis correct in its own right (RFC 2241 §3 gives code 85 the same format), so nothing is removed, and the second test row pins that.grep -rn "nds_servers\|NDS_SERVERS" .returns two hits repo-wide: the enum definition and that one table line.grep -rn "nis_servers" tests/returns none. The onlyNISin the tests istest_parser.py:355-356, whereOption.NIS_SERVERSappears inside an assertedparameter_list— that is option 55's array of requested codes, decoded byarray8, which never touches the decode map. The tests prove the client can ask for NIS servers; nothing proves it can read the answer.Mutants
nis_serversfails withKeyError: 'nis_servers'(it cannot be encoded).NDS_SERVERSwithNIS_SERVERSrather than adding:nds_serversfails withKeyError: 'nds_servers'. That is what pins the fix as additive rather than a substitution.What I ran, and what I could not
The two rows go into the existing
test_encode_decode_optionstable. I could not run the repo's suite.make testis Linux-only andtests/test_linux/cannot even be collected on macOS —pyroute2/ext/rawsocket.py:3fails withImportError: cannot import name 'AF_PACKET' from 'socket'. So I drove the parametrized table directly instead: a small runner reads the@pytest.mark.parametrizetuple out oftest_encode.pywithast.literal_evaland executes the same test body. All 13 cases pass with the change; the mutants above are the same runner on the same table. Every claim about the repo's own nox sessions is therefore untested by me — CI is the first real run.pre-commit run --files pyroute2/dhcp/dhcp4msg.py tests/test_linux/test_dhcp/test_encode.pypasses (isort, black, flake8, whitespace, end-of-file).Also not done: no live DHCP server exchange, and I did not touch
Lease, which has nonis_serversaccessor. Related but deliberately left alone:leases.py:173annotatesdomain_searchaslist[str], but option 119 is likewise absent from this table so it decodes viaarray8to a list of ints — that one needs an RFC 3397 name-compression decoder, not a table entry, so it is not in this PR.Not from a bug report; found checking protocol constant tables against their RFCs. AI assistance: this change was written with an AI coding assistant.