linma / rpms / iproute

Forked from rpms/iproute 4 years ago
Clone

Blame SOURCES/0003-macsec-fix-byte-ordering-on-input-display-of-sci.patch

4aca6e
From 22f1d933f66b7e87734fcefd7b70fb0db3ebce16 Mon Sep 17 00:00:00 2001
4aca6e
From: Davide Caratti <dcaratti@redhat.com>
4aca6e
Date: Fri, 25 Nov 2016 10:43:10 +0100
4aca6e
Subject: [PATCH] macsec: fix byte ordering on input/display of 'sci'
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1355629
4aca6e
Upstream Status: iproute2.git commit 0330f49ea06e
4aca6e
4aca6e
Conflicts:
4aca6e
- ntohll() and htonll() have been added manually because of missing
4aca6e
upstream commit 1e5293056a02.
4aca6e
- get_be64() has been aded manually _ it was left behind while
4aca6e
backporting upstream commit 9f7401fa4967, because of the missing
4aca6e
implementation of htonll()/ntohll().
4aca6e
4aca6e
commit 0330f49ea06eed134b51a6924faf64ec6b1bb3ed
4aca6e
Author: Davide Caratti <dcaratti@redhat.com>
4aca6e
Date:   Tue Aug 30 13:23:14 2016 +0200
4aca6e
4aca6e
    macsec: fix byte ordering on input/display of 'sci'
4aca6e
4aca6e
    use get_be64() in place of get_u64() when parsing input 'sci' parameter,
4aca6e
    so that 'sci' can be entered using network byte order regardless the
4aca6e
    endianness of target system; use ntohll() when printing out 'sci'. While
4aca6e
    at it, improve documentation of 'sci' in ip-link.8.
4aca6e
4aca6e
    Signed-off-by: Davide Caratti <dcaratti@redhat.com>
4aca6e
4aca6e
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
4aca6e
---
4aca6e
 include/utils.h       |  4 ++++
4aca6e
 ip/ipmacsec.c         |  8 ++++----
4aca6e
 lib/utils.c           | 11 +++++++++++
4aca6e
 man/man8/ip-link.8.in |  4 +++-
4aca6e
 4 files changed, 22 insertions(+), 5 deletions(-)
4aca6e
4aca6e
diff --git a/include/utils.h b/include/utils.h
4aca6e
index fad82dc..2d1e390 100644
4aca6e
--- a/include/utils.h
4aca6e
+++ b/include/utils.h
4aca6e
@@ -98,6 +98,7 @@ extern int get_u16(__u16 *val, const char *arg, int base);
4aca6e
 extern int get_s16(__s16 *val, const char *arg, int base);
4aca6e
 extern int get_u8(__u8 *val, const char *arg, int base);
4aca6e
 extern int get_s8(__s8 *val, const char *arg, int base);
4aca6e
+int get_be64(__be64 *val, const char *arg, int base);
4aca6e
 int get_be32(__be32 *val, const char *arg, int base);
4aca6e
 int get_be16(__be16 *val, const char *arg, int base);
4aca6e
 
4aca6e
@@ -159,6 +160,9 @@ int print_timestamp(FILE *fp);
4aca6e
 
4aca6e
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
4aca6e
 
4aca6e
+#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
4aca6e
+#define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
4aca6e
+
4aca6e
 extern int cmdlineno;
4aca6e
 extern ssize_t getcmdline(char **line, size_t *len, FILE *in);
4aca6e
 extern int makeargs(char *line, char *argv[], int maxargs);
4aca6e
diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
4aca6e
index 21e53be..596594f 100644
4aca6e
--- a/ip/ipmacsec.c
4aca6e
+++ b/ip/ipmacsec.c
4aca6e
@@ -149,7 +149,7 @@ static int get_an(__u8 *val, const char *arg)
4aca6e
 
4aca6e
 static int get_sci(__u64 *sci, const char *arg)
4aca6e
 {
4aca6e
-	return get_u64(sci, arg, 16);
4aca6e
+	return get_be64(sci, arg, 16);
4aca6e
 }
4aca6e
 
4aca6e
 static int get_port(__be16 *port, const char *arg)
4aca6e
@@ -791,7 +791,7 @@ static void print_tx_sc(const char *prefix, __u64 sci, __u8 encoding_sa,
4aca6e
 	struct rtattr *a;
4aca6e
 	int rem;
4aca6e
 
4aca6e
-	printf("%sTXSC: %016llx on SA %d\n", prefix, sci, encoding_sa);
4aca6e
+	printf("%sTXSC: %016llx on SA %d\n", prefix, ntohll(sci), encoding_sa);
4aca6e
 	print_secy_stats(prefix, secy_stats);
4aca6e
 	print_txsc_stats(prefix, txsc_stats);
4aca6e
 
4aca6e
@@ -860,7 +860,7 @@ static void print_rx_sc(const char *prefix, __u64 sci, __u8 active,
4aca6e
 	struct rtattr *a;
4aca6e
 	int rem;
4aca6e
 
4aca6e
-	printf("%sRXSC: %016llx, state %s\n", prefix, sci,
4aca6e
+	printf("%sRXSC: %016llx, state %s\n", prefix, ntohll(sci),
4aca6e
 	       values_on_off[!!active]);
4aca6e
 	print_rxsc_stats(prefix, rxsc_stats);
4aca6e
 
4aca6e
@@ -1032,7 +1032,7 @@ static void macsec_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
4aca6e
 
4aca6e
 	if (tb[IFLA_MACSEC_SCI]) {
4aca6e
 		fprintf(f, "sci %016llx ",
4aca6e
-			rta_getattr_u64(tb[IFLA_MACSEC_SCI]));
4aca6e
+			ntohll(rta_getattr_u64(tb[IFLA_MACSEC_SCI])));
4aca6e
 	}
4aca6e
 
4aca6e
 	print_flag(f, tb, "protect", IFLA_MACSEC_PROTECT);
4aca6e
diff --git a/lib/utils.c b/lib/utils.c
4aca6e
index b310166..d3ed875 100644
4aca6e
--- a/lib/utils.c
4aca6e
+++ b/lib/utils.c
4aca6e
@@ -363,6 +363,17 @@ int get_s8(__s8 *val, const char *arg, int base)
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
+int get_be64(__be64 *val, const char *arg, int base)
4aca6e
+{
4aca6e
+	__u64 v;
4aca6e
+	int ret = get_u64(&v, arg, base);
4aca6e
+
4aca6e
+	if (!ret)
4aca6e
+		*val = htonll(v);
4aca6e
+
4aca6e
+	return ret;
4aca6e
+}
4aca6e
+
4aca6e
 int get_be32(__be32 *val, const char *arg, int base)
4aca6e
 {
4aca6e
 	__u32 v;
4aca6e
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
4aca6e
index fd665b8..73cd86d 100644
4aca6e
--- a/man/man8/ip-link.8.in
4aca6e
+++ b/man/man8/ip-link.8.in
4aca6e
@@ -819,7 +819,9 @@ interpreted as octal and hexadecimal, respectively.
4aca6e
 
4aca6e
 .sp
4aca6e
 .BI sci " SCI "
4aca6e
-- sets the SCI for this MACsec device.
4aca6e
+- sets the secure channel identifier for this MACsec device.
4aca6e
+.I SCI
4aca6e
+is a 64bit wide number in hexadecimal format.
4aca6e
 
4aca6e
 .sp
4aca6e
 .BI cipher " CIPHER_SUITE "
4aca6e
-- 
4aca6e
1.8.3.1
4aca6e