]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/sched/sch_netem.c
neofb: kill some redundant code
[linux-2.6-omap-h63xx.git] / net / sched / sch_netem.c
index 4093f1eaaf60ea132bceef39be84f1f10979420f..a11959908d9a68c405114d56c5073c0d77647402 100644 (file)
@@ -82,6 +82,13 @@ struct netem_skb_cb {
        psched_time_t   time_to_send;
 };
 
+static inline struct netem_skb_cb *netem_skb_cb(struct sk_buff *skb)
+{
+       BUILD_BUG_ON(sizeof(skb->cb) <
+               sizeof(struct qdisc_skb_cb) + sizeof(struct netem_skb_cb));
+       return (struct netem_skb_cb *)qdisc_skb_cb(skb)->data;
+}
+
 /* init_crandom - initialize correlated random number generator
  * Use entropy source for initial seed.
  */
@@ -169,7 +176,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
        if (count == 0) {
                sch->qstats.drops++;
                kfree_skb(skb);
-               return NET_XMIT_BYPASS;
+               return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
        }
 
        skb_orphan(skb);
@@ -180,11 +187,11 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
         * skb will be queued.
         */
        if (count > 1 && (skb2 = skb_clone(skb, GFP_ATOMIC)) != NULL) {
-               struct Qdisc *rootq = qdisc_dev(sch)->tx_queue.qdisc;
+               struct Qdisc *rootq = qdisc_root(sch);
                u32 dupsave = q->duplicate; /* prevent duplicating a dup... */
                q->duplicate = 0;
 
-               rootq->enqueue(skb2, rootq);
+               qdisc_enqueue_root(skb2, rootq);
                q->duplicate = dupsave;
        }
 
@@ -205,7 +212,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
                skb->data[net_random() % skb_headlen(skb)] ^= 1<<(net_random() % 8);
        }
 
-       cb = (struct netem_skb_cb *)skb->cb;
+       cb = netem_skb_cb(skb);
        if (q->gap == 0                 /* not doing reordering */
            || q->counter < q->gap      /* inside last reordering gap */
            || q->reorder < get_crandom(&q->reorder_cor)) {
@@ -218,7 +225,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
                now = psched_get_time();
                cb->time_to_send = now + delay;
                ++q->counter;
-               ret = q->qdisc->enqueue(skb, q->qdisc);
+               ret = qdisc_enqueue(skb, q->qdisc);
        } else {
                /*
                 * Do re-ordering by putting one out of N packets at the front
@@ -231,10 +238,11 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
 
        if (likely(ret == NET_XMIT_SUCCESS)) {
                sch->q.qlen++;
-               sch->bstats.bytes += skb->len;
+               sch->bstats.bytes += qdisc_pkt_len(skb);
                sch->bstats.packets++;
-       } else
+       } else if (net_xmit_drop_count(ret)) {
                sch->qstats.drops++;
+       }
 
        pr_debug("netem: enqueue ret %d\n", ret);
        return ret;
@@ -277,8 +285,7 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
 
        skb = q->qdisc->dequeue(q->qdisc);
        if (skb) {
-               const struct netem_skb_cb *cb
-                       = (const struct netem_skb_cb *)skb->cb;
+               const struct netem_skb_cb *cb = netem_skb_cb(skb);
                psched_time_t now = psched_get_time();
 
                /* if more time remaining? */
@@ -319,6 +326,7 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
        struct netem_sched_data *q = qdisc_priv(sch);
        unsigned long n = nla_len(attr)/sizeof(__s16);
        const __s16 *data = nla_data(attr);
+       spinlock_t *root_lock;
        struct disttable *d;
        int i;
 
@@ -333,9 +341,11 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
        for (i = 0; i < n; i++)
                d->table[i] = data[i];
 
-       spin_lock_bh(&sch->dev_queue->lock);
+       root_lock = qdisc_root_sleeping_lock(sch);
+
+       spin_lock_bh(root_lock);
        d = xchg(&q->delay_dist, d);
-       spin_unlock_bh(&sch->dev_queue->lock);
+       spin_unlock_bh(root_lock);
 
        kfree(d);
        return 0;
@@ -378,6 +388,20 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
        [TCA_NETEM_CORRUPT]     = { .len = sizeof(struct tc_netem_corrupt) },
 };
 
+static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
+                     const struct nla_policy *policy, int len)
+{
+       int nested_len = nla_len(nla) - NLA_ALIGN(len);
+
+       if (nested_len < 0)
+               return -EINVAL;
+       if (nested_len >= nla_attr_size(0))
+               return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len),
+                                nested_len, policy);
+       memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
+       return 0;
+}
+
 /* Parse netlink message to set options */
 static int netem_change(struct Qdisc *sch, struct nlattr *opt)
 {
@@ -389,8 +413,8 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
        if (opt == NULL)
                return -EINVAL;
 
-       ret = nla_parse_nested_compat(tb, TCA_NETEM_MAX, opt, netem_policy,
-                                     qopt, sizeof(*qopt));
+       qopt = nla_data(opt);
+       ret = parse_attr(tb, TCA_NETEM_MAX, opt, netem_policy, sizeof(*qopt));
        if (ret < 0)
                return ret;
 
@@ -454,7 +478,7 @@ static int tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch)
 {
        struct fifo_sched_data *q = qdisc_priv(sch);
        struct sk_buff_head *list = &sch->q;
-       psched_time_t tnext = ((struct netem_skb_cb *)nskb->cb)->time_to_send;
+       psched_time_t tnext = netem_skb_cb(nskb)->time_to_send;
        struct sk_buff *skb;
 
        if (likely(skb_queue_len(list) < q->limit)) {
@@ -465,8 +489,7 @@ static int tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch)
                }
 
                skb_queue_reverse_walk(list, skb) {
-                       const struct netem_skb_cb *cb
-                               = (const struct netem_skb_cb *)skb->cb;
+                       const struct netem_skb_cb *cb = netem_skb_cb(skb);
 
                        if (tnext >= cb->time_to_send)
                                break;
@@ -474,8 +497,8 @@ static int tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch)
 
                __skb_queue_after(list, skb, nskb);
 
-               sch->qstats.backlog += nskb->len;
-               sch->bstats.bytes += nskb->len;
+               sch->qstats.backlog += qdisc_pkt_len(nskb);
+               sch->bstats.bytes += qdisc_pkt_len(nskb);
                sch->bstats.packets++;
 
                return NET_XMIT_SUCCESS;