|
@@ -2071,9 +2071,28 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-struct xt_table *ip6t_register_table(struct net *net,
|
|
|
- const struct xt_table *table,
|
|
|
- const struct ip6t_replace *repl)
|
|
|
+static void __ip6t_unregister_table(struct net *net, struct xt_table *table)
|
|
|
+{
|
|
|
+ struct xt_table_info *private;
|
|
|
+ void *loc_cpu_entry;
|
|
|
+ struct module *table_owner = table->me;
|
|
|
+ struct ip6t_entry *iter;
|
|
|
+
|
|
|
+ private = xt_unregister_table(table);
|
|
|
+
|
|
|
+ /* Decrease module usage counts and free resources */
|
|
|
+ loc_cpu_entry = private->entries;
|
|
|
+ xt_entry_foreach(iter, loc_cpu_entry, private->size)
|
|
|
+ cleanup_entry(iter, net);
|
|
|
+ if (private->number > private->initial_entries)
|
|
|
+ module_put(table_owner);
|
|
|
+ xt_free_table_info(private);
|
|
|
+}
|
|
|
+
|
|
|
+int ip6t_register_table(struct net *net, const struct xt_table *table,
|
|
|
+ const struct ip6t_replace *repl,
|
|
|
+ const struct nf_hook_ops *ops,
|
|
|
+ struct xt_table **res)
|
|
|
{
|
|
|
int ret;
|
|
|
struct xt_table_info *newinfo;
|
|
@@ -2082,10 +2101,8 @@ struct xt_table *ip6t_register_table(struct net *net,
|
|
|
struct xt_table *new_table;
|
|
|
|
|
|
newinfo = xt_alloc_table_info(repl->size);
|
|
|
- if (!newinfo) {
|
|
|
- ret = -ENOMEM;
|
|
|
- goto out;
|
|
|
- }
|
|
|
+ if (!newinfo)
|
|
|
+ return -ENOMEM;
|
|
|
|
|
|
loc_cpu_entry = newinfo->entries;
|
|
|
memcpy(loc_cpu_entry, repl->entries, repl->size);
|
|
@@ -2099,30 +2116,28 @@ struct xt_table *ip6t_register_table(struct net *net,
|
|
|
ret = PTR_ERR(new_table);
|
|
|
goto out_free;
|
|
|
}
|
|
|
- return new_table;
|
|
|
+
|
|
|
+ /* set res now, will see skbs right after nf_register_net_hooks */
|
|
|
+ WRITE_ONCE(*res, new_table);
|
|
|
+
|
|
|
+ ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
|
|
|
+ if (ret != 0) {
|
|
|
+ __ip6t_unregister_table(net, new_table);
|
|
|
+ *res = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
|
|
|
out_free:
|
|
|
xt_free_table_info(newinfo);
|
|
|
-out:
|
|
|
- return ERR_PTR(ret);
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
-void ip6t_unregister_table(struct net *net, struct xt_table *table)
|
|
|
+void ip6t_unregister_table(struct net *net, struct xt_table *table,
|
|
|
+ const struct nf_hook_ops *ops)
|
|
|
{
|
|
|
- struct xt_table_info *private;
|
|
|
- void *loc_cpu_entry;
|
|
|
- struct module *table_owner = table->me;
|
|
|
- struct ip6t_entry *iter;
|
|
|
-
|
|
|
- private = xt_unregister_table(table);
|
|
|
-
|
|
|
- /* Decrease module usage counts and free resources */
|
|
|
- loc_cpu_entry = private->entries;
|
|
|
- xt_entry_foreach(iter, loc_cpu_entry, private->size)
|
|
|
- cleanup_entry(iter, net);
|
|
|
- if (private->number > private->initial_entries)
|
|
|
- module_put(table_owner);
|
|
|
- xt_free_table_info(private);
|
|
|
+ nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
|
|
|
+ __ip6t_unregister_table(net, table);
|
|
|
}
|
|
|
|
|
|
/* Returns 1 if the type and code is matched by the range, 0 otherwise */
|