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