net sched actions: fix GETing actions
[cascardo/linux.git] / net / sched / act_api.c
index b4c7be3..c910217 100644 (file)
@@ -420,18 +420,19 @@ static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
        return res;
 }
 
-int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
-                   struct tcf_result *res)
+int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
+                   int nr_actions, struct tcf_result *res)
 {
-       const struct tc_action *a;
-       int ret = -1;
+       int ret = -1, i;
 
        if (skb->tc_verd & TC_NCLS) {
                skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
                ret = TC_ACT_OK;
                goto exec_done;
        }
-       list_for_each_entry(a, actions, list) {
+       for (i = 0; i < nr_actions; i++) {
+               const struct tc_action *a = actions[i];
+
 repeat:
                ret = a->ops->act(skb, a, res);
                if (ret == TC_ACT_REPEAT)
@@ -591,9 +592,19 @@ err_out:
        return ERR_PTR(err);
 }
 
-int tcf_action_init(struct net *net, struct nlattr *nla,
-                                 struct nlattr *est, char *name, int ovr,
-                                 int bind, struct list_head *actions)
+static void cleanup_a(struct list_head *actions, int ovr)
+{
+       struct tc_action *a;
+
+       if (!ovr)
+               return;
+
+       list_for_each_entry(a, actions, list)
+               a->tcfa_refcnt--;
+}
+
+int tcf_action_init(struct net *net, struct nlattr *nla, struct nlattr *est,
+                   char *name, int ovr, int bind, struct list_head *actions)
 {
        struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
        struct tc_action *act;
@@ -611,8 +622,15 @@ int tcf_action_init(struct net *net, struct nlattr *nla,
                        goto err;
                }
                act->order = i;
+               if (ovr)
+                       act->tcfa_refcnt++;
                list_add_tail(&act->list, actions);
        }
+
+       /* Remove the temp refcnt which was necessary to protect against
+        * destroying an existing action which was being replaced
+        */
+       cleanup_a(actions, ovr);
        return 0;
 
 err:
@@ -882,6 +900,8 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
                        goto err;
                }
                act->order = i;
+               if (event == RTM_GETACTION)
+                       act->tcfa_refcnt++;
                list_add_tail(&act->list, &actions);
        }
 
@@ -922,9 +942,8 @@ tcf_add_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
        return err;
 }
 
-static int
-tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
-              u32 portid, int ovr)
+static int tcf_action_add(struct net *net, struct nlattr *nla,
+                         struct nlmsghdr *n, u32 portid, int ovr)
 {
        int ret = 0;
        LIST_HEAD(actions);
@@ -987,8 +1006,7 @@ replay:
        return ret;
 }
 
-static struct nlattr *
-find_dump_kind(const struct nlmsghdr *n)
+static struct nlattr *find_dump_kind(const struct nlmsghdr *n)
 {
        struct nlattr *tb1, *tb2[TCA_ACT_MAX + 1];
        struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
@@ -1015,8 +1033,7 @@ find_dump_kind(const struct nlmsghdr *n)
        return kind;
 }
 
-static int
-tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
+static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
 {
        struct net *net = sock_net(skb->sk);
        struct nlmsghdr *nlh;