sch_fifo.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <asm/uaccess.h>
  14. #include <asm/system.h>
  15. #include <linux/bitops.h>
  16. #include <linux/types.h>
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/string.h>
  20. #include <linux/mm.h>
  21. #include <linux/socket.h>
  22. #include <linux/sockios.h>
  23. #include <linux/in.h>
  24. #include <linux/errno.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/if_ether.h>
  27. #include <linux/inet.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/notifier.h>
  31. #include <net/ip.h>
  32. #include <net/route.h>
  33. #include <linux/skbuff.h>
  34. #include <net/sock.h>
  35. #include <net/pkt_sched.h>
  36. /* 1 band FIFO pseudo-"scheduler" */
  37. struct fifo_sched_data
  38. {
  39. unsigned limit;
  40. };
  41. static int
  42. bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
  43. {
  44. struct fifo_sched_data *q = qdisc_priv(sch);
  45. if (likely(sch->qstats.backlog + skb->len <= q->limit))
  46. return qdisc_enqueue_tail(skb, sch);
  47. return qdisc_reshape_fail(skb, sch);
  48. }
  49. static int
  50. pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
  51. {
  52. struct fifo_sched_data *q = qdisc_priv(sch);
  53. if (likely(skb_queue_len(&sch->q) < q->limit))
  54. return qdisc_enqueue_tail(skb, sch);
  55. return qdisc_reshape_fail(skb, sch);
  56. }
  57. static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
  58. {
  59. struct fifo_sched_data *q = qdisc_priv(sch);
  60. if (opt == NULL) {
  61. unsigned int limit = sch->dev->tx_queue_len ? : 1;
  62. if (sch->ops == &bfifo_qdisc_ops)
  63. q->limit = limit*sch->dev->mtu;
  64. else
  65. q->limit = limit;
  66. } else {
  67. struct tc_fifo_qopt *ctl = RTA_DATA(opt);
  68. if (opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
  69. return -EINVAL;
  70. q->limit = ctl->limit;
  71. }
  72. return 0;
  73. }
  74. static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
  75. {
  76. struct fifo_sched_data *q = qdisc_priv(sch);
  77. unsigned char *b = skb->tail;
  78. struct tc_fifo_qopt opt;
  79. opt.limit = q->limit;
  80. RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
  81. return skb->len;
  82. rtattr_failure:
  83. skb_trim(skb, b - skb->data);
  84. return -1;
  85. }
  86. struct Qdisc_ops pfifo_qdisc_ops = {
  87. .next = NULL,
  88. .cl_ops = NULL,
  89. .id = "pfifo",
  90. .priv_size = sizeof(struct fifo_sched_data),
  91. .enqueue = pfifo_enqueue,
  92. .dequeue = qdisc_dequeue_head,
  93. .requeue = qdisc_requeue,
  94. .drop = qdisc_queue_drop,
  95. .init = fifo_init,
  96. .reset = qdisc_reset_queue,
  97. .destroy = NULL,
  98. .change = fifo_init,
  99. .dump = fifo_dump,
  100. .owner = THIS_MODULE,
  101. };
  102. struct Qdisc_ops bfifo_qdisc_ops = {
  103. .next = NULL,
  104. .cl_ops = NULL,
  105. .id = "bfifo",
  106. .priv_size = sizeof(struct fifo_sched_data),
  107. .enqueue = bfifo_enqueue,
  108. .dequeue = qdisc_dequeue_head,
  109. .requeue = qdisc_requeue,
  110. .drop = qdisc_queue_drop,
  111. .init = fifo_init,
  112. .reset = qdisc_reset_queue,
  113. .destroy = NULL,
  114. .change = fifo_init,
  115. .dump = fifo_dump,
  116. .owner = THIS_MODULE,
  117. };
  118. EXPORT_SYMBOL(bfifo_qdisc_ops);
  119. EXPORT_SYMBOL(pfifo_qdisc_ops);