History

net: macsec: add support for specifying offload upon link creation

This patch adds new netlink attribute to allow a user to (optionally) specify the desired offload mode immediately upon MACSec link creation. Separate iproute patch will be required to support this from user space.

Mark Starovoytov committed 6 years ago

Commit 791bb3f1 parent f0b59893 files · +31 −2Browse files

Unified · Split

3 files
  1. drivers/net/macsec.c +29 −2
  2. include/uapi/linux/if_link.h +1 −0
  3. tools/include/uapi/linux/if_link.h +1 −0
drivers/net/macsec.c+29−2
@@ -1469,6 +1469,11 @@ static struct net_device *get_dev_from_nl(struct net *net, · 1468 unmodified lines
14691469 return dev;
14701470 }
14711471
1472+static enum macsec_offload nla_get_offload(const struct nlattr *nla)
1473+{
1474+ return (__force enum macsec_offload)nla_get_u8(nla);
1475+}
1476+
14721477 static sci_t nla_get_sci(const struct nlattr *nla)
14731478 {
14741479 return (__force sci_t)nla_get_u64(nla);
@@ -4012,8 +4017,16 @@ static int macsec_newlink(struct net *net, struct net_device *dev, · 2537 unmodified lines
40124017
40134018 macsec->real_dev = real_dev;
40144019
4015− /* MACsec offloading is off by default */
4016− macsec->offload = MACSEC_OFFLOAD_OFF;
4020+ if (data && data[IFLA_MACSEC_OFFLOAD])
4021+ macsec->offload = nla_get_offload(data[IFLA_MACSEC_OFFLOAD]);
4022+ else
4023+ /* MACsec offloading is off by default */
4024+ macsec->offload = MACSEC_OFFLOAD_OFF;
4025+
4026+ /* Check if the offloading mode is supported by the underlying layers */
4027+ if (macsec->offload != MACSEC_OFFLOAD_OFF &&
4028+ !macsec_check_offload(macsec->offload, macsec))
4029+ return -EOPNOTSUPP;
40174030
40184031 if (data && data[IFLA_MACSEC_ICV_LEN])
40194032 icv_len = nla_get_u8(data[IFLA_MACSEC_ICV_LEN]);
@@ -4056,6 +4069,20 @@ static int macsec_newlink(struct net *net, struct net_device *dev, · 36 unmodified lines
40564069 goto del_dev;
40574070 }
40584071
4072+ /* If h/w offloading is available, propagate to the device */
4073+ if (macsec_is_offloaded(macsec)) {
4074+ const struct macsec_ops *ops;
4075+ struct macsec_context ctx;
4076+
4077+ ops = macsec_get_ops(macsec, &ctx);
4078+ if (ops) {
4079+ ctx.secy = &macsec->secy;
4080+ err = macsec_offload(ops->mdo_add_secy, &ctx);
4081+ if (err)
4082+ goto del_dev;
4083+ }
4084+ }
4085+
40594086 err = register_macsec_dev(real_dev, dev);
40604087 if (err < 0)
40614088 goto del_dev;
include/uapi/linux/if_link.h+1−0
@@ -463,6 +463,7 @@ enum { · 462 unmodified lines
463463 IFLA_MACSEC_REPLAY_PROTECT,
464464 IFLA_MACSEC_VALIDATION,
465465 IFLA_MACSEC_PAD,
466+ IFLA_MACSEC_OFFLOAD,
466467 __IFLA_MACSEC_MAX,
467468 };
468469
tools/include/uapi/linux/if_link.h+1−0
@@ -463,6 +463,7 @@ enum { · 462 unmodified lines
463463 IFLA_MACSEC_REPLAY_PROTECT,
464464 IFLA_MACSEC_VALIDATION,
465465 IFLA_MACSEC_PAD,
466+ IFLA_MACSEC_OFFLOAD,
466467 __IFLA_MACSEC_MAX,
467468 };
468469