2 * net/sched/simp.c Simple example of an action
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.
9 * Authors: Jamal Hadi Salim (2005)
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>
22 #include <linux/socket.h>
23 #include <linux/sockios.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>
34 #include <net/pkt_sched.h>
36 #define TCA_ACT_SIMP 22
38 /* XXX: Hide all these common elements under some macro
41 #include <linux/tc_act/tc_defact.h>
42 #include <net/tc_act/tc_defact.h>
44 /* use generic hash table with 8 buckets */
46 #define MY_TAB_MASK (MY_TAB_SIZE - 1)
48 static struct tcf_defact *tcf_simp_ht[MY_TAB_SIZE];
49 static DEFINE_RWLOCK(simp_lock);
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
57 #define CONFIG_NET_ACT_INIT 1
58 #include <net/pkt_act.h>
59 #include <net/act_generic.h>
61 static int tcf_simp(struct sk_buff **pskb, struct tc_action *a)
63 struct sk_buff *skb = *pskb;
64 struct tcf_defact *p = PRIV(a, defact);
67 p->tm.lastuse = jiffies;
68 p->bstats.bytes += skb->len;
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)
75 printk("simple: %s_%d\n", (char *)p->defdata, p->bstats.packets);
76 spin_unlock(&p->lock);
80 static struct tc_action_ops act_simp_ops = {
83 .capab = TCA_CAP_NONE,
89 MODULE_AUTHOR("Jamal Hadi Salim(2005)");
90 MODULE_DESCRIPTION("Simple example action");
91 MODULE_LICENSE("GPL");
93 static int __init simp_init_module(void)
95 int ret = tcf_register_action(&act_simp_ops);
97 printk("Simple TC action Loaded\n");
101 static void __exit simp_cleanup_module(void)
103 tcf_unregister_action(&act_simp_ops);
106 module_init(simp_init_module);
107 module_exit(simp_cleanup_module);