Commit Graph
100 Commits
Author SHA1 Message Date
Yu Watanabe f74118be4f ycm: apply "ruff format" and "ruff check --fix" 2026-05-18 02:32:42 +09:00
Yu Watanabe 75f7304512 ruff: do not warn about too long line and lambda assignment 2026-05-18 02:32:42 +09:00
Yu Watanabe c54decc406 ruff: use single quotes for multiline strings 2026-05-18 02:32:39 +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 ba22984544 sd-dhcp-client: use dhcp_message_send_{udp,raw}() and update BPF code (#42138) 2026-05-18 01:26:55 +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 ddd535a424 NEWS: mention new 'networkctl dhcp-lease' command 2026-05-17 21:03:55 +09:00
Yu Watanabe 6cbf8222ca networkctl: add dhcp-lease verb to dump DHCP lease
This shows the DHCP message of an acquired DHCP lease.
Example:
```
$ networkctl dhcp-lease eth0
Header:
              KEY VALUE
   Hardware Type: ETHER
Hardware Address: 41:42:43:31:32:33
  Client Address: 192.0.2.123
  Server Address: 192.0.2.1

Options:
CODE NAME               DATA
   1 subnet mask        255.255.255.0
   3 router             192.0.2.1
   6 domain name server 192.0.2.1
  12 hostname           test-node
  15 domain name        lan
  28 broadcast address  192.0.2.255
  42 NTP server         192.0.2.11
                        192.0.2.12
  51 lease time         1d
  53 message type       5
  54 server identifier  192.0.2.1
  58 renewal time       11h 5min 38s
  59 rebinding time     20h 5min 38s
 119 domain search      hoge.example.com
                        foo.example.com
```
2026-05-17 21:02:20 +09:00
Yu Watanabe 9022ccc219 dhcp: cleanups for sd-dhcp-lease.c and rewrite test-dhcp-client (#42135) 2026-05-17 20:12:37 +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 a192c67630 ci/alpine: do not install util-linux-login
For some reasons, after util-linux is bumped from 2.41.4-r0 to 2.42-r0,
the 'su' command from util-linux-login seems to not correctly run commands in
https://github.com/jirutka/setup-alpine/blob/v1.4.1/alpine.sh
and causes the following spurious failure:
```
2026-05-15T21:19:15.6539432Z ##[group]Set up user runner
2026-05-15T21:19:15.6981963Z /bin/sh: line 0: ��: not found
2026-05-15T21:19:15.6982503Z /bin/sh: line 1: ␡ELF␂␁␁␃: not found
2026-05-15T21:19:15.6985788Z /bin/sh: line 10: ␒␐␆␒B␈␒�␄␒y␄␒�␁␒␞␇␒:␁␒�␃␒�␄␒@␁␒9␈␒?␆␒␚␈␒x: not found
2026-05-15T21:19:15.7010731Z /bin/sh: line 33: can't open ␂␒-␂␒�: no such file
2026-05-15T21:19:15.7016026Z /bin/sh: line 33: syntax error: unexpected word (expecting ")")
2026-05-15T21:19:15.7049583Z
2026-05-15T21:19:15.7050199Z ␛[1;31mError occurred at line 338:␛[0m
2026-05-15T21:19:15.7050830Z   335 | 		echo 'permit nopass keepenv $SUDO_USER' | tee /etc/doas.d/root.conf
2026-05-15T21:19:15.7051287Z   336 | 	fi
2026-05-15T21:19:15.7051549Z   337 | SHELL
2026-05-15T21:19:15.7052039Z ␛[1;31m> 338 | abin/"$INPUT_SHELL_NAME" --root /.setup.sh␛[0m
2026-05-15T21:19:15.7052506Z   339 |
2026-05-15T21:19:15.7052796Z   340 | rm .setup.sh
2026-05-15T21:19:15.7053172Z   341 | endgroup
2026-05-15T21:19:15.7096322Z ##[error]Error occurred at line 338: abin/"$INPUT_SHELL_NAME" --root /.setup.sh (see the job log for more information)
2026-05-15T21:19:15.7101400Z ##[error]Process completed with exit code 1.
```
Let's not install the package. It seems no command provided by the
package is used.
2026-05-17 10:56:34 +01: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 cec4d5e673 sd-dhcp-client: two tiny cleanups (#42129) 2026-05-17 04:16:32 +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 5768f1dd6f Final batch of conversions to option and verb macros (#42127) 2026-05-17 03:50:48 +09:00
Yu Watanabe bd3bbacd24 sd-dhcp-client: drop unused legacy code (#42128) 2026-05-17 03:42:29 +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 ad350e6ecf network: drop serialization of DHCP lease
No one use it now anymore. Let's drop it.
2026-05-17 01:31:42 +09:00
Yu Watanabe 7f2c6185fe networkctl: always use DHCP message serialized in JSON desciption
Now the interface description by networkd always contains DHCP message
(of course when there is a bound DHCP lease). Let's use it.
2026-05-17 01:31:42 +09:00
Yu Watanabe c5bcbb4c85 network: drop unmet conditions
Now sd_dhcp_lease object always wraps sd_dhcp_message object, hence we
can unconditionally use it.
2026-05-17 01:31:42 +09:00
Yu Watanabe b2e64f53b7 sd-dhcp-client: use new message parser (#42123)
In 26b7c5ff3b, we introduced a new parser
for received DHCP message, but it was not used at that time. This PR
replaces the legacy parser with the new one, and makes the fuzzer also
use the new parser.
2026-05-17 00:33:43 +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 ace3a7b500 udev,sd-device: drop old database support (#40801)
Closes #40776.
2026-05-16 08:26:16 +09:00
Yu Watanabe c0e40b14ad networkctl: load information about DHCP client from varlink
By the previous commit, networkd now exposes the received DHCP message
in the Descibe() DBus/Varlink method. Let's make networkctl deserialize
the DHCP message and use it where necessary.
2026-05-16 08:05:01 +09:00
Yu Watanabe 29e221c9e6 network: append DHCP message in json output
Also, get private options from sd_dhcp_message object if sd_dhcp_lease
has it.

With this change, networkctl will be able to use the serialized DHCP
message object. Preparation for later changes.
2026-05-16 08:05:01 +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 206f0391a6 varlink: MethodNotImplemented: drop extraneous dot; vl_error_MethodNotFound: an method (#42112) 2026-05-16 05:10:38 +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
Yu Watanabe 3b64024464 udev/node: drop support of old file format in /run/udev/links/
The new file format in /run/udev/links/ has been introduced in
377a83f0d8 (v250, released on 2021-12-23).
Let's drop the old format support, to simplify the logic.
2026-05-15 13:47:45 +02:00
Yu Watanabe dfe0e81de6 udev/watch: use mapping from device ID -> watch on restart
The mapping from device ID to watch handle has been introduced by
e7f781e473 (v249, released on 2021-07-07).
Let's drop the runtime upgradability of udevd from an ancient version.
2026-05-15 13:47:45 +02:00
Yu Watanabe 1fdcf3ee40 sd-device: drop support of udev database version 0
The udev database versioning has been introduced in v247, which is
released on 2020-11-26.
Let's drop the support of old udev database.
2026-05-15 13:47:45 +02:00
Yu Watanabe bbf69974a8 TODO: fix typo 2026-05-15 15:33:11 +09:00
Yu Watanabe c33a9eb858 sd-journal: update comments 2026-05-15 15:04:02 +09:00
Yu Watanabe f795ecc3d7 A few more conversions of options and verbs (#41795)
I had those prepared before but I didn't submit them because the
automatic layout didn't work well. In two cases now the sync of widths
between verbs and options is disabled and one case is left with the
automatic alignment. I think it'd good enough to merge.
2026-05-15 02:47:23 +09:00
Yu Watanabe a7c76ceaef meson: don't use Python module for host Python (#41959)
Checking for pefile required that module to be made available for the
Python used to build systemd, even though it's only used at runtime,
potentially via a different Python installation.

Furthermore, Meson's Python module doesn't do the right thing when cross
compiling and looking up a Python for the host system, so this would end
up uselessly checking whether the build Python had the pefile module,
which is not needed. Even if it were made to check the host Python using
find_program, it still relies on being able to run its Python, which in
a cross scenario it probably wouldn't be able to do.

All in all, this check does more harm than good, and prevents building
ukify in valid configurations, so remove it.
2026-05-15 00:38:19 +09:00
Yu Watanabe d6c79c13ff Implement Socket Context/Runtime for io.systemd.Unit.List (#42057)
The PR implements the following objects + tests for
io.systemd.Unit.List:
- SocketContext
- Socket Runtime

It's a continuation of the following PRs:

* https://github.com/systemd/systemd/pull/37432
* https://github.com/systemd/systemd/pull/37646
* https://github.com/systemd/systemd/pull/38032
* https://github.com/systemd/systemd/pull/38212
* https://github.com/systemd/systemd/pull/39391
* https://github.com/systemd/systemd/pull/41980
2026-05-14 23:29:47 +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 98d061e28b TODO: fix typo 2026-05-13 05:34:21 +09:00
Yu Watanabe d5244e1df5 test: split unit tests (#42062) 2026-05-13 04:54:57 +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 2f8348e352 dhcp: introduce sd_dhcp_message object and several related functions (part 1) (#42047) 2026-05-13 02:58:20 +09:00
Yu Watanabe d56adae624 copy: fix typo and slightly update comment 2026-05-13 02:04:33 +09:00
Yu Watanabe 3c5bb1f352 option: fix typo 2026-05-13 01:57:12 +09:00
Yu Watanabe 47eb11e4c2 po: update Japanese translation 2026-05-13 01:51:48 +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
Yu Watanabe f51e7eeb7c fuzz: modernize fuzz-dhcp-server
- Do not include .c file.
- Use ASSERT_OK() and friends.
2026-05-13 00:47:03 +09:00
Yu Watanabe e507487b6d dhcp-protocol: introduce more sub-options for DHCP Relay Agent Information option
These new values will be used later.
2026-05-13 00:46:09 +09:00
Yu Watanabe 25482d832c sd-dhcp-lease: drop sd_dhcp_lease.have_subnet_mask and have_broadcast
NULL address is invalid in both cases. Let's refuse to use them when NULL.
2026-05-13 00:43:00 +09:00
Yu Watanabe 28423ea18c dhcp-message: introduce dhcp_message_{append,get}_option_hostname() and related functions
These are for DHCP options 12 (Hostname) and 81 (FQDN) options.
2026-05-13 00:27:49 +09:00
Yu Watanabe aa9584a037 dhcp-message: introduce dhcp_message_{append,get}_option_parameter_request_list()
These are for DHCP option 55 (parameter request list).
2026-05-13 00:27:49 +09:00
Yu Watanabe a6a6e371f7 dhcp-message: introduce dhcp_message_{append,get}_option_client_id()
These are for DHCP option 61 (client ID).
2026-05-13 00:27:49 +09:00
Yu Watanabe 1c4ee9e969 dhcp-message: introduce dhcp_message_{append,get}_option_string()
These are for DHCP options that takes a string e.g. DHCP options
17 (root path), 60 (vendor class identifier), and so on.
2026-05-13 00:27:49 +09:00
Yu Watanabe 174a61135c dhcp-message: introduce dhcp_message_{append,get}_option_addresses()
These functions support multiple addresses.

These are for e.g. DHCP options 6 (DNS servers), 42 (NTP servers) and so on.
2026-05-13 00:27:49 +09:00
Yu Watanabe 4b2ff0a00f dhcp-message: introduce dhcp_message_{append,get}_option_address()
These are equivalent to dhcp_message_{append,get}_option_be32(), but for
type safety.

These are for e.g. DHCP options 50 (requested IP address).
2026-05-13 00:27:49 +09:00
Yu Watanabe 7b97d772a2 dhcp-message: introduce dhcp_message_{append,get}_option_sec()
These are for e.g. DHCP options 51 (lease time), 58 (renewal time), and
59 (rebinding time).
2026-05-13 00:27:49 +09:00
Yu Watanabe 8c18bb6547 dhcp-message: introduce sd_dhcp_message object and several functions for the object 2026-05-13 00:27:49 +09:00
Yu Watanabe 8bc6aa614d network: use TLV and iovec to manage several DHCP options (#42045) 2026-05-13 00:02:10 +09:00
Yu Watanabe 0b8b2af657 Introduce helper functions to parse and build length-prefixed data and TLV data (#41802)
These are currently not used yet, but will be used later in
parsing/building network packets like DHCP message.
2026-05-12 20:08:40 +09:00
Yu Watanabe 30b14a0886 dhcp: use struct iovec_wrapper to manage user class 2026-05-12 20:06:28 +09:00
Yu Watanabe fa881fda15 sd-dhcp-option: drop unused sd_dhcp_option 2026-05-12 20:06:28 +09:00
Yu Watanabe 431ec1b145 dhcp: use TLV object to manage extra and vendor options
Note, previously we replaced the previous option with the same option code with
new one. But, DHCP message can have multiple options with same option code.
Hence, this make the conf parser not replace, but append new one.
2026-05-12 20:06:28 +09:00
Yu Watanabe 47747cd212 sd-dhcp-protocol: rename DHCP option 43, 124, and 125
There are four DHCP options with confusing names:
Option 43: Vendor-Specific Information
Option 60: Vendor Class Identifier
Option 124: Vendor-Identifying Vendor Class
Option 125: Vendor-Identifying Vendor-Specific Information

Let's use their full names for their corresponding enums.
2026-05-12 20:06:28 +09:00
Yu Watanabe 320ae462b1 tlv-util: introduce tlv-util that handles Tag-Length-Value data format
In many network protocols e.g. DHCP, the TLV format is used.
Let's introduce a simple parser and builder of the data format.
2026-05-12 15:53:12 +09:00
Yu Watanabe 4fc58bf621 iovec-wrapper: reintroduce iovw_free() and iovw_free_free()
They were dropped by the commit 267b16f33c,
but will be used later. Hence, let's reintroduce them.
2026-05-12 15:33:21 +09:00
Yu Watanabe 32729ae92f iovec-wrapper: introduce iovec_split() and iovw_merge()
In many network protocols, the length-prefixed data format is often
used. Let's add a simple parser and builder for the format.
2026-05-12 15:33:21 +09:00
Yu Watanabe fe6fed5d97 iovec-wrapper: introduce iovw_put_full() and friends to make them accept zero length entry
These will be used later. Preparation for later commits.
2026-05-12 15:33:21 +09:00
Yu Watanabe 58863bdaec iovec-wrapper: make iovw_size() take NULL again
This partially reverts 267b16f33c.

We usually make xyz_size() take NULL, e.g. hashmap_size().
2026-05-12 15:33:21 +09:00