netfilter: ebtables: Simplify the arguments to ebt_do_table
[deliverable/linux.git] / net / ipv6 / netfilter / ip6table_nat.c
1 /*
2 * Copyright (c) 2011 Patrick McHardy <kaber@trash.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * Based on Rusty Russell's IPv4 NAT code. Development of IPv6 NAT
9 * funded by Astaro.
10 */
11
12 #include <linux/module.h>
13 #include <linux/netfilter.h>
14 #include <linux/netfilter_ipv6.h>
15 #include <linux/netfilter_ipv6/ip6_tables.h>
16 #include <linux/ipv6.h>
17 #include <net/ipv6.h>
18
19 #include <net/netfilter/nf_nat.h>
20 #include <net/netfilter/nf_nat_core.h>
21 #include <net/netfilter/nf_nat_l3proto.h>
22
23 static const struct xt_table nf_nat_ipv6_table = {
24 .name = "nat",
25 .valid_hooks = (1 << NF_INET_PRE_ROUTING) |
26 (1 << NF_INET_POST_ROUTING) |
27 (1 << NF_INET_LOCAL_OUT) |
28 (1 << NF_INET_LOCAL_IN),
29 .me = THIS_MODULE,
30 .af = NFPROTO_IPV6,
31 };
32
33 static unsigned int ip6table_nat_do_chain(const struct nf_hook_ops *ops,
34 struct sk_buff *skb,
35 const struct nf_hook_state *state,
36 struct nf_conn *ct)
37 {
38 return ip6t_do_table(skb, ops->hooknum, state,
39 state->net->ipv6.ip6table_nat);
40 }
41
42 static unsigned int ip6table_nat_fn(const struct nf_hook_ops *ops,
43 struct sk_buff *skb,
44 const struct nf_hook_state *state)
45 {
46 return nf_nat_ipv6_fn(ops, skb, state, ip6table_nat_do_chain);
47 }
48
49 static unsigned int ip6table_nat_in(const struct nf_hook_ops *ops,
50 struct sk_buff *skb,
51 const struct nf_hook_state *state)
52 {
53 return nf_nat_ipv6_in(ops, skb, state, ip6table_nat_do_chain);
54 }
55
56 static unsigned int ip6table_nat_out(const struct nf_hook_ops *ops,
57 struct sk_buff *skb,
58 const struct nf_hook_state *state)
59 {
60 return nf_nat_ipv6_out(ops, skb, state, ip6table_nat_do_chain);
61 }
62
63 static unsigned int ip6table_nat_local_fn(const struct nf_hook_ops *ops,
64 struct sk_buff *skb,
65 const struct nf_hook_state *state)
66 {
67 return nf_nat_ipv6_local_fn(ops, skb, state, ip6table_nat_do_chain);
68 }
69
70 static struct nf_hook_ops nf_nat_ipv6_ops[] __read_mostly = {
71 /* Before packet filtering, change destination */
72 {
73 .hook = ip6table_nat_in,
74 .owner = THIS_MODULE,
75 .pf = NFPROTO_IPV6,
76 .hooknum = NF_INET_PRE_ROUTING,
77 .priority = NF_IP6_PRI_NAT_DST,
78 },
79 /* After packet filtering, change source */
80 {
81 .hook = ip6table_nat_out,
82 .owner = THIS_MODULE,
83 .pf = NFPROTO_IPV6,
84 .hooknum = NF_INET_POST_ROUTING,
85 .priority = NF_IP6_PRI_NAT_SRC,
86 },
87 /* Before packet filtering, change destination */
88 {
89 .hook = ip6table_nat_local_fn,
90 .owner = THIS_MODULE,
91 .pf = NFPROTO_IPV6,
92 .hooknum = NF_INET_LOCAL_OUT,
93 .priority = NF_IP6_PRI_NAT_DST,
94 },
95 /* After packet filtering, change source */
96 {
97 .hook = ip6table_nat_fn,
98 .owner = THIS_MODULE,
99 .pf = NFPROTO_IPV6,
100 .hooknum = NF_INET_LOCAL_IN,
101 .priority = NF_IP6_PRI_NAT_SRC,
102 },
103 };
104
105 static int __net_init ip6table_nat_net_init(struct net *net)
106 {
107 struct ip6t_replace *repl;
108
109 repl = ip6t_alloc_initial_table(&nf_nat_ipv6_table);
110 if (repl == NULL)
111 return -ENOMEM;
112 net->ipv6.ip6table_nat = ip6t_register_table(net, &nf_nat_ipv6_table, repl);
113 kfree(repl);
114 return PTR_ERR_OR_ZERO(net->ipv6.ip6table_nat);
115 }
116
117 static void __net_exit ip6table_nat_net_exit(struct net *net)
118 {
119 ip6t_unregister_table(net, net->ipv6.ip6table_nat);
120 }
121
122 static struct pernet_operations ip6table_nat_net_ops = {
123 .init = ip6table_nat_net_init,
124 .exit = ip6table_nat_net_exit,
125 };
126
127 static int __init ip6table_nat_init(void)
128 {
129 int err;
130
131 err = register_pernet_subsys(&ip6table_nat_net_ops);
132 if (err < 0)
133 goto err1;
134
135 err = nf_register_hooks(nf_nat_ipv6_ops, ARRAY_SIZE(nf_nat_ipv6_ops));
136 if (err < 0)
137 goto err2;
138 return 0;
139
140 err2:
141 unregister_pernet_subsys(&ip6table_nat_net_ops);
142 err1:
143 return err;
144 }
145
146 static void __exit ip6table_nat_exit(void)
147 {
148 nf_unregister_hooks(nf_nat_ipv6_ops, ARRAY_SIZE(nf_nat_ipv6_ops));
149 unregister_pernet_subsys(&ip6table_nat_net_ops);
150 }
151
152 module_init(ip6table_nat_init);
153 module_exit(ip6table_nat_exit);
154
155 MODULE_LICENSE("GPL");
This page took 0.053221 seconds and 5 git commands to generate.