blob: 34e7e51e601e0f3e4baec3e5e1dba4ec1a0e8841 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * net/sched/em_u32.c U32 Ematch
3 *
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.
8 *
9 * Authors: Thomas Graf <tgraf@suug.ch>
10 * Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11 *
12 * Based on net/sched/cls_u32.c
13 */
14
15#include <linux/config.h>
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/skbuff.h>
20#include <net/pkt_cls.h>
21
22static int em_u32_match(struct sk_buff *skb, struct tcf_ematch *em,
23 struct tcf_pkt_info *info)
24{
25 struct tc_u32_key *key = (struct tc_u32_key *) em->data;
26 unsigned char *ptr = skb->nh.raw;
27
28 if (info) {
29 if (info->ptr)
30 ptr = info->ptr;
31 ptr += (info->nexthdr & key->offmask);
32 }
33
34 ptr += key->off;
35
36 if (!tcf_valid_offset(skb, ptr, sizeof(u32)))
37 return 0;
38
39 return !(((*(u32*) ptr) ^ key->val) & key->mask);
40}
41
42static struct tcf_ematch_ops em_u32_ops = {
43 .kind = TCF_EM_U32,
44 .datalen = sizeof(struct tc_u32_key),
45 .match = em_u32_match,
46 .owner = THIS_MODULE,
47 .link = LIST_HEAD_INIT(em_u32_ops.link)
48};
49
50static int __init init_em_u32(void)
51{
52 return tcf_em_register(&em_u32_ops);
53}
54
55static void __exit exit_em_u32(void)
56{
57 tcf_em_unregister(&em_u32_ops);
58}
59
60MODULE_LICENSE("GPL");
61
62module_init(init_em_u32);
63module_exit(exit_em_u32);