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