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