sch_ingress.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 bool ingress_cl_offload(u32 classid)
  26. {
  27. return true;
  28. }
  29. static unsigned long ingress_bind_filter(struct Qdisc *sch,
  30. unsigned long parent, u32 classid)
  31. {
  32. return ingress_get(sch, classid);
  33. }
  34. static void ingress_put(struct Qdisc *sch, unsigned long cl)
  35. {
  36. }
  37. static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
  38. {
  39. }
  40. static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
  41. unsigned long cl)
  42. {
  43. struct net_device *dev = qdisc_dev(sch);
  44. return &dev->ingress_cl_list;
  45. }
  46. static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
  47. {
  48. net_inc_ingress_queue();
  49. sch->flags |= TCQ_F_CPUSTATS;
  50. return 0;
  51. }
  52. static void ingress_destroy(struct Qdisc *sch)
  53. {
  54. struct net_device *dev = qdisc_dev(sch);
  55. tcf_destroy_chain(&dev->ingress_cl_list);
  56. net_dec_ingress_queue();
  57. }
  58. static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
  59. {
  60. struct nlattr *nest;
  61. nest = nla_nest_start(skb, TCA_OPTIONS);
  62. if (nest == NULL)
  63. goto nla_put_failure;
  64. return nla_nest_end(skb, nest);
  65. nla_put_failure:
  66. nla_nest_cancel(skb, nest);
  67. return -1;
  68. }
  69. static const struct Qdisc_class_ops ingress_class_ops = {
  70. .leaf = ingress_leaf,
  71. .get = ingress_get,
  72. .put = ingress_put,
  73. .walk = ingress_walk,
  74. .tcf_chain = ingress_find_tcf,
  75. .tcf_cl_offload = ingress_cl_offload,
  76. .bind_tcf = ingress_bind_filter,
  77. .unbind_tcf = ingress_put,
  78. };
  79. static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
  80. .cl_ops = &ingress_class_ops,
  81. .id = "ingress",
  82. .init = ingress_init,
  83. .destroy = ingress_destroy,
  84. .dump = ingress_dump,
  85. .owner = THIS_MODULE,
  86. };
  87. static unsigned long clsact_get(struct Qdisc *sch, u32 classid)
  88. {
  89. switch (TC_H_MIN(classid)) {
  90. case TC_H_MIN(TC_H_MIN_INGRESS):
  91. case TC_H_MIN(TC_H_MIN_EGRESS):
  92. return TC_H_MIN(classid);
  93. default:
  94. return 0;
  95. }
  96. }
  97. static bool clsact_cl_offload(u32 classid)
  98. {
  99. return TC_H_MIN(classid) == TC_H_MIN(TC_H_MIN_INGRESS);
  100. }
  101. static unsigned long clsact_bind_filter(struct Qdisc *sch,
  102. unsigned long parent, u32 classid)
  103. {
  104. return clsact_get(sch, classid);
  105. }
  106. static struct tcf_proto __rcu **clsact_find_tcf(struct Qdisc *sch,
  107. unsigned long cl)
  108. {
  109. struct net_device *dev = qdisc_dev(sch);
  110. switch (cl) {
  111. case TC_H_MIN(TC_H_MIN_INGRESS):
  112. return &dev->ingress_cl_list;
  113. case TC_H_MIN(TC_H_MIN_EGRESS):
  114. return &dev->egress_cl_list;
  115. default:
  116. return NULL;
  117. }
  118. }
  119. static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
  120. {
  121. net_inc_ingress_queue();
  122. net_inc_egress_queue();
  123. sch->flags |= TCQ_F_CPUSTATS;
  124. return 0;
  125. }
  126. static void clsact_destroy(struct Qdisc *sch)
  127. {
  128. struct net_device *dev = qdisc_dev(sch);
  129. tcf_destroy_chain(&dev->ingress_cl_list);
  130. tcf_destroy_chain(&dev->egress_cl_list);
  131. net_dec_ingress_queue();
  132. net_dec_egress_queue();
  133. }
  134. static const struct Qdisc_class_ops clsact_class_ops = {
  135. .leaf = ingress_leaf,
  136. .get = clsact_get,
  137. .put = ingress_put,
  138. .walk = ingress_walk,
  139. .tcf_chain = clsact_find_tcf,
  140. .tcf_cl_offload = clsact_cl_offload,
  141. .bind_tcf = clsact_bind_filter,
  142. .unbind_tcf = ingress_put,
  143. };
  144. static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
  145. .cl_ops = &clsact_class_ops,
  146. .id = "clsact",
  147. .init = clsact_init,
  148. .destroy = clsact_destroy,
  149. .dump = ingress_dump,
  150. .owner = THIS_MODULE,
  151. };
  152. static int __init ingress_module_init(void)
  153. {
  154. int ret;
  155. ret = register_qdisc(&ingress_qdisc_ops);
  156. if (!ret) {
  157. ret = register_qdisc(&clsact_qdisc_ops);
  158. if (ret)
  159. unregister_qdisc(&ingress_qdisc_ops);
  160. }
  161. return ret;
  162. }
  163. static void __exit ingress_module_exit(void)
  164. {
  165. unregister_qdisc(&ingress_qdisc_ops);
  166. unregister_qdisc(&clsact_qdisc_ops);
  167. }
  168. module_init(ingress_module_init);
  169. module_exit(ingress_module_exit);
  170. MODULE_ALIAS("sch_clsact");
  171. MODULE_LICENSE("GPL");