sch_ingress.c 3.4 KB

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