sch_ingress.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* net/sched/sch_ingress.c - Ingress and clsact qdisc
  2. *
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU General Public License
  5. * as published by the Free Software Foundation; either version
  6. * 2 of the License, or (at your option) any later version.
  7. *
  8. * Authors: Jamal Hadi Salim 1999
  9. */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/list.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/rtnetlink.h>
  15. #include <net/netlink.h>
  16. #include <net/pkt_sched.h>
  17. static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
  18. {
  19. return NULL;
  20. }
  21. static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
  22. {
  23. return TC_H_MIN(classid) + 1;
  24. }
  25. static unsigned long ingress_bind_filter(struct Qdisc *sch,
  26. unsigned long parent, u32 classid)
  27. {
  28. return ingress_get(sch, classid);
  29. }
  30. static void ingress_put(struct Qdisc *sch, unsigned long cl)
  31. {
  32. }
  33. static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
  34. {
  35. }
  36. static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
  37. unsigned long cl)
  38. {
  39. struct net_device *dev = qdisc_dev(sch);
  40. return &dev->ingress_cl_list;
  41. }
  42. static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
  43. {
  44. net_inc_ingress_queue();
  45. sch->flags |= TCQ_F_CPUSTATS;
  46. return 0;
  47. }
  48. static void ingress_destroy(struct Qdisc *sch)
  49. {
  50. struct net_device *dev = qdisc_dev(sch);
  51. tcf_destroy_chain(&dev->ingress_cl_list);
  52. net_dec_ingress_queue();
  53. }
  54. static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
  55. {
  56. struct nlattr *nest;
  57. nest = nla_nest_start(skb, TCA_OPTIONS);
  58. if (nest == NULL)
  59. goto nla_put_failure;
  60. return nla_nest_end(skb, nest);
  61. nla_put_failure:
  62. nla_nest_cancel(skb, nest);
  63. return -1;
  64. }
  65. static const struct Qdisc_class_ops ingress_class_ops = {
  66. .leaf = ingress_leaf,
  67. .get = ingress_get,
  68. .put = ingress_put,
  69. .walk = ingress_walk,
  70. .tcf_chain = ingress_find_tcf,
  71. .bind_tcf = ingress_bind_filter,
  72. .unbind_tcf = ingress_put,
  73. };
  74. static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
  75. .cl_ops = &ingress_class_ops,
  76. .id = "ingress",
  77. .init = ingress_init,
  78. .destroy = ingress_destroy,
  79. .dump = ingress_dump,
  80. .owner = THIS_MODULE,
  81. };
  82. static unsigned long clsact_get(struct Qdisc *sch, u32 classid)
  83. {
  84. switch (TC_H_MIN(classid)) {
  85. case TC_H_MIN(TC_H_MIN_INGRESS):
  86. case TC_H_MIN(TC_H_MIN_EGRESS):
  87. return TC_H_MIN(classid);
  88. default:
  89. return 0;
  90. }
  91. }
  92. static unsigned long clsact_bind_filter(struct Qdisc *sch,
  93. unsigned long parent, u32 classid)
  94. {
  95. return clsact_get(sch, classid);
  96. }
  97. static struct tcf_proto __rcu **clsact_find_tcf(struct Qdisc *sch,
  98. unsigned long cl)
  99. {
  100. struct net_device *dev = qdisc_dev(sch);
  101. switch (cl) {
  102. case TC_H_MIN(TC_H_MIN_INGRESS):
  103. return &dev->ingress_cl_list;
  104. case TC_H_MIN(TC_H_MIN_EGRESS):
  105. return &dev->egress_cl_list;
  106. default:
  107. return NULL;
  108. }
  109. }
  110. static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
  111. {
  112. net_inc_ingress_queue();
  113. net_inc_egress_queue();
  114. sch->flags |= TCQ_F_CPUSTATS;
  115. return 0;
  116. }
  117. static void clsact_destroy(struct Qdisc *sch)
  118. {
  119. struct net_device *dev = qdisc_dev(sch);
  120. tcf_destroy_chain(&dev->ingress_cl_list);
  121. tcf_destroy_chain(&dev->egress_cl_list);
  122. net_dec_ingress_queue();
  123. net_dec_egress_queue();
  124. }
  125. static const struct Qdisc_class_ops clsact_class_ops = {
  126. .leaf = ingress_leaf,
  127. .get = clsact_get,
  128. .put = ingress_put,
  129. .walk = ingress_walk,
  130. .tcf_chain = clsact_find_tcf,
  131. .bind_tcf = clsact_bind_filter,
  132. .unbind_tcf = ingress_put,
  133. };
  134. static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
  135. .cl_ops = &clsact_class_ops,
  136. .id = "clsact",
  137. .init = clsact_init,
  138. .destroy = clsact_destroy,
  139. .dump = ingress_dump,
  140. .owner = THIS_MODULE,
  141. };
  142. static int __init ingress_module_init(void)
  143. {
  144. int ret;
  145. ret = register_qdisc(&ingress_qdisc_ops);
  146. if (!ret) {
  147. ret = register_qdisc(&clsact_qdisc_ops);
  148. if (ret)
  149. unregister_qdisc(&ingress_qdisc_ops);
  150. }
  151. return ret;
  152. }
  153. static void __exit ingress_module_exit(void)
  154. {
  155. unregister_qdisc(&ingress_qdisc_ops);
  156. unregister_qdisc(&clsact_qdisc_ops);
  157. }
  158. module_init(ingress_module_init);
  159. module_exit(ingress_module_exit);
  160. MODULE_ALIAS("sch_clsact");
  161. MODULE_LICENSE("GPL");