netfilter: ip6table_raw: fix table priority
[safe/jmp/linux-2.6] / net / sched / cls_u32.c
index a4e72e8..07372f6 100644 (file)
@@ -75,21 +75,18 @@ struct tc_u_hnode
 
 struct tc_u_common
 {
-       struct tc_u_common      *next;
        struct tc_u_hnode       *hlist;
        struct Qdisc            *q;
        int                     refcnt;
        u32                     hgenerator;
 };
 
-static struct tcf_ext_map u32_ext_map = {
+static const 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)
+static __inline__ unsigned u32_hash_fold(__be32 key, struct tc_u32_sel *sel, u8 fshift)
 {
        unsigned h = ntohl(key & sel->hmask)>>fshift;
 
@@ -137,7 +134,7 @@ next_knode:
 
                for (i = n->sel.nkeys; i>0; i--, key++) {
 
-                       if ((*(u32*)(ptr+key->off+(off2&key->offmask))^key->val)&key->mask) {
+                       if ((*(__be32*)(ptr+key->off+(off2&key->offmask))^key->val)&key->mask) {
                                n = n->next;
                                goto next_knode;
                        }
@@ -182,7 +179,7 @@ check_terminal:
                ht = n->ht_down;
                sel = 0;
                if (ht->divisor)
-                       sel = ht->divisor&u32_hash_fold(*(u32*)(ptr+n->sel.hoff), &n->sel,n->fshift);
+                       sel = ht->divisor&u32_hash_fold(*(__be32*)(ptr+n->sel.hoff), &n->sel,n->fshift);
 
                if (!(n->sel.flags&(TC_U32_VAROFFSET|TC_U32_OFFSET|TC_U32_EAT)))
                        goto next_ht;
@@ -190,7 +187,7 @@ check_terminal:
                if (n->sel.flags&(TC_U32_OFFSET|TC_U32_VAROFFSET)) {
                        off2 = n->sel.off + 3;
                        if (n->sel.flags&TC_U32_VAROFFSET)
-                               off2 += ntohs(n->sel.offmask & *(u16*)(ptr+n->sel.offoff)) >>n->sel.offshift;
+                               off2 += ntohs(n->sel.offmask & *(__be16*)(ptr+n->sel.offoff)) >>n->sel.offshift;
                        off2 &= ~3;
                }
                if (n->sel.flags&TC_U32_EAT) {
@@ -287,9 +284,7 @@ static int u32_init(struct tcf_proto *tp)
        struct tc_u_hnode *root_ht;
        struct tc_u_common *tp_c;
 
-       for (tp_c = u32_list; tp_c; tp_c = tp_c->next)
-               if (tp_c->q == tp->q)
-                       break;
+       tp_c = tp->q->u32_node;
 
        root_ht = kzalloc(sizeof(*root_ht), GFP_KERNEL);
        if (root_ht == NULL)
@@ -307,8 +302,7 @@ static int u32_init(struct tcf_proto *tp)
                        return -ENOBUFS;
                }
                tp_c->q = tp->q;
-               tp_c->next = u32_list;
-               u32_list = tp_c;
+               tp->q->u32_node = tp_c;
        }
 
        tp_c->refcnt++;
@@ -351,7 +345,7 @@ static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode* key)
                        }
                }
        }
-       BUG_TRAP(0);
+       WARN_ON(1);
        return 0;
 }
 
@@ -374,7 +368,7 @@ static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
        struct tc_u_common *tp_c = tp->data;
        struct tc_u_hnode **hn;
 
-       BUG_TRAP(!ht->refcnt);
+       WARN_ON(ht->refcnt);
 
        u32_clear_hnode(tp, ht);
 
@@ -386,38 +380,34 @@ static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
                }
        }
 
-       BUG_TRAP(0);
+       WARN_ON(1);
        return -ENOENT;
 }
 
 static void u32_destroy(struct tcf_proto *tp)
 {
        struct tc_u_common *tp_c = tp->data;
-       struct tc_u_hnode *root_ht = xchg(&tp->root, NULL);
+       struct tc_u_hnode *root_ht = tp->root;
 
-       BUG_TRAP(root_ht != NULL);
+       WARN_ON(root_ht == NULL);
 
        if (root_ht && --root_ht->refcnt == 0)
                u32_destroy_hnode(tp, root_ht);
 
        if (--tp_c->refcnt == 0) {
                struct tc_u_hnode *ht;
-               struct tc_u_common **tp_cp;
 
-               for (tp_cp = &u32_list; *tp_cp; tp_cp = &(*tp_cp)->next) {
-                       if (*tp_cp == tp_c) {
-                               *tp_cp = tp_c->next;
-                               break;
-                       }
-               }
+               tp->q->u32_node = NULL;
 
-               for (ht=tp_c->hlist; ht; ht = ht->next)
+               for (ht = tp_c->hlist; ht; ht = ht->next) {
+                       ht->refcnt--;
                        u32_clear_hnode(tp, ht);
+               }
 
                while ((ht = tp_c->hlist) != NULL) {
                        tp_c->hlist = ht->next;
 
-                       BUG_TRAP(ht->refcnt == 0);
+                       WARN_ON(ht->refcnt != 0);
 
                        kfree(ht);
                }
@@ -441,8 +431,12 @@ static int u32_delete(struct tcf_proto *tp, unsigned long arg)
        if (tp->root == ht)
                return -EINVAL;
 
-       if (--ht->refcnt == 0)
+       if (ht->refcnt == 1) {
+               ht->refcnt--;
                u32_destroy_hnode(tp, ht);
+       } else {
+               return -EBUSY;
+       }
 
        return 0;
 }
@@ -460,6 +454,16 @@ static u32 gen_new_kid(struct tc_u_hnode *ht, u32 handle)
        return handle|(i>0xFFF ? 0xFFF : i);
 }
 
+static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = {
+       [TCA_U32_CLASSID]       = { .type = NLA_U32 },
+       [TCA_U32_HASH]          = { .type = NLA_U32 },
+       [TCA_U32_LINK]          = { .type = NLA_U32 },
+       [TCA_U32_DIVISOR]       = { .type = NLA_U32 },
+       [TCA_U32_SEL]           = { .len = sizeof(struct tc_u32_sel) },
+       [TCA_U32_INDEV]         = { .type = NLA_STRING, .len = IFNAMSIZ },
+       [TCA_U32_MARK]          = { .len = sizeof(struct tc_u32_mark) },
+};
+
 static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
                         struct tc_u_hnode *ht,
                         struct tc_u_knode *n, struct nlattr **tb,
@@ -475,7 +479,7 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
        err = -EINVAL;
        if (tb[TCA_U32_LINK]) {
                u32 handle = nla_get_u32(tb[TCA_U32_LINK]);
-               struct tc_u_hnode *ht_down = NULL;
+               struct tc_u_hnode *ht_down = NULL, *ht_old;
 
                if (TC_U32_KEY(handle))
                        goto errout;
@@ -489,11 +493,12 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
                }
 
                tcf_tree_lock(tp);
-               ht_down = xchg(&n->ht_down, ht_down);
+               ht_old = n->ht_down;
+               n->ht_down = ht_down;
                tcf_tree_unlock(tp);
 
-               if (ht_down)
-                       ht_down->refcnt--;
+               if (ht_old)
+                       ht_old->refcnt--;
        }
        if (tb[TCA_U32_CLASSID]) {
                n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]);
@@ -531,7 +536,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
        if (opt == NULL)
                return handle ? -EINVAL : 0;
 
-       err = nla_parse_nested(tb, TCA_U32_MAX, opt, NULL);
+       err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy);
        if (err < 0)
                return err;
 
@@ -558,7 +563,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
                if (ht == NULL)
                        return -ENOBUFS;
                ht->tp_c = tp_c;
-               ht->refcnt = 0;
+               ht->refcnt = 1;
                ht->divisor = divisor;
                ht->handle = handle;
                ht->prio = tp->prio;
@@ -593,8 +598,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
        } else
                handle = gen_new_kid(ht, htid);
 
-       if (tb[TCA_U32_SEL] == NULL ||
-           nla_len(tb[TCA_U32_SEL]) < sizeof(struct tc_u32_sel))
+       if (tb[TCA_U32_SEL] == NULL)
                return -EINVAL;
 
        s = nla_data(tb[TCA_U32_SEL]);
@@ -620,13 +624,6 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
        if (tb[TCA_U32_MARK]) {
                struct tc_u32_mark *mark;
 
-               if (nla_len(tb[TCA_U32_MARK]) < sizeof(struct tc_u32_mark)) {
-#ifdef CONFIG_CLS_U32_PERF
-                       kfree(n->pf);
-#endif
-                       kfree(n);
-                       return -EINVAL;
-               }
                mark = nla_data(tb[TCA_U32_MARK]);
                memcpy(&n->mark, mark, sizeof(struct tc_u32_mark));
                n->mark.success = 0;
@@ -641,8 +638,9 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
                                break;
 
                n->next = *ins;
-               wmb();
+               tcf_tree_lock(tp);
                *ins = n;
+               tcf_tree_unlock(tp);
 
                *arg = (unsigned long)n;
                return 0;