13
13
#define INIT_ERR_PREFIX "ct_fs_smfs init failed"
14
14
#define ct_dbg (fmt , args ...)\
15
15
netdev_dbg(fs->netdev, "ct_fs_smfs debug: " fmt "\n", ##args)
16
- #define MLX5_CT_TCP_FLAGS_MASK cpu_to_be16(be32_to_cpu(TCP_FLAG_RST | TCP_FLAG_FIN) >> 16)
17
16
18
17
struct mlx5_ct_fs_smfs_matcher {
19
18
struct mlx5dr_matcher * dr_matcher ;
@@ -220,78 +219,6 @@ mlx5_ct_fs_smfs_destroy(struct mlx5_ct_fs *fs)
220
219
mlx5_smfs_action_destroy (fs_smfs -> fwd_action );
221
220
}
222
221
223
- static inline bool
224
- mlx5_tc_ct_valid_used_dissector_keys (const u64 used_keys )
225
- {
226
- #define DISS_BIT (name ) BIT_ULL(FLOW_DISSECTOR_KEY_ ## name)
227
- const u64 basic_keys = DISS_BIT (BASIC ) | DISS_BIT (CONTROL ) |
228
- DISS_BIT (META );
229
- const u64 ipv4_tcp = basic_keys | DISS_BIT (IPV4_ADDRS ) |
230
- DISS_BIT (PORTS ) | DISS_BIT (TCP );
231
- const u64 ipv6_tcp = basic_keys | DISS_BIT (IPV6_ADDRS ) |
232
- DISS_BIT (PORTS ) | DISS_BIT (TCP );
233
- const u64 ipv4_udp = basic_keys | DISS_BIT (IPV4_ADDRS ) |
234
- DISS_BIT (PORTS );
235
- const u64 ipv6_udp = basic_keys | DISS_BIT (IPV6_ADDRS ) |
236
- DISS_BIT (PORTS );
237
- const u64 ipv4_gre = basic_keys | DISS_BIT (IPV4_ADDRS );
238
- const u64 ipv6_gre = basic_keys | DISS_BIT (IPV6_ADDRS );
239
-
240
- return (used_keys == ipv4_tcp || used_keys == ipv4_udp || used_keys == ipv6_tcp ||
241
- used_keys == ipv6_udp || used_keys == ipv4_gre || used_keys == ipv6_gre );
242
- }
243
-
244
- static bool
245
- mlx5_ct_fs_smfs_ct_validate_flow_rule (struct mlx5_ct_fs * fs , struct flow_rule * flow_rule )
246
- {
247
- struct flow_match_ipv4_addrs ipv4_addrs ;
248
- struct flow_match_ipv6_addrs ipv6_addrs ;
249
- struct flow_match_control control ;
250
- struct flow_match_basic basic ;
251
- struct flow_match_ports ports ;
252
- struct flow_match_tcp tcp ;
253
-
254
- if (!mlx5_tc_ct_valid_used_dissector_keys (flow_rule -> match .dissector -> used_keys )) {
255
- ct_dbg ("rule uses unexpected dissectors (0x%016llx)" ,
256
- flow_rule -> match .dissector -> used_keys );
257
- return false;
258
- }
259
-
260
- flow_rule_match_basic (flow_rule , & basic );
261
- flow_rule_match_control (flow_rule , & control );
262
- flow_rule_match_ipv4_addrs (flow_rule , & ipv4_addrs );
263
- flow_rule_match_ipv6_addrs (flow_rule , & ipv6_addrs );
264
- if (basic .key -> ip_proto != IPPROTO_GRE )
265
- flow_rule_match_ports (flow_rule , & ports );
266
- if (basic .key -> ip_proto == IPPROTO_TCP )
267
- flow_rule_match_tcp (flow_rule , & tcp );
268
-
269
- if (basic .mask -> n_proto != htons (0xFFFF ) ||
270
- (basic .key -> n_proto != htons (ETH_P_IP ) && basic .key -> n_proto != htons (ETH_P_IPV6 )) ||
271
- basic .mask -> ip_proto != 0xFF ||
272
- (basic .key -> ip_proto != IPPROTO_UDP && basic .key -> ip_proto != IPPROTO_TCP &&
273
- basic .key -> ip_proto != IPPROTO_GRE )) {
274
- ct_dbg ("rule uses unexpected basic match (n_proto 0x%04x/0x%04x, ip_proto 0x%02x/0x%02x)" ,
275
- ntohs (basic .key -> n_proto ), ntohs (basic .mask -> n_proto ),
276
- basic .key -> ip_proto , basic .mask -> ip_proto );
277
- return false;
278
- }
279
-
280
- if (basic .key -> ip_proto != IPPROTO_GRE &&
281
- (ports .mask -> src != htons (0xFFFF ) || ports .mask -> dst != htons (0xFFFF ))) {
282
- ct_dbg ("rule uses ports match (src 0x%04x, dst 0x%04x)" ,
283
- ports .mask -> src , ports .mask -> dst );
284
- return false;
285
- }
286
-
287
- if (basic .key -> ip_proto == IPPROTO_TCP && tcp .mask -> flags != MLX5_CT_TCP_FLAGS_MASK ) {
288
- ct_dbg ("rule uses unexpected tcp match (flags 0x%02x)" , tcp .mask -> flags );
289
- return false;
290
- }
291
-
292
- return true;
293
- }
294
-
295
222
static struct mlx5_ct_fs_rule *
296
223
mlx5_ct_fs_smfs_ct_rule_add (struct mlx5_ct_fs * fs , struct mlx5_flow_spec * spec ,
297
224
struct mlx5_flow_attr * attr , struct flow_rule * flow_rule )
@@ -304,7 +231,7 @@ mlx5_ct_fs_smfs_ct_rule_add(struct mlx5_ct_fs *fs, struct mlx5_flow_spec *spec,
304
231
int num_actions = 0 , err ;
305
232
bool nat , tcp , ipv4 , gre ;
306
233
307
- if (!mlx5_ct_fs_smfs_ct_validate_flow_rule (fs , flow_rule ))
234
+ if (!mlx5e_tc_ct_is_valid_flow_rule (fs -> netdev , flow_rule ))
308
235
return ERR_PTR (- EOPNOTSUPP );
309
236
310
237
smfs_rule = kzalloc (sizeof (* smfs_rule ), GFP_KERNEL );
0 commit comments