Commit a5b5c958 authored by WANG Cong's avatar WANG Cong Committed by David S. Miller

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: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 86062033
...@@ -89,7 +89,7 @@ struct tc_action_ops { ...@@ -89,7 +89,7 @@ struct tc_action_ops {
struct module *owner; struct module *owner;
int (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *); int (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *);
int (*dump)(struct sk_buff *, struct tc_action *, int, int); int (*dump)(struct sk_buff *, struct tc_action *, int, int);
int (*cleanup)(struct tc_action *, int bind); void (*cleanup)(struct tc_action *, int bind);
int (*lookup)(struct tc_action *, u32); int (*lookup)(struct tc_action *, u32);
int (*init)(struct net *net, struct nlattr *nla, int (*init)(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action *act, int ovr, struct nlattr *est, struct tc_action *act, int ovr,
......
...@@ -56,6 +56,8 @@ int tcf_hash_release(struct tc_action *a, int bind) ...@@ -56,6 +56,8 @@ int tcf_hash_release(struct tc_action *a, int bind)
p->tcfc_refcnt--; p->tcfc_refcnt--;
if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) { if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
if (a->ops->cleanup)
a->ops->cleanup(a, bind);
tcf_hash_destroy(a); tcf_hash_destroy(a);
ret = 1; ret = 1;
} }
...@@ -277,8 +279,8 @@ int tcf_register_action(struct tc_action_ops *act) ...@@ -277,8 +279,8 @@ int tcf_register_action(struct tc_action_ops *act)
{ {
struct tc_action_ops *a; struct tc_action_ops *a;
/* Must supply act, dump, cleanup and init */ /* Must supply act, dump and init */
if (!act->act || !act->dump || !act->cleanup || !act->init) if (!act->act || !act->dump || !act->init)
return -EINVAL; return -EINVAL;
/* Supply defaults */ /* Supply defaults */
...@@ -390,7 +392,7 @@ void tcf_action_destroy(struct list_head *actions, int bind) ...@@ -390,7 +392,7 @@ void tcf_action_destroy(struct list_head *actions, int bind)
struct tc_action *a, *tmp; struct tc_action *a, *tmp;
list_for_each_entry_safe(a, tmp, actions, list) { list_for_each_entry_safe(a, tmp, actions, list) {
if (a->ops->cleanup(a, bind) == ACT_P_DELETED) if (tcf_hash_release(a, bind) == ACT_P_DELETED)
module_put(a->ops->owner); module_put(a->ops->owner);
list_del(&a->list); list_del(&a->list);
kfree(a); kfree(a);
......
...@@ -566,7 +566,6 @@ static struct tc_action_ops act_csum_ops = { ...@@ -566,7 +566,6 @@ static struct tc_action_ops act_csum_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.act = tcf_csum, .act = tcf_csum,
.dump = tcf_csum_dump, .dump = tcf_csum_dump,
.cleanup = tcf_hash_release,
.init = tcf_csum_init, .init = tcf_csum_init,
}; };
......
...@@ -185,7 +185,6 @@ static struct tc_action_ops act_gact_ops = { ...@@ -185,7 +185,6 @@ static struct tc_action_ops act_gact_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.act = tcf_gact, .act = tcf_gact,
.dump = tcf_gact_dump, .dump = tcf_gact_dump,
.cleanup = tcf_hash_release,
.init = tcf_gact_init, .init = tcf_gact_init,
}; };
......
...@@ -69,23 +69,12 @@ static void ipt_destroy_target(struct xt_entry_target *t) ...@@ -69,23 +69,12 @@ static void ipt_destroy_target(struct xt_entry_target *t)
module_put(par.target->me); module_put(par.target->me);
} }
static int tcf_ipt_release(struct tc_action *a, int bind) static void tcf_ipt_release(struct tc_action *a, int bind)
{ {
struct tcf_ipt *ipt = to_ipt(a); struct tcf_ipt *ipt = to_ipt(a);
int ret = 0; ipt_destroy_target(ipt->tcfi_t);
if (ipt) { kfree(ipt->tcfi_tname);
if (bind) kfree(ipt->tcfi_t);
ipt->tcf_bindcnt--;
ipt->tcf_refcnt--;
if (ipt->tcf_bindcnt <= 0 && ipt->tcf_refcnt <= 0) {
ipt_destroy_target(ipt->tcfi_t);
kfree(ipt->tcfi_tname);
kfree(ipt->tcfi_t);
tcf_hash_destroy(a);
ret = ACT_P_DELETED;
}
}
return ret;
} }
static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = { static 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,7 +122,7 @@ static int tcf_ipt_init(struct net *net, struct nlattr *nla, struct nlattr *est,
} else { } else {
if (bind)/* dont override defaults */ if (bind)/* dont override defaults */
return 0; return 0;
tcf_ipt_release(a, bind); tcf_hash_release(a, bind);
if (!ovr) if (!ovr)
return -EEXIST; return -EEXIST;
......
...@@ -33,22 +33,12 @@ ...@@ -33,22 +33,12 @@
static LIST_HEAD(mirred_list); static LIST_HEAD(mirred_list);
static struct tcf_hashinfo mirred_hash_info; static struct tcf_hashinfo mirred_hash_info;
static int tcf_mirred_release(struct tc_action *a, int bind) static void tcf_mirred_release(struct tc_action *a, int bind)
{ {
struct tcf_mirred *m = to_mirred(a); struct tcf_mirred *m = to_mirred(a);
if (m) { list_del(&m->tcfm_list);
if (bind) if (m->tcfm_dev)
m->tcf_bindcnt--; dev_put(m->tcfm_dev);
m->tcf_refcnt--;
if (!m->tcf_bindcnt && m->tcf_refcnt <= 0) {
list_del(&m->tcfm_list);
if (m->tcfm_dev)
dev_put(m->tcfm_dev);
tcf_hash_destroy(a);
return 1;
}
}
return 0;
} }
static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = { static 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,7 +100,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else {
if (!ovr) { if (!ovr) {
tcf_mirred_release(a, bind); tcf_hash_release(a, bind);
return -EEXIST; return -EEXIST;
} }
} }
......
...@@ -289,7 +289,6 @@ static struct tc_action_ops act_nat_ops = { ...@@ -289,7 +289,6 @@ static struct tc_action_ops act_nat_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.act = tcf_nat, .act = tcf_nat,
.dump = tcf_nat_dump, .dump = tcf_nat_dump,
.cleanup = tcf_hash_release,
.init = tcf_nat_init, .init = tcf_nat_init,
}; };
......
...@@ -99,18 +99,11 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, ...@@ -99,18 +99,11 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
return ret; return ret;
} }
static int tcf_pedit_cleanup(struct tc_action *a, int bind) static void tcf_pedit_cleanup(struct tc_action *a, int bind)
{ {
struct tcf_pedit *p = a->priv; struct tcf_pedit *p = a->priv;
struct tc_pedit_key *keys = p->tcfp_keys;
if (p) { kfree(keys);
struct tc_pedit_key *keys = p->tcfp_keys;
if (tcf_hash_release(a, bind)) {
kfree(keys);
return 1;
}
}
return 0;
} }
static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a, static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
......
...@@ -354,7 +354,6 @@ static struct tc_action_ops act_police_ops = { ...@@ -354,7 +354,6 @@ static struct tc_action_ops act_police_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.act = tcf_act_police, .act = tcf_act_police,
.dump = tcf_act_police_dump, .dump = tcf_act_police_dump,
.cleanup = tcf_hash_release,
.init = tcf_act_police_locate, .init = tcf_act_police_locate,
.walk = tcf_act_police_walker .walk = tcf_act_police_walker
}; };
......
...@@ -47,21 +47,10 @@ static int tcf_simp(struct sk_buff *skb, const struct tc_action *a, ...@@ -47,21 +47,10 @@ static int tcf_simp(struct sk_buff *skb, const struct tc_action *a,
return d->tcf_action; return d->tcf_action;
} }
static int tcf_simp_release(struct tc_action *a, int bind) static void tcf_simp_release(struct tc_action *a, int bind)
{ {
struct tcf_defact *d = to_defact(a); struct tcf_defact *d = to_defact(a);
int ret = 0; kfree(d->tcfd_defdata);
if (d) {
if (bind)
d->tcf_bindcnt--;
d->tcf_refcnt--;
if (d->tcf_bindcnt <= 0 && d->tcf_refcnt <= 0) {
kfree(d->tcfd_defdata);
tcf_hash_destroy(a);
ret = 1;
}
}
return ret;
} }
static int alloc_defdata(struct tcf_defact *d, char *defdata) static 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,7 +121,7 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
if (bind) if (bind)
return 0; return 0;
tcf_simp_release(a, bind); tcf_hash_release(a, bind);
if (!ovr) if (!ovr)
return -EEXIST; return -EEXIST;
......
...@@ -180,7 +180,6 @@ static struct tc_action_ops act_skbedit_ops = { ...@@ -180,7 +180,6 @@ static struct tc_action_ops act_skbedit_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.act = tcf_skbedit, .act = tcf_skbedit,
.dump = tcf_skbedit_dump, .dump = tcf_skbedit_dump,
.cleanup = tcf_hash_release,
.init = tcf_skbedit_init, .init = tcf_skbedit_init,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment