Skip to content

Commit

Permalink
net_sched: act: move tcf_hashinfo_init() into tcf_register_action()
Browse files Browse the repository at this point in the history
Cc: Jamal Hadi Salim <[email protected]>
Cc: David S. Miller <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: Jamal Hadi Salim <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
congwang authored and davem330 committed Feb 13, 2014
1 parent a5b5c95 commit 4f1e9d8
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 82 deletions.
2 changes: 1 addition & 1 deletion include/net/act_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a,
void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est);
void tcf_hash_insert(struct tc_action *a);

int tcf_register_action(struct tc_action_ops *a);
int tcf_register_action(struct tc_action_ops *a, unsigned int mask);
int tcf_unregister_action(struct tc_action_ops *a);
void tcf_action_destroy(struct list_head *actions, int bind);
int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
Expand Down
16 changes: 15 additions & 1 deletion net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ EXPORT_SYMBOL(tcf_hash_insert);
static LIST_HEAD(act_base);
static DEFINE_RWLOCK(act_mod_lock);

int tcf_register_action(struct tc_action_ops *act)
int tcf_register_action(struct tc_action_ops *act, unsigned int mask)
{
struct tc_action_ops *a;
int err;

/* Must supply act, dump and init */
if (!act->act || !act->dump || !act->init)
Expand All @@ -289,10 +290,21 @@ int tcf_register_action(struct tc_action_ops *act)
if (!act->walk)
act->walk = tcf_generic_walker;

act->hinfo = kmalloc(sizeof(struct tcf_hashinfo), GFP_KERNEL);
if (!act->hinfo)
return -ENOMEM;
err = tcf_hashinfo_init(act->hinfo, mask);
if (err) {
kfree(act->hinfo);
return err;
}

write_lock(&act_mod_lock);
list_for_each_entry(a, &act_base, head) {
if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
write_unlock(&act_mod_lock);
tcf_hashinfo_destroy(act->hinfo);
kfree(act->hinfo);
return -EEXIST;
}
}
Expand All @@ -311,6 +323,8 @@ int tcf_unregister_action(struct tc_action_ops *act)
list_for_each_entry(a, &act_base, head) {
if (a == act) {
list_del(&act->head);
tcf_hashinfo_destroy(act->hinfo);
kfree(act->hinfo);
err = 0;
break;
}
Expand Down
8 changes: 1 addition & 7 deletions net/sched/act_csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <net/tc_act/tc_csum.h>

#define CSUM_TAB_MASK 15
static struct tcf_hashinfo csum_hash_info;

static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
[TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), },
Expand Down Expand Up @@ -561,7 +560,6 @@ static int tcf_csum_dump(struct sk_buff *skb,

static struct tc_action_ops act_csum_ops = {
.kind = "csum",
.hinfo = &csum_hash_info,
.type = TCA_ACT_CSUM,
.owner = THIS_MODULE,
.act = tcf_csum,
Expand All @@ -574,11 +572,7 @@ MODULE_LICENSE("GPL");

static int __init csum_init_module(void)
{
int err = tcf_hashinfo_init(&csum_hash_info, CSUM_TAB_MASK);
if (err)
return err;

return tcf_register_action(&act_csum_ops);
return tcf_register_action(&act_csum_ops, CSUM_TAB_MASK);
}

static void __exit csum_cleanup_module(void)
Expand Down
8 changes: 1 addition & 7 deletions net/sched/act_gact.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <net/tc_act/tc_gact.h>

#define GACT_TAB_MASK 15
static struct tcf_hashinfo gact_hash_info;

#ifdef CONFIG_GACT_PROB
static int gact_net_rand(struct tcf_gact *gact)
Expand Down Expand Up @@ -180,7 +179,6 @@ static int tcf_gact_dump(struct sk_buff *skb, struct tc_action *a, int bind, int

static struct tc_action_ops act_gact_ops = {
.kind = "gact",
.hinfo = &gact_hash_info,
.type = TCA_ACT_GACT,
.owner = THIS_MODULE,
.act = tcf_gact,
Expand All @@ -194,21 +192,17 @@ MODULE_LICENSE("GPL");

static int __init gact_init_module(void)
{
int err = tcf_hashinfo_init(&gact_hash_info, GACT_TAB_MASK);
if (err)
return err;
#ifdef CONFIG_GACT_PROB
pr_info("GACT probability on\n");
#else
pr_info("GACT probability NOT on\n");
#endif
return tcf_register_action(&act_gact_ops);
return tcf_register_action(&act_gact_ops, GACT_TAB_MASK);
}

static void __exit gact_cleanup_module(void)
{
tcf_unregister_action(&act_gact_ops);
tcf_hashinfo_destroy(&gact_hash_info);
}

module_init(gact_init_module);
Expand Down
14 changes: 3 additions & 11 deletions net/sched/act_ipt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


#define IPT_TAB_MASK 15
static struct tcf_hashinfo ipt_hash_info;

static int ipt_init_target(struct xt_entry_target *t, char *table, unsigned int hook)
{
Expand Down Expand Up @@ -262,7 +261,6 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind, int

static struct tc_action_ops act_ipt_ops = {
.kind = "ipt",
.hinfo = &ipt_hash_info,
.type = TCA_ACT_IPT,
.owner = THIS_MODULE,
.act = tcf_ipt,
Expand All @@ -273,7 +271,6 @@ static struct tc_action_ops act_ipt_ops = {

static struct tc_action_ops act_xt_ops = {
.kind = "xt",
.hinfo = &ipt_hash_info,
.type = TCA_ACT_XT,
.owner = THIS_MODULE,
.act = tcf_ipt,
Expand All @@ -289,20 +286,16 @@ MODULE_ALIAS("act_xt");

static int __init ipt_init_module(void)
{
int ret1, ret2, err;
err = tcf_hashinfo_init(&ipt_hash_info, IPT_TAB_MASK);
if (err)
return err;
int ret1, ret2;

ret1 = tcf_register_action(&act_xt_ops);
ret1 = tcf_register_action(&act_xt_ops, IPT_TAB_MASK);
if (ret1 < 0)
printk("Failed to load xt action\n");
ret2 = tcf_register_action(&act_ipt_ops);
ret2 = tcf_register_action(&act_ipt_ops, IPT_TAB_MASK);
if (ret2 < 0)
printk("Failed to load ipt action\n");

if (ret1 < 0 && ret2 < 0) {
tcf_hashinfo_destroy(&ipt_hash_info);
return ret1;
} else
return 0;
Expand All @@ -312,7 +305,6 @@ static void __exit ipt_cleanup_module(void)
{
tcf_unregister_action(&act_xt_ops);
tcf_unregister_action(&act_ipt_ops);
tcf_hashinfo_destroy(&ipt_hash_info);
}

module_init(ipt_init_module);
Expand Down
10 changes: 1 addition & 9 deletions net/sched/act_mirred.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

#define MIRRED_TAB_MASK 7
static LIST_HEAD(mirred_list);
static struct tcf_hashinfo mirred_hash_info;

static void tcf_mirred_release(struct tc_action *a, int bind)
{
Expand Down Expand Up @@ -234,7 +233,6 @@ static struct notifier_block mirred_device_notifier = {

static struct tc_action_ops act_mirred_ops = {
.kind = "mirred",
.hinfo = &mirred_hash_info,
.type = TCA_ACT_MIRRED,
.owner = THIS_MODULE,
.act = tcf_mirred,
Expand All @@ -253,19 +251,13 @@ static int __init mirred_init_module(void)
if (err)
return err;

err = tcf_hashinfo_init(&mirred_hash_info, MIRRED_TAB_MASK);
if (err) {
unregister_netdevice_notifier(&mirred_device_notifier);
return err;
}
pr_info("Mirror/redirect action on\n");
return tcf_register_action(&act_mirred_ops);
return tcf_register_action(&act_mirred_ops, MIRRED_TAB_MASK);
}

static void __exit mirred_cleanup_module(void)
{
tcf_unregister_action(&act_mirred_ops);
tcf_hashinfo_destroy(&mirred_hash_info);
unregister_netdevice_notifier(&mirred_device_notifier);
}

Expand Down
9 changes: 1 addition & 8 deletions net/sched/act_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#define NAT_TAB_MASK 15

static struct tcf_hashinfo nat_hash_info;

static const struct nla_policy nat_policy[TCA_NAT_MAX + 1] = {
[TCA_NAT_PARMS] = { .len = sizeof(struct tc_nat) },
};
Expand Down Expand Up @@ -284,7 +282,6 @@ static int tcf_nat_dump(struct sk_buff *skb, struct tc_action *a,

static struct tc_action_ops act_nat_ops = {
.kind = "nat",
.hinfo = &nat_hash_info,
.type = TCA_ACT_NAT,
.owner = THIS_MODULE,
.act = tcf_nat,
Expand All @@ -297,16 +294,12 @@ MODULE_LICENSE("GPL");

static int __init nat_init_module(void)
{
int err = tcf_hashinfo_init(&nat_hash_info, NAT_TAB_MASK);
if (err)
return err;
return tcf_register_action(&act_nat_ops);
return tcf_register_action(&act_nat_ops, NAT_TAB_MASK);
}

static void __exit nat_cleanup_module(void)
{
tcf_unregister_action(&act_nat_ops);
tcf_hashinfo_destroy(&nat_hash_info);
}

module_init(nat_init_module);
Expand Down
9 changes: 1 addition & 8 deletions net/sched/act_pedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

#define PEDIT_TAB_MASK 15

static struct tcf_hashinfo pedit_hash_info;

static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
[TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) },
};
Expand Down Expand Up @@ -218,7 +216,6 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,

static struct tc_action_ops act_pedit_ops = {
.kind = "pedit",
.hinfo = &pedit_hash_info,
.type = TCA_ACT_PEDIT,
.owner = THIS_MODULE,
.act = tcf_pedit,
Expand All @@ -233,15 +230,11 @@ MODULE_LICENSE("GPL");

static int __init pedit_init_module(void)
{
int err = tcf_hashinfo_init(&pedit_hash_info, PEDIT_TAB_MASK);
if (err)
return err;
return tcf_register_action(&act_pedit_ops);
return tcf_register_action(&act_pedit_ops, PEDIT_TAB_MASK);
}

static void __exit pedit_cleanup_module(void)
{
tcf_hashinfo_destroy(&pedit_hash_info);
tcf_unregister_action(&act_pedit_ops);
}

Expand Down
13 changes: 2 additions & 11 deletions net/sched/act_police.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct tcf_police {
container_of(pc, struct tcf_police, common)

#define POL_TAB_MASK 15
static struct tcf_hashinfo police_hash_info;

/* old policer structure from before tc actions */
struct tc_police_compat {
Expand Down Expand Up @@ -234,7 +233,7 @@ static int tcf_act_police_locate(struct net *net, struct nlattr *nla,

police->tcfp_t_c = ktime_to_ns(ktime_get());
police->tcf_index = parm->index ? parm->index :
tcf_hash_new_index(a->ops->hinfo);
tcf_hash_new_index(hinfo);
h = tcf_hash(police->tcf_index, POL_TAB_MASK);
spin_lock_bh(&hinfo->lock);
hlist_add_head(&police->tcf_head, &hinfo->htab[h]);
Expand Down Expand Up @@ -349,7 +348,6 @@ MODULE_LICENSE("GPL");

static struct tc_action_ops act_police_ops = {
.kind = "police",
.hinfo = &police_hash_info,
.type = TCA_ID_POLICE,
.owner = THIS_MODULE,
.act = tcf_act_police,
Expand All @@ -361,19 +359,12 @@ static struct tc_action_ops act_police_ops = {
static int __init
police_init_module(void)
{
int err = tcf_hashinfo_init(&police_hash_info, POL_TAB_MASK);
if (err)
return err;
err = tcf_register_action(&act_police_ops);
if (err)
tcf_hashinfo_destroy(&police_hash_info);
return err;
return tcf_register_action(&act_police_ops, POL_TAB_MASK);
}

static void __exit
police_cleanup_module(void)
{
tcf_hashinfo_destroy(&police_hash_info);
tcf_unregister_action(&act_police_ops);
}

Expand Down
14 changes: 2 additions & 12 deletions net/sched/act_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <net/tc_act/tc_defact.h>

#define SIMP_TAB_MASK 7
static struct tcf_hashinfo simp_hash_info;

#define SIMP_MAX_DATA 32
static int tcf_simp(struct sk_buff *skb, const struct tc_action *a,
Expand Down Expand Up @@ -163,7 +162,6 @@ static int tcf_simp_dump(struct sk_buff *skb, struct tc_action *a,

static struct tc_action_ops act_simp_ops = {
.kind = "simple",
.hinfo = &simp_hash_info,
.type = TCA_ACT_SIMP,
.owner = THIS_MODULE,
.act = tcf_simp,
Expand All @@ -178,23 +176,15 @@ MODULE_LICENSE("GPL");

static int __init simp_init_module(void)
{
int err, ret;
err = tcf_hashinfo_init(&simp_hash_info, SIMP_TAB_MASK);
if (err)
return err;

ret = tcf_register_action(&act_simp_ops);
int ret;
ret = tcf_register_action(&act_simp_ops, SIMP_TAB_MASK);
if (!ret)
pr_info("Simple TC action Loaded\n");
else
tcf_hashinfo_destroy(&simp_hash_info);

return ret;
}

static void __exit simp_cleanup_module(void)
{
tcf_hashinfo_destroy(&simp_hash_info);
tcf_unregister_action(&act_simp_ops);
}

Expand Down
Loading

0 comments on commit 4f1e9d8

Please sign in to comment.