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