xref: /openbmc/linux/include/net/tc_act/tc_gact.h (revision 2dd6532e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NET_TC_GACT_H
3 #define __NET_TC_GACT_H
4 
5 #include <net/act_api.h>
6 #include <linux/tc_act/tc_gact.h>
7 
8 struct tcf_gact {
9 	struct tc_action	common;
10 #ifdef CONFIG_GACT_PROB
11 	u16			tcfg_ptype;
12 	u16			tcfg_pval;
13 	int			tcfg_paction;
14 	atomic_t		packets;
15 #endif
16 };
17 #define to_gact(a) ((struct tcf_gact *)a)
18 
19 static inline bool __is_tcf_gact_act(const struct tc_action *a, int act,
20 				     bool is_ext)
21 {
22 #ifdef CONFIG_NET_CLS_ACT
23 	struct tcf_gact *gact;
24 
25 	if (a->ops && a->ops->id != TCA_ID_GACT)
26 		return false;
27 
28 	gact = to_gact(a);
29 	if ((!is_ext && gact->tcf_action == act) ||
30 	    (is_ext && TC_ACT_EXT_CMP(gact->tcf_action, act)))
31 		return true;
32 
33 #endif
34 	return false;
35 }
36 
37 static inline bool is_tcf_gact_ok(const struct tc_action *a)
38 {
39 	return __is_tcf_gact_act(a, TC_ACT_OK, false);
40 }
41 
42 static inline bool is_tcf_gact_shot(const struct tc_action *a)
43 {
44 	return __is_tcf_gact_act(a, TC_ACT_SHOT, false);
45 }
46 
47 static inline bool is_tcf_gact_trap(const struct tc_action *a)
48 {
49 	return __is_tcf_gact_act(a, TC_ACT_TRAP, false);
50 }
51 
52 static inline bool is_tcf_gact_goto_chain(const struct tc_action *a)
53 {
54 	return __is_tcf_gact_act(a, TC_ACT_GOTO_CHAIN, true);
55 }
56 
57 static inline u32 tcf_gact_goto_chain_index(const struct tc_action *a)
58 {
59 	return READ_ONCE(a->tcfa_action) & TC_ACT_EXT_VAL_MASK;
60 }
61 
62 static inline bool is_tcf_gact_continue(const struct tc_action *a)
63 {
64 	return __is_tcf_gact_act(a, TC_ACT_UNSPEC, false);
65 }
66 
67 static inline bool is_tcf_gact_reclassify(const struct tc_action *a)
68 {
69 	return __is_tcf_gact_act(a, TC_ACT_RECLASSIFY, false);
70 }
71 
72 static inline bool is_tcf_gact_pipe(const struct tc_action *a)
73 {
74 	return __is_tcf_gact_act(a, TC_ACT_PIPE, false);
75 }
76 
77 #endif /* __NET_TC_GACT_H */
78