naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0238-macsec-cipher-and-icvlen-can-be-set-separately.patch

049c96
From b669a186dc9a68efb82595d991726bb5e3cb51b6 Mon Sep 17 00:00:00 2001
049c96
From: Davide Caratti <dcaratti@redhat.com>
049c96
Date: Wed, 3 Aug 2016 17:22:11 +0200
049c96
Subject: [PATCH] macsec: cipher and icvlen can be set separately
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1354408
049c96
Upstream Status: iproute2.git commit 89bb6e673a6a
049c96
049c96
commit 89bb6e673a6ae9dd9b6845ed95358dd6653c167e
049c96
Author: Davide Caratti <dcaratti@redhat.com>
049c96
Date:   Tue Jul 26 11:03:20 2016 +0200
049c96
049c96
    macsec: cipher and icvlen can be set separately
049c96
049c96
    since kernel driver has valid default values for 'cipher' and 'icvlen',
049c96
    there is no need for requiring users to specify both of them when a new
049c96
    link is added. Also, prompt an error message and exit with appropriate
049c96
    exit status in case of unsupported cipher suite.
049c96
049c96
    Signed-off-by: Davide Caratti <dcaratti@redhat.com>
049c96
049c96
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
049c96
---
049c96
 ip/ipmacsec.c         | 52 +++++++++++++++++----------------------------------
049c96
 man/man8/ip-link.8.in |  6 ++++++
049c96
 man/man8/ip-macsec.8  |  4 ++--
049c96
 3 files changed, 25 insertions(+), 37 deletions(-)
049c96
049c96
diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
049c96
index 34ba341..329be00 100644
049c96
--- a/ip/ipmacsec.c
049c96
+++ b/ip/ipmacsec.c
049c96
@@ -1071,34 +1071,6 @@ static void macsec_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
049c96
 	}
049c96
 }
049c96
 
049c96
-
049c96
-static int do_cipher_suite(struct cipher_args *cipher, int *argcp,
049c96
-			   char ***argvp)
049c96
-{
049c96
-	char **argv = *argvp;
049c96
-	int argc = *argcp;
049c96
-
049c96
-	if (argc == 0)
049c96
-		return -1;
049c96
-
049c96
-	if (strcmp(*argv, "default") == 0 ||
049c96
-	    strcmp(*argv, "gcm-aes-128") == 0 ||
049c96
-	    strcmp(*argv, "GCM-AES-128") == 0)
049c96
-		cipher->id = MACSEC_DEFAULT_CIPHER_ID;
049c96
-	NEXT_ARG();
049c96
-
049c96
-	if (strcmp(*argv, "icvlen") == 0) {
049c96
-		NEXT_ARG();
049c96
-		if (cipher->icv_len != 0)
049c96
-			duparg2("icvlen", "icvlen");
049c96
-		get_icvlen(&cipher->icv_len, *argv);
049c96
-	}
049c96
-	*argcp = argc;
049c96
-	*argvp = argv;
049c96
-
049c96
-	return 0;
049c96
-}
049c96
-
049c96
 static bool check_txsc_flags(bool es, bool scb, bool sci)
049c96
 {
049c96
 	if (sci && (es || scb))
049c96
@@ -1112,7 +1084,8 @@ static void usage(FILE *f)
049c96
 {
049c96
 	fprintf(f,
049c96
 		"Usage: ... macsec [ port PORT | sci SCI ]\n"
049c96
-		"                  [ cipher CIPHER_SUITE ]\n"
049c96
+		"                  [ cipher { default | gcm-aes-128 } ]\n"
049c96
+		"                  [ icvlen { 8..16 } ]\n"
049c96
 		"                  [ encrypt { on | off } ]\n"
049c96
 		"                  [ send_sci { on | off } ]\n"
049c96
 		"                  [ end_station { on | off } ]\n"
049c96
@@ -1122,7 +1095,6 @@ static void usage(FILE *f)
049c96
 		"                  [ validate { strict | check | disabled } ]\n"
049c96
 		"                  [ encodingsa { 0..3 } ]\n"
049c96
 		);
049c96
-	fprintf(f, "CIPHER_SUITE := [ default = gcm-aes-128 ] icvlen { 8..32 }\n");
049c96
 }
049c96
 
049c96
 static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
@@ -1154,11 +1126,21 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
 
049c96
 	while (argc > 0) {
049c96
 		if (strcmp(*argv, "cipher") == 0) {
049c96
+			NEXT_ARG();
049c96
 			if (cipher.id)
049c96
-				duparg2("cipher", "cipher");
049c96
+				duparg("cipher", *argv);
049c96
+			if (strcmp(*argv, "default") == 0 ||
049c96
+			    strcmp(*argv, "gcm-aes-128") == 0 ||
049c96
+			    strcmp(*argv, "GCM-AES-128") == 0)
049c96
+				cipher.id = MACSEC_DEFAULT_CIPHER_ID;
049c96
+			else
049c96
+				invarg("expected: default or gcm-aes-128",
049c96
+				       *argv);
049c96
+		} else if (strcmp(*argv, "icvlen") == 0) {
049c96
 			NEXT_ARG();
049c96
-			if (do_cipher_suite(&cipher, &argc, &argv))
049c96
-				return -1;
049c96
+			if (cipher.icv_len)
049c96
+				duparg("icvlen", *argv);
049c96
+			get_icvlen(&cipher.icv_len, *argv);
049c96
 		} else if (strcmp(*argv, "encrypt") == 0) {
049c96
 			NEXT_ARG();
049c96
 			int i;
049c96
@@ -1264,12 +1246,12 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
 		return -1;
049c96
 	}
049c96
 
049c96
-	if (cipher.id) {
049c96
+	if (cipher.id)
049c96
 		addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_CIPHER_SUITE,
049c96
 			  &cipher.id, sizeof(cipher.id));
049c96
+	if (cipher.icv_len)
049c96
 		addattr_l(hdr, MACSEC_BUFLEN, IFLA_MACSEC_ICV_LEN,
049c96
 			  &cipher.icv_len, sizeof(cipher.icv_len));
049c96
-	}
049c96
 
049c96
 	if (replay_protect != -1) {
049c96
 		addattr32(hdr, MACSEC_BUFLEN, IFLA_MACSEC_WINDOW, window);
049c96
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
049c96
index 2633521..18c7040 100644
049c96
--- a/man/man8/ip-link.8.in
049c96
+++ b/man/man8/ip-link.8.in
049c96
@@ -753,6 +753,8 @@ the following additional arguments are supported:
049c96
 ] [
049c96
 .BI cipher " CIPHER_SUITE"
049c96
 ] [
049c96
+.BR icvlen " { "
049c96
+.IR 8..16 " } ] ["
049c96
 .BR encrypt " {"
049c96
 .BR on " | " off " } ] [ "
049c96
 .BR send_sci " { " on " | " off " } ] ["
049c96
@@ -780,6 +782,10 @@ the following additional arguments are supported:
049c96
 - defines the cipher suite to use.
049c96
 
049c96
 .sp
049c96
+.BI icvlen " LENGTH "
049c96
+- sets the length of the Integrity Check Value (ICV).
049c96
+
049c96
+.sp
049c96
 .BR "encrypt on " or " encrypt off"
049c96
 - switches between authenticated encryption, or authenticity mode only.
049c96
 
049c96
diff --git a/man/man8/ip-macsec.8 b/man/man8/ip-macsec.8
049c96
index f928c43..105aeec 100644
049c96
--- a/man/man8/ip-macsec.8
049c96
+++ b/man/man8/ip-macsec.8
049c96
@@ -7,8 +7,8 @@ ip-macsec \- MACsec device configuration
049c96
 .BI port " PORT"
049c96
 |
049c96
 .BI sci  " SCI"
049c96
-] [ [
049c96
-.BR cipher " { " default " | " gcm-aes-128 " } ] "
049c96
+] [
049c96
+.BR cipher " { " default " | " gcm-aes-128 " } ] ["
049c96
 .BI icvlen " ICVLEN"
049c96
 ] [
049c96
 .BR encrypt " { " on " | " off " } ] ["
049c96
-- 
049c96
1.8.3.1
049c96