aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched
diff options
context:
space:
mode:
authorWANG Cong <xiyou.wangcong@gmail.com>2014-02-11 20:07:32 -0500
committerDavid S. Miller <davem@davemloft.net>2014-02-12 19:23:32 -0500
commita5b5c958ffd1610545d6b4b8290aa9c5266d10fa (patch)
tree532a87c5ae6d0c2f2f766820c051f7a5b8f7a366 /net/sched
parent86062033feb8a1692f7a3d570c652f1b4a4b4b52 (diff)
net_sched: act: refactor cleanup ops
For bindcnt and refcnt etc., they are common for all actions, not need to repeat such operations for their own, they can be unified now. Actions just need to do its specific cleanup if needed. Cc: Jamal Hadi Salim <jhs@mojatatu.com> Cc: David S. Miller <davem@davemloft.net> Signed-off-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>
Diffstat (limited to 'net/sched')
-rw-r--r--net/sched/act_api.c8
-rw-r--r--net/sched/act_csum.c1
-rw-r--r--net/sched/act_gact.c1
-rw-r--r--net/sched/act_ipt.c21
-rw-r--r--net/sched/act_mirred.c20
-rw-r--r--net/sched/act_nat.c1
-rw-r--r--net/sched/act_pedit.c13
-rw-r--r--net/sched/act_police.c1
-rw-r--r--net/sched/act_simple.c17
-rw-r--r--net/sched/act_skbedit.c1
10 files changed, 21 insertions, 63 deletions
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 4f2b807b3621..a5bf9351ce5c 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -56,6 +56,8 @@ int tcf_hash_release(struct tc_action *a, int bind)
56 56
57 p->tcfc_refcnt--; 57 p->tcfc_refcnt--;
58 if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) { 58 if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
59 if (a->ops->cleanup)
60 a->ops->cleanup(a, bind);
59 tcf_hash_destroy(a); 61 tcf_hash_destroy(a);
60 ret = 1; 62 ret = 1;
61 } 63 }
@@ -277,8 +279,8 @@ int tcf_register_action(struct tc_action_ops *act)
277{ 279{
278 struct tc_action_ops *a; 280 struct tc_action_ops *a;
279 281
280 /* Must supply act, dump, cleanup and init */ 282 /* Must supply act, dump and init */
281 if (!act->act || !act->dump || !act->cleanup || !act->init) 283 if (!act->act || !act->dump || !act->init)
282 return -EINVAL; 284 return -EINVAL;
283 285
284 /* Supply defaults */ 286 /* Supply defaults */
@@ -390,7 +392,7 @@ void tcf_action_destroy(struct list_head *actions, int bind)
390 struct tc_action *a, *tmp; 392 struct tc_action *a, *tmp;
391 393
392 list_for_each_entry_safe(a, tmp, actions, list) { 394 list_for_each_entry_safe(a, tmp, actions, list) {
393 if (a->ops->cleanup(a, bind) == ACT_P_DELETED) 395 if (tcf_hash_release(a, bind) == ACT_P_DELETED)
394 module_put(a->ops->owner); 396 module_put(a->ops->owner);
395 list_del(&a->list); 397 list_del(&a->list);
396 kfree(a); 398 kfree(a);
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index f0f6e7a625d1..8df3060e7ac1 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -566,7 +566,6 @@ static struct tc_action_ops act_csum_ops = {
566 .owner = THIS_MODULE, 566 .owner = THIS_MODULE,
567 .act = tcf_csum, 567 .act = tcf_csum,
568 .dump = tcf_csum_dump, 568 .dump = tcf_csum_dump,
569 .cleanup = tcf_hash_release,
570 .init = tcf_csum_init, 569 .init = tcf_csum_init,
571}; 570};
572 571
diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
index af6c0acd9bf1..094a1b509d75 100644
--- a/net/sched/act_gact.c
+++ b/net/sched/act_gact.c
@@ -185,7 +185,6 @@ static struct tc_action_ops act_gact_ops = {
185 .owner = THIS_MODULE, 185 .owner = THIS_MODULE,
186 .act = tcf_gact, 186 .act = tcf_gact,
187 .dump = tcf_gact_dump, 187 .dump = tcf_gact_dump,
188 .cleanup = tcf_hash_release,
189 .init = tcf_gact_init, 188 .init = tcf_gact_init,
190}; 189};
191 190
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index f5e69782d400..71f29f1b5a20 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -69,23 +69,12 @@ static void ipt_destroy_target(struct xt_entry_target *t)
69 module_put(par.target->me); 69 module_put(par.target->me);
70} 70}
71 71
72static int tcf_ipt_release(struct tc_action *a, int bind) 72static void tcf_ipt_release(struct tc_action *a, int bind)
73{ 73{
74 struct tcf_ipt *ipt = to_ipt(a); 74 struct tcf_ipt *ipt = to_ipt(a);
75 int ret = 0; 75 ipt_destroy_target(ipt->tcfi_t);
76 if (ipt) { 76 kfree(ipt->tcfi_tname);
77 if (bind) 77 kfree(ipt->tcfi_t);
78 ipt->tcf_bindcnt--;
79 ipt->tcf_refcnt--;
80 if (ipt->tcf_bindcnt <= 0 && ipt->tcf_refcnt <= 0) {
81 ipt_destroy_target(ipt->tcfi_t);
82 kfree(ipt->tcfi_tname);
83 kfree(ipt->tcfi_t);
84 tcf_hash_destroy(a);
85 ret = ACT_P_DELETED;
86 }
87 }
88 return ret;
89} 78}
90 79
91static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = { 80static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = {
@@ -133,7 +122,7 @@ static int tcf_ipt_init(struct net *net, struct nlattr *nla, struct nlattr *est,
133 } else { 122 } else {
134 if (bind)/* dont override defaults */ 123 if (bind)/* dont override defaults */
135 return 0; 124 return 0;
136 tcf_ipt_release(a, bind); 125 tcf_hash_release(a, bind);
137 126
138 if (!ovr) 127 if (!ovr)
139 return -EEXIST; 128 return -EEXIST;
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 3edeecafba2f..0f00eb96af84 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -33,22 +33,12 @@
33static LIST_HEAD(mirred_list); 33static LIST_HEAD(mirred_list);
34static struct tcf_hashinfo mirred_hash_info; 34static struct tcf_hashinfo mirred_hash_info;
35 35
36static int tcf_mirred_release(struct tc_action *a, int bind) 36static void tcf_mirred_release(struct tc_action *a, int bind)
37{ 37{
38 struct tcf_mirred *m = to_mirred(a); 38 struct tcf_mirred *m = to_mirred(a);
39 if (m) { 39 list_del(&m->tcfm_list);
40 if (bind) 40 if (m->tcfm_dev)
41 m->tcf_bindcnt--; 41 dev_put(m->tcfm_dev);
42 m->tcf_refcnt--;
43 if (!m->tcf_bindcnt && m->tcf_refcnt <= 0) {
44 list_del(&m->tcfm_list);
45 if (m->tcfm_dev)
46 dev_put(m->tcfm_dev);
47 tcf_hash_destroy(a);
48 return 1;
49 }
50 }
51 return 0;
52} 42}
53 43
54static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = { 44static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = {
@@ -110,7 +100,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
110 ret = ACT_P_CREATED; 100 ret = ACT_P_CREATED;
111 } else { 101 } else {
112 if (!ovr) { 102 if (!ovr) {
113 tcf_mirred_release(a, bind); 103 tcf_hash_release(a, bind);
114 return -EEXIST; 104 return -EEXIST;
115 } 105 }
116 } 106 }
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index ce9a3914ed4a..9a3cb1d16d19 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -289,7 +289,6 @@ static struct tc_action_ops act_nat_ops = {
289 .owner = THIS_MODULE, 289 .owner = THIS_MODULE,
290 .act = tcf_nat, 290 .act = tcf_nat,
291 .dump = tcf_nat_dump, 291 .dump = tcf_nat_dump,
292 .cleanup = tcf_hash_release,
293 .init = tcf_nat_init, 292 .init = tcf_nat_init,
294}; 293};
295 294
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 091ced38a376..8aa795b275f2 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -99,18 +99,11 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
99 return ret; 99 return ret;
100} 100}
101 101
102static int tcf_pedit_cleanup(struct tc_action *a, int bind) 102static void tcf_pedit_cleanup(struct tc_action *a, int bind)
103{ 103{
104 struct tcf_pedit *p = a->priv; 104 struct tcf_pedit *p = a->priv;
105 105 struct tc_pedit_key *keys = p->tcfp_keys;
106 if (p) { 106 kfree(keys);
107 struct tc_pedit_key *keys = p->tcfp_keys;
108 if (tcf_hash_release(a, bind)) {
109 kfree(keys);
110 return 1;
111 }
112 }
113 return 0;
114} 107}
115 108
116static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a, 109static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 4695d02bd249..7ff7bef065bf 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -354,7 +354,6 @@ static struct tc_action_ops act_police_ops = {
354 .owner = THIS_MODULE, 354 .owner = THIS_MODULE,
355 .act = tcf_act_police, 355 .act = tcf_act_police,
356 .dump = tcf_act_police_dump, 356 .dump = tcf_act_police_dump,
357 .cleanup = tcf_hash_release,
358 .init = tcf_act_police_locate, 357 .init = tcf_act_police_locate,
359 .walk = tcf_act_police_walker 358 .walk = tcf_act_police_walker
360}; 359};
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index 11c2922bb900..14b5e362a1d6 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -47,21 +47,10 @@ static int tcf_simp(struct sk_buff *skb, const struct tc_action *a,
47 return d->tcf_action; 47 return d->tcf_action;
48} 48}
49 49
50static int tcf_simp_release(struct tc_action *a, int bind) 50static void tcf_simp_release(struct tc_action *a, int bind)
51{ 51{
52 struct tcf_defact *d = to_defact(a); 52 struct tcf_defact *d = to_defact(a);
53 int ret = 0; 53 kfree(d->tcfd_defdata);
54 if (d) {
55 if (bind)
56 d->tcf_bindcnt--;
57 d->tcf_refcnt--;
58 if (d->tcf_bindcnt <= 0 && d->tcf_refcnt <= 0) {
59 kfree(d->tcfd_defdata);
60 tcf_hash_destroy(a);
61 ret = 1;
62 }
63 }
64 return ret;
65} 54}
66 55
67static int alloc_defdata(struct tcf_defact *d, char *defdata) 56static int alloc_defdata(struct tcf_defact *d, char *defdata)
@@ -132,7 +121,7 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
132 121
133 if (bind) 122 if (bind)
134 return 0; 123 return 0;
135 tcf_simp_release(a, bind); 124 tcf_hash_release(a, bind);
136 if (!ovr) 125 if (!ovr)
137 return -EEXIST; 126 return -EEXIST;
138 127
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index 71fd2d499109..9f91928fcaeb 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -180,7 +180,6 @@ static struct tc_action_ops act_skbedit_ops = {
180 .owner = THIS_MODULE, 180 .owner = THIS_MODULE,
181 .act = tcf_skbedit, 181 .act = tcf_skbedit,
182 .dump = tcf_skbedit_dump, 182 .dump = tcf_skbedit_dump,
183 .cleanup = tcf_hash_release,
184 .init = tcf_skbedit_init, 183 .init = tcf_skbedit_init,
185}; 184};
186 185