tc_pedit.h 1.5 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
L
Linus Torvalds 已提交
2 3 4 5
#ifndef __NET_TC_PED_H
#define __NET_TC_PED_H

#include <net/act_api.h>
6
#include <linux/tc_act/tc_pedit.h>
L
Linus Torvalds 已提交
7

8 9
struct tcf_pedit_key_ex {
	enum pedit_header_type htype;
10
	enum pedit_cmd cmd;
11 12
};

13
struct tcf_pedit {
14
	struct tc_action	common;
15 16 17
	unsigned char		tcfp_nkeys;
	unsigned char		tcfp_flags;
	struct tc_pedit_key	*tcfp_keys;
18
	struct tcf_pedit_key_ex	*tcfp_keys_ex;
L
Linus Torvalds 已提交
19
};
20

21
#define to_pedit(a) ((struct tcf_pedit *)a)
L
Linus Torvalds 已提交
22

23 24 25
static inline bool is_tcf_pedit(const struct tc_action *a)
{
#ifdef CONFIG_NET_CLS_ACT
26
	if (a->ops && a->ops->id == TCA_ID_PEDIT)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
		return true;
#endif
	return false;
}

static inline int tcf_pedit_nkeys(const struct tc_action *a)
{
	return to_pedit(a)->tcfp_nkeys;
}

static inline u32 tcf_pedit_htype(const struct tc_action *a, int index)
{
	if (to_pedit(a)->tcfp_keys_ex)
		return to_pedit(a)->tcfp_keys_ex[index].htype;

	return TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
}

static inline u32 tcf_pedit_cmd(const struct tc_action *a, int index)
{
	if (to_pedit(a)->tcfp_keys_ex)
		return to_pedit(a)->tcfp_keys_ex[index].cmd;

	return __PEDIT_CMD_MAX;
}

static inline u32 tcf_pedit_mask(const struct tc_action *a, int index)
{
	return to_pedit(a)->tcfp_keys[index].mask;
}

static inline u32 tcf_pedit_val(const struct tc_action *a, int index)
{
	return to_pedit(a)->tcfp_keys[index].val;
}

static inline u32 tcf_pedit_offset(const struct tc_action *a, int index)
{
	return to_pedit(a)->tcfp_keys[index].off;
}
67
#endif /* __NET_TC_PED_H */