Import 2.1.99pre2
[davej-history.git] / net / sched / sch_fifo.c
blob14bc8bb8bfd710e8aef5ff453c2f3359d7831877
1 /*
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 <asm/uaccess.h>
14 #include <asm/system.h>
15 #include <asm/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>
37 /* 1 band FIFO pseudo-"scheduler" */
39 struct fifo_sched_data
41 unsigned limit;
44 static int
45 bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
47 struct fifo_sched_data *q = (struct fifo_sched_data *)sch->data;
49 if (sch->stats.backlog <= q->limit) {
50 __skb_queue_tail(&sch->q, skb);
51 sch->stats.backlog += skb->len;
52 sch->stats.bytes += skb->len;
53 sch->stats.packets++;
54 return 1;
56 sch->stats.drops++;
57 #ifdef CONFIG_NET_CLS_POLICE
58 if (sch->reshape_fail==NULL || sch->reshape_fail(skb, sch))
59 #endif
60 kfree_skb(skb);
61 return 0;
64 static int
65 bfifo_requeue(struct sk_buff *skb, struct Qdisc* sch)
67 __skb_queue_head(&sch->q, skb);
68 sch->stats.backlog += skb->len;
69 return 1;
72 static struct sk_buff *
73 bfifo_dequeue(struct Qdisc* sch)
75 struct sk_buff *skb;
77 skb = __skb_dequeue(&sch->q);
78 if (skb)
79 sch->stats.backlog -= skb->len;
80 return skb;
83 static int
84 fifo_drop(struct Qdisc* sch)
86 struct sk_buff *skb;
88 skb = __skb_dequeue_tail(&sch->q);
89 if (skb) {
90 sch->stats.backlog -= skb->len;
91 kfree_skb(skb);
92 return 1;
94 return 0;
97 static void
98 fifo_reset(struct Qdisc* sch)
100 struct sk_buff *skb;
102 while ((skb=__skb_dequeue(&sch->q)) != NULL)
103 kfree_skb(skb);
104 sch->stats.backlog = 0;
107 static int
108 pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
110 struct fifo_sched_data *q = (struct fifo_sched_data *)sch->data;
112 if (sch->q.qlen <= q->limit) {
113 __skb_queue_tail(&sch->q, skb);
114 sch->stats.bytes += skb->len;
115 sch->stats.packets++;
116 return 1;
118 sch->stats.drops++;
119 #ifdef CONFIG_NET_CLS_POLICE
120 if (sch->reshape_fail==NULL || sch->reshape_fail(skb, sch))
121 #endif
122 kfree_skb(skb);
123 return 0;
126 static int
127 pfifo_requeue(struct sk_buff *skb, struct Qdisc* sch)
129 __skb_queue_head(&sch->q, skb);
130 return 1;
134 static struct sk_buff *
135 pfifo_dequeue(struct Qdisc* sch)
137 return __skb_dequeue(&sch->q);
141 static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
143 struct fifo_sched_data *q = (void*)sch->data;
145 if (opt == NULL) {
146 q->limit = sch->dev->tx_queue_len;
147 if (sch->ops == &bfifo_qdisc_ops)
148 q->limit *= sch->dev->mtu;
149 } else {
150 struct tc_fifo_qopt *ctl = RTA_DATA(opt);
151 if (opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
152 return -EINVAL;
153 q->limit = ctl->limit;
155 return 0;
158 #ifdef CONFIG_RTNETLINK
159 static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
161 struct fifo_sched_data *q = (void*)sch->data;
162 unsigned char *b = skb->tail;
163 struct tc_fifo_qopt opt;
165 opt.limit = q->limit;
166 RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
168 return skb->len;
170 rtattr_failure:
171 skb_trim(skb, b - skb->data);
172 return -1;
174 #endif
176 struct Qdisc_ops pfifo_qdisc_ops =
178 NULL,
179 NULL,
180 "pfifo",
181 sizeof(struct fifo_sched_data),
183 pfifo_enqueue,
184 pfifo_dequeue,
185 pfifo_requeue,
186 fifo_drop,
188 fifo_init,
189 fifo_reset,
190 NULL,
191 #ifdef CONFIG_RTNETLINK
192 fifo_dump,
193 #endif
196 struct Qdisc_ops bfifo_qdisc_ops =
198 NULL,
199 NULL,
200 "bfifo",
201 sizeof(struct fifo_sched_data),
203 bfifo_enqueue,
204 bfifo_dequeue,
205 bfifo_requeue,
206 fifo_drop,
208 fifo_init,
209 fifo_reset,
210 NULL,
211 #ifdef CONFIG_RTNETLINK
212 fifo_dump,
213 #endif