From: Luca Boccassi Date: Thu, 14 Feb 2019 23:29:18 +0000 (+0000) Subject: ip route: get: allow zero-length subnet mask X-Git-Tag: v5.0.0~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2f9dc14c41f388764f7634d36c3d05e354f053a;p=thirdparty%2Fiproute2.git ip route: get: allow zero-length subnet mask A /0 subnet mask is theoretically valid, but ip route get doesn't allow it: $ ip route get 1.0.0.0/0 need at least a destination address Change the check and remember whether we found an address or not, since according to the documentation it's a mandatory parameter. $ ip/ip route get 1.0.0.0/0 1.0.0.0 via 192.168.1.1 dev eth0 src 192.168.1.91 uid 1000 cache Reported-by: Clément Hertling Signed-off-by: Luca Boccassi Signed-off-by: Stephen Hemminger --- diff --git a/ip/iproute.c b/ip/iproute.c index 5f58a3b34..cc02a3e1b 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -1932,6 +1932,7 @@ static int iproute_get(int argc, char **argv) int fib_match = 0; int from_ok = 0; unsigned int mark = 0; + bool address_found = false; iproute_reset_filter(0); filter.cloned = 2; @@ -2037,11 +2038,12 @@ static int iproute_get(int argc, char **argv) addattr_l(&req.n, sizeof(req), RTA_DST, &addr.data, addr.bytelen); req.r.rtm_dst_len = addr.bitlen; + address_found = true; } argc--; argv++; } - if (req.r.rtm_dst_len == 0) { + if (!address_found) { fprintf(stderr, "need at least a destination address\n"); return -1; }