summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-11-02 12:58:50 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-11-03 03:15:00 +0900
commit59aa622013277cfe6349d0789a7a00ad2b884902 (patch)
tree9a1e282f03a54a2b9e027c9c0d6580c1668044e2
parent222cd15654fda4ec9d58f866ab57861ab19f5920 (diff)
downloadsystemd-59aa622013277cfe6349d0789a7a00ad2b884902.tar.gz
network: dhcp-server: introduce Router= setting to specify router address
Closes #21202.
-rw-r--r--man/systemd.network.xml16
-rw-r--r--src/libsystemd-network/dhcp-server-internal.h1
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c18
-rw-r--r--src/network/networkd-dhcp-server.c8
-rw-r--r--src/network/networkd-network-gperf.gperf1
-rw-r--r--src/network/networkd-network.h1
-rw-r--r--src/systemd/sd-dhcp-server.h2
-rw-r--r--test/fuzz/fuzz-network-parser/directives.network1
8 files changed, 32 insertions, 16 deletions
diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index f7c4e3e49e..49814a05eb 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -2482,12 +2482,16 @@ Token=prefixstable:2002:da8:1::</programlisting></para>
<varlistentry>
<term><varname>EmitRouter=</varname></term>
-
- <listitem><para>Similar to the <varname>EmitDNS=</varname>
- setting described above, this setting configures whether the
- DHCP lease should contain the router option. The same syntax,
- propagation semantics and defaults apply as for
- <varname>EmitDNS=</varname>.</para></listitem>
+ <term><varname>Router=</varname></term>
+
+ <listitem><para>The <varname>EmitRouter=</varname> setting takes a boolean value, and configures
+ whether the DHCP lease should contain the router option. The <varname>Router=</varname> setting
+ takes an IPv4 address, and configures the router address to be emitted. When the
+ <varname>Router=</varname> setting is not specified, then the server address will be used for
+ the router option. When the <varname>EmitRouter=</varname> setting is disabled, the
+ <varname>Router=</varname> setting will be ignored. The <varname>EmitRouter=</varname> setting
+ defaults to true, and the <varname>Router=</varname> setting defaults to unset.
+ </para></listitem>
</varlistentry>
<varlistentry>
diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h
index 3b87a4c066..13d8cd77b4 100644
--- a/src/libsystemd-network/dhcp-server-internal.h
+++ b/src/libsystemd-network/dhcp-server-internal.h
@@ -68,6 +68,7 @@ struct sd_dhcp_server {
OrderedSet *vendor_options;
bool emit_router;
+ struct in_addr router_address;
Hashmap *bound_leases_by_client_id;
Hashmap *bound_leases_by_address;
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index 604c34fe15..261818b46a 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -533,7 +533,10 @@ static int server_send_offer_or_ack(
if (server->emit_router) {
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
- SD_DHCP_OPTION_ROUTER, 4, &server->address);
+ SD_DHCP_OPTION_ROUTER, 4,
+ in4_addr_is_set(&server->router_address) ?
+ &server->router_address.s_addr :
+ &server->address);
if (r < 0)
return r;
}
@@ -1418,15 +1421,18 @@ int sd_dhcp_server_set_lpr(sd_dhcp_server *server, const struct in_addr lpr[], s
return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_LPR, lpr, n);
}
-int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled) {
+int sd_dhcp_server_set_router(sd_dhcp_server *server, const struct in_addr *router) {
assert_return(server, -EINVAL);
- if (enabled == server->emit_router)
- return 0;
+ /* router is NULL: router option will not be appended.
+ * router is null address (0.0.0.0): the server address will be used as the router address.
+ * otherwise: the specified address will be used as the router address.*/
- server->emit_router = enabled;
+ server->emit_router = router;
+ if (router)
+ server->router_address = *router;
- return 1;
+ return 0;
}
int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v) {
diff --git a/src/network/networkd-dhcp-server.c b/src/network/networkd-dhcp-server.c
index 45ef1b4903..9fa0c4233c 100644
--- a/src/network/networkd-dhcp-server.c
+++ b/src/network/networkd-dhcp-server.c
@@ -448,9 +448,11 @@ static int dhcp4_server_configure(Link *link) {
dhcp_lease_server_type_to_string(type));
}
- r = sd_dhcp_server_set_emit_router(link->dhcp_server, link->network->dhcp_server_emit_router);
- if (r < 0)
- return log_link_error_errno(link, r, "Failed to set router emission for DHCP server: %m");
+ if (link->network->dhcp_server_emit_router) {
+ r = sd_dhcp_server_set_router(link->dhcp_server, &link->network->dhcp_server_router);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Failed to set router address for DHCP server: %m");
+ }
r = sd_dhcp_server_set_relay_target(link->dhcp_server, &link->network->dhcp_server_relay_target);
if (r < 0)
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 595dd36121..1f0a625183 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -290,6 +290,7 @@ DHCPServer.SMTP, config_parse_dhcp_server_emit,
DHCPServer.EmitLPR, config_parse_bool, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_LPR].emit)
DHCPServer.LPR, config_parse_dhcp_server_emit, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_LPR])
DHCPServer.EmitRouter, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_router)
+DHCPServer.Router, config_parse_in_addr_non_null, AF_INET, offsetof(Network, dhcp_server_router)
DHCPServer.EmitTimezone, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_timezone)
DHCPServer.Timezone, config_parse_timezone, 0, offsetof(Network, dhcp_server_timezone)
DHCPServer.PoolOffset, config_parse_uint32, 0, offsetof(Network, dhcp_server_pool_offset)
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index 91553265da..f5258c9fcd 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -202,6 +202,7 @@ struct Network {
char *dhcp_server_relay_agent_remote_id;
NetworkDHCPServerEmitAddress dhcp_server_emit[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
bool dhcp_server_emit_router;
+ struct in_addr dhcp_server_router;
bool dhcp_server_emit_timezone;
char *dhcp_server_timezone;
usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
diff --git a/src/systemd/sd-dhcp-server.h b/src/systemd/sd-dhcp-server.h
index 149a14fdc6..59ef27e1dc 100644
--- a/src/systemd/sd-dhcp-server.h
+++ b/src/systemd/sd-dhcp-server.h
@@ -60,7 +60,7 @@ int sd_dhcp_server_configure_pool(sd_dhcp_server *server, const struct in_addr *
int sd_dhcp_server_set_bind_to_interface(sd_dhcp_server *server, int enabled);
int sd_dhcp_server_set_timezone(sd_dhcp_server *server, const char *timezone);
-int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled);
+int sd_dhcp_server_set_router(sd_dhcp_server *server, const struct in_addr *address);
int sd_dhcp_server_set_servers(
sd_dhcp_server *server,
diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network
index 985c2fc0d3..2ff20e0f08 100644
--- a/test/fuzz/fuzz-network-parser/directives.network
+++ b/test/fuzz/fuzz-network-parser/directives.network
@@ -379,6 +379,7 @@ SMTP=
EmitLPR=
LPR=
EmitRouter=
+Router=
MaxLeaseTimeSec=
DefaultLeaseTimeSec=
EmitTimezone=