naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0002-Really-fix-get_addr-and-get_prefix-error-messages.patch

36cfb7
From aed8229c0bec5c56deaf1ea2047ca0263732477f Mon Sep 17 00:00:00 2001
36cfb7
From: Phil Sutter <psutter@redhat.com>
36cfb7
Date: Fri, 11 Aug 2017 11:11:32 +0200
36cfb7
Subject: [PATCH] Really fix get_addr() and get_prefix() error messages
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1477206
36cfb7
Upstream Status: iproute2.git commit 34705c807a389
36cfb7
36cfb7
commit 34705c807a38909247d1bb29ccdffe42e5c1dab3
36cfb7
Author: Phil Sutter <phil@nwl.cc>
36cfb7
Date:   Tue Aug 1 18:36:11 2017 +0200
36cfb7
36cfb7
    Really fix get_addr() and get_prefix() error messages
36cfb7
36cfb7
    Both functions take the desired address family as a parameter. So using
36cfb7
    that to notify the user what address family was expected is correct,
36cfb7
    unlike using dst->family which will tell the user only what address
36cfb7
    family was specified.
36cfb7
36cfb7
    The situation which commit 334af76143368 tried to fix was when 'ip'
36cfb7
    would accept addresses from multiple families. In that case, the family
36cfb7
    parameter is set to AF_UNSPEC so that get_addr_1() may accept any valid
36cfb7
    address.
36cfb7
36cfb7
    This patch introduces a wrapper around family_name() which returns the
36cfb7
    string "any valid" for AF_UNSPEC instead of the three question marks
36cfb7
    unsuitable for use in error messages.
36cfb7
36cfb7
    Tests for AF_UNSPEC:
36cfb7
36cfb7
    | # ip a a 256.10.166.1/24 dev d0
36cfb7
    | Error: any valid prefix is expected rather than "256.10.166.1/24".
36cfb7
36cfb7
    | # ip neighbor add proxy 2001:db8::g dev d0
36cfb7
    | Error: any valid address is expected rather than "2001:db8::g".
36cfb7
36cfb7
    Tests for explicit address family:
36cfb7
36cfb7
    | # ip -6 addrlabel add prefix 1.1.1.1/24 label 123
36cfb7
    | Error: inet6 prefix is expected rather than "1.1.1.1/24".
36cfb7
36cfb7
    | # ip -4 addrlabel add prefix dead:beef::1/24 label 123
36cfb7
    | Error: inet prefix is expected rather than "dead:beef::1/24".
36cfb7
36cfb7
    Reported-by: Jaroslav Aster <jaster@redhat.com>
36cfb7
    Fixes: 334af76143368 ("fix get_addr() and get_prefix() error messages")
36cfb7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
36cfb7
---
36cfb7
 lib/utils.c | 11 +++++++++--
36cfb7
 1 file changed, 9 insertions(+), 2 deletions(-)
36cfb7
36cfb7
diff --git a/lib/utils.c b/lib/utils.c
e138d9
index 6d5642f4f1f3f..7d6ee53ad938d 100644
36cfb7
--- a/lib/utils.c
36cfb7
+++ b/lib/utils.c
36cfb7
@@ -613,12 +613,19 @@ done:
36cfb7
 	return err;
36cfb7
 }
36cfb7
 
36cfb7
+static const char *family_name_verbose(int family)
36cfb7
+{
36cfb7
+	if (family == AF_UNSPEC)
36cfb7
+		return "any valid";
36cfb7
+	return family_name(family);
36cfb7
+}
36cfb7
+
36cfb7
 int get_addr(inet_prefix *dst, const char *arg, int family)
36cfb7
 {
36cfb7
 	if (get_addr_1(dst, arg, family)) {
36cfb7
 		fprintf(stderr,
36cfb7
 			"Error: %s address is expected rather than \"%s\".\n",
36cfb7
-			family_name(dst->family), arg);
36cfb7
+			family_name_verbose(family), arg);
36cfb7
 		exit(1);
36cfb7
 	}
36cfb7
 	return 0;
36cfb7
@@ -636,7 +643,7 @@ int get_prefix(inet_prefix *dst, char *arg, int family)
36cfb7
 	if (get_prefix_1(dst, arg, family)) {
36cfb7
 		fprintf(stderr,
36cfb7
 			"Error: %s prefix is expected rather than \"%s\".\n",
36cfb7
-			family_name(dst->family), arg);
36cfb7
+			family_name_verbose(family), arg);
36cfb7
 		exit(1);
36cfb7
 	}
36cfb7
 	return 0;
36cfb7
-- 
e138d9
2.21.0
36cfb7