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 <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/netdevice.h>
17 #include <linux/skbuff.h>
18 #include <linux/rtnetlink.h>
19 #include <net/pkt_sched.h>
21 #define TCA_ACT_SIMP 22
23 /* XXX: Hide all these common elements under some macro
26 #include <linux/tc_act/tc_defact.h>
27 #include <net/tc_act/tc_defact.h>
29 /* use generic hash table with 8 buckets */
31 #define MY_TAB_MASK (MY_TAB_SIZE - 1)
33 static struct tcf_defact
*tcf_simp_ht
[MY_TAB_SIZE
];
34 static DEFINE_RWLOCK(simp_lock
);
36 /* override the defaults */
37 #define tcf_st tcf_defact
38 #define tc_st tc_defact
39 #define tcf_t_lock simp_lock
40 #define tcf_ht tcf_simp_ht
42 #define CONFIG_NET_ACT_INIT 1
43 #include <net/pkt_act.h>
44 #include <net/act_generic.h>
46 static int tcf_simp(struct sk_buff
*skb
, struct tc_action
*a
, struct tcf_result
*res
)
48 struct tcf_defact
*p
= PRIV(a
, defact
);
51 p
->tm
.lastuse
= jiffies
;
52 p
->bstats
.bytes
+= skb
->len
;
55 /* print policy string followed by _ then packet count
56 * Example if this was the 3rd packet and the string was "hello"
57 * then it would look like "hello_3" (without quotes)
59 printk("simple: %s_%d\n", (char *)p
->defdata
, p
->bstats
.packets
);
60 spin_unlock(&p
->lock
);
64 static struct tc_action_ops act_simp_ops
= {
67 .capab
= TCA_CAP_NONE
,
73 MODULE_AUTHOR("Jamal Hadi Salim(2005)");
74 MODULE_DESCRIPTION("Simple example action");
75 MODULE_LICENSE("GPL");
77 static int __init
simp_init_module(void)
79 int ret
= tcf_register_action(&act_simp_ops
);
81 printk("Simple TC action Loaded\n");
85 static void __exit
simp_cleanup_module(void)
87 tcf_unregister_action(&act_simp_ops
);
90 module_init(simp_init_module
);
91 module_exit(simp_cleanup_module
);