Skip to content

Commit eb27aec

Browse files
committed
networkd: dhcpv4 - add notion of 'CriticalConnection'
These connections are never torn down, even when the DHCP specifications say that they should be. This is useful/necessary when the rootfs (or another critical fs) is mounted over this network connection, and dataloss would result if the connection is lost. This option defaults to off, but our initrd generator (TBD) will enable it when applicable.
1 parent e7fb33f commit eb27aec

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

man/systemd-networkd.service.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@
293293
will be used as the transient hostname.</para>
294294
</listitem>
295295
</varlistentry>
296+
<varlistentry>
297+
<term><varname>CriticalConnection</varname></term>
298+
<listitem>
299+
<para>When true the connection will never be torn down even if the DHCP lease
300+
expires. This is contrary to the DHCP specification, but may be the best choice
301+
if, say, the root filesystem relies on this connection. Defaults to false.</para>
302+
</listitem>
303+
</varlistentry>
296304
</variablelist>
297305

298306
</refsect2>

src/network/networkd-gperf.gperf

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,29 @@ struct ConfigPerfItem;
1515
%struct-type
1616
%includes
1717
%%
18-
Match.MACAddress, config_parse_hwaddr, 0, offsetof(Network, match_mac)
19-
Match.Path, config_parse_string, 0, offsetof(Network, match_path)
20-
Match.Driver, config_parse_string, 0, offsetof(Network, match_driver)
21-
Match.Type, config_parse_string, 0, offsetof(Network, match_type)
22-
Match.Name, config_parse_ifname, 0, offsetof(Network, match_name)
23-
Network.Description, config_parse_string, 0, offsetof(Network, description)
24-
Network.Bridge, config_parse_bridge, 0, offsetof(Network, bridge)
25-
Network.Bond, config_parse_bond, 0, offsetof(Network, bond)
26-
Network.VLAN, config_parse_vlan, 0, offsetof(Network, vlan)
27-
Network.DHCP, config_parse_bool, 0, offsetof(Network, dhcp)
28-
Network.Address, config_parse_address, 0, 0
29-
Network.Gateway, config_parse_gateway, 0, 0
30-
Network.DNS, config_parse_dns, 0, offsetof(Network, dns)
31-
Address.Address, config_parse_address, 0, 0
32-
Address.Label, config_parse_label, 0, 0
33-
Route.Gateway, config_parse_gateway, 0, 0
34-
Route.Destination, config_parse_destination, 0, 0
35-
DHCPv4.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp_dns)
36-
DHCPv4.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_mtu)
37-
DHCPv4.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_hostname)
38-
DHCPv4.UseDomainName, config_parse_bool, 0, offsetof(Network, dhcp_domainname)
39-
Netdev.Description, config_parse_string, 0, offsetof(Netdev, description)
40-
Netdev.Name, config_parse_ifname, 0, offsetof(Netdev, name)
41-
Netdev.Kind, config_parse_netdev_kind, 0, offsetof(Netdev, kind)
42-
VLAN.Id, config_parse_int, 0, offsetof(Netdev, vlanid)
18+
Match.MACAddress, config_parse_hwaddr, 0, offsetof(Network, match_mac)
19+
Match.Path, config_parse_string, 0, offsetof(Network, match_path)
20+
Match.Driver, config_parse_string, 0, offsetof(Network, match_driver)
21+
Match.Type, config_parse_string, 0, offsetof(Network, match_type)
22+
Match.Name, config_parse_ifname, 0, offsetof(Network, match_name)
23+
Network.Description, config_parse_string, 0, offsetof(Network, description)
24+
Network.Bridge, config_parse_bridge, 0, offsetof(Network, bridge)
25+
Network.Bond, config_parse_bond, 0, offsetof(Network, bond)
26+
Network.VLAN, config_parse_vlan, 0, offsetof(Network, vlan)
27+
Network.DHCP, config_parse_bool, 0, offsetof(Network, dhcp)
28+
Network.Address, config_parse_address, 0, 0
29+
Network.Gateway, config_parse_gateway, 0, 0
30+
Network.DNS, config_parse_dns, 0, offsetof(Network, dns)
31+
Address.Address, config_parse_address, 0, 0
32+
Address.Label, config_parse_label, 0, 0
33+
Route.Gateway, config_parse_gateway, 0, 0
34+
Route.Destination, config_parse_destination, 0, 0
35+
DHCPv4.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp_dns)
36+
DHCPv4.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_mtu)
37+
DHCPv4.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_hostname)
38+
DHCPv4.UseDomainName, config_parse_bool, 0, offsetof(Network, dhcp_domainname)
39+
DHCPv4.CriticalConnection, config_parse_bool, 0, offsetof(Network, dhcp_critical)
40+
Netdev.Description, config_parse_string, 0, offsetof(Netdev, description)
41+
Netdev.Name, config_parse_ifname, 0, offsetof(Netdev, name)
42+
Netdev.Kind, config_parse_netdev_kind, 0, offsetof(Netdev, kind)
43+
VLAN.Id, config_parse_int, 0, offsetof(Netdev, vlanid)

src/network/networkd-link.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) {
443443

444444
if (event == DHCP_EVENT_IP_CHANGE || event == DHCP_EVENT_EXPIRED ||
445445
event == DHCP_EVENT_STOP) {
446+
if (link->network->dhcp_critical) {
447+
log_warning_link(link, "DHCPv4 connection considered system critical, "
448+
"ignoring request to reconfigure it down.");
449+
return;
450+
}
451+
446452
if (link->dhcp_address) {
447453
address_drop(link->dhcp_address, link, address_drop_handler);
448454

src/network/networkd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct Network {
103103
bool dhcp_mtu;
104104
bool dhcp_hostname;
105105
bool dhcp_domainname;
106+
bool dhcp_critical;
106107

107108
LIST_HEAD(Address, static_addresses);
108109
LIST_HEAD(Route, static_routes);

0 commit comments

Comments
 (0)