vserver 1.9.5.x5
[linux-2.6.git] / net / sched / cls_u32.c
1 /*
2  * net/sched/cls_u32.c  Ugly (or Universal) 32bit key Packet Classifier.
3  *
4  *              This program is free software; you can redistribute it and/or
5  *              modify it under the terms of the GNU General Public License
6  *              as published by the Free Software Foundation; either version
7  *              2 of the License, or (at your option) any later version.
8  *
9  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10  *
11  *      The filters are packed to hash tables of key nodes
12  *      with a set of 32bit key/mask pairs at every node.
13  *      Nodes reference next level hash tables etc.
14  *
15  *      This scheme is the best universal classifier I managed to
16  *      invent; it is not super-fast, but it is not slow (provided you
17  *      program it correctly), and general enough.  And its relative
18  *      speed grows as the number of rules becomes larger.
19  *
20  *      It seems that it represents the best middle point between
21  *      speed and manageability both by human and by machine.
22  *
23  *      It is especially useful for link sharing combined with QoS;
24  *      pure RSVP doesn't need such a general approach and can use
25  *      much simpler (and faster) schemes, sort of cls_rsvp.c.
26  *
27  *      JHS: We should remove the CONFIG_NET_CLS_IND from here
28  *      eventually when the meta match extension is made available
29  *
30  *      nfmark match added by Catalin(ux aka Dino) BOIE <catab at umbrella.ro>
31  */
32
33 #include <asm/uaccess.h>
34 #include <asm/system.h>
35 #include <linux/bitops.h>
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/types.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/string.h>
42 #include <linux/mm.h>
43 #include <linux/socket.h>
44 #include <linux/sockios.h>
45 #include <linux/in.h>
46 #include <linux/errno.h>
47 #include <linux/interrupt.h>
48 #include <linux/if_ether.h>
49 #include <linux/inet.h>
50 #include <linux/netdevice.h>
51 #include <linux/etherdevice.h>
52 #include <linux/notifier.h>
53 #include <linux/rtnetlink.h>
54 #include <net/ip.h>
55 #include <net/route.h>
56 #include <linux/skbuff.h>
57 #include <net/sock.h>
58 #include <net/act_api.h>
59 #include <net/pkt_cls.h>
60
61
62 struct tc_u32_mark
63 {
64         u32             val;
65         u32             mask;
66         u32             success;
67 };
68
69 struct tc_u_knode
70 {
71         struct tc_u_knode       *next;
72         u32                     handle;
73         struct tc_u_hnode       *ht_up;
74         struct tcf_exts         exts;
75 #ifdef CONFIG_NET_CLS_IND
76         char                     indev[IFNAMSIZ];
77 #endif
78         u8                      fshift;
79         struct tcf_result       res;
80         struct tc_u_hnode       *ht_down;
81 #ifdef CONFIG_CLS_U32_PERF
82         struct tc_u32_pcnt      *pf;
83 #endif
84 #ifdef CONFIG_CLS_U32_MARK
85         struct tc_u32_mark      mark;
86 #endif
87         struct tc_u32_sel       sel;
88 };
89
90 struct tc_u_hnode
91 {
92         struct tc_u_hnode       *next;
93         u32                     handle;
94         u32                     prio;
95         struct tc_u_common      *tp_c;
96         int                     refcnt;
97         unsigned                divisor;
98         struct tc_u_knode       *ht[1];
99 };
100
101 struct tc_u_common
102 {
103         struct tc_u_common      *next;
104         struct tc_u_hnode       *hlist;
105         struct Qdisc            *q;
106         int                     refcnt;
107         u32                     hgenerator;
108 };
109
110 static struct tcf_ext_map u32_ext_map = {
111         .action = TCA_U32_ACT,
112         .police = TCA_U32_POLICE
113 };
114
115 static struct tc_u_common *u32_list;
116
117 static __inline__ unsigned u32_hash_fold(u32 key, struct tc_u32_sel *sel, u8 fshift)
118 {
119         unsigned h = (key & sel->hmask)>>fshift;
120
121         return h;
122 }
123
124 static int u32_classify(struct sk_buff *skb, struct tcf_proto *tp, struct tcf_result *res)
125 {
126         struct {
127                 struct tc_u_knode *knode;
128                 u8                *ptr;
129         } stack[TC_U32_MAXDEPTH];
130
131         struct tc_u_hnode *ht = (struct tc_u_hnode*)tp->root;
132         u8 *ptr = skb->nh.raw;
133         struct tc_u_knode *n;
134         int sdepth = 0;
135         int off2 = 0;
136         int sel = 0;
137 #ifdef CONFIG_CLS_U32_PERF
138         int j;
139 #endif
140         int i, r;
141
142 next_ht:
143         n = ht->ht[sel];
144
145 next_knode:
146         if (n) {
147                 struct tc_u32_key *key = n->sel.keys;
148
149 #ifdef CONFIG_CLS_U32_PERF
150                 n->pf->rcnt +=1;
151                 j = 0;
152 #endif
153
154 #ifdef CONFIG_CLS_U32_MARK
155                 if ((skb->nfmark & n->mark.mask) != n->mark.val) {
156                         n = n->next;
157                         goto next_knode;
158                 } else {
159                         n->mark.success++;
160                 }
161 #endif
162
163                 for (i = n->sel.nkeys; i>0; i--, key++) {
164
165                         if ((*(u32*)(ptr+key->off+(off2&key->offmask))^key->val)&key->mask) {
166                                 n = n->next;
167                                 goto next_knode;
168                         }
169 #ifdef CONFIG_CLS_U32_PERF
170                         n->pf->kcnts[j] +=1;
171                         j++;
172 #endif
173                 }
174                 if (n->ht_down == NULL) {
175 check_terminal:
176                         if (n->sel.flags&TC_U32_TERMINAL) {
177
178                                 *res = n->res;
179 #ifdef CONFIG_NET_CLS_IND
180                                 if (!tcf_match_indev(skb, n->indev)) {
181                                         n = n->next;
182                                         goto next_knode;
183                                 }
184 #endif
185 #ifdef CONFIG_CLS_U32_PERF
186                                 n->pf->rhit +=1;
187 #endif
188                                 r = tcf_exts_exec(skb, &n->exts, res);
189                                 if (r < 0) {
190                                         n = n->next;
191                                         goto next_knode;
192                                 }
193
194                                 return r;
195                         }
196                         n = n->next;
197                         goto next_knode;
198                 }
199
200                 /* PUSH */
201                 if (sdepth >= TC_U32_MAXDEPTH)
202                         goto deadloop;
203                 stack[sdepth].knode = n;
204                 stack[sdepth].ptr = ptr;
205                 sdepth++;
206
207                 ht = n->ht_down;
208                 sel = 0;
209                 if (ht->divisor)
210                         sel = ht->divisor&u32_hash_fold(*(u32*)(ptr+n->sel.hoff), &n->sel,n->fshift);
211
212                 if (!(n->sel.flags&(TC_U32_VAROFFSET|TC_U32_OFFSET|TC_U32_EAT)))
213                         goto next_ht;
214
215                 if (n->sel.flags&(TC_U32_OFFSET|TC_U32_VAROFFSET)) {
216                         off2 = n->sel.off + 3;
217                         if (n->sel.flags&TC_U32_VAROFFSET)
218                                 off2 += ntohs(n->sel.offmask & *(u16*)(ptr+n->sel.offoff)) >>n->sel.offshift;
219                         off2 &= ~3;
220                 }
221                 if (n->sel.flags&TC_U32_EAT) {
222                         ptr += off2;
223                         off2 = 0;
224                 }
225
226                 if (ptr < skb->tail)
227                         goto next_ht;
228         }
229
230         /* POP */
231         if (sdepth--) {
232                 n = stack[sdepth].knode;
233                 ht = n->ht_up;
234                 ptr = stack[sdepth].ptr;
235                 goto check_terminal;
236         }
237         return -1;
238
239 deadloop:
240         if (net_ratelimit())
241                 printk("cls_u32: dead loop\n");
242         return -1;
243 }
244
245 static __inline__ struct tc_u_hnode *
246 u32_lookup_ht(struct tc_u_common *tp_c, u32 handle)
247 {
248         struct tc_u_hnode *ht;
249
250         for (ht = tp_c->hlist; ht; ht = ht->next)
251                 if (ht->handle == handle)
252                         break;
253
254         return ht;
255 }
256
257 static __inline__ struct tc_u_knode *
258 u32_lookup_key(struct tc_u_hnode *ht, u32 handle)
259 {
260         unsigned sel;
261         struct tc_u_knode *n = NULL;
262
263         sel = TC_U32_HASH(handle);
264         if (sel > ht->divisor)
265                 goto out;
266
267         for (n = ht->ht[sel]; n; n = n->next)
268                 if (n->handle == handle)
269                         break;
270 out:
271         return n;
272 }
273
274
275 static unsigned long u32_get(struct tcf_proto *tp, u32 handle)
276 {
277         struct tc_u_hnode *ht;
278         struct tc_u_common *tp_c = tp->data;
279
280         if (TC_U32_HTID(handle) == TC_U32_ROOT)
281                 ht = tp->root;
282         else
283                 ht = u32_lookup_ht(tp_c, TC_U32_HTID(handle));
284
285         if (!ht)
286                 return 0;
287
288         if (TC_U32_KEY(handle) == 0)
289                 return (unsigned long)ht;
290
291         return (unsigned long)u32_lookup_key(ht, handle);
292 }
293
294 static void u32_put(struct tcf_proto *tp, unsigned long f)
295 {
296 }
297
298 static u32 gen_new_htid(struct tc_u_common *tp_c)
299 {
300         int i = 0x800;
301
302         do {
303                 if (++tp_c->hgenerator == 0x7FF)
304                         tp_c->hgenerator = 1;
305         } while (--i>0 && u32_lookup_ht(tp_c, (tp_c->hgenerator|0x800)<<20));
306
307         return i > 0 ? (tp_c->hgenerator|0x800)<<20 : 0;
308 }
309
310 static int u32_init(struct tcf_proto *tp)
311 {
312         struct tc_u_hnode *root_ht;
313         struct tc_u_common *tp_c;
314
315         for (tp_c = u32_list; tp_c; tp_c = tp_c->next)
316                 if (tp_c->q == tp->q)
317                         break;
318
319         root_ht = kmalloc(sizeof(*root_ht), GFP_KERNEL);
320         if (root_ht == NULL)
321                 return -ENOBUFS;
322
323         memset(root_ht, 0, sizeof(*root_ht));
324         root_ht->divisor = 0;
325         root_ht->refcnt++;
326         root_ht->handle = tp_c ? gen_new_htid(tp_c) : 0x80000000;
327         root_ht->prio = tp->prio;
328
329         if (tp_c == NULL) {
330                 tp_c = kmalloc(sizeof(*tp_c), GFP_KERNEL);
331                 if (tp_c == NULL) {
332                         kfree(root_ht);
333                         return -ENOBUFS;
334                 }
335                 memset(tp_c, 0, sizeof(*tp_c));
336                 tp_c->q = tp->q;
337                 tp_c->next = u32_list;
338                 u32_list = tp_c;
339         }
340
341         tp_c->refcnt++;
342         root_ht->next = tp_c->hlist;
343         tp_c->hlist = root_ht;
344         root_ht->tp_c = tp_c;
345
346         tp->root = root_ht;
347         tp->data = tp_c;
348         return 0;
349 }
350
351 static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n)
352 {
353         tcf_unbind_filter(tp, &n->res);
354         tcf_exts_destroy(tp, &n->exts);
355         if (n->ht_down)
356                 n->ht_down->refcnt--;
357 #ifdef CONFIG_CLS_U32_PERF
358         if (n && (NULL != n->pf))
359                 kfree(n->pf);
360 #endif
361         kfree(n);
362         return 0;
363 }
364
365 static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode* key)
366 {
367         struct tc_u_knode **kp;
368         struct tc_u_hnode *ht = key->ht_up;
369
370         if (ht) {
371                 for (kp = &ht->ht[TC_U32_HASH(key->handle)]; *kp; kp = &(*kp)->next) {
372                         if (*kp == key) {
373                                 tcf_tree_lock(tp);
374                                 *kp = key->next;
375                                 tcf_tree_unlock(tp);
376
377                                 u32_destroy_key(tp, key);
378                                 return 0;
379                         }
380                 }
381         }
382         BUG_TRAP(0);
383         return 0;
384 }
385
386 static void u32_clear_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
387 {
388         struct tc_u_knode *n;
389         unsigned h;
390
391         for (h=0; h<=ht->divisor; h++) {
392                 while ((n = ht->ht[h]) != NULL) {
393                         ht->ht[h] = n->next;
394
395                         u32_destroy_key(tp, n);
396                 }
397         }
398 }
399
400 static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
401 {
402         struct tc_u_common *tp_c = tp->data;
403         struct tc_u_hnode **hn;
404
405         BUG_TRAP(!ht->refcnt);
406
407         u32_clear_hnode(tp, ht);
408
409         for (hn = &tp_c->hlist; *hn; hn = &(*hn)->next) {
410                 if (*hn == ht) {
411                         *hn = ht->next;
412                         kfree(ht);
413                         return 0;
414                 }
415         }
416
417         BUG_TRAP(0);
418         return -ENOENT;
419 }
420
421 static void u32_destroy(struct tcf_proto *tp)
422 {
423         struct tc_u_common *tp_c = tp->data;
424         struct tc_u_hnode *root_ht = xchg(&tp->root, NULL);
425
426         BUG_TRAP(root_ht != NULL);
427
428         if (root_ht && --root_ht->refcnt == 0)
429                 u32_destroy_hnode(tp, root_ht);
430
431         if (--tp_c->refcnt == 0) {
432                 struct tc_u_hnode *ht;
433                 struct tc_u_common **tp_cp;
434
435                 for (tp_cp = &u32_list; *tp_cp; tp_cp = &(*tp_cp)->next) {
436                         if (*tp_cp == tp_c) {
437                                 *tp_cp = tp_c->next;
438                                 break;
439                         }
440                 }
441
442                 for (ht=tp_c->hlist; ht; ht = ht->next)
443                         u32_clear_hnode(tp, ht);
444
445                 while ((ht = tp_c->hlist) != NULL) {
446                         tp_c->hlist = ht->next;
447
448                         BUG_TRAP(ht->refcnt == 0);
449
450                         kfree(ht);
451                 };
452
453                 kfree(tp_c);
454         }
455
456         tp->data = NULL;
457 }
458
459 static int u32_delete(struct tcf_proto *tp, unsigned long arg)
460 {
461         struct tc_u_hnode *ht = (struct tc_u_hnode*)arg;
462
463         if (ht == NULL)
464                 return 0;
465
466         if (TC_U32_KEY(ht->handle))
467                 return u32_delete_key(tp, (struct tc_u_knode*)ht);
468
469         if (tp->root == ht)
470                 return -EINVAL;
471
472         if (--ht->refcnt == 0)
473                 u32_destroy_hnode(tp, ht);
474
475         return 0;
476 }
477
478 static u32 gen_new_kid(struct tc_u_hnode *ht, u32 handle)
479 {
480         struct tc_u_knode *n;
481         unsigned i = 0x7FF;
482
483         for (n=ht->ht[TC_U32_HASH(handle)]; n; n = n->next)
484                 if (i < TC_U32_NODE(n->handle))
485                         i = TC_U32_NODE(n->handle);
486         i++;
487
488         return handle|(i>0xFFF ? 0xFFF : i);
489 }
490
491 static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
492                          struct tc_u_hnode *ht,
493                          struct tc_u_knode *n, struct rtattr **tb,
494                          struct rtattr *est)
495 {
496         int err;
497         struct tcf_exts e;
498
499         err = tcf_exts_validate(tp, tb, est, &e, &u32_ext_map);
500         if (err < 0)
501                 return err;
502
503         err = -EINVAL;
504         if (tb[TCA_U32_LINK-1]) {
505                 u32 handle = *(u32*)RTA_DATA(tb[TCA_U32_LINK-1]);
506                 struct tc_u_hnode *ht_down = NULL;
507
508                 if (TC_U32_KEY(handle))
509                         goto errout;
510
511                 if (handle) {
512                         ht_down = u32_lookup_ht(ht->tp_c, handle);
513
514                         if (ht_down == NULL)
515                                 goto errout;
516                         ht_down->refcnt++;
517                 }
518
519                 tcf_tree_lock(tp);
520                 ht_down = xchg(&n->ht_down, ht_down);
521                 tcf_tree_unlock(tp);
522
523                 if (ht_down)
524                         ht_down->refcnt--;
525         }
526         if (tb[TCA_U32_CLASSID-1]) {
527                 n->res.classid = *(u32*)RTA_DATA(tb[TCA_U32_CLASSID-1]);
528                 tcf_bind_filter(tp, &n->res, base);
529         }
530
531 #ifdef CONFIG_NET_CLS_IND
532         if (tb[TCA_U32_INDEV-1]) {
533                 int err = tcf_change_indev(tp, n->indev, tb[TCA_U32_INDEV-1]);
534                 if (err < 0)
535                         goto errout;
536         }
537 #endif
538         tcf_exts_change(tp, &n->exts, &e);
539
540         return 0;
541 errout:
542         tcf_exts_destroy(tp, &e);
543         return err;
544 }
545
546 static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
547                       struct rtattr **tca,
548                       unsigned long *arg)
549 {
550         struct tc_u_common *tp_c = tp->data;
551         struct tc_u_hnode *ht;
552         struct tc_u_knode *n;
553         struct tc_u32_sel *s;
554         struct rtattr *opt = tca[TCA_OPTIONS-1];
555         struct rtattr *tb[TCA_U32_MAX];
556         u32 htid;
557         int err;
558
559         if (opt == NULL)
560                 return handle ? -EINVAL : 0;
561
562         if (rtattr_parse_nested(tb, TCA_U32_MAX, opt) < 0)
563                 return -EINVAL;
564
565         if ((n = (struct tc_u_knode*)*arg) != NULL) {
566                 if (TC_U32_KEY(n->handle) == 0)
567                         return -EINVAL;
568
569                 return u32_set_parms(tp, base, n->ht_up, n, tb, tca[TCA_RATE-1]);
570         }
571
572         if (tb[TCA_U32_DIVISOR-1]) {
573                 unsigned divisor = *(unsigned*)RTA_DATA(tb[TCA_U32_DIVISOR-1]);
574
575                 if (--divisor > 0x100)
576                         return -EINVAL;
577                 if (TC_U32_KEY(handle))
578                         return -EINVAL;
579                 if (handle == 0) {
580                         handle = gen_new_htid(tp->data);
581                         if (handle == 0)
582                                 return -ENOMEM;
583                 }
584                 ht = kmalloc(sizeof(*ht) + divisor*sizeof(void*), GFP_KERNEL);
585                 if (ht == NULL)
586                         return -ENOBUFS;
587                 memset(ht, 0, sizeof(*ht) + divisor*sizeof(void*));
588                 ht->tp_c = tp_c;
589                 ht->refcnt = 0;
590                 ht->divisor = divisor;
591                 ht->handle = handle;
592                 ht->prio = tp->prio;
593                 ht->next = tp_c->hlist;
594                 tp_c->hlist = ht;
595                 *arg = (unsigned long)ht;
596                 return 0;
597         }
598
599         if (tb[TCA_U32_HASH-1]) {
600                 htid = *(unsigned*)RTA_DATA(tb[TCA_U32_HASH-1]);
601                 if (TC_U32_HTID(htid) == TC_U32_ROOT) {
602                         ht = tp->root;
603                         htid = ht->handle;
604                 } else {
605                         ht = u32_lookup_ht(tp->data, TC_U32_HTID(htid));
606                         if (ht == NULL)
607                                 return -EINVAL;
608                 }
609         } else {
610                 ht = tp->root;
611                 htid = ht->handle;
612         }
613
614         if (ht->divisor < TC_U32_HASH(htid))
615                 return -EINVAL;
616
617         if (handle) {
618                 if (TC_U32_HTID(handle) && TC_U32_HTID(handle^htid))
619                         return -EINVAL;
620                 handle = htid | TC_U32_NODE(handle);
621         } else
622                 handle = gen_new_kid(ht, htid);
623
624         if (tb[TCA_U32_SEL-1] == 0 ||
625             RTA_PAYLOAD(tb[TCA_U32_SEL-1]) < sizeof(struct tc_u32_sel))
626                 return -EINVAL;
627
628         s = RTA_DATA(tb[TCA_U32_SEL-1]);
629
630         n = kmalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key), GFP_KERNEL);
631         if (n == NULL)
632                 return -ENOBUFS;
633
634         memset(n, 0, sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key));
635 #ifdef CONFIG_CLS_U32_PERF
636         n->pf = kmalloc(sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(u64), GFP_KERNEL);
637         if (n->pf == NULL) {
638                 kfree(n);
639                 return -ENOBUFS;
640         }
641         memset(n->pf, 0, sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(u64));
642 #endif
643
644         memcpy(&n->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
645         n->ht_up = ht;
646         n->handle = handle;
647 {
648         u8 i = 0;
649         u32 mask = s->hmask;
650         if (mask) {
651                 while (!(mask & 1)) {
652                         i++;
653                         mask>>=1;
654                 }
655         }
656         n->fshift = i;
657 }
658
659 #ifdef CONFIG_CLS_U32_MARK
660         if (tb[TCA_U32_MARK-1]) {
661                 struct tc_u32_mark *mark;
662
663                 if (RTA_PAYLOAD(tb[TCA_U32_MARK-1]) < sizeof(struct tc_u32_mark)) {
664 #ifdef CONFIG_CLS_U32_PERF
665                         kfree(n->pf);
666 #endif
667                         kfree(n);
668                         return -EINVAL;
669                 }
670                 mark = RTA_DATA(tb[TCA_U32_MARK-1]);
671                 memcpy(&n->mark, mark, sizeof(struct tc_u32_mark));
672                 n->mark.success = 0;
673         }
674 #endif
675
676         err = u32_set_parms(tp, base, ht, n, tb, tca[TCA_RATE-1]);
677         if (err == 0) {
678                 struct tc_u_knode **ins;
679                 for (ins = &ht->ht[TC_U32_HASH(handle)]; *ins; ins = &(*ins)->next)
680                         if (TC_U32_NODE(handle) < TC_U32_NODE((*ins)->handle))
681                                 break;
682
683                 n->next = *ins;
684                 wmb();
685                 *ins = n;
686
687                 *arg = (unsigned long)n;
688                 return 0;
689         }
690 #ifdef CONFIG_CLS_U32_PERF
691         if (n && (NULL != n->pf))
692                 kfree(n->pf);
693 #endif
694         kfree(n);
695         return err;
696 }
697
698 static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)
699 {
700         struct tc_u_common *tp_c = tp->data;
701         struct tc_u_hnode *ht;
702         struct tc_u_knode *n;
703         unsigned h;
704
705         if (arg->stop)
706                 return;
707
708         for (ht = tp_c->hlist; ht; ht = ht->next) {
709                 if (ht->prio != tp->prio)
710                         continue;
711                 if (arg->count >= arg->skip) {
712                         if (arg->fn(tp, (unsigned long)ht, arg) < 0) {
713                                 arg->stop = 1;
714                                 return;
715                         }
716                 }
717                 arg->count++;
718                 for (h = 0; h <= ht->divisor; h++) {
719                         for (n = ht->ht[h]; n; n = n->next) {
720                                 if (arg->count < arg->skip) {
721                                         arg->count++;
722                                         continue;
723                                 }
724                                 if (arg->fn(tp, (unsigned long)n, arg) < 0) {
725                                         arg->stop = 1;
726                                         return;
727                                 }
728                                 arg->count++;
729                         }
730                 }
731         }
732 }
733
734 static int u32_dump(struct tcf_proto *tp, unsigned long fh,
735                      struct sk_buff *skb, struct tcmsg *t)
736 {
737         struct tc_u_knode *n = (struct tc_u_knode*)fh;
738         unsigned char    *b = skb->tail;
739         struct rtattr *rta;
740
741         if (n == NULL)
742                 return skb->len;
743
744         t->tcm_handle = n->handle;
745
746         rta = (struct rtattr*)b;
747         RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
748
749         if (TC_U32_KEY(n->handle) == 0) {
750                 struct tc_u_hnode *ht = (struct tc_u_hnode*)fh;
751                 u32 divisor = ht->divisor+1;
752                 RTA_PUT(skb, TCA_U32_DIVISOR, 4, &divisor);
753         } else {
754                 RTA_PUT(skb, TCA_U32_SEL,
755                         sizeof(n->sel) + n->sel.nkeys*sizeof(struct tc_u32_key),
756                         &n->sel);
757                 if (n->ht_up) {
758                         u32 htid = n->handle & 0xFFFFF000;
759                         RTA_PUT(skb, TCA_U32_HASH, 4, &htid);
760                 }
761                 if (n->res.classid)
762                         RTA_PUT(skb, TCA_U32_CLASSID, 4, &n->res.classid);
763                 if (n->ht_down)
764                         RTA_PUT(skb, TCA_U32_LINK, 4, &n->ht_down->handle);
765
766 #ifdef CONFIG_CLS_U32_MARK
767                 if (n->mark.val || n->mark.mask)
768                         RTA_PUT(skb, TCA_U32_MARK, sizeof(n->mark), &n->mark);
769 #endif
770
771                 if (tcf_exts_dump(skb, &n->exts, &u32_ext_map) < 0)
772                         goto rtattr_failure;
773
774 #ifdef CONFIG_NET_CLS_IND
775                 if(strlen(n->indev))
776                         RTA_PUT(skb, TCA_U32_INDEV, IFNAMSIZ, n->indev);
777 #endif
778 #ifdef CONFIG_CLS_U32_PERF
779                 RTA_PUT(skb, TCA_U32_PCNT, 
780                 sizeof(struct tc_u32_pcnt) + n->sel.nkeys*sizeof(u64),
781                         n->pf);
782 #endif
783         }
784
785         rta->rta_len = skb->tail - b;
786         if (TC_U32_KEY(n->handle))
787                 if (tcf_exts_dump_stats(skb, &n->exts, &u32_ext_map) < 0)
788                         goto rtattr_failure;
789         return skb->len;
790
791 rtattr_failure:
792         skb_trim(skb, b - skb->data);
793         return -1;
794 }
795
796 static struct tcf_proto_ops cls_u32_ops = {
797         .next           =       NULL,
798         .kind           =       "u32",
799         .classify       =       u32_classify,
800         .init           =       u32_init,
801         .destroy        =       u32_destroy,
802         .get            =       u32_get,
803         .put            =       u32_put,
804         .change         =       u32_change,
805         .delete         =       u32_delete,
806         .walk           =       u32_walk,
807         .dump           =       u32_dump,
808         .owner          =       THIS_MODULE,
809 };
810
811 static int __init init_u32(void)
812 {
813         printk("u32 classifier\n");
814 #ifdef CONFIG_CLS_U32_PERF
815         printk("    Perfomance counters on\n");
816 #endif
817 #ifdef CONFIG_NET_CLS_POLICE
818         printk("    OLD policer on \n");
819 #endif
820 #ifdef CONFIG_NET_CLS_IND
821         printk("    input device check on \n");
822 #endif
823 #ifdef CONFIG_NET_CLS_ACT
824         printk("    Actions configured \n");
825 #endif
826         return register_tcf_proto_ops(&cls_u32_ops);
827 }
828
829 static void __exit exit_u32(void) 
830 {
831         unregister_tcf_proto_ops(&cls_u32_ops);
832 }
833
834 module_init(init_u32)
835 module_exit(exit_u32)
836 MODULE_LICENSE("GPL");