ipv4: tcp: set unicast_sock uc_ttl to -1
[linux-3.10.git] / net / sched / sch_atm.c
index ccee10d..ca8e0a5 100644 (file)
@@ -3,7 +3,9 @@
 /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
 
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/init.h>
+#include <linux/interrupt.h>
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <linux/skbuff.h>
 #include <net/netlink.h>
 #include <net/pkt_sched.h>
 
-extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
-
-#if 0 /* control */
-#define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
-#else
-#define DPRINTK(format,args...)
-#endif
-
-#if 0 /* data */
-#define D2PRINTK(format,args...) printk(KERN_DEBUG format,##args)
-#else
-#define D2PRINTK(format,args...)
-#endif
-
 /*
  * The ATM queuing discipline provides a framework for invoking classifiers
  * (aka "filters"), which in turn select classes of this queuing discipline.
@@ -49,7 +37,6 @@ extern struct socket *sockfd_lookup(int fd, int *err);        /* @@@ fix this */
  *  - should lock the flow while there is data in the queue (?)
  */
 
-#define PRIV(sch) qdisc_priv(sch)
 #define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back))
 
 struct atm_flow_data {
@@ -57,14 +44,14 @@ struct atm_flow_data {
        struct tcf_proto        *filter_list;
        struct atm_vcc          *vcc;   /* VCC; NULL if VCC is closed */
        void                    (*old_pop)(struct atm_vcc *vcc,
-                                          struct sk_buff * skb); /* chaining */
+                                          struct sk_buff *skb); /* chaining */
        struct atm_qdisc_data   *parent;        /* parent qdisc */
        struct socket           *sock;          /* for closing */
        u32                     classid;        /* x:y type ID */
        int                     ref;            /* reference count */
-       struct gnet_stats_basic bstats;
+       struct gnet_stats_basic_packed  bstats;
        struct gnet_stats_queue qstats;
-       struct atm_flow_data    *next;
+       struct list_head        list;
        struct atm_flow_data    *excess;        /* flow for excess traffic;
                                                   NULL to set CLP instead */
        int                     hdr_len;
@@ -73,49 +60,39 @@ struct atm_flow_data {
 
 struct atm_qdisc_data {
        struct atm_flow_data    link;           /* unclassified skbs go here */
-       struct atm_flow_data    *flows;         /* NB: "link" is also on this
+       struct list_head        flows;          /* NB: "link" is also on this
                                                   list */
-       struct tasklet_struct   task;           /* requeue tasklet */
+       struct tasklet_struct   task;           /* dequeue tasklet */
 };
 
 /* ------------------------- Class/flow operations ------------------------- */
 
-static int find_flow(struct atm_qdisc_data *qdisc, struct atm_flow_data *flow)
-{
-       struct atm_flow_data *walk;
-
-       DPRINTK("find_flow(qdisc %p,flow %p)\n", qdisc, flow);
-       for (walk = qdisc->flows; walk; walk = walk->next)
-               if (walk == flow)
-                       return 1;
-       DPRINTK("find_flow: not found\n");
-       return 0;
-}
-
 static inline struct atm_flow_data *lookup_flow(struct Qdisc *sch, u32 classid)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow;
 
-       for (flow = p->flows; flow; flow = flow->next)
+       list_for_each_entry(flow, &p->flows, list) {
                if (flow->classid == classid)
-                       break;
-       return flow;
+                       return flow;
+       }
+       return NULL;
 }
 
 static int atm_tc_graft(struct Qdisc *sch, unsigned long arg,
                        struct Qdisc *new, struct Qdisc **old)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow = (struct atm_flow_data *)arg;
 
-       DPRINTK("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",
+       pr_debug("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",
                sch, p, flow, new, old);
-       if (!find_flow(p, flow))
+       if (list_empty(&flow->list))
                return -EINVAL;
        if (!new)
                new = &noop_qdisc;
-       *old = xchg(&flow->q, new);
+       *old = flow->q;
+       flow->q = new;
        if (*old)
                qdisc_reset(*old);
        return 0;
@@ -125,20 +102,20 @@ static struct Qdisc *atm_tc_leaf(struct Qdisc *sch, unsigned long cl)
 {
        struct atm_flow_data *flow = (struct atm_flow_data *)cl;
 
-       DPRINTK("atm_tc_leaf(sch %p,flow %p)\n", sch, flow);
+       pr_debug("atm_tc_leaf(sch %p,flow %p)\n", sch, flow);
        return flow ? flow->q : NULL;
 }
 
 static unsigned long atm_tc_get(struct Qdisc *sch, u32 classid)
 {
-       struct atm_qdisc_data *p __maybe_unused = PRIV(sch);
+       struct atm_qdisc_data *p __maybe_unused = qdisc_priv(sch);
        struct atm_flow_data *flow;
 
-       DPRINTK("atm_tc_get(sch %p,[qdisc %p],classid %x)\n", sch, p, classid);
+       pr_debug("atm_tc_get(sch %p,[qdisc %p],classid %x)\n", sch, p, classid);
        flow = lookup_flow(sch, classid);
        if (flow)
                flow->ref++;
-       DPRINTK("atm_tc_get: flow %p\n", flow);
+       pr_debug("atm_tc_get: flow %p\n", flow);
        return (unsigned long)flow;
 }
 
@@ -155,27 +132,19 @@ static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
  */
 static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow = (struct atm_flow_data *)cl;
-       struct atm_flow_data **prev;
 
-       DPRINTK("atm_tc_put(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
+       pr_debug("atm_tc_put(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
        if (--flow->ref)
                return;
-       DPRINTK("atm_tc_put: destroying\n");
-       for (prev = &p->flows; *prev; prev = &(*prev)->next)
-               if (*prev == flow)
-                       break;
-       if (!*prev) {
-               printk(KERN_CRIT "atm_tc_put: class %p not found\n", flow);
-               return;
-       }
-       *prev = flow->next;
-       DPRINTK("atm_tc_put: qdisc %p\n", flow->q);
+       pr_debug("atm_tc_put: destroying\n");
+       list_del_init(&flow->list);
+       pr_debug("atm_tc_put: qdisc %p\n", flow->q);
        qdisc_destroy(flow->q);
-       tcf_destroy_chain(flow->filter_list);
+       tcf_destroy_chain(&flow->filter_list);
        if (flow->sock) {
-               DPRINTK("atm_tc_put: f_count %d\n",
+               pr_debug("atm_tc_put: f_count %ld\n",
                        file_count(flow->sock->file));
                flow->vcc->pop = flow->old_pop;
                sockfd_put(flow->sock);
@@ -194,7 +163,7 @@ static void sch_atm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
 {
        struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent;
 
-       D2PRINTK("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n", vcc, skb, p);
+       pr_debug("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n", vcc, skb, p);
        VCC2FLOW(vcc)->old_pop(vcc, skb);
        tasklet_schedule(&p->task);
 }
@@ -208,19 +177,24 @@ static const u8 llc_oui_ip[] = {
        0x08, 0x00
 };                             /* Ethertype IP (0800) */
 
+static const struct nla_policy atm_policy[TCA_ATM_MAX + 1] = {
+       [TCA_ATM_FD]            = { .type = NLA_U32 },
+       [TCA_ATM_EXCESS]        = { .type = NLA_U32 },
+};
+
 static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
-                        struct rtattr **tca, unsigned long *arg)
+                        struct nlattr **tca, unsigned long *arg)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow = (struct atm_flow_data *)*arg;
        struct atm_flow_data *excess = NULL;
-       struct rtattr *opt = tca[TCA_OPTIONS - 1];
-       struct rtattr *tb[TCA_ATM_MAX];
+       struct nlattr *opt = tca[TCA_OPTIONS];
+       struct nlattr *tb[TCA_ATM_MAX + 1];
        struct socket *sock;
        int fd, error, hdr_len;
        void *hdr;
 
-       DPRINTK("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x,"
+       pr_debug("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x,"
                "flow %p,opt %p)\n", sch, p, classid, parent, flow, opt);
        /*
         * The concept of parents doesn't apply for this qdisc.
@@ -236,34 +210,38 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
         */
        if (flow)
                return -EBUSY;
-       if (opt == NULL || rtattr_parse_nested(tb, TCA_ATM_MAX, opt))
+       if (opt == NULL)
                return -EINVAL;
-       if (!tb[TCA_ATM_FD - 1] || RTA_PAYLOAD(tb[TCA_ATM_FD - 1]) < sizeof(fd))
+
+       error = nla_parse_nested(tb, TCA_ATM_MAX, opt, atm_policy);
+       if (error < 0)
+               return error;
+
+       if (!tb[TCA_ATM_FD])
                return -EINVAL;
-       fd = *(int *)RTA_DATA(tb[TCA_ATM_FD - 1]);
-       DPRINTK("atm_tc_change: fd %d\n", fd);
-       if (tb[TCA_ATM_HDR - 1]) {
-               hdr_len = RTA_PAYLOAD(tb[TCA_ATM_HDR - 1]);
-               hdr = RTA_DATA(tb[TCA_ATM_HDR - 1]);
+       fd = nla_get_u32(tb[TCA_ATM_FD]);
+       pr_debug("atm_tc_change: fd %d\n", fd);
+       if (tb[TCA_ATM_HDR]) {
+               hdr_len = nla_len(tb[TCA_ATM_HDR]);
+               hdr = nla_data(tb[TCA_ATM_HDR]);
        } else {
                hdr_len = RFC1483LLC_LEN;
                hdr = NULL;     /* default LLC/SNAP for IP */
        }
-       if (!tb[TCA_ATM_EXCESS - 1])
+       if (!tb[TCA_ATM_EXCESS])
                excess = NULL;
        else {
-               if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS - 1]) != sizeof(u32))
-                       return -EINVAL;
                excess = (struct atm_flow_data *)
-                       atm_tc_get(sch, *(u32 *)RTA_DATA(tb[TCA_ATM_EXCESS - 1]));
+                       atm_tc_get(sch, nla_get_u32(tb[TCA_ATM_EXCESS]));
                if (!excess)
                        return -ENOENT;
        }
-       DPRINTK("atm_tc_change: type %d, payload %d, hdr_len %d\n",
-               opt->rta_type, RTA_PAYLOAD(opt), hdr_len);
-       if (!(sock = sockfd_lookup(fd, &error)))
+       pr_debug("atm_tc_change: type %d, payload %d, hdr_len %d\n",
+                opt->nla_type, nla_len(opt), hdr_len);
+       sock = sockfd_lookup(fd, &error);
+       if (!sock)
                return error;   /* f_count++ */
-       DPRINTK("atm_tc_change: f_count %d\n", file_count(sock->file));
+       pr_debug("atm_tc_change: f_count %ld\n", file_count(sock->file));
        if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) {
                error = -EPROTOTYPE;
                goto err_out;
@@ -272,49 +250,45 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
           on vcc->send */
        if (classid) {
                if (TC_H_MAJ(classid ^ sch->handle)) {
-                       DPRINTK("atm_tc_change: classid mismatch\n");
+                       pr_debug("atm_tc_change: classid mismatch\n");
                        error = -EINVAL;
                        goto err_out;
                }
-               if (find_flow(p, flow)) {
-                       error = -EEXIST;
-                       goto err_out;
-               }
        } else {
                int i;
                unsigned long cl;
 
                for (i = 1; i < 0x8000; i++) {
                        classid = TC_H_MAKE(sch->handle, 0x8000 | i);
-                       if (!(cl = atm_tc_get(sch, classid)))
+                       cl = atm_tc_get(sch, classid);
+                       if (!cl)
                                break;
                        atm_tc_put(sch, cl);
                }
        }
-       DPRINTK("atm_tc_change: new id %x\n", classid);
-       flow = kmalloc(sizeof(struct atm_flow_data) + hdr_len, GFP_KERNEL);
-       DPRINTK("atm_tc_change: flow %p\n", flow);
+       pr_debug("atm_tc_change: new id %x\n", classid);
+       flow = kzalloc(sizeof(struct atm_flow_data) + hdr_len, GFP_KERNEL);
+       pr_debug("atm_tc_change: flow %p\n", flow);
        if (!flow) {
                error = -ENOBUFS;
                goto err_out;
        }
-       memset(flow, 0, sizeof(*flow));
        flow->filter_list = NULL;
-       if (!(flow->q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, classid)))
+       flow->q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, classid);
+       if (!flow->q)
                flow->q = &noop_qdisc;
-       DPRINTK("atm_tc_change: qdisc %p\n", flow->q);
+       pr_debug("atm_tc_change: qdisc %p\n", flow->q);
        flow->sock = sock;
        flow->vcc = ATM_SD(sock);       /* speedup */
        flow->vcc->user_back = flow;
-       DPRINTK("atm_tc_change: vcc %p\n", flow->vcc);
+       pr_debug("atm_tc_change: vcc %p\n", flow->vcc);
        flow->old_pop = flow->vcc->pop;
        flow->parent = p;
        flow->vcc->pop = sch_atm_pop;
        flow->classid = classid;
        flow->ref = 1;
        flow->excess = excess;
-       flow->next = p->link.next;
-       p->link.next = flow;
+       list_add(&flow->list, &p->link.list);
        flow->hdr_len = hdr_len;
        if (hdr)
                memcpy(flow->hdr, hdr, hdr_len);
@@ -331,11 +305,11 @@ err_out:
 
 static int atm_tc_delete(struct Qdisc *sch, unsigned long arg)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow = (struct atm_flow_data *)arg;
 
-       DPRINTK("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
-       if (!find_flow(PRIV(sch), flow))
+       pr_debug("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
+       if (list_empty(&flow->list))
                return -EINVAL;
        if (flow->filter_list || flow == &p->link)
                return -EBUSY;
@@ -344,7 +318,7 @@ static int atm_tc_delete(struct Qdisc *sch, unsigned long arg)
         * creation), and one for the reference held when calling delete.
         */
        if (flow->ref < 2) {
-               printk(KERN_ERR "atm_tc_delete: flow->ref == %d\n", flow->ref);
+               pr_err("atm_tc_delete: flow->ref == %d\n", flow->ref);
                return -EINVAL;
        }
        if (flow->ref > 2)
@@ -355,28 +329,28 @@ static int atm_tc_delete(struct Qdisc *sch, unsigned long arg)
 
 static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow;
 
-       DPRINTK("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker);
+       pr_debug("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker);
        if (walker->stop)
                return;
-       for (flow = p->flows; flow; flow = flow->next) {
-               if (walker->count >= walker->skip)
-                       if (walker->fn(sch, (unsigned long)flow, walker) < 0) {
-                               walker->stop = 1;
-                               break;
-                       }
+       list_for_each_entry(flow, &p->flows, list) {
+               if (walker->count >= walker->skip &&
+                   walker->fn(sch, (unsigned long)flow, walker) < 0) {
+                       walker->stop = 1;
+                       break;
+               }
                walker->count++;
        }
 }
 
 static struct tcf_proto **atm_tc_find_tcf(struct Qdisc *sch, unsigned long cl)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow = (struct atm_flow_data *)cl;
 
-       DPRINTK("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
+       pr_debug("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
        return flow ? &flow->filter_list : &p->link.filter_list;
 }
 
@@ -384,30 +358,37 @@ static struct tcf_proto **atm_tc_find_tcf(struct Qdisc *sch, unsigned long cl)
 
 static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
-       struct atm_flow_data *flow = NULL;      /* @@@ */
+       struct atm_qdisc_data *p = qdisc_priv(sch);
+       struct atm_flow_data *flow;
        struct tcf_result res;
        int result;
        int ret = NET_XMIT_POLICED;
 
-       D2PRINTK("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
+       pr_debug("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
        result = TC_POLICE_OK;  /* be nice to gcc */
+       flow = NULL;
        if (TC_H_MAJ(skb->priority) != sch->handle ||
-           !(flow = (struct atm_flow_data *)atm_tc_get(sch, skb->priority)))
-               for (flow = p->flows; flow; flow = flow->next)
+           !(flow = (struct atm_flow_data *)atm_tc_get(sch, skb->priority))) {
+               list_for_each_entry(flow, &p->flows, list) {
                        if (flow->filter_list) {
-                               result = tc_classify(skb, flow->filter_list,
-                                                    &res);
+                               result = tc_classify_compat(skb,
+                                                           flow->filter_list,
+                                                           &res);
                                if (result < 0)
                                        continue;
                                flow = (struct atm_flow_data *)res.class;
                                if (!flow)
                                        flow = lookup_flow(sch, res.classid);
-                               break;
+                               goto done;
                        }
-       if (!flow)
+               }
+               flow = NULL;
+done:
+               ;
+       }
+       if (!flow) {
                flow = &p->link;
-       else {
+       } else {
                if (flow->vcc)
                        ATM_SKB(skb)->atm_options = flow->vcc->atm_options;
                /*@@@ looks good ... but it's not supposed to work :-) */
@@ -416,42 +397,30 @@ static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
                case TC_ACT_QUEUED:
                case TC_ACT_STOLEN:
                        kfree_skb(skb);
-                       return NET_XMIT_SUCCESS;
+                       return NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
                case TC_ACT_SHOT:
                        kfree_skb(skb);
                        goto drop;
-               }
-#elif defined(CONFIG_NET_CLS_POLICE)
-               switch (result) {
-               case TC_POLICE_SHOT:
-                       kfree_skb(skb);
-                       goto drop;
                case TC_POLICE_RECLASSIFY:
                        if (flow->excess)
                                flow = flow->excess;
-                       else {
+                       else
                                ATM_SKB(skb)->atm_options |= ATM_ATMOPT_CLP;
-                               break;
-                       }
-                       /* fall through */
-               case TC_POLICE_OK:
-                       /* fall through */
-               default:
                        break;
                }
 #endif
        }
-       if ((ret = flow->q->enqueue(skb, flow->q)) != 0) {
+
+       ret = qdisc_enqueue(skb, flow->q);
+       if (ret != NET_XMIT_SUCCESS) {
 drop: __maybe_unused
-               sch->qstats.drops++;
-               if (flow)
-                       flow->qstats.drops++;
+               if (net_xmit_drop_count(ret)) {
+                       sch->qstats.drops++;
+                       if (flow)
+                               flow->qstats.drops++;
+               }
                return ret;
        }
-       sch->bstats.bytes += skb->len;
-       sch->bstats.packets++;
-       flow->bstats.bytes += skb->len;
-       flow->bstats.packets++;
        /*
         * Okay, this may seem weird. We pretend we've dropped the packet if
         * it goes via ATM. The reason for this is that the outer qdisc
@@ -463,10 +432,10 @@ drop: __maybe_unused
         */
        if (flow == &p->link) {
                sch->q.qlen++;
-               return 0;
+               return NET_XMIT_SUCCESS;
        }
        tasklet_schedule(&p->task);
-       return NET_XMIT_BYPASS;
+       return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
 }
 
 /*
@@ -479,22 +448,29 @@ drop: __maybe_unused
 static void sch_atm_dequeue(unsigned long data)
 {
        struct Qdisc *sch = (struct Qdisc *)data;
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow;
        struct sk_buff *skb;
 
-       D2PRINTK("sch_atm_dequeue(sch %p,[qdisc %p])\n", sch, p);
-       for (flow = p->link.next; flow; flow = flow->next)
+       pr_debug("sch_atm_dequeue(sch %p,[qdisc %p])\n", sch, p);
+       list_for_each_entry(flow, &p->flows, list) {
+               if (flow == &p->link)
+                       continue;
                /*
                 * If traffic is properly shaped, this won't generate nasty
                 * little bursts. Otherwise, it may ... (but that's okay)
                 */
-               while ((skb = flow->q->dequeue(flow->q))) {
-                       if (!atm_may_send(flow->vcc, skb->truesize)) {
-                               (void)flow->q->ops->requeue(skb, flow->q);
+               while ((skb = flow->q->ops->peek(flow->q))) {
+                       if (!atm_may_send(flow->vcc, skb->truesize))
                                break;
-                       }
-                       D2PRINTK("atm_tc_dequeue: sending on class %p\n", flow);
+
+                       skb = qdisc_dequeue_peeked(flow->q);
+                       if (unlikely(!skb))
+                               break;
+
+                       qdisc_bstats_update(sch, skb);
+                       bstats_update(&flow->bstats, skb);
+                       pr_debug("atm_tc_dequeue: sending on class %p\n", flow);
                        /* remove any LL header somebody else has attached */
                        skb_pull(skb, skb_network_offset(skb));
                        if (skb_headroom(skb) < flow->hdr_len) {
@@ -506,7 +482,7 @@ static void sch_atm_dequeue(unsigned long data)
                                        continue;
                                skb = new;
                        }
-                       D2PRINTK("sch_atm_dequeue: ip %p, data %p\n",
+                       pr_debug("sch_atm_dequeue: ip %p, data %p\n",
                                 skb_network_header(skb), skb->data);
                        ATM_SKB(skb)->vcc = flow->vcc;
                        memcpy(skb_push(skb, flow->hdr_len), flow->hdr,
@@ -516,102 +492,91 @@ static void sch_atm_dequeue(unsigned long data)
                        /* atm.atm_options are already set by atm_tc_enqueue */
                        flow->vcc->send(flow->vcc, skb);
                }
+       }
 }
 
 static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct sk_buff *skb;
 
-       D2PRINTK("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
+       pr_debug("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
        tasklet_schedule(&p->task);
-       skb = p->link.q->dequeue(p->link.q);
+       skb = qdisc_dequeue_peeked(p->link.q);
        if (skb)
                sch->q.qlen--;
        return skb;
 }
 
-static int atm_tc_requeue(struct sk_buff *skb, struct Qdisc *sch)
+static struct sk_buff *atm_tc_peek(struct Qdisc *sch)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
-       int ret;
+       struct atm_qdisc_data *p = qdisc_priv(sch);
 
-       D2PRINTK("atm_tc_requeue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
-       ret = p->link.q->ops->requeue(skb, p->link.q);
-       if (!ret) {
-               sch->q.qlen++;
-               sch->qstats.requeues++;
-       } else {
-               sch->qstats.drops++;
-               p->link.qstats.drops++;
-       }
-       return ret;
+       pr_debug("atm_tc_peek(sch %p,[qdisc %p])\n", sch, p);
+
+       return p->link.q->ops->peek(p->link.q);
 }
 
 static unsigned int atm_tc_drop(struct Qdisc *sch)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow;
        unsigned int len;
 
-       DPRINTK("atm_tc_drop(sch %p,[qdisc %p])\n", sch, p);
-       for (flow = p->flows; flow; flow = flow->next)
+       pr_debug("atm_tc_drop(sch %p,[qdisc %p])\n", sch, p);
+       list_for_each_entry(flow, &p->flows, list) {
                if (flow->q->ops->drop && (len = flow->q->ops->drop(flow->q)))
                        return len;
+       }
        return 0;
 }
 
-static int atm_tc_init(struct Qdisc *sch, struct rtattr *opt)
+static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
-
-       DPRINTK("atm_tc_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt);
-       p->flows = &p->link;
-       if (!(p->link.q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops,
-                                           sch->handle)))
+       struct atm_qdisc_data *p = qdisc_priv(sch);
+
+       pr_debug("atm_tc_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt);
+       INIT_LIST_HEAD(&p->flows);
+       INIT_LIST_HEAD(&p->link.list);
+       list_add(&p->link.list, &p->flows);
+       p->link.q = qdisc_create_dflt(sch->dev_queue,
+                                     &pfifo_qdisc_ops, sch->handle);
+       if (!p->link.q)
                p->link.q = &noop_qdisc;
-       DPRINTK("atm_tc_init: link (%p) qdisc %p\n", &p->link, p->link.q);
+       pr_debug("atm_tc_init: link (%p) qdisc %p\n", &p->link, p->link.q);
        p->link.filter_list = NULL;
        p->link.vcc = NULL;
        p->link.sock = NULL;
        p->link.classid = sch->handle;
        p->link.ref = 1;
-       p->link.next = NULL;
        tasklet_init(&p->task, sch_atm_dequeue, (unsigned long)sch);
        return 0;
 }
 
 static void atm_tc_reset(struct Qdisc *sch)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow;
 
-       DPRINTK("atm_tc_reset(sch %p,[qdisc %p])\n", sch, p);
-       for (flow = p->flows; flow; flow = flow->next)
+       pr_debug("atm_tc_reset(sch %p,[qdisc %p])\n", sch, p);
+       list_for_each_entry(flow, &p->flows, list)
                qdisc_reset(flow->q);
        sch->q.qlen = 0;
 }
 
 static void atm_tc_destroy(struct Qdisc *sch)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
-       struct atm_flow_data *flow;
+       struct atm_qdisc_data *p = qdisc_priv(sch);
+       struct atm_flow_data *flow, *tmp;
 
-       DPRINTK("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p);
-       /* races ? */
-       while ((flow = p->flows)) {
-               tcf_destroy_chain(flow->filter_list);
-               flow->filter_list = NULL;
+       pr_debug("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p);
+       list_for_each_entry(flow, &p->flows, list)
+               tcf_destroy_chain(&flow->filter_list);
+
+       list_for_each_entry_safe(flow, tmp, &p->flows, list) {
                if (flow->ref > 1)
-                       printk(KERN_ERR "atm_destroy: %p->ref = %d\n", flow,
-                              flow->ref);
+                       pr_err("atm_destroy: %p->ref = %d\n", flow, flow->ref);
                atm_tc_put(sch, (unsigned long)flow);
-               if (p->flows == flow) {
-                       printk(KERN_ERR "atm_destroy: putting flow %p didn't "
-                              "kill it\n", flow);
-                       p->flows = flow->next;  /* brute force */
-                       break;
-               }
        }
        tasklet_kill(&p->task);
 }
@@ -619,20 +584,23 @@ static void atm_tc_destroy(struct Qdisc *sch)
 static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
                             struct sk_buff *skb, struct tcmsg *tcm)
 {
-       struct atm_qdisc_data *p = PRIV(sch);
+       struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow = (struct atm_flow_data *)cl;
-       unsigned char *b = skb_tail_pointer(skb);
-       struct rtattr *rta;
+       struct nlattr *nest;
 
-       DPRINTK("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
+       pr_debug("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
                sch, p, flow, skb, tcm);
-       if (!find_flow(p, flow))
+       if (list_empty(&flow->list))
                return -EINVAL;
        tcm->tcm_handle = flow->classid;
        tcm->tcm_info = flow->q->handle;
-       rta = (struct rtattr *)b;
-       RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
-       RTA_PUT(skb, TCA_ATM_HDR, flow->hdr_len, flow->hdr);
+
+       nest = nla_nest_start(skb, TCA_OPTIONS);
+       if (nest == NULL)
+               goto nla_put_failure;
+
+       if (nla_put(skb, TCA_ATM_HDR, flow->hdr_len, flow->hdr))
+               goto nla_put_failure;
        if (flow->vcc) {
                struct sockaddr_atmpvc pvc;
                int state;
@@ -641,22 +609,24 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
                pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number : -1;
                pvc.sap_addr.vpi = flow->vcc->vpi;
                pvc.sap_addr.vci = flow->vcc->vci;
-               RTA_PUT(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc);
+               if (nla_put(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc))
+                       goto nla_put_failure;
                state = ATM_VF2VS(flow->vcc->flags);
-               RTA_PUT(skb, TCA_ATM_STATE, sizeof(state), &state);
+               if (nla_put_u32(skb, TCA_ATM_STATE, state))
+                       goto nla_put_failure;
        }
-       if (flow->excess)
-               RTA_PUT(skb, TCA_ATM_EXCESS, sizeof(u32), &flow->classid);
-       else {
-               static u32 zero;
-
-               RTA_PUT(skb, TCA_ATM_EXCESS, sizeof(zero), &zero);
+       if (flow->excess) {
+               if (nla_put_u32(skb, TCA_ATM_EXCESS, flow->classid))
+                       goto nla_put_failure;
+       } else {
+               if (nla_put_u32(skb, TCA_ATM_EXCESS, 0))
+                       goto nla_put_failure;
        }
-       rta->rta_len = skb_tail_pointer(skb) - b;
+       nla_nest_end(skb, nest);
        return skb->len;
 
-rtattr_failure:
-       nlmsg_trim(skb, b);
+nla_put_failure:
+       nla_nest_cancel(skb, nest);
        return -1;
 }
 static int
@@ -679,7 +649,7 @@ static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb)
        return 0;
 }
 
-static struct Qdisc_class_ops atm_class_ops = {
+static const struct Qdisc_class_ops atm_class_ops = {
        .graft          = atm_tc_graft,
        .leaf           = atm_tc_leaf,
        .get            = atm_tc_get,
@@ -694,13 +664,13 @@ static struct Qdisc_class_ops atm_class_ops = {
        .dump_stats     = atm_tc_dump_class_stats,
 };
 
-static struct Qdisc_ops atm_qdisc_ops = {
+static struct Qdisc_ops atm_qdisc_ops __read_mostly = {
        .cl_ops         = &atm_class_ops,
        .id             = "atm",
        .priv_size      = sizeof(struct atm_qdisc_data),
        .enqueue        = atm_tc_enqueue,
        .dequeue        = atm_tc_dequeue,
-       .requeue        = atm_tc_requeue,
+       .peek           = atm_tc_peek,
        .drop           = atm_tc_drop,
        .init           = atm_tc_init,
        .reset          = atm_tc_reset,