Commit aee12a0a authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

ebtables: remove nf_hook_register usage

Similar to ip_register_table, pass nf_hook_ops to ebt_register_table().
This allows to handle hook registration also via pernet_ops and allows
us to avoid use of legacy register_hook api.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 1a0ed0ad
...@@ -109,8 +109,10 @@ struct ebt_table { ...@@ -109,8 +109,10 @@ struct ebt_table {
#define EBT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) & \ #define EBT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) & \
~(__alignof__(struct _xt_align)-1)) ~(__alignof__(struct _xt_align)-1))
extern struct ebt_table *ebt_register_table(struct net *net, extern struct ebt_table *ebt_register_table(struct net *net,
const struct ebt_table *table); const struct ebt_table *table,
extern void ebt_unregister_table(struct net *net, struct ebt_table *table); const struct nf_hook_ops *);
extern void ebt_unregister_table(struct net *net, struct ebt_table *table,
const struct nf_hook_ops *);
extern unsigned int ebt_do_table(struct sk_buff *skb, extern unsigned int ebt_do_table(struct sk_buff *skb,
const struct nf_hook_state *state, const struct nf_hook_state *state,
struct ebt_table *table); struct ebt_table *table);
......
...@@ -65,13 +65,13 @@ static int ebt_broute(struct sk_buff *skb) ...@@ -65,13 +65,13 @@ static int ebt_broute(struct sk_buff *skb)
static int __net_init broute_net_init(struct net *net) static int __net_init broute_net_init(struct net *net)
{ {
net->xt.broute_table = ebt_register_table(net, &broute_table); net->xt.broute_table = ebt_register_table(net, &broute_table, NULL);
return PTR_ERR_OR_ZERO(net->xt.broute_table); return PTR_ERR_OR_ZERO(net->xt.broute_table);
} }
static void __net_exit broute_net_exit(struct net *net) static void __net_exit broute_net_exit(struct net *net)
{ {
ebt_unregister_table(net, net->xt.broute_table); ebt_unregister_table(net, net->xt.broute_table, NULL);
} }
static struct pernet_operations broute_net_ops = { static struct pernet_operations broute_net_ops = {
......
...@@ -93,13 +93,13 @@ static struct nf_hook_ops ebt_ops_filter[] __read_mostly = { ...@@ -93,13 +93,13 @@ static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {
static int __net_init frame_filter_net_init(struct net *net) static int __net_init frame_filter_net_init(struct net *net)
{ {
net->xt.frame_filter = ebt_register_table(net, &frame_filter); net->xt.frame_filter = ebt_register_table(net, &frame_filter, ebt_ops_filter);
return PTR_ERR_OR_ZERO(net->xt.frame_filter); return PTR_ERR_OR_ZERO(net->xt.frame_filter);
} }
static void __net_exit frame_filter_net_exit(struct net *net) static void __net_exit frame_filter_net_exit(struct net *net)
{ {
ebt_unregister_table(net, net->xt.frame_filter); ebt_unregister_table(net, net->xt.frame_filter, ebt_ops_filter);
} }
static struct pernet_operations frame_filter_net_ops = { static struct pernet_operations frame_filter_net_ops = {
...@@ -109,20 +109,11 @@ static struct pernet_operations frame_filter_net_ops = { ...@@ -109,20 +109,11 @@ static struct pernet_operations frame_filter_net_ops = {
static int __init ebtable_filter_init(void) static int __init ebtable_filter_init(void)
{ {
int ret; return register_pernet_subsys(&frame_filter_net_ops);
ret = register_pernet_subsys(&frame_filter_net_ops);
if (ret < 0)
return ret;
ret = nf_register_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter));
if (ret < 0)
unregister_pernet_subsys(&frame_filter_net_ops);
return ret;
} }
static void __exit ebtable_filter_fini(void) static void __exit ebtable_filter_fini(void)
{ {
nf_unregister_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter));
unregister_pernet_subsys(&frame_filter_net_ops); unregister_pernet_subsys(&frame_filter_net_ops);
} }
......
...@@ -93,13 +93,13 @@ static struct nf_hook_ops ebt_ops_nat[] __read_mostly = { ...@@ -93,13 +93,13 @@ static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {
static int __net_init frame_nat_net_init(struct net *net) static int __net_init frame_nat_net_init(struct net *net)
{ {
net->xt.frame_nat = ebt_register_table(net, &frame_nat); net->xt.frame_nat = ebt_register_table(net, &frame_nat, ebt_ops_nat);
return PTR_ERR_OR_ZERO(net->xt.frame_nat); return PTR_ERR_OR_ZERO(net->xt.frame_nat);
} }
static void __net_exit frame_nat_net_exit(struct net *net) static void __net_exit frame_nat_net_exit(struct net *net)
{ {
ebt_unregister_table(net, net->xt.frame_nat); ebt_unregister_table(net, net->xt.frame_nat, ebt_ops_nat);
} }
static struct pernet_operations frame_nat_net_ops = { static struct pernet_operations frame_nat_net_ops = {
...@@ -109,20 +109,11 @@ static struct pernet_operations frame_nat_net_ops = { ...@@ -109,20 +109,11 @@ static struct pernet_operations frame_nat_net_ops = {
static int __init ebtable_nat_init(void) static int __init ebtable_nat_init(void)
{ {
int ret; return register_pernet_subsys(&frame_nat_net_ops);
ret = register_pernet_subsys(&frame_nat_net_ops);
if (ret < 0)
return ret;
ret = nf_register_hooks(ebt_ops_nat, ARRAY_SIZE(ebt_ops_nat));
if (ret < 0)
unregister_pernet_subsys(&frame_nat_net_ops);
return ret;
} }
static void __exit ebtable_nat_fini(void) static void __exit ebtable_nat_fini(void)
{ {
nf_unregister_hooks(ebt_ops_nat, ARRAY_SIZE(ebt_ops_nat));
unregister_pernet_subsys(&frame_nat_net_ops); unregister_pernet_subsys(&frame_nat_net_ops);
} }
......
...@@ -1157,8 +1157,30 @@ static int do_replace(struct net *net, const void __user *user, ...@@ -1157,8 +1157,30 @@ static int do_replace(struct net *net, const void __user *user,
return ret; return ret;
} }
static void __ebt_unregister_table(struct net *net, struct ebt_table *table)
{
int i;
mutex_lock(&ebt_mutex);
list_del(&table->list);
mutex_unlock(&ebt_mutex);
EBT_ENTRY_ITERATE(table->private->entries, table->private->entries_size,
ebt_cleanup_entry, net, NULL);
if (table->private->nentries)
module_put(table->me);
vfree(table->private->entries);
if (table->private->chainstack) {
for_each_possible_cpu(i)
vfree(table->private->chainstack[i]);
vfree(table->private->chainstack);
}
vfree(table->private);
kfree(table);
}
struct ebt_table * struct ebt_table *
ebt_register_table(struct net *net, const struct ebt_table *input_table) ebt_register_table(struct net *net, const struct ebt_table *input_table,
const struct nf_hook_ops *ops)
{ {
struct ebt_table_info *newinfo; struct ebt_table_info *newinfo;
struct ebt_table *t, *table; struct ebt_table *t, *table;
...@@ -1238,6 +1260,16 @@ ebt_register_table(struct net *net, const struct ebt_table *input_table) ...@@ -1238,6 +1260,16 @@ ebt_register_table(struct net *net, const struct ebt_table *input_table)
} }
list_add(&table->list, &net->xt.tables[NFPROTO_BRIDGE]); list_add(&table->list, &net->xt.tables[NFPROTO_BRIDGE]);
mutex_unlock(&ebt_mutex); mutex_unlock(&ebt_mutex);
if (!ops)
return table;
ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
if (ret) {
__ebt_unregister_table(net, table);
return ERR_PTR(ret);
}
return table; return table;
free_unlock: free_unlock:
mutex_unlock(&ebt_mutex); mutex_unlock(&ebt_mutex);
...@@ -1256,29 +1288,12 @@ ebt_register_table(struct net *net, const struct ebt_table *input_table) ...@@ -1256,29 +1288,12 @@ ebt_register_table(struct net *net, const struct ebt_table *input_table)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
void ebt_unregister_table(struct net *net, struct ebt_table *table) void ebt_unregister_table(struct net *net, struct ebt_table *table,
const struct nf_hook_ops *ops)
{ {
int i; if (ops)
nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
if (!table) { __ebt_unregister_table(net, table);
BUGPRINT("Request to unregister NULL table!!!\n");
return;
}
mutex_lock(&ebt_mutex);
list_del(&table->list);
mutex_unlock(&ebt_mutex);
EBT_ENTRY_ITERATE(table->private->entries, table->private->entries_size,
ebt_cleanup_entry, net, NULL);
if (table->private->nentries)
module_put(table->me);
vfree(table->private->entries);
if (table->private->chainstack) {
for_each_possible_cpu(i)
vfree(table->private->chainstack[i]);
vfree(table->private->chainstack);
}
vfree(table->private);
kfree(table);
} }
/* userspace just supplied us with counters */ /* userspace just supplied us with counters */
......
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