From 36423ff433de5d349791aee7586ebf000e74a49b Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Thu, 11 May 2017 10:12:54 +0530 Subject: [PATCH 1/2] networkd: route replace parse prefix with generic in_addr_prefix_from_string --- src/network/networkd-route.c | 41 ++++++------------------------------ 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index c5ee08a77a2..a1c60c49b11 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -772,45 +772,18 @@ int config_parse_destination(const char *unit, if (r < 0) return r; - /* Destination|Source=address/prefixlen */ - - /* address */ - e = strchr(rvalue, '/'); - if (e) - address = strndupa(rvalue, e - rvalue); - else - address = rvalue; - - r = in_addr_from_string_auto(address, &f, &buffer); + r = in_addr_prefix_from_string(rvalue, AF_INET, &buffer, &prefixlen); if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Destination is invalid, ignoring assignment: %s", address); - return 0; - } - - if (f != AF_INET && f != AF_INET6) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Unknown address family, ignoring assignment: %s", address); - return 0; - } - - /* prefixlen */ - if (e) { - r = safe_atou8(e + 1, &prefixlen); + r = in_addr_prefix_from_string(rvalue, AF_INET6, &buffer, &prefixlen); if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Route destination prefix length is invalid, ignoring assignment: %s", e + 1); + log_syntax(unit, LOG_ERR, filename, line, r, "Route source or destination prefix is invalid, ignoring assignment: %s", rvalue); return 0; } - } else { - switch (f) { - case AF_INET: - prefixlen = 32; - break; - case AF_INET6: - prefixlen = 128; - break; - } - } - n->family = f; + n->family = AF_INET6; + } else + n->family = AF_INET; + if (streq(lvalue, "Destination")) { n->dst = buffer; n->dst_prefixlen = prefixlen; From d84ed2bd132609d2ed6dd9c00a1d7cb2cf94409d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 11 May 2017 14:00:25 -0400 Subject: [PATCH 2/2] networkd: pretiffy message about invalid prefix We know how the field we are parsing is called, let's put this information in the error message: "Route Source= prefix is invalid, ignoring assignment: ..." "Route Destination= prefix is invalid, ignoring assignment: ..." --- src/network/networkd-route.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index a1c60c49b11..bbfcdb23949 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -776,7 +776,9 @@ int config_parse_destination(const char *unit, if (r < 0) { r = in_addr_prefix_from_string(rvalue, AF_INET6, &buffer, &prefixlen); if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Route source or destination prefix is invalid, ignoring assignment: %s", rvalue); + log_syntax(unit, LOG_ERR, filename, line, r, + "Route %s= prefix is invalid, ignoring assignment: %s", + lvalue, rvalue); return 0; }