ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
Blob Blame History Raw
From 84b5b79a8f7b423c5b7cad4170eb68d57fe5e26c Mon Sep 17 00:00:00 2001
From: Angus Gibson <angus@agibson.me>
Date: Mon, 8 Sep 2014 20:26:47 +1000
Subject: [PATCH] networkd: allow specification of DHCP route metric

This lets the routing metric for links to be specified per-network,
still defaulting to DHCP_ROUTE_METRIC (1024) if unspecified. Hopefully
this helps with multiple interfaces configured via DHCP.
---
 man/systemd.network.xml                  | 6 ++++++
 src/network/networkd-dhcp4.c             | 6 +++---
 src/network/networkd-network-gperf.gperf | 1 +
 src/network/networkd-network.c           | 1 +
 src/network/networkd.h                   | 1 +
 5 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 641e02aab1..4cc13b2afc 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -494,6 +494,12 @@
                                                 hand, this must not be enabled on networks where broadcasts are filtered out.</para>
                                         </listitem>
                                 </varlistentry>
+                                <varlistentry>
+                                        <term><varname>RouteMetric=</varname></term>
+                                        <listitem>
+                                                <para>Set the routing metric for routes specified by the DHCP server.</para>
+                                        </listitem>
+                                </varlistentry>
                        </variablelist>
 
         </refsect1>
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index b87fa73082..e0b3acad1b 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -103,7 +103,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route_gw->dst_prefixlen = 32;
                 route_gw->prefsrc_addr.in = address;
                 route_gw->scope = RT_SCOPE_LINK;
-                route_gw->metrics = DHCP_ROUTE_METRIC;
+                route_gw->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route_gw, link, &dhcp4_route_handler);
                 if (r < 0) {
@@ -118,7 +118,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route->family = AF_INET;
                 route->in_addr.in = gateway;
                 route->prefsrc_addr.in = address;
-                route->metrics = DHCP_ROUTE_METRIC;
+                route->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route, link, &dhcp4_route_handler);
                 if (r < 0) {
@@ -157,7 +157,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route->in_addr.in = static_routes[i].gw_addr;
                 route->dst_addr.in = static_routes[i].dst_addr;
                 route->dst_prefixlen = static_routes[i].dst_prefixlen;
-                route->metrics = DHCP_ROUTE_METRIC;
+                route->metrics = link->network->dhcp_route_metric;
 
                 r = route_configure(route, link, &dhcp4_route_handler);
                 if (r < 0) {
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index c5b9614a2b..a73646187e 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -57,6 +57,7 @@ DHCP.SendHostname,           config_parse_bool,                  0,
 DHCP.RequestBroadcast,       config_parse_bool,                  0,                             offsetof(Network, dhcp_broadcast)
 DHCP.CriticalConnection,     config_parse_bool,                  0,                             offsetof(Network, dhcp_critical)
 DHCP.VendorClassIdentifier,  config_parse_string,                0,                             offsetof(Network, dhcp_vendor_class_identifier)
+DHCP.RouteMetric,            config_parse_unsigned,              0,                             offsetof(Network, dhcp_route_metric)
 /* backwards compatibility: do not add new entries to this section */
 DHCPv4.UseDNS,               config_parse_bool,                  0,                             offsetof(Network, dhcp_dns)
 DHCPv4.UseMTU,               config_parse_bool,                  0,                             offsetof(Network, dhcp_mtu)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index fc62395217..a2e27e0910 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -85,6 +85,7 @@ static int network_load_one(Manager *manager, const char *filename) {
         network->dhcp_hostname = true;
         network->dhcp_routes = true;
         network->dhcp_sendhost = true;
+        network->dhcp_route_metric = DHCP_ROUTE_METRIC;
 
         network->llmnr = LLMNR_SUPPORT_YES;
 
diff --git a/src/network/networkd.h b/src/network/networkd.h
index c6e6b22c38..7c5459b6ac 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -100,6 +100,7 @@ struct Network {
         bool dhcp_broadcast;
         bool dhcp_critical;
         bool dhcp_routes;
+        unsigned dhcp_route_metric;
         bool ipv4ll;
         bool ipv4ll_route;