From 369ac19243d984a4dae685aaeeecc1d8faf99a45 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 25 Feb 2022 02:43:40 +0900 Subject: [PATCH] network: add NextServer= and Filename= setting to [DHCPServer] section Closes #4403. --- man/systemd.network.xml | 17 +++++++++++++++++ src/network/networkd-dhcp-server.c | 8 ++++++++ src/network/networkd-network-gperf.gperf | 2 ++ src/network/networkd-network.c | 1 + src/network/networkd-network.h | 2 ++ .../fuzz/fuzz-network-parser/directives.network | 2 ++ 6 files changed, 32 insertions(+) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 5939e38a00a..3f5a22e801b 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -2626,6 +2626,23 @@ Token=prefixstable:2002:da8:1:: /etc/localtime symlink. + + NextServer= + + + Takes an IPv4 address. Configures the next server used by e.g. PXE boot systems. + Defaults to unset. + + + + + Filename= + + + Takes a path or url to a file loaded by e.g. a PXE boot loader. Defaults to unset. + + + SendOption= diff --git a/src/network/networkd-dhcp-server.c b/src/network/networkd-dhcp-server.c index b28d13ba65a..c4eaac3dee3 100644 --- a/src/network/networkd-dhcp-server.c +++ b/src/network/networkd-dhcp-server.c @@ -416,6 +416,14 @@ static int dhcp4_server_configure(Link *link) { return log_link_error_errno(link, r, "Failed to set default lease time for DHCPv4 server instance: %m"); } + r = sd_dhcp_server_set_next_server(link->dhcp_server, &link->network->dhcp_server_next_server); + if (r < 0) + return log_link_warning_errno(link, r, "Failed to set next server for DHCPv4 server instance: %m"); + + r = sd_dhcp_server_set_filename(link->dhcp_server, link->network->dhcp_server_filename); + if (r < 0) + return log_link_warning_errno(link, r, "Failed to set filename for DHCPv4 server instance: %m"); + for (sd_dhcp_lease_server_type_t type = 0; type < _SD_DHCP_LEASE_SERVER_TYPE_MAX; type ++) { if (!link->network->dhcp_server_emit[type].emit) diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index edce61996ad..5d83a25c701 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -305,6 +305,8 @@ DHCPServer.PoolSize, config_parse_uint32, DHCPServer.SendVendorOption, config_parse_dhcp_send_option, 0, offsetof(Network, dhcp_server_send_vendor_options) DHCPServer.SendOption, config_parse_dhcp_send_option, 0, offsetof(Network, dhcp_server_send_options) DHCPServer.BindToInterface, config_parse_bool, 0, offsetof(Network, dhcp_server_bind_to_interface) +DHCPServer.NextServer, config_parse_in_addr_non_null, AF_INET, offsetof(Network, dhcp_server_next_server) +DHCPServer.Filename, config_parse_string, 0, offsetof(Network, dhcp_server_filename) DHCPServerStaticLease.Address, config_parse_dhcp_static_lease_address, 0, 0 DHCPServerStaticLease.MACAddress, config_parse_dhcp_static_lease_hwaddr, 0, 0 Bridge.Cost, config_parse_uint32, 0, offsetof(Network, cost) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index a2c68254390..eeededcb6c8 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -700,6 +700,7 @@ static Network *network_free(Network *network) { free(network->dhcp_server_relay_agent_circuit_id); free(network->dhcp_server_relay_agent_remote_id); + free(network->dhcp_server_filename); free(network->description); free(network->dhcp_vendor_class_identifier); diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 47248f790b8..299d84ed8b5 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -200,6 +200,8 @@ struct Network { uint32_t dhcp_server_pool_size; OrderedHashmap *dhcp_server_send_options; OrderedHashmap *dhcp_server_send_vendor_options; + struct in_addr dhcp_server_next_server; + char *dhcp_server_filename; /* link local addressing support */ AddressFamily link_local; diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network index ef302dca7b7..c682ac4ac1a 100644 --- a/test/fuzz/fuzz-network-parser/directives.network +++ b/test/fuzz/fuzz-network-parser/directives.network @@ -409,6 +409,8 @@ RelayAgentCircuitId= RelayAgentRemoteId= ServerAddress= UplinkInterface= +NextServer= +Filename= [DHCPServerStaticLease] MACAddress= Address=