From f1dbc4f8ccee0d05da474b7423b674afdd37860a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 30 Dec 2024 10:14:07 +0900 Subject: [PATCH 1/3] man/networkd.conf: update section explanation These section contains not only DUID related settings. Follow-up for 418f2dc75564330d4ff6c86193f4a3c8ffbb1f1b. --- man/networkd.conf.xml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/man/networkd.conf.xml b/man/networkd.conf.xml index 4772e82799..e843e3d9b1 100644 --- a/man/networkd.conf.xml +++ b/man/networkd.conf.xml @@ -247,10 +247,9 @@ [DHCPv4] Section Options - This section configures the DHCP Unique Identifier (DUID) value used by DHCP protocol. DHCPv4 - client protocol sends IAID and DUID to the DHCP server when acquiring a dynamic IPv4 address if - . IAID and DUID allows a DHCP server to uniquely identify the - machine and the interface requesting a DHCP IP address. To configure IAID and ClientIdentifier, see + This section configures the default configurations of DHCPv4 client. If the DHCPv4 client is + enabled on an interface, then the configurations below will be used by default unless explicitly + specified in the corresponding .network file. See also systemd.network5. @@ -354,11 +353,9 @@ DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00 [DHCPv6] Section Options - This section configures the DHCP Unique Identifier (DUID) value used by DHCPv6 protocol. - DHCPv6 client protocol sends the DHCP Unique Identifier and the interface Identity Association - Identifier (IAID) to a DHCPv6 server when acquiring a dynamic IPv6 address. IAID and DUID allows a - DHCPv6 server to uniquely identify the machine and the interface requesting a DHCP IP address. To - configure IAID, see + This section configures the default configurations of DHCPv6 client. If the DHCPv6 client is + enabled on an interface, then the configurations below will be used by default unless explicitly + specified in the corresponding .network file. See also systemd.network5. From 7bbe9ad796d69370d49e2f3eeddd4727ba413ffc Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 30 Dec 2024 10:16:37 +0900 Subject: [PATCH 2/3] network: introduce system wide default setting for DHCPv4 client ID Typically, the same client identifier setting is used for all interfaces. Hence, better to provide the system-wide setting to specify the client identifier. --- man/networkd.conf.xml | 14 ++++++++++++++ man/systemd.network.xml | 7 +++++-- src/network/networkd-dhcp4.c | 2 +- src/network/networkd-gperf.gperf | 1 + src/network/networkd-manager.c | 1 + src/network/networkd-manager.h | 1 + src/network/networkd.conf | 1 + 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/man/networkd.conf.xml b/man/networkd.conf.xml index e843e3d9b1..1d5edfd45f 100644 --- a/man/networkd.conf.xml +++ b/man/networkd.conf.xml @@ -256,6 +256,20 @@ The following options are understood: + + ClientIdentifier= + + Specifies the default DHCPv4 client identifier to be used. Takes one of + or . If set to , the MAC address of each link will be used. + If set to , an RFC4361-compliant Client ID, which is the combination of IAID + and DUID, is used. IAID can be configured by IAID= in each matching + .network file. DUID can be configured by DUIDType= and + DUIDRawData=. Defaults to . + + + + + DUIDType= Specifies how the DUID should be generated. See diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 6ed4dde4df..1c26609917 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -2371,8 +2371,11 @@ NFTSet=prefix:netdev:filter:eth_ipv4_prefix . If set to , the MAC address of the link is used. If set to , an RFC4361-compliant Client ID, which is the combination of IAID and DUID, is used. IAID can be configured by IAID=. DUID can be configured by - DUIDType= and DUIDRawData=. Defaults to - . + DUIDType= and DUIDRawData=. When + Anonymize= is enabled, is unconditionally used and the + specified value will be ignored. When unspecified, the value specified in the same setting in + networkd.conf5 + will be used. diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index d94ac1a213..30abef49a2 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -52,7 +52,7 @@ void network_adjust_dhcp4(Network *network) { } if (network->dhcp_client_identifier < 0) - network->dhcp_client_identifier = network->dhcp_anonymize ? DHCP_CLIENT_ID_MAC : DHCP_CLIENT_ID_DUID; + network->dhcp_client_identifier = network->dhcp_anonymize ? DHCP_CLIENT_ID_MAC : network->manager->dhcp_client_identifier; /* By default, RapidCommit= is enabled when Anonymize=no and neither AllowList= nor DenyList= is specified. */ if (network->dhcp_use_rapid_commit < 0) diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf index b69ef5fd31..21e8d12690 100644 --- a/src/network/networkd-gperf.gperf +++ b/src/network/networkd-gperf.gperf @@ -37,6 +37,7 @@ IPv6AcceptRA.UseDomains, config_parse_use_domains, IPv6AddressLabel.Prefix, config_parse_ipv6_address_label_section, IPV6_ADDRESS_LABEL_BY_MANAGER | IPV6_ADDRESS_LABEL_PREFIX, 0 IPv6AddressLabel.Label, config_parse_ipv6_address_label_section, IPV6_ADDRESS_LABEL_BY_MANAGER | IPV6_ADDRESS_LABEL, 0 DHCPv4.UseDomains, config_parse_use_domains, 0, offsetof(Manager, dhcp_use_domains) +DHCPv4.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Manager, dhcp_client_identifier) DHCPv4.DUIDType, config_parse_duid_type, 0, offsetof(Manager, dhcp_duid) DHCPv4.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, dhcp_duid) DHCPv6.UseDomains, config_parse_use_domains, 0, offsetof(Manager, dhcp6_use_domains) diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 829937958b..8061976d7b 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -647,6 +647,7 @@ int manager_new(Manager **ret, bool test_mode) { .dhcp_use_domains = _USE_DOMAINS_INVALID, .dhcp6_use_domains = _USE_DOMAINS_INVALID, .ndisc_use_domains = _USE_DOMAINS_INVALID, + .dhcp_client_identifier = DHCP_CLIENT_ID_DUID, .dhcp_duid.type = DUID_TYPE_EN, .dhcp6_duid.type = DUID_TYPE_EN, .duid_product_uuid.type = DUID_TYPE_UUID, diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index faa3357151..9891b8c1fc 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -78,6 +78,7 @@ struct Manager { UseDomains dhcp6_use_domains; UseDomains ndisc_use_domains; + DHCPClientIdentifier dhcp_client_identifier; DUID dhcp_duid; DUID dhcp6_duid; DUID duid_product_uuid; diff --git a/src/network/networkd.conf b/src/network/networkd.conf index 857df0899f..a5a9418bbb 100644 --- a/src/network/networkd.conf +++ b/src/network/networkd.conf @@ -36,6 +36,7 @@ #UseDomains= [DHCPv4] +#ClientIdentifier=duid #DUIDType=vendor #DUIDRawData= #UseDomains= From 5e5fe05896babe72346b387acdedbd67a4f0578d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 30 Dec 2024 11:18:59 +0900 Subject: [PATCH 3/3] test-network: add test cases for global [DHCPv4] ClientIdentifier= setting --- .../conf/10-dhcp-client-id-duid.conf | 3 +++ .../test-network/conf/10-dhcp-client-id-mac.conf | 3 +++ test/test-network/systemd-networkd-tests.py | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/test-network/conf/10-dhcp-client-id-duid.conf create mode 100644 test/test-network/conf/10-dhcp-client-id-mac.conf diff --git a/test/test-network/conf/10-dhcp-client-id-duid.conf b/test/test-network/conf/10-dhcp-client-id-duid.conf new file mode 100644 index 0000000000..8d87fb0c7c --- /dev/null +++ b/test/test-network/conf/10-dhcp-client-id-duid.conf @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[DHCPv4] +ClientIdentifier=duid diff --git a/test/test-network/conf/10-dhcp-client-id-mac.conf b/test/test-network/conf/10-dhcp-client-id-mac.conf new file mode 100644 index 0000000000..130e9162f1 --- /dev/null +++ b/test/test-network/conf/10-dhcp-client-id-mac.conf @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[DHCPv4] +ClientIdentifier=mac diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 136a6ed744..9203948d6c 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -6742,8 +6742,9 @@ class NetworkdDHCPServerTests(unittest.TestCase, Utilities): self.assertIn('Gateway: 192.168.5.1', output) self.assertIn('Time Zone: Europe/Berlin', output) - def test_dhcp_server_static_lease(self): + def test_dhcp_server_static_lease_mac_by_network(self): copy_network_unit('25-veth.netdev', '25-dhcp-client-static-lease.network', '25-dhcp-server-static-lease.network') + copy_networkd_conf_dropin('10-dhcp-client-id-duid.conf') start_networkd() self.wait_online('veth99:routable', 'veth-peer:routable') @@ -6752,7 +6753,18 @@ class NetworkdDHCPServerTests(unittest.TestCase, Utilities): self.assertIn('Address: 10.1.1.200 (DHCPv4 via 10.1.1.1)', output) self.assertIn('DHCPv4 Client ID: 12:34:56:78:9a:bc', output) - def test_dhcp_server_static_lease_default_client_id(self): + def test_dhcp_server_static_lease_mac_by_global(self): + copy_network_unit('25-veth.netdev', '25-dhcp-client.network', '25-dhcp-server-static-lease.network') + copy_networkd_conf_dropin('10-dhcp-client-id-mac.conf') + start_networkd() + self.wait_online('veth99:routable', 'veth-peer:routable') + + output = networkctl_status('veth99') + print(output) + self.assertIn('Address: 10.1.1.200 (DHCPv4 via 10.1.1.1)', output) + self.assertIn('DHCPv4 Client ID: 12:34:56:78:9a:bc', output) + + def test_dhcp_server_static_lease_duid(self): copy_network_unit('25-veth.netdev', '25-dhcp-client.network', '25-dhcp-server-static-lease.network') start_networkd() self.wait_online('veth99:routable', 'veth-peer:routable')