sch_ingress.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* net/sched/sch_ingress.c - Ingress qdisc
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version
  5. * 2 of the License, or (at your option) any later version.
  6. *
  7. * Authors: Jamal Hadi Salim 1999
  8. */
  9. #include <linux/module.h>
  10. #include <linux/types.h>
  11. #include <linux/list.h>
  12. #include <linux/skbuff.h>
  13. #include <linux/rtnetlink.h>
  14. #include <net/netlink.h>
  15. #include <net/pkt_sched.h>
  16. struct ingress_qdisc_data {
  17. struct tcf_proto __rcu *filter_list;
  18. };
  19. /* ------------------------- Class/flow operations ------------------------- */
  20. static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
  21. {
  22. return NULL;
  23. }
  24. static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
  25. {
  26. return TC_H_MIN(classid) + 1;
  27. }
  28. static unsigned long ingress_bind_filter(struct Qdisc *sch,
  29. unsigned long parent, u32 classid)
  30. {
  31. return ingress_get(sch, classid);
  32. }
  33. static void ingress_put(struct Qdisc *sch, unsigned long cl)
  34. {
  35. }
  36. static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
  37. {
  38. }
  39. static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
  40. unsigned long cl)
  41. {
  42. struct ingress_qdisc_data *p = qdisc_priv(sch);
  43. return &p->filter_list;
  44. }
  45. /* --------------------------- Qdisc operations ---------------------------- */
  46. static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
  47. {
  48. struct ingress_qdisc_data *p = qdisc_priv(sch);
  49. struct tcf_result res;
  50. struct tcf_proto *fl = rcu_dereference_bh(p->filter_list);
  51. int result;
  52. result = tc_classify(skb, fl, &res);
  53. qdisc_bstats_update(sch, skb);
  54. switch (result) {
  55. case TC_ACT_SHOT:
  56. result = TC_ACT_SHOT;
  57. qdisc_qstats_drop(sch);
  58. break;
  59. case TC_ACT_STOLEN:
  60. case TC_ACT_QUEUED:
  61. result = TC_ACT_STOLEN;
  62. break;
  63. case TC_ACT_RECLASSIFY:
  64. case TC_ACT_OK:
  65. skb->tc_index = TC_H_MIN(res.classid);
  66. default:
  67. result = TC_ACT_OK;
  68. break;
  69. }
  70. return result;
  71. }
  72. /* ------------------------------------------------------------- */
  73. static void ingress_destroy(struct Qdisc *sch)
  74. {
  75. struct ingress_qdisc_data *p = qdisc_priv(sch);
  76. tcf_destroy_chain(&p->filter_list);
  77. }
  78. static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
  79. {
  80. struct nlattr *nest;
  81. nest = nla_nest_start(skb, TCA_OPTIONS);
  82. if (nest == NULL)
  83. goto nla_put_failure;
  84. return nla_nest_end(skb, nest);
  85. nla_put_failure:
  86. nla_nest_cancel(skb, nest);
  87. return -1;
  88. }
  89. static const struct Qdisc_class_ops ingress_class_ops = {
  90. .leaf = ingress_leaf,
  91. .get = ingress_get,
  92. .put = ingress_put,
  93. .walk = ingress_walk,
  94. .tcf_chain = ingress_find_tcf,
  95. .bind_tcf = ingress_bind_filter,
  96. .unbind_tcf = ingress_put,
  97. };
  98. static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
  99. .cl_ops = &ingress_class_ops,
  100. .id = "ingress",
  101. .priv_size = sizeof(struct ingress_qdisc_data),
  102. .enqueue = ingress_enqueue,
  103. .destroy = ingress_destroy,
  104. .dump = ingress_dump,
  105. .owner = THIS_MODULE,
  106. };
  107. static int __init ingress_module_init(void)
  108. {
  109. return register_qdisc(&ingress_qdisc_ops);
  110. }
  111. static void __exit ingress_module_exit(void)
  112. {
  113. unregister_qdisc(&ingress_qdisc_ops);
  114. }
  115. module_init(ingress_module_init)
  116. module_exit(ingress_module_exit)
  117. MODULE_LICENSE("GPL");