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
1469 return dev;1469 return dev;
1470}1470}
1471 1471
1472static enum macsec_offload nla_get_offload(const struct nlattr *nla)
1473{
1474 return (__force enum macsec_offload)nla_get_u8(nla);
1475}
1476
1472static sci_t nla_get_sci(const struct nlattr *nla)1477static sci_t nla_get_sci(const struct nlattr *nla)
1473{1478{
1474 return (__force sci_t)nla_get_u64(nla);1479 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
4012 4017
4013 macsec->real_dev = real_dev;4018 macsec->real_dev = real_dev;
4014 4019
4015 /* MACsec offloading is off by default */4020 if (data && data[IFLA_MACSEC_OFFLOAD])
4016 macsec->offload = MACSEC_OFFLOAD_OFF;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;
4017 4030
4018 if (data && data[IFLA_MACSEC_ICV_LEN])4031 if (data && data[IFLA_MACSEC_ICV_LEN])
4019 icv_len = nla_get_u8(data[IFLA_MACSEC_ICV_LEN]);4032 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
4056 goto del_dev;4069 goto del_dev;
4057 }4070 }
4058 4071
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
4059 err = register_macsec_dev(real_dev, dev);4086 err = register_macsec_dev(real_dev, dev);
4060 if (err < 0)4087 if (err < 0)
4061 goto del_dev;4088 goto del_dev;
include/uapi/linux/if_link.h+1−0
@@ -463,6 +463,7 @@ enum { · 462 unmodified lines
463 IFLA_MACSEC_REPLAY_PROTECT,463 IFLA_MACSEC_REPLAY_PROTECT,
464 IFLA_MACSEC_VALIDATION,464 IFLA_MACSEC_VALIDATION,
465 IFLA_MACSEC_PAD,465 IFLA_MACSEC_PAD,
466 IFLA_MACSEC_OFFLOAD,
466 __IFLA_MACSEC_MAX,467 __IFLA_MACSEC_MAX,
467};468};
468 469
tools/include/uapi/linux/if_link.h+1−0
@@ -463,6 +463,7 @@ enum { · 462 unmodified lines
463 IFLA_MACSEC_REPLAY_PROTECT,463 IFLA_MACSEC_REPLAY_PROTECT,
464 IFLA_MACSEC_VALIDATION,464 IFLA_MACSEC_VALIDATION,
465 IFLA_MACSEC_PAD,465 IFLA_MACSEC_PAD,
466 IFLA_MACSEC_OFFLOAD,
466 __IFLA_MACSEC_MAX,467 __IFLA_MACSEC_MAX,
467};468};
468 469