19 #include <netlink-private/netlink.h> 20 #include <netlink-private/tc.h> 21 #include <netlink/netlink.h> 22 #include <netlink/route/cls/ematch.h> 23 #include <netlink/route/cls/ematch/cmp.h> 24 #include <linux/tc_ematch/tc_em_cmp.h> 26 void rtnl_ematch_cmp_set(
struct rtnl_ematch *e,
struct tcf_em_cmp *cfg)
28 memcpy(rtnl_ematch_data(e), cfg,
sizeof(*cfg));
31 struct tcf_em_cmp *rtnl_ematch_cmp_get(
struct rtnl_ematch *e)
33 return rtnl_ematch_data(e);
36 static int cmp_parse(
struct rtnl_ematch *e,
void *data,
size_t len)
38 memcpy(rtnl_ematch_data(e), data, len);
43 static const char *align_txt[] = {
44 [TCF_EM_ALIGN_U8] =
"u8",
45 [TCF_EM_ALIGN_U16] =
"u16",
46 [TCF_EM_ALIGN_U32] =
"u32" 49 static const char *layer_txt[] = {
50 [TCF_LAYER_LINK] =
"eth",
51 [TCF_LAYER_NETWORK] =
"ip",
52 [TCF_LAYER_TRANSPORT] =
"tcp" 55 static const char *operand_txt[] = {
56 [TCF_EM_OPND_EQ] =
"=",
57 [TCF_EM_OPND_LT] =
"<",
58 [TCF_EM_OPND_GT] =
">",
61 static void cmp_dump(
struct rtnl_ematch *e,
struct nl_dump_params *p)
63 struct tcf_em_cmp *cmp = rtnl_ematch_data(e);
65 if (cmp->flags & TCF_EM_CMP_TRANS)
66 nl_dump(p,
"ntoh%c(", (cmp->align == TCF_EM_ALIGN_U32) ?
'l' :
's');
69 align_txt[cmp->align], layer_txt[cmp->layer], cmp->off);
72 nl_dump(p,
" & 0x%x", cmp->mask);
74 if (cmp->flags & TCF_EM_CMP_TRANS)
77 nl_dump(p,
" %s %u", operand_txt[cmp->opnd], cmp->val);
81 .eo_kind = TCF_EM_CMP,
83 .eo_minlen =
sizeof(
struct tcf_em_cmp),
84 .eo_datalen =
sizeof(
struct tcf_em_cmp),
85 .eo_parse = cmp_parse,
89 static void __init cmp_init(
void)
int rtnl_ematch_register(struct rtnl_ematch_ops *ops)
Register ematch module.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Extended Match Operations.