xref: /linux/include/net/tc_act/tc_ct.h (revision 3494bec0f6ac8ac06e0ad7c35933db345b2c5a83)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NET_TC_CT_H
3 #define __NET_TC_CT_H
4 
5 #include <net/act_api.h>
6 #include <uapi/linux/tc_act/tc_ct.h>
7 
8 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
9 #include <net/netfilter/nf_nat.h>
10 #include <net/netfilter/nf_conntrack_labels.h>
11 
12 struct tcf_ct_params {
13 	struct nf_conn *tmpl;
14 	u16 zone;
15 
16 	u32 mark;
17 	u32 mark_mask;
18 
19 	u32 labels[NF_CT_LABELS_MAX_SIZE / sizeof(u32)];
20 	u32 labels_mask[NF_CT_LABELS_MAX_SIZE / sizeof(u32)];
21 
22 	struct nf_nat_range2 range;
23 	bool ipv4_range;
24 
25 	u16 ct_action;
26 
27 	struct rcu_head rcu;
28 };
29 
30 struct tcf_ct {
31 	struct tc_action common;
32 	struct tcf_ct_params __rcu *params;
33 };
34 
35 #define to_ct(a) ((struct tcf_ct *)a)
36 #define to_ct_params(a)							\
37 	((struct tcf_ct_params *)					\
38 	 rcu_dereference_protected(to_ct(a)->params,			\
39 				   lockdep_is_held(&a->tcfa_lock)))
40 
41 static inline uint16_t tcf_ct_zone(const struct tc_action *a)
42 {
43 	return to_ct_params(a)->zone;
44 }
45 
46 static inline int tcf_ct_action(const struct tc_action *a)
47 {
48 	return to_ct_params(a)->ct_action;
49 }
50 
51 #else
52 static inline uint16_t tcf_ct_zone(const struct tc_action *a) { return 0; }
53 static inline int tcf_ct_action(const struct tc_action *a) { return 0; }
54 #endif /* CONFIG_NF_CONNTRACK */
55 
56 static inline bool is_tcf_ct(const struct tc_action *a)
57 {
58 #if defined(CONFIG_NET_CLS_ACT) && IS_ENABLED(CONFIG_NF_CONNTRACK)
59 	if (a->ops && a->ops->id == TCA_ID_CT)
60 		return true;
61 #endif
62 	return false;
63 }
64 
65 #endif /* __NET_TC_CT_H */
66