Commit Graph
2107 Commits
Author SHA1 Message Date
Luca Boccassi 6fa5ebc506 dhcp-client: reject messages larger than the maximum UDP payload
dhcp_message_verify_header() only enforced a lower bound on the input
length, so dhcp_message_parse() happily accepted arbitrarily large
buffers. Such inputs could never have been received via UDP and would
later fail in dhcp_message_build() with -E2BIG once the parsed options'
combined size exceeds UDP_PAYLOAD_MAX_SIZE, which the fuzzer surfaced as
an assertion failure.

Reject inputs above UDP_PAYLOAD_MAX_SIZE up front, so the parse stage
mirrors what the wire format can actually carry.

Follow-up for 8c18bb6547

Fixes https://github.com/systemd/systemd/issues/42147

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-19 01:43:25 +09:00
Yu Watanabe a0177d96dc dhcp-message: introduce dhcp_message_{payload,packet}_size() 2026-05-18 09:34:32 +09:00
Luca Boccassi 1d73c5f04f dhcp-client: clear overloaded sname/file fields after parsing
When SD_DHCP_OPTION_OVERLOAD indicates that the sname and/or file header
fields are overloaded with extra DHCP options, dhcp_message_parse() merges
those options into message->options but leaves the raw bytes untouched in
the header. As a result, dhcp_message_build() emits the header (including
the overloaded bytes) verbatim, and the next parse re-parses those bytes,
appending duplicate entries to the options map (each tag's iov list grows).
Subsequent builds then differ from the first, breaking the parse/build
roundtrip.

This was caught by fuzz-dhcp-client, which asserts that two consecutive
build calls produce identical output.

Zero out the overloaded fields after parsing them, since their content has
already been merged into the options map. This makes the roundtrip
idempotent and avoids re-emitting stale overloaded data in the rebuilt
header. The JSON build/parse path was already correct (it omits sname/file
from the JSON when the overload bit is set), so only the binary path needed
fixing.

Fixes https://github.com/systemd/systemd/issues/42139

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 04:52:25 +09:00
Yu Watanabe aa0f03eb03 networkctl: introduce 'dhcp-lease' command to dump acquired DHCP lease (#42137) 2026-05-18 01:28:11 +09:00
Yu Watanabe a72f23d2b8 sd-dhcp-client: drop unused data in sd_dhcp_client
With the previous commit, now sd_dhcp_client.link is not used anymore.
Let's drop it.
2026-05-17 22:44:17 +09:00
Yu Watanabe 0c69b24741 dhcp-client-send: move/update BPF code and socket initialization from dhcp-network.c
- BPF code now supports the case when IP header has IP packet options,
- also set socket priority to UDP socket.

Co-developed-by: Google Gemini Pro
2026-05-17 22:44:17 +09:00
Yu Watanabe 89cf6d81f7 dhcp-client-send: use dhcp_message_send_{udp,raw}() 2026-05-17 22:44:17 +09:00
Yu Watanabe 149adb2fdc dhcp-message-dump: introduce dump_dhcp_message()
It dumps DHCP messages in a human friendly format.
It will be used in networkctl in a later commit.
2026-05-17 20:09:47 +09:00
Yu Watanabe 335ac4a71d fuzz-dhcp-client: externally set socket fd, rather than override functions 2026-05-17 15:20:29 +09:00
Yu Watanabe acdaee339f test-dhcp-client: add test cases for discover attempt counter 2026-05-17 15:20:29 +09:00
Yu Watanabe 115c354b57 test-dhcp-client: add test cases for IPv6-only mode 2026-05-17 15:20:29 +09:00
Yu Watanabe 7df9210283 test-dhcp-client: add test case for BOOTP client mode 2026-05-17 15:20:29 +09:00
Yu Watanabe 9bd6b949d3 test-dhcp-client: add test case for INIT-REBOOT sequence 2026-05-17 15:20:29 +09:00
Yu Watanabe f7c144b9c7 test-dhcp-client: add test case for rapid commit mode 2026-05-17 15:20:24 +09:00
Yu Watanabe 3eba8d6265 test-dhcp-client: add test case for anonymized mode 2026-05-17 15:18:41 +09:00
Yu Watanabe 385cd74fca test-dhcp-client: rewrite the test by using sd_dhcp_message
More test cases will be added later.
2026-05-17 04:13:47 +09:00
Yu Watanabe 33c6d10749 sd-dhcp-client: allow to set socket fd externally
It will be used by the unit test and fuzzer for the DHCP client.
Preparation for later changes.
2026-05-17 04:13:47 +09:00
Yu Watanabe f2169cfe8e sd-dhcp-lease: coding style cleanups
Rename function arguments for storing results, and accept NULL for
them. Also, adjust the position of asterisk.
2026-05-17 04:13:47 +09:00
Yu Watanabe cec4d5e673 sd-dhcp-client: two tiny cleanups (#42129) 2026-05-17 04:16:32 +09:00
Yu Watanabe ff32569f2a sd-dhcp-client: set TOS and socket priority by default
Also this renames sd_dhcp_client_set_service_type() to _set_ip_service_type().
2026-05-17 01:34:44 +09:00
Yu Watanabe e7c550895a sd-dhcp-client: split out setting anonymize parameter
No effective functional change. Just refactoring.
2026-05-17 01:33:43 +09:00
Yu Watanabe 4095391bd6 dhcp-packet: drop unused dhcp_packet_verify_headers() 2026-05-17 01:31:43 +09:00
Yu Watanabe 4d1779a7c5 sd-dhcp-lease: drop several more unused functions and conditions 2026-05-17 01:31:43 +09:00
Yu Watanabe c63c262875 sd-dhcp-lease: drop unused dhcp_lease_save() and dhcp_lease_load()
They are not used anymore. Let's kill them.
2026-05-17 01:31:42 +09:00
Yu Watanabe 8de24db5de sd-dhcp-client: do not trigger assertion when running on interface with small MTU
This also drops spurious default value. If mtu is unset, now the correct
default value is set in client_new_message() in dhcp-client-send.c.
2026-05-16 22:34:25 +09:00
Yu Watanabe 1a0f2c1fb2 sd-dhcp-client: drop unnecessary T1/T2 adjustment logic
It is already done in client_parse_ack() -> dhcp_lease_new_from_message().
2026-05-16 22:34:25 +09:00
Yu Watanabe de079ebc04 sd-dhcp-lease: drop unused dhcp_lease_unref_and_replace() 2026-05-16 22:34:25 +09:00
Yu Watanabe 0435151bc8 sd-dhcp-client: use dhcp_client_parse_message()
This also unify two IO event source handlers.
2026-05-16 22:34:25 +09:00
Yu Watanabe fcf2de89bb fuzz-dhcp-client: fuzz dhcp_client_parse_message()
Also, if the fuzzing engine provides a valid message, then try to build
json variant and UDP payload from the parsed message. We will drop
dhcp_lease_save() and dhcp_lease_load(), hence the tests for them are
dropped.
2026-05-16 22:34:25 +09:00
Yu Watanabe 6ae696a956 socket-util: extend the buffer in sockaddr_union to make it consistent with hw_addr_data
Concerned by Claude:
https://github.com/systemd/systemd/pull/42119#discussion_r3251133516
2026-05-16 22:33:40 +09:00
Yu Watanabe 8fe6094450 dhcp-message: introduce dhcp_message_send_{udp,raw}() 2026-05-16 22:33:00 +09:00
Yu Watanabe 26b7c5ff3b sd-dhcp-lease: introduce dhcp_client_parse_message()
It parses a received DHCP message and create corresponding sd_dhcp_lease
object for the message. Internally, it uses sd_dhcp_message object.

Note, the new parser is not used yet. The currently used one will be
replaced in later commit.
2026-05-16 08:04:45 +09:00
Yu Watanabe f39c071f31 dhcp-client-send: introduce dhcp_client_send_message()
This internally uses sd_dhcp_message object, and replaces functions
for creating and sending DHCP messages.

By using sd_dhcp_message internally, now we can correctly send long
(> 255 bytes) option data that cannot be fit in a single DHCP option TLV.

This also fixes the value in DHCP option 57 (Maximum Message Size).
Previously the IP and UDP header size is subtracted from the interface
MTU, but it should not.

Except for the above, this should not change any effective behaviors.
2026-05-16 08:03:15 +09:00
Yu Watanabe c5997b2bbf dhcp-message: allow to serialize/deserialize sd_dhcp_message object
By using this, we can expose received DHCP message in Describe()
DBus/Varlink methods. Preparation for later change.
2026-05-15 14:23:58 +02:00
r-vdp 62feba20aa sd-radv: do not stop on transient send errors
When the periodic RA timer fires, any error returned by sendmsg()
currently propagates up through sd_radv_send() into radv_timeout(),
which then calls sd_radv_stop(). The RA engine is never started again
until the next carrier transition.

On an 802.3ad bond there is a window right after carrier-up where the
link is administratively up but no aggregator has been selected yet, so
sendmsg() returns ENOBUFS. If the very first RA after a flap lands in
that window, radv stops permanently and all clients lose their SLAAC
addresses, on-link/PD prefixes, and default router once the previously
advertised lifetimes expire, while IPv4 keeps working, leading to a very
confusing situation with v4 up and v6 down.

Handle this the same way solicited RAs already do (see
radv_process_packet()): log the failure and reschedule the timer instead
of giving up. ra_sent is left untouched on failure so we stay in the
fast initial-advertisement regime until a send actually succeeds.
2026-05-15 03:34:52 +09:00
Yu Watanabe 7e612d5c15 dhcp-message: introduce dhcp_message_get_option_dnr()
This is for DHCP option 162 (DNR).
2026-05-13 09:41:24 +09:00
Yu Watanabe 64846d9d8a dhcp-message: introduce dhcp_message_{append,get}_option_6rd()
These are for DHCP option 212 (6rd).
2026-05-13 09:41:24 +09:00
Yu Watanabe ff9d98423c dhcp-message: introduce dhcp_message_{append,get}_option_routes()
These are for DHCP options 33 (static route), 121 (classless static
route), and 249 (private classless static route).
2026-05-13 09:41:24 +09:00
Yu Watanabe 08249b359b dhcp: move definition of sd_dhcp_route and related functions to dhcp-route.[ch]
This also renames arguments for storing results.
No functional change, just refactoring and preparation for later commits.
2026-05-13 09:41:24 +09:00
Yu Watanabe e178adc6e1 dhcp-message: add SIP server option support
The DHCP option 120 (SIP server) option takes a list of addresses or
domain names, and the first byte in the data classifies which type is
stored. Let's extend _addresses() and _domains() to make them support
the SIP server option.
2026-05-13 09:41:24 +09:00
Yu Watanabe c588c31144 dhcp-message: introduce dhcp_message_get_option_domains()
This is for e.g. DHCP option 119 (domain search).
2026-05-13 09:41:24 +09:00
Yu Watanabe 295a4dd6ed dhcp-message: introduce dhcp_message_{append,get}_option_length_prefixed_data()
This is for e.g. User Class option.
2026-05-13 09:41:24 +09:00
Yu Watanabe a43dfaa31b dhcp-message: introduce dhcp_message_{append,get}_option_sub_tlv()
This is for e.g. Vendor-Specific Information option.
2026-05-13 09:41:19 +09:00
Yu Watanabe 3d66a4550a dhcp: random trivial cleanups (#42061) 2026-05-13 08:15:11 +09:00
Yu Watanabe 304899fa57 sd-dhcp-client: always set default broadcast hardware address when unspecified
The default value for InfiniBand is copied from dhcp-network.c.
2026-05-13 07:47:53 +09:00
Yu Watanabe c28ec168aa test: move test cases for client_id_{hash,compare}_func() to test-dhcp-client-id.c 2026-05-13 03:02:37 +09:00
Yu Watanabe 000eb0f908 test: move unit test for dhcp_identifier_set_iaid() to test-dhcp-duid.c 2026-05-13 03:02:24 +09:00
Yu Watanabe bcc7755438 dhcp-network: make dhcp_network_send_{raw,udp}_socket() take iovec_wrapper 2026-05-13 02:59:00 +09:00
Yu Watanabe 74f3cc4576 sd-dhcp-server-lease: rename dhcp_server_lease_append_json() -> dhcp_server_lease_build_json()
It does not append, but build a new JSON variant.
2026-05-13 00:48:13 +09:00
Yu Watanabe 9179cb31ed sd-dhcp-server: coding style fix 2026-05-13 00:47:48 +09:00