aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched/simple.c
diff options
context:
space:
mode:
authorJamal Hadi Salim <hadi@cyberus.ca>2005-04-24 23:10:16 -0400
committerDavid S. Miller <davem@davemloft.net>2005-04-24 23:10:16 -0400
commitdb7530797992bb2be703f9f3cc69b1a578f812f8 (patch)
tree741ca281d2acb1f5a62df20ccda4ad294b57347b /net/sched/simple.c
parentac6910e189471e6b46ecea59e7620b083329ad4f (diff)
[PKT_SCHED]: Introduce simple actions.
And provide an example simply action in order to demonstrate usage. Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sched/simple.c')
-rw-r--r--net/sched/simple.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/net/sched/simple.c b/net/sched/simple.c
new file mode 100644
index 000000000000..b0d3d15848ad
--- /dev/null
+++ b/net/sched/simple.c
@@ -0,0 +1,107 @@
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 <asm/uaccess.h>
14#include <asm/system.h>
15#include <asm/bitops.h>
16#include <linux/config.h>
17#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/sched.h>
20#include <linux/string.h>
21#include <linux/mm.h>
22#include <linux/socket.h>
23#include <linux/sockios.h>
24#include <linux/in.h>
25#include <linux/errno.h>
26#include <linux/interrupt.h>
27#include <linux/netdevice.h>
28#include <linux/skbuff.h>
29#include <linux/rtnetlink.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/proc_fs.h>
33#include <net/sock.h>
34#include <net/pkt_sched.h>
35
36#define TCA_ACT_SIMP 22
37
38/* XXX: Hide all these common elements under some macro
39 * probably
40*/
41#include <linux/tc_act/tc_defact.h>
42#include <net/tc_act/tc_defact.h>
43
44/* use generic hash table with 8 buckets */
45#define MY_TAB_SIZE 8
46#define MY_TAB_MASK (MY_TAB_SIZE - 1)
47static u32 idx_gen;
48static struct tcf_defact *tcf_simp_ht[MY_TAB_SIZE];
49static DEFINE_RWLOCK(simp_lock);
50
51/* override the defaults */
52#define tcf_st tcf_defact
53#define tc_st tc_defact
54#define tcf_t_lock simp_lock
55#define tcf_ht tcf_simp_ht
56
57#define CONFIG_NET_ACT_INIT 1
58#include <net/pkt_act.h>
59#include <net/act_generic.h>
60
61static int tcf_simp(struct sk_buff **pskb, struct tc_action *a)
62{
63 struct sk_buff *skb = *pskb;
64 struct tcf_defact *p = PRIV(a, defact);
65
66 spin_lock(&p->lock);
67 p->tm.lastuse = jiffies;
68 p->bstats.bytes += skb->len;
69 p->bstats.packets++;
70
71 /* print policy string followed by _ then packet count
72 * Example if this was the 3rd packet and the string was "hello"
73 * then it would look like "hello_3" (without quotes)
74 **/
75 printk("simple: %s_%d\n", (char *)p->defdata, p->bstats.packets);
76 spin_unlock(&p->lock);
77 return p->action;
78}
79
80static struct tc_action_ops act_simp_ops = {
81 .kind = "simple",
82 .type = TCA_ACT_SIMP,
83 .capab = TCA_CAP_NONE,
84 .owner = THIS_MODULE,
85 .act = tcf_simp,
86 tca_use_default_ops
87};
88
89MODULE_AUTHOR("Jamal Hadi Salim(2005)");
90MODULE_DESCRIPTION("Simple example action");
91MODULE_LICENSE("GPL");
92
93static int __init simp_init_module(void)
94{
95 int ret = tcf_register_action(&act_simp_ops);
96 if (!ret)
97 printk("Simple TC action Loaded\n");
98 return ret;
99}
100
101static void __exit simp_cleanup_module(void)
102{
103 tcf_unregister_action(&act_simp_ops);
104}
105
106module_init(simp_init_module);
107module_exit(simp_cleanup_module);