xref: /OK3568_Linux_fs/kernel/include/net/tc_act/tc_skbedit.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2008, Intel Corporation.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Author: Alexander Duyck <alexander.h.duyck@intel.com>
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __NET_TC_SKBEDIT_H
9*4882a593Smuzhiyun #define __NET_TC_SKBEDIT_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <net/act_api.h>
12*4882a593Smuzhiyun #include <linux/tc_act/tc_skbedit.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun struct tcf_skbedit_params {
15*4882a593Smuzhiyun 	u32 flags;
16*4882a593Smuzhiyun 	u32 priority;
17*4882a593Smuzhiyun 	u32 mark;
18*4882a593Smuzhiyun 	u32 mask;
19*4882a593Smuzhiyun 	u16 queue_mapping;
20*4882a593Smuzhiyun 	u16 ptype;
21*4882a593Smuzhiyun 	struct rcu_head rcu;
22*4882a593Smuzhiyun };
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun struct tcf_skbedit {
25*4882a593Smuzhiyun 	struct tc_action common;
26*4882a593Smuzhiyun 	struct tcf_skbedit_params __rcu *params;
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun #define to_skbedit(a) ((struct tcf_skbedit *)a)
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* Return true iff action is the one identified by FLAG. */
is_tcf_skbedit_with_flag(const struct tc_action * a,u32 flag)31*4882a593Smuzhiyun static inline bool is_tcf_skbedit_with_flag(const struct tc_action *a, u32 flag)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun #ifdef CONFIG_NET_CLS_ACT
34*4882a593Smuzhiyun 	u32 flags;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	if (a->ops && a->ops->id == TCA_ID_SKBEDIT) {
37*4882a593Smuzhiyun 		rcu_read_lock();
38*4882a593Smuzhiyun 		flags = rcu_dereference(to_skbedit(a)->params)->flags;
39*4882a593Smuzhiyun 		rcu_read_unlock();
40*4882a593Smuzhiyun 		return flags == flag;
41*4882a593Smuzhiyun 	}
42*4882a593Smuzhiyun #endif
43*4882a593Smuzhiyun 	return false;
44*4882a593Smuzhiyun }
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* Return true iff action is mark */
is_tcf_skbedit_mark(const struct tc_action * a)47*4882a593Smuzhiyun static inline bool is_tcf_skbedit_mark(const struct tc_action *a)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun 	return is_tcf_skbedit_with_flag(a, SKBEDIT_F_MARK);
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun 
tcf_skbedit_mark(const struct tc_action * a)52*4882a593Smuzhiyun static inline u32 tcf_skbedit_mark(const struct tc_action *a)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun 	u32 mark;
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	rcu_read_lock();
57*4882a593Smuzhiyun 	mark = rcu_dereference(to_skbedit(a)->params)->mark;
58*4882a593Smuzhiyun 	rcu_read_unlock();
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun 	return mark;
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* Return true iff action is ptype */
is_tcf_skbedit_ptype(const struct tc_action * a)64*4882a593Smuzhiyun static inline bool is_tcf_skbedit_ptype(const struct tc_action *a)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun 	return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PTYPE);
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun 
tcf_skbedit_ptype(const struct tc_action * a)69*4882a593Smuzhiyun static inline u32 tcf_skbedit_ptype(const struct tc_action *a)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun 	u16 ptype;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	rcu_read_lock();
74*4882a593Smuzhiyun 	ptype = rcu_dereference(to_skbedit(a)->params)->ptype;
75*4882a593Smuzhiyun 	rcu_read_unlock();
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	return ptype;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /* Return true iff action is priority */
is_tcf_skbedit_priority(const struct tc_action * a)81*4882a593Smuzhiyun static inline bool is_tcf_skbedit_priority(const struct tc_action *a)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun 	return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PRIORITY);
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun 
tcf_skbedit_priority(const struct tc_action * a)86*4882a593Smuzhiyun static inline u32 tcf_skbedit_priority(const struct tc_action *a)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun 	u32 priority;
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	rcu_read_lock();
91*4882a593Smuzhiyun 	priority = rcu_dereference(to_skbedit(a)->params)->priority;
92*4882a593Smuzhiyun 	rcu_read_unlock();
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	return priority;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun #endif /* __NET_TC_SKBEDIT_H */
98