upgrade to fedora-2.6.12-1.1398.FC4 + vserver 2.0.rc7
[linux-2.6.git] / net / sched / cls_u32.c
index 0e8505b..364b87d 100644 (file)
@@ -27,6 +27,7 @@
  *     JHS: We should remove the CONFIG_NET_CLS_IND from here
  *     eventually when the meta match extension is made available
  *
+ *     nfmark match added by Catalin(ux aka Dino) BOIE <catab at umbrella.ro>
  */
 
 #include <asm/uaccess.h>
 #include <net/act_api.h>
 #include <net/pkt_cls.h>
 
-
 struct tc_u_knode
 {
        struct tc_u_knode       *next;
        u32                     handle;
        struct tc_u_hnode       *ht_up;
-#ifdef CONFIG_NET_CLS_ACT
-       struct tc_action        *action;
-#else
-#ifdef CONFIG_NET_CLS_POLICE
-       struct tcf_police       *police;
-#endif
-#endif
+       struct tcf_exts         exts;
 #ifdef CONFIG_NET_CLS_IND
        char                     indev[IFNAMSIZ];
 #endif
@@ -78,6 +72,9 @@ struct tc_u_knode
        struct tc_u_hnode       *ht_down;
 #ifdef CONFIG_CLS_U32_PERF
        struct tc_u32_pcnt      *pf;
+#endif
+#ifdef CONFIG_CLS_U32_MARK
+       struct tc_u32_mark      mark;
 #endif
        struct tc_u32_sel       sel;
 };
@@ -86,6 +83,7 @@ struct tc_u_hnode
 {
        struct tc_u_hnode       *next;
        u32                     handle;
+       u32                     prio;
        struct tc_u_common      *tp_c;
        int                     refcnt;
        unsigned                divisor;
@@ -101,6 +99,11 @@ struct tc_u_common
        u32                     hgenerator;
 };
 
+static struct tcf_ext_map u32_ext_map = {
+       .action = TCA_U32_ACT,
+       .police = TCA_U32_POLICE
+};
+
 static struct tc_u_common *u32_list;
 
 static __inline__ unsigned u32_hash_fold(u32 key, struct tc_u32_sel *sel, u8 fshift)
@@ -126,7 +129,7 @@ static int u32_classify(struct sk_buff *skb, struct tcf_proto *tp, struct tcf_re
 #ifdef CONFIG_CLS_U32_PERF
        int j;
 #endif
-       int i;
+       int i, r;
 
 next_ht:
        n = ht->ht[sel];
@@ -139,6 +142,16 @@ next_knode:
                n->pf->rcnt +=1;
                j = 0;
 #endif
+
+#ifdef CONFIG_CLS_U32_MARK
+               if ((skb->nfmark & n->mark.mask) != n->mark.val) {
+                       n = n->next;
+                       goto next_knode;
+               } else {
+                       n->mark.success++;
+               }
+#endif
+
                for (i = n->sel.nkeys; i>0; i--, key++) {
 
                        if ((*(u32*)(ptr+key->off+(off2&key->offmask))^key->val)&key->mask) {
@@ -164,22 +177,13 @@ check_terminal:
 #ifdef CONFIG_CLS_U32_PERF
                                n->pf->rhit +=1;
 #endif
-#ifdef CONFIG_NET_CLS_ACT
-                               if (n->action) {
-                                       int pol_res = tcf_action_exec(skb, n->action, res);
-                                       if (pol_res >= 0)
-                                               return pol_res;
-                               } else
-#else
-#ifdef CONFIG_NET_CLS_POLICE
-                               if (n->police) {
-                                       int pol_res = tcf_police(skb, n->police);
-                                       if (pol_res >= 0)
-                                               return pol_res;
-                               } else
-#endif
-#endif
-                                       return 0;
+                               r = tcf_exts_exec(skb, &n->exts, res);
+                               if (r < 0) {
+                                       n = n->next;
+                                       goto next_knode;
+                               }
+
+                               return r;
                        }
                        n = n->next;
                        goto next_knode;
@@ -312,6 +316,7 @@ static int u32_init(struct tcf_proto *tp)
        root_ht->divisor = 0;
        root_ht->refcnt++;
        root_ht->handle = tp_c ? gen_new_htid(tp_c) : 0x80000000;
+       root_ht->prio = tp->prio;
 
        if (tp_c == NULL) {
                tp_c = kmalloc(sizeof(*tp_c), GFP_KERNEL);
@@ -338,15 +343,7 @@ static int u32_init(struct tcf_proto *tp)
 static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n)
 {
        tcf_unbind_filter(tp, &n->res);
-#ifdef CONFIG_NET_CLS_ACT
-       if (n->action) {
-               tcf_action_destroy(n->action, TCA_ACT_UNBIND);
-       }
-#else
-#ifdef CONFIG_NET_CLS_POLICE
-       tcf_police_release(n->police, TCA_ACT_UNBIND);
-#endif
-#endif
+       tcf_exts_destroy(tp, &n->exts);
        if (n->ht_down)
                n->ht_down->refcnt--;
 #ifdef CONFIG_CLS_U32_PERF
@@ -488,18 +485,26 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
                         struct tc_u_knode *n, struct rtattr **tb,
                         struct rtattr *est)
 {
+       int err;
+       struct tcf_exts e;
+
+       err = tcf_exts_validate(tp, tb, est, &e, &u32_ext_map);
+       if (err < 0)
+               return err;
+
+       err = -EINVAL;
        if (tb[TCA_U32_LINK-1]) {
                u32 handle = *(u32*)RTA_DATA(tb[TCA_U32_LINK-1]);
                struct tc_u_hnode *ht_down = NULL;
 
                if (TC_U32_KEY(handle))
-                       return -EINVAL;
+                       goto errout;
 
                if (handle) {
                        ht_down = u32_lookup_ht(ht->tp_c, handle);
 
                        if (ht_down == NULL)
-                               return -EINVAL;
+                               goto errout;
                        ht_down->refcnt++;
                }
 
@@ -514,36 +519,20 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
                n->res.classid = *(u32*)RTA_DATA(tb[TCA_U32_CLASSID-1]);
                tcf_bind_filter(tp, &n->res, base);
        }
-#ifdef CONFIG_NET_CLS_ACT
-       if (tb[TCA_U32_POLICE-1]) {
-               int err = tcf_change_act_police(tp, &n->action, tb[TCA_U32_POLICE-1], est);
-               if (err < 0)
-                       return err;
-       }
 
-       if (tb[TCA_U32_ACT-1]) {
-               int err = tcf_change_act(tp, &n->action, tb[TCA_U32_ACT-1], est);
-               if (err < 0)
-                       return err;
-       }
-#else
-#ifdef CONFIG_NET_CLS_POLICE
-       if (tb[TCA_U32_POLICE-1]) {
-               int err = tcf_change_police(tp, &n->police, tb[TCA_U32_POLICE-1], est);
-               if (err < 0)
-                       return err;
-       }
-#endif
-#endif
 #ifdef CONFIG_NET_CLS_IND
        if (tb[TCA_U32_INDEV-1]) {
                int err = tcf_change_indev(tp, n->indev, tb[TCA_U32_INDEV-1]);
                if (err < 0)
-                       return err;
+                       goto errout;
        }
 #endif
+       tcf_exts_change(tp, &n->exts, &e);
 
        return 0;
+errout:
+       tcf_exts_destroy(tp, &e);
+       return err;
 }
 
 static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
@@ -562,7 +551,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
        if (opt == NULL)
                return handle ? -EINVAL : 0;
 
-       if (rtattr_parse(tb, TCA_U32_MAX, RTA_DATA(opt), RTA_PAYLOAD(opt)) < 0)
+       if (rtattr_parse_nested(tb, TCA_U32_MAX, opt) < 0)
                return -EINVAL;
 
        if ((n = (struct tc_u_knode*)*arg) != NULL) {
@@ -592,6 +581,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
                ht->refcnt = 0;
                ht->divisor = divisor;
                ht->handle = handle;
+               ht->prio = tp->prio;
                ht->next = tp_c->hlist;
                tp_c->hlist = ht;
                *arg = (unsigned long)ht;
@@ -635,12 +625,12 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
 
        memset(n, 0, sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key));
 #ifdef CONFIG_CLS_U32_PERF
-       n->pf = kmalloc(sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(__u64), GFP_KERNEL);
+       n->pf = kmalloc(sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(u64), GFP_KERNEL);
        if (n->pf == NULL) {
                kfree(n);
                return -ENOBUFS;
        }
-       memset(n->pf, 0, sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(__u64));
+       memset(n->pf, 0, sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(u64));
 #endif
 
        memcpy(&n->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
@@ -657,6 +647,24 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
        }
        n->fshift = i;
 }
+
+#ifdef CONFIG_CLS_U32_MARK
+       if (tb[TCA_U32_MARK-1]) {
+               struct tc_u32_mark *mark;
+
+               if (RTA_PAYLOAD(tb[TCA_U32_MARK-1]) < sizeof(struct tc_u32_mark)) {
+#ifdef CONFIG_CLS_U32_PERF
+                       kfree(n->pf);
+#endif
+                       kfree(n);
+                       return -EINVAL;
+               }
+               mark = RTA_DATA(tb[TCA_U32_MARK-1]);
+               memcpy(&n->mark, mark, sizeof(struct tc_u32_mark));
+               n->mark.success = 0;
+       }
+#endif
+
        err = u32_set_parms(tp, base, ht, n, tb, tca[TCA_RATE-1]);
        if (err == 0) {
                struct tc_u_knode **ins;
@@ -690,6 +698,8 @@ static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)
                return;
 
        for (ht = tp_c->hlist; ht; ht = ht->next) {
+               if (ht->prio != tp->prio)
+                       continue;
                if (arg->count >= arg->skip) {
                        if (arg->fn(tp, (unsigned long)ht, arg) < 0) {
                                arg->stop = 1;
@@ -744,42 +754,30 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,
                        RTA_PUT(skb, TCA_U32_CLASSID, 4, &n->res.classid);
                if (n->ht_down)
                        RTA_PUT(skb, TCA_U32_LINK, 4, &n->ht_down->handle);
-#ifdef CONFIG_NET_CLS_ACT
-               if (tcf_dump_act(skb, n->action, TCA_U32_ACT, TCA_U32_POLICE) < 0)
-                       goto rtattr_failure;
-#else
-#ifdef CONFIG_NET_CLS_POLICE
-               if (tcf_dump_police(skb, n->police, TCA_U32_POLICE) < 0)
-                       goto rtattr_failure;
-#endif
+
+#ifdef CONFIG_CLS_U32_MARK
+               if (n->mark.val || n->mark.mask)
+                       RTA_PUT(skb, TCA_U32_MARK, sizeof(n->mark), &n->mark);
 #endif
 
+               if (tcf_exts_dump(skb, &n->exts, &u32_ext_map) < 0)
+                       goto rtattr_failure;
+
 #ifdef CONFIG_NET_CLS_IND
                if(strlen(n->indev))
                        RTA_PUT(skb, TCA_U32_INDEV, IFNAMSIZ, n->indev);
 #endif
 #ifdef CONFIG_CLS_U32_PERF
                RTA_PUT(skb, TCA_U32_PCNT, 
-               sizeof(struct tc_u32_pcnt) + n->sel.nkeys*sizeof(__u64),
+               sizeof(struct tc_u32_pcnt) + n->sel.nkeys*sizeof(u64),
                        n->pf);
 #endif
        }
 
        rta->rta_len = skb->tail - b;
-#ifdef CONFIG_NET_CLS_ACT
-       if (TC_U32_KEY(n->handle) != 0) {
-               if (TC_U32_KEY(n->handle) && n->action && n->action->type == TCA_OLD_COMPAT) {
-                       if (tcf_action_copy_stats(skb,n->action))
-                               goto rtattr_failure;
-               }
-       }
-#else
-#ifdef CONFIG_NET_CLS_POLICE
-       if (TC_U32_KEY(n->handle) && n->police)
-               if (tcf_police_dump_stats(skb, n->police) < 0)
+       if (TC_U32_KEY(n->handle))
+               if (tcf_exts_dump_stats(skb, &n->exts, &u32_ext_map) < 0)
                        goto rtattr_failure;
-#endif
-#endif
        return skb->len;
 
 rtattr_failure: