aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/netfilter/iptable_mangle.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/netfilter/iptable_mangle.c')
-rw-r--r--net/ipv4/netfilter/iptable_mangle.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c
index 292f2ed4416..c55a210853a 100644
--- a/net/ipv4/netfilter/iptable_mangle.c
+++ b/net/ipv4/netfilter/iptable_mangle.c
@@ -33,7 +33,7 @@ static struct
33 struct ipt_replace repl; 33 struct ipt_replace repl;
34 struct ipt_standard entries[5]; 34 struct ipt_standard entries[5];
35 struct ipt_error term; 35 struct ipt_error term;
36} initial_table __initdata = { 36} initial_table __net_initdata = {
37 .repl = { 37 .repl = {
38 .name = "mangle", 38 .name = "mangle",
39 .valid_hooks = MANGLE_VALID_HOOKS, 39 .valid_hooks = MANGLE_VALID_HOOKS,
@@ -64,14 +64,13 @@ static struct
64 .term = IPT_ERROR_INIT, /* ERROR */ 64 .term = IPT_ERROR_INIT, /* ERROR */
65}; 65};
66 66
67static struct xt_table __packet_mangler = { 67static struct xt_table packet_mangler = {
68 .name = "mangle", 68 .name = "mangle",
69 .valid_hooks = MANGLE_VALID_HOOKS, 69 .valid_hooks = MANGLE_VALID_HOOKS,
70 .lock = RW_LOCK_UNLOCKED, 70 .lock = RW_LOCK_UNLOCKED,
71 .me = THIS_MODULE, 71 .me = THIS_MODULE,
72 .af = AF_INET, 72 .af = AF_INET,
73}; 73};
74static struct xt_table *packet_mangler;
75 74
76/* The work comes in here from netfilter.c. */ 75/* The work comes in here from netfilter.c. */
77static unsigned int 76static unsigned int
@@ -81,7 +80,7 @@ ipt_route_hook(unsigned int hook,
81 const struct net_device *out, 80 const struct net_device *out,
82 int (*okfn)(struct sk_buff *)) 81 int (*okfn)(struct sk_buff *))
83{ 82{
84 return ipt_do_table(skb, hook, in, out, packet_mangler); 83 return ipt_do_table(skb, hook, in, out, init_net.ipv4.iptable_mangle);
85} 84}
86 85
87static unsigned int 86static unsigned int
@@ -113,7 +112,7 @@ ipt_local_hook(unsigned int hook,
113 daddr = iph->daddr; 112 daddr = iph->daddr;
114 tos = iph->tos; 113 tos = iph->tos;
115 114
116 ret = ipt_do_table(skb, hook, in, out, packet_mangler); 115 ret = ipt_do_table(skb, hook, in, out, init_net.ipv4.iptable_mangle);
117 /* Reroute for ANY change. */ 116 /* Reroute for ANY change. */
118 if (ret != NF_DROP && ret != NF_STOLEN && ret != NF_QUEUE) { 117 if (ret != NF_DROP && ret != NF_STOLEN && ret != NF_QUEUE) {
119 iph = ip_hdr(skb); 118 iph = ip_hdr(skb);
@@ -167,15 +166,33 @@ static struct nf_hook_ops ipt_ops[] __read_mostly = {
167 }, 166 },
168}; 167};
169 168
169static int __net_init iptable_mangle_net_init(struct net *net)
170{
171 /* Register table */
172 net->ipv4.iptable_mangle =
173 ipt_register_table(net, &packet_mangler, &initial_table.repl);
174 if (IS_ERR(net->ipv4.iptable_mangle))
175 return PTR_ERR(net->ipv4.iptable_mangle);
176 return 0;
177}
178
179static void __net_exit iptable_mangle_net_exit(struct net *net)
180{
181 ipt_unregister_table(net->ipv4.iptable_mangle);
182}
183
184static struct pernet_operations iptable_mangle_net_ops = {
185 .init = iptable_mangle_net_init,
186 .exit = iptable_mangle_net_exit,
187};
188
170static int __init iptable_mangle_init(void) 189static int __init iptable_mangle_init(void)
171{ 190{
172 int ret; 191 int ret;
173 192
174 /* Register table */ 193 ret = register_pernet_subsys(&iptable_mangle_net_ops);
175 packet_mangler = ipt_register_table(&init_net, &__packet_mangler, 194 if (ret < 0)
176 &initial_table.repl); 195 return ret;
177 if (IS_ERR(packet_mangler))
178 return PTR_ERR(packet_mangler);
179 196
180 /* Register hooks */ 197 /* Register hooks */
181 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 198 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
@@ -185,14 +202,14 @@ static int __init iptable_mangle_init(void)
185 return ret; 202 return ret;
186 203
187 cleanup_table: 204 cleanup_table:
188 ipt_unregister_table(packet_mangler); 205 unregister_pernet_subsys(&iptable_mangle_net_ops);
189 return ret; 206 return ret;
190} 207}
191 208
192static void __exit iptable_mangle_fini(void) 209static void __exit iptable_mangle_fini(void)
193{ 210{
194 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); 211 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
195 ipt_unregister_table(packet_mangler); 212 unregister_pernet_subsys(&iptable_mangle_net_ops);
196} 213}
197 214
198module_init(iptable_mangle_init); 215module_init(iptable_mangle_init);