aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched/em_nbyte.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/sched/em_nbyte.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'net/sched/em_nbyte.c')
-rw-r--r--net/sched/em_nbyte.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/net/sched/em_nbyte.c b/net/sched/em_nbyte.c
new file mode 100644
index 000000000000..71ea926a9f09
--- /dev/null
+++ b/net/sched/em_nbyte.c
@@ -0,0 +1,82 @@
1/*
2 * net/sched/em_nbyte.c N-Byte 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 */
11
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>
21
22struct nbyte_data
23{
24 struct tcf_em_nbyte hdr;
25 char pattern[0];
26};
27
28static int em_nbyte_change(struct tcf_proto *tp, void *data, int data_len,
29 struct tcf_ematch *em)
30{
31 struct tcf_em_nbyte *nbyte = data;
32
33 if (data_len < sizeof(*nbyte) ||
34 data_len < (sizeof(*nbyte) + nbyte->len))
35 return -EINVAL;
36
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;
41
42 memcpy((void *) em->data, data, em->datalen);
43
44 return 0;
45}
46
47static int em_nbyte_match(struct sk_buff *skb, struct tcf_ematch *em,
48 struct tcf_pkt_info *info)
49{
50 struct nbyte_data *nbyte = (struct nbyte_data *) em->data;
51 unsigned char *ptr = tcf_get_base_ptr(skb, nbyte->hdr.layer);
52
53 ptr += nbyte->hdr.off;
54
55 if (!tcf_valid_offset(skb, ptr, nbyte->hdr.len))
56 return 0;
57
58 return !memcmp(ptr + nbyte->hdr.off, nbyte->pattern, nbyte->hdr.len);
59}
60
61static 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)
67};
68
69static int __init init_em_nbyte(void)
70{
71 return tcf_em_register(&em_nbyte_ops);
72}
73
74static void __exit exit_em_nbyte(void)
75{
76 tcf_em_unregister(&em_nbyte_ops);
77}
78
79MODULE_LICENSE("GPL");
80
81module_init(init_em_nbyte);
82module_exit(exit_em_nbyte);