1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-08 21:17:47 +03:00

network: dhcp-server: introduce Router= setting to specify router address

Closes #21202.
This commit is contained in:
Yu Watanabe 2021-11-02 12:58:50 +09:00
parent 222cd15654
commit 59aa622013
8 changed files with 31 additions and 15 deletions

View File

@ -2482,12 +2482,16 @@ Token=prefixstable:2002:da8:1::</programlisting></para>
<varlistentry> <varlistentry>
<term><varname>EmitRouter=</varname></term> <term><varname>EmitRouter=</varname></term>
<term><varname>Router=</varname></term>
<listitem><para>Similar to the <varname>EmitDNS=</varname> <listitem><para>The <varname>EmitRouter=</varname> setting takes a boolean value, and configures
setting described above, this setting configures whether the whether the DHCP lease should contain the router option. The <varname>Router=</varname> setting
DHCP lease should contain the router option. The same syntax, takes an IPv4 address, and configures the router address to be emitted. When the
propagation semantics and defaults apply as for <varname>Router=</varname> setting is not specified, then the server address will be used for
<varname>EmitDNS=</varname>.</para></listitem> 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>
<varlistentry> <varlistentry>

View File

@ -68,6 +68,7 @@ struct sd_dhcp_server {
OrderedSet *vendor_options; OrderedSet *vendor_options;
bool emit_router; bool emit_router;
struct in_addr router_address;
Hashmap *bound_leases_by_client_id; Hashmap *bound_leases_by_client_id;
Hashmap *bound_leases_by_address; Hashmap *bound_leases_by_address;

View File

@ -533,7 +533,10 @@ static int server_send_offer_or_ack(
if (server->emit_router) { if (server->emit_router) {
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, 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) if (r < 0)
return r; 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); 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); assert_return(server, -EINVAL);
if (enabled == server->emit_router) /* 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 = router;
if (router)
server->router_address = *router;
return 0; return 0;
server->emit_router = enabled;
return 1;
} }
int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v) { int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v) {

View File

@ -448,9 +448,11 @@ static int dhcp4_server_configure(Link *link) {
dhcp_lease_server_type_to_string(type)); dhcp_lease_server_type_to_string(type));
} }
r = sd_dhcp_server_set_emit_router(link->dhcp_server, link->network->dhcp_server_emit_router); if (link->network->dhcp_server_emit_router) {
r = sd_dhcp_server_set_router(link->dhcp_server, &link->network->dhcp_server_router);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Failed to set router emission for DHCP server: %m"); 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); r = sd_dhcp_server_set_relay_target(link->dhcp_server, &link->network->dhcp_server_relay_target);
if (r < 0) if (r < 0)

View File

@ -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.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.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.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.EmitTimezone, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_timezone)
DHCPServer.Timezone, config_parse_timezone, 0, offsetof(Network, dhcp_server_timezone) DHCPServer.Timezone, config_parse_timezone, 0, offsetof(Network, dhcp_server_timezone)
DHCPServer.PoolOffset, config_parse_uint32, 0, offsetof(Network, dhcp_server_pool_offset) DHCPServer.PoolOffset, config_parse_uint32, 0, offsetof(Network, dhcp_server_pool_offset)

View File

@ -202,6 +202,7 @@ struct Network {
char *dhcp_server_relay_agent_remote_id; char *dhcp_server_relay_agent_remote_id;
NetworkDHCPServerEmitAddress dhcp_server_emit[_SD_DHCP_LEASE_SERVER_TYPE_MAX]; NetworkDHCPServerEmitAddress dhcp_server_emit[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
bool dhcp_server_emit_router; bool dhcp_server_emit_router;
struct in_addr dhcp_server_router;
bool dhcp_server_emit_timezone; bool dhcp_server_emit_timezone;
char *dhcp_server_timezone; char *dhcp_server_timezone;
usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec; usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;

View File

@ -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_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_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( int sd_dhcp_server_set_servers(
sd_dhcp_server *server, sd_dhcp_server *server,

View File

@ -379,6 +379,7 @@ SMTP=
EmitLPR= EmitLPR=
LPR= LPR=
EmitRouter= EmitRouter=
Router=
MaxLeaseTimeSec= MaxLeaseTimeSec=
DefaultLeaseTimeSec= DefaultLeaseTimeSec=
EmitTimezone= EmitTimezone=