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

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