Skip to content

Commit a738518

Browse files
raed-salemSaeed Mahameed
authored andcommitted
net/mlx5e: IPsec, support upper protocol selector field offload
Add support to policy/state upper protocol selector field offload, this will enable to select traffic for IPsec operation based on l4 protocol (TCP/UDP) with specific source/destination port. Signed-off-by: Raed Salem <raeds@nvidia.com> Reviewed-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
1 parent ce23177 commit a738518

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ void mlx5e_ipsec_build_accel_xfrm_attrs(struct mlx5e_ipsec_sa_entry *sa_entry,
158158
attrs->family = x->props.family;
159159
attrs->type = x->xso.type;
160160
attrs->reqid = x->props.reqid;
161+
attrs->upspec.dport = ntohs(x->sel.dport);
162+
attrs->upspec.dport_mask = ntohs(x->sel.dport_mask);
163+
attrs->upspec.sport = ntohs(x->sel.sport);
164+
attrs->upspec.sport_mask = ntohs(x->sel.sport_mask);
165+
attrs->upspec.proto = x->sel.proto;
161166

162167
mlx5e_ipsec_init_limits(sa_entry, attrs);
163168
}
@@ -221,6 +226,13 @@ static int mlx5e_xfrm_validate_state(struct mlx5_core_dev *mdev,
221226
NL_SET_ERR_MSG_MOD(extack, "Cannot offload xfrm states with geniv other than seqiv");
222227
return -EINVAL;
223228
}
229+
230+
if (x->sel.proto != IPPROTO_IP &&
231+
(x->sel.proto != IPPROTO_UDP || x->xso.dir != XFRM_DEV_OFFLOAD_OUT)) {
232+
NL_SET_ERR_MSG_MOD(extack, "Device does not support upper protocol other than UDP, and only Tx direction");
233+
return -EINVAL;
234+
}
235+
224236
switch (x->xso.type) {
225237
case XFRM_DEV_OFFLOAD_CRYPTO:
226238
if (!(mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_CRYPTO)) {
@@ -517,6 +529,12 @@ static int mlx5e_xfrm_validate_policy(struct xfrm_policy *x,
517529
return -EINVAL;
518530
}
519531

532+
if (x->selector.proto != IPPROTO_IP &&
533+
(x->selector.proto != IPPROTO_UDP || x->xdo.dir != XFRM_DEV_OFFLOAD_OUT)) {
534+
NL_SET_ERR_MSG_MOD(extack, "Device does not support upper protocol other than UDP, and only Tx direction");
535+
return -EINVAL;
536+
}
537+
520538
return 0;
521539
}
522540

@@ -537,6 +555,11 @@ mlx5e_ipsec_build_accel_pol_attrs(struct mlx5e_ipsec_pol_entry *pol_entry,
537555
attrs->action = x->action;
538556
attrs->type = XFRM_DEV_OFFLOAD_PACKET;
539557
attrs->reqid = x->xfrm_vec[0].reqid;
558+
attrs->upspec.dport = ntohs(sel->dport);
559+
attrs->upspec.dport_mask = ntohs(sel->dport_mask);
560+
attrs->upspec.sport = ntohs(sel->sport);
561+
attrs->upspec.sport_mask = ntohs(sel->sport_mask);
562+
attrs->upspec.proto = sel->proto;
540563
}
541564

542565
static int mlx5e_xfrm_add_policy(struct xfrm_policy *x,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ struct aes_gcm_keymat {
5252
u32 aes_key[256 / 32];
5353
};
5454

55+
struct upspec {
56+
u16 dport;
57+
u16 dport_mask;
58+
u16 sport;
59+
u16 sport_mask;
60+
u8 proto;
61+
};
62+
5563
struct mlx5_accel_esp_xfrm_attrs {
5664
u32 esn;
5765
u32 spi;
@@ -68,6 +76,7 @@ struct mlx5_accel_esp_xfrm_attrs {
6876
__be32 a6[4];
6977
} daddr;
7078

79+
struct upspec upspec;
7180
u8 dir : 2;
7281
u8 esn_overlap : 1;
7382
u8 esn_trigger : 1;
@@ -181,6 +190,7 @@ struct mlx5_accel_pol_xfrm_attrs {
181190
__be32 a6[4];
182191
} daddr;
183192

193+
struct upspec upspec;
184194
u8 family;
185195
u8 action;
186196
u8 type : 2;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,27 @@ static void setup_fte_reg_c0(struct mlx5_flow_spec *spec, u32 reqid)
467467
misc_parameters_2.metadata_reg_c_0, reqid);
468468
}
469469

470+
static void setup_fte_upper_proto_match(struct mlx5_flow_spec *spec, struct upspec *upspec)
471+
{
472+
if (upspec->proto != IPPROTO_UDP)
473+
return;
474+
475+
spec->match_criteria_enable |= MLX5_MATCH_OUTER_HEADERS;
476+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, spec->match_criteria, ip_protocol);
477+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, ip_protocol, upspec->proto);
478+
if (upspec->dport) {
479+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_criteria, udp_dport,
480+
upspec->dport_mask);
481+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, udp_dport, upspec->dport);
482+
}
483+
484+
if (upspec->sport) {
485+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_criteria, udp_dport,
486+
upspec->sport_mask);
487+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, udp_dport, upspec->sport);
488+
}
489+
}
490+
470491
static int setup_modify_header(struct mlx5_core_dev *mdev, u32 val, u8 dir,
471492
struct mlx5_flow_act *flow_act)
472493
{
@@ -654,6 +675,7 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
654675
setup_fte_addr6(spec, attrs->saddr.a6, attrs->daddr.a6);
655676

656677
setup_fte_no_frags(spec);
678+
setup_fte_upper_proto_match(spec, &attrs->upspec);
657679

658680
switch (attrs->type) {
659681
case XFRM_DEV_OFFLOAD_CRYPTO:
@@ -728,6 +750,7 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
728750
setup_fte_addr6(spec, attrs->saddr.a6, attrs->daddr.a6);
729751

730752
setup_fte_no_frags(spec);
753+
setup_fte_upper_proto_match(spec, &attrs->upspec);
731754

732755
err = setup_modify_header(mdev, attrs->reqid, XFRM_DEV_OFFLOAD_OUT,
733756
&flow_act);

0 commit comments

Comments
 (0)