mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
network: dhcp-server: introduce Router= setting to specify router address
Closes #21202.
This commit is contained in:
parent
222cd15654
commit
59aa622013
@ -2482,12 +2482,16 @@ Token=prefixstable:2002:da8:1::</programlisting></para>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>EmitRouter=</varname></term>
|
||||
<term><varname>Router=</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>
|
||||
<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>
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -379,6 +379,7 @@ SMTP=
|
||||
EmitLPR=
|
||||
LPR=
|
||||
EmitRouter=
|
||||
Router=
|
||||
MaxLeaseTimeSec=
|
||||
DefaultLeaseTimeSec=
|
||||
EmitTimezone=
|
||||
|
Loading…
Reference in New Issue
Block a user