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