hrtimer: convert net::sched_cbq to the new hrtimer apis
[safe/jmp/linux-2.6] / net / sched / sch_tbf.c
index 5386295..94c6159 100644 (file)
  */
 
 #include <linux/module.h>
-#include <asm/uaccess.h>
-#include <asm/system.h>
-#include <linux/bitops.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/jiffies.h>
 #include <linux/string.h>
-#include <linux/mm.h>
-#include <linux/socket.h>
-#include <linux/sockios.h>
-#include <linux/in.h>
 #include <linux/errno.h>
-#include <linux/interrupt.h>
-#include <linux/if_ether.h>
-#include <linux/inet.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/notifier.h>
-#include <net/ip.h>
-#include <net/netlink.h>
-#include <net/route.h>
 #include <linux/skbuff.h>
-#include <net/sock.h>
+#include <net/netlink.h>
 #include <net/pkt_sched.h>
 
 
@@ -132,31 +115,26 @@ struct tbf_sched_data
        struct qdisc_watchdog watchdog; /* Watchdog timer */
 };
 
-#define L2T(q,L)   ((q)->R_tab->data[(L)>>(q)->R_tab->rate.cell_log])
-#define L2T_P(q,L) ((q)->P_tab->data[(L)>>(q)->P_tab->rate.cell_log])
+#define L2T(q,L)   qdisc_l2t((q)->R_tab,L)
+#define L2T_P(q,L) qdisc_l2t((q)->P_tab,L)
 
 static int tbf_enqueue(struct sk_buff *skb, struct Qdisc* sch)
 {
        struct tbf_sched_data *q = qdisc_priv(sch);
        int ret;
 
-       if (skb->len > q->max_size) {
-               sch->qstats.drops++;
-#ifdef CONFIG_NET_CLS_POLICE
-               if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch))
-#endif
-                       kfree_skb(skb);
-
-               return NET_XMIT_DROP;
-       }
+       if (qdisc_pkt_len(skb) > q->max_size)
+               return qdisc_reshape_fail(skb, sch);
 
-       if ((ret = q->qdisc->enqueue(skb, q->qdisc)) != 0) {
-               sch->qstats.drops++;
+       ret = qdisc_enqueue(skb, q->qdisc);
+       if (ret != 0) {
+               if (net_xmit_drop_count(ret))
+                       sch->qstats.drops++;
                return ret;
        }
 
        sch->q.qlen++;
-       sch->bstats.bytes += skb->len;
+       sch->bstats.bytes += qdisc_pkt_len(skb);
        sch->bstats.packets++;
        return 0;
 }
@@ -197,7 +175,7 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
                psched_time_t now;
                long toks;
                long ptoks = 0;
-               unsigned int len = skb->len;
+               unsigned int len = qdisc_pkt_len(skb);
 
                now = psched_get_time();
                toks = psched_tdiff_bounded(now, q->t_c, q->buffer);
@@ -259,57 +237,39 @@ 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 rtattr *rta;
-       int ret;
-
-       q = qdisc_create_dflt(sch->dev, &bfifo_qdisc_ops,
-                             TC_H_MAKE(sch->handle, 1));
-       if (q) {
-               rta = kmalloc(RTA_LENGTH(sizeof(struct tc_fifo_qopt)), GFP_KERNEL);
-               if (rta) {
-                       rta->rta_type = RTM_NEWQDISC;
-                       rta->rta_len = RTA_LENGTH(sizeof(struct tc_fifo_qopt));
-                       ((struct tc_fifo_qopt *)RTA_DATA(rta))->limit = limit;
-
-                       ret = q->ops->change(q, rta);
-                       kfree(rta);
-
-                       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 rtattr *opt)
+static int tbf_change(struct Qdisc* sch, struct nlattr *opt)
 {
-       int err = -EINVAL;
+       int err;
        struct tbf_sched_data *q = qdisc_priv(sch);
-       struct rtattr *tb[TCA_TBF_PTAB];
+       struct nlattr *tb[TCA_TBF_PTAB + 1];
        struct tc_tbf_qopt *qopt;
        struct qdisc_rate_table *rtab = NULL;
        struct qdisc_rate_table *ptab = NULL;
        struct Qdisc *child = NULL;
        int max_size,n;
 
-       if (rtattr_parse_nested(tb, TCA_TBF_PTAB, opt) ||
-           tb[TCA_TBF_PARMS-1] == NULL ||
-           RTA_PAYLOAD(tb[TCA_TBF_PARMS-1]) < sizeof(*qopt))
+       err = nla_parse_nested(tb, TCA_TBF_PTAB, opt, tbf_policy);
+       if (err < 0)
+               return err;
+
+       err = -EINVAL;
+       if (tb[TCA_TBF_PARMS] == NULL)
                goto done;
 
-       qopt = RTA_DATA(tb[TCA_TBF_PARMS-1]);
-       rtab = qdisc_get_rtab(&qopt->rate, tb[TCA_TBF_RTAB-1]);
+       qopt = nla_data(tb[TCA_TBF_PARMS]);
+       rtab = qdisc_get_rtab(&qopt->rate, tb[TCA_TBF_RTAB]);
        if (rtab == NULL)
                goto done;
 
        if (qopt->peakrate.rate) {
                if (qopt->peakrate.rate > qopt->rate.rate)
-                       ptab = qdisc_get_rtab(&qopt->peakrate, tb[TCA_TBF_PTAB-1]);
+                       ptab = qdisc_get_rtab(&qopt->peakrate, tb[TCA_TBF_PTAB]);
                if (ptab == NULL)
                        goto done;
        }
@@ -329,8 +289,11 @@ static int tbf_change(struct Qdisc* sch, struct rtattr *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);
@@ -356,7 +319,7 @@ done:
        return err;
 }
 
-static int tbf_init(struct Qdisc* sch, struct rtattr *opt)
+static int tbf_init(struct Qdisc* sch, struct nlattr *opt)
 {
        struct tbf_sched_data *q = qdisc_priv(sch);
 
@@ -387,12 +350,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 rtattr *rta;
+       struct nlattr *nest;
        struct tc_tbf_qopt opt;
 
-       rta = (struct rtattr*)b;
-       RTA_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;
@@ -402,13 +365,13 @@ static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)
                memset(&opt.peakrate, 0, sizeof(opt.peakrate));
        opt.mtu = q->mtu;
        opt.buffer = q->buffer;
-       RTA_PUT(skb, TCA_TBF_PARMS, sizeof(opt), &opt);
-       rta->rta_len = skb_tail_pointer(skb) - b;
+       NLA_PUT(skb, TCA_TBF_PARMS, sizeof(opt), &opt);
 
+       nla_nest_end(skb, nest);
        return skb->len;
 
-rtattr_failure:
-       nlmsg_trim(skb, b);
+nla_put_failure:
+       nla_nest_cancel(skb, nest);
        return -1;
 }
 
@@ -459,7 +422,7 @@ static void tbf_put(struct Qdisc *sch, unsigned long arg)
 }
 
 static int tbf_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
-                           struct rtattr **tca, unsigned long *arg)
+                           struct nlattr **tca, unsigned long *arg)
 {
        return -ENOSYS;
 }
@@ -486,7 +449,7 @@ static struct tcf_proto **tbf_find_tcf(struct Qdisc *sch, unsigned long cl)
        return NULL;
 }
 
-static struct Qdisc_class_ops tbf_class_ops =
+static const struct Qdisc_class_ops tbf_class_ops =
 {
        .graft          =       tbf_graft,
        .leaf           =       tbf_leaf,
@@ -499,7 +462,7 @@ static struct Qdisc_class_ops tbf_class_ops =
        .dump           =       tbf_dump_class,
 };
 
-static struct Qdisc_ops tbf_qdisc_ops = {
+static struct Qdisc_ops tbf_qdisc_ops __read_mostly = {
        .next           =       NULL,
        .cl_ops         =       &tbf_class_ops,
        .id             =       "tbf",