naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

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

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