naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone
Blob Blame History Raw
From f2cb0f1570ca603c5d92d6a7d87596d07fdb01cd Mon Sep 17 00:00:00 2001
Message-Id: <f2cb0f1570ca603c5d92d6a7d87596d07fdb01cd.1612868485.git.aclaudi@redhat.com>
In-Reply-To: <cb7ce51cc1abd7b98370b903ec96205ebfe48661.1612868485.git.aclaudi@redhat.com>
References: <cb7ce51cc1abd7b98370b903ec96205ebfe48661.1612868485.git.aclaudi@redhat.com>
From: Andrea Claudi <aclaudi@redhat.com>
Date: Tue, 9 Feb 2021 12:00:58 +0100
Subject: [PATCH] iproute: force rtm_dst_len to 32/128
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1852038
Upstream Status: unknown commit 5a37254b

commit 5a37254b71249bfb73d44d6278d767a6b127a2f9
Author: Luca Boccassi <bluca@debian.org>
Date:   Sun Jan 24 17:36:58 2021 +0000

    iproute: force rtm_dst_len to 32/128

    Since NETLINK_GET_STRICT_CHK was enabled, the kernel rejects commands
    that pass a prefix length, eg:

     ip route get `1.0.0.0/1
      Error: ipv4: Invalid values in header for route get request.
     ip route get 0.0.0.0/0
      Error: ipv4: rtm_src_len and rtm_dst_len must be 32 for IPv4

    Since there's no point in setting a rtm_dst_len that we know is going
    to be rejected, just force it to the right value if it's passed on
    the command line. Print a warning to stderr to notify users.

    Bug-Debian: https://bugs.debian.org/944730
    Reported-By: Clément 'wxcafé' Hertling <wxcafe@wxcafe.net>
    Signed-off-by: Luca Boccassi <bluca@debian.org>
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 ip/iproute.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 05ec2c29..1f3c347e 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -2067,7 +2067,18 @@ static int iproute_get(int argc, char **argv)
 			if (addr.bytelen)
 				addattr_l(&req.n, sizeof(req),
 					  RTA_DST, &addr.data, addr.bytelen);
-			req.r.rtm_dst_len = addr.bitlen;
+			if (req.r.rtm_family == AF_INET && addr.bitlen != 32) {
+				fprintf(stderr,
+					"Warning: /%u as prefix is invalid, only /32 (or none) is supported.\n",
+					addr.bitlen);
+				req.r.rtm_dst_len = 32;
+			} else if (req.r.rtm_family == AF_INET6 && addr.bitlen != 128) {
+				fprintf(stderr,
+					"Warning: /%u as prefix is invalid, only /128 (or none) is supported.\n",
+					addr.bitlen);
+				req.r.rtm_dst_len = 128;
+			} else
+				req.r.rtm_dst_len = addr.bitlen;
 			address_found = true;
 		}
 		argc--; argv++;
-- 
2.29.2