Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / sched / em_nbyte.c
blob71ea926a9f092fcce116144a94ea24d6eef76244
1 /*
2 * net/sched/em_nbyte.c N-Byte 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/config.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/string.h>
18 #include <linux/skbuff.h>
19 #include <linux/tc_ematch/tc_em_nbyte.h>
20 #include <net/pkt_cls.h>
22 struct nbyte_data
24 struct tcf_em_nbyte hdr;
25 char pattern[0];
28 static int em_nbyte_change(struct tcf_proto *tp, void *data, int data_len,
29 struct tcf_ematch *em)
31 struct tcf_em_nbyte *nbyte = data;
33 if (data_len < sizeof(*nbyte) ||
34 data_len < (sizeof(*nbyte) + nbyte->len))
35 return -EINVAL;
37 em->datalen = sizeof(*nbyte) + nbyte->len;
38 em->data = (unsigned long) kmalloc(em->datalen, GFP_KERNEL);
39 if (em->data == 0UL)
40 return -ENOBUFS;
42 memcpy((void *) em->data, data, em->datalen);
44 return 0;
47 static int em_nbyte_match(struct sk_buff *skb, struct tcf_ematch *em,
48 struct tcf_pkt_info *info)
50 struct nbyte_data *nbyte = (struct nbyte_data *) em->data;
51 unsigned char *ptr = tcf_get_base_ptr(skb, nbyte->hdr.layer);
53 ptr += nbyte->hdr.off;
55 if (!tcf_valid_offset(skb, ptr, nbyte->hdr.len))
56 return 0;
58 return !memcmp(ptr + nbyte->hdr.off, nbyte->pattern, nbyte->hdr.len);
61 static struct tcf_ematch_ops em_nbyte_ops = {
62 .kind = TCF_EM_NBYTE,
63 .change = em_nbyte_change,
64 .match = em_nbyte_match,
65 .owner = THIS_MODULE,
66 .link = LIST_HEAD_INIT(em_nbyte_ops.link)
69 static int __init init_em_nbyte(void)
71 return tcf_em_register(&em_nbyte_ops);
74 static void __exit exit_em_nbyte(void)
76 tcf_em_unregister(&em_nbyte_ops);
79 MODULE_LICENSE("GPL");
81 module_init(init_em_nbyte);
82 module_exit(exit_em_nbyte);