naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0128-ip-tunnel-Use-tnl_parse_key-to-parse-tunnel-key.patch

36cfb7
From 8f2338a51859158b8699e0736f84ab1e42a3da97 Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Wed, 5 Jun 2019 13:05:04 +0200
36cfb7
Subject: [PATCH] ip/tunnel: Use tnl_parse_key() to parse tunnel key
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1714660
36cfb7
Upstream Status: iproute2.git commit 1f44b93744f11
36cfb7
Conflicts: context change due to missing commit 2a80154fde40b
36cfb7
           ("vti6: fix local/remote any addr handling")
36cfb7
36cfb7
commit 1f44b93744f11f2a8249e3c13751ab7debebaa5f
36cfb7
Author: Serhey Popovych <serhe.popovych@gmail.com>
36cfb7
Date:   Mon Dec 18 19:48:03 2017 +0200
36cfb7
36cfb7
    ip/tunnel: Use tnl_parse_key() to parse tunnel key
36cfb7
36cfb7
    It is added with
36cfb7
    commit a7ed1520ee96 ("ip/tunnel: introduce tnl_parse_key()")
36cfb7
    to avoid code duplication in ip6?tunnel.c.
36cfb7
36cfb7
    Reuse it for gre/gre6 and vti/vti6 tunnel rtnl
36cfb7
    configuration interface with the same purpose
36cfb7
    it is used in tunnel ioctl interface in ip6?tunnel.c.
36cfb7
36cfb7
    While there change type of key variables from
36cfb7
    unsigned integer to __be32 to reflect nature of the
36cfb7
    value they store and place error message in
36cfb7
    tnl_parse_key() on a single line to make single
36cfb7
    call to fprintf().
36cfb7
36cfb7
    Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
36cfb7
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
36cfb7
---
36cfb7
 ip/link_gre.c  | 45 +++++----------------------------------------
36cfb7
 ip/link_gre6.c | 45 +++++----------------------------------------
36cfb7
 ip/link_vti.c  | 45 +++++----------------------------------------
36cfb7
 ip/link_vti6.c | 45 +++++----------------------------------------
36cfb7
 ip/tunnel.c    |  5 +++--
36cfb7
 5 files changed, 23 insertions(+), 162 deletions(-)
36cfb7
36cfb7
diff --git a/ip/link_gre.c b/ip/link_gre.c
36cfb7
index ced993692e6f6..1376d2e3af7de 100644
36cfb7
--- a/ip/link_gre.c
36cfb7
+++ b/ip/link_gre.c
36cfb7
@@ -77,8 +77,8 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
36cfb7
 	struct rtattr *greinfo[IFLA_GRE_MAX + 1];
36cfb7
 	__u16 iflags = 0;
36cfb7
 	__u16 oflags = 0;
36cfb7
-	unsigned int ikey = 0;
36cfb7
-	unsigned int okey = 0;
36cfb7
+	__be32 ikey = 0;
36cfb7
+	__be32 okey = 0;
36cfb7
 	unsigned int saddr = 0;
36cfb7
 	unsigned int daddr = 0;
36cfb7
 	unsigned int link = 0;
36cfb7
@@ -167,53 +167,18 @@ get_failed:
36cfb7
 
36cfb7
 	while (argc > 0) {
36cfb7
 		if (!matches(*argv, "key")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
 			iflags |= GRE_KEY;
36cfb7
 			oflags |= GRE_KEY;
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr,
36cfb7
-						"Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-
36cfb7
-			ikey = okey = uval;
36cfb7
+			ikey = okey = tnl_parse_key("key", *argv);
36cfb7
 		} else if (!matches(*argv, "ikey")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
 			iflags |= GRE_KEY;
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-			ikey = uval;
36cfb7
+			ikey = tnl_parse_key("ikey", *argv);
36cfb7
 		} else if (!matches(*argv, "okey")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
 			oflags |= GRE_KEY;
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-			okey = uval;
36cfb7
+			okey = tnl_parse_key("okey", *argv);
36cfb7
 		} else if (!matches(*argv, "seq")) {
36cfb7
 			iflags |= GRE_SEQ;
36cfb7
 			oflags |= GRE_SEQ;
36cfb7
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
36cfb7
index a9d18ee954641..22e6e44aae29b 100644
36cfb7
--- a/ip/link_gre6.c
36cfb7
+++ b/ip/link_gre6.c
36cfb7
@@ -89,8 +89,8 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
36cfb7
 	struct rtattr *greinfo[IFLA_GRE_MAX + 1];
36cfb7
 	__u16 iflags = 0;
36cfb7
 	__u16 oflags = 0;
36cfb7
-	unsigned int ikey = 0;
36cfb7
-	unsigned int okey = 0;
36cfb7
+	__be32 ikey = 0;
36cfb7
+	__be32 okey = 0;
36cfb7
 	struct in6_addr raddr = IN6ADDR_ANY_INIT;
36cfb7
 	struct in6_addr laddr = IN6ADDR_ANY_INIT;
36cfb7
 	unsigned int link = 0;
36cfb7
@@ -181,53 +181,18 @@ get_failed:
36cfb7
 
36cfb7
 	while (argc > 0) {
36cfb7
 		if (!matches(*argv, "key")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
 			iflags |= GRE_KEY;
36cfb7
 			oflags |= GRE_KEY;
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr,
36cfb7
-						"Invalid value for \"key\"\n");
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-
36cfb7
-			ikey = okey = uval;
36cfb7
+			ikey = okey = tnl_parse_key("key", *argv);
36cfb7
 		} else if (!matches(*argv, "ikey")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
 			iflags |= GRE_KEY;
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr, "invalid value of \"ikey\"\n");
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-			ikey = uval;
36cfb7
+			ikey = tnl_parse_key("ikey", *argv);
36cfb7
 		} else if (!matches(*argv, "okey")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
 			oflags |= GRE_KEY;
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr, "invalid value of \"okey\"\n");
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-			okey = uval;
36cfb7
+			okey = tnl_parse_key("okey", *argv);
36cfb7
 		} else if (!matches(*argv, "seq")) {
36cfb7
 			iflags |= GRE_SEQ;
36cfb7
 			oflags |= GRE_SEQ;
36cfb7
diff --git a/ip/link_vti.c b/ip/link_vti.c
36cfb7
index d2aacbe78ded1..6e4234170bb50 100644
36cfb7
--- a/ip/link_vti.c
36cfb7
+++ b/ip/link_vti.c
36cfb7
@@ -62,8 +62,8 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
36cfb7
 	struct rtattr *tb[IFLA_MAX + 1];
36cfb7
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
36cfb7
 	struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
36cfb7
-	unsigned int ikey = 0;
36cfb7
-	unsigned int okey = 0;
36cfb7
+	__be32 ikey = 0;
36cfb7
+	__be32 okey = 0;
36cfb7
 	unsigned int saddr = 0;
36cfb7
 	unsigned int daddr = 0;
36cfb7
 	unsigned int link = 0;
36cfb7
@@ -116,49 +116,14 @@ get_failed:
36cfb7
 
36cfb7
 	while (argc > 0) {
36cfb7
 		if (!matches(*argv, "key")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr,
36cfb7
-						"Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-
36cfb7
-			ikey = okey = uval;
36cfb7
+			ikey = okey = tnl_parse_key("key", *argv);
36cfb7
 		} else if (!matches(*argv, "ikey")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-			ikey = uval;
36cfb7
+			ikey = tnl_parse_key("ikey", *argv);
36cfb7
 		} else if (!matches(*argv, "okey")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-			okey = uval;
36cfb7
+			okey = tnl_parse_key("okey", *argv);
36cfb7
 		} else if (!matches(*argv, "remote")) {
36cfb7
 			NEXT_ARG();
36cfb7
 			if (!strcmp(*argv, "any")) {
36cfb7
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
36cfb7
index aedfbeaeea0e1..e246cedbcb7a7 100644
36cfb7
--- a/ip/link_vti6.c
36cfb7
+++ b/ip/link_vti6.c
36cfb7
@@ -59,8 +59,8 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
36cfb7
 	struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
36cfb7
 	struct in6_addr saddr;
36cfb7
 	struct in6_addr daddr;
36cfb7
-	unsigned int ikey = 0;
36cfb7
-	unsigned int okey = 0;
36cfb7
+	__be32 ikey = 0;
36cfb7
+	__be32 okey = 0;
36cfb7
 	unsigned int link = 0;
36cfb7
 	int len;
36cfb7
 
36cfb7
@@ -111,49 +111,14 @@ get_failed:
36cfb7
 
36cfb7
 	while (argc > 0) {
36cfb7
 		if (!matches(*argv, "key")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr,
36cfb7
-						"Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-
36cfb7
-			ikey = okey = uval;
36cfb7
+			ikey = okey = tnl_parse_key("key", *argv);
36cfb7
 		} else if (!matches(*argv, "ikey")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-			ikey = uval;
36cfb7
+			ikey = tnl_parse_key("ikey", *argv);
36cfb7
 		} else if (!matches(*argv, "okey")) {
36cfb7
-			unsigned int uval;
36cfb7
-
36cfb7
 			NEXT_ARG();
36cfb7
-			if (strchr(*argv, '.'))
36cfb7
-				uval = get_addr32(*argv);
36cfb7
-			else {
36cfb7
-				if (get_unsigned(&uval, *argv, 0) < 0) {
36cfb7
-					fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
36cfb7
-					exit(-1);
36cfb7
-				}
36cfb7
-				uval = htonl(uval);
36cfb7
-			}
36cfb7
-			okey = uval;
36cfb7
+			okey = tnl_parse_key("okey", *argv);
36cfb7
 		} else if (!matches(*argv, "remote")) {
36cfb7
 			NEXT_ARG();
36cfb7
 			if (!strcmp(*argv, "any")) {
36cfb7
diff --git a/ip/tunnel.c b/ip/tunnel.c
36cfb7
index 7956d71aa7334..3967d5df3ca1c 100644
36cfb7
--- a/ip/tunnel.c
36cfb7
+++ b/ip/tunnel.c
36cfb7
@@ -189,8 +189,9 @@ __be32 tnl_parse_key(const char *name, const char *key)
36cfb7
 		return get_addr32(key);
36cfb7
 
36cfb7
 	if (get_unsigned(&uval, key, 0) < 0) {
36cfb7
-		fprintf(stderr, "invalid value for \"%s\": \"%s\";", name, key);
36cfb7
-		fprintf(stderr, " it should be an unsigned integer\n");
36cfb7
+		fprintf(stderr,
36cfb7
+			"invalid value for \"%s\": \"%s\"; it should be an unsigned integer\n",
36cfb7
+			name, key);
36cfb7
 		exit(-1);
36cfb7
 	}
36cfb7
 	return htonl(uval);
36cfb7
-- 
e138d9
2.21.0
36cfb7