sch_fifo.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * net/sched/sch_fifo.c The simplest FIFO queue.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/skbuff.h>
  16. #include <net/pkt_sched.h>
  17. /* 1 band FIFO pseudo-"scheduler" */
  18. struct fifo_sched_data
  19. {
  20. u32 limit;
  21. };
  22. static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
  23. {
  24. struct fifo_sched_data *q = qdisc_priv(sch);
  25. if (likely(sch->qstats.backlog + skb->len <= q->limit))
  26. return qdisc_enqueue_tail(skb, sch);
  27. return qdisc_reshape_fail(skb, sch);
  28. }
  29. static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
  30. {
  31. struct fifo_sched_data *q = qdisc_priv(sch);
  32. if (likely(skb_queue_len(&sch->q) < q->limit))
  33. return qdisc_enqueue_tail(skb, sch);
  34. return qdisc_reshape_fail(skb, sch);
  35. }
  36. static int fifo_init(struct Qdisc *sch, struct nlattr *opt)
  37. {
  38. struct fifo_sched_data *q = qdisc_priv(sch);
  39. if (opt == NULL) {
  40. u32 limit = sch->dev->tx_queue_len ? : 1;
  41. if (sch->ops == &bfifo_qdisc_ops)
  42. limit *= sch->dev->mtu;
  43. q->limit = limit;
  44. } else {
  45. struct tc_fifo_qopt *ctl = nla_data(opt);
  46. if (nla_len(opt) < sizeof(*ctl))
  47. return -EINVAL;
  48. q->limit = ctl->limit;
  49. }
  50. return 0;
  51. }
  52. static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
  53. {
  54. struct fifo_sched_data *q = qdisc_priv(sch);
  55. struct tc_fifo_qopt opt = { .limit = q->limit };
  56. NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
  57. return skb->len;
  58. nla_put_failure:
  59. return -1;
  60. }
  61. struct Qdisc_ops pfifo_qdisc_ops __read_mostly = {
  62. .id = "pfifo",
  63. .priv_size = sizeof(struct fifo_sched_data),
  64. .enqueue = pfifo_enqueue,
  65. .dequeue = qdisc_dequeue_head,
  66. .requeue = qdisc_requeue,
  67. .drop = qdisc_queue_drop,
  68. .init = fifo_init,
  69. .reset = qdisc_reset_queue,
  70. .change = fifo_init,
  71. .dump = fifo_dump,
  72. .owner = THIS_MODULE,
  73. };
  74. EXPORT_SYMBOL(pfifo_qdisc_ops);
  75. struct Qdisc_ops bfifo_qdisc_ops __read_mostly = {
  76. .id = "bfifo",
  77. .priv_size = sizeof(struct fifo_sched_data),
  78. .enqueue = bfifo_enqueue,
  79. .dequeue = qdisc_dequeue_head,
  80. .requeue = qdisc_requeue,
  81. .drop = qdisc_queue_drop,
  82. .init = fifo_init,
  83. .reset = qdisc_reset_queue,
  84. .change = fifo_init,
  85. .dump = fifo_dump,
  86. .owner = THIS_MODULE,
  87. };
  88. EXPORT_SYMBOL(bfifo_qdisc_ops);