teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0197-networkd-allow-specification-of-DHCP-route-metric.patch

Zbigniew Jędrzejewski-Szmek 62fe94
From 84b5b79a8f7b423c5b7cad4170eb68d57fe5e26c Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek 62fe94
From: Angus Gibson <angus@agibson.me>
Zbigniew Jędrzejewski-Szmek 62fe94
Date: Mon, 8 Sep 2014 20:26:47 +1000
Zbigniew Jędrzejewski-Szmek 62fe94
Subject: [PATCH] networkd: allow specification of DHCP route metric
Zbigniew Jędrzejewski-Szmek 62fe94
Zbigniew Jędrzejewski-Szmek 62fe94
This lets the routing metric for links to be specified per-network,
Zbigniew Jędrzejewski-Szmek 62fe94
still defaulting to DHCP_ROUTE_METRIC (1024) if unspecified. Hopefully
Zbigniew Jędrzejewski-Szmek 62fe94
this helps with multiple interfaces configured via DHCP.
Zbigniew Jędrzejewski-Szmek 62fe94
---
Zbigniew Jędrzejewski-Szmek 62fe94
 man/systemd.network.xml                  | 6 ++++++
Zbigniew Jędrzejewski-Szmek 62fe94
 src/network/networkd-dhcp4.c             | 6 +++---
Zbigniew Jędrzejewski-Szmek 62fe94
 src/network/networkd-network-gperf.gperf | 1 +
Zbigniew Jędrzejewski-Szmek 62fe94
 src/network/networkd-network.c           | 1 +
Zbigniew Jędrzejewski-Szmek 62fe94
 src/network/networkd.h                   | 1 +
Zbigniew Jędrzejewski-Szmek 62fe94
 5 files changed, 12 insertions(+), 3 deletions(-)
Zbigniew Jędrzejewski-Szmek 62fe94
Zbigniew Jędrzejewski-Szmek 62fe94
diff --git a/man/systemd.network.xml b/man/systemd.network.xml
Zbigniew Jędrzejewski-Szmek 62fe94
index 641e02aab1..4cc13b2afc 100644
Zbigniew Jędrzejewski-Szmek 62fe94
--- a/man/systemd.network.xml
Zbigniew Jędrzejewski-Szmek 62fe94
+++ b/man/systemd.network.xml
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -494,6 +494,12 @@
Zbigniew Jędrzejewski-Szmek 62fe94
                                                 hand, this must not be enabled on networks where broadcasts are filtered out.</para>
Zbigniew Jędrzejewski-Szmek 62fe94
                                         </listitem>
Zbigniew Jędrzejewski-Szmek 62fe94
                                 </varlistentry>
Zbigniew Jędrzejewski-Szmek 62fe94
+                                <varlistentry>
Zbigniew Jędrzejewski-Szmek 62fe94
+                                        <term><varname>RouteMetric=</varname></term>
Zbigniew Jędrzejewski-Szmek 62fe94
+                                        <listitem>
Zbigniew Jędrzejewski-Szmek 62fe94
+                                                <para>Set the routing metric for routes specified by the DHCP server.</para>
Zbigniew Jędrzejewski-Szmek 62fe94
+                                        </listitem>
Zbigniew Jędrzejewski-Szmek 62fe94
+                                </varlistentry>
Zbigniew Jędrzejewski-Szmek 62fe94
                        </variablelist>
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
         </refsect1>
Zbigniew Jędrzejewski-Szmek 62fe94
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
Zbigniew Jędrzejewski-Szmek 62fe94
index b87fa73082..e0b3acad1b 100644
Zbigniew Jędrzejewski-Szmek 62fe94
--- a/src/network/networkd-dhcp4.c
Zbigniew Jędrzejewski-Szmek 62fe94
+++ b/src/network/networkd-dhcp4.c
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -103,7 +103,7 @@ static int link_set_dhcp_routes(Link *link) {
Zbigniew Jędrzejewski-Szmek 62fe94
                 route_gw->dst_prefixlen = 32;
Zbigniew Jędrzejewski-Szmek 62fe94
                 route_gw->prefsrc_addr.in = address;
Zbigniew Jędrzejewski-Szmek 62fe94
                 route_gw->scope = RT_SCOPE_LINK;
Zbigniew Jędrzejewski-Szmek 62fe94
-                route_gw->metrics = DHCP_ROUTE_METRIC;
Zbigniew Jędrzejewski-Szmek 62fe94
+                route_gw->metrics = link->network->dhcp_route_metric;
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
                 r = route_configure(route_gw, link, &dhcp4_route_handler);
Zbigniew Jędrzejewski-Szmek 62fe94
                 if (r < 0) {
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -118,7 +118,7 @@ static int link_set_dhcp_routes(Link *link) {
Zbigniew Jędrzejewski-Szmek 62fe94
                 route->family = AF_INET;
Zbigniew Jędrzejewski-Szmek 62fe94
                 route->in_addr.in = gateway;
Zbigniew Jędrzejewski-Szmek 62fe94
                 route->prefsrc_addr.in = address;
Zbigniew Jędrzejewski-Szmek 62fe94
-                route->metrics = DHCP_ROUTE_METRIC;
Zbigniew Jędrzejewski-Szmek 62fe94
+                route->metrics = link->network->dhcp_route_metric;
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
                 r = route_configure(route, link, &dhcp4_route_handler);
Zbigniew Jędrzejewski-Szmek 62fe94
                 if (r < 0) {
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -157,7 +157,7 @@ static int link_set_dhcp_routes(Link *link) {
Zbigniew Jędrzejewski-Szmek 62fe94
                 route->in_addr.in = static_routes[i].gw_addr;
Zbigniew Jędrzejewski-Szmek 62fe94
                 route->dst_addr.in = static_routes[i].dst_addr;
Zbigniew Jędrzejewski-Szmek 62fe94
                 route->dst_prefixlen = static_routes[i].dst_prefixlen;
Zbigniew Jędrzejewski-Szmek 62fe94
-                route->metrics = DHCP_ROUTE_METRIC;
Zbigniew Jędrzejewski-Szmek 62fe94
+                route->metrics = link->network->dhcp_route_metric;
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
                 r = route_configure(route, link, &dhcp4_route_handler);
Zbigniew Jędrzejewski-Szmek 62fe94
                 if (r < 0) {
Zbigniew Jędrzejewski-Szmek 62fe94
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
Zbigniew Jędrzejewski-Szmek 62fe94
index c5b9614a2b..a73646187e 100644
Zbigniew Jędrzejewski-Szmek 62fe94
--- a/src/network/networkd-network-gperf.gperf
Zbigniew Jędrzejewski-Szmek 62fe94
+++ b/src/network/networkd-network-gperf.gperf
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -57,6 +57,7 @@ DHCP.SendHostname,           config_parse_bool,                  0,
Zbigniew Jędrzejewski-Szmek 62fe94
 DHCP.RequestBroadcast,       config_parse_bool,                  0,                             offsetof(Network, dhcp_broadcast)
Zbigniew Jędrzejewski-Szmek 62fe94
 DHCP.CriticalConnection,     config_parse_bool,                  0,                             offsetof(Network, dhcp_critical)
Zbigniew Jędrzejewski-Szmek 62fe94
 DHCP.VendorClassIdentifier,  config_parse_string,                0,                             offsetof(Network, dhcp_vendor_class_identifier)
Zbigniew Jędrzejewski-Szmek 62fe94
+DHCP.RouteMetric,            config_parse_unsigned,              0,                             offsetof(Network, dhcp_route_metric)
Zbigniew Jędrzejewski-Szmek 62fe94
 /* backwards compatibility: do not add new entries to this section */
Zbigniew Jędrzejewski-Szmek 62fe94
 DHCPv4.UseDNS,               config_parse_bool,                  0,                             offsetof(Network, dhcp_dns)
Zbigniew Jędrzejewski-Szmek 62fe94
 DHCPv4.UseMTU,               config_parse_bool,                  0,                             offsetof(Network, dhcp_mtu)
Zbigniew Jędrzejewski-Szmek 62fe94
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
Zbigniew Jędrzejewski-Szmek 62fe94
index fc62395217..a2e27e0910 100644
Zbigniew Jędrzejewski-Szmek 62fe94
--- a/src/network/networkd-network.c
Zbigniew Jędrzejewski-Szmek 62fe94
+++ b/src/network/networkd-network.c
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -85,6 +85,7 @@ static int network_load_one(Manager *manager, const char *filename) {
Zbigniew Jędrzejewski-Szmek 62fe94
         network->dhcp_hostname = true;
Zbigniew Jędrzejewski-Szmek 62fe94
         network->dhcp_routes = true;
Zbigniew Jędrzejewski-Szmek 62fe94
         network->dhcp_sendhost = true;
Zbigniew Jędrzejewski-Szmek 62fe94
+        network->dhcp_route_metric = DHCP_ROUTE_METRIC;
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
         network->llmnr = LLMNR_SUPPORT_YES;
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
diff --git a/src/network/networkd.h b/src/network/networkd.h
Zbigniew Jędrzejewski-Szmek 62fe94
index c6e6b22c38..7c5459b6ac 100644
Zbigniew Jędrzejewski-Szmek 62fe94
--- a/src/network/networkd.h
Zbigniew Jędrzejewski-Szmek 62fe94
+++ b/src/network/networkd.h
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -100,6 +100,7 @@ struct Network {
Zbigniew Jędrzejewski-Szmek 62fe94
         bool dhcp_broadcast;
Zbigniew Jędrzejewski-Szmek 62fe94
         bool dhcp_critical;
Zbigniew Jędrzejewski-Szmek 62fe94
         bool dhcp_routes;
Zbigniew Jędrzejewski-Szmek 62fe94
+        unsigned dhcp_route_metric;
Zbigniew Jędrzejewski-Szmek 62fe94
         bool ipv4ll;
Zbigniew Jędrzejewski-Szmek 62fe94
         bool ipv4ll_route;
Zbigniew Jędrzejewski-Szmek 62fe94