naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0174-utils-add-get_be-16-32-64-use-them-where-possible.patch

049c96
From 25b35417c2ea49d31289177a81cb988369e138db Mon Sep 17 00:00:00 2001
049c96
From: Davide Caratti <dcaratti@redhat.com>
049c96
Date: Wed, 6 Jul 2016 18:41:34 +0200
049c96
Subject: [PATCH] utils: add get_be{16, 32, 64}, use them where possible
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1300765
049c96
Upstream Status: iproute2.git commit 9f7401fa4967
049c96
049c96
Conflicts:
049c96
- context conflicts due to missing code cleanups (lack of upstream commit
049c96
892e21248cfd and 56f5daac98da)
049c96
- hunks not merged:
049c96
get_be64() implementation in utils.{c,h} due to missing support for
049c96
lwtunnel (lack of upstream commit 1e5293056a02 implementing htonll())
049c96
ip/ipfou.c due to missing support for foo-over-udp (lack of upstream commit
049c96
6928747b6e79)
049c96
tc/f_flower.c due to missing support for Flower classifier (lack of upstream
049c96
commit 30eb304ecd1d)
049c96
ip/iproute_lwtunnel.c due to missing support for lwtunnel (lack of upstream
049c96
commit 1e5293056a02)
049c96
049c96
commit 9f7401fa4967178a071c53498f6bdc460c7cc4ea
049c96
Author: Sabrina Dubroca <sd@queasysnail.net>
049c96
Date:   Fri Jun 3 16:45:46 2016 +0200
049c96
049c96
    utils: add get_be{16, 32, 64}, use them where possible
049c96
049c96
    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
049c96
    Acked-by: Phil Sutter <phil@nwl.cc>
049c96
049c96
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
049c96
---
049c96
 include/utils.h   |  2 ++
049c96
 ip/iplink_vxlan.c |  7 ++-----
049c96
 ip/ipxfrm.c       | 13 +++----------
049c96
 ip/xfrm_state.c   | 10 +++-------
049c96
 lib/ll_proto.c    |  3 +--
049c96
 lib/utils.c       | 22 ++++++++++++++++++++++
049c96
 tc/f_u32.c        |  8 ++------
049c96
 7 files changed, 35 insertions(+), 30 deletions(-)
049c96
049c96
diff --git a/include/utils.h b/include/utils.h
049c96
index 86af63b..4fd48b6 100644
049c96
--- a/include/utils.h
049c96
+++ b/include/utils.h
049c96
@@ -97,6 +97,8 @@ extern int get_u16(__u16 *val, const char *arg, int base);
049c96
 extern int get_s16(__s16 *val, const char *arg, int base);
049c96
 extern int get_u8(__u8 *val, const char *arg, int base);
049c96
 extern int get_s8(__s8 *val, const char *arg, int base);
049c96
+int get_be32(__be32 *val, const char *arg, int base);
049c96
+int get_be16(__be16 *val, const char *arg, int base);
049c96
 
049c96
 char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen);
049c96
 __u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len);
049c96
diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c
049c96
index a4cf924..2ca97a4 100644
049c96
--- a/ip/iplink_vxlan.c
049c96
+++ b/ip/iplink_vxlan.c
049c96
@@ -153,15 +153,12 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
 				invarg("max addresses", *argv);
049c96
 		} else if (!matches(*argv, "port") ||
049c96
 			   !matches(*argv, "srcport")) {
049c96
-			__u16 minport, maxport;
049c96
 			NEXT_ARG();
049c96
-			if (get_u16(&minport, *argv, 0))
049c96
+			if (get_be16(&range.low, *argv, 0))
049c96
 				invarg("min port", *argv);
049c96
 			NEXT_ARG();
049c96
-			if (get_u16(&maxport, *argv, 0))
049c96
+			if (get_be16(&range.high, *argv, 0))
049c96
 				invarg("max port", *argv);
049c96
-			range.low = htons(minport);
049c96
-			range.high = htons(maxport);
049c96
 		} else if (!matches(*argv, "dstport")){
049c96
 			NEXT_ARG();
049c96
 			if (get_u16(&dstport, *argv, 0))
049c96
diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
049c96
index feff09a..0344355 100644
049c96
--- a/ip/ipxfrm.c
049c96
+++ b/ip/ipxfrm.c
049c96
@@ -1057,15 +1057,10 @@ int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
049c96
 			filter.id_proto_mask = XFRM_FILTER_MASK_FULL;
049c96
 
049c96
 		} else if (strcmp(*argv, "spi") == 0) {
049c96
-			__u32 spi;
049c96
-
049c96
 			NEXT_ARG();
049c96
-			if (get_u32(&spi, *argv, 0))
049c96
+			if (get_be32(&id->spi, *argv, 0))
049c96
 				invarg("SPI value is invalid", *argv);
049c96
 
049c96
-			spi = htonl(spi);
049c96
-			id->spi = spi;
049c96
-
049c96
 			filter.id_spi_mask = XFRM_FILTER_MASK_FULL;
049c96
 
049c96
 		} else {
049c96
@@ -1199,9 +1194,8 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
049c96
 
049c96
 			NEXT_ARG();
049c96
 
049c96
-			if (get_u16(&sel->sport, *argv, 0))
049c96
+			if (get_be16(&sel->sport, *argv, 0))
049c96
 				invarg("value after \"sport\" is invalid", *argv);
049c96
-			sel->sport = htons(sel->sport);
049c96
 			if (sel->sport)
049c96
 				sel->sport_mask = ~((__u16)0);
049c96
 
049c96
@@ -1212,9 +1206,8 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
049c96
 
049c96
 			NEXT_ARG();
049c96
 
049c96
-			if (get_u16(&sel->dport, *argv, 0))
049c96
+			if (get_be16(&sel->dport, *argv, 0))
049c96
 				invarg("value after \"dport\" is invalid", *argv);
049c96
-			sel->dport = htons(sel->dport);
049c96
 			if (sel->dport)
049c96
 				sel->dport_mask = ~((__u16)0);
049c96
 
049c96
diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c
049c96
index 20d7a7e..4dfddbc 100644
049c96
--- a/ip/xfrm_state.c
049c96
+++ b/ip/xfrm_state.c
049c96
@@ -176,11 +176,9 @@ static int xfrm_seq_parse(__u32 *seq, int *argcp, char ***argvp)
049c96
 	int argc = *argcp;
049c96
 	char **argv = *argvp;
049c96
 
049c96
-	if (get_u32(seq, *argv, 0))
049c96
+	if (get_be32(seq, *argv, 0))
049c96
 		invarg("SEQ value is invalid", *argv);
049c96
 
049c96
-	*seq = htonl(*seq);
049c96
-
049c96
 	*argcp = argc;
049c96
 	*argvp = argv;
049c96
 
049c96
@@ -346,13 +344,11 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv)
049c96
 		        NEXT_ARG();
049c96
 			xfrm_encap_type_parse(&encap.encap_type, &argc, &argv);
049c96
 			NEXT_ARG();
049c96
-			if (get_u16(&encap.encap_sport, *argv, 0))
049c96
+			if (get_be16(&encap.encap_sport, *argv, 0))
049c96
 				invarg("SPORT value after \"encap\" is invalid", *argv);
049c96
-			encap.encap_sport = htons(encap.encap_sport);
049c96
 			NEXT_ARG();
049c96
-			if (get_u16(&encap.encap_dport, *argv, 0))
049c96
+			if (get_be16(&encap.encap_dport, *argv, 0))
049c96
 				invarg("DPORT value after \"encap\" is invalid", *argv);
049c96
-			encap.encap_dport = htons(encap.encap_dport);
049c96
 			NEXT_ARG();
049c96
 			get_addr(&oa, *argv, AF_UNSPEC);
049c96
 			memcpy(&encap.encap_oa, &oa.data, sizeof(encap.encap_oa));
049c96
diff --git a/lib/ll_proto.c b/lib/ll_proto.c
049c96
index d8df68c..e094d9f 100644
049c96
--- a/lib/ll_proto.c
049c96
+++ b/lib/ll_proto.c
049c96
@@ -111,8 +111,7 @@ int ll_proto_a2n(unsigned short *id, const char *buf)
049c96
 			 return 0;
049c96
 		 }
049c96
 	}
049c96
-	if (get_u16(id, buf, 0))
049c96
+	if (get_be16(id, buf, 0))
049c96
 		return -1;
049c96
-	*id = htons(*id);
049c96
 	return 0;
049c96
 }
049c96
diff --git a/lib/utils.c b/lib/utils.c
049c96
index 5337084..687c188 100644
049c96
--- a/lib/utils.c
049c96
+++ b/lib/utils.c
049c96
@@ -351,6 +351,28 @@ int get_s8(__s8 *val, const char *arg, int base)
049c96
 	return 0;
049c96
 }
049c96
 
049c96
+int get_be32(__be32 *val, const char *arg, int base)
049c96
+{
049c96
+	__u32 v;
049c96
+	int ret = get_u32(&v, arg, base);
049c96
+
049c96
+	if (!ret)
049c96
+		*val = htonl(v);
049c96
+
049c96
+	return ret;
049c96
+}
049c96
+
049c96
+int get_be16(__be16 *val, const char *arg, int base)
049c96
+{
049c96
+	__u16 v;
049c96
+	int ret = get_u16(&v, arg, base);
049c96
+
049c96
+	if (!ret)
049c96
+		*val = htons(v);
049c96
+
049c96
+	return ret;
049c96
+}
049c96
+
049c96
 /* This uses a non-standard parsing (ie not inet_aton, or inet_pton)
049c96
  * because of legacy choice to parse 10.8 as 10.8.0.0 not 10.0.0.8
049c96
  */
049c96
diff --git a/tc/f_u32.c b/tc/f_u32.c
049c96
index 8bc9a17..134925e 100644
049c96
--- a/tc/f_u32.c
049c96
+++ b/tc/f_u32.c
049c96
@@ -765,11 +765,9 @@ static int parse_offset(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
049c96
 			}
049c96
 			sel->flags |= TC_U32_VAROFFSET;
049c96
 		} else if (matches(*argv, "mask") == 0) {
049c96
-			__u16 mask;
049c96
 			NEXT_ARG();
049c96
-			if (get_u16(&mask, *argv, 16))
049c96
+			if (get_be16(&sel->offmask, *argv, 16))
049c96
 				return -1;
049c96
-			sel->offmask = htons(mask);
049c96
 			sel->flags |= TC_U32_VAROFFSET;
049c96
 		} else if (matches(*argv, "shift") == 0) {
049c96
 			int shift;
049c96
@@ -798,11 +796,9 @@ static int parse_hashkey(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
049c96
 
049c96
 	while (argc > 0) {
049c96
 		if (matches(*argv, "mask") == 0) {
049c96
-			__u32 mask;
049c96
 			NEXT_ARG();
049c96
-			if (get_u32(&mask, *argv, 16))
049c96
+			if (get_be32(&sel->hmask, *argv, 16))
049c96
 				return -1;
049c96
-			sel->hmask = htonl(mask);
049c96
 		} else if (matches(*argv, "at") == 0) {
049c96
 			int num;
049c96
 			NEXT_ARG();
049c96
-- 
049c96
1.8.3.1
049c96