1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * net/sched/em_u32.c U32 Ematch
5 * Authors: Thomas Graf <tgraf@suug.ch>
6 * Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
8 * Based on net/sched/cls_u32.c
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/skbuff.h>
15 #include <net/pkt_cls.h>
17 static int em_u32_match(struct sk_buff
*skb
, struct tcf_ematch
*em
,
18 struct tcf_pkt_info
*info
)
20 struct tc_u32_key
*key
= (struct tc_u32_key
*) em
->data
;
21 const unsigned char *ptr
= skb_network_header(skb
);
26 ptr
+= (info
->nexthdr
& key
->offmask
);
31 if (!tcf_valid_offset(skb
, ptr
, sizeof(u32
)))
34 return !(((*(__be32
*) ptr
) ^ key
->val
) & key
->mask
);
37 static struct tcf_ematch_ops em_u32_ops
= {
39 .datalen
= sizeof(struct tc_u32_key
),
40 .match
= em_u32_match
,
42 .link
= LIST_HEAD_INIT(em_u32_ops
.link
)
45 static int __init
init_em_u32(void)
47 return tcf_em_register(&em_u32_ops
);
50 static void __exit
exit_em_u32(void)
52 tcf_em_unregister(&em_u32_ops
);
55 MODULE_LICENSE("GPL");
57 module_init(init_em_u32
);
58 module_exit(exit_em_u32
);
60 MODULE_ALIAS_TCF_EMATCH(TCF_EM_U32
);