sch_ingress.c 3.2 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 *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 **ingress_find_tcf(struct Qdisc *sch, unsigned long cl)
  40. {
  41. struct ingress_qdisc_data *p = qdisc_priv(sch);
  42. return &p->filter_list;
  43. }
  44. /* --------------------------- Qdisc operations ---------------------------- */
  45. static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
  46. {
  47. struct ingress_qdisc_data *p = qdisc_priv(sch);
  48. struct tcf_result res;
  49. int result;
  50. result = tc_classify(skb, p->filter_list, &res);
  51. qdisc_bstats_update(sch, skb);
  52. switch (result) {
  53. case TC_ACT_SHOT:
  54. result = TC_ACT_SHOT;
  55. sch->qstats.drops++;
  56. break;
  57. case TC_ACT_STOLEN:
  58. case TC_ACT_QUEUED:
  59. result = TC_ACT_STOLEN;
  60. break;
  61. case TC_ACT_RECLASSIFY:
  62. case TC_ACT_OK:
  63. skb->tc_index = TC_H_MIN(res.classid);
  64. default:
  65. result = TC_ACT_OK;
  66. break;
  67. }
  68. return result;
  69. }
  70. /* ------------------------------------------------------------- */
  71. static void ingress_destroy(struct Qdisc *sch)
  72. {
  73. struct ingress_qdisc_data *p = qdisc_priv(sch);
  74. tcf_destroy_chain(&p->filter_list);
  75. }
  76. static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
  77. {
  78. struct nlattr *nest;
  79. nest = nla_nest_start(skb, TCA_OPTIONS);
  80. if (nest == NULL)
  81. goto nla_put_failure;
  82. nla_nest_end(skb, nest);
  83. return skb->len;
  84. nla_put_failure:
  85. nla_nest_cancel(skb, nest);
  86. return -1;
  87. }
  88. static const struct Qdisc_class_ops ingress_class_ops = {
  89. .leaf = ingress_leaf,
  90. .get = ingress_get,
  91. .put = ingress_put,
  92. .walk = ingress_walk,
  93. .tcf_chain = ingress_find_tcf,
  94. .bind_tcf = ingress_bind_filter,
  95. .unbind_tcf = ingress_put,
  96. };
  97. static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
  98. .cl_ops = &ingress_class_ops,
  99. .id = "ingress",
  100. .priv_size = sizeof(struct ingress_qdisc_data),
  101. .enqueue = ingress_enqueue,
  102. .destroy = ingress_destroy,
  103. .dump = ingress_dump,
  104. .owner = THIS_MODULE,
  105. };
  106. static int __init ingress_module_init(void)
  107. {
  108. return register_qdisc(&ingress_qdisc_ops);
  109. }
  110. static void __exit ingress_module_exit(void)
  111. {
  112. unregister_qdisc(&ingress_qdisc_ops);
  113. }
  114. module_init(ingress_module_init)
  115. module_exit(ingress_module_exit)
  116. MODULE_LICENSE("GPL");