Skip to contentSkip to conversation

ip route: get: allow zero-length subnet mask

RFC Superseded Luca Boccassi 2 participants 4 messages Feb 13, 2019 – Feb 19, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 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

Remove the check so that it can go through:

$ 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

---
Stephen et al, this was reported by a Debian user:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921737

It makes sense to me at a cursory glance, but sending as RFC as I'm not 100% familiar with the route get function.

 ip/iproute.c | 5 -----
 1 file changed, 5 deletions(-)
ip/iproute.c +0 -5
index 5f58a3b3..d78f43d8 100644
@@ -2041,11 +2041,6 @@ static int iproute_get(int argc, char **argv)
 		argc--; argv++;
 	}
 
-	if (req.r.rtm_dst_len == 0) {
-		fprintf(stderr, "need at least a destination address\n");
-		return -1;
-	}
-
 	if (idev || odev)  {
 		int idx;
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 31 lines · On Wed, 13 Feb 2019 20:09:53 +0000 Luca Boccassi <[email protected]> wrote:

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

Remove the check so that it can go through:

$ 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

---
Stephen et al, this was reported by a Debian user:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921737

It makes sense to me at a cursory glance, but sending as RFC as I'm not 100% familiar with the route get function.

 ip/iproute.c | 5 -----
 1 file changed, 5 deletions(-)
ip/iproute.c +0 -0
index 5f58a3b3..d78f43d8 100644
@@ -2041,11 +2041,6 @@ static int iproute_get(int argc, char **argv)
 		argc--; argv++;

ip/iproute.c static int iproute_get(int argc, char **argv) · line 2046

Quoted 10 lines
ip/iproute.c +0 -5
 	}
 
-	if (req.r.rtm_dst_len == 0) {
-		fprintf(stderr, "need at least a destination address\n");
-		return -1;
-	}
-
 	if (idev || odev)  {
 		int idx;
 

You still need a way to report error for:
ip route get
(i.e when no address is present)

#2 lore raw

RFC v2 1/1 ip route: get: allow zero-length subnet mask

In reply to Luca Boccassi

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

---
v2: changed the check instead of removing it, so that "ip route get" fails since the address is a mandatory parameter according to the manpage.

 ip/iproute.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ip/iproute.c +3 -1
index 5f58a3b3..cc02a3e1 100644
@@ -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;
 	}
Signature · 1 line
2.20.1
#3 lore raw
Quoted 9 lines · On Thu, 14 Feb 2019 23:29:18 +0000 Luca Boccassi <[email protected]> wrote:

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.

Quoted 7 lines
$ 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

---

Applied