Skip to content

Commit f9006ac

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: arp_tables: pass table pointer via nf_hook_ops
Same change as previous patch. Only difference: no need to handle NULL template_ops parameter, the only caller (arptable_filter) always passes non-NULL argument. This removes all remaining accesses to net->ipv4.arptable_filter. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent ae68933 commit f9006ac

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

‎include/linux/netfilter_arp/arp_tables.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct arpt_error {
5151
extern void *arpt_alloc_initial_table(const struct xt_table *);
5252
int arpt_register_table(struct net *net, const struct xt_table *table,
5353
const struct arpt_replace *repl,
54-
const struct nf_hook_ops *ops, struct xt_table **res);
54+
const struct nf_hook_ops *ops);
5555
void arpt_unregister_table(struct net *net, const char *name);
5656
void arpt_unregister_table_pre_exit(struct net *net, const char *name,
5757
const struct nf_hook_ops *ops);

‎net/ipv4/netfilter/arp_tables.c‎

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,10 +1499,11 @@ static void __arpt_unregister_table(struct net *net, struct xt_table *table)
14991499
int arpt_register_table(struct net *net,
15001500
const struct xt_table *table,
15011501
const struct arpt_replace *repl,
1502-
const struct nf_hook_ops *ops,
1503-
struct xt_table **res)
1502+
const struct nf_hook_ops *template_ops)
15041503
{
1505-
int ret;
1504+
struct nf_hook_ops *ops;
1505+
unsigned int num_ops;
1506+
int ret, i;
15061507
struct xt_table_info *newinfo;
15071508
struct xt_table_info bootstrap = {0};
15081509
void *loc_cpu_entry;
@@ -1516,28 +1517,42 @@ int arpt_register_table(struct net *net,
15161517
memcpy(loc_cpu_entry, repl->entries, repl->size);
15171518

15181519
ret = translate_table(net, newinfo, loc_cpu_entry, repl);
1519-
if (ret != 0)
1520-
goto out_free;
1520+
if (ret != 0) {
1521+
xt_free_table_info(newinfo);
1522+
return ret;
1523+
}
15211524

15221525
new_table = xt_register_table(net, table, &bootstrap, newinfo);
15231526
if (IS_ERR(new_table)) {
1524-
ret = PTR_ERR(new_table);
1525-
goto out_free;
1527+
xt_free_table_info(newinfo);
1528+
return PTR_ERR(new_table);
15261529
}
15271530

1528-
/* set res now, will see skbs right after nf_register_net_hooks */
1529-
WRITE_ONCE(*res, new_table);
1531+
num_ops = hweight32(table->valid_hooks);
1532+
if (num_ops == 0) {
1533+
ret = -EINVAL;
1534+
goto out_free;
1535+
}
15301536

1531-
ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
1532-
if (ret != 0) {
1533-
__arpt_unregister_table(net, new_table);
1534-
*res = NULL;
1537+
ops = kmemdup(template_ops, sizeof(*ops) * num_ops, GFP_KERNEL);
1538+
if (!ops) {
1539+
ret = -ENOMEM;
1540+
goto out_free;
15351541
}
15361542

1543+
for (i = 0; i < num_ops; i++)
1544+
ops[i].priv = new_table;
1545+
1546+
new_table->ops = ops;
1547+
1548+
ret = nf_register_net_hooks(net, ops, num_ops);
1549+
if (ret != 0)
1550+
goto out_free;
1551+
15371552
return ret;
15381553

15391554
out_free:
1540-
xt_free_table_info(newinfo);
1555+
__arpt_unregister_table(net, new_table);
15411556
return ret;
15421557
}
15431558

‎net/ipv4/netfilter/arptable_filter.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static unsigned int
3434
arptable_filter_hook(void *priv, struct sk_buff *skb,
3535
const struct nf_hook_state *state)
3636
{
37-
return arpt_do_table(skb, state, state->net->ipv4.arptable_filter);
37+
return arpt_do_table(skb, state, priv);
3838
}
3939

4040
static struct nf_hook_ops *arpfilter_ops __read_mostly;
@@ -47,8 +47,7 @@ static int __net_init arptable_filter_table_init(struct net *net)
4747
repl = arpt_alloc_initial_table(&packet_filter);
4848
if (repl == NULL)
4949
return -ENOMEM;
50-
err = arpt_register_table(net, &packet_filter, repl, arpfilter_ops,
51-
&net->ipv4.arptable_filter);
50+
err = arpt_register_table(net, &packet_filter, repl, arpfilter_ops);
5251
kfree(repl);
5352
return err;
5453
}
@@ -61,7 +60,6 @@ static void __net_exit arptable_filter_net_pre_exit(struct net *net)
6160
static void __net_exit arptable_filter_net_exit(struct net *net)
6261
{
6362
arpt_unregister_table(net, "filter");
64-
net->ipv4.arptable_filter = NULL;
6563
}
6664

6765
static struct pernet_operations arptable_filter_net_ops = {

0 commit comments

Comments
 (0)