sch_red.c (20fea08b5fb639c4c175b5c74a2bb346c5c5bc2e) | sch_red.c (1e90474c377e92db7262a8968a45c1dd980ca9e5) |
---|---|
1/* 2 * net/sched/sch_red.c Random Early Detection 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 * --- 163 unchanged lines hidden (view full) --- 172{ 173 struct red_sched_data *q = qdisc_priv(sch); 174 qdisc_destroy(q->qdisc); 175} 176 177static struct Qdisc *red_create_dflt(struct Qdisc *sch, u32 limit) 178{ 179 struct Qdisc *q; | 1/* 2 * net/sched/sch_red.c Random Early Detection 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 * --- 163 unchanged lines hidden (view full) --- 172{ 173 struct red_sched_data *q = qdisc_priv(sch); 174 qdisc_destroy(q->qdisc); 175} 176 177static struct Qdisc *red_create_dflt(struct Qdisc *sch, u32 limit) 178{ 179 struct Qdisc *q; |
180 struct rtattr *rta; | 180 struct nlattr *nla; |
181 int ret; 182 183 q = qdisc_create_dflt(sch->dev, &bfifo_qdisc_ops, 184 TC_H_MAKE(sch->handle, 1)); 185 if (q) { | 181 int ret; 182 183 q = qdisc_create_dflt(sch->dev, &bfifo_qdisc_ops, 184 TC_H_MAKE(sch->handle, 1)); 185 if (q) { |
186 rta = kmalloc(RTA_LENGTH(sizeof(struct tc_fifo_qopt)), | 186 nla = kmalloc(nla_attr_size(sizeof(struct tc_fifo_qopt)), |
187 GFP_KERNEL); | 187 GFP_KERNEL); |
188 if (rta) { 189 rta->rta_type = RTM_NEWQDISC; 190 rta->rta_len = RTA_LENGTH(sizeof(struct tc_fifo_qopt)); 191 ((struct tc_fifo_qopt *)RTA_DATA(rta))->limit = limit; | 188 if (nla) { 189 nla->nla_type = RTM_NEWQDISC; 190 nla->nla_len = nla_attr_size(sizeof(struct tc_fifo_qopt)); 191 ((struct tc_fifo_qopt *)nla_data(nla))->limit = limit; |
192 | 192 |
193 ret = q->ops->change(q, rta); 194 kfree(rta); | 193 ret = q->ops->change(q, nla); 194 kfree(nla); |
195 196 if (ret == 0) 197 return q; 198 } 199 qdisc_destroy(q); 200 } 201 return NULL; 202} 203 | 195 196 if (ret == 0) 197 return q; 198 } 199 qdisc_destroy(q); 200 } 201 return NULL; 202} 203 |
204static int red_change(struct Qdisc *sch, struct rtattr *opt) | 204static int red_change(struct Qdisc *sch, struct nlattr *opt) |
205{ 206 struct red_sched_data *q = qdisc_priv(sch); | 205{ 206 struct red_sched_data *q = qdisc_priv(sch); |
207 struct rtattr *tb[TCA_RED_MAX]; | 207 struct nlattr *tb[TCA_RED_MAX + 1]; |
208 struct tc_red_qopt *ctl; 209 struct Qdisc *child = NULL; 210 | 208 struct tc_red_qopt *ctl; 209 struct Qdisc *child = NULL; 210 |
211 if (opt == NULL || rtattr_parse_nested(tb, TCA_RED_MAX, opt)) | 211 if (opt == NULL || nla_parse_nested(tb, TCA_RED_MAX, opt, NULL)) |
212 return -EINVAL; 213 | 212 return -EINVAL; 213 |
214 if (tb[TCA_RED_PARMS-1] == NULL || 215 RTA_PAYLOAD(tb[TCA_RED_PARMS-1]) < sizeof(*ctl) || 216 tb[TCA_RED_STAB-1] == NULL || 217 RTA_PAYLOAD(tb[TCA_RED_STAB-1]) < RED_STAB_SIZE) | 214 if (tb[TCA_RED_PARMS] == NULL || 215 nla_len(tb[TCA_RED_PARMS]) < sizeof(*ctl) || 216 tb[TCA_RED_STAB] == NULL || 217 nla_len(tb[TCA_RED_STAB]) < RED_STAB_SIZE) |
218 return -EINVAL; 219 | 218 return -EINVAL; 219 |
220 ctl = RTA_DATA(tb[TCA_RED_PARMS-1]); | 220 ctl = nla_data(tb[TCA_RED_PARMS]); |
221 222 if (ctl->limit > 0) { 223 child = red_create_dflt(sch, ctl->limit); 224 if (child == NULL) 225 return -ENOMEM; 226 } 227 228 sch_tree_lock(sch); 229 q->flags = ctl->flags; 230 q->limit = ctl->limit; 231 if (child) { 232 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen); 233 qdisc_destroy(xchg(&q->qdisc, child)); 234 } 235 236 red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog, 237 ctl->Plog, ctl->Scell_log, | 221 222 if (ctl->limit > 0) { 223 child = red_create_dflt(sch, ctl->limit); 224 if (child == NULL) 225 return -ENOMEM; 226 } 227 228 sch_tree_lock(sch); 229 q->flags = ctl->flags; 230 q->limit = ctl->limit; 231 if (child) { 232 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen); 233 qdisc_destroy(xchg(&q->qdisc, child)); 234 } 235 236 red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog, 237 ctl->Plog, ctl->Scell_log, |
238 RTA_DATA(tb[TCA_RED_STAB-1])); | 238 nla_data(tb[TCA_RED_STAB])); |
239 240 if (skb_queue_empty(&sch->q)) 241 red_end_of_idle_period(&q->parms); 242 243 sch_tree_unlock(sch); 244 return 0; 245} 246 | 239 240 if (skb_queue_empty(&sch->q)) 241 red_end_of_idle_period(&q->parms); 242 243 sch_tree_unlock(sch); 244 return 0; 245} 246 |
247static int red_init(struct Qdisc* sch, struct rtattr *opt) | 247static int red_init(struct Qdisc* sch, struct nlattr *opt) |
248{ 249 struct red_sched_data *q = qdisc_priv(sch); 250 251 q->qdisc = &noop_qdisc; 252 return red_change(sch, opt); 253} 254 255static int red_dump(struct Qdisc *sch, struct sk_buff *skb) 256{ 257 struct red_sched_data *q = qdisc_priv(sch); | 248{ 249 struct red_sched_data *q = qdisc_priv(sch); 250 251 q->qdisc = &noop_qdisc; 252 return red_change(sch, opt); 253} 254 255static int red_dump(struct Qdisc *sch, struct sk_buff *skb) 256{ 257 struct red_sched_data *q = qdisc_priv(sch); |
258 struct rtattr *opts = NULL; | 258 struct nlattr *opts = NULL; |
259 struct tc_red_qopt opt = { 260 .limit = q->limit, 261 .flags = q->flags, 262 .qth_min = q->parms.qth_min >> q->parms.Wlog, 263 .qth_max = q->parms.qth_max >> q->parms.Wlog, 264 .Wlog = q->parms.Wlog, 265 .Plog = q->parms.Plog, 266 .Scell_log = q->parms.Scell_log, 267 }; 268 | 259 struct tc_red_qopt opt = { 260 .limit = q->limit, 261 .flags = q->flags, 262 .qth_min = q->parms.qth_min >> q->parms.Wlog, 263 .qth_max = q->parms.qth_max >> q->parms.Wlog, 264 .Wlog = q->parms.Wlog, 265 .Plog = q->parms.Plog, 266 .Scell_log = q->parms.Scell_log, 267 }; 268 |
269 opts = RTA_NEST(skb, TCA_OPTIONS); 270 RTA_PUT(skb, TCA_RED_PARMS, sizeof(opt), &opt); 271 return RTA_NEST_END(skb, opts); | 269 opts = nla_nest_start(skb, TCA_OPTIONS); 270 if (opts == NULL) 271 goto nla_put_failure; 272 NLA_PUT(skb, TCA_RED_PARMS, sizeof(opt), &opt); 273 return nla_nest_end(skb, opts); |
272 | 274 |
273rtattr_failure: 274 return RTA_NEST_CANCEL(skb, opts); | 275nla_put_failure: 276 return nla_nest_cancel(skb, opts); |
275} 276 277static int red_dump_stats(struct Qdisc *sch, struct gnet_dump *d) 278{ 279 struct red_sched_data *q = qdisc_priv(sch); 280 struct tc_red_xstats st = { 281 .early = q->stats.prob_drop + q->stats.forced_drop, 282 .pdrop = q->stats.pdrop, --- 44 unchanged lines hidden (view full) --- 327} 328 329static void red_put(struct Qdisc *sch, unsigned long arg) 330{ 331 return; 332} 333 334static int red_change_class(struct Qdisc *sch, u32 classid, u32 parentid, | 277} 278 279static int red_dump_stats(struct Qdisc *sch, struct gnet_dump *d) 280{ 281 struct red_sched_data *q = qdisc_priv(sch); 282 struct tc_red_xstats st = { 283 .early = q->stats.prob_drop + q->stats.forced_drop, 284 .pdrop = q->stats.pdrop, --- 44 unchanged lines hidden (view full) --- 329} 330 331static void red_put(struct Qdisc *sch, unsigned long arg) 332{ 333 return; 334} 335 336static int red_change_class(struct Qdisc *sch, u32 classid, u32 parentid, |
335 struct rtattr **tca, unsigned long *arg) | 337 struct nlattr **tca, unsigned long *arg) |
336{ 337 return -ENOSYS; 338} 339 340static int red_delete(struct Qdisc *sch, unsigned long cl) 341{ 342 return -ENOSYS; 343} --- 61 unchanged lines hidden --- | 338{ 339 return -ENOSYS; 340} 341 342static int red_delete(struct Qdisc *sch, unsigned long cl) 343{ 344 return -ENOSYS; 345} --- 61 unchanged lines hidden --- |