0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/module.h>
0012 #include <linux/types.h>
0013 #include <linux/kernel.h>
0014 #include <linux/skbuff.h>
0015 #include <net/pkt_cls.h>
0016
0017 static int em_u32_match(struct sk_buff *skb, struct tcf_ematch *em,
0018 struct tcf_pkt_info *info)
0019 {
0020 struct tc_u32_key *key = (struct tc_u32_key *) em->data;
0021 const unsigned char *ptr = skb_network_header(skb);
0022
0023 if (info) {
0024 if (info->ptr)
0025 ptr = info->ptr;
0026 ptr += (info->nexthdr & key->offmask);
0027 }
0028
0029 ptr += key->off;
0030
0031 if (!tcf_valid_offset(skb, ptr, sizeof(u32)))
0032 return 0;
0033
0034 return !(((*(__be32 *) ptr) ^ key->val) & key->mask);
0035 }
0036
0037 static struct tcf_ematch_ops em_u32_ops = {
0038 .kind = TCF_EM_U32,
0039 .datalen = sizeof(struct tc_u32_key),
0040 .match = em_u32_match,
0041 .owner = THIS_MODULE,
0042 .link = LIST_HEAD_INIT(em_u32_ops.link)
0043 };
0044
0045 static int __init init_em_u32(void)
0046 {
0047 return tcf_em_register(&em_u32_ops);
0048 }
0049
0050 static void __exit exit_em_u32(void)
0051 {
0052 tcf_em_unregister(&em_u32_ops);
0053 }
0054
0055 MODULE_LICENSE("GPL");
0056
0057 module_init(init_em_u32);
0058 module_exit(exit_em_u32);
0059
0060 MODULE_ALIAS_TCF_EMATCH(TCF_EM_U32);