Skip to content

Commit 7f95b02

Browse files
rleonPaolo Abeni
authored andcommitted
net/mlx5e: Always start IPsec sequence number from 1
According to RFC4303, section "3.3.3. Sequence Number Generation", the first packet sent using a given SA will contain a sequence number of 1. This is applicable to both ESN and non-ESN mode, which was not covered in commit mentioned in Fixes line. Fixes: 3d42c8c ("net/mlx5e: Ensure that IPsec sequence packet number starts from 1") Signed-off-by: Leon Romanovsky <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 25f2352 commit 7f95b02

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,12 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x,
724724
/* check esn */
725725
if (x->props.flags & XFRM_STATE_ESN)
726726
mlx5e_ipsec_update_esn_state(sa_entry);
727+
else
728+
/* According to RFC4303, section "3.3.3. Sequence Number Generation",
729+
* the first packet sent using a given SA will contain a sequence
730+
* number of 1.
731+
*/
732+
sa_entry->esn_state.esn = 1;
727733

728734
mlx5e_ipsec_build_accel_xfrm_attrs(sa_entry, &sa_entry->attrs);
729735

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ u32 mlx5_ipsec_device_caps(struct mlx5_core_dev *mdev)
9191
EXPORT_SYMBOL_GPL(mlx5_ipsec_device_caps);
9292

9393
static void mlx5e_ipsec_packet_setup(void *obj, u32 pdn,
94-
struct mlx5_accel_esp_xfrm_attrs *attrs)
94+
struct mlx5e_ipsec_sa_entry *sa_entry)
9595
{
96+
struct mlx5_accel_esp_xfrm_attrs *attrs = &sa_entry->attrs;
9697
void *aso_ctx;
9798

9899
aso_ctx = MLX5_ADDR_OF(ipsec_obj, obj, ipsec_aso);
@@ -120,8 +121,12 @@ static void mlx5e_ipsec_packet_setup(void *obj, u32 pdn,
120121
* active.
121122
*/
122123
MLX5_SET(ipsec_obj, obj, aso_return_reg, MLX5_IPSEC_ASO_REG_C_4_5);
123-
if (attrs->dir == XFRM_DEV_OFFLOAD_OUT)
124+
if (attrs->dir == XFRM_DEV_OFFLOAD_OUT) {
124125
MLX5_SET(ipsec_aso, aso_ctx, mode, MLX5_IPSEC_ASO_INC_SN);
126+
if (!attrs->replay_esn.trigger)
127+
MLX5_SET(ipsec_aso, aso_ctx, mode_parameter,
128+
sa_entry->esn_state.esn);
129+
}
125130

126131
if (attrs->lft.hard_packet_limit != XFRM_INF) {
127132
MLX5_SET(ipsec_aso, aso_ctx, remove_flow_pkt_cnt,
@@ -175,7 +180,7 @@ static int mlx5_create_ipsec_obj(struct mlx5e_ipsec_sa_entry *sa_entry)
175180

176181
res = &mdev->mlx5e_res.hw_objs;
177182
if (attrs->type == XFRM_DEV_OFFLOAD_PACKET)
178-
mlx5e_ipsec_packet_setup(obj, res->pdn, attrs);
183+
mlx5e_ipsec_packet_setup(obj, res->pdn, sa_entry);
179184

180185
err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
181186
if (!err)

0 commit comments

Comments
 (0)