sch_ingress.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. return;
  39. }
  40. static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, 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. int result;
  51. result = tc_classify(skb, p->filter_list, &res);
  52. sch->bstats.packets++;
  53. sch->bstats.bytes += qdisc_pkt_len(skb);
  54. switch (result) {
  55. case TC_ACT_SHOT:
  56. result = TC_ACT_SHOT;
  57. sch->qstats.drops++;
  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. nla_nest_end(skb, nest);
  85. return skb->len;
  86. nla_put_failure:
  87. nla_nest_cancel(skb, nest);
  88. return -1;
  89. }
  90. static const struct Qdisc_class_ops ingress_class_ops = {
  91. .leaf = ingress_leaf,
  92. .get = ingress_get,
  93. .put = ingress_put,
  94. .walk = ingress_walk,
  95. .tcf_chain = ingress_find_tcf,
  96. .bind_tcf = ingress_bind_filter,
  97. .unbind_tcf = ingress_put,
  98. };
  99. static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
  100. .cl_ops = &ingress_class_ops,
  101. .id = "ingress",
  102. .priv_size = sizeof(struct ingress_qdisc_data),
  103. .enqueue = ingress_enqueue,
  104. .destroy = ingress_destroy,
  105. .dump = ingress_dump,
  106. .owner = THIS_MODULE,
  107. };
  108. static int __init ingress_module_init(void)
  109. {
  110. return register_qdisc(&ingress_qdisc_ops);
  111. }
  112. static void __exit ingress_module_exit(void)
  113. {
  114. unregister_qdisc(&ingress_qdisc_ops);
  115. }
  116. module_init(ingress_module_init)
  117. module_exit(ingress_module_exit)
  118. MODULE_LICENSE("GPL");