[NET_SCHED]: Remove unnecessary stats_lock pointers
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / sched / sch_atm.c
blob16fe802a66f778bc3afed2e5c6fc636aed392742
1 /* net/sched/sch_atm.c - ATM VC selection "queueing discipline" */
3 /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
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>
22 extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
24 #if 0 /* control */
25 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
26 #else
27 #define DPRINTK(format,args...)
28 #endif
30 #if 0 /* data */
31 #define D2PRINTK(format,args...) printk(KERN_DEBUG format,##args)
32 #else
33 #define D2PRINTK(format,args...)
34 #endif
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.
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.
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.
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 (?)
59 #define PRIV(sch) qdisc_priv(sch)
60 #define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back))
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 struct atm_flow_data *next;
75 struct atm_flow_data *excess; /* flow for excess traffic;
76 NULL to set CLP instead */
77 int hdr_len;
78 unsigned char hdr[0]; /* header data; MUST BE LAST */
81 struct atm_qdisc_data {
82 struct atm_flow_data link; /* unclassified skbs go here */
83 struct atm_flow_data *flows; /* NB: "link" is also on this
84 list */
85 struct tasklet_struct task; /* requeue tasklet */
89 /* ------------------------- Class/flow operations ------------------------- */
92 static int find_flow(struct atm_qdisc_data *qdisc,struct atm_flow_data *flow)
94 struct atm_flow_data *walk;
96 DPRINTK("find_flow(qdisc %p,flow %p)\n",qdisc,flow);
97 for (walk = qdisc->flows; walk; walk = walk->next)
98 if (walk == flow) return 1;
99 DPRINTK("find_flow: not found\n");
100 return 0;
104 static __inline__ struct atm_flow_data *lookup_flow(struct Qdisc *sch,
105 u32 classid)
107 struct atm_qdisc_data *p = PRIV(sch);
108 struct atm_flow_data *flow;
110 for (flow = p->flows; flow; flow = flow->next)
111 if (flow->classid == classid) break;
112 return flow;
116 static int atm_tc_graft(struct Qdisc *sch,unsigned long arg,
117 struct Qdisc *new,struct Qdisc **old)
119 struct atm_qdisc_data *p = PRIV(sch);
120 struct atm_flow_data *flow = (struct atm_flow_data *) arg;
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;
132 static struct Qdisc *atm_tc_leaf(struct Qdisc *sch,unsigned long cl)
134 struct atm_flow_data *flow = (struct atm_flow_data *) cl;
136 DPRINTK("atm_tc_leaf(sch %p,flow %p)\n",sch,flow);
137 return flow ? flow->q : NULL;
141 static unsigned long atm_tc_get(struct Qdisc *sch,u32 classid)
143 struct atm_qdisc_data *p __attribute__((unused)) = PRIV(sch);
144 struct atm_flow_data *flow;
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;
154 static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
155 unsigned long parent, u32 classid)
157 return atm_tc_get(sch,classid);
161 * atm_tc_put handles all destructions, including the ones that are explicitly
162 * requested (atm_tc_destroy, etc.). The assumption here is that we never drop
163 * anything that still seems to be in use.
166 static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
168 struct atm_qdisc_data *p = PRIV(sch);
169 struct atm_flow_data *flow = (struct atm_flow_data *) cl;
170 struct atm_flow_data **prev;
172 DPRINTK("atm_tc_put(sch %p,[qdisc %p],flow %p)\n",sch,p,flow);
173 if (--flow->ref) return;
174 DPRINTK("atm_tc_put: destroying\n");
175 for (prev = &p->flows; *prev; prev = &(*prev)->next)
176 if (*prev == flow) break;
177 if (!*prev) {
178 printk(KERN_CRIT "atm_tc_put: class %p not found\n",flow);
179 return;
181 *prev = flow->next;
182 DPRINTK("atm_tc_put: qdisc %p\n",flow->q);
183 qdisc_destroy(flow->q);
184 tcf_destroy_chain(flow->filter_list);
185 if (flow->sock) {
186 DPRINTK("atm_tc_put: f_count %d\n",
187 file_count(flow->sock->file));
188 flow->vcc->pop = flow->old_pop;
189 sockfd_put(flow->sock);
191 if (flow->excess) atm_tc_put(sch,(unsigned long) flow->excess);
192 if (flow != &p->link) kfree(flow);
194 * If flow == &p->link, the qdisc no longer works at this point and
195 * needs to be removed. (By the caller of atm_tc_put.)
200 static void sch_atm_pop(struct atm_vcc *vcc,struct sk_buff *skb)
202 struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent;
204 D2PRINTK("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n",vcc,skb,p);
205 VCC2FLOW(vcc)->old_pop(vcc,skb);
206 tasklet_schedule(&p->task);
209 static const u8 llc_oui_ip[] = {
210 0xaa, /* DSAP: non-ISO */
211 0xaa, /* SSAP: non-ISO */
212 0x03, /* Ctrl: Unnumbered Information Command PDU */
213 0x00, /* OUI: EtherType */
214 0x00, 0x00,
215 0x08, 0x00 }; /* Ethertype IP (0800) */
217 static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
218 struct rtattr **tca, unsigned long *arg)
220 struct atm_qdisc_data *p = PRIV(sch);
221 struct atm_flow_data *flow = (struct atm_flow_data *) *arg;
222 struct atm_flow_data *excess = NULL;
223 struct rtattr *opt = tca[TCA_OPTIONS-1];
224 struct rtattr *tb[TCA_ATM_MAX];
225 struct socket *sock;
226 int fd,error,hdr_len;
227 void *hdr;
229 DPRINTK("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x,"
230 "flow %p,opt %p)\n",sch,p,classid,parent,flow,opt);
232 * The concept of parents doesn't apply for this qdisc.
234 if (parent && parent != TC_H_ROOT && parent != sch->handle)
235 return -EINVAL;
237 * ATM classes cannot be changed. In order to change properties of the
238 * ATM connection, that socket needs to be modified directly (via the
239 * native ATM API. In order to send a flow to a different VC, the old
240 * class needs to be removed and a new one added. (This may be changed
241 * later.)
243 if (flow) return -EBUSY;
244 if (opt == NULL || rtattr_parse_nested(tb, TCA_ATM_MAX, opt))
245 return -EINVAL;
246 if (!tb[TCA_ATM_FD-1] || RTA_PAYLOAD(tb[TCA_ATM_FD-1]) < sizeof(fd))
247 return -EINVAL;
248 fd = *(int *) RTA_DATA(tb[TCA_ATM_FD-1]);
249 DPRINTK("atm_tc_change: fd %d\n",fd);
250 if (tb[TCA_ATM_HDR-1]) {
251 hdr_len = RTA_PAYLOAD(tb[TCA_ATM_HDR-1]);
252 hdr = RTA_DATA(tb[TCA_ATM_HDR-1]);
254 else {
255 hdr_len = RFC1483LLC_LEN;
256 hdr = NULL; /* default LLC/SNAP for IP */
258 if (!tb[TCA_ATM_EXCESS-1]) excess = NULL;
259 else {
260 if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS-1]) != sizeof(u32))
261 return -EINVAL;
262 excess = (struct atm_flow_data *) atm_tc_get(sch,
263 *(u32 *) RTA_DATA(tb[TCA_ATM_EXCESS-1]));
264 if (!excess) return -ENOENT;
266 DPRINTK("atm_tc_change: type %d, payload %d, hdr_len %d\n",
267 opt->rta_type,RTA_PAYLOAD(opt),hdr_len);
268 if (!(sock = sockfd_lookup(fd,&error))) return error; /* f_count++ */
269 DPRINTK("atm_tc_change: f_count %d\n",file_count(sock->file));
270 if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) {
271 error = -EPROTOTYPE;
272 goto err_out;
274 /* @@@ should check if the socket is really operational or we'll crash
275 on vcc->send */
276 if (classid) {
277 if (TC_H_MAJ(classid ^ sch->handle)) {
278 DPRINTK("atm_tc_change: classid mismatch\n");
279 error = -EINVAL;
280 goto err_out;
282 if (find_flow(p,flow)) {
283 error = -EEXIST;
284 goto err_out;
287 else {
288 int i;
289 unsigned long cl;
291 for (i = 1; i < 0x8000; i++) {
292 classid = TC_H_MAKE(sch->handle,0x8000 | i);
293 if (!(cl = atm_tc_get(sch,classid))) break;
294 atm_tc_put(sch,cl);
297 DPRINTK("atm_tc_change: new id %x\n",classid);
298 flow = kmalloc(sizeof(struct atm_flow_data)+hdr_len,GFP_KERNEL);
299 DPRINTK("atm_tc_change: flow %p\n",flow);
300 if (!flow) {
301 error = -ENOBUFS;
302 goto err_out;
304 memset(flow,0,sizeof(*flow));
305 flow->filter_list = NULL;
306 if (!(flow->q = qdisc_create_dflt(sch->dev,&pfifo_qdisc_ops,classid)))
307 flow->q = &noop_qdisc;
308 DPRINTK("atm_tc_change: qdisc %p\n",flow->q);
309 flow->sock = sock;
310 flow->vcc = ATM_SD(sock); /* speedup */
311 flow->vcc->user_back = flow;
312 DPRINTK("atm_tc_change: vcc %p\n",flow->vcc);
313 flow->old_pop = flow->vcc->pop;
314 flow->parent = p;
315 flow->vcc->pop = sch_atm_pop;
316 flow->classid = classid;
317 flow->ref = 1;
318 flow->excess = excess;
319 flow->next = p->link.next;
320 p->link.next = flow;
321 flow->hdr_len = hdr_len;
322 if (hdr)
323 memcpy(flow->hdr,hdr,hdr_len);
324 else
325 memcpy(flow->hdr,llc_oui_ip,sizeof(llc_oui_ip));
326 *arg = (unsigned long) flow;
327 return 0;
328 err_out:
329 if (excess) atm_tc_put(sch,(unsigned long) excess);
330 sockfd_put(sock);
331 return error;
335 static int atm_tc_delete(struct Qdisc *sch,unsigned long arg)
337 struct atm_qdisc_data *p = PRIV(sch);
338 struct atm_flow_data *flow = (struct atm_flow_data *) arg;
340 DPRINTK("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n",sch,p,flow);
341 if (!find_flow(PRIV(sch),flow)) return -EINVAL;
342 if (flow->filter_list || flow == &p->link) return -EBUSY;
344 * Reference count must be 2: one for "keepalive" (set at class
345 * creation), and one for the reference held when calling delete.
347 if (flow->ref < 2) {
348 printk(KERN_ERR "atm_tc_delete: flow->ref == %d\n",flow->ref);
349 return -EINVAL;
351 if (flow->ref > 2) return -EBUSY; /* catch references via excess, etc.*/
352 atm_tc_put(sch,arg);
353 return 0;
357 static void atm_tc_walk(struct Qdisc *sch,struct qdisc_walker *walker)
359 struct atm_qdisc_data *p = PRIV(sch);
360 struct atm_flow_data *flow;
362 DPRINTK("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n",sch,p,walker);
363 if (walker->stop) return;
364 for (flow = p->flows; flow; flow = flow->next) {
365 if (walker->count >= walker->skip)
366 if (walker->fn(sch,(unsigned long) flow,walker) < 0) {
367 walker->stop = 1;
368 break;
370 walker->count++;
375 static struct tcf_proto **atm_tc_find_tcf(struct Qdisc *sch,unsigned long cl)
377 struct atm_qdisc_data *p = PRIV(sch);
378 struct atm_flow_data *flow = (struct atm_flow_data *) cl;
380 DPRINTK("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n",sch,p,flow);
381 return flow ? &flow->filter_list : &p->link.filter_list;
385 /* --------------------------- Qdisc operations ---------------------------- */
388 static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
390 struct atm_qdisc_data *p = PRIV(sch);
391 struct atm_flow_data *flow = NULL ; /* @@@ */
392 struct tcf_result res;
393 int result;
394 int ret = NET_XMIT_POLICED;
396 D2PRINTK("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n",skb,sch,p);
397 result = TC_POLICE_OK; /* be nice to gcc */
398 if (TC_H_MAJ(skb->priority) != sch->handle ||
399 !(flow = (struct atm_flow_data *) atm_tc_get(sch,skb->priority)))
400 for (flow = p->flows; flow; flow = flow->next)
401 if (flow->filter_list) {
402 result = tc_classify(skb,flow->filter_list,
403 &res);
404 if (result < 0) continue;
405 flow = (struct atm_flow_data *) res.class;
406 if (!flow) flow = lookup_flow(sch,res.classid);
407 break;
409 if (!flow) flow = &p->link;
410 else {
411 if (flow->vcc)
412 ATM_SKB(skb)->atm_options = flow->vcc->atm_options;
413 /*@@@ looks good ... but it's not supposed to work :-)*/
414 #ifdef CONFIG_NET_CLS_POLICE
415 switch (result) {
416 case TC_POLICE_SHOT:
417 kfree_skb(skb);
418 break;
419 case TC_POLICE_RECLASSIFY:
420 if (flow->excess) flow = flow->excess;
421 else {
422 ATM_SKB(skb)->atm_options |=
423 ATM_ATMOPT_CLP;
424 break;
426 /* fall through */
427 case TC_POLICE_OK:
428 /* fall through */
429 default:
430 break;
432 #endif
434 if (
435 #ifdef CONFIG_NET_CLS_POLICE
436 result == TC_POLICE_SHOT ||
437 #endif
438 (ret = flow->q->enqueue(skb,flow->q)) != 0) {
439 sch->qstats.drops++;
440 if (flow) flow->qstats.drops++;
441 return ret;
443 sch->bstats.bytes += skb->len;
444 sch->bstats.packets++;
445 flow->bstats.bytes += skb->len;
446 flow->bstats.packets++;
448 * Okay, this may seem weird. We pretend we've dropped the packet if
449 * it goes via ATM. The reason for this is that the outer qdisc
450 * expects to be able to q->dequeue the packet later on if we return
451 * success at this place. Also, sch->q.qdisc needs to reflect whether
452 * there is a packet egligible for dequeuing or not. Note that the
453 * statistics of the outer qdisc are necessarily wrong because of all
454 * this. There's currently no correct solution for this.
456 if (flow == &p->link) {
457 sch->q.qlen++;
458 return 0;
460 tasklet_schedule(&p->task);
461 return NET_XMIT_BYPASS;
466 * Dequeue packets and send them over ATM. Note that we quite deliberately
467 * avoid checking net_device's flow control here, simply because sch_atm
468 * uses its own channels, which have nothing to do with any CLIP/LANE/or
469 * non-ATM interfaces.
473 static void sch_atm_dequeue(unsigned long data)
475 struct Qdisc *sch = (struct Qdisc *) data;
476 struct atm_qdisc_data *p = PRIV(sch);
477 struct atm_flow_data *flow;
478 struct sk_buff *skb;
480 D2PRINTK("sch_atm_dequeue(sch %p,[qdisc %p])\n",sch,p);
481 for (flow = p->link.next; flow; flow = flow->next)
483 * If traffic is properly shaped, this won't generate nasty
484 * little bursts. Otherwise, it may ... (but that's okay)
486 while ((skb = flow->q->dequeue(flow->q))) {
487 if (!atm_may_send(flow->vcc,skb->truesize)) {
488 (void) flow->q->ops->requeue(skb,flow->q);
489 break;
491 D2PRINTK("atm_tc_dequeue: sending on class %p\n",flow);
492 /* remove any LL header somebody else has attached */
493 skb_pull(skb, skb_network_offset(skb));
494 if (skb_headroom(skb) < flow->hdr_len) {
495 struct sk_buff *new;
497 new = skb_realloc_headroom(skb,flow->hdr_len);
498 dev_kfree_skb(skb);
499 if (!new) continue;
500 skb = new;
502 D2PRINTK("sch_atm_dequeue: ip %p, data %p\n",
503 skb_network_header(skb), skb->data);
504 ATM_SKB(skb)->vcc = flow->vcc;
505 memcpy(skb_push(skb,flow->hdr_len),flow->hdr,
506 flow->hdr_len);
507 atomic_add(skb->truesize,
508 &sk_atm(flow->vcc)->sk_wmem_alloc);
509 /* atm.atm_options are already set by atm_tc_enqueue */
510 (void) flow->vcc->send(flow->vcc,skb);
515 static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
517 struct atm_qdisc_data *p = PRIV(sch);
518 struct sk_buff *skb;
520 D2PRINTK("atm_tc_dequeue(sch %p,[qdisc %p])\n",sch,p);
521 tasklet_schedule(&p->task);
522 skb = p->link.q->dequeue(p->link.q);
523 if (skb) sch->q.qlen--;
524 return skb;
528 static int atm_tc_requeue(struct sk_buff *skb,struct Qdisc *sch)
530 struct atm_qdisc_data *p = PRIV(sch);
531 int ret;
533 D2PRINTK("atm_tc_requeue(skb %p,sch %p,[qdisc %p])\n",skb,sch,p);
534 ret = p->link.q->ops->requeue(skb,p->link.q);
535 if (!ret) {
536 sch->q.qlen++;
537 sch->qstats.requeues++;
538 } else {
539 sch->qstats.drops++;
540 p->link.qstats.drops++;
542 return ret;
546 static unsigned int atm_tc_drop(struct Qdisc *sch)
548 struct atm_qdisc_data *p = PRIV(sch);
549 struct atm_flow_data *flow;
550 unsigned int len;
552 DPRINTK("atm_tc_drop(sch %p,[qdisc %p])\n",sch,p);
553 for (flow = p->flows; flow; flow = flow->next)
554 if (flow->q->ops->drop && (len = flow->q->ops->drop(flow->q)))
555 return len;
556 return 0;
560 static int atm_tc_init(struct Qdisc *sch,struct rtattr *opt)
562 struct atm_qdisc_data *p = PRIV(sch);
564 DPRINTK("atm_tc_init(sch %p,[qdisc %p],opt %p)\n",sch,p,opt);
565 p->flows = &p->link;
566 if(!(p->link.q = qdisc_create_dflt(sch->dev,&pfifo_qdisc_ops,
567 sch->handle)))
568 p->link.q = &noop_qdisc;
569 DPRINTK("atm_tc_init: link (%p) qdisc %p\n",&p->link,p->link.q);
570 p->link.filter_list = NULL;
571 p->link.vcc = NULL;
572 p->link.sock = NULL;
573 p->link.classid = sch->handle;
574 p->link.ref = 1;
575 p->link.next = NULL;
576 tasklet_init(&p->task,sch_atm_dequeue,(unsigned long) sch);
577 return 0;
581 static void atm_tc_reset(struct Qdisc *sch)
583 struct atm_qdisc_data *p = PRIV(sch);
584 struct atm_flow_data *flow;
586 DPRINTK("atm_tc_reset(sch %p,[qdisc %p])\n",sch,p);
587 for (flow = p->flows; flow; flow = flow->next) qdisc_reset(flow->q);
588 sch->q.qlen = 0;
592 static void atm_tc_destroy(struct Qdisc *sch)
594 struct atm_qdisc_data *p = PRIV(sch);
595 struct atm_flow_data *flow;
597 DPRINTK("atm_tc_destroy(sch %p,[qdisc %p])\n",sch,p);
598 /* races ? */
599 while ((flow = p->flows)) {
600 tcf_destroy_chain(flow->filter_list);
601 flow->filter_list = NULL;
602 if (flow->ref > 1)
603 printk(KERN_ERR "atm_destroy: %p->ref = %d\n",flow,
604 flow->ref);
605 atm_tc_put(sch,(unsigned long) flow);
606 if (p->flows == flow) {
607 printk(KERN_ERR "atm_destroy: putting flow %p didn't "
608 "kill it\n",flow);
609 p->flows = flow->next; /* brute force */
610 break;
613 tasklet_kill(&p->task);
617 static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
618 struct sk_buff *skb, struct tcmsg *tcm)
620 struct atm_qdisc_data *p = PRIV(sch);
621 struct atm_flow_data *flow = (struct atm_flow_data *) cl;
622 unsigned char *b = skb_tail_pointer(skb);
623 struct rtattr *rta;
625 DPRINTK("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
626 sch,p,flow,skb,tcm);
627 if (!find_flow(p,flow)) return -EINVAL;
628 tcm->tcm_handle = flow->classid;
629 tcm->tcm_info = flow->q->handle;
630 rta = (struct rtattr *) b;
631 RTA_PUT(skb,TCA_OPTIONS,0,NULL);
632 RTA_PUT(skb,TCA_ATM_HDR,flow->hdr_len,flow->hdr);
633 if (flow->vcc) {
634 struct sockaddr_atmpvc pvc;
635 int state;
637 pvc.sap_family = AF_ATMPVC;
638 pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number : -1;
639 pvc.sap_addr.vpi = flow->vcc->vpi;
640 pvc.sap_addr.vci = flow->vcc->vci;
641 RTA_PUT(skb,TCA_ATM_ADDR,sizeof(pvc),&pvc);
642 state = ATM_VF2VS(flow->vcc->flags);
643 RTA_PUT(skb,TCA_ATM_STATE,sizeof(state),&state);
645 if (flow->excess)
646 RTA_PUT(skb,TCA_ATM_EXCESS,sizeof(u32),&flow->classid);
647 else {
648 static u32 zero;
650 RTA_PUT(skb,TCA_ATM_EXCESS,sizeof(zero),&zero);
652 rta->rta_len = skb_tail_pointer(skb) - b;
653 return skb->len;
655 rtattr_failure:
656 nlmsg_trim(skb, b);
657 return -1;
659 static int
660 atm_tc_dump_class_stats(struct Qdisc *sch, unsigned long arg,
661 struct gnet_dump *d)
663 struct atm_flow_data *flow = (struct atm_flow_data *) arg;
665 flow->qstats.qlen = flow->q->q.qlen;
667 if (gnet_stats_copy_basic(d, &flow->bstats) < 0 ||
668 gnet_stats_copy_queue(d, &flow->qstats) < 0)
669 return -1;
671 return 0;
674 static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb)
676 return 0;
679 static struct Qdisc_class_ops atm_class_ops = {
680 .graft = atm_tc_graft,
681 .leaf = atm_tc_leaf,
682 .get = atm_tc_get,
683 .put = atm_tc_put,
684 .change = atm_tc_change,
685 .delete = atm_tc_delete,
686 .walk = atm_tc_walk,
687 .tcf_chain = atm_tc_find_tcf,
688 .bind_tcf = atm_tc_bind_filter,
689 .unbind_tcf = atm_tc_put,
690 .dump = atm_tc_dump_class,
691 .dump_stats = atm_tc_dump_class_stats,
694 static struct Qdisc_ops atm_qdisc_ops = {
695 .next = NULL,
696 .cl_ops = &atm_class_ops,
697 .id = "atm",
698 .priv_size = sizeof(struct atm_qdisc_data),
699 .enqueue = atm_tc_enqueue,
700 .dequeue = atm_tc_dequeue,
701 .requeue = atm_tc_requeue,
702 .drop = atm_tc_drop,
703 .init = atm_tc_init,
704 .reset = atm_tc_reset,
705 .destroy = atm_tc_destroy,
706 .change = NULL,
707 .dump = atm_tc_dump,
708 .owner = THIS_MODULE,
712 static int __init atm_init(void)
714 return register_qdisc(&atm_qdisc_ops);
717 static void __exit atm_exit(void)
719 unregister_qdisc(&atm_qdisc_ops);
722 module_init(atm_init)
723 module_exit(atm_exit)
724 MODULE_LICENSE("GPL");