From f2cb0f1570ca603c5d92d6a7d87596d07fdb01cd Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Andrea Claudi 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 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 Signed-off-by: Luca Boccassi Signed-off-by: Stephen Hemminger --- 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