diff options
author | Jan Engelhardt <jengelh@medozas.de> | 2009-06-17 16:14:54 -0400 |
---|---|---|
committer | Jan Engelhardt <jengelh@medozas.de> | 2010-02-10 11:50:47 -0500 |
commit | e3eaa9910b380530cfd2c0670fcd3f627674da8a (patch) | |
tree | 309e522e78f78149ec3cb99ffc386d1b72415a96 | |
parent | 2b95efe7f6bb750256a702cc32d33b0cb2cd8223 (diff) |
netfilter: xtables: generate initial table on-demand
The static initial tables are pretty large, and after the net
namespace has been instantiated, they just hang around for nothing.
This commit removes them and creates tables on-demand at runtime when
needed.
Size shrinks by 7735 bytes (x86_64).
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
-rw-r--r-- | include/linux/netfilter_arp/arp_tables.h | 1 | ||||
-rw-r--r-- | include/linux/netfilter_ipv4/ip_tables.h | 1 | ||||
-rw-r--r-- | include/linux/netfilter_ipv6/ip6_tables.h | 1 | ||||
-rw-r--r-- | net/ipv4/netfilter/arp_tables.c | 7 | ||||
-rw-r--r-- | net/ipv4/netfilter/arptable_filter.c | 40 | ||||
-rw-r--r-- | net/ipv4/netfilter/ip_tables.c | 7 | ||||
-rw-r--r-- | net/ipv4/netfilter/iptable_filter.c | 46 | ||||
-rw-r--r-- | net/ipv4/netfilter/iptable_mangle.c | 46 | ||||
-rw-r--r-- | net/ipv4/netfilter/iptable_raw.c | 36 | ||||
-rw-r--r-- | net/ipv4/netfilter/iptable_security.c | 39 | ||||
-rw-r--r-- | net/ipv4/netfilter/nf_nat_rule.c | 39 | ||||
-rw-r--r-- | net/ipv6/netfilter/ip6_tables.c | 7 | ||||
-rw-r--r-- | net/ipv6/netfilter/ip6table_filter.c | 46 | ||||
-rw-r--r-- | net/ipv6/netfilter/ip6table_mangle.c | 45 | ||||
-rw-r--r-- | net/ipv6/netfilter/ip6table_raw.c | 36 | ||||
-rw-r--r-- | net/ipv6/netfilter/ip6table_security.c | 39 | ||||
-rw-r--r-- | net/netfilter/x_tables.c | 4 | ||||
-rw-r--r-- | net/netfilter/xt_repldata.h | 35 |
18 files changed, 141 insertions, 334 deletions
diff --git a/include/linux/netfilter_arp/arp_tables.h b/include/linux/netfilter_arp/arp_tables.h index f2336523a9df..0b33980611b2 100644 --- a/include/linux/netfilter_arp/arp_tables.h +++ b/include/linux/netfilter_arp/arp_tables.h | |||
@@ -258,6 +258,7 @@ struct arpt_error { | |||
258 | .target.errorname = "ERROR", \ | 258 | .target.errorname = "ERROR", \ |
259 | } | 259 | } |
260 | 260 | ||
261 | extern void *arpt_alloc_initial_table(const struct xt_table *); | ||
261 | extern struct xt_table *arpt_register_table(struct net *net, | 262 | extern struct xt_table *arpt_register_table(struct net *net, |
262 | const struct xt_table *table, | 263 | const struct xt_table *table, |
263 | const struct arpt_replace *repl); | 264 | const struct arpt_replace *repl); |
diff --git a/include/linux/netfilter_ipv4/ip_tables.h b/include/linux/netfilter_ipv4/ip_tables.h index 8d1f273d350b..364973b42133 100644 --- a/include/linux/netfilter_ipv4/ip_tables.h +++ b/include/linux/netfilter_ipv4/ip_tables.h | |||
@@ -282,6 +282,7 @@ struct ipt_error { | |||
282 | .target.errorname = "ERROR", \ | 282 | .target.errorname = "ERROR", \ |
283 | } | 283 | } |
284 | 284 | ||
285 | extern void *ipt_alloc_initial_table(const struct xt_table *); | ||
285 | extern unsigned int ipt_do_table(struct sk_buff *skb, | 286 | extern unsigned int ipt_do_table(struct sk_buff *skb, |
286 | unsigned int hook, | 287 | unsigned int hook, |
287 | const struct net_device *in, | 288 | const struct net_device *in, |
diff --git a/include/linux/netfilter_ipv6/ip6_tables.h b/include/linux/netfilter_ipv6/ip6_tables.h index d2952d2fa658..8031eb486a10 100644 --- a/include/linux/netfilter_ipv6/ip6_tables.h +++ b/include/linux/netfilter_ipv6/ip6_tables.h | |||
@@ -297,6 +297,7 @@ ip6t_get_target(struct ip6t_entry *e) | |||
297 | #include <linux/init.h> | 297 | #include <linux/init.h> |
298 | extern void ip6t_init(void) __init; | 298 | extern void ip6t_init(void) __init; |
299 | 299 | ||
300 | extern void *ip6t_alloc_initial_table(const struct xt_table *); | ||
300 | extern struct xt_table *ip6t_register_table(struct net *net, | 301 | extern struct xt_table *ip6t_register_table(struct net *net, |
301 | const struct xt_table *table, | 302 | const struct xt_table *table, |
302 | const struct ip6t_replace *repl); | 303 | const struct ip6t_replace *repl); |
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c index 90203e1b9187..72723ea1054b 100644 --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | #include <linux/netfilter/x_tables.h> | 28 | #include <linux/netfilter/x_tables.h> |
29 | #include <linux/netfilter_arp/arp_tables.h> | 29 | #include <linux/netfilter_arp/arp_tables.h> |
30 | #include "../../netfilter/xt_repldata.h" | ||
30 | 31 | ||
31 | MODULE_LICENSE("GPL"); | 32 | MODULE_LICENSE("GPL"); |
32 | MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); | 33 | MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); |
@@ -58,6 +59,12 @@ do { \ | |||
58 | #define ARP_NF_ASSERT(x) | 59 | #define ARP_NF_ASSERT(x) |
59 | #endif | 60 | #endif |
60 | 61 | ||
62 | void *arpt_alloc_initial_table(const struct xt_table *info) | ||
63 | { | ||
64 | return xt_alloc_initial_table(arpt, ARPT); | ||
65 | } | ||
66 | EXPORT_SYMBOL_GPL(arpt_alloc_initial_table); | ||
67 | |||
61 | static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap, | 68 | static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap, |
62 | const char *hdr_addr, int len) | 69 | const char *hdr_addr, int len) |
63 | { | 70 | { |
diff --git a/net/ipv4/netfilter/arptable_filter.c b/net/ipv4/netfilter/arptable_filter.c index b361de0dac4c..bfe26f32b930 100644 --- a/net/ipv4/netfilter/arptable_filter.c +++ b/net/ipv4/netfilter/arptable_filter.c | |||
@@ -6,6 +6,7 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/netfilter/x_tables.h> | ||
9 | #include <linux/netfilter_arp/arp_tables.h> | 10 | #include <linux/netfilter_arp/arp_tables.h> |
10 | 11 | ||
11 | MODULE_LICENSE("GPL"); | 12 | MODULE_LICENSE("GPL"); |
@@ -15,36 +16,6 @@ MODULE_DESCRIPTION("arptables filter table"); | |||
15 | #define FILTER_VALID_HOOKS ((1 << NF_ARP_IN) | (1 << NF_ARP_OUT) | \ | 16 | #define FILTER_VALID_HOOKS ((1 << NF_ARP_IN) | (1 << NF_ARP_OUT) | \ |
16 | (1 << NF_ARP_FORWARD)) | 17 | (1 << NF_ARP_FORWARD)) |
17 | 18 | ||
18 | static const struct | ||
19 | { | ||
20 | struct arpt_replace repl; | ||
21 | struct arpt_standard entries[3]; | ||
22 | struct arpt_error term; | ||
23 | } initial_table __net_initdata = { | ||
24 | .repl = { | ||
25 | .name = "filter", | ||
26 | .valid_hooks = FILTER_VALID_HOOKS, | ||
27 | .num_entries = 4, | ||
28 | .size = sizeof(struct arpt_standard) * 3 + sizeof(struct arpt_error), | ||
29 | .hook_entry = { | ||
30 | [NF_ARP_IN] = 0, | ||
31 | [NF_ARP_OUT] = sizeof(struct arpt_standard), | ||
32 | [NF_ARP_FORWARD] = 2 * sizeof(struct arpt_standard), | ||
33 | }, | ||
34 | .underflow = { | ||
35 | [NF_ARP_IN] = 0, | ||
36 | [NF_ARP_OUT] = sizeof(struct arpt_standard), | ||
37 | [NF_ARP_FORWARD] = 2 * sizeof(struct arpt_standard), | ||
38 | }, | ||
39 | }, | ||
40 | .entries = { | ||
41 | ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_IN */ | ||
42 | ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_OUT */ | ||
43 | ARPT_STANDARD_INIT(NF_ACCEPT), /* ARP_FORWARD */ | ||
44 | }, | ||
45 | .term = ARPT_ERROR_INIT, | ||
46 | }; | ||
47 | |||
48 | static const struct xt_table packet_filter = { | 19 | static const struct xt_table packet_filter = { |
49 | .name = "filter", | 20 | .name = "filter", |
50 | .valid_hooks = FILTER_VALID_HOOKS, | 21 | .valid_hooks = FILTER_VALID_HOOKS, |
@@ -68,9 +39,14 @@ static struct nf_hook_ops *arpfilter_ops __read_mostly; | |||
68 | 39 | ||
69 | static int __net_init arptable_filter_net_init(struct net *net) | 40 | static int __net_init arptable_filter_net_init(struct net *net) |
70 | { | 41 | { |
71 | /* Register table */ | 42 | struct arpt_replace *repl; |
43 | |||
44 | repl = arpt_alloc_initial_table(&packet_filter); | ||
45 | if (repl == NULL) | ||
46 | return -ENOMEM; | ||
72 | net->ipv4.arptable_filter = | 47 | net->ipv4.arptable_filter = |
73 | arpt_register_table(net, &packet_filter, &initial_table.repl); | 48 | arpt_register_table(net, &packet_filter, repl); |
49 | kfree(repl); | ||
74 | if (IS_ERR(net->ipv4.arptable_filter)) | 50 | if (IS_ERR(net->ipv4.arptable_filter)) |
75 | return PTR_ERR(net->ipv4.arptable_filter); | 51 | return PTR_ERR(net->ipv4.arptable_filter); |
76 | return 0; | 52 | return 0; |
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c index 5bf7de1527a5..2057b1bb6178 100644 --- a/net/ipv4/netfilter/ip_tables.c +++ b/net/ipv4/netfilter/ip_tables.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/netfilter/x_tables.h> | 28 | #include <linux/netfilter/x_tables.h> |
29 | #include <linux/netfilter_ipv4/ip_tables.h> | 29 | #include <linux/netfilter_ipv4/ip_tables.h> |
30 | #include <net/netfilter/nf_log.h> | 30 | #include <net/netfilter/nf_log.h> |
31 | #include "../../netfilter/xt_repldata.h" | ||
31 | 32 | ||
32 | MODULE_LICENSE("GPL"); | 33 | MODULE_LICENSE("GPL"); |
33 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); | 34 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); |
@@ -66,6 +67,12 @@ do { \ | |||
66 | #define inline | 67 | #define inline |
67 | #endif | 68 | #endif |
68 | 69 | ||
70 | void *ipt_alloc_initial_table(const struct xt_table *info) | ||
71 | { | ||
72 | return xt_alloc_initial_table(ipt, IPT); | ||
73 | } | ||
74 | EXPORT_SYMBOL_GPL(ipt_alloc_initial_table); | ||
75 | |||
69 | /* | 76 | /* |
70 | We keep a set of rules for each CPU, so we can avoid write-locking | 77 | We keep a set of rules for each CPU, so we can avoid write-locking |
71 | them in the softirq when updating the counters and therefore | 78 | them in the softirq when updating the counters and therefore |
diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c index c14bb85db1d9..c8dc9800d620 100644 --- a/net/ipv4/netfilter/iptable_filter.c +++ b/net/ipv4/netfilter/iptable_filter.c | |||
@@ -23,36 +23,6 @@ MODULE_DESCRIPTION("iptables filter table"); | |||
23 | (1 << NF_INET_FORWARD) | \ | 23 | (1 << NF_INET_FORWARD) | \ |
24 | (1 << NF_INET_LOCAL_OUT)) | 24 | (1 << NF_INET_LOCAL_OUT)) |
25 | 25 | ||
26 | static struct | ||
27 | { | ||
28 | struct ipt_replace repl; | ||
29 | struct ipt_standard entries[3]; | ||
30 | struct ipt_error term; | ||
31 | } initial_table __net_initdata = { | ||
32 | .repl = { | ||
33 | .name = "filter", | ||
34 | .valid_hooks = FILTER_VALID_HOOKS, | ||
35 | .num_entries = 4, | ||
36 | .size = sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error), | ||
37 | .hook_entry = { | ||
38 | [NF_INET_LOCAL_IN] = 0, | ||
39 | [NF_INET_FORWARD] = sizeof(struct ipt_standard), | ||
40 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2, | ||
41 | }, | ||
42 | .underflow = { | ||
43 | [NF_INET_LOCAL_IN] = 0, | ||
44 | [NF_INET_FORWARD] = sizeof(struct ipt_standard), | ||
45 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2, | ||
46 | }, | ||
47 | }, | ||
48 | .entries = { | ||
49 | IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */ | ||
50 | IPT_STANDARD_INIT(NF_ACCEPT), /* FORWARD */ | ||
51 | IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
52 | }, | ||
53 | .term = IPT_ERROR_INIT, /* ERROR */ | ||
54 | }; | ||
55 | |||
56 | static const struct xt_table packet_filter = { | 26 | static const struct xt_table packet_filter = { |
57 | .name = "filter", | 27 | .name = "filter", |
58 | .valid_hooks = FILTER_VALID_HOOKS, | 28 | .valid_hooks = FILTER_VALID_HOOKS, |
@@ -86,9 +56,18 @@ module_param(forward, bool, 0000); | |||
86 | 56 | ||
87 | static int __net_init iptable_filter_net_init(struct net *net) | 57 | static int __net_init iptable_filter_net_init(struct net *net) |
88 | { | 58 | { |
89 | /* Register table */ | 59 | struct ipt_replace *repl; |
60 | |||
61 | repl = ipt_alloc_initial_table(&packet_filter); | ||
62 | if (repl == NULL) | ||
63 | return -ENOMEM; | ||
64 | /* Entry 1 is the FORWARD hook */ | ||
65 | ((struct ipt_standard *)repl->entries)[1].target.verdict = | ||
66 | -forward - 1; | ||
67 | |||
90 | net->ipv4.iptable_filter = | 68 | net->ipv4.iptable_filter = |
91 | ipt_register_table(net, &packet_filter, &initial_table.repl); | 69 | ipt_register_table(net, &packet_filter, repl); |
70 | kfree(repl); | ||
92 | if (IS_ERR(net->ipv4.iptable_filter)) | 71 | if (IS_ERR(net->ipv4.iptable_filter)) |
93 | return PTR_ERR(net->ipv4.iptable_filter); | 72 | return PTR_ERR(net->ipv4.iptable_filter); |
94 | return 0; | 73 | return 0; |
@@ -113,9 +92,6 @@ static int __init iptable_filter_init(void) | |||
113 | return -EINVAL; | 92 | return -EINVAL; |
114 | } | 93 | } |
115 | 94 | ||
116 | /* Entry 1 is the FORWARD hook */ | ||
117 | initial_table.entries[1].target.verdict = -forward - 1; | ||
118 | |||
119 | ret = register_pernet_subsys(&iptable_filter_net_ops); | 95 | ret = register_pernet_subsys(&iptable_filter_net_ops); |
120 | if (ret < 0) | 96 | if (ret < 0) |
121 | return ret; | 97 | return ret; |
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c index 2355a229f8ee..58d7097baa3d 100644 --- a/net/ipv4/netfilter/iptable_mangle.c +++ b/net/ipv4/netfilter/iptable_mangle.c | |||
@@ -27,43 +27,6 @@ MODULE_DESCRIPTION("iptables mangle table"); | |||
27 | (1 << NF_INET_LOCAL_OUT) | \ | 27 | (1 << NF_INET_LOCAL_OUT) | \ |
28 | (1 << NF_INET_POST_ROUTING)) | 28 | (1 << NF_INET_POST_ROUTING)) |
29 | 29 | ||
30 | /* Ouch - five different hooks? Maybe this should be a config option..... -- BC */ | ||
31 | static const struct | ||
32 | { | ||
33 | struct ipt_replace repl; | ||
34 | struct ipt_standard entries[5]; | ||
35 | struct ipt_error term; | ||
36 | } initial_table __net_initdata = { | ||
37 | .repl = { | ||
38 | .name = "mangle", | ||
39 | .valid_hooks = MANGLE_VALID_HOOKS, | ||
40 | .num_entries = 6, | ||
41 | .size = sizeof(struct ipt_standard) * 5 + sizeof(struct ipt_error), | ||
42 | .hook_entry = { | ||
43 | [NF_INET_PRE_ROUTING] = 0, | ||
44 | [NF_INET_LOCAL_IN] = sizeof(struct ipt_standard), | ||
45 | [NF_INET_FORWARD] = sizeof(struct ipt_standard) * 2, | ||
46 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 3, | ||
47 | [NF_INET_POST_ROUTING] = sizeof(struct ipt_standard) * 4, | ||
48 | }, | ||
49 | .underflow = { | ||
50 | [NF_INET_PRE_ROUTING] = 0, | ||
51 | [NF_INET_LOCAL_IN] = sizeof(struct ipt_standard), | ||
52 | [NF_INET_FORWARD] = sizeof(struct ipt_standard) * 2, | ||
53 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 3, | ||
54 | [NF_INET_POST_ROUTING] = sizeof(struct ipt_standard) * 4, | ||
55 | }, | ||
56 | }, | ||
57 | .entries = { | ||
58 | IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */ | ||
59 | IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */ | ||
60 | IPT_STANDARD_INIT(NF_ACCEPT), /* FORWARD */ | ||
61 | IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
62 | IPT_STANDARD_INIT(NF_ACCEPT), /* POST_ROUTING */ | ||
63 | }, | ||
64 | .term = IPT_ERROR_INIT, /* ERROR */ | ||
65 | }; | ||
66 | |||
67 | static const struct xt_table packet_mangler = { | 30 | static const struct xt_table packet_mangler = { |
68 | .name = "mangle", | 31 | .name = "mangle", |
69 | .valid_hooks = MANGLE_VALID_HOOKS, | 32 | .valid_hooks = MANGLE_VALID_HOOKS, |
@@ -134,9 +97,14 @@ static struct nf_hook_ops *mangle_ops __read_mostly; | |||
134 | 97 | ||
135 | static int __net_init iptable_mangle_net_init(struct net *net) | 98 | static int __net_init iptable_mangle_net_init(struct net *net) |
136 | { | 99 | { |
137 | /* Register table */ | 100 | struct ipt_replace *repl; |
101 | |||
102 | repl = ipt_alloc_initial_table(&packet_mangler); | ||
103 | if (repl == NULL) | ||
104 | return -ENOMEM; | ||
138 | net->ipv4.iptable_mangle = | 105 | net->ipv4.iptable_mangle = |
139 | ipt_register_table(net, &packet_mangler, &initial_table.repl); | 106 | ipt_register_table(net, &packet_mangler, repl); |
107 | kfree(repl); | ||
140 | if (IS_ERR(net->ipv4.iptable_mangle)) | 108 | if (IS_ERR(net->ipv4.iptable_mangle)) |
141 | return PTR_ERR(net->ipv4.iptable_mangle); | 109 | return PTR_ERR(net->ipv4.iptable_mangle); |
142 | return 0; | 110 | return 0; |
diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c index 62a99154f14c..06fb9d11953c 100644 --- a/net/ipv4/netfilter/iptable_raw.c +++ b/net/ipv4/netfilter/iptable_raw.c | |||
@@ -9,33 +9,6 @@ | |||
9 | 9 | ||
10 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) | 10 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) |
11 | 11 | ||
12 | static const struct | ||
13 | { | ||
14 | struct ipt_replace repl; | ||
15 | struct ipt_standard entries[2]; | ||
16 | struct ipt_error term; | ||
17 | } initial_table __net_initdata = { | ||
18 | .repl = { | ||
19 | .name = "raw", | ||
20 | .valid_hooks = RAW_VALID_HOOKS, | ||
21 | .num_entries = 3, | ||
22 | .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error), | ||
23 | .hook_entry = { | ||
24 | [NF_INET_PRE_ROUTING] = 0, | ||
25 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) | ||
26 | }, | ||
27 | .underflow = { | ||
28 | [NF_INET_PRE_ROUTING] = 0, | ||
29 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) | ||
30 | }, | ||
31 | }, | ||
32 | .entries = { | ||
33 | IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */ | ||
34 | IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
35 | }, | ||
36 | .term = IPT_ERROR_INIT, /* ERROR */ | ||
37 | }; | ||
38 | |||
39 | static const struct xt_table packet_raw = { | 12 | static const struct xt_table packet_raw = { |
40 | .name = "raw", | 13 | .name = "raw", |
41 | .valid_hooks = RAW_VALID_HOOKS, | 14 | .valid_hooks = RAW_VALID_HOOKS, |
@@ -66,9 +39,14 @@ static struct nf_hook_ops *rawtable_ops __read_mostly; | |||
66 | 39 | ||
67 | static int __net_init iptable_raw_net_init(struct net *net) | 40 | static int __net_init iptable_raw_net_init(struct net *net) |
68 | { | 41 | { |
69 | /* Register table */ | 42 | struct ipt_replace *repl; |
43 | |||
44 | repl = ipt_alloc_initial_table(&packet_raw); | ||
45 | if (repl == NULL) | ||
46 | return -ENOMEM; | ||
70 | net->ipv4.iptable_raw = | 47 | net->ipv4.iptable_raw = |
71 | ipt_register_table(net, &packet_raw, &initial_table.repl); | 48 | ipt_register_table(net, &packet_raw, repl); |
49 | kfree(repl); | ||
72 | if (IS_ERR(net->ipv4.iptable_raw)) | 50 | if (IS_ERR(net->ipv4.iptable_raw)) |
73 | return PTR_ERR(net->ipv4.iptable_raw); | 51 | return PTR_ERR(net->ipv4.iptable_raw); |
74 | return 0; | 52 | return 0; |
diff --git a/net/ipv4/netfilter/iptable_security.c b/net/ipv4/netfilter/iptable_security.c index b1bf3ca2c6c7..cce2f64e6f21 100644 --- a/net/ipv4/netfilter/iptable_security.c +++ b/net/ipv4/netfilter/iptable_security.c | |||
@@ -27,36 +27,6 @@ MODULE_DESCRIPTION("iptables security table, for MAC rules"); | |||
27 | (1 << NF_INET_FORWARD) | \ | 27 | (1 << NF_INET_FORWARD) | \ |
28 | (1 << NF_INET_LOCAL_OUT) | 28 | (1 << NF_INET_LOCAL_OUT) |
29 | 29 | ||
30 | static const struct | ||
31 | { | ||
32 | struct ipt_replace repl; | ||
33 | struct ipt_standard entries[3]; | ||
34 | struct ipt_error term; | ||
35 | } initial_table __net_initdata = { | ||
36 | .repl = { | ||
37 | .name = "security", | ||
38 | .valid_hooks = SECURITY_VALID_HOOKS, | ||
39 | .num_entries = 4, | ||
40 | .size = sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error), | ||
41 | .hook_entry = { | ||
42 | [NF_INET_LOCAL_IN] = 0, | ||
43 | [NF_INET_FORWARD] = sizeof(struct ipt_standard), | ||
44 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2, | ||
45 | }, | ||
46 | .underflow = { | ||
47 | [NF_INET_LOCAL_IN] = 0, | ||
48 | [NF_INET_FORWARD] = sizeof(struct ipt_standard), | ||
49 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2, | ||
50 | }, | ||
51 | }, | ||
52 | .entries = { | ||
53 | IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */ | ||
54 | IPT_STANDARD_INIT(NF_ACCEPT), /* FORWARD */ | ||
55 | IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
56 | }, | ||
57 | .term = IPT_ERROR_INIT, /* ERROR */ | ||
58 | }; | ||
59 | |||
60 | static const struct xt_table security_table = { | 30 | static const struct xt_table security_table = { |
61 | .name = "security", | 31 | .name = "security", |
62 | .valid_hooks = SECURITY_VALID_HOOKS, | 32 | .valid_hooks = SECURITY_VALID_HOOKS, |
@@ -87,9 +57,14 @@ static struct nf_hook_ops *sectbl_ops __read_mostly; | |||
87 | 57 | ||
88 | static int __net_init iptable_security_net_init(struct net *net) | 58 | static int __net_init iptable_security_net_init(struct net *net) |
89 | { | 59 | { |
90 | net->ipv4.iptable_security = | 60 | struct ipt_replace *repl; |
91 | ipt_register_table(net, &security_table, &initial_table.repl); | ||
92 | 61 | ||
62 | repl = ipt_alloc_initial_table(&security_table); | ||
63 | if (repl == NULL) | ||
64 | return -ENOMEM; | ||
65 | net->ipv4.iptable_security = | ||
66 | ipt_register_table(net, &security_table, repl); | ||
67 | kfree(repl); | ||
93 | if (IS_ERR(net->ipv4.iptable_security)) | 68 | if (IS_ERR(net->ipv4.iptable_security)) |
94 | return PTR_ERR(net->ipv4.iptable_security); | 69 | return PTR_ERR(net->ipv4.iptable_security); |
95 | 70 | ||
diff --git a/net/ipv4/netfilter/nf_nat_rule.c b/net/ipv4/netfilter/nf_nat_rule.c index 85da34fdc755..ab74cc0535e2 100644 --- a/net/ipv4/netfilter/nf_nat_rule.c +++ b/net/ipv4/netfilter/nf_nat_rule.c | |||
@@ -28,36 +28,6 @@ | |||
28 | (1 << NF_INET_POST_ROUTING) | \ | 28 | (1 << NF_INET_POST_ROUTING) | \ |
29 | (1 << NF_INET_LOCAL_OUT)) | 29 | (1 << NF_INET_LOCAL_OUT)) |
30 | 30 | ||
31 | static const struct | ||
32 | { | ||
33 | struct ipt_replace repl; | ||
34 | struct ipt_standard entries[3]; | ||
35 | struct ipt_error term; | ||
36 | } nat_initial_table __net_initdata = { | ||
37 | .repl = { | ||
38 | .name = "nat", | ||
39 | .valid_hooks = NAT_VALID_HOOKS, | ||
40 | .num_entries = 4, | ||
41 | .size = sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error), | ||
42 | .hook_entry = { | ||
43 | [NF_INET_PRE_ROUTING] = 0, | ||
44 | [NF_INET_POST_ROUTING] = sizeof(struct ipt_standard), | ||
45 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2 | ||
46 | }, | ||
47 | .underflow = { | ||
48 | [NF_INET_PRE_ROUTING] = 0, | ||
49 | [NF_INET_POST_ROUTING] = sizeof(struct ipt_standard), | ||
50 | [NF_INET_LOCAL_OUT] = sizeof(struct ipt_standard) * 2 | ||
51 | }, | ||
52 | }, | ||
53 | .entries = { | ||
54 | IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */ | ||
55 | IPT_STANDARD_INIT(NF_ACCEPT), /* POST_ROUTING */ | ||
56 | IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
57 | }, | ||
58 | .term = IPT_ERROR_INIT, /* ERROR */ | ||
59 | }; | ||
60 | |||
61 | static const struct xt_table nat_table = { | 31 | static const struct xt_table nat_table = { |
62 | .name = "nat", | 32 | .name = "nat", |
63 | .valid_hooks = NAT_VALID_HOOKS, | 33 | .valid_hooks = NAT_VALID_HOOKS, |
@@ -186,8 +156,13 @@ static struct xt_target ipt_dnat_reg __read_mostly = { | |||
186 | 156 | ||
187 | static int __net_init nf_nat_rule_net_init(struct net *net) | 157 | static int __net_init nf_nat_rule_net_init(struct net *net) |
188 | { | 158 | { |
189 | net->ipv4.nat_table = ipt_register_table(net, &nat_table, | 159 | struct ipt_replace *repl; |
190 | &nat_initial_table.repl); | 160 | |
161 | repl = ipt_alloc_initial_table(&nat_table); | ||
162 | if (repl == NULL) | ||
163 | return -ENOMEM; | ||
164 | net->ipv4.nat_table = ipt_register_table(net, &nat_table, repl); | ||
165 | kfree(repl); | ||
191 | if (IS_ERR(net->ipv4.nat_table)) | 166 | if (IS_ERR(net->ipv4.nat_table)) |
192 | return PTR_ERR(net->ipv4.nat_table); | 167 | return PTR_ERR(net->ipv4.nat_table); |
193 | return 0; | 168 | return 0; |
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c index 4332f4591482..dcd7825fe7b6 100644 --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/netfilter_ipv6/ip6_tables.h> | 29 | #include <linux/netfilter_ipv6/ip6_tables.h> |
30 | #include <linux/netfilter/x_tables.h> | 30 | #include <linux/netfilter/x_tables.h> |
31 | #include <net/netfilter/nf_log.h> | 31 | #include <net/netfilter/nf_log.h> |
32 | #include "../../netfilter/xt_repldata.h" | ||
32 | 33 | ||
33 | MODULE_LICENSE("GPL"); | 34 | MODULE_LICENSE("GPL"); |
34 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); | 35 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); |
@@ -67,6 +68,12 @@ do { \ | |||
67 | #define inline | 68 | #define inline |
68 | #endif | 69 | #endif |
69 | 70 | ||
71 | void *ip6t_alloc_initial_table(const struct xt_table *info) | ||
72 | { | ||
73 | return xt_alloc_initial_table(ip6t, IP6T); | ||
74 | } | ||
75 | EXPORT_SYMBOL_GPL(ip6t_alloc_initial_table); | ||
76 | |||
70 | /* | 77 | /* |
71 | We keep a set of rules for each CPU, so we can avoid write-locking | 78 | We keep a set of rules for each CPU, so we can avoid write-locking |
72 | them in the softirq when updating the counters and therefore | 79 | them in the softirq when updating the counters and therefore |
diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c index 6e95d0614ca9..36b72cafc227 100644 --- a/net/ipv6/netfilter/ip6table_filter.c +++ b/net/ipv6/netfilter/ip6table_filter.c | |||
@@ -21,36 +21,6 @@ MODULE_DESCRIPTION("ip6tables filter table"); | |||
21 | (1 << NF_INET_FORWARD) | \ | 21 | (1 << NF_INET_FORWARD) | \ |
22 | (1 << NF_INET_LOCAL_OUT)) | 22 | (1 << NF_INET_LOCAL_OUT)) |
23 | 23 | ||
24 | static struct | ||
25 | { | ||
26 | struct ip6t_replace repl; | ||
27 | struct ip6t_standard entries[3]; | ||
28 | struct ip6t_error term; | ||
29 | } initial_table __net_initdata = { | ||
30 | .repl = { | ||
31 | .name = "filter", | ||
32 | .valid_hooks = FILTER_VALID_HOOKS, | ||
33 | .num_entries = 4, | ||
34 | .size = sizeof(struct ip6t_standard) * 3 + sizeof(struct ip6t_error), | ||
35 | .hook_entry = { | ||
36 | [NF_INET_LOCAL_IN] = 0, | ||
37 | [NF_INET_FORWARD] = sizeof(struct ip6t_standard), | ||
38 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2 | ||
39 | }, | ||
40 | .underflow = { | ||
41 | [NF_INET_LOCAL_IN] = 0, | ||
42 | [NF_INET_FORWARD] = sizeof(struct ip6t_standard), | ||
43 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2 | ||
44 | }, | ||
45 | }, | ||
46 | .entries = { | ||
47 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */ | ||
48 | IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */ | ||
49 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
50 | }, | ||
51 | .term = IP6T_ERROR_INIT, /* ERROR */ | ||
52 | }; | ||
53 | |||
54 | static const struct xt_table packet_filter = { | 24 | static const struct xt_table packet_filter = { |
55 | .name = "filter", | 25 | .name = "filter", |
56 | .valid_hooks = FILTER_VALID_HOOKS, | 26 | .valid_hooks = FILTER_VALID_HOOKS, |
@@ -78,9 +48,18 @@ module_param(forward, bool, 0000); | |||
78 | 48 | ||
79 | static int __net_init ip6table_filter_net_init(struct net *net) | 49 | static int __net_init ip6table_filter_net_init(struct net *net) |
80 | { | 50 | { |
81 | /* Register table */ | 51 | struct ip6t_replace *repl; |
52 | |||
53 | repl = ip6t_alloc_initial_table(&packet_filter); | ||
54 | if (repl == NULL) | ||
55 | return -ENOMEM; | ||
56 | /* Entry 1 is the FORWARD hook */ | ||
57 | ((struct ip6t_standard *)repl->entries)[1].target.verdict = | ||
58 | -forward - 1; | ||
59 | |||
82 | net->ipv6.ip6table_filter = | 60 | net->ipv6.ip6table_filter = |
83 | ip6t_register_table(net, &packet_filter, &initial_table.repl); | 61 | ip6t_register_table(net, &packet_filter, repl); |
62 | kfree(repl); | ||
84 | if (IS_ERR(net->ipv6.ip6table_filter)) | 63 | if (IS_ERR(net->ipv6.ip6table_filter)) |
85 | return PTR_ERR(net->ipv6.ip6table_filter); | 64 | return PTR_ERR(net->ipv6.ip6table_filter); |
86 | return 0; | 65 | return 0; |
@@ -105,9 +84,6 @@ static int __init ip6table_filter_init(void) | |||
105 | return -EINVAL; | 84 | return -EINVAL; |
106 | } | 85 | } |
107 | 86 | ||
108 | /* Entry 1 is the FORWARD hook */ | ||
109 | initial_table.entries[1].target.verdict = -forward - 1; | ||
110 | |||
111 | ret = register_pernet_subsys(&ip6table_filter_net_ops); | 87 | ret = register_pernet_subsys(&ip6table_filter_net_ops); |
112 | if (ret < 0) | 88 | if (ret < 0) |
113 | return ret; | 89 | return ret; |
diff --git a/net/ipv6/netfilter/ip6table_mangle.c b/net/ipv6/netfilter/ip6table_mangle.c index 5023ac52ffec..dc803b7e8e54 100644 --- a/net/ipv6/netfilter/ip6table_mangle.c +++ b/net/ipv6/netfilter/ip6table_mangle.c | |||
@@ -21,42 +21,6 @@ MODULE_DESCRIPTION("ip6tables mangle table"); | |||
21 | (1 << NF_INET_LOCAL_OUT) | \ | 21 | (1 << NF_INET_LOCAL_OUT) | \ |
22 | (1 << NF_INET_POST_ROUTING)) | 22 | (1 << NF_INET_POST_ROUTING)) |
23 | 23 | ||
24 | static const struct | ||
25 | { | ||
26 | struct ip6t_replace repl; | ||
27 | struct ip6t_standard entries[5]; | ||
28 | struct ip6t_error term; | ||
29 | } initial_table __net_initdata = { | ||
30 | .repl = { | ||
31 | .name = "mangle", | ||
32 | .valid_hooks = MANGLE_VALID_HOOKS, | ||
33 | .num_entries = 6, | ||
34 | .size = sizeof(struct ip6t_standard) * 5 + sizeof(struct ip6t_error), | ||
35 | .hook_entry = { | ||
36 | [NF_INET_PRE_ROUTING] = 0, | ||
37 | [NF_INET_LOCAL_IN] = sizeof(struct ip6t_standard), | ||
38 | [NF_INET_FORWARD] = sizeof(struct ip6t_standard) * 2, | ||
39 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 3, | ||
40 | [NF_INET_POST_ROUTING] = sizeof(struct ip6t_standard) * 4, | ||
41 | }, | ||
42 | .underflow = { | ||
43 | [NF_INET_PRE_ROUTING] = 0, | ||
44 | [NF_INET_LOCAL_IN] = sizeof(struct ip6t_standard), | ||
45 | [NF_INET_FORWARD] = sizeof(struct ip6t_standard) * 2, | ||
46 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 3, | ||
47 | [NF_INET_POST_ROUTING] = sizeof(struct ip6t_standard) * 4, | ||
48 | }, | ||
49 | }, | ||
50 | .entries = { | ||
51 | IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */ | ||
52 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */ | ||
53 | IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */ | ||
54 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
55 | IP6T_STANDARD_INIT(NF_ACCEPT), /* POST_ROUTING */ | ||
56 | }, | ||
57 | .term = IP6T_ERROR_INIT, /* ERROR */ | ||
58 | }; | ||
59 | |||
60 | static const struct xt_table packet_mangler = { | 24 | static const struct xt_table packet_mangler = { |
61 | .name = "mangle", | 25 | .name = "mangle", |
62 | .valid_hooks = MANGLE_VALID_HOOKS, | 26 | .valid_hooks = MANGLE_VALID_HOOKS, |
@@ -126,9 +90,14 @@ ip6table_mangle_hook(unsigned int hook, struct sk_buff *skb, | |||
126 | static struct nf_hook_ops *mangle_ops __read_mostly; | 90 | static struct nf_hook_ops *mangle_ops __read_mostly; |
127 | static int __net_init ip6table_mangle_net_init(struct net *net) | 91 | static int __net_init ip6table_mangle_net_init(struct net *net) |
128 | { | 92 | { |
129 | /* Register table */ | 93 | struct ip6t_replace *repl; |
94 | |||
95 | repl = ip6t_alloc_initial_table(&packet_mangler); | ||
96 | if (repl == NULL) | ||
97 | return -ENOMEM; | ||
130 | net->ipv6.ip6table_mangle = | 98 | net->ipv6.ip6table_mangle = |
131 | ip6t_register_table(net, &packet_mangler, &initial_table.repl); | 99 | ip6t_register_table(net, &packet_mangler, repl); |
100 | kfree(repl); | ||
132 | if (IS_ERR(net->ipv6.ip6table_mangle)) | 101 | if (IS_ERR(net->ipv6.ip6table_mangle)) |
133 | return PTR_ERR(net->ipv6.ip6table_mangle); | 102 | return PTR_ERR(net->ipv6.ip6table_mangle); |
134 | return 0; | 103 | return 0; |
diff --git a/net/ipv6/netfilter/ip6table_raw.c b/net/ipv6/netfilter/ip6table_raw.c index 3bfa69511641..aef31a29de9e 100644 --- a/net/ipv6/netfilter/ip6table_raw.c +++ b/net/ipv6/netfilter/ip6table_raw.c | |||
@@ -8,33 +8,6 @@ | |||
8 | 8 | ||
9 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) | 9 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) |
10 | 10 | ||
11 | static const struct | ||
12 | { | ||
13 | struct ip6t_replace repl; | ||
14 | struct ip6t_standard entries[2]; | ||
15 | struct ip6t_error term; | ||
16 | } initial_table __net_initdata = { | ||
17 | .repl = { | ||
18 | .name = "raw", | ||
19 | .valid_hooks = RAW_VALID_HOOKS, | ||
20 | .num_entries = 3, | ||
21 | .size = sizeof(struct ip6t_standard) * 2 + sizeof(struct ip6t_error), | ||
22 | .hook_entry = { | ||
23 | [NF_INET_PRE_ROUTING] = 0, | ||
24 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) | ||
25 | }, | ||
26 | .underflow = { | ||
27 | [NF_INET_PRE_ROUTING] = 0, | ||
28 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) | ||
29 | }, | ||
30 | }, | ||
31 | .entries = { | ||
32 | IP6T_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */ | ||
33 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
34 | }, | ||
35 | .term = IP6T_ERROR_INIT, /* ERROR */ | ||
36 | }; | ||
37 | |||
38 | static const struct xt_table packet_raw = { | 11 | static const struct xt_table packet_raw = { |
39 | .name = "raw", | 12 | .name = "raw", |
40 | .valid_hooks = RAW_VALID_HOOKS, | 13 | .valid_hooks = RAW_VALID_HOOKS, |
@@ -58,9 +31,14 @@ static struct nf_hook_ops *rawtable_ops __read_mostly; | |||
58 | 31 | ||
59 | static int __net_init ip6table_raw_net_init(struct net *net) | 32 | static int __net_init ip6table_raw_net_init(struct net *net) |
60 | { | 33 | { |
61 | /* Register table */ | 34 | struct ip6t_replace *repl; |
35 | |||
36 | repl = ip6t_alloc_initial_table(&packet_raw); | ||
37 | if (repl == NULL) | ||
38 | return -ENOMEM; | ||
62 | net->ipv6.ip6table_raw = | 39 | net->ipv6.ip6table_raw = |
63 | ip6t_register_table(net, &packet_raw, &initial_table.repl); | 40 | ip6t_register_table(net, &packet_raw, repl); |
41 | kfree(repl); | ||
64 | if (IS_ERR(net->ipv6.ip6table_raw)) | 42 | if (IS_ERR(net->ipv6.ip6table_raw)) |
65 | return PTR_ERR(net->ipv6.ip6table_raw); | 43 | return PTR_ERR(net->ipv6.ip6table_raw); |
66 | return 0; | 44 | return 0; |
diff --git a/net/ipv6/netfilter/ip6table_security.c b/net/ipv6/netfilter/ip6table_security.c index dd2200f17a6c..0824d865aa9b 100644 --- a/net/ipv6/netfilter/ip6table_security.c +++ b/net/ipv6/netfilter/ip6table_security.c | |||
@@ -26,36 +26,6 @@ MODULE_DESCRIPTION("ip6tables security table, for MAC rules"); | |||
26 | (1 << NF_INET_FORWARD) | \ | 26 | (1 << NF_INET_FORWARD) | \ |
27 | (1 << NF_INET_LOCAL_OUT) | 27 | (1 << NF_INET_LOCAL_OUT) |
28 | 28 | ||
29 | static const struct | ||
30 | { | ||
31 | struct ip6t_replace repl; | ||
32 | struct ip6t_standard entries[3]; | ||
33 | struct ip6t_error term; | ||
34 | } initial_table __net_initdata = { | ||
35 | .repl = { | ||
36 | .name = "security", | ||
37 | .valid_hooks = SECURITY_VALID_HOOKS, | ||
38 | .num_entries = 4, | ||
39 | .size = sizeof(struct ip6t_standard) * 3 + sizeof(struct ip6t_error), | ||
40 | .hook_entry = { | ||
41 | [NF_INET_LOCAL_IN] = 0, | ||
42 | [NF_INET_FORWARD] = sizeof(struct ip6t_standard), | ||
43 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2, | ||
44 | }, | ||
45 | .underflow = { | ||
46 | [NF_INET_LOCAL_IN] = 0, | ||
47 | [NF_INET_FORWARD] = sizeof(struct ip6t_standard), | ||
48 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2, | ||
49 | }, | ||
50 | }, | ||
51 | .entries = { | ||
52 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */ | ||
53 | IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */ | ||
54 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | ||
55 | }, | ||
56 | .term = IP6T_ERROR_INIT, /* ERROR */ | ||
57 | }; | ||
58 | |||
59 | static const struct xt_table security_table = { | 29 | static const struct xt_table security_table = { |
60 | .name = "security", | 30 | .name = "security", |
61 | .valid_hooks = SECURITY_VALID_HOOKS, | 31 | .valid_hooks = SECURITY_VALID_HOOKS, |
@@ -79,9 +49,14 @@ static struct nf_hook_ops *sectbl_ops __read_mostly; | |||
79 | 49 | ||
80 | static int __net_init ip6table_security_net_init(struct net *net) | 50 | static int __net_init ip6table_security_net_init(struct net *net) |
81 | { | 51 | { |
82 | net->ipv6.ip6table_security = | 52 | struct ip6t_replace *repl; |
83 | ip6t_register_table(net, &security_table, &initial_table.repl); | ||
84 | 53 | ||
54 | repl = ip6t_alloc_initial_table(&security_table); | ||
55 | if (repl == NULL) | ||
56 | return -ENOMEM; | ||
57 | net->ipv6.ip6table_security = | ||
58 | ip6t_register_table(net, &security_table, repl); | ||
59 | kfree(repl); | ||
85 | if (IS_ERR(net->ipv6.ip6table_security)) | 60 | if (IS_ERR(net->ipv6.ip6table_security)) |
86 | return PTR_ERR(net->ipv6.ip6table_security); | 61 | return PTR_ERR(net->ipv6.ip6table_security); |
87 | 62 | ||
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c index b51cb0d7234a..dc2e05cb54c0 100644 --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c | |||
@@ -26,7 +26,9 @@ | |||
26 | 26 | ||
27 | #include <linux/netfilter/x_tables.h> | 27 | #include <linux/netfilter/x_tables.h> |
28 | #include <linux/netfilter_arp.h> | 28 | #include <linux/netfilter_arp.h> |
29 | 29 | #include <linux/netfilter_ipv4/ip_tables.h> | |
30 | #include <linux/netfilter_ipv6/ip6_tables.h> | ||
31 | #include <linux/netfilter_arp/arp_tables.h> | ||
30 | 32 | ||
31 | MODULE_LICENSE("GPL"); | 33 | MODULE_LICENSE("GPL"); |
32 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); | 34 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); |
diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h new file mode 100644 index 000000000000..6efe4e5a81c6 --- /dev/null +++ b/net/netfilter/xt_repldata.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * Today's hack: quantum tunneling in structs | ||
3 | * | ||
4 | * 'entries' and 'term' are never anywhere referenced by word in code. In fact, | ||
5 | * they serve as the hanging-off data accessed through repl.data[]. | ||
6 | */ | ||
7 | |||
8 | #define xt_alloc_initial_table(type, typ2) ({ \ | ||
9 | unsigned int hook_mask = info->valid_hooks; \ | ||
10 | unsigned int nhooks = hweight32(hook_mask); \ | ||
11 | unsigned int bytes = 0, hooknum = 0, i = 0; \ | ||
12 | struct { \ | ||
13 | struct type##_replace repl; \ | ||
14 | struct type##_standard entries[nhooks]; \ | ||
15 | struct type##_error term; \ | ||
16 | } *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \ | ||
17 | if (tbl == NULL) \ | ||
18 | return NULL; \ | ||
19 | strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \ | ||
20 | tbl->term = (struct type##_error)typ2##_ERROR_INIT; \ | ||
21 | tbl->repl.valid_hooks = hook_mask; \ | ||
22 | tbl->repl.num_entries = nhooks + 1; \ | ||
23 | tbl->repl.size = nhooks * sizeof(struct type##_standard) + \ | ||
24 | sizeof(struct type##_error); \ | ||
25 | for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \ | ||
26 | if (!(hook_mask & 1)) \ | ||
27 | continue; \ | ||
28 | tbl->repl.hook_entry[hooknum] = bytes; \ | ||
29 | tbl->repl.underflow[hooknum] = bytes; \ | ||
30 | tbl->entries[i++] = (struct type##_standard) \ | ||
31 | typ2##_STANDARD_INIT(NF_ACCEPT); \ | ||
32 | bytes += sizeof(struct type##_standard); \ | ||
33 | } \ | ||
34 | tbl; \ | ||
35 | }) | ||