]>
Commit | Line | Data |
---|---|---|
9fb9cbb1 YK |
1 | /* |
2 | * Copyright (C)2004 USAGI/WIDE Project | |
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 | * Author: | |
9 | * Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> | |
9fb9cbb1 YK |
10 | */ |
11 | ||
9fb9cbb1 YK |
12 | #include <linux/types.h> |
13 | #include <linux/ipv6.h> | |
14 | #include <linux/in6.h> | |
15 | #include <linux/netfilter.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/skbuff.h> | |
18 | #include <linux/icmp.h> | |
9fb9cbb1 | 19 | #include <net/ipv6.h> |
04128f23 | 20 | #include <net/inet_frag.h> |
9fb9cbb1 | 21 | |
8fa9ff68 | 22 | #include <linux/netfilter_bridge.h> |
9fb9cbb1 | 23 | #include <linux/netfilter_ipv6.h> |
121d1e09 | 24 | #include <linux/netfilter_ipv6/ip6_tables.h> |
9fb9cbb1 YK |
25 | #include <net/netfilter/nf_conntrack.h> |
26 | #include <net/netfilter/nf_conntrack_helper.h> | |
605dcad6 | 27 | #include <net/netfilter/nf_conntrack_l4proto.h> |
9fb9cbb1 YK |
28 | #include <net/netfilter/nf_conntrack_l3proto.h> |
29 | #include <net/netfilter/nf_conntrack_core.h> | |
5d0aa2cc | 30 | #include <net/netfilter/nf_conntrack_zones.h> |
41d73ec0 | 31 | #include <net/netfilter/nf_conntrack_seqadj.h> |
9d2493f8 | 32 | #include <net/netfilter/ipv6/nf_conntrack_ipv6.h> |
58a317f1 | 33 | #include <net/netfilter/nf_nat_helper.h> |
e97c3e27 | 34 | #include <net/netfilter/ipv6/nf_defrag_ipv6.h> |
74f7a655 | 35 | #include <net/netfilter/nf_log.h> |
9fb9cbb1 | 36 | |
8ce8439a JE |
37 | static bool ipv6_pkt_to_tuple(const struct sk_buff *skb, unsigned int nhoff, |
38 | struct nf_conntrack_tuple *tuple) | |
9fb9cbb1 | 39 | { |
32948588 JE |
40 | const u_int32_t *ap; |
41 | u_int32_t _addrs[8]; | |
9fb9cbb1 YK |
42 | |
43 | ap = skb_header_pointer(skb, nhoff + offsetof(struct ipv6hdr, saddr), | |
44 | sizeof(_addrs), _addrs); | |
45 | if (ap == NULL) | |
8ce8439a | 46 | return false; |
9fb9cbb1 YK |
47 | |
48 | memcpy(tuple->src.u3.ip6, ap, sizeof(tuple->src.u3.ip6)); | |
49 | memcpy(tuple->dst.u3.ip6, ap + 4, sizeof(tuple->dst.u3.ip6)); | |
50 | ||
8ce8439a | 51 | return true; |
9fb9cbb1 YK |
52 | } |
53 | ||
8ce8439a JE |
54 | static bool ipv6_invert_tuple(struct nf_conntrack_tuple *tuple, |
55 | const struct nf_conntrack_tuple *orig) | |
9fb9cbb1 YK |
56 | { |
57 | memcpy(tuple->src.u3.ip6, orig->dst.u3.ip6, sizeof(tuple->src.u3.ip6)); | |
58 | memcpy(tuple->dst.u3.ip6, orig->src.u3.ip6, sizeof(tuple->dst.u3.ip6)); | |
59 | ||
8ce8439a | 60 | return true; |
9fb9cbb1 YK |
61 | } |
62 | ||
824f1fbe | 63 | static void ipv6_print_tuple(struct seq_file *s, |
9fb9cbb1 YK |
64 | const struct nf_conntrack_tuple *tuple) |
65 | { | |
824f1fbe JP |
66 | seq_printf(s, "src=%pI6 dst=%pI6 ", |
67 | tuple->src.u3.ip6, tuple->dst.u3.ip6); | |
9fb9cbb1 YK |
68 | } |
69 | ||
ffc30690 YK |
70 | static int ipv6_get_l4proto(const struct sk_buff *skb, unsigned int nhoff, |
71 | unsigned int *dataoff, u_int8_t *protonum) | |
9fb9cbb1 | 72 | { |
ffc30690 | 73 | unsigned int extoff = nhoff + sizeof(struct ipv6hdr); |
2b60af01 | 74 | __be16 frag_off; |
ffc30690 | 75 | int protoff; |
2b60af01 | 76 | u8 nexthdr; |
ffc30690 YK |
77 | |
78 | if (skb_copy_bits(skb, nhoff + offsetof(struct ipv6hdr, nexthdr), | |
2b60af01 | 79 | &nexthdr, sizeof(nexthdr)) != 0) { |
ffc30690 YK |
80 | pr_debug("ip6_conntrack_core: can't get nexthdr\n"); |
81 | return -NF_ACCEPT; | |
82 | } | |
2b60af01 | 83 | protoff = ipv6_skip_exthdr(skb, extoff, &nexthdr, &frag_off); |
9fb9cbb1 | 84 | /* |
d7a769ff FF |
85 | * (protoff == skb->len) means the packet has not data, just |
86 | * IPv6 and possibly extensions headers, but it is tracked anyway | |
9fb9cbb1 | 87 | */ |
2b60af01 | 88 | if (protoff < 0 || (frag_off & htons(~0x7)) != 0) { |
0d53778e | 89 | pr_debug("ip6_conntrack_core: can't find proto in pkt\n"); |
9fb9cbb1 YK |
90 | return -NF_ACCEPT; |
91 | } | |
92 | ||
93 | *dataoff = protoff; | |
2b60af01 | 94 | *protonum = nexthdr; |
9fb9cbb1 YK |
95 | return NF_ACCEPT; |
96 | } | |
97 | ||
795aa6ef | 98 | static unsigned int ipv6_helper(const struct nf_hook_ops *ops, |
12f7a505 | 99 | struct sk_buff *skb, |
238e54c9 | 100 | const struct nf_hook_state *state) |
9fb9cbb1 YK |
101 | { |
102 | struct nf_conn *ct; | |
32948588 JE |
103 | const struct nf_conn_help *help; |
104 | const struct nf_conntrack_helper *helper; | |
9fb9cbb1 | 105 | enum ip_conntrack_info ctinfo; |
4cdd3408 PM |
106 | __be16 frag_off; |
107 | int protoff; | |
108 | u8 nexthdr; | |
9fb9cbb1 YK |
109 | |
110 | /* This is where we call the helper: as the packet goes out. */ | |
3db05fea | 111 | ct = nf_ct_get(skb, &ctinfo); |
fb048833 | 112 | if (!ct || ctinfo == IP_CT_RELATED_REPLY) |
12f7a505 | 113 | return NF_ACCEPT; |
dc808fe2 HW |
114 | |
115 | help = nfct_help(ct); | |
3c158f7f | 116 | if (!help) |
12f7a505 | 117 | return NF_ACCEPT; |
3c158f7f PM |
118 | /* rcu_read_lock()ed by nf_hook_slow */ |
119 | helper = rcu_dereference(help->helper); | |
120 | if (!helper) | |
12f7a505 | 121 | return NF_ACCEPT; |
dc808fe2 | 122 | |
4cdd3408 PM |
123 | nexthdr = ipv6_hdr(skb)->nexthdr; |
124 | protoff = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &nexthdr, | |
125 | &frag_off); | |
126 | if (protoff < 0 || (frag_off & htons(~0x7)) != 0) { | |
0d53778e | 127 | pr_debug("proto header not found\n"); |
dc808fe2 | 128 | return NF_ACCEPT; |
9fb9cbb1 YK |
129 | } |
130 | ||
b20ab9cc | 131 | return helper->help(skb, protoff, ct, ctinfo); |
12f7a505 PNA |
132 | } |
133 | ||
795aa6ef | 134 | static unsigned int ipv6_confirm(const struct nf_hook_ops *ops, |
12f7a505 | 135 | struct sk_buff *skb, |
238e54c9 | 136 | const struct nf_hook_state *state) |
12f7a505 | 137 | { |
58a317f1 PM |
138 | struct nf_conn *ct; |
139 | enum ip_conntrack_info ctinfo; | |
140 | unsigned char pnum = ipv6_hdr(skb)->nexthdr; | |
141 | int protoff; | |
142 | __be16 frag_off; | |
143 | ||
144 | ct = nf_ct_get(skb, &ctinfo); | |
145 | if (!ct || ctinfo == IP_CT_RELATED_REPLY) | |
146 | goto out; | |
147 | ||
148 | protoff = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &pnum, | |
149 | &frag_off); | |
150 | if (protoff < 0 || (frag_off & htons(~0x7)) != 0) { | |
151 | pr_debug("proto header not found\n"); | |
152 | goto out; | |
153 | } | |
154 | ||
155 | /* adjust seqs for loopback traffic only in outgoing direction */ | |
156 | if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) && | |
157 | !nf_is_loopback_packet(skb)) { | |
41d73ec0 | 158 | if (!nf_ct_seq_adjust(skb, ct, ctinfo, protoff)) { |
58a317f1 PM |
159 | NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop); |
160 | return NF_DROP; | |
161 | } | |
162 | } | |
163 | out: | |
9fb9cbb1 | 164 | /* We've seen it coming out the other side: confirm it */ |
3db05fea | 165 | return nf_conntrack_confirm(skb); |
9fb9cbb1 YK |
166 | } |
167 | ||
795aa6ef | 168 | static unsigned int ipv6_conntrack_in(const struct nf_hook_ops *ops, |
a702a65f | 169 | struct sk_buff *skb, |
238e54c9 | 170 | const struct nf_hook_state *state) |
a702a65f | 171 | { |
238e54c9 | 172 | return nf_conntrack_in(dev_net(state->in), PF_INET6, ops->hooknum, skb); |
9fb9cbb1 YK |
173 | } |
174 | ||
795aa6ef | 175 | static unsigned int ipv6_conntrack_local(const struct nf_hook_ops *ops, |
3db05fea | 176 | struct sk_buff *skb, |
238e54c9 | 177 | const struct nf_hook_state *state) |
9fb9cbb1 YK |
178 | { |
179 | /* root is playing with raw sockets. */ | |
3db05fea | 180 | if (skb->len < sizeof(struct ipv6hdr)) { |
e87cc472 | 181 | net_notice_ratelimited("ipv6_conntrack_local: packet too short\n"); |
9fb9cbb1 YK |
182 | return NF_ACCEPT; |
183 | } | |
238e54c9 | 184 | return nf_conntrack_in(dev_net(state->out), PF_INET6, ops->hooknum, skb); |
9fb9cbb1 YK |
185 | } |
186 | ||
1999414a | 187 | static struct nf_hook_ops ipv6_conntrack_ops[] __read_mostly = { |
964ddaa1 PM |
188 | { |
189 | .hook = ipv6_conntrack_in, | |
190 | .owner = THIS_MODULE, | |
57750a22 | 191 | .pf = NFPROTO_IPV6, |
6e23ae2a | 192 | .hooknum = NF_INET_PRE_ROUTING, |
964ddaa1 PM |
193 | .priority = NF_IP6_PRI_CONNTRACK, |
194 | }, | |
195 | { | |
196 | .hook = ipv6_conntrack_local, | |
197 | .owner = THIS_MODULE, | |
57750a22 | 198 | .pf = NFPROTO_IPV6, |
6e23ae2a | 199 | .hooknum = NF_INET_LOCAL_OUT, |
964ddaa1 PM |
200 | .priority = NF_IP6_PRI_CONNTRACK, |
201 | }, | |
12f7a505 PNA |
202 | { |
203 | .hook = ipv6_helper, | |
204 | .owner = THIS_MODULE, | |
205 | .pf = NFPROTO_IPV6, | |
206 | .hooknum = NF_INET_POST_ROUTING, | |
207 | .priority = NF_IP6_PRI_CONNTRACK_HELPER, | |
208 | }, | |
964ddaa1 PM |
209 | { |
210 | .hook = ipv6_confirm, | |
211 | .owner = THIS_MODULE, | |
57750a22 | 212 | .pf = NFPROTO_IPV6, |
6e23ae2a | 213 | .hooknum = NF_INET_POST_ROUTING, |
964ddaa1 PM |
214 | .priority = NF_IP6_PRI_LAST, |
215 | }, | |
12f7a505 PNA |
216 | { |
217 | .hook = ipv6_helper, | |
218 | .owner = THIS_MODULE, | |
219 | .pf = NFPROTO_IPV6, | |
220 | .hooknum = NF_INET_LOCAL_IN, | |
221 | .priority = NF_IP6_PRI_CONNTRACK_HELPER, | |
222 | }, | |
964ddaa1 PM |
223 | { |
224 | .hook = ipv6_confirm, | |
225 | .owner = THIS_MODULE, | |
57750a22 | 226 | .pf = NFPROTO_IPV6, |
6e23ae2a | 227 | .hooknum = NF_INET_LOCAL_IN, |
964ddaa1 PM |
228 | .priority = NF_IP6_PRI_LAST-1, |
229 | }, | |
9fb9cbb1 YK |
230 | }; |
231 | ||
121d1e09 FW |
232 | static int |
233 | ipv6_getorigdst(struct sock *sk, int optval, void __user *user, int *len) | |
234 | { | |
235 | const struct inet_sock *inet = inet_sk(sk); | |
236 | const struct ipv6_pinfo *inet6 = inet6_sk(sk); | |
237 | const struct nf_conntrack_tuple_hash *h; | |
238 | struct sockaddr_in6 sin6; | |
239 | struct nf_conntrack_tuple tuple = { .src.l3num = NFPROTO_IPV6 }; | |
240 | struct nf_conn *ct; | |
241 | ||
efe4208f | 242 | tuple.src.u3.in6 = sk->sk_v6_rcv_saddr; |
121d1e09 | 243 | tuple.src.u.tcp.port = inet->inet_sport; |
efe4208f | 244 | tuple.dst.u3.in6 = sk->sk_v6_daddr; |
121d1e09 FW |
245 | tuple.dst.u.tcp.port = inet->inet_dport; |
246 | tuple.dst.protonum = sk->sk_protocol; | |
247 | ||
248 | if (sk->sk_protocol != IPPROTO_TCP && sk->sk_protocol != IPPROTO_SCTP) | |
249 | return -ENOPROTOOPT; | |
250 | ||
251 | if (*len < 0 || (unsigned int) *len < sizeof(sin6)) | |
252 | return -EINVAL; | |
253 | ||
254 | h = nf_conntrack_find_get(sock_net(sk), NF_CT_DEFAULT_ZONE, &tuple); | |
255 | if (!h) { | |
256 | pr_debug("IP6T_SO_ORIGINAL_DST: Can't find %pI6c/%u-%pI6c/%u.\n", | |
257 | &tuple.src.u3.ip6, ntohs(tuple.src.u.tcp.port), | |
258 | &tuple.dst.u3.ip6, ntohs(tuple.dst.u.tcp.port)); | |
259 | return -ENOENT; | |
260 | } | |
261 | ||
262 | ct = nf_ct_tuplehash_to_ctrack(h); | |
263 | ||
264 | sin6.sin6_family = AF_INET6; | |
265 | sin6.sin6_port = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u.tcp.port; | |
266 | sin6.sin6_flowinfo = inet6->flow_label & IPV6_FLOWINFO_MASK; | |
267 | memcpy(&sin6.sin6_addr, | |
268 | &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.in6, | |
269 | sizeof(sin6.sin6_addr)); | |
121d1e09 FW |
270 | |
271 | nf_ct_put(ct); | |
d00bd3d4 HFS |
272 | sin6.sin6_scope_id = ipv6_iface_scope_id(&sin6.sin6_addr, |
273 | sk->sk_bound_dev_if); | |
121d1e09 FW |
274 | return copy_to_user(user, &sin6, sizeof(sin6)) ? -EFAULT : 0; |
275 | } | |
276 | ||
07a93626 | 277 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
c1d10adb PNA |
278 | |
279 | #include <linux/netfilter/nfnetlink.h> | |
280 | #include <linux/netfilter/nfnetlink_conntrack.h> | |
281 | ||
fdf70832 | 282 | static int ipv6_tuple_to_nlattr(struct sk_buff *skb, |
c1d10adb PNA |
283 | const struct nf_conntrack_tuple *tuple) |
284 | { | |
930345ea JB |
285 | if (nla_put_in6_addr(skb, CTA_IP_V6_SRC, &tuple->src.u3.in6) || |
286 | nla_put_in6_addr(skb, CTA_IP_V6_DST, &tuple->dst.u3.in6)) | |
e549a6b3 | 287 | goto nla_put_failure; |
c1d10adb PNA |
288 | return 0; |
289 | ||
df6fb868 | 290 | nla_put_failure: |
c1d10adb PNA |
291 | return -1; |
292 | } | |
293 | ||
f73e924c PM |
294 | static const struct nla_policy ipv6_nla_policy[CTA_IP_MAX+1] = { |
295 | [CTA_IP_V6_SRC] = { .len = sizeof(u_int32_t)*4 }, | |
296 | [CTA_IP_V6_DST] = { .len = sizeof(u_int32_t)*4 }, | |
c1d10adb PNA |
297 | }; |
298 | ||
fdf70832 | 299 | static int ipv6_nlattr_to_tuple(struct nlattr *tb[], |
c1d10adb PNA |
300 | struct nf_conntrack_tuple *t) |
301 | { | |
df6fb868 | 302 | if (!tb[CTA_IP_V6_SRC] || !tb[CTA_IP_V6_DST]) |
c1d10adb PNA |
303 | return -EINVAL; |
304 | ||
67b61f6c JB |
305 | t->src.u3.in6 = nla_get_in6_addr(tb[CTA_IP_V6_SRC]); |
306 | t->dst.u3.in6 = nla_get_in6_addr(tb[CTA_IP_V6_DST]); | |
c1d10adb PNA |
307 | |
308 | return 0; | |
309 | } | |
a400c30e HE |
310 | |
311 | static int ipv6_nlattr_tuple_size(void) | |
312 | { | |
313 | return nla_policy_len(ipv6_nla_policy, CTA_IP_MAX + 1); | |
314 | } | |
c1d10adb PNA |
315 | #endif |
316 | ||
61075af5 | 317 | struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6 __read_mostly = { |
9fb9cbb1 YK |
318 | .l3proto = PF_INET6, |
319 | .name = "ipv6", | |
320 | .pkt_to_tuple = ipv6_pkt_to_tuple, | |
321 | .invert_tuple = ipv6_invert_tuple, | |
322 | .print_tuple = ipv6_print_tuple, | |
ffc30690 | 323 | .get_l4proto = ipv6_get_l4proto, |
07a93626 | 324 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
fdf70832 | 325 | .tuple_to_nlattr = ipv6_tuple_to_nlattr, |
a400c30e | 326 | .nlattr_tuple_size = ipv6_nlattr_tuple_size, |
fdf70832 | 327 | .nlattr_to_tuple = ipv6_nlattr_to_tuple, |
f73e924c | 328 | .nla_policy = ipv6_nla_policy, |
c1d10adb | 329 | #endif |
9fb9cbb1 YK |
330 | .me = THIS_MODULE, |
331 | }; | |
332 | ||
32292a7f PM |
333 | MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET6)); |
334 | MODULE_LICENSE("GPL"); | |
335 | MODULE_AUTHOR("Yasuyuki KOZAKAI @USAGI <yasuyuki.kozakai@toshiba.co.jp>"); | |
336 | ||
121d1e09 FW |
337 | static struct nf_sockopt_ops so_getorigdst6 = { |
338 | .pf = NFPROTO_IPV6, | |
339 | .get_optmin = IP6T_SO_ORIGINAL_DST, | |
340 | .get_optmax = IP6T_SO_ORIGINAL_DST + 1, | |
341 | .get = ipv6_getorigdst, | |
342 | .owner = THIS_MODULE, | |
343 | }; | |
344 | ||
a7c439d3 | 345 | static int ipv6_net_init(struct net *net) |
9fb9cbb1 YK |
346 | { |
347 | int ret = 0; | |
348 | ||
c296bb4d | 349 | ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_tcp6); |
9fb9cbb1 | 350 | if (ret < 0) { |
c296bb4d | 351 | pr_err("nf_conntrack_tcp6: pernet registration failed\n"); |
a7c439d3 | 352 | goto out; |
9fb9cbb1 | 353 | } |
c296bb4d | 354 | ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udp6); |
9fb9cbb1 | 355 | if (ret < 0) { |
c296bb4d | 356 | pr_err("nf_conntrack_udp6: pernet registration failed\n"); |
a7c439d3 | 357 | goto cleanup_tcp6; |
9fb9cbb1 | 358 | } |
c296bb4d | 359 | ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_icmpv6); |
9fb9cbb1 | 360 | if (ret < 0) { |
c296bb4d | 361 | pr_err("nf_conntrack_icmp6: pernet registration failed\n"); |
a7c439d3 | 362 | goto cleanup_udp6; |
9fb9cbb1 | 363 | } |
6330750d | 364 | ret = nf_ct_l3proto_pernet_register(net, &nf_conntrack_l3proto_ipv6); |
9fb9cbb1 | 365 | if (ret < 0) { |
6330750d | 366 | pr_err("nf_conntrack_ipv6: pernet registration failed.\n"); |
9fb9cbb1 YK |
367 | goto cleanup_icmpv6; |
368 | } | |
a7c439d3 G |
369 | return 0; |
370 | cleanup_icmpv6: | |
c296bb4d | 371 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_icmpv6); |
a7c439d3 | 372 | cleanup_udp6: |
c296bb4d | 373 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udp6); |
a7c439d3 | 374 | cleanup_tcp6: |
c296bb4d | 375 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_tcp6); |
a7c439d3 G |
376 | out: |
377 | return ret; | |
378 | } | |
9fb9cbb1 | 379 | |
a7c439d3 G |
380 | static void ipv6_net_exit(struct net *net) |
381 | { | |
6330750d | 382 | nf_ct_l3proto_pernet_unregister(net, &nf_conntrack_l3proto_ipv6); |
c296bb4d G |
383 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_icmpv6); |
384 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udp6); | |
385 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_tcp6); | |
a7c439d3 G |
386 | } |
387 | ||
388 | static struct pernet_operations ipv6_net_ops = { | |
389 | .init = ipv6_net_init, | |
390 | .exit = ipv6_net_exit, | |
391 | }; | |
392 | ||
393 | static int __init nf_conntrack_l3proto_ipv6_init(void) | |
394 | { | |
395 | int ret = 0; | |
396 | ||
397 | need_conntrack(); | |
398 | nf_defrag_ipv6_enable(); | |
399 | ||
121d1e09 FW |
400 | ret = nf_register_sockopt(&so_getorigdst6); |
401 | if (ret < 0) { | |
402 | pr_err("Unable to register netfilter socket option\n"); | |
403 | return ret; | |
404 | } | |
405 | ||
a7c439d3 G |
406 | ret = register_pernet_subsys(&ipv6_net_ops); |
407 | if (ret < 0) | |
6330750d G |
408 | goto cleanup_sockopt; |
409 | ||
964ddaa1 PM |
410 | ret = nf_register_hooks(ipv6_conntrack_ops, |
411 | ARRAY_SIZE(ipv6_conntrack_ops)); | |
9fb9cbb1 | 412 | if (ret < 0) { |
654d0fbd | 413 | pr_err("nf_conntrack_ipv6: can't register pre-routing defrag " |
9fb9cbb1 | 414 | "hook.\n"); |
6330750d G |
415 | goto cleanup_pernet; |
416 | } | |
417 | ||
c296bb4d G |
418 | ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_tcp6); |
419 | if (ret < 0) { | |
420 | pr_err("nf_conntrack_ipv6: can't register tcp6 proto.\n"); | |
421 | goto cleanup_hooks; | |
422 | } | |
423 | ||
424 | ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udp6); | |
425 | if (ret < 0) { | |
426 | pr_err("nf_conntrack_ipv6: can't register udp6 proto.\n"); | |
427 | goto cleanup_tcp6; | |
428 | } | |
429 | ||
430 | ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_icmpv6); | |
431 | if (ret < 0) { | |
432 | pr_err("nf_conntrack_ipv6: can't register icmpv6 proto.\n"); | |
433 | goto cleanup_udp6; | |
434 | } | |
435 | ||
6330750d G |
436 | ret = nf_ct_l3proto_register(&nf_conntrack_l3proto_ipv6); |
437 | if (ret < 0) { | |
438 | pr_err("nf_conntrack_ipv6: can't register ipv6 proto.\n"); | |
c296bb4d | 439 | goto cleanup_icmpv6; |
9fb9cbb1 | 440 | } |
9fb9cbb1 YK |
441 | return ret; |
442 | ||
c296bb4d G |
443 | cleanup_icmpv6: |
444 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_icmpv6); | |
445 | cleanup_udp6: | |
446 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udp6); | |
447 | cleanup_tcp6: | |
448 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_tcp6); | |
6330750d G |
449 | cleanup_hooks: |
450 | nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops)); | |
a7c439d3 | 451 | cleanup_pernet: |
6330750d G |
452 | unregister_pernet_subsys(&ipv6_net_ops); |
453 | cleanup_sockopt: | |
121d1e09 | 454 | nf_unregister_sockopt(&so_getorigdst6); |
9fb9cbb1 YK |
455 | return ret; |
456 | } | |
457 | ||
65b4b4e8 | 458 | static void __exit nf_conntrack_l3proto_ipv6_fini(void) |
9fb9cbb1 | 459 | { |
32292a7f | 460 | synchronize_net(); |
6330750d | 461 | nf_ct_l3proto_unregister(&nf_conntrack_l3proto_ipv6); |
c296bb4d G |
462 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_tcp6); |
463 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udp6); | |
464 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_icmpv6); | |
32292a7f | 465 | nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops)); |
a7c439d3 | 466 | unregister_pernet_subsys(&ipv6_net_ops); |
121d1e09 | 467 | nf_unregister_sockopt(&so_getorigdst6); |
9fb9cbb1 YK |
468 | } |
469 | ||
65b4b4e8 AM |
470 | module_init(nf_conntrack_l3proto_ipv6_init); |
471 | module_exit(nf_conntrack_l3proto_ipv6_fini); |