From c167e0140babcf1a045cee34ce4938f5087f8fe6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 3 Aug 2019 08:15:50 +0200 Subject: all: allow configuring default-routes as manual, static routes Up until now, a default-route (with prefix length zero) could not be configured directly. The user could only set ipv4.gateway, ipv4.never-default, ipv4.route-metric and ipv4.route-table to influence the setting of the default-route (respectively for IPv6). That is a problematic limitation. For one, whether a route has prefix length zero or non-zero does not make a fundamental difference. Also, it makes it impossible to configure all the routing attributes that one can configure otherwise for static routes. For example, the default-route could not be configured as "onlink", could not have a special MTU, nor could it be placed in a dedicated routing table. Fix that by lifting the restriction. Note that "ipv4.never-default" does not apply to /0 manual routes. Likewise, the previous manners of configuring default-routes ("ipv4.gateway") don't conflict with manual default-routes. Server-side this all the pieces are already in place to accept a default-route as static routes. This was done by earlier commits like 5c299454b49b ('core: rework tracking of gateway/default-route in ip-config'). A long time ago, NMIPRoute would assert that the prefix length is positive. That was relaxed by commit a2e93f2de4ac ('libnm: allow zero prefix length for NMIPRoute'), already before 1.0.0. Using libnm from before 1.0.0 would result in assertion failures. Note that the default-route-metric-penalty based on connectivity checking applies to all /0 routes, even these static routes. Be they added due to DHCP, "ipv4.gateway", "ipv4.routes" or "wireguard.peer-routes". I wonder whether doing that unconditionally is desirable, and maybe there should be a way to opt-out/opt-in for the entire profile or even per-routes. https://bugzilla.redhat.com/show_bug.cgi?id=1714438 --- libnm-core/nm-keyfile.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'libnm-core/nm-keyfile.c') diff --git a/libnm-core/nm-keyfile.c b/libnm-core/nm-keyfile.c index b0c7a13478..9b032c4cd8 100644 --- a/libnm-core/nm-keyfile.c +++ b/libnm-core/nm-keyfile.c @@ -248,15 +248,16 @@ static gpointer build_route (KeyfileReaderInfo *info, const char *property_name, int family, - const char *dest_str, guint32 plen, - const char *gateway_str, const char *metric_str) + const char *dest_str, + guint32 plen, + const char *gateway_str, + const char *metric_str) { NMIPRoute *route; guint32 u32; gint64 metric = -1; GError *error = NULL; - g_return_val_if_fail (plen, NULL); g_return_val_if_fail (dest_str, NULL); /* Next hop */ @@ -294,7 +295,10 @@ build_route (KeyfileReaderInfo *info, metric = u32; } - route = nm_ip_route_new (family, dest_str, plen, gateway_str, + route = nm_ip_route_new (family, + dest_str, + plen, + gateway_str, metric, &error); if (!route) { @@ -517,8 +521,7 @@ read_one_ip_address_or_route (KeyfileReaderInfo *info, /* parse plen, fallback to defaults */ if (plen_str) { - if ( !get_one_int (info, property_name, plen_str, ipv6 ? 128 : 32, &plen) - || (route && plen == 0)) { + if (!get_one_int (info, property_name, plen_str, ipv6 ? 128 : 32, &plen)) { plen = DEFAULT_PREFIX (route, ipv6); if ( info->error || !handle_warn (info, property_name, NM_KEYFILE_WARN_SEVERITY_WARN, @@ -536,12 +539,19 @@ read_one_ip_address_or_route (KeyfileReaderInfo *info, /* build the appropriate data structure for NetworkManager settings */ if (route) { - result = build_route (info, property_name, + result = build_route (info, + property_name, ipv6 ? AF_INET6 : AF_INET, - address_str, plen, gateway_str, metric_str); + address_str, + plen, + gateway_str, + metric_str); } else { - result = build_address (info, ipv6 ? AF_INET6 : AF_INET, - address_str, plen, property_name); + result = build_address (info, + ipv6 ? AF_INET6 : AF_INET, + address_str, + plen, + property_name); if (!result) return NULL; if (gateway_str) -- cgit v1.2.1