sch_ingress.c 3.5 KB

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