sch_fifo.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/config.h>
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/skbuff.h>
  18. #include <net/pkt_sched.h>
  19. /* 1 band FIFO pseudo-"scheduler" */
  20. struct fifo_sched_data
  21. {
  22. u32 limit;
  23. };
  24. static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
  25. {
  26. struct fifo_sched_data *q = qdisc_priv(sch);
  27. if (likely(sch->qstats.backlog + skb->len <= q->limit))
  28. return qdisc_enqueue_tail(skb, sch);
  29. return qdisc_reshape_fail(skb, sch);
  30. }
  31. static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
  32. {
  33. struct fifo_sched_data *q = qdisc_priv(sch);
  34. if (likely(skb_queue_len(&sch->q) < q->limit))
  35. return qdisc_enqueue_tail(skb, sch);
  36. return qdisc_reshape_fail(skb, sch);
  37. }
  38. static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
  39. {
  40. struct fifo_sched_data *q = qdisc_priv(sch);
  41. if (opt == NULL) {
  42. u32 limit = sch->dev->tx_queue_len ? : 1;
  43. if (sch->ops == &bfifo_qdisc_ops)
  44. limit *= sch->dev->mtu;
  45. q->limit = limit;
  46. } else {
  47. struct tc_fifo_qopt *ctl = RTA_DATA(opt);
  48. if (RTA_PAYLOAD(opt) < sizeof(*ctl))
  49. return -EINVAL;
  50. q->limit = ctl->limit;
  51. }
  52. return 0;
  53. }
  54. static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
  55. {
  56. struct fifo_sched_data *q = qdisc_priv(sch);
  57. struct tc_fifo_qopt opt = { .limit = q->limit };
  58. RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
  59. return skb->len;
  60. rtattr_failure:
  61. return -1;
  62. }
  63. struct Qdisc_ops pfifo_qdisc_ops = {
  64. .id = "pfifo",
  65. .priv_size = sizeof(struct fifo_sched_data),
  66. .enqueue = pfifo_enqueue,
  67. .dequeue = qdisc_dequeue_head,
  68. .requeue = qdisc_requeue,
  69. .drop = qdisc_queue_drop,
  70. .init = fifo_init,
  71. .reset = qdisc_reset_queue,
  72. .change = fifo_init,
  73. .dump = fifo_dump,
  74. .owner = THIS_MODULE,
  75. };
  76. struct Qdisc_ops bfifo_qdisc_ops = {
  77. .id = "bfifo",
  78. .priv_size = sizeof(struct fifo_sched_data),
  79. .enqueue = bfifo_enqueue,
  80. .dequeue = qdisc_dequeue_head,
  81. .requeue = qdisc_requeue,
  82. .drop = qdisc_queue_drop,
  83. .init = fifo_init,
  84. .reset = qdisc_reset_queue,
  85. .change = fifo_init,
  86. .dump = fifo_dump,
  87. .owner = THIS_MODULE,
  88. };
  89. EXPORT_SYMBOL(bfifo_qdisc_ops);
  90. EXPORT_SYMBOL(pfifo_qdisc_ops);