simple.c 2.6 KB

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