Skip to content

Commit cc18f48

Browse files
rleonklassert
authored andcommitted
xfrm: provide common xdo_dev_offload_ok callback implementation
Almost all drivers except bond and nsim had same check if device can perform XFRM offload on that specific packet. The check was that packet doesn't have IPv4 options and IPv6 extensions. In NIC drivers, the IPv4 HELEN comparison was slightly different, but the intent was to check for the same conditions. So let's chose more strict variant as a common base. Reviewed-by: Zhu Yanjun <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 49431af commit cc18f48

File tree

12 files changed

+22
-145
lines changed

12 files changed

+22
-145
lines changed

Documentation/networking/xfrm_device.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ been setup for offload, it first calls into xdo_dev_offload_ok() with
126126
the skb and the intended offload state to ask the driver if the offload
127127
will serviceable. This can check the packet information to be sure the
128128
offload can be supported (e.g. IPv4 or IPv6, no IPv4 options, etc) and
129-
return true of false to signify its support.
129+
return true or false to signify its support. In case driver doesn't implement
130+
this callback, the stack provides reasonable defaults.
130131

131132
Crypto offload mode:
132133
When ready to send, the driver needs to inspect the Tx packet for the

drivers/net/bonding/bond_main.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -673,22 +673,16 @@ static void bond_ipsec_free_sa(struct xfrm_state *xs)
673673
static bool bond_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs)
674674
{
675675
struct net_device *real_dev;
676-
bool ok = false;
677676

678677
rcu_read_lock();
679678
real_dev = bond_ipsec_dev(xs);
680-
if (!real_dev)
681-
goto out;
682-
683-
if (!real_dev->xfrmdev_ops ||
684-
!real_dev->xfrmdev_ops->xdo_dev_offload_ok ||
685-
netif_is_bond_master(real_dev))
686-
goto out;
679+
if (!real_dev || netif_is_bond_master(real_dev)) {
680+
rcu_read_unlock();
681+
return false;
682+
}
687683

688-
ok = real_dev->xfrmdev_ops->xdo_dev_offload_ok(skb, xs);
689-
out:
690684
rcu_read_unlock();
691-
return ok;
685+
return true;
692686
}
693687

694688
/**

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6538,26 +6538,6 @@ static void cxgb4_xfrm_free_state(struct xfrm_state *x)
65386538
mutex_unlock(&uld_mutex);
65396539
}
65406540

6541-
static bool cxgb4_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
6542-
{
6543-
struct adapter *adap = netdev2adap(x->xso.dev);
6544-
bool ret = false;
6545-
6546-
if (!mutex_trylock(&uld_mutex)) {
6547-
dev_dbg(adap->pdev_dev,
6548-
"crypto uld critical resource is under use\n");
6549-
return ret;
6550-
}
6551-
if (chcr_offload_state(adap, CXGB4_XFRMDEV_OPS))
6552-
goto out_unlock;
6553-
6554-
ret = adap->uld[CXGB4_ULD_IPSEC].xfrmdev_ops->xdo_dev_offload_ok(skb, x);
6555-
6556-
out_unlock:
6557-
mutex_unlock(&uld_mutex);
6558-
return ret;
6559-
}
6560-
65616541
static void cxgb4_advance_esn_state(struct xfrm_state *x)
65626542
{
65636543
struct adapter *adap = netdev2adap(x->xso.dev);
@@ -6583,7 +6563,6 @@ static const struct xfrmdev_ops cxgb4_xfrmdev_ops = {
65836563
.xdo_dev_state_add = cxgb4_xfrm_add_state,
65846564
.xdo_dev_state_delete = cxgb4_xfrm_del_state,
65856565
.xdo_dev_state_free = cxgb4_xfrm_free_state,
6586-
.xdo_dev_offload_ok = cxgb4_ipsec_offload_ok,
65876566
.xdo_dev_state_advance_esn = cxgb4_advance_esn_state,
65886567
};
65896568

drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
static LIST_HEAD(uld_ctx_list);
7272
static DEFINE_MUTEX(dev_mutex);
7373

74-
static bool ch_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x);
7574
static int ch_ipsec_uld_state_change(void *handle, enum cxgb4_state new_state);
7675
static int ch_ipsec_xmit(struct sk_buff *skb, struct net_device *dev);
7776
static void *ch_ipsec_uld_add(const struct cxgb4_lld_info *infop);
@@ -85,7 +84,6 @@ static const struct xfrmdev_ops ch_ipsec_xfrmdev_ops = {
8584
.xdo_dev_state_add = ch_ipsec_xfrm_add_state,
8685
.xdo_dev_state_delete = ch_ipsec_xfrm_del_state,
8786
.xdo_dev_state_free = ch_ipsec_xfrm_free_state,
88-
.xdo_dev_offload_ok = ch_ipsec_offload_ok,
8987
.xdo_dev_state_advance_esn = ch_ipsec_advance_esn_state,
9088
};
9189

@@ -323,20 +321,6 @@ static void ch_ipsec_xfrm_free_state(struct xfrm_state *x)
323321
module_put(THIS_MODULE);
324322
}
325323

326-
static bool ch_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
327-
{
328-
if (x->props.family == AF_INET) {
329-
/* Offload with IP options is not supported yet */
330-
if (ip_hdr(skb)->ihl > 5)
331-
return false;
332-
} else {
333-
/* Offload with IPv6 extension headers is not support yet */
334-
if (ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr))
335-
return false;
336-
}
337-
return true;
338-
}
339-
340324
static void ch_ipsec_advance_esn_state(struct xfrm_state *x)
341325
{
342326
/* do nothing */

drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -817,30 +817,9 @@ static void ixgbe_ipsec_del_sa(struct xfrm_state *xs)
817817
}
818818
}
819819

820-
/**
821-
* ixgbe_ipsec_offload_ok - can this packet use the xfrm hw offload
822-
* @skb: current data packet
823-
* @xs: pointer to transformer state struct
824-
**/
825-
static bool ixgbe_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs)
826-
{
827-
if (xs->props.family == AF_INET) {
828-
/* Offload with IPv4 options is not supported yet */
829-
if (ip_hdr(skb)->ihl != 5)
830-
return false;
831-
} else {
832-
/* Offload with IPv6 extension headers is not support yet */
833-
if (ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr))
834-
return false;
835-
}
836-
837-
return true;
838-
}
839-
840820
static const struct xfrmdev_ops ixgbe_xfrmdev_ops = {
841821
.xdo_dev_state_add = ixgbe_ipsec_add_sa,
842822
.xdo_dev_state_delete = ixgbe_ipsec_del_sa,
843-
.xdo_dev_offload_ok = ixgbe_ipsec_offload_ok,
844823
};
845824

846825
/**

drivers/net/ethernet/intel/ixgbevf/ipsec.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -428,30 +428,9 @@ static void ixgbevf_ipsec_del_sa(struct xfrm_state *xs)
428428
}
429429
}
430430

431-
/**
432-
* ixgbevf_ipsec_offload_ok - can this packet use the xfrm hw offload
433-
* @skb: current data packet
434-
* @xs: pointer to transformer state struct
435-
**/
436-
static bool ixgbevf_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs)
437-
{
438-
if (xs->props.family == AF_INET) {
439-
/* Offload with IPv4 options is not supported yet */
440-
if (ip_hdr(skb)->ihl != 5)
441-
return false;
442-
} else {
443-
/* Offload with IPv6 extension headers is not support yet */
444-
if (ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr))
445-
return false;
446-
}
447-
448-
return true;
449-
}
450-
451431
static const struct xfrmdev_ops ixgbevf_xfrmdev_ops = {
452432
.xdo_dev_state_add = ixgbevf_ipsec_add_sa,
453433
.xdo_dev_state_delete = ixgbevf_ipsec_del_sa,
454-
.xdo_dev_offload_ok = ixgbevf_ipsec_offload_ok,
455434
};
456435

457436
/**

drivers/net/ethernet/marvell/octeontx2/nic/cn10k_ipsec.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -744,24 +744,9 @@ static void cn10k_ipsec_del_state(struct xfrm_state *x)
744744
queue_work(pf->ipsec.sa_workq, &pf->ipsec.sa_work);
745745
}
746746

747-
static bool cn10k_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
748-
{
749-
if (x->props.family == AF_INET) {
750-
/* Offload with IPv4 options is not supported yet */
751-
if (ip_hdr(skb)->ihl > 5)
752-
return false;
753-
} else {
754-
/* Offload with IPv6 extension headers is not support yet */
755-
if (ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr))
756-
return false;
757-
}
758-
return true;
759-
}
760-
761747
static const struct xfrmdev_ops cn10k_ipsec_xfrmdev_ops = {
762748
.xdo_dev_state_add = cn10k_ipsec_add_state,
763749
.xdo_dev_state_delete = cn10k_ipsec_del_state,
764-
.xdo_dev_offload_ok = cn10k_ipsec_offload_ok,
765750
};
766751

767752
static void cn10k_ipsec_sa_wq_handler(struct work_struct *work)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -953,21 +953,6 @@ void mlx5e_ipsec_cleanup(struct mlx5e_priv *priv)
953953
priv->ipsec = NULL;
954954
}
955955

956-
static bool mlx5e_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
957-
{
958-
if (x->props.family == AF_INET) {
959-
/* Offload with IPv4 options is not supported yet */
960-
if (ip_hdr(skb)->ihl > 5)
961-
return false;
962-
} else {
963-
/* Offload with IPv6 extension headers is not support yet */
964-
if (ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr))
965-
return false;
966-
}
967-
968-
return true;
969-
}
970-
971956
static void mlx5e_xfrm_advance_esn_state(struct xfrm_state *x)
972957
{
973958
struct mlx5e_ipsec_sa_entry *sa_entry = to_ipsec_sa_entry(x);
@@ -1196,7 +1181,6 @@ static const struct xfrmdev_ops mlx5e_ipsec_xfrmdev_ops = {
11961181
.xdo_dev_state_add = mlx5e_xfrm_add_state,
11971182
.xdo_dev_state_delete = mlx5e_xfrm_del_state,
11981183
.xdo_dev_state_free = mlx5e_xfrm_free_state,
1199-
.xdo_dev_offload_ok = mlx5e_ipsec_offload_ok,
12001184
.xdo_dev_state_advance_esn = mlx5e_xfrm_advance_esn_state,
12011185

12021186
.xdo_dev_state_update_stats = mlx5e_xfrm_update_stats,

drivers/net/ethernet/netronome/nfp/crypto/ipsec.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,20 +565,9 @@ static void nfp_net_xfrm_del_state(struct xfrm_state *x)
565565
xa_erase(&nn->xa_ipsec, x->xso.offload_handle - 1);
566566
}
567567

568-
static bool nfp_net_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
569-
{
570-
if (x->props.family == AF_INET)
571-
/* Offload with IPv4 options is not supported yet */
572-
return ip_hdr(skb)->ihl == 5;
573-
574-
/* Offload with IPv6 extension headers is not support yet */
575-
return !(ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr));
576-
}
577-
578568
static const struct xfrmdev_ops nfp_net_ipsec_xfrmdev_ops = {
579569
.xdo_dev_state_add = nfp_net_xfrm_add_state,
580570
.xdo_dev_state_delete = nfp_net_xfrm_del_state,
581-
.xdo_dev_offload_ok = nfp_net_ipsec_offload_ok,
582571
};
583572

584573
void nfp_net_ipsec_init(struct nfp_net *nn)

drivers/net/netdevsim/ipsec.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,9 @@ static void nsim_ipsec_del_sa(struct xfrm_state *xs)
217217
ipsec->count--;
218218
}
219219

220-
static bool nsim_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs)
221-
{
222-
struct netdevsim *ns = netdev_priv(xs->xso.real_dev);
223-
struct nsim_ipsec *ipsec = &ns->ipsec;
224-
225-
ipsec->ok++;
226-
227-
return true;
228-
}
229-
230220
static const struct xfrmdev_ops nsim_xfrmdev_ops = {
231221
.xdo_dev_state_add = nsim_ipsec_add_sa,
232222
.xdo_dev_state_delete = nsim_ipsec_del_sa,
233-
.xdo_dev_offload_ok = nsim_ipsec_offload_ok,
234223
};
235224

236225
bool nsim_ipsec_tx(struct netdevsim *ns, struct sk_buff *skb)

0 commit comments

Comments
 (0)