Skip to content

Commit 6b5662b

Browse files
Cosmin Ratiukuba-moo
authored andcommitted
net/mlx5e: CT: Update connection tracking steering entries
Previously, replacing a connection tracking steering entry was done by adding a new rule (with the same tag but possibly different mod hdr actions/labels) then removing the old rule. This approach doesn't work in hardware steering because two steering entries with the same tag cannot coexist in a hardware steering table. This commit prepares for that by adding a new ct_rule_update operation on the ct_fs_ops struct which is used instead of add+delete. Implementations for both dmfs (firmware steering) and smfs (software steering) are provided, which simply add the new rule and delete the old one. Signed-off-by: Cosmin Ratiu <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 486aeb2 commit 6b5662b

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/tc/ct_fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ struct mlx5_ct_fs_ops {
2525
struct mlx5_flow_attr *attr,
2626
struct flow_rule *flow_rule);
2727
void (*ct_rule_del)(struct mlx5_ct_fs *fs, struct mlx5_ct_fs_rule *fs_rule);
28+
int (*ct_rule_update)(struct mlx5_ct_fs *fs, struct mlx5_ct_fs_rule *fs_rule,
29+
struct mlx5_flow_spec *spec, struct mlx5_flow_attr *attr);
2830

2931
size_t priv_size;
3032
};

drivers/net/ethernet/mellanox/mlx5/core/en/tc/ct_fs_dmfs.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,30 @@ mlx5_ct_fs_dmfs_ct_rule_del(struct mlx5_ct_fs *fs, struct mlx5_ct_fs_rule *fs_ru
6565
kfree(dmfs_rule);
6666
}
6767

68+
static int mlx5_ct_fs_dmfs_ct_rule_update(struct mlx5_ct_fs *fs, struct mlx5_ct_fs_rule *fs_rule,
69+
struct mlx5_flow_spec *spec, struct mlx5_flow_attr *attr)
70+
{
71+
struct mlx5_ct_fs_dmfs_rule *dmfs_rule = container_of(fs_rule,
72+
struct mlx5_ct_fs_dmfs_rule,
73+
fs_rule);
74+
struct mlx5e_priv *priv = netdev_priv(fs->netdev);
75+
struct mlx5_flow_handle *rule;
76+
77+
rule = mlx5_tc_rule_insert(priv, spec, attr);
78+
if (IS_ERR(rule))
79+
return PTR_ERR(rule);
80+
mlx5_tc_rule_delete(priv, dmfs_rule->rule, dmfs_rule->attr);
81+
82+
dmfs_rule->rule = rule;
83+
dmfs_rule->attr = attr;
84+
85+
return 0;
86+
}
87+
6888
static struct mlx5_ct_fs_ops dmfs_ops = {
6989
.ct_rule_add = mlx5_ct_fs_dmfs_ct_rule_add,
7090
.ct_rule_del = mlx5_ct_fs_dmfs_ct_rule_del,
91+
.ct_rule_update = mlx5_ct_fs_dmfs_ct_rule_update,
7192

7293
.init = mlx5_ct_fs_dmfs_init,
7394
.destroy = mlx5_ct_fs_dmfs_destroy,

drivers/net/ethernet/mellanox/mlx5/core/en/tc/ct_fs_smfs.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,35 @@ mlx5_ct_fs_smfs_ct_rule_del(struct mlx5_ct_fs *fs, struct mlx5_ct_fs_rule *fs_ru
368368
kfree(smfs_rule);
369369
}
370370

371+
static int mlx5_ct_fs_smfs_ct_rule_update(struct mlx5_ct_fs *fs, struct mlx5_ct_fs_rule *fs_rule,
372+
struct mlx5_flow_spec *spec, struct mlx5_flow_attr *attr)
373+
{
374+
struct mlx5_ct_fs_smfs_rule *smfs_rule = container_of(fs_rule,
375+
struct mlx5_ct_fs_smfs_rule,
376+
fs_rule);
377+
struct mlx5_ct_fs_smfs *fs_smfs = mlx5_ct_fs_priv(fs);
378+
struct mlx5dr_action *actions[3]; /* We only need to create 3 actions, see below. */
379+
struct mlx5dr_rule *rule;
380+
381+
actions[0] = smfs_rule->count_action;
382+
actions[1] = attr->modify_hdr->action.dr_action;
383+
actions[2] = fs_smfs->fwd_action;
384+
385+
rule = mlx5_smfs_rule_create(smfs_rule->smfs_matcher->dr_matcher, spec,
386+
ARRAY_SIZE(actions), actions, spec->flow_context.flow_source);
387+
if (!rule)
388+
return -EINVAL;
389+
390+
mlx5_smfs_rule_destroy(smfs_rule->rule);
391+
smfs_rule->rule = rule;
392+
393+
return 0;
394+
}
395+
371396
static struct mlx5_ct_fs_ops fs_smfs_ops = {
372397
.ct_rule_add = mlx5_ct_fs_smfs_ct_rule_add,
373398
.ct_rule_del = mlx5_ct_fs_smfs_ct_rule_del,
399+
.ct_rule_update = mlx5_ct_fs_smfs_ct_rule_update,
374400

375401
.init = mlx5_ct_fs_smfs_init,
376402
.destroy = mlx5_ct_fs_smfs_destroy,

drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,6 @@ mlx5_tc_ct_entry_update_rule(struct mlx5_tc_ct_priv *ct_priv,
884884
struct mlx5_ct_zone_rule *zone_rule = &entry->zone_rules[nat];
885885
struct mlx5_flow_attr *attr = zone_rule->attr, *old_attr;
886886
struct mlx5e_mod_hdr_handle *mh;
887-
struct mlx5_ct_fs_rule *rule;
888887
struct mlx5_flow_spec *spec;
889888
int err;
890889

@@ -902,22 +901,19 @@ mlx5_tc_ct_entry_update_rule(struct mlx5_tc_ct_priv *ct_priv,
902901
err = mlx5_tc_ct_entry_create_mod_hdr(ct_priv, attr, flow_rule, &mh, zone_restore_id,
903902
nat, mlx5_tc_ct_entry_in_ct_nat_table(entry));
904903
if (err) {
905-
ct_dbg("Failed to create ct entry mod hdr");
904+
ct_dbg("Failed to create ct entry mod hdr, err: %d", err);
906905
goto err_mod_hdr;
907906
}
908907

909908
mlx5_tc_ct_set_tuple_match(ct_priv, spec, flow_rule);
910909
mlx5e_tc_match_to_reg_match(spec, ZONE_TO_REG, entry->tuple.zone, MLX5_CT_ZONE_MASK);
911910

912-
rule = ct_priv->fs_ops->ct_rule_add(ct_priv->fs, spec, attr, flow_rule);
913-
if (IS_ERR(rule)) {
914-
err = PTR_ERR(rule);
915-
ct_dbg("Failed to add replacement ct entry rule, nat: %d", nat);
911+
err = ct_priv->fs_ops->ct_rule_update(ct_priv->fs, zone_rule->rule, spec, attr);
912+
if (err) {
913+
ct_dbg("Failed to update ct entry rule, nat: %d, err: %d", nat, err);
916914
goto err_rule;
917915
}
918916

919-
ct_priv->fs_ops->ct_rule_del(ct_priv->fs, zone_rule->rule);
920-
zone_rule->rule = rule;
921917
mlx5_tc_ct_entry_destroy_mod_hdr(ct_priv, old_attr, zone_rule->mh);
922918
zone_rule->mh = mh;
923919
mlx5_put_label_mapping(ct_priv, old_attr->ct_attr.ct_labels_id);

0 commit comments

Comments
 (0)