Skip to content

Commit 51d41cd

Browse files
rleongregkh
authored andcommitted
xfrm: add new packet offload flag
[ Upstream commit d14f28b ] In the next patches, the xfrm core code will be extended to support new type of offload - packet offload. In that mode, both policy and state should be specially configured in order to perform whole offloaded data path. Full offload takes care of encryption, decryption, encapsulation and other operations with headers. As this mode is new for XFRM policy flow, we can "start fresh" with flag bits and release first and second bit for future use. Reviewed-by: Raed Salem <raeds@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Stable-dep-of: 68de007 ("xfrm: annotate data-races around xfrm_policy_count[] and xfrm_policy_default[]") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c314efa commit 51d41cd

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

include/net/xfrm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,19 @@ enum {
131131
XFRM_DEV_OFFLOAD_OUT,
132132
};
133133

134+
enum {
135+
XFRM_DEV_OFFLOAD_UNSPECIFIED,
136+
XFRM_DEV_OFFLOAD_CRYPTO,
137+
XFRM_DEV_OFFLOAD_PACKET,
138+
};
139+
134140
struct xfrm_dev_offload {
135141
struct net_device *dev;
136142
netdevice_tracker dev_tracker;
137143
struct net_device *real_dev;
138144
unsigned long offload_handle;
139145
u8 dir : 2;
146+
u8 type : 2;
140147
};
141148

142149
struct xfrm_mode {

include/uapi/linux/xfrm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,12 @@ struct xfrm_user_offload {
519519
*/
520520
#define XFRM_OFFLOAD_IPV6 1
521521
#define XFRM_OFFLOAD_INBOUND 2
522+
/* Two bits above are relevant for state path only, while
523+
* offload is used for both policy and state flows.
524+
*
525+
* In policy offload mode, they are free and can be safely reused.
526+
*/
527+
#define XFRM_OFFLOAD_PACKET 4
522528

523529
struct xfrm_userpolicy_default {
524530
#define XFRM_USERPOLICY_UNSPEC 0

net/xfrm/xfrm_device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,15 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
296296
else
297297
xso->dir = XFRM_DEV_OFFLOAD_OUT;
298298

299+
xso->type = XFRM_DEV_OFFLOAD_CRYPTO;
300+
299301
err = dev->xfrmdev_ops->xdo_dev_state_add(x);
300302
if (err) {
301303
xso->dev = NULL;
302304
xso->dir = 0;
303305
xso->real_dev = NULL;
304306
netdev_put(dev, &xso->dev_tracker);
307+
xso->type = XFRM_DEV_OFFLOAD_UNSPECIFIED;
305308

306309
if (err != -EOPNOTSUPP) {
307310
NL_SET_ERR_MSG(extack, "Device failed to offload this state");

net/xfrm/xfrm_user.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ static int copy_user_offload(struct xfrm_dev_offload *xso, struct sk_buff *skb)
947947
xuo->ifindex = xso->dev->ifindex;
948948
if (xso->dir == XFRM_DEV_OFFLOAD_IN)
949949
xuo->flags = XFRM_OFFLOAD_INBOUND;
950+
if (xso->type == XFRM_DEV_OFFLOAD_PACKET)
951+
xuo->flags |= XFRM_OFFLOAD_PACKET;
950952

951953
return 0;
952954
}

0 commit comments

Comments
 (0)