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