mirror of
https://github.com/systemd/systemd.git
synced 2025-01-10 05:18:17 +03:00
Merge pull request #21210 from yuwata/network-dhcp-server-introduce-router-setting
network: dhcp-server: introduce Router= setting to specify router address
This commit is contained in:
commit
ab7b261663
@ -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=
|
||||
|
@ -11,3 +11,4 @@ ServerAddress=192.168.5.1/24
|
||||
PoolOffset=10
|
||||
PoolSize=50
|
||||
UplinkInterface=dummy98
|
||||
Router=192.168.5.3
|
||||
|
@ -3989,10 +3989,10 @@ class NetworkdDHCPServerTests(unittest.TestCase, Utilities):
|
||||
|
||||
output = check_output(*networkctl_cmd, '-n', '0', 'status', 'veth99', env=env)
|
||||
print(output)
|
||||
self.assertRegex(output, '192.168.5.*')
|
||||
self.assertRegex(output, 'Gateway: 192.168.5.1')
|
||||
self.assertRegex(output, 'DNS: 192.168.5.1')
|
||||
self.assertRegex(output, 'NTP: 192.168.5.1')
|
||||
self.assertRegex(output, 'Address: 192.168.5.[0-9]* \(DHCP4 via 192.168.5.1\)')
|
||||
self.assertIn('Gateway: 192.168.5.3', output)
|
||||
self.assertIn('DNS: 192.168.5.1', output)
|
||||
self.assertIn('NTP: 192.168.5.1', output)
|
||||
|
||||
def test_emit_router_timezone(self):
|
||||
copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
|
||||
@ -4001,9 +4001,9 @@ class NetworkdDHCPServerTests(unittest.TestCase, Utilities):
|
||||
|
||||
output = check_output(*networkctl_cmd, '-n', '0', 'status', 'veth99', env=env)
|
||||
print(output)
|
||||
self.assertRegex(output, 'Gateway: 192.168.5.*')
|
||||
self.assertRegex(output, '192.168.5.*')
|
||||
self.assertRegex(output, 'Europe/Berlin')
|
||||
self.assertRegex(output, 'Address: 192.168.5.[0-9]* \(DHCP4 via 192.168.5.1\)')
|
||||
self.assertIn('Gateway: 192.168.5.1', output)
|
||||
self.assertIn('Time Zone: Europe/Berlin', output)
|
||||
|
||||
def test_dhcp_server_static_lease(self):
|
||||
copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-static-lease.network', 'dhcp-server-static-lease.network')
|
||||
@ -4012,7 +4012,7 @@ class NetworkdDHCPServerTests(unittest.TestCase, Utilities):
|
||||
|
||||
output = check_output(*networkctl_cmd, '-n', '0', 'status', 'veth99', env=env)
|
||||
print(output)
|
||||
self.assertIn('10.1.1.200 (DHCP4 via 10.1.1.1)', output)
|
||||
self.assertIn('Address: 10.1.1.200 (DHCP4 via 10.1.1.1)', output)
|
||||
|
||||
class NetworkdDHCPServerRelayAgentTests(unittest.TestCase, Utilities):
|
||||
links = [
|
||||
|
Loading…
Reference in New Issue
Block a user