diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/sched/em_cmp.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_cmp.c')
-rw-r--r-- | net/sched/em_cmp.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/net/sched/em_cmp.c b/net/sched/em_cmp.c new file mode 100644 index 000000000000..bf1f00f8b1bf --- /dev/null +++ b/net/sched/em_cmp.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | * net/sched/em_cmp.c Simple packet data comparison 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/skbuff.h> | ||
17 | #include <linux/tc_ematch/tc_em_cmp.h> | ||
18 | #include <net/pkt_cls.h> | ||
19 | |||
20 | static inline int cmp_needs_transformation(struct tcf_em_cmp *cmp) | ||
21 | { | ||
22 | return unlikely(cmp->flags & TCF_EM_CMP_TRANS); | ||
23 | } | ||
24 | |||
25 | static int em_cmp_match(struct sk_buff *skb, struct tcf_ematch *em, | ||
26 | struct tcf_pkt_info *info) | ||
27 | { | ||
28 | struct tcf_em_cmp *cmp = (struct tcf_em_cmp *) em->data; | ||
29 | unsigned char *ptr = tcf_get_base_ptr(skb, cmp->layer) + cmp->off; | ||
30 | u32 val = 0; | ||
31 | |||
32 | if (!tcf_valid_offset(skb, ptr, cmp->align)) | ||
33 | return 0; | ||
34 | |||
35 | switch (cmp->align) { | ||
36 | case TCF_EM_ALIGN_U8: | ||
37 | val = *ptr; | ||
38 | break; | ||
39 | |||
40 | case TCF_EM_ALIGN_U16: | ||
41 | val = *ptr << 8; | ||
42 | val |= *(ptr+1); | ||
43 | |||
44 | if (cmp_needs_transformation(cmp)) | ||
45 | val = be16_to_cpu(val); | ||
46 | break; | ||
47 | |||
48 | case TCF_EM_ALIGN_U32: | ||
49 | /* Worth checking boundries? The branching seems | ||
50 | * to get worse. Visit again. */ | ||
51 | val = *ptr << 24; | ||
52 | val |= *(ptr+1) << 16; | ||
53 | val |= *(ptr+2) << 8; | ||
54 | val |= *(ptr+3); | ||
55 | |||
56 | if (cmp_needs_transformation(cmp)) | ||
57 | val = be32_to_cpu(val); | ||
58 | break; | ||
59 | |||
60 | default: | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | if (cmp->mask) | ||
65 | val &= cmp->mask; | ||
66 | |||
67 | switch (cmp->opnd) { | ||
68 | case TCF_EM_OPND_EQ: | ||
69 | return val == cmp->val; | ||
70 | case TCF_EM_OPND_LT: | ||
71 | return val < cmp->val; | ||
72 | case TCF_EM_OPND_GT: | ||
73 | return val > cmp->val; | ||
74 | } | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | static struct tcf_ematch_ops em_cmp_ops = { | ||
80 | .kind = TCF_EM_CMP, | ||
81 | .datalen = sizeof(struct tcf_em_cmp), | ||
82 | .match = em_cmp_match, | ||
83 | .owner = THIS_MODULE, | ||
84 | .link = LIST_HEAD_INIT(em_cmp_ops.link) | ||
85 | }; | ||
86 | |||
87 | static int __init init_em_cmp(void) | ||
88 | { | ||
89 | return tcf_em_register(&em_cmp_ops); | ||
90 | } | ||
91 | |||
92 | static void __exit exit_em_cmp(void) | ||
93 | { | ||
94 | tcf_em_unregister(&em_cmp_ops); | ||
95 | } | ||
96 | |||
97 | MODULE_LICENSE("GPL"); | ||
98 | |||
99 | module_init(init_em_cmp); | ||
100 | module_exit(exit_em_cmp); | ||
101 | |||