network/dhcp: introduce global setting for DHCPv4 client identifier (#35783)

Typically, the same client identifier setting is used for all
interfaces. Hence, better to provide the system-wide setting to specify
the client identifier.
This commit is contained in:
Daan De Meyer
2025-01-03 09:19:55 +01:00
committed by GitHub
10 changed files with 50 additions and 14 deletions
+20 -9
View File
@@ -247,16 +247,29 @@
<refsect1>
<title>[DHCPv4] Section Options</title>
<para>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
<option>ClientIdentifier=duid</option>. 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
<para>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 <filename>.network</filename> file. See also
<citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
<para>The following options are understood:</para>
<variablelist class='network-directives'>
<varlistentry>
<term><varname>ClientIdentifier=</varname></term>
<listitem>
<para>Specifies the default DHCPv4 client identifier to be used. Takes one of <option>mac</option>
or <option>duid</option>. If set to <option>mac</option>, the MAC address of each link will be used.
If set to <option>duid</option>, an RFC4361-compliant Client ID, which is the combination of IAID
and DUID, is used. IAID can be configured by <varname>IAID=</varname> in each matching
<filename>.network</filename> file. DUID can be configured by <varname>DUIDType=</varname> and
<varname>DUIDRawData=</varname>. Defaults to <option>duid</option>.</para>
<xi:include href="version-info.xml" xpointer="v258"/>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>DUIDType=</varname></term>
<listitem><para>Specifies how the DUID should be generated. See
@@ -354,11 +367,9 @@ DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00</programlisting>
<refsect1>
<title>[DHCPv6] Section Options</title>
<para>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
<para>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 <filename>.network</filename> file. See also
<citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
+5 -2
View File
@@ -2371,8 +2371,11 @@ NFTSet=prefix:netdev:filter:eth_ipv4_prefix</programlisting>
<option>duid</option>. If set to <option>mac</option>, the MAC address of the link is used. If set
to <option>duid</option>, an RFC4361-compliant Client ID, which is the combination of IAID and
DUID, is used. IAID can be configured by <varname>IAID=</varname>. DUID can be configured by
<varname>DUIDType=</varname> and <varname>DUIDRawData=</varname>. Defaults to
<option>duid</option>.</para>
<varname>DUIDType=</varname> and <varname>DUIDRawData=</varname>. When
<varname>Anonymize=</varname> is enabled, <option>mac</option> is unconditionally used and the
specified value will be ignored. When unspecified, the value specified in the same setting in
<citerefentry><refentrytitle>networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
will be used.</para>
<xi:include href="version-info.xml" xpointer="v220"/>
</listitem>
+1 -1
View File
@@ -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)
+1
View File
@@ -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)
+1
View File
@@ -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,
+1
View File
@@ -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;
+1
View File
@@ -36,6 +36,7 @@
#UseDomains=
[DHCPv4]
#ClientIdentifier=duid
#DUIDType=vendor
#DUIDRawData=
#UseDomains=
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[DHCPv4]
ClientIdentifier=duid
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[DHCPv4]
ClientIdentifier=mac
+14 -2
View File
@@ -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')