Skip to content

Commit 791bb3f

Browse files
mstarovodavem330
authored andcommitted
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. Signed-off-by: Mark Starovoytov <mstarovoitov@marvell.com> Signed-off-by: Igor Russkikh <irusskikh@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f0b5989 commit 791bb3f

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎drivers/net/macsec.c‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,11 @@ static struct net_device *get_dev_from_nl(struct net *net,
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,
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,
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ enum {
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ enum {
463463
IFLA_MACSEC_REPLAY_PROTECT,
464464
IFLA_MACSEC_VALIDATION,
465465
IFLA_MACSEC_PAD,
466+
IFLA_MACSEC_OFFLOAD,
466467
__IFLA_MACSEC_MAX,
467468
};
468469

0 commit comments

Comments
 (0)