aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched
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
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')
-rw-r--r--net/sched/Kconfig10
-rw-r--r--net/sched/Makefile11
-rw-r--r--net/sched/simple.c107
3 files changed, 123 insertions, 5 deletions
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index 3d1d902dd1a1..9c118baed9dc 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -506,3 +506,13 @@ config NET_CLS_POLICE
506 Say Y to support traffic policing (bandwidth limits). Needed for 506 Say Y to support traffic policing (bandwidth limits). Needed for
507 ingress and egress rate limiting. 507 ingress and egress rate limiting.
508 508
509config NET_ACT_SIMP
510 tristate "Simple action"
511 depends on NET_CLS_ACT
512 ---help---
513 You must have new iproute2 to use this feature.
514 This adds a very simple action for demonstration purposes
515 The idea is to give action authors a basic example to look at.
516 All this action will do is print on the console the configured
517 policy string followed by _ then packet count.
518
diff --git a/net/sched/Makefile b/net/sched/Makefile
index 431e55786efd..eb3fe583eba8 100644
--- a/net/sched/Makefile
+++ b/net/sched/Makefile
@@ -6,13 +6,14 @@ obj-y := sch_generic.o
6 6
7obj-$(CONFIG_NET_SCHED) += sch_api.o sch_fifo.o 7obj-$(CONFIG_NET_SCHED) += sch_api.o sch_fifo.o
8obj-$(CONFIG_NET_CLS) += cls_api.o 8obj-$(CONFIG_NET_CLS) += cls_api.o
9obj-$(CONFIG_NET_CLS_ACT) += act_api.o 9obj-$(CONFIG_NET_CLS_ACT) += act_api.o
10obj-$(CONFIG_NET_ACT_POLICE) += police.o 10obj-$(CONFIG_NET_ACT_POLICE) += police.o
11obj-$(CONFIG_NET_CLS_POLICE) += police.o 11obj-$(CONFIG_NET_CLS_POLICE) += police.o
12obj-$(CONFIG_NET_ACT_GACT) += gact.o 12obj-$(CONFIG_NET_ACT_GACT) += gact.o
13obj-$(CONFIG_NET_ACT_MIRRED) += mirred.o 13obj-$(CONFIG_NET_ACT_MIRRED) += mirred.o
14obj-$(CONFIG_NET_ACT_IPT) += ipt.o 14obj-$(CONFIG_NET_ACT_IPT) += ipt.o
15obj-$(CONFIG_NET_ACT_PEDIT) += pedit.o 15obj-$(CONFIG_NET_ACT_PEDIT) += pedit.o
16obj-$(CONFIG_NET_ACT_SIMP) += simple.o
16obj-$(CONFIG_NET_SCH_CBQ) += sch_cbq.o 17obj-$(CONFIG_NET_SCH_CBQ) += sch_cbq.o
17obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o 18obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o
18obj-$(CONFIG_NET_SCH_HPFQ) += sch_hpfq.o 19obj-$(CONFIG_NET_SCH_HPFQ) += sch_hpfq.o
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);