This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / net / sched / sch_atm.c
1 /* net/sched/sch_atm.c - ATM VC selection "queueing discipline" */
2
3 /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
4
5
6 #include <linux/config.h>
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/string.h>
10 #include <linux/errno.h>
11 #include <linux/skbuff.h>
12 #include <linux/interrupt.h>
13 #include <linux/atmdev.h>
14 #include <linux/atmclip.h>
15 #include <linux/netdevice.h>
16 #include <linux/rtnetlink.h>
17 #include <linux/file.h> /* for fput */
18 #include <net/pkt_sched.h>
19 #include <net/sock.h>
20
21
22 extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
23
24 #if 0 /* control */
25 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
26 #else
27 #define DPRINTK(format,args...)
28 #endif
29
30 #if 0 /* data */
31 #define D2PRINTK(format,args...) printk(KERN_DEBUG format,##args)
32 #else
33 #define D2PRINTK(format,args...)
34 #endif
35
36
37 /*
38  * The ATM queuing discipline provides a framework for invoking classifiers
39  * (aka "filters"), which in turn select classes of this queuing discipline.
40  * Each class maps the flow(s) it is handling to a given VC. Multiple classes
41  * may share the same VC.
42  *
43  * When creating a class, VCs are specified by passing the number of the open
44  * socket descriptor by which the calling process references the VC. The kernel
45  * keeps the VC open at least until all classes using it are removed.
46  *
47  * In this file, most functions are named atm_tc_* to avoid confusion with all
48  * the atm_* in net/atm. This naming convention differs from what's used in the
49  * rest of net/sched.
50  *
51  * Known bugs:
52  *  - sometimes messes up the IP stack
53  *  - any manipulations besides the few operations described in the README, are
54  *    untested and likely to crash the system
55  *  - should lock the flow while there is data in the queue (?)
56  */
57
58
59 #define PRIV(sch) ((struct atm_qdisc_data *) (sch)->data)
60 #define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back))
61
62
63 struct atm_flow_data {
64         struct Qdisc            *q;             /* FIFO, TBF, etc. */
65         struct tcf_proto        *filter_list;
66         struct atm_vcc          *vcc;           /* VCC; NULL if VCC is closed */
67         void (*old_pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* chaining */
68         struct atm_qdisc_data   *parent;        /* parent qdisc */
69         struct socket           *sock;          /* for closing */
70         u32                     classid;        /* x:y type ID */
71         int                     ref;            /* reference count */
72         struct tc_stats         stats;
73         spinlock_t              *stats_lock;
74         struct atm_flow_data    *next;
75         struct atm_flow_data    *excess;        /* flow for excess traffic;
76                                                    NULL to set CLP instead */
77         int                     hdr_len;
78         unsigned char           hdr[0];         /* header data; MUST BE LAST */
79 };
80
81 struct atm_qdisc_data {
82         struct atm_flow_data    link;           /* unclassified skbs go here */
83         struct atm_flow_data    *flows;         /* NB: "link" is also on this
84                                                    list */
85         struct tasklet_struct   task;           /* requeue tasklet */
86 };
87
88
89 /* ------------------------- Class/flow operations ------------------------- */
90
91
92 static int find_flow(struct atm_qdisc_data *qdisc,struct atm_flow_data *flow)
93 {
94         struct atm_flow_data *walk;
95
96         DPRINTK("find_flow(qdisc %p,flow %p)\n",qdisc,flow);
97         for (walk = qdisc->flows; walk; walk = walk->next)
98                 if (walk == flow) return 1;
99         DPRINTK("find_flow: not found\n");
100         return 0;
101 }
102
103
104 static __inline__ struct atm_flow_data *lookup_flow(struct Qdisc *sch,
105     u32 classid)
106 {
107         struct atm_flow_data *flow;
108
109         for (flow = PRIV(sch)->flows; flow; flow = flow->next)
110                 if (flow->classid == classid) break;
111         return flow;
112 }
113
114
115 static int atm_tc_graft(struct Qdisc *sch,unsigned long arg,
116     struct Qdisc *new,struct Qdisc **old)
117 {
118         struct atm_qdisc_data *p = PRIV(sch);
119         struct atm_flow_data *flow = (struct atm_flow_data *) arg;
120
121         DPRINTK("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",sch,
122             p,flow,new,old);
123         if (!find_flow(p,flow)) return -EINVAL;
124         if (!new) new = &noop_qdisc;
125         *old = xchg(&flow->q,new);
126         if (*old) qdisc_reset(*old);
127         return 0;
128 }
129
130
131 static struct Qdisc *atm_tc_leaf(struct Qdisc *sch,unsigned long cl)
132 {
133         struct atm_flow_data *flow = (struct atm_flow_data *) cl;
134
135         DPRINTK("atm_tc_leaf(sch %p,flow %p)\n",sch,flow);
136         return flow ? flow->q : NULL;
137 }
138
139
140 static unsigned long atm_tc_get(struct Qdisc *sch,u32 classid)
141 {
142         struct atm_qdisc_data *p __attribute__((unused)) = PRIV(sch);
143         struct atm_flow_data *flow;
144
145         DPRINTK("atm_tc_get(sch %p,[qdisc %p],classid %x)\n",sch,p,classid);
146         flow = lookup_flow(sch,classid);
147         if (flow) flow->ref++;
148         DPRINTK("atm_tc_get: flow %p\n",flow);
149         return (unsigned long) flow;
150 }
151
152
153 static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
154     unsigned long parent, u32 classid)
155 {
156         return atm_tc_get(sch,classid);
157 }
158
159
160 static void destroy_filters(struct atm_flow_data *flow)
161 {
162         struct tcf_proto *filter;
163
164         while ((filter = flow->filter_list)) {
165                 DPRINTK("destroy_filters: destroying filter %p\n",filter);
166                 flow->filter_list = filter->next;
167                 tcf_destroy(filter);
168         }
169 }
170
171
172 /*
173  * atm_tc_put handles all destructions, including the ones that are explicitly
174  * requested (atm_tc_destroy, etc.). The assumption here is that we never drop
175  * anything that still seems to be in use.
176  */
177
178 static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
179 {
180         struct atm_qdisc_data *p = PRIV(sch);
181         struct atm_flow_data *flow = (struct atm_flow_data *) cl;
182         struct atm_flow_data **prev;
183
184         DPRINTK("atm_tc_put(sch %p,[qdisc %p],flow %p)\n",sch,p,flow);
185         if (--flow->ref) return;
186         DPRINTK("atm_tc_put: destroying\n");
187         for (prev = &p->flows; *prev; prev = &(*prev)->next)
188                 if (*prev == flow) break;
189         if (!*prev) {
190                 printk(KERN_CRIT "atm_tc_put: class %p not found\n",flow);
191                 return;
192         }
193         *prev = flow->next;
194         DPRINTK("atm_tc_put: qdisc %p\n",flow->q);
195         qdisc_destroy(flow->q);
196         destroy_filters(flow);
197         if (flow->sock) {
198                 DPRINTK("atm_tc_put: f_count %d\n",
199                     file_count(flow->sock->file));
200                 flow->vcc->pop = flow->old_pop;
201                 sockfd_put(flow->sock);
202         }
203         if (flow->excess) atm_tc_put(sch,(unsigned long) flow->excess);
204         if (flow != &p->link) kfree(flow);
205         /*
206          * If flow == &p->link, the qdisc no longer works at this point and
207          * needs to be removed. (By the caller of atm_tc_put.)
208          */
209 }
210
211
212 static void sch_atm_pop(struct atm_vcc *vcc,struct sk_buff *skb)
213 {
214         struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent;
215
216         D2PRINTK("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n",vcc,skb,p);
217         VCC2FLOW(vcc)->old_pop(vcc,skb);
218         tasklet_schedule(&p->task);
219 }
220
221 static const u8 llc_oui_ip[] = {
222         0xaa,           /* DSAP: non-ISO */
223         0xaa,           /* SSAP: non-ISO */
224         0x03,           /* Ctrl: Unnumbered Information Command PDU */
225         0x00,           /* OUI: EtherType */
226         0x00, 0x00,
227         0x08, 0x00 };   /* Ethertype IP (0800) */
228
229 static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
230     struct rtattr **tca, unsigned long *arg)
231 {
232         struct atm_qdisc_data *p = PRIV(sch);
233         struct atm_flow_data *flow = (struct atm_flow_data *) *arg;
234         struct atm_flow_data *excess = NULL;
235         struct rtattr *opt = tca[TCA_OPTIONS-1];
236         struct rtattr *tb[TCA_ATM_MAX];
237         struct socket *sock;
238         int fd,error,hdr_len;
239         void *hdr;
240
241         DPRINTK("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x,"
242             "flow %p,opt %p)\n",sch,p,classid,parent,flow,opt);
243         /*
244          * The concept of parents doesn't apply for this qdisc.
245          */
246         if (parent && parent != TC_H_ROOT && parent != sch->handle)
247                 return -EINVAL;
248         /*
249          * ATM classes cannot be changed. In order to change properties of the
250          * ATM connection, that socket needs to be modified directly (via the
251          * native ATM API. In order to send a flow to a different VC, the old
252          * class needs to be removed and a new one added. (This may be changed
253          * later.)
254          */
255         if (flow) return -EBUSY;
256         if (opt == NULL || rtattr_parse(tb,TCA_ATM_MAX,RTA_DATA(opt),
257             RTA_PAYLOAD(opt))) return -EINVAL;
258         if (!tb[TCA_ATM_FD-1] || RTA_PAYLOAD(tb[TCA_ATM_FD-1]) < sizeof(fd))
259                 return -EINVAL;
260         fd = *(int *) RTA_DATA(tb[TCA_ATM_FD-1]);
261         DPRINTK("atm_tc_change: fd %d\n",fd);
262         if (tb[TCA_ATM_HDR-1]) {
263                 hdr_len = RTA_PAYLOAD(tb[TCA_ATM_HDR-1]);
264                 hdr = RTA_DATA(tb[TCA_ATM_HDR-1]);
265         }
266         else {
267                 hdr_len = RFC1483LLC_LEN;
268                 hdr = NULL; /* default LLC/SNAP for IP */
269         }
270         if (!tb[TCA_ATM_EXCESS-1]) excess = NULL;
271         else {
272                 if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS-1]) != sizeof(u32))
273                         return -EINVAL;
274                 excess = (struct atm_flow_data *) atm_tc_get(sch,
275                     *(u32 *) RTA_DATA(tb[TCA_ATM_EXCESS-1]));
276                 if (!excess) return -ENOENT;
277         }
278         DPRINTK("atm_tc_change: type %d, payload %d, hdr_len %d\n",
279             opt->rta_type,RTA_PAYLOAD(opt),hdr_len);
280         if (!(sock = sockfd_lookup(fd,&error))) return error; /* f_count++ */
281         DPRINTK("atm_tc_change: f_count %d\n",file_count(sock->file));
282         if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) {
283                 error = -EPROTOTYPE;
284                 goto err_out;
285         }
286         /* @@@ should check if the socket is really operational or we'll crash
287            on vcc->send */
288         if (classid) {
289                 if (TC_H_MAJ(classid ^ sch->handle)) {
290                         DPRINTK("atm_tc_change: classid mismatch\n");
291                         error = -EINVAL;
292                         goto err_out;
293                 }
294                 if (find_flow(p,flow)) {
295                         error = -EEXIST;
296                         goto err_out;
297                 }
298         }
299         else {
300                 int i;
301                 unsigned long cl;
302
303                 for (i = 1; i < 0x8000; i++) {
304                         classid = TC_H_MAKE(sch->handle,0x8000 | i);
305                         if (!(cl = atm_tc_get(sch,classid))) break;
306                         atm_tc_put(sch,cl);
307                 }
308         }
309         DPRINTK("atm_tc_change: new id %x\n",classid);
310         flow = kmalloc(sizeof(struct atm_flow_data)+hdr_len,GFP_KERNEL);
311         DPRINTK("atm_tc_change: flow %p\n",flow);
312         if (!flow) {
313                 error = -ENOBUFS;
314                 goto err_out;
315         }
316         memset(flow,0,sizeof(*flow));
317         flow->filter_list = NULL;
318         if (!(flow->q = qdisc_create_dflt(sch->dev,&pfifo_qdisc_ops)))
319                 flow->q = &noop_qdisc;
320         DPRINTK("atm_tc_change: qdisc %p\n",flow->q);
321         flow->sock = sock;
322         flow->vcc = ATM_SD(sock); /* speedup */
323         flow->vcc->user_back = flow;
324         DPRINTK("atm_tc_change: vcc %p\n",flow->vcc);
325         flow->old_pop = flow->vcc->pop;
326         flow->parent = p;
327         flow->vcc->pop = sch_atm_pop;
328         flow->classid = classid;
329         flow->ref = 1;
330         flow->excess = excess;
331         flow->next = p->link.next;
332         p->link.next = flow;
333         flow->hdr_len = hdr_len;
334         if (hdr)
335                 memcpy(flow->hdr,hdr,hdr_len);
336         else
337                 memcpy(flow->hdr,llc_oui_ip,sizeof(llc_oui_ip));
338         *arg = (unsigned long) flow;
339         return 0;
340 err_out:
341         if (excess) atm_tc_put(sch,(unsigned long) excess);
342         sockfd_put(sock);
343         return error;
344 }
345
346
347 static int atm_tc_delete(struct Qdisc *sch,unsigned long arg)
348 {
349         struct atm_qdisc_data *p = PRIV(sch);
350         struct atm_flow_data *flow = (struct atm_flow_data *) arg;
351
352         DPRINTK("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n",sch,p,flow);
353         if (!find_flow(PRIV(sch),flow)) return -EINVAL;
354         if (flow->filter_list || flow == &p->link) return -EBUSY;
355         /*
356          * Reference count must be 2: one for "keepalive" (set at class
357          * creation), and one for the reference held when calling delete.
358          */
359         if (flow->ref < 2) {
360                 printk(KERN_ERR "atm_tc_delete: flow->ref == %d\n",flow->ref);
361                 return -EINVAL;
362         }
363         if (flow->ref > 2) return -EBUSY; /* catch references via excess, etc.*/
364         atm_tc_put(sch,arg);
365         return 0;
366 }
367
368
369 static void atm_tc_walk(struct Qdisc *sch,struct qdisc_walker *walker)
370 {
371         struct atm_qdisc_data *p = PRIV(sch);
372         struct atm_flow_data *flow;
373
374         DPRINTK("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n",sch,p,walker);
375         if (walker->stop) return;
376         for (flow = p->flows; flow; flow = flow->next) {
377                 if (walker->count >= walker->skip)
378                         if (walker->fn(sch,(unsigned long) flow,walker) < 0) {
379                                 walker->stop = 1;
380                                 break;
381                         }
382                 walker->count++;
383         }
384 }
385
386
387 static struct tcf_proto **atm_tc_find_tcf(struct Qdisc *sch,unsigned long cl)
388 {
389         struct atm_qdisc_data *p = PRIV(sch);
390         struct atm_flow_data *flow = (struct atm_flow_data *) cl;
391
392         DPRINTK("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n",sch,p,flow);
393         return flow ? &flow->filter_list : &p->link.filter_list;
394 }
395
396
397 /* --------------------------- Qdisc operations ---------------------------- */
398
399
400 static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
401 {
402         struct atm_qdisc_data *p = PRIV(sch);
403         struct atm_flow_data *flow = NULL ; /* @@@ */
404         struct tcf_result res;
405         int result;
406         int ret = NET_XMIT_POLICED;
407
408         D2PRINTK("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n",skb,sch,p);
409         result = TC_POLICE_OK; /* be nice to gcc */
410         if (TC_H_MAJ(skb->priority) != sch->handle ||
411             !(flow = (struct atm_flow_data *) atm_tc_get(sch,skb->priority)))
412                 for (flow = p->flows; flow; flow = flow->next)
413                         if (flow->filter_list) {
414                                 result = tc_classify(skb,flow->filter_list,
415                                     &res);
416                                 if (result < 0) continue;
417                                 flow = (struct atm_flow_data *) res.class;
418                                 if (!flow) flow = lookup_flow(sch,res.classid);
419                                 break;
420                         }
421         if (!flow) flow = &p->link;
422         else {
423                 if (flow->vcc)
424                         ATM_SKB(skb)->atm_options = flow->vcc->atm_options;
425                         /*@@@ looks good ... but it's not supposed to work :-)*/
426 #ifdef CONFIG_NET_CLS_POLICE
427                 switch (result) {
428                         case TC_POLICE_SHOT:
429                                 kfree_skb(skb);
430                                 break;
431                         case TC_POLICE_RECLASSIFY:
432                                 if (flow->excess) flow = flow->excess;
433                                 else {
434                                         ATM_SKB(skb)->atm_options |=
435                                             ATM_ATMOPT_CLP;
436                                         break;
437                                 }
438                                 /* fall through */
439                         case TC_POLICE_OK:
440                                 /* fall through */
441                         default:
442                                 break;
443                 }
444 #endif
445         }
446         if (
447 #ifdef CONFIG_NET_CLS_POLICE
448             result == TC_POLICE_SHOT ||
449 #endif
450             (ret = flow->q->enqueue(skb,flow->q)) != 0) {
451                 sch->stats.drops++;
452                 if (flow) flow->stats.drops++;
453                 return ret;
454         }
455         sch->stats.bytes += skb->len;
456         sch->stats.packets++;
457         flow->stats.bytes += skb->len;
458         flow->stats.packets++;
459         /*
460          * Okay, this may seem weird. We pretend we've dropped the packet if
461          * it goes via ATM. The reason for this is that the outer qdisc
462          * expects to be able to q->dequeue the packet later on if we return
463          * success at this place. Also, sch->q.qdisc needs to reflect whether
464          * there is a packet egligible for dequeuing or not. Note that the
465          * statistics of the outer qdisc are necessarily wrong because of all
466          * this. There's currently no correct solution for this.
467          */
468         if (flow == &p->link) {
469                 sch->q.qlen++;
470                 return 0;
471         }
472         tasklet_schedule(&p->task);
473         return NET_XMIT_BYPASS;
474 }
475
476
477 /*
478  * Dequeue packets and send them over ATM. Note that we quite deliberately
479  * avoid checking net_device's flow control here, simply because sch_atm
480  * uses its own channels, which have nothing to do with any CLIP/LANE/or
481  * non-ATM interfaces.
482  */
483
484
485 static void sch_atm_dequeue(unsigned long data)
486 {
487         struct Qdisc *sch = (struct Qdisc *) data;
488         struct atm_qdisc_data *p = PRIV(sch);
489         struct atm_flow_data *flow;
490         struct sk_buff *skb;
491
492         D2PRINTK("sch_atm_dequeue(sch %p,[qdisc %p])\n",sch,p);
493         for (flow = p->link.next; flow; flow = flow->next)
494                 /*
495                  * If traffic is properly shaped, this won't generate nasty
496                  * little bursts. Otherwise, it may ... (but that's okay)
497                  */
498                 while ((skb = flow->q->dequeue(flow->q))) {
499                         if (!atm_may_send(flow->vcc,skb->truesize)) {
500                                 (void) flow->q->ops->requeue(skb,flow->q);
501                                 break;
502                         }
503                         D2PRINTK("atm_tc_dequeue: sending on class %p\n",flow);
504                         /* remove any LL header somebody else has attached */
505                         skb_pull(skb,(char *) skb->nh.iph-(char *) skb->data);
506                         if (skb_headroom(skb) < flow->hdr_len) {
507                                 struct sk_buff *new;
508
509                                 new = skb_realloc_headroom(skb,flow->hdr_len);
510                                 dev_kfree_skb(skb);
511                                 if (!new) continue;
512                                 skb = new;
513                         }
514                         D2PRINTK("sch_atm_dequeue: ip %p, data %p\n",
515                             skb->nh.iph,skb->data);
516                         ATM_SKB(skb)->vcc = flow->vcc;
517                         memcpy(skb_push(skb,flow->hdr_len),flow->hdr,
518                             flow->hdr_len);
519                         atomic_add(skb->truesize,
520                                    &flow->vcc->sk->sk_wmem_alloc);
521                         /* atm.atm_options are already set by atm_tc_enqueue */
522                         (void) flow->vcc->send(flow->vcc,skb);
523                 }
524 }
525
526
527 static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
528 {
529         struct atm_qdisc_data *p = PRIV(sch);
530         struct sk_buff *skb;
531
532         D2PRINTK("atm_tc_dequeue(sch %p,[qdisc %p])\n",sch,p);
533         tasklet_schedule(&p->task);
534         skb = p->link.q->dequeue(p->link.q);
535         if (skb) sch->q.qlen--;
536         return skb;
537 }
538
539
540 static int atm_tc_requeue(struct sk_buff *skb,struct Qdisc *sch)
541 {
542         struct atm_qdisc_data *p = PRIV(sch);
543         int ret;
544
545         D2PRINTK("atm_tc_requeue(skb %p,sch %p,[qdisc %p])\n",skb,sch,p);
546         ret = p->link.q->ops->requeue(skb,p->link.q);
547         if (!ret) sch->q.qlen++;
548         else {
549                 sch->stats.drops++;
550                 p->link.stats.drops++;
551         }
552         return ret;
553 }
554
555
556 static unsigned int atm_tc_drop(struct Qdisc *sch)
557 {
558         struct atm_qdisc_data *p = PRIV(sch);
559         struct atm_flow_data *flow;
560         unsigned int len;
561
562         DPRINTK("atm_tc_drop(sch %p,[qdisc %p])\n",sch,p);
563         for (flow = p->flows; flow; flow = flow->next)
564                 if (flow->q->ops->drop && (len = flow->q->ops->drop(flow->q)))
565                         return len;
566         return 0;
567 }
568
569
570 static int atm_tc_init(struct Qdisc *sch,struct rtattr *opt)
571 {
572         struct atm_qdisc_data *p = PRIV(sch);
573
574         DPRINTK("atm_tc_init(sch %p,[qdisc %p],opt %p)\n",sch,p,opt);
575         memset(p,0,sizeof(*p));
576         p->flows = &p->link;
577         if(!(p->link.q = qdisc_create_dflt(sch->dev,&pfifo_qdisc_ops)))
578                 p->link.q = &noop_qdisc;
579         DPRINTK("atm_tc_init: link (%p) qdisc %p\n",&p->link,p->link.q);
580         p->link.filter_list = NULL;
581         p->link.vcc = NULL;
582         p->link.sock = NULL;
583         p->link.classid = sch->handle;
584         p->link.ref = 1;
585         p->link.next = NULL;
586         tasklet_init(&p->task,sch_atm_dequeue,(unsigned long) sch);
587         return 0;
588 }
589
590
591 static void atm_tc_reset(struct Qdisc *sch)
592 {
593         struct atm_qdisc_data *p = PRIV(sch);
594         struct atm_flow_data *flow;
595
596         DPRINTK("atm_tc_reset(sch %p,[qdisc %p])\n",sch,p);
597         for (flow = p->flows; flow; flow = flow->next) qdisc_reset(flow->q);
598         sch->q.qlen = 0;
599 }
600
601
602 static void atm_tc_destroy(struct Qdisc *sch)
603 {
604         struct atm_qdisc_data *p = PRIV(sch);
605         struct atm_flow_data *flow;
606
607         DPRINTK("atm_tc_destroy(sch %p,[qdisc %p])\n",sch,p);
608         /* races ? */
609         while ((flow = p->flows)) {
610                 destroy_filters(flow);
611                 if (flow->ref > 1)
612                         printk(KERN_ERR "atm_destroy: %p->ref = %d\n",flow,
613                             flow->ref);
614                 atm_tc_put(sch,(unsigned long) flow);
615                 if (p->flows == flow) {
616                         printk(KERN_ERR "atm_destroy: putting flow %p didn't "
617                             "kill it\n",flow);
618                         p->flows = flow->next; /* brute force */
619                         break;
620                 }
621         }
622         tasklet_kill(&p->task);
623 }
624
625
626 static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
627     struct sk_buff *skb, struct tcmsg *tcm)
628 {
629         struct atm_qdisc_data *p = PRIV(sch);
630         struct atm_flow_data *flow = (struct atm_flow_data *) cl;
631         unsigned char *b = skb->tail;
632         struct rtattr *rta;
633
634         DPRINTK("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
635             sch,p,flow,skb,tcm);
636         if (!find_flow(p,flow)) return -EINVAL;
637         tcm->tcm_handle = flow->classid;
638         rta = (struct rtattr *) b;
639         RTA_PUT(skb,TCA_OPTIONS,0,NULL);
640         RTA_PUT(skb,TCA_ATM_HDR,flow->hdr_len,flow->hdr);
641         if (flow->vcc) {
642                 struct sockaddr_atmpvc pvc;
643                 int state;
644
645                 pvc.sap_family = AF_ATMPVC;
646                 pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number : -1;
647                 pvc.sap_addr.vpi = flow->vcc->vpi;
648                 pvc.sap_addr.vci = flow->vcc->vci;
649                 RTA_PUT(skb,TCA_ATM_ADDR,sizeof(pvc),&pvc);
650                 state = ATM_VF2VS(flow->vcc->flags);
651                 RTA_PUT(skb,TCA_ATM_STATE,sizeof(state),&state);
652         }
653         if (flow->excess)
654                 RTA_PUT(skb,TCA_ATM_EXCESS,sizeof(u32),&flow->classid);
655         else {
656                 static u32 zero;
657
658                 RTA_PUT(skb,TCA_ATM_EXCESS,sizeof(zero),&zero);
659         }
660         rta->rta_len = skb->tail-b;
661         return skb->len;
662
663 rtattr_failure:
664         skb_trim(skb,b-skb->data);
665         return -1;
666 }
667
668 static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb)
669 {
670         return 0;
671 }
672
673 static struct Qdisc_class_ops atm_class_ops = {
674         .graft          =       atm_tc_graft,
675         .leaf           =       atm_tc_leaf,
676         .get            =       atm_tc_get,
677         .put            =       atm_tc_put,
678         .change         =       atm_tc_change,
679         .delete         =       atm_tc_delete,
680         .walk           =       atm_tc_walk,
681         .tcf_chain      =       atm_tc_find_tcf,
682         .bind_tcf       =       atm_tc_bind_filter,
683         .unbind_tcf     =       atm_tc_put,
684         .dump           =       atm_tc_dump_class,
685 };
686
687 static struct Qdisc_ops atm_qdisc_ops = {
688         .next           =       NULL,
689         .cl_ops         =       &atm_class_ops,
690         .id             =       "atm",
691         .priv_size      =       sizeof(struct atm_qdisc_data),
692         .enqueue        =       atm_tc_enqueue,
693         .dequeue        =       atm_tc_dequeue,
694         .requeue        =       atm_tc_requeue,
695         .drop           =       atm_tc_drop,
696         .init           =       atm_tc_init,
697         .reset          =       atm_tc_reset,
698         .destroy        =       atm_tc_destroy,
699         .change         =       NULL,
700         .dump           =       atm_tc_dump,
701         .owner          =       THIS_MODULE,
702 };
703
704
705 static int __init atm_init(void)
706 {
707         return register_qdisc(&atm_qdisc_ops);
708 }
709
710 static void __exit atm_exit(void) 
711 {
712         unregister_qdisc(&atm_qdisc_ops);
713 }
714
715 module_init(atm_init)
716 module_exit(atm_exit)