chiark / gitweb /
networkd: make metric of routes configurable
authorSusant Sahani <susant@redhat.com>
Thu, 10 Jul 2014 17:39:58 +0000 (23:09 +0530)
committerTom Gundersen <teg@jklm.no>
Mon, 14 Jul 2014 09:39:20 +0000 (11:39 +0200)
Now route metric can be configuted via conf file:

example conf:

[Match]
Name=em1

[Route]
Gateway=192.168.1.12
Metric=10

Test:
ip route output
default via 192.168.1.12 dev em1 metric 10

[tomegun: squash TODO update and reword man page a bit]

TODO
man/systemd.network.xml
src/network/networkd-network-gperf.gperf
src/network/networkd-route.c
src/network/networkd.h

diff --git a/TODO b/TODO
index 4bdf6c311551e96916842f8d02afb6f3ccf4cccf..877321f157ed664532077fad14c3bee102522c9a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -624,7 +624,6 @@ Features:
    - properly handle routerless dhcp leases
    - default to DHCP unicast, but make broadcast opt-in. detect devices that needs broadcast and opt-in automatically (needs kernel patch?)
    - add more attribute support for SIT tunnel
-   - make metric of routes configurable
    - work with non-ethernet devices
    - add support for more bond options
 
index c13085c05691dfc679374db5662918719e3594e5..738977ee8dfde98c7d6c6c8f2ac755429a8f0fe7 100644 (file)
                                                 prefixlength. If ommitted, a full-length host route is assumed.</para>
                                         </listitem>
                                 </varlistentry>
+                                <varlistentry>
+                                        <term><varname>Metric=</varname></term>
+                                        <listitem>
+                                                <para>The metric of the route. An unsigned integer</para>
+                                        </listitem>
+                                </varlistentry>
                         </variablelist>
         </refsect1>
 
index c821eadb705511204a71a0f140e39edf9b7e2a67..50cb0f8be9ec1e37fe32b47ce80c55161aaf8d1a 100644 (file)
@@ -43,7 +43,7 @@ Address.Peer,                config_parse_address,               0,
 Address.Broadcast,           config_parse_broadcast,             0,                             0
 Address.Label,               config_parse_label,                 0,                             0
 Route.Gateway,               config_parse_gateway,               0,                             0
-Route.Destination,           config_parse_destination,           0,                             0
+Route.Metric,                config_parse_route_priority,        0,                             0
 DHCP.UseDNS,                 config_parse_bool,                  0,                             offsetof(Network, dhcp_dns)
 DHCP.UseMTU,                 config_parse_bool,                  0,                             offsetof(Network, dhcp_mtu)
 DHCP.UseHostname,            config_parse_bool,                  0,                             offsetof(Network, dhcp_hostname)
index acfe3f023f1dfd2a15f1df406acb535158a28232..9e6295f8c828f0e1deb1c7e972272529053b9ca2 100644 (file)
@@ -360,3 +360,39 @@ int config_parse_destination(const char *unit,
 
         return 0;
 }
+
+int config_parse_route_priority(const char *unit,
+                                const char *filename,
+                                unsigned line,
+                                const char *section,
+                                unsigned section_line,
+                                const char *lvalue,
+                                int ltype,
+                                const char *rvalue,
+                                void *data,
+                                void *userdata) {
+        Network *network = userdata;
+        _cleanup_route_free_ Route *n = NULL;
+        _cleanup_free_ char *route = NULL;
+        int r;
+
+        assert(filename);
+        assert(section);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = route_new_static(network, section_line, &n);
+        if (r < 0)
+                return r;
+
+        r = config_parse_unsigned(unit, filename, line, section,
+                                  section_line, lvalue, ltype,
+                                  rvalue, &n->metrics, userdata);
+        if (r < 0)
+                return r;
+
+        n = NULL;
+
+        return 0;
+}
index 9132e70217f665d7d54af4c64513dea1c64a4c11..aca3b8dd24a7264b50742ed1d41387bea6cf0fb5 100644 (file)
@@ -467,6 +467,9 @@ int config_parse_destination(const char *unit, const char *filename, unsigned li
                              const char *section, unsigned section_line, const char *lvalue,
                              int ltype, const char *rvalue, void *data, void *userdata);
 
+int config_parse_route_priority(const char *unit, const char *filename, unsigned line,
+                                const char *section, unsigned section_line, const char *lvalue,
+                                int ltype, const char *rvalue, void *data, void *userdata);
 /* Address */
 int address_new_static(Network *network, unsigned section, Address **ret);
 int address_new_dynamic(Address **ret);