]> err.no Git - linux-2.6/blobdiff - net/sched/sch_tbf.c
pkt_sched: Remove RR scheduler.
[linux-2.6] / net / sched / sch_tbf.c
index f9b1543e3d7604abeb5c538e0840a053848953c5..444c227fcb6b089e911765fa83595681564282d1 100644 (file)
@@ -242,33 +242,11 @@ static void tbf_reset(struct Qdisc* sch)
        qdisc_watchdog_cancel(&q->watchdog);
 }
 
-static struct Qdisc *tbf_create_dflt_qdisc(struct Qdisc *sch, u32 limit)
-{
-       struct Qdisc *q;
-       struct nlattr *nla;
-       int ret;
-
-       q = qdisc_create_dflt(sch->dev, &bfifo_qdisc_ops,
-                             TC_H_MAKE(sch->handle, 1));
-       if (q) {
-               nla = kmalloc(nla_attr_size(sizeof(struct tc_fifo_qopt)),
-                             GFP_KERNEL);
-               if (nla) {
-                       nla->nla_type = RTM_NEWQDISC;
-                       nla->nla_len = nla_attr_size(sizeof(struct tc_fifo_qopt));
-                       ((struct tc_fifo_qopt *)nla_data(nla))->limit = limit;
-
-                       ret = q->ops->change(q, nla);
-                       kfree(nla);
-
-                       if (ret == 0)
-                               return q;
-               }
-               qdisc_destroy(q);
-       }
-
-       return NULL;
-}
+static const struct nla_policy tbf_policy[TCA_TBF_MAX + 1] = {
+       [TCA_TBF_PARMS] = { .len = sizeof(struct tc_tbf_qopt) },
+       [TCA_TBF_RTAB]  = { .type = NLA_BINARY, .len = TC_RTAB_SIZE },
+       [TCA_TBF_PTAB]  = { .type = NLA_BINARY, .len = TC_RTAB_SIZE },
+};
 
 static int tbf_change(struct Qdisc* sch, struct nlattr *opt)
 {
@@ -281,13 +259,12 @@ static int tbf_change(struct Qdisc* sch, struct nlattr *opt)
        struct Qdisc *child = NULL;
        int max_size,n;
 
-       err = nla_parse_nested(tb, TCA_TBF_PTAB, opt, NULL);
+       err = nla_parse_nested(tb, TCA_TBF_PTAB, opt, tbf_policy);
        if (err < 0)
                return err;
 
        err = -EINVAL;
-       if (tb[TCA_TBF_PARMS] == NULL ||
-           nla_len(tb[TCA_TBF_PARMS]) < sizeof(*qopt))
+       if (tb[TCA_TBF_PARMS] == NULL)
                goto done;
 
        qopt = nla_data(tb[TCA_TBF_PARMS]);
@@ -317,8 +294,11 @@ static int tbf_change(struct Qdisc* sch, struct nlattr *opt)
                goto done;
 
        if (qopt->limit > 0) {
-               if ((child = tbf_create_dflt_qdisc(sch, qopt->limit)) == NULL)
+               child = fifo_create_dflt(sch, &bfifo_qdisc_ops, qopt->limit);
+               if (IS_ERR(child)) {
+                       err = PTR_ERR(child);
                        goto done;
+               }
        }
 
        sch_tree_lock(sch);
@@ -375,12 +355,12 @@ static void tbf_destroy(struct Qdisc *sch)
 static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)
 {
        struct tbf_sched_data *q = qdisc_priv(sch);
-       unsigned char *b = skb_tail_pointer(skb);
-       struct nlattr *nla;
+       struct nlattr *nest;
        struct tc_tbf_qopt opt;
 
-       nla = (struct nlattr*)b;
-       NLA_PUT(skb, TCA_OPTIONS, 0, NULL);
+       nest = nla_nest_start(skb, TCA_OPTIONS);
+       if (nest == NULL)
+               goto nla_put_failure;
 
        opt.limit = q->limit;
        opt.rate = q->R_tab->rate;
@@ -391,12 +371,12 @@ static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)
        opt.mtu = q->mtu;
        opt.buffer = q->buffer;
        NLA_PUT(skb, TCA_TBF_PARMS, sizeof(opt), &opt);
-       nla->nla_len = skb_tail_pointer(skb) - b;
 
+       nla_nest_end(skb, nest);
        return skb->len;
 
 nla_put_failure:
-       nlmsg_trim(skb, b);
+       nla_nest_cancel(skb, nest);
        return -1;
 }