developer | 7e32f7e | 2022-05-18 21:10:08 +0800 | [diff] [blame^] | 1 | From 791bb3fcafcedd11f9066da9fee9342ecb6904d0 Mon Sep 17 00:00:00 2001 |
| 2 | From: Mark Starovoytov <mstarovoitov@marvell.com> |
| 3 | Date: Wed, 25 Mar 2020 16:01:34 +0300 |
| 4 | Subject: net: macsec: add support for specifying offload upon link creation |
| 5 | |
| 6 | This patch adds new netlink attribute to allow a user to (optionally) |
| 7 | specify the desired offload mode immediately upon MACSec link creation. |
| 8 | |
| 9 | Separate iproute patch will be required to support this from user space. |
| 10 | |
| 11 | Signed-off-by: Mark Starovoytov <mstarovoitov@marvell.com> |
| 12 | Signed-off-by: Igor Russkikh <irusskikh@marvell.com> |
| 13 | Signed-off-by: David S. Miller <davem@davemloft.net> |
| 14 | --- |
| 15 | drivers/net/macsec.c | 31 +++++++++++++++++++++++++++++-- |
| 16 | include/uapi/linux/if_link.h | 1 + |
| 17 | tools/include/uapi/linux/if_link.h | 1 + |
| 18 | 3 files changed, 31 insertions(+), 2 deletions(-) |
| 19 | |
| 20 | diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c |
| 21 | index 2dad91cba459c..da82d7f16a09d 100644 |
| 22 | --- a/drivers/net/macsec.c |
| 23 | +++ b/drivers/net/macsec.c |
| 24 | @@ -1469,6 +1469,11 @@ static struct net_device *get_dev_from_nl(struct net *net, |
| 25 | return dev; |
| 26 | } |
| 27 | |
| 28 | +static enum macsec_offload nla_get_offload(const struct nlattr *nla) |
| 29 | +{ |
| 30 | + return (__force enum macsec_offload)nla_get_u8(nla); |
| 31 | +} |
| 32 | + |
| 33 | static sci_t nla_get_sci(const struct nlattr *nla) |
| 34 | { |
| 35 | return (__force sci_t)nla_get_u64(nla); |
| 36 | @@ -4012,8 +4017,16 @@ static int macsec_newlink(struct net *net, struct net_device *dev, |
| 37 | |
| 38 | macsec->real_dev = real_dev; |
| 39 | |
| 40 | - /* MACsec offloading is off by default */ |
| 41 | - macsec->offload = MACSEC_OFFLOAD_OFF; |
| 42 | + if (data && data[IFLA_MACSEC_OFFLOAD]) |
| 43 | + macsec->offload = nla_get_offload(data[IFLA_MACSEC_OFFLOAD]); |
| 44 | + else |
| 45 | + /* MACsec offloading is off by default */ |
| 46 | + macsec->offload = MACSEC_OFFLOAD_OFF; |
| 47 | + |
| 48 | + /* Check if the offloading mode is supported by the underlying layers */ |
| 49 | + if (macsec->offload != MACSEC_OFFLOAD_OFF && |
| 50 | + !macsec_check_offload(macsec->offload, macsec)) |
| 51 | + return -EOPNOTSUPP; |
| 52 | |
| 53 | if (data && data[IFLA_MACSEC_ICV_LEN]) |
| 54 | icv_len = nla_get_u8(data[IFLA_MACSEC_ICV_LEN]); |
| 55 | @@ -4056,6 +4069,20 @@ static int macsec_newlink(struct net *net, struct net_device *dev, |
| 56 | goto del_dev; |
| 57 | } |
| 58 | |
| 59 | + /* If h/w offloading is available, propagate to the device */ |
| 60 | + if (macsec_is_offloaded(macsec)) { |
| 61 | + const struct macsec_ops *ops; |
| 62 | + struct macsec_context ctx; |
| 63 | + |
| 64 | + ops = macsec_get_ops(macsec, &ctx); |
| 65 | + if (ops) { |
| 66 | + ctx.secy = &macsec->secy; |
| 67 | + err = macsec_offload(ops->mdo_add_secy, &ctx); |
| 68 | + if (err) |
| 69 | + goto del_dev; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | err = register_macsec_dev(real_dev, dev); |
| 74 | if (err < 0) |
| 75 | goto del_dev; |
| 76 | diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h |
| 77 | index d6ccd0105c050..e204c3e4dce10 100644 |
| 78 | --- a/include/uapi/linux/if_link.h |
| 79 | +++ b/include/uapi/linux/if_link.h |
| 80 | @@ -463,6 +463,7 @@ enum { |
| 81 | IFLA_MACSEC_REPLAY_PROTECT, |
| 82 | IFLA_MACSEC_VALIDATION, |
| 83 | IFLA_MACSEC_PAD, |
| 84 | + IFLA_MACSEC_OFFLOAD, |
| 85 | __IFLA_MACSEC_MAX, |
| 86 | }; |
| 87 | |
| 88 | diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h |
| 89 | index 771371d5b9960..24cf6fe075f74 100644 |
| 90 | --- a/tools/include/uapi/linux/if_link.h |
| 91 | +++ b/tools/include/uapi/linux/if_link.h |
| 92 | @@ -463,6 +463,7 @@ enum { |
| 93 | IFLA_MACSEC_REPLAY_PROTECT, |
| 94 | IFLA_MACSEC_VALIDATION, |
| 95 | IFLA_MACSEC_PAD, |
| 96 | + IFLA_MACSEC_OFFLOAD, |
| 97 | __IFLA_MACSEC_MAX, |
| 98 | }; |
| 99 | |
| 100 | -- |
| 101 | cgit 1.2.3-1.el7 |
| 102 | |