diff options
Diffstat (limited to 'net/sched/sch_fifo.c')
-rw-r--r-- | net/sched/sch_fifo.c | 152 |
1 files changed, 26 insertions, 126 deletions
diff --git a/net/sched/sch_fifo.c b/net/sched/sch_fifo.c index 4888305c96da..033083bf0e74 100644 --- a/net/sched/sch_fifo.c +++ b/net/sched/sch_fifo.c | |||
@@ -11,131 +11,38 @@ | |||
11 | 11 | ||
12 | #include <linux/config.h> | 12 | #include <linux/config.h> |
13 | #include <linux/module.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> | 14 | #include <linux/types.h> |
18 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
19 | #include <linux/sched.h> | ||
20 | #include <linux/string.h> | ||
21 | #include <linux/mm.h> | ||
22 | #include <linux/socket.h> | ||
23 | #include <linux/sockios.h> | ||
24 | #include <linux/in.h> | ||
25 | #include <linux/errno.h> | 16 | #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> | 17 | #include <linux/netdevice.h> |
30 | #include <linux/etherdevice.h> | ||
31 | #include <linux/notifier.h> | ||
32 | #include <net/ip.h> | ||
33 | #include <net/route.h> | ||
34 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
35 | #include <net/sock.h> | ||
36 | #include <net/pkt_sched.h> | 19 | #include <net/pkt_sched.h> |
37 | 20 | ||
38 | /* 1 band FIFO pseudo-"scheduler" */ | 21 | /* 1 band FIFO pseudo-"scheduler" */ |
39 | 22 | ||
40 | struct fifo_sched_data | 23 | struct fifo_sched_data |
41 | { | 24 | { |
42 | unsigned limit; | 25 | u32 limit; |
43 | }; | 26 | }; |
44 | 27 | ||
45 | static int | 28 | static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch) |
46 | bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch) | ||
47 | { | 29 | { |
48 | struct fifo_sched_data *q = qdisc_priv(sch); | 30 | struct fifo_sched_data *q = qdisc_priv(sch); |
49 | 31 | ||
50 | if (sch->qstats.backlog + skb->len <= q->limit) { | 32 | if (likely(sch->qstats.backlog + skb->len <= q->limit)) |
51 | __skb_queue_tail(&sch->q, skb); | 33 | return qdisc_enqueue_tail(skb, sch); |
52 | sch->qstats.backlog += skb->len; | ||
53 | sch->bstats.bytes += skb->len; | ||
54 | sch->bstats.packets++; | ||
55 | return 0; | ||
56 | } | ||
57 | sch->qstats.drops++; | ||
58 | #ifdef CONFIG_NET_CLS_POLICE | ||
59 | if (sch->reshape_fail==NULL || sch->reshape_fail(skb, sch)) | ||
60 | #endif | ||
61 | kfree_skb(skb); | ||
62 | return NET_XMIT_DROP; | ||
63 | } | ||
64 | |||
65 | static int | ||
66 | bfifo_requeue(struct sk_buff *skb, struct Qdisc* sch) | ||
67 | { | ||
68 | __skb_queue_head(&sch->q, skb); | ||
69 | sch->qstats.backlog += skb->len; | ||
70 | sch->qstats.requeues++; | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static struct sk_buff * | ||
75 | bfifo_dequeue(struct Qdisc* sch) | ||
76 | { | ||
77 | struct sk_buff *skb; | ||
78 | 34 | ||
79 | skb = __skb_dequeue(&sch->q); | 35 | return qdisc_reshape_fail(skb, sch); |
80 | if (skb) | ||
81 | sch->qstats.backlog -= skb->len; | ||
82 | return skb; | ||
83 | } | 36 | } |
84 | 37 | ||
85 | static unsigned int | 38 | static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch) |
86 | fifo_drop(struct Qdisc* sch) | ||
87 | { | ||
88 | struct sk_buff *skb; | ||
89 | |||
90 | skb = __skb_dequeue_tail(&sch->q); | ||
91 | if (skb) { | ||
92 | unsigned int len = skb->len; | ||
93 | sch->qstats.backlog -= len; | ||
94 | kfree_skb(skb); | ||
95 | return len; | ||
96 | } | ||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | static void | ||
101 | fifo_reset(struct Qdisc* sch) | ||
102 | { | ||
103 | skb_queue_purge(&sch->q); | ||
104 | sch->qstats.backlog = 0; | ||
105 | } | ||
106 | |||
107 | static int | ||
108 | pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch) | ||
109 | { | 39 | { |
110 | struct fifo_sched_data *q = qdisc_priv(sch); | 40 | struct fifo_sched_data *q = qdisc_priv(sch); |
111 | 41 | ||
112 | if (sch->q.qlen < q->limit) { | 42 | if (likely(skb_queue_len(&sch->q) < q->limit)) |
113 | __skb_queue_tail(&sch->q, skb); | 43 | return qdisc_enqueue_tail(skb, sch); |
114 | sch->bstats.bytes += skb->len; | ||
115 | sch->bstats.packets++; | ||
116 | return 0; | ||
117 | } | ||
118 | sch->qstats.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 NET_XMIT_DROP; | ||
124 | } | ||
125 | |||
126 | static int | ||
127 | pfifo_requeue(struct sk_buff *skb, struct Qdisc* sch) | ||
128 | { | ||
129 | __skb_queue_head(&sch->q, skb); | ||
130 | sch->qstats.requeues++; | ||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | 44 | ||
135 | static struct sk_buff * | 45 | return qdisc_reshape_fail(skb, sch); |
136 | pfifo_dequeue(struct Qdisc* sch) | ||
137 | { | ||
138 | return __skb_dequeue(&sch->q); | ||
139 | } | 46 | } |
140 | 47 | ||
141 | static int fifo_init(struct Qdisc *sch, struct rtattr *opt) | 48 | static int fifo_init(struct Qdisc *sch, struct rtattr *opt) |
@@ -143,66 +50,59 @@ static int fifo_init(struct Qdisc *sch, struct rtattr *opt) | |||
143 | struct fifo_sched_data *q = qdisc_priv(sch); | 50 | struct fifo_sched_data *q = qdisc_priv(sch); |
144 | 51 | ||
145 | if (opt == NULL) { | 52 | if (opt == NULL) { |
146 | unsigned int limit = sch->dev->tx_queue_len ? : 1; | 53 | u32 limit = sch->dev->tx_queue_len ? : 1; |
147 | 54 | ||
148 | if (sch->ops == &bfifo_qdisc_ops) | 55 | if (sch->ops == &bfifo_qdisc_ops) |
149 | q->limit = limit*sch->dev->mtu; | 56 | limit *= sch->dev->mtu; |
150 | else | 57 | |
151 | q->limit = limit; | 58 | q->limit = limit; |
152 | } else { | 59 | } else { |
153 | struct tc_fifo_qopt *ctl = RTA_DATA(opt); | 60 | struct tc_fifo_qopt *ctl = RTA_DATA(opt); |
154 | if (opt->rta_len < RTA_LENGTH(sizeof(*ctl))) | 61 | |
62 | if (RTA_PAYLOAD(opt) < sizeof(*ctl)) | ||
155 | return -EINVAL; | 63 | return -EINVAL; |
64 | |||
156 | q->limit = ctl->limit; | 65 | q->limit = ctl->limit; |
157 | } | 66 | } |
67 | |||
158 | return 0; | 68 | return 0; |
159 | } | 69 | } |
160 | 70 | ||
161 | static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb) | 71 | static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb) |
162 | { | 72 | { |
163 | struct fifo_sched_data *q = qdisc_priv(sch); | 73 | struct fifo_sched_data *q = qdisc_priv(sch); |
164 | unsigned char *b = skb->tail; | 74 | struct tc_fifo_qopt opt = { .limit = q->limit }; |
165 | struct tc_fifo_qopt opt; | ||
166 | 75 | ||
167 | opt.limit = q->limit; | ||
168 | RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt); | 76 | RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt); |
169 | |||
170 | return skb->len; | 77 | return skb->len; |
171 | 78 | ||
172 | rtattr_failure: | 79 | rtattr_failure: |
173 | skb_trim(skb, b - skb->data); | ||
174 | return -1; | 80 | return -1; |
175 | } | 81 | } |
176 | 82 | ||
177 | struct Qdisc_ops pfifo_qdisc_ops = { | 83 | struct Qdisc_ops pfifo_qdisc_ops = { |
178 | .next = NULL, | ||
179 | .cl_ops = NULL, | ||
180 | .id = "pfifo", | 84 | .id = "pfifo", |
181 | .priv_size = sizeof(struct fifo_sched_data), | 85 | .priv_size = sizeof(struct fifo_sched_data), |
182 | .enqueue = pfifo_enqueue, | 86 | .enqueue = pfifo_enqueue, |
183 | .dequeue = pfifo_dequeue, | 87 | .dequeue = qdisc_dequeue_head, |
184 | .requeue = pfifo_requeue, | 88 | .requeue = qdisc_requeue, |
185 | .drop = fifo_drop, | 89 | .drop = qdisc_queue_drop, |
186 | .init = fifo_init, | 90 | .init = fifo_init, |
187 | .reset = fifo_reset, | 91 | .reset = qdisc_reset_queue, |
188 | .destroy = NULL, | ||
189 | .change = fifo_init, | 92 | .change = fifo_init, |
190 | .dump = fifo_dump, | 93 | .dump = fifo_dump, |
191 | .owner = THIS_MODULE, | 94 | .owner = THIS_MODULE, |
192 | }; | 95 | }; |
193 | 96 | ||
194 | struct Qdisc_ops bfifo_qdisc_ops = { | 97 | struct Qdisc_ops bfifo_qdisc_ops = { |
195 | .next = NULL, | ||
196 | .cl_ops = NULL, | ||
197 | .id = "bfifo", | 98 | .id = "bfifo", |
198 | .priv_size = sizeof(struct fifo_sched_data), | 99 | .priv_size = sizeof(struct fifo_sched_data), |
199 | .enqueue = bfifo_enqueue, | 100 | .enqueue = bfifo_enqueue, |
200 | .dequeue = bfifo_dequeue, | 101 | .dequeue = qdisc_dequeue_head, |
201 | .requeue = bfifo_requeue, | 102 | .requeue = qdisc_requeue, |
202 | .drop = fifo_drop, | 103 | .drop = qdisc_queue_drop, |
203 | .init = fifo_init, | 104 | .init = fifo_init, |
204 | .reset = fifo_reset, | 105 | .reset = qdisc_reset_queue, |
205 | .destroy = NULL, | ||
206 | .change = fifo_init, | 106 | .change = fifo_init, |
207 | .dump = fifo_dump, | 107 | .dump = fifo_dump, |
208 | .owner = THIS_MODULE, | 108 | .owner = THIS_MODULE, |