2 * net/sched/em_cmp.c Simple packet data comparison ematch
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Thomas Graf <tgraf@suug.ch>
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/tc_ematch/tc_em_cmp.h>
17 #include <net/pkt_cls.h>
19 static inline int cmp_needs_transformation(struct tcf_em_cmp *cmp)
21 return unlikely(cmp->flags & TCF_EM_CMP_TRANS);
24 static int em_cmp_match(struct sk_buff *skb, struct tcf_ematch *em,
25 struct tcf_pkt_info *info)
27 struct tcf_em_cmp *cmp = (struct tcf_em_cmp *) em->data;
28 unsigned char *ptr = tcf_get_base_ptr(skb, cmp->layer) + cmp->off;
31 if (!tcf_valid_offset(skb, ptr, cmp->align))
39 case TCF_EM_ALIGN_U16:
43 if (cmp_needs_transformation(cmp))
44 val = be16_to_cpu(val);
47 case TCF_EM_ALIGN_U32:
48 /* Worth checking boundries? The branching seems
49 * to get worse. Visit again. */
51 val |= *(ptr+1) << 16;
55 if (cmp_needs_transformation(cmp))
56 val = be32_to_cpu(val);
68 return val == cmp->val;
70 return val < cmp->val;
72 return val > cmp->val;
78 static struct tcf_ematch_ops em_cmp_ops = {
80 .datalen = sizeof(struct tcf_em_cmp),
81 .match = em_cmp_match,
83 .link = LIST_HEAD_INIT(em_cmp_ops.link)
86 static int __init init_em_cmp(void)
88 return tcf_em_register(&em_cmp_ops);
91 static void __exit exit_em_cmp(void)
93 tcf_em_unregister(&em_cmp_ops);
96 MODULE_LICENSE("GPL");
98 module_init(init_em_cmp);
99 module_exit(exit_em_cmp);