From 1312172fbfc57d523fba953a3c04cccc9b21f53f Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 23 Feb 2016 13:27:50 +0100 Subject: [PATCH] networkd: route - support 'onlink' routes By setting GatewayOnlink=yes, the kernel will assume that the gateway is onlink even if there is no route to it. Resolves issue #1283. --- man/systemd.network.xml | 8 +++++ src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-route.c | 41 ++++++++++++++++++++++++ src/network/networkd-route.h | 1 + 4 files changed, 51 insertions(+) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index c6bbb958337..94f732e5283 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -648,6 +648,14 @@ As in the [Network] section. + + GatewayOnlink= + + Explicitly consider the gateway to be onlink, even if there + is no route to it. A boolean, defaults to + no. + + Destination= diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 7a9a136d5b3..4def6b8d493 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -64,6 +64,7 @@ Address.Peer, config_parse_address, Address.Broadcast, config_parse_broadcast, 0, 0 Address.Label, config_parse_label, 0, 0 Route.Gateway, config_parse_gateway, 0, 0 +Route.GatewayOnlink, config_parse_gateway_onlink, 0, 0 Route.Destination, config_parse_destination, 0, 0 Route.Source, config_parse_destination, 0, 0 Route.Metric, config_parse_route_priority, 0, 0 diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index e065a5a5a9e..001452370f9 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -581,6 +581,47 @@ int config_parse_gateway(const char *unit, return 0; } +int config_parse_gateway_onlink(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; + bool onlink; + 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_bool(unit, filename, line, section, + section_line, lvalue, ltype, + rvalue, &onlink, userdata); + if (r < 0) + return r; + + if (onlink) + n->flags |= RTNH_F_ONLINK; + else + n->flags &= ~RTNH_F_ONLINK; + + n = NULL; + + return 0; +} + int config_parse_preferred_src(const char *unit, const char *filename, unsigned line, diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index a4a4bf26537..0341a909235 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -70,6 +70,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free); #define _cleanup_route_free_ _cleanup_(route_freep) int config_parse_gateway(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); +int config_parse_gateway_onlink(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); int config_parse_preferred_src(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); int config_parse_destination(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); 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); -- 2.47.3