From 5d8e593dce074bff966fc0a46579c61b4f3bc33a Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Thu, 10 Jul 2014 23:09:58 +0530 Subject: [PATCH] networkd: make metric of routes configurable 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 | 1 - man/systemd.network.xml | 6 ++++++ src/network/networkd-network-gperf.gperf | 2 +- src/network/networkd-route.c | 36 ++++++++++++++++++++++++++++++++ src/network/networkd.h | 3 +++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 4bdf6c3..877321f 100644 --- 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 diff --git a/man/systemd.network.xml b/man/systemd.network.xml index c13085c..738977e 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -389,6 +389,12 @@ prefixlength. If ommitted, a full-length host route is assumed. + + Metric= + + The metric of the route. An unsigned integer + + diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index c821ead..50cb0f8 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -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) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index acfe3f0..9e6295f 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -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; +} diff --git a/src/network/networkd.h b/src/network/networkd.h index 9132e70..aca3b8d 100644 --- a/src/network/networkd.h +++ b/src/network/networkd.h @@ -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); -- 2.7.4