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)
committerMichael Biebl <biebl@debian.org>
Sun, 17 May 2020 17:28:49 +0000 (18:28 +0100)
Closes #15117.

(cherry picked from commit b453122789ec4c6f39e6ceb9900e0e80a6abeb99)

Gbp-Pq: Name network-add-a-flag-to-ignore-gateway-provided-by-DHCP-ser.patch

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 bd19b766c37361eb87c88c00c9976d0a9492f3bd..120347d231bbbc11a11207520ac4c2ca1a805422 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 fb726c8634690d73d1be90db46ee2743dc64eaae..d3dda3df6b103a0c7c17497046c3385a95e165eb 100644 (file)
@@ -162,6 +162,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 2e716b291e9779b761a5fa7b15e1e75a4c2670e3..c643419142b1f6b1464d0aa112600755d6b6a83c 100644 (file)
@@ -383,6 +383,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 266e40cef518ab90566840212c33643533e5de6b..0d46dbb8de4a1bd8e34bb23752993a0764103b3a 100644 (file)
@@ -110,6 +110,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 2b41239b745817f49d6ce4b6e0aaf20861239d12..107ad06bc1ecec2e1e3ddaf1612c309baa70eea6 100644 (file)
@@ -73,6 +73,7 @@ UseDNS=
 RoutesToDNS=
 UseDomains=
 UseRoutes=
+UseGateway=
 IAID=
 UserClass=
 UseNTP=