xref: /openbmc/linux/include/net/tc_act/tc_pedit.h (revision e3d786a3)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NET_TC_PED_H
3 #define __NET_TC_PED_H
4 
5 #include <net/act_api.h>
6 #include <linux/tc_act/tc_pedit.h>
7 
8 struct tcf_pedit_key_ex {
9 	enum pedit_header_type htype;
10 	enum pedit_cmd cmd;
11 };
12 
13 struct tcf_pedit {
14 	struct tc_action	common;
15 	unsigned char		tcfp_nkeys;
16 	unsigned char		tcfp_flags;
17 	struct tc_pedit_key	*tcfp_keys;
18 	struct tcf_pedit_key_ex	*tcfp_keys_ex;
19 };
20 
21 #define to_pedit(a) ((struct tcf_pedit *)a)
22 
23 static inline bool is_tcf_pedit(const struct tc_action *a)
24 {
25 #ifdef CONFIG_NET_CLS_ACT
26 	if (a->ops && a->ops->type == TCA_ACT_PEDIT)
27 		return true;
28 #endif
29 	return false;
30 }
31 
32 static inline int tcf_pedit_nkeys(const struct tc_action *a)
33 {
34 	return to_pedit(a)->tcfp_nkeys;
35 }
36 
37 static inline u32 tcf_pedit_htype(const struct tc_action *a, int index)
38 {
39 	if (to_pedit(a)->tcfp_keys_ex)
40 		return to_pedit(a)->tcfp_keys_ex[index].htype;
41 
42 	return TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
43 }
44 
45 static inline u32 tcf_pedit_cmd(const struct tc_action *a, int index)
46 {
47 	if (to_pedit(a)->tcfp_keys_ex)
48 		return to_pedit(a)->tcfp_keys_ex[index].cmd;
49 
50 	return __PEDIT_CMD_MAX;
51 }
52 
53 static inline u32 tcf_pedit_mask(const struct tc_action *a, int index)
54 {
55 	return to_pedit(a)->tcfp_keys[index].mask;
56 }
57 
58 static inline u32 tcf_pedit_val(const struct tc_action *a, int index)
59 {
60 	return to_pedit(a)->tcfp_keys[index].val;
61 }
62 
63 static inline u32 tcf_pedit_offset(const struct tc_action *a, int index)
64 {
65 	return to_pedit(a)->tcfp_keys[index].off;
66 }
67 #endif /* __NET_TC_PED_H */
68