]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/sched/sch_tbf.c
[NETLINK]: Use nlmsg_trim() where appropriate
[net-next-2.6.git] / net / sched / sch_tbf.c
index d9a5d298d755539443fa2a618ff70ba4863126da..626ce96800fee9dcecfe942e951136cd9b11f086 100644 (file)
@@ -32,6 +32,7 @@
 #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>
@@ -127,8 +128,8 @@ struct tbf_sched_data
        long    tokens;                 /* Current number of B tokens */
        long    ptokens;                /* Current number of P tokens */
        psched_time_t   t_c;            /* Time check-point */
-       struct timer_list wd_timer;     /* Watchdog timer */
        struct Qdisc    *qdisc;         /* Inner qdisc, default - bfifo queue */
+       struct qdisc_watchdog watchdog; /* Watchdog timer */
 };
 
 #define L2T(q,L)   ((q)->R_tab->data[(L)>>(q)->R_tab->rate.cell_log])
@@ -185,14 +186,6 @@ static unsigned int tbf_drop(struct Qdisc* sch)
        return len;
 }
 
-static void tbf_watchdog(unsigned long arg)
-{
-       struct Qdisc *sch = (struct Qdisc*)arg;
-
-       sch->flags &= ~TCQ_F_THROTTLED;
-       netif_schedule(sch->dev);
-}
-
 static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
 {
        struct tbf_sched_data *q = qdisc_priv(sch);
@@ -202,7 +195,7 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
 
        if (skb) {
                psched_time_t now;
-               long toks, delay;
+               long toks;
                long ptoks = 0;
                unsigned int len = skb->len;
 
@@ -230,12 +223,8 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
                        return skb;
                }
 
-               delay = PSCHED_US2JIFFIE(max_t(long, -toks, -ptoks));
-
-               if (delay == 0)
-                       delay = 1;
-
-               mod_timer(&q->wd_timer, jiffies+delay);
+               qdisc_watchdog_schedule(&q->watchdog,
+                                       now + max_t(long, -toks, -ptoks));
 
                /* Maybe we have a shorter packet in the queue,
                   which can be sent now. It sounds cool,
@@ -250,11 +239,10 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
 
                if (q->qdisc->ops->requeue(skb, q->qdisc) != NET_XMIT_SUCCESS) {
                        /* When requeue fails skb is dropped */
-                       sch->q.qlen--;
+                       qdisc_tree_decrease_qlen(q->qdisc, 1);
                        sch->qstats.drops++;
                }
 
-               sch->flags |= TCQ_F_THROTTLED;
                sch->qstats.overlimits++;
        }
        return NULL;
@@ -269,21 +257,22 @@ static void tbf_reset(struct Qdisc* sch)
        PSCHED_GET_TIME(q->t_c);
        q->tokens = q->buffer;
        q->ptokens = q->mtu;
-       sch->flags &= ~TCQ_F_THROTTLED;
-       del_timer(&q->wd_timer);
+       qdisc_watchdog_cancel(&q->watchdog);
 }
 
-static struct Qdisc *tbf_create_dflt_qdisc(struct net_device *dev, u32 limit)
+static struct Qdisc *tbf_create_dflt_qdisc(struct Qdisc *sch, u32 limit)
 {
-       struct Qdisc *q = qdisc_create_dflt(dev, &bfifo_qdisc_ops);
-        struct rtattr *rta;
+       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)); 
+                       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);
@@ -341,13 +330,15 @@ static int tbf_change(struct Qdisc* sch, struct rtattr *opt)
                goto done;
 
        if (qopt->limit > 0) {
-               if ((child = tbf_create_dflt_qdisc(sch->dev, qopt->limit)) == NULL)
+               if ((child = tbf_create_dflt_qdisc(sch, qopt->limit)) == NULL)
                        goto done;
        }
 
        sch_tree_lock(sch);
-       if (child)
+       if (child) {
+               qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen);
                qdisc_destroy(xchg(&q->qdisc, child));
+       }
        q->limit = qopt->limit;
        q->mtu = qopt->mtu;
        q->max_size = max_size;
@@ -374,10 +365,7 @@ static int tbf_init(struct Qdisc* sch, struct rtattr *opt)
                return -EINVAL;
 
        PSCHED_GET_TIME(q->t_c);
-       init_timer(&q->wd_timer);
-       q->wd_timer.function = tbf_watchdog;
-       q->wd_timer.data = (unsigned long)sch;
-
+       qdisc_watchdog_init(&q->watchdog, sch);
        q->qdisc = &noop_qdisc;
 
        return tbf_change(sch, opt);
@@ -387,7 +375,7 @@ static void tbf_destroy(struct Qdisc *sch)
 {
        struct tbf_sched_data *q = qdisc_priv(sch);
 
-       del_timer(&q->wd_timer);
+       qdisc_watchdog_cancel(&q->watchdog);
 
        if (q->P_tab)
                qdisc_put_rtab(q->P_tab);
@@ -400,7 +388,7 @@ 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;
+       unsigned char *b = skb_tail_pointer(skb);
        struct rtattr *rta;
        struct tc_tbf_qopt opt;
 
@@ -416,12 +404,12 @@ static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)
        opt.mtu = q->mtu;
        opt.buffer = q->buffer;
        RTA_PUT(skb, TCA_TBF_PARMS, sizeof(opt), &opt);
-       rta->rta_len = skb->tail - b;
+       rta->rta_len = skb_tail_pointer(skb) - b;
 
        return skb->len;
 
 rtattr_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -449,8 +437,8 @@ static int tbf_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
 
        sch_tree_lock(sch);
        *old = xchg(&q->qdisc, new);
+       qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
        qdisc_reset(*old);
-       sch->q.qlen = 0;
        sch_tree_unlock(sch);
 
        return 0;
@@ -471,7 +459,7 @@ static void tbf_put(struct Qdisc *sch, unsigned long arg)
 {
 }
 
-static int tbf_change_class(struct Qdisc *sch, u32 classid, u32 parentid, 
+static int tbf_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
                            struct rtattr **tca, unsigned long *arg)
 {
        return -ENOSYS;