blob: 17105c82537fa2472c3bd4e33b7a0c4bdbd345fa [file] [log] [blame]
Jamal Hadi Salimdb753072005-04-24 20:10:16 -07001/*
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
David S. Millercbdbf002005-04-25 12:15:01 -070013#include <linux/module.h>
14#include <linux/init.h>
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070015#include <linux/kernel.h>
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070016#include <linux/netdevice.h>
17#include <linux/skbuff.h>
18#include <linux/rtnetlink.h>
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070019#include <net/pkt_sched.h>
20
21#define TCA_ACT_SIMP 22
22
23/* XXX: Hide all these common elements under some macro
24 * probably
25*/
26#include <linux/tc_act/tc_defact.h>
27#include <net/tc_act/tc_defact.h>
28
29/* use generic hash table with 8 buckets */
30#define MY_TAB_SIZE 8
31#define MY_TAB_MASK (MY_TAB_SIZE - 1)
32static u32 idx_gen;
33static struct tcf_defact *tcf_simp_ht[MY_TAB_SIZE];
34static DEFINE_RWLOCK(simp_lock);
35
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
41
42#define CONFIG_NET_ACT_INIT 1
43#include <net/pkt_act.h>
44#include <net/act_generic.h>
45
Patrick McHardyf43c5a02006-01-08 22:15:34 -080046static int tcf_simp(struct sk_buff *skb, struct tc_action *a, struct tcf_result *res)
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070047{
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070048 struct tcf_defact *p = PRIV(a, defact);
49
50 spin_lock(&p->lock);
51 p->tm.lastuse = jiffies;
52 p->bstats.bytes += skb->len;
53 p->bstats.packets++;
54
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)
58 **/
59 printk("simple: %s_%d\n", (char *)p->defdata, p->bstats.packets);
60 spin_unlock(&p->lock);
61 return p->action;
62}
63
64static struct tc_action_ops act_simp_ops = {
65 .kind = "simple",
66 .type = TCA_ACT_SIMP,
67 .capab = TCA_CAP_NONE,
68 .owner = THIS_MODULE,
69 .act = tcf_simp,
70 tca_use_default_ops
71};
72
73MODULE_AUTHOR("Jamal Hadi Salim(2005)");
74MODULE_DESCRIPTION("Simple example action");
75MODULE_LICENSE("GPL");
76
77static int __init simp_init_module(void)
78{
79 int ret = tcf_register_action(&act_simp_ops);
80 if (!ret)
81 printk("Simple TC action Loaded\n");
82 return ret;
83}
84
85static void __exit simp_cleanup_module(void)
86{
87 tcf_unregister_action(&act_simp_ops);
88}
89
90module_init(simp_init_module);
91module_exit(simp_cleanup_module);