2 * net/sched/sch_fifo.c The simplest FIFO queue.
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.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <asm/uaccess.h>
15 #include <asm/system.h>
16 #include <linux/bitops.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/string.h>
22 #include <linux/socket.h>
23 #include <linux/sockios.h>
25 #include <linux/errno.h>
26 #include <linux/interrupt.h>
27 #include <linux/if_ether.h>
28 #include <linux/inet.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/notifier.h>
33 #include <net/route.h>
34 #include <linux/skbuff.h>
36 #include <net/pkt_sched.h>
38 /* 1 band FIFO pseudo-"scheduler" */
40 struct fifo_sched_data
46 bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
48 struct fifo_sched_data *q = qdisc_priv(sch);
50 if (sch->qstats.backlog + skb->len <= q->limit) {
51 __skb_queue_tail(&sch->q, skb);
52 sch->qstats.backlog += skb->len;
53 sch->bstats.bytes += skb->len;
54 sch->bstats.packets++;
58 #ifdef CONFIG_NET_CLS_POLICE
59 if (sch->reshape_fail==NULL || sch->reshape_fail(skb, sch))
66 bfifo_requeue(struct sk_buff *skb, struct Qdisc* sch)
68 __skb_queue_head(&sch->q, skb);
69 sch->qstats.backlog += skb->len;
70 sch->qstats.requeues++;
74 static struct sk_buff *
75 bfifo_dequeue(struct Qdisc* sch)
79 skb = __skb_dequeue(&sch->q);
81 sch->qstats.backlog -= skb->len;
86 fifo_drop(struct Qdisc* sch)
90 skb = __skb_dequeue_tail(&sch->q);
92 unsigned int len = skb->len;
93 sch->qstats.backlog -= len;
101 fifo_reset(struct Qdisc* sch)
103 skb_queue_purge(&sch->q);
104 sch->qstats.backlog = 0;
108 pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
110 struct fifo_sched_data *q = qdisc_priv(sch);
112 if (sch->q.qlen < q->limit) {
113 __skb_queue_tail(&sch->q, skb);
114 sch->bstats.bytes += skb->len;
115 sch->bstats.packets++;
119 #ifdef CONFIG_NET_CLS_POLICE
120 if (sch->reshape_fail==NULL || sch->reshape_fail(skb, sch))
123 return NET_XMIT_DROP;
127 pfifo_requeue(struct sk_buff *skb, struct Qdisc* sch)
129 __skb_queue_head(&sch->q, skb);
130 sch->qstats.requeues++;
135 static struct sk_buff *
136 pfifo_dequeue(struct Qdisc* sch)
138 return __skb_dequeue(&sch->q);
141 static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
143 struct fifo_sched_data *q = qdisc_priv(sch);
146 unsigned int limit = sch->dev->tx_queue_len ? : 1;
148 if (sch->ops == &bfifo_qdisc_ops)
149 q->limit = limit*sch->dev->mtu;
153 struct tc_fifo_qopt *ctl = RTA_DATA(opt);
154 if (opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
156 q->limit = ctl->limit;
161 static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
163 struct fifo_sched_data *q = qdisc_priv(sch);
164 unsigned char *b = skb->tail;
165 struct tc_fifo_qopt opt;
167 opt.limit = q->limit;
168 RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
173 skb_trim(skb, b - skb->data);
177 struct Qdisc_ops pfifo_qdisc_ops = {
181 .priv_size = sizeof(struct fifo_sched_data),
182 .enqueue = pfifo_enqueue,
183 .dequeue = pfifo_dequeue,
184 .requeue = pfifo_requeue,
191 .owner = THIS_MODULE,
194 struct Qdisc_ops bfifo_qdisc_ops = {
198 .priv_size = sizeof(struct fifo_sched_data),
199 .enqueue = bfifo_enqueue,
200 .dequeue = bfifo_dequeue,
201 .requeue = bfifo_requeue,
208 .owner = THIS_MODULE,
211 EXPORT_SYMBOL(bfifo_qdisc_ops);
212 EXPORT_SYMBOL(pfifo_qdisc_ops);