Skip to content

Commit 72046a9

Browse files
Eli CohenSaeed Mahameed
authored andcommitted
net/mlx5e: Allow to match on mpls parameters
Support matching on MPLS over UDP parameters using misc2 section of match parameters. Signed-off-by: Eli Cohen <[email protected]> Reviewed-by: Roi Dayan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent f828ca6 commit 72046a9

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,55 @@ static int parse_tunnel(struct mlx5e_priv *priv,
7373
void *headers_c,
7474
void *headers_v)
7575
{
76+
struct flow_rule *rule = flow_cls_offload_flow_rule(f);
77+
struct flow_match_enc_keyid enc_keyid;
78+
struct flow_match_mpls match;
79+
void *misc2_c;
80+
void *misc2_v;
81+
82+
misc2_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria,
83+
misc_parameters_2);
84+
misc2_v = MLX5_ADDR_OF(fte_match_param, spec->match_value,
85+
misc_parameters_2);
86+
87+
if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_MPLS))
88+
return 0;
89+
90+
if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_KEYID))
91+
return 0;
92+
93+
flow_rule_match_enc_keyid(rule, &enc_keyid);
94+
95+
if (!enc_keyid.mask->keyid)
96+
return 0;
97+
98+
if (!(MLX5_CAP_GEN(priv->mdev, flex_parser_protocols) &
99+
MLX5_FLEX_PROTO_CW_MPLS_UDP))
100+
return -EOPNOTSUPP;
101+
102+
flow_rule_match_mpls(rule, &match);
103+
104+
MLX5_SET(fte_match_set_misc2, misc2_c,
105+
outer_first_mpls_over_udp.mpls_label, match.mask->mpls_label);
106+
MLX5_SET(fte_match_set_misc2, misc2_v,
107+
outer_first_mpls_over_udp.mpls_label, match.key->mpls_label);
108+
109+
MLX5_SET(fte_match_set_misc2, misc2_c,
110+
outer_first_mpls_over_udp.mpls_exp, match.mask->mpls_tc);
111+
MLX5_SET(fte_match_set_misc2, misc2_v,
112+
outer_first_mpls_over_udp.mpls_exp, match.key->mpls_tc);
113+
114+
MLX5_SET(fte_match_set_misc2, misc2_c,
115+
outer_first_mpls_over_udp.mpls_s_bos, match.mask->mpls_bos);
116+
MLX5_SET(fte_match_set_misc2, misc2_v,
117+
outer_first_mpls_over_udp.mpls_s_bos, match.key->mpls_bos);
118+
119+
MLX5_SET(fte_match_set_misc2, misc2_c,
120+
outer_first_mpls_over_udp.mpls_ttl, match.mask->mpls_ttl);
121+
MLX5_SET(fte_match_set_misc2, misc2_v,
122+
outer_first_mpls_over_udp.mpls_ttl, match.key->mpls_ttl);
123+
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2;
124+
76125
return 0;
77126
}
78127

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,20 @@ static int mlx5e_flower_parse_meta(struct net_device *filter_dev,
20732073
return 0;
20742074
}
20752075

2076+
static bool skip_key_basic(struct net_device *filter_dev,
2077+
struct flow_cls_offload *f)
2078+
{
2079+
/* When doing mpls over udp decap, the user needs to provide
2080+
* MPLS_UC as the protocol in order to be able to match on mpls
2081+
* label fields. However, the actual ethertype is IP so we want to
2082+
* avoid matching on this, otherwise we'll fail the match.
2083+
*/
2084+
if (netif_is_bareudp(filter_dev) && f->common.chain_index == 0)
2085+
return true;
2086+
2087+
return false;
2088+
}
2089+
20762090
static int __parse_cls_flower(struct mlx5e_priv *priv,
20772091
struct mlx5e_tc_flow *flow,
20782092
struct mlx5_flow_spec *spec,
@@ -2117,7 +2131,8 @@ static int __parse_cls_flower(struct mlx5e_priv *priv,
21172131
BIT(FLOW_DISSECTOR_KEY_IP) |
21182132
BIT(FLOW_DISSECTOR_KEY_CT) |
21192133
BIT(FLOW_DISSECTOR_KEY_ENC_IP) |
2120-
BIT(FLOW_DISSECTOR_KEY_ENC_OPTS))) {
2134+
BIT(FLOW_DISSECTOR_KEY_ENC_OPTS) |
2135+
BIT(FLOW_DISSECTOR_KEY_MPLS))) {
21212136
NL_SET_ERR_MSG_MOD(extack, "Unsupported key");
21222137
netdev_warn(priv->netdev, "Unsupported key used: 0x%x\n",
21232138
dissector->used_keys);
@@ -2147,7 +2162,8 @@ static int __parse_cls_flower(struct mlx5e_priv *priv,
21472162
if (err)
21482163
return err;
21492164

2150-
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
2165+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC) &&
2166+
!skip_key_basic(filter_dev, f)) {
21512167
struct flow_match_basic match;
21522168

21532169
flow_rule_match_basic(rule, &match);

0 commit comments

Comments
 (0)