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