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