Skip to contentSkip to conversation

macsec: add extended packet number (XPN) support

PATCH Superseded Emeel Hakim 2 participants 5 messages Aug 24, 2022 – Sep 1, 2022

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 macsec: add extended packet number (XPN) support

This patch adds support for extended packet number (XPN). XPN can be configured by passing 'xpn on' as part of the ip link add command using macsec type.
In addition, using 'xpn' keyword instead of the 'pn', passing a 12 bytes salt using the 'salt' keyword and passing short secure channel id (ssci) using the 'ssci' keyword as part of the ip macsec command is required (see example).

e.g:

create a MACsec device on link eth0 with enabled xpn

  # ip link add link eth0 macsec0 type macsec port 11
	encrypt on xpn on

configure a secure association on the device

  # ip macsec add macsec0 tx sa 0 xpn 1024 on ssci 5
	salt 838383838383838383838383
	key 01 81818181818181818181818181818181

configure a secure association on the device with ssci = 5

  # ip macsec add macsec0 tx sa 0 xpn 1024 on ssci 5
	salt 838383838383838383838383
	key 01 82828282828282828282828282828282

---
V1->V2:
- Updated commit message.
- Related uapi change got accepted upstream. "https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=5d8175783585"
- Allowed ssci to be empty to leave it up to the kernel to reject invalid requests.
- Removed the flag option and exchanged it by a property for xpn.
- Added the 64b xpn, ssci as part of the dump.

 include/uapi/linux/if_macsec.h |   2 +
 ip/ipmacsec.c                  | 125 +++++++++++++++++++++++++++------
 2 files changed, 107 insertions(+), 20 deletions(-)
include/uapi/linux/if_macsec.h +2 -0
index eee31cec..6edfea0a 100644
@@ -22,6 +22,8 @@
 
 #define MACSEC_KEYID_LEN 16
 
+#define MACSEC_SALT_LEN 12
+
 /* cipher IDs as per IEEE802.1AE-2018 (Table 14-1) */
 #define MACSEC_CIPHER_ID_GCM_AES_128 0x0080C20001000001ULL
 #define MACSEC_CIPHER_ID_GCM_AES_256 0x0080C20001000002ULL
ip/ipmacsec.c +105 -20

259 lines not on this page · raw message

Signature · 1 line
2.21.3
#1 lore raw

PATCH v2 2/2 macsec: add user manual description for extended packet number feature

Update the user manual describing how to use extended packet number (XPN) feature for macsec. As part of configuring XPN, providing ssci and salt is required hence update user manual on how to provide the above as part of the ip macsec command.

---
V1->V2:
- Updated documentation.

 man/man8/ip-macsec.8 | 52 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
man/man8/ip-macsec.8 +51 -1
index bb816157..991a775a 100644
@@ -19,6 +19,7 @@ ip-macsec \- MACsec device configuration
 .BR scb " { " on " | " off " } ] ["
 .BR protect " { " on " | " off " } ] ["
 .BR replay " { " on " | " off " } ] ["
+.BR xpn " { " on " | " off " } ] ["
 .BI window " WINDOW"
 ] [
 .BR validate " { " strict " | " check " | " disabled " } ] ["
@@ -63,7 +64,13 @@ ip-macsec \- MACsec device configuration
 
 .IR OPTS " := [ "
 .BR pn " { "
-.IR 1..2^32-1 " } ] ["
+.IR 1..2^32-1 " } |"
+.BR xpn " { "
+.IR 1..2^64-1 " } ] ["
+.B salt
+.IR SALT " ] ["
+.B ssci
+.IR <u32> " ] ["
 .BR on " | " off " ]"
 .br
 .IR SCI " := { "
@@ -75,6 +82,8 @@ ip-macsec \- MACsec device configuration
 }
 .br
 .IR PORT " := { " 1..2^16-1 " } "
+.br
+.IR SALT " := 96-bit hex string "
 
 
 .SH DESCRIPTION
@@ -116,6 +125,29 @@ type.
 .nf
 # ip link add link eth0 macsec0 type macsec port 11 encrypt on offload mac
 
+.SH EXTENDED PACKET NUMBER EXAMPLES
+.PP
+.SS Create a MACsec device on link eth0 with enabled extended packet number (offload is disabled by default)
+.nf
+# ip link add link eth0 macsec0 type macsec port 11 encrypt on xpn on
+.PP
+.SS Configure a secure association on that device
+.nf
+# ip macsec add macsec0 tx sa 0 xpn 1024 on salt 838383838383838383838383 ssci 123 key 01 81818181818181818181818181818181
+.PP
+.SS Configure a receive channel
+.nf
+# ip macsec add macsec0 rx port 11 address c6:19:52:8f:e6:a0
+.PP
+.SS Configure a receive association
+.nf
+# ip macsec add macsec0 rx port 11 address c6:19:52:8f:e6:a0 sa 0 xpn 1 on salt 838383838383838383838383 ssci 123 key 00 82828282828282828282828282828282
+.PP
+.SS Display MACsec configuration
+.nf
+# ip macsec show
+.PP
+
 .SH NOTES
 This tool can be used to configure the 802.1AE keys of the interface. Note that 802.1AE uses GCM-AES
 with a initialization vector (IV) derived from the packet number. The same key must not be used
@@ -125,6 +157,24 @@ that reconfigures the keys. It is wrong to just configure the keys statically an
 indefinitely. The suggested and standardized way for key management is 802.1X-2010, which is implemented
 by wpa_supplicant.
 
+.SH EXTENDED PACKET NUMBER NOTES
+Passing flag
+.B xpn
+to
+.B ip link add
+command using the
+.I macsec
+type requires using the keyword
+.B 'xpn'
+instead of
+.B 'pn'
+in addition to providing a salt using the
+.B 'salt'
+keyword when using the
+.B ip macsec
+command.
+
+
 .SH SEE ALSO
 .br
 .BR ip-link (8)
Signature · 1 line
2.21.3
#2 lore raw
In reply to Emeel Hakim

ip/ipmacsec.c static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa) · line 184

Quoted 6 lines · Emeel Hakim
ip/ipmacsec.c +1 -1
@@ -174,14 +181,34 @@ static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa)
 
 	while (argc > 0) {
 		if (strcmp(*argv, "pn") == 0) {
-			if (sa->pn != 0)
+			if (sa->pn.pn32 != 0)

pn64 to cover the entire range? ie., pn and xpn on the same command line.

Quoted 19 lines
ip/ipmacsec.c +12 -2
 				duparg2("pn", "pn");
 			NEXT_ARG();
-			ret = get_u32(&sa->pn, *argv, 0);
+			ret = get_u32(&sa->pn.pn32, *argv, 0);
 			if (ret)
 				invarg("expected pn", *argv);
-			if (sa->pn == 0)
+			if (sa->pn.pn32 == 0)
 				invarg("expected pn != 0", *argv);
+		} else if (strcmp(*argv, "xpn") == 0) {
+			if (sa->pn.pn64 != 0)
+				duparg2("xpn", "xpn");
+			NEXT_ARG();
+			ret = get_u64(&sa->pn.pn64, *argv, 0);
+			if (ret)
+				invarg("expected pn", *argv);
+			if (sa->pn.pn64 == 0)
+				invarg("expected pn != 0", *argv);
+			sa->xpn = true;

ip/ipmacsec.c static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa) · line 211

Quoted 10 lines
ip/ipmacsec.c +10 -0
+		} else if (strcmp(*argv, "salt") == 0) {
+			unsigned int len;
+
+			NEXT_ARG();
+			if (!hexstring_a2n(*argv, sa->salt, MACSEC_SALT_LEN,
+					   &len))
+				invarg("expected salt", *argv);
+		} else if (strcmp(*argv, "ssci") == 0) {
+			NEXT_ARG();
+			ret = get_u32(&sa->ssci, *argv, 0);

that can fail, so check ret and throw an error message

Quoted 3 lines
ip/ipmacsec.c +0 -0
 		} else if (strcmp(*argv, "key") == 0) {
 			unsigned int len;
 

...

ip/ipmacsec.c static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, · line 1465

Quoted 9 lines
ip/ipmacsec.c +5 -0
@@ -1388,6 +1458,14 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
 				return ret;
 			addattr8(n, MACSEC_BUFLEN,
 				 IFLA_MACSEC_OFFLOAD, offload);
+		} else if (strcmp(*argv, "xpn") == 0) {
+			NEXT_ARG();
+			int i;
+
+			i = parse_on_off("xpn", *argv, &ret);

drop the 'i' and just
xpn = parse_on_off("xpn", *argv, &ret);

besides you have i as an int when xpn is bool and parse_on_off returns a bool.

#3 lore raw
Quoted 15 lines

-----Original Message-----
From: David Ahern <[email protected]>
Sent: Thursday, 1 September 2022 5:53
To: Emeel Hakim <[email protected]>; [email protected]
Cc: Tariq Toukan <[email protected]>; Raed Salem <[email protected]>; [email protected]
Subject: Re: [PATCH main v2 1/2] macsec: add extended packet number (XPN) support

Quoted 3 lines · Emeel Hakim
(quoted diff) +0 -0
@@ -174,14 +181,34 @@ static int parse_sa_args(int *argcp, char
 ***argvp, struct sa_desc *sa)
 
Quoted 6 lines

ip/ipmacsec.c static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa) · line 184

Quoted 4 lines
ip/ipmacsec.c +1 -1
      while (argc > 0) {
              if (strcmp(*argv, "pn") == 0) {
-                     if (sa->pn != 0)
+                     if (sa->pn.pn32 != 0)

pn64 to cover the entire range? ie., pn and xpn on the same command line.

Didn’t really get the comment if to have "pn" as the only parameter in the command line or just to save all the packet numbers in a 64-bit variable and preserve the current API , can you please elaborate?
please notice that kernel has a check for the pn length , it expects 32 bits in case of none extended packet number (xpn), hence passing 64-bit in case of none xpn will fail. Xpn is a secure channel property where pn is an SA property so during the parsing of the SA command line (which includes the pn) I don’t have a legit way to distinguish between xpn or none xpn cases hence the separation.

Quoted 31 lines
Quoted 20 lines
ip/ipmacsec.c +12 -2
                              duparg2("pn", "pn");
                      NEXT_ARG();
-                     ret = get_u32(&sa->pn, *argv, 0);
+                     ret = get_u32(&sa->pn.pn32, *argv, 0);
                      if (ret)
                              invarg("expected pn", *argv);
-                     if (sa->pn == 0)
+                     if (sa->pn.pn32 == 0)
                              invarg("expected pn != 0", *argv);
+             } else if (strcmp(*argv, "xpn") == 0) {
+                     if (sa->pn.pn64 != 0)
+                             duparg2("xpn", "xpn");
+                     NEXT_ARG();
+                     ret = get_u64(&sa->pn.pn64, *argv, 0);
+                     if (ret)
+                             invarg("expected pn", *argv);
+                     if (sa->pn.pn64 == 0)
+                             invarg("expected pn != 0", *argv);
+                     sa->xpn = true;

ip/ipmacsec.c static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa) · line 211

Quoted 10 lines
ip/ipmacsec.c +10 -0
+             } else if (strcmp(*argv, "salt") == 0) {
+                     unsigned int len;
+
+                     NEXT_ARG();
+                     if (!hexstring_a2n(*argv, sa->salt, MACSEC_SALT_LEN,
+                                        &len))
+                             invarg("expected salt", *argv);
+             } else if (strcmp(*argv, "ssci") == 0) {
+                     NEXT_ARG();
+                     ret = get_u32(&sa->ssci, *argv, 0);
Quoted 1 line

that can fail, so check ret and throw an error message

Ack

Quoted 19 lines
Quoted 4 lines
ip/ipmacsec.c +0 -0
              } else if (strcmp(*argv, "key") == 0) {
                      unsigned int len;

...

Review static int macsec_parse_opt(struct link_util *lu, int

Quoted 1 line
(quoted diff) +0 -0
@@ -1388,6 +1458,14 @@ static int macsec_parse_opt(struct link_util *lu, int

argc, char **argv,

ip/ipmacsec.c static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, · line 1465

Quoted 8 lines
ip/ipmacsec.c +5 -0
                              return ret;
                      addattr8(n, MACSEC_BUFLEN,
                               IFLA_MACSEC_OFFLOAD, offload);
+             } else if (strcmp(*argv, "xpn") == 0) {
+                     NEXT_ARG();
+                     int i;
+
+                     i = parse_on_off("xpn", *argv, &ret);
Quoted 4 lines

drop the 'i' and just
xpn = parse_on_off("xpn", *argv, &ret);

besides you have i as an int when xpn is bool and parse_on_off returns a bool.

Ack

#4 lore raw
Quoted 22 lines · Emeel Hakim
Quoted 15 lines

-----Original Message-----
From: David Ahern <[email protected]>
Sent: Thursday, 1 September 2022 5:53
To: Emeel Hakim <[email protected]>; [email protected]
Cc: Tariq Toukan <[email protected]>; Raed Salem <[email protected]>; [email protected]
Subject: Re: [PATCH main v2 1/2] macsec: add extended packet number (XPN) support

Quoted 3 lines · Emeel Hakim
(quoted diff) +0 -0
@@ -174,14 +181,34 @@ static int parse_sa_args(int *argcp, char
 ***argvp, struct sa_desc *sa)
 
Quoted 6 lines

ip/ipmacsec.c static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa) · line 184

Quoted 4 lines
ip/ipmacsec.c +1 -1
      while (argc > 0) {
              if (strcmp(*argv, "pn") == 0) {
-                     if (sa->pn != 0)
+                     if (sa->pn.pn32 != 0)

pn64 to cover the entire range? ie., pn and xpn on the same command line.

Quoted 2 lines

Didn’t really get the comment if to have "pn" as the only parameter in the command line or just to save all the packet numbers in a 64-bit variable and preserve the current API , can you please elaborate?
please notice that kernel has a check for the pn length , it expects 32 bits in case of none extended packet number (xpn), hence passing 64-bit in case of none xpn will fail. Xpn is a secure channel property where pn is an SA property so during the parsing of the SA command line (which includes the pn) I don’t have a legit way to distinguish between xpn or none xpn cases hence the separation.

you are checking for duplicate pn argument. My comment is that if you check sa->pn.pn64 you can check for a duplicate xpn and pn where a command line has an xpn argument with the upper 32bits set folllowed by a pn argument.

Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
ip/ipmacsec.c +0 -0
                              duparg2("pn", "pn");
                      NEXT_ARG();

ip/ipmacsec.c static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa) · line 194

Quoted 10 lines
ip/ipmacsec.c +5 -2
-                     ret = get_u32(&sa->pn, *argv, 0);
+                     ret = get_u32(&sa->pn.pn32, *argv, 0);
                      if (ret)
                              invarg("expected pn", *argv);
-                     if (sa->pn == 0)
+                     if (sa->pn.pn32 == 0)
                              invarg("expected pn != 0", *argv);
+             } else if (strcmp(*argv, "xpn") == 0) {
+                     if (sa->pn.pn64 != 0)
+                             duparg2("xpn", "xpn");

this check right here but above for the "pn" case.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
ip/ipmacsec.c +14 -0
+                     NEXT_ARG();
+                     ret = get_u64(&sa->pn.pn64, *argv, 0);
+                     if (ret)
+                             invarg("expected pn", *argv);
+                     if (sa->pn.pn64 == 0)
+                             invarg("expected pn != 0", *argv);
+                     sa->xpn = true;
+             } else if (strcmp(*argv, "salt") == 0) {
+                     unsigned int len;
+
+                     NEXT_ARG();
+                     if (!hexstring_a2n(*argv, sa->salt, MACSEC_SALT_LEN,
+                                        &len))
+                             invarg("expected salt", *argv);