]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: add a flag to ignore gateway provided by DHCP server
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Mar 2020 09:55:10 +0000 (18:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Mar 2020 10:34:43 +0000 (19:34 +0900)
Closes #15117.

man/systemd.network.xml
src/network/networkd-dhcp4.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h
test/fuzz/fuzz-network-parser/directives.network

index a174a1fb248246dc96c53b0414839b73cfa0aa69..3dfc43e43d6e66cb9ccd16d151406fed2ccfe713 100644 (file)
               "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>
 
index 13e3e32f40e8c6add46c852127b8f29d9beb6e5a..3f6580422eec7bbcf45f0220da1d979412278bd3 100644 (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);
index e1b9b5687af5029003b5e3bdd0cacd4359513d75..e690ef85a9b7964f183c1beb2749f2ff436e8c35 100644 (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)
index f99886d5f96e1699c9093ab01972b2f56a6aeb3b..248172f8a204b8ce8059685603cf3ab22ec79950 100644 (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,
index f8ecb1f687ba9ad0e132a3107f05998a1dc0b0a1..6fe87d8915387e12a39099d12cf3c6a3497f0f1a 100644 (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;
index a729adcc86f4fb630771e28cadc09ccc5e19fe5a..bfaeaaf4be259365cc482ec7700254157f2b34ab 100644 (file)
@@ -73,6 +73,7 @@ UseDNS=
 RoutesToDNS=
 UseDomains=
 UseRoutes=
+UseGateway=
 IAID=
 UserClass=
 UseNTP=