1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

network: add a flag to ignore gateway provided by DHCP server

Closes #15117.
This commit is contained in:
Yu Watanabe 2020-03-16 18:55:10 +09:00
parent f12d19b304
commit b453122789
6 changed files with 15 additions and 2 deletions

View File

@ -1474,7 +1474,13 @@
"link" scope will be used. For anything else, scope defaults to "global".</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UseGateway=</varname></term>
<listitem>
<para>When true (the default), the gateway will be requested from the DHCP server and added to the
routing table with a metric of 1024, and a scope of "link".</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UseTimezone=</varname></term>

View File

@ -323,6 +323,9 @@ static int link_set_dhcp_routes(Link *link) {
}
}
if (!link->network->dhcp_use_gateway)
return 0;
r = sd_dhcp_lease_get_router(link->dhcp_lease, &router);
if (IN_SET(r, 0, -ENODATA))
log_link_info(link, "DHCP: No gateway received from DHCP server.");
@ -451,7 +454,7 @@ static int dhcp_remove_router(Link *link, sd_dhcp_lease *lease, const struct in_
assert(link);
assert(address);
if (!link->network->dhcp_use_routes)
if (!link->network->dhcp_use_gateway)
return 0;
r = sd_dhcp_lease_get_router(lease, &router);

View File

@ -163,6 +163,7 @@ DHCPv4.UseMTU, config_parse_bool,
DHCPv4.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_use_hostname)
DHCPv4.UseDomains, config_parse_dhcp_use_domains, 0, offsetof(Network, dhcp_use_domains)
DHCPv4.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_use_routes)
DHCPv4.UseGateway, config_parse_bool, 0, offsetof(Network, dhcp_use_gateway)
DHCPv4.RequestOptions, config_parse_dhcp_request_options, 0, 0
DHCPv4.Anonymize, config_parse_bool, 0, offsetof(Network, dhcp_anonymize)
DHCPv4.SendHostname, config_parse_bool, 0, offsetof(Network, dhcp_send_hostname)

View File

@ -384,6 +384,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
.dhcp_use_dns = true,
.dhcp_use_hostname = true,
.dhcp_use_routes = true,
.dhcp_use_gateway = true,
/* NOTE: this var might be overwritten by network_apply_anonymize_if_set */
.dhcp_send_hostname = true,
.dhcp_send_release = true,

View File

@ -109,6 +109,7 @@ struct Network {
bool dhcp_use_sip;
bool dhcp_use_mtu;
bool dhcp_use_routes;
bool dhcp_use_gateway;
bool dhcp_use_timezone;
bool rapid_commit;
bool dhcp_use_hostname;

View File

@ -73,6 +73,7 @@ UseDNS=
RoutesToDNS=
UseDomains=
UseRoutes=
UseGateway=
IAID=
UserClass=
UseNTP=