net sched actions: fix GETing actions
authorJamal Hadi Salim <jhs@mojatatu.com>
Mon, 19 Sep 2016 23:02:51 +0000 (19:02 -0400)
committerDavid S. Miller <davem@davemloft.net>
Wed, 21 Sep 2016 03:34:55 +0000 (23:34 -0400)
With the batch changes that translated transient actions into
a temporary list lost in the translation was the fact that
tcf_action_destroy() will eventually delete the action from
the permanent location if the refcount is zero.

Example of what broke:
...add a gact action to drop
sudo $TC actions add action drop index 10
...now retrieve it, looks good
sudo $TC actions get action gact index 10
...retrieve it again and find it is gone!
sudo $TC actions get action gact index 10

Fixes: 22dc13c837c3 ("net_sched: convert tcf_exts from list to pointer array"),
Fixes: 824a7e8863b3 ("net_sched: remove an unnecessary list_del()")
Fixes: f07fed82ad79 ("net_sched: remove the leftover cleanup_a()")
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/act_api.c

index d0aceb1740b124e5c2759e3ff60f53430d95e097..c9102172ce3b0fa72ceabacc8475ae30298d0ec4 100644 (file)
@@ -592,6 +592,17 @@ err_out:
        return ERR_PTR(err);
 }
 
+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)
 {
@@ -611,8 +622,15 @@ int tcf_action_init(struct net *net, struct nlattr *nla, struct nlattr *est,
                        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);
        }