blob: 3ab4c675ab5dad934834cd50ffbabc5192d0ec0b [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
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070013#include <linux/config.h>
David S. Millercbdbf002005-04-25 12:15:01 -070014#include <linux/module.h>
15#include <linux/init.h>
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070016#include <linux/kernel.h>
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070017#include <linux/netdevice.h>
18#include <linux/skbuff.h>
19#include <linux/rtnetlink.h>
Jamal Hadi Salimdb753072005-04-24 20:10:16 -070020#include <net/pkt_sched.h>
21
22#define TCA_ACT_SIMP 22
23
24/* XXX: Hide all these common elements under some macro
25 * probably
26*/
27#include <linux/tc_act/tc_defact.h>
28#include <net/tc_act/tc_defact.h>
29
30/* use generic hash table with 8 buckets */
31#define MY_TAB_SIZE 8
32#define MY_TAB_MASK (MY_TAB_SIZE - 1)
33static u32 idx_gen;
34static struct tcf_defact *tcf_simp_ht[MY_TAB_SIZE];
35static DEFINE_RWLOCK(simp_lock);
36
37/* override the defaults */
38#define tcf_st tcf_defact
39#define tc_st tc_defact
40#define tcf_t_lock simp_lock
41#define tcf_ht tcf_simp_ht
42
43#define CONFIG_NET_ACT_INIT 1
44#include <net/pkt_act.h>
45#include <net/act_generic.h>
46
47static int tcf_simp(struct sk_buff **pskb, struct tc_action *a)
48{
49 struct sk_buff *skb = *pskb;
50 struct tcf_defact *p = PRIV(a, defact);
51
52 spin_lock(&p->lock);
53 p->tm.lastuse = jiffies;
54 p->bstats.bytes += skb->len;
55 p->bstats.packets++;
56
57 /* print policy string followed by _ then packet count
58 * Example if this was the 3rd packet and the string was "hello"
59 * then it would look like "hello_3" (without quotes)
60 **/
61 printk("simple: %s_%d\n", (char *)p->defdata, p->bstats.packets);
62 spin_unlock(&p->lock);
63 return p->action;
64}
65
66static struct tc_action_ops act_simp_ops = {
67 .kind = "simple",
68 .type = TCA_ACT_SIMP,
69 .capab = TCA_CAP_NONE,
70 .owner = THIS_MODULE,
71 .act = tcf_simp,
72 tca_use_default_ops
73};
74
75MODULE_AUTHOR("Jamal Hadi Salim(2005)");
76MODULE_DESCRIPTION("Simple example action");
77MODULE_LICENSE("GPL");
78
79static int __init simp_init_module(void)
80{
81 int ret = tcf_register_action(&act_simp_ops);
82 if (!ret)
83 printk("Simple TC action Loaded\n");
84 return ret;
85}
86
87static void __exit simp_cleanup_module(void)
88{
89 tcf_unregister_action(&act_simp_ops);
90}
91
92module_init(simp_init_module);
93module_exit(simp_cleanup_module);