sch_fifo.c 2.5 KB

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