Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / net / sched / cls_api.c
index d2b6f54..7cf6c0f 100644 (file)
@@ -135,6 +135,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
        unsigned long cl;
        unsigned long fh;
        int err;
+       int tp_created = 0;
 
        if (net != &init_net)
                return -EINVAL;
@@ -167,8 +168,7 @@ replay:
 
        /* Find qdisc */
        if (!parent) {
-               struct netdev_queue *dev_queue = netdev_get_tx_queue(dev, 0);
-               q = dev_queue->qdisc_sleeping;
+               q = dev->qdisc;
                parent = q->handle;
        } else {
                q = qdisc_lookup(dev, TC_H_MAJ(t->tcm_parent));
@@ -180,6 +180,9 @@ replay:
        if ((cops = q->ops->cl_ops) == NULL)
                return -EINVAL;
 
+       if (cops->tcf_chain == NULL)
+               return -EOPNOTSUPP;
+
        /* Do we search for filter, attached to class? */
        if (TC_H_MIN(parent)) {
                cl = cops->get(q, parent);
@@ -205,7 +208,7 @@ replay:
                }
        }
 
-       root_lock = qdisc_root_lock(q);
+       root_lock = qdisc_root_sleeping_lock(q);
 
        if (tp == NULL) {
                /* Proto-tcf does not exist, create new one */
@@ -227,7 +230,7 @@ replay:
                err = -ENOENT;
                tp_ops = tcf_proto_lookup_ops(tca[TCA_KIND]);
                if (tp_ops == NULL) {
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
                        struct nlattr *kind = tca[TCA_KIND];
                        char name[IFNAMSIZ];
 
@@ -254,7 +257,7 @@ replay:
                }
                tp->ops = tp_ops;
                tp->protocol = protocol;
-               tp->prio = nprio ? : tcf_auto_prio(*back);
+               tp->prio = nprio ? : TC_H_MAJ(tcf_auto_prio(*back));
                tp->q = q;
                tp->classify = tp_ops->classify;
                tp->classid = parent;
@@ -266,10 +269,7 @@ replay:
                        goto errout;
                }
 
-               spin_lock_bh(root_lock);
-               tp->next = *back;
-               *back = tp;
-               spin_unlock_bh(root_lock);
+               tp_created = 1;
 
        } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind))
                goto errout;
@@ -280,7 +280,7 @@ replay:
                if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
                        spin_lock_bh(root_lock);
                        *back = tp->next;
-                       spin_lock_bh(root_lock);
+                       spin_unlock_bh(root_lock);
 
                        tfilter_notify(skb, n, tp, fh, RTM_DELTFILTER);
                        tcf_destroy(tp);
@@ -296,8 +296,11 @@ replay:
                switch (n->nlmsg_type) {
                case RTM_NEWTFILTER:
                        err = -EEXIST;
-                       if (n->nlmsg_flags & NLM_F_EXCL)
+                       if (n->nlmsg_flags & NLM_F_EXCL) {
+                               if (tp_created)
+                                       tcf_destroy(tp);
                                goto errout;
+                       }
                        break;
                case RTM_DELTFILTER:
                        err = tp->ops->delete(tp, fh);
@@ -314,8 +317,18 @@ replay:
        }
 
        err = tp->ops->change(tp, cl, t->tcm_handle, tca, &fh);
-       if (err == 0)
+       if (err == 0) {
+               if (tp_created) {
+                       spin_lock_bh(root_lock);
+                       tp->next = *back;
+                       *back = tp;
+                       spin_unlock_bh(root_lock);
+               }
                tfilter_notify(skb, n, tp, fh, RTM_NEWTFILTER);
+       } else {
+               if (tp_created)
+                       tcf_destroy(tp);
+       }
 
 errout:
        if (cl)
@@ -337,7 +350,7 @@ static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp,
        tcm = NLMSG_DATA(nlh);
        tcm->tcm_family = AF_UNSPEC;
        tcm->tcm__pad1 = 0;
-       tcm->tcm__pad1 = 0;
+       tcm->tcm__pad2 = 0;
        tcm->tcm_ifindex = qdisc_dev(tp->q)->ifindex;
        tcm->tcm_parent = tp->classid;
        tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
@@ -394,7 +407,6 @@ static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
 static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
 {
        struct net *net = sock_net(skb->sk);
-       struct netdev_queue *dev_queue;
        int t;
        int s_t;
        struct net_device *dev;
@@ -413,15 +425,16 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
        if ((dev = dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL)
                return skb->len;
 
-       dev_queue = netdev_get_tx_queue(dev, 0);
        if (!tcm->tcm_parent)
-               q = dev_queue->qdisc_sleeping;
+               q = dev->qdisc;
        else
                q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent));
        if (!q)
                goto out;
        if ((cops = q->ops->cl_ops) == NULL)
                goto errout;
+       if (cops->tcf_chain == NULL)
+               goto errout;
        if (TC_H_MIN(tcm->tcm_parent)) {
                cl = cops->get(q, tcm->tcm_parent);
                if (cl == 0)
@@ -531,7 +544,8 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
        if (src->action) {
                struct tc_action *act;
                tcf_tree_lock(tp);
-               act = xchg(&dst->action, src->action);
+               act = dst->action;
+               dst->action = src->action;
                tcf_tree_unlock(tp);
                if (act)
                        tcf_action_destroy(act, TCA_ACT_UNBIND);