diff options
Diffstat (limited to 'net/sched/act_simple.c')
-rw-r--r-- | net/sched/act_simple.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c new file mode 100644 index 000000000000..e5f2e1f431e2 --- /dev/null +++ b/net/sched/act_simple.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | * net/sched/simp.c Simple example of an action | ||
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: Jamal Hadi Salim (2005) | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/config.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/netdevice.h> | ||
18 | #include <linux/skbuff.h> | ||
19 | #include <linux/rtnetlink.h> | ||
20 | #include <net/pkt_sched.h> | ||
21 | |||
22 | #define TCA_ACT_SIMP 22 | ||
23 | |||
24 | /* XXX: Hide all these common elements under some macro | ||
25 | * probably | ||
26 | */ | ||
27 | #include <linux/tc_act/tc_defact.h> | ||
28 | #include <net/tc_act/tc_defact.h> | ||
29 | |||
30 | /* use generic hash table with 8 buckets */ | ||
31 | #define MY_TAB_SIZE 8 | ||
32 | #define MY_TAB_MASK (MY_TAB_SIZE - 1) | ||
33 | static u32 idx_gen; | ||
34 | static struct tcf_defact *tcf_simp_ht[MY_TAB_SIZE]; | ||
35 | static DEFINE_RWLOCK(simp_lock); | ||
36 | |||
37 | /* override the defaults */ | ||
38 | #define tcf_st tcf_defact | ||
39 | #define tc_st tc_defact | ||
40 | #define tcf_t_lock simp_lock | ||
41 | #define tcf_ht tcf_simp_ht | ||
42 | |||
43 | #define CONFIG_NET_ACT_INIT 1 | ||
44 | #include <net/pkt_act.h> | ||
45 | #include <net/act_generic.h> | ||
46 | |||
47 | static int tcf_simp(struct sk_buff *skb, struct tc_action *a, struct tcf_result *res) | ||
48 | { | ||
49 | struct tcf_defact *p = PRIV(a, defact); | ||
50 | |||
51 | spin_lock(&p->lock); | ||
52 | p->tm.lastuse = jiffies; | ||
53 | p->bstats.bytes += skb->len; | ||
54 | p->bstats.packets++; | ||
55 | |||
56 | /* print policy string followed by _ then packet count | ||
57 | * Example if this was the 3rd packet and the string was "hello" | ||
58 | * then it would look like "hello_3" (without quotes) | ||
59 | **/ | ||
60 | printk("simple: %s_%d\n", (char *)p->defdata, p->bstats.packets); | ||
61 | spin_unlock(&p->lock); | ||
62 | return p->action; | ||
63 | } | ||
64 | |||
65 | static struct tc_action_ops act_simp_ops = { | ||
66 | .kind = "simple", | ||
67 | .type = TCA_ACT_SIMP, | ||
68 | .capab = TCA_CAP_NONE, | ||
69 | .owner = THIS_MODULE, | ||
70 | .act = tcf_simp, | ||
71 | tca_use_default_ops | ||
72 | }; | ||
73 | |||
74 | MODULE_AUTHOR("Jamal Hadi Salim(2005)"); | ||
75 | MODULE_DESCRIPTION("Simple example action"); | ||
76 | MODULE_LICENSE("GPL"); | ||
77 | |||
78 | static int __init simp_init_module(void) | ||
79 | { | ||
80 | int ret = tcf_register_action(&act_simp_ops); | ||
81 | if (!ret) | ||
82 | printk("Simple TC action Loaded\n"); | ||
83 | return ret; | ||
84 | } | ||
85 | |||
86 | static void __exit simp_cleanup_module(void) | ||
87 | { | ||
88 | tcf_unregister_action(&act_simp_ops); | ||
89 | } | ||
90 | |||
91 | module_init(simp_init_module); | ||
92 | module_exit(simp_cleanup_module); | ||