]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
macsec: add support for specifying offload at link add time
authorMark Starovoytov <mstarovoitov@marvell.com>
Fri, 24 Apr 2020 08:38:57 +0000 (11:38 +0300)
committerDavid Ahern <dsahern@gmail.com>
Sun, 26 Apr 2020 18:32:03 +0000 (18:32 +0000)
This patch adds support for configuring offload mode upon MACsec
device creation.

If offload mode is not specified, then netlink attribute is not
added. Default behavior on the kernel side in this case is
backward-compatible (offloading is disabled by default).

Example:
$ ip link add link eth0 macsec0 type macsec port 11 encrypt on offload mac

Signed-off-by: Mark Starovoytov <mstarovoitov@marvell.com>
Signed-off-by: Igor Russkikh <irusskikh@marvell.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/ipmacsec.c
man/man8/ip-macsec.8

index d214b101b83e91e474b56aa94f8f51af51111918..18289ecd6d9e0841b493e721c6acc192903cdb47 100644 (file)
@@ -1220,6 +1220,15 @@ static void macsec_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                             validate_to_str(val));
        }
 
+       if (tb[IFLA_MACSEC_OFFLOAD]) {
+               __u8 val = rta_getattr_u8(tb[IFLA_MACSEC_OFFLOAD]);
+
+               print_string(PRINT_ANY,
+                            "offload",
+                            "offload %s ",
+                            offload_to_str(val));
+       }
+
        const char *inc_sci, *es, *replay;
 
        if (is_json_context()) {
@@ -1268,6 +1277,7 @@ static void usage(FILE *f)
                "                  [ replay { on | off} window { 0..2^32-1 } ]\n"
                "                  [ validate { strict | check | disabled } ]\n"
                "                  [ encodingsa { 0..3 } ]\n"
+               "                  [ offload { mac | phy | off } ]\n"
                );
 }
 
@@ -1277,6 +1287,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
        int ret;
        __u8 encoding_sa = 0xff;
        __u32 window = -1;
+       enum macsec_offload offload;
        struct cipher_args cipher = {0};
        enum macsec_validation_type validate;
        bool es = false, scb = false, send_sci = false;
@@ -1398,6 +1409,15 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
                        ret = get_an(&encoding_sa, *argv);
                        if (ret)
                                invarg("expected an { 0..3 }", *argv);
+               } else if (strcmp(*argv, "offload") == 0) {
+                       NEXT_ARG();
+                       ret = one_of("offload", *argv,
+                                    offload_str, ARRAY_SIZE(offload_str),
+                                    (int *)&offload);
+                       if (ret != 0)
+                               return ret;
+                       addattr8(n, MACSEC_BUFLEN,
+                                IFLA_MACSEC_OFFLOAD, offload);
                } else {
                        fprintf(stderr, "macsec: unknown command \"%s\"?\n",
                                *argv);
index b2ee7bee0e2c73ecd3a3b98a3375ed20b9b2563c..8e9175c57eff021b89ce348f294ec1404244e0b8 100644 (file)
@@ -23,6 +23,8 @@ ip-macsec \- MACsec device configuration
 ] [
 .BR validate " { " strict " | " check " | " disabled " } ] ["
 .BI encodingsa " SA"
+] [
+.BR offload " { " off " | " phy " | " mac " }"
 ]
 
 .BI "ip macsec add " DEV " tx sa"
@@ -86,7 +88,7 @@ type.
 
 .SH EXAMPLES
 .PP
-.SS Create a MACsec device on link eth0
+.SS Create a MACsec device on link eth0 (offload is disabled by default)
 .nf
 # ip link add link eth0 macsec0 type macsec port 11 encrypt on
 .PP
@@ -109,6 +111,10 @@ type.
 .SS Configure offloading on an interface
 .nf
 # ip macsec offload macsec0 phy
+.PP
+.SS Configure offloading upon MACsec device creation
+.nf
+# ip link add link eth0 macsec0 type macsec port 11 encrypt on offload mac
 
 .SH NOTES
 This tool can be used to configure the 802.1AE keys of the interface. Note that 802.1AE uses GCM-AES