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