blob: 0e40948f4fc6516237b90f940f58bb0e1298c5f8 [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/*
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>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080010 */
11
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080012#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>
19#include <linux/sysctl.h>
20#include <net/ipv6.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070021#include <net/inet_frag.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080022
23#include <linux/netfilter_ipv6.h>
24#include <net/netfilter/nf_conntrack.h>
25#include <net/netfilter/nf_conntrack_helper.h>
Martin Josefsson605dcad2006-11-29 02:35:06 +010026#include <net/netfilter/nf_conntrack_l4proto.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080027#include <net/netfilter/nf_conntrack_l3proto.h>
28#include <net/netfilter/nf_conntrack_core.h>
29
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080030static int ipv6_pkt_to_tuple(const struct sk_buff *skb, unsigned int nhoff,
31 struct nf_conntrack_tuple *tuple)
32{
33 u_int32_t _addrs[8], *ap;
34
35 ap = skb_header_pointer(skb, nhoff + offsetof(struct ipv6hdr, saddr),
36 sizeof(_addrs), _addrs);
37 if (ap == NULL)
38 return 0;
39
40 memcpy(tuple->src.u3.ip6, ap, sizeof(tuple->src.u3.ip6));
41 memcpy(tuple->dst.u3.ip6, ap + 4, sizeof(tuple->dst.u3.ip6));
42
43 return 1;
44}
45
46static int ipv6_invert_tuple(struct nf_conntrack_tuple *tuple,
47 const struct nf_conntrack_tuple *orig)
48{
49 memcpy(tuple->src.u3.ip6, orig->dst.u3.ip6, sizeof(tuple->src.u3.ip6));
50 memcpy(tuple->dst.u3.ip6, orig->src.u3.ip6, sizeof(tuple->dst.u3.ip6));
51
52 return 1;
53}
54
55static int ipv6_print_tuple(struct seq_file *s,
56 const struct nf_conntrack_tuple *tuple)
57{
Joe Perches46b86a22006-01-13 14:29:07 -080058 return seq_printf(s, "src=" NIP6_FMT " dst=" NIP6_FMT " ",
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080059 NIP6(*((struct in6_addr *)tuple->src.u3.ip6)),
60 NIP6(*((struct in6_addr *)tuple->dst.u3.ip6)));
61}
62
63static int ipv6_print_conntrack(struct seq_file *s,
64 const struct nf_conn *conntrack)
65{
66 return 0;
67}
68
69/*
70 * Based on ipv6_skip_exthdr() in net/ipv6/exthdr.c
71 *
72 * This function parses (probably truncated) exthdr set "hdr"
73 * of length "len". "nexthdrp" initially points to some place,
74 * where type of the first header can be found.
75 *
76 * It skips all well-known exthdrs, and returns pointer to the start
77 * of unparsable area i.e. the first header with unknown type.
78 * if success, *nexthdr is updated by type/protocol of this header.
79 *
80 * NOTES: - it may return pointer pointing beyond end of packet,
81 * if the last recognized header is truncated in the middle.
82 * - if packet is truncated, so that all parsed headers are skipped,
83 * it returns -1.
84 * - if packet is fragmented, return pointer of the fragment header.
85 * - ESP is unparsable for now and considered like
86 * normal payload protocol.
87 * - Note also special handling of AUTH header. Thanks to IPsec wizards.
88 */
89
Adrian Bunk1a3a2062007-07-30 18:04:57 -070090static int nf_ct_ipv6_skip_exthdr(const struct sk_buff *skb, int start,
91 u8 *nexthdrp, int len)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080092{
93 u8 nexthdr = *nexthdrp;
94
95 while (ipv6_ext_hdr(nexthdr)) {
96 struct ipv6_opt_hdr hdr;
97 int hdrlen;
98
99 if (len < (int)sizeof(struct ipv6_opt_hdr))
100 return -1;
101 if (nexthdr == NEXTHDR_NONE)
102 break;
103 if (nexthdr == NEXTHDR_FRAGMENT)
104 break;
105 if (skb_copy_bits(skb, start, &hdr, sizeof(hdr)))
106 BUG();
107 if (nexthdr == NEXTHDR_AUTH)
108 hdrlen = (hdr.hdrlen+2)<<2;
109 else
110 hdrlen = ipv6_optlen(&hdr);
111
112 nexthdr = hdr.nexthdr;
113 len -= hdrlen;
114 start += hdrlen;
115 }
116
117 *nexthdrp = nexthdr;
118 return start;
119}
120
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -0700121static int ipv6_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
122 unsigned int *dataoff, u_int8_t *protonum)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800123{
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -0700124 unsigned int extoff = nhoff + sizeof(struct ipv6hdr);
125 unsigned char pnum;
126 int protoff;
127
128 if (skb_copy_bits(skb, nhoff + offsetof(struct ipv6hdr, nexthdr),
129 &pnum, sizeof(pnum)) != 0) {
130 pr_debug("ip6_conntrack_core: can't get nexthdr\n");
131 return -NF_ACCEPT;
132 }
133 protoff = nf_ct_ipv6_skip_exthdr(skb, extoff, &pnum, skb->len - extoff);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800134 /*
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -0700135 * (protoff == skb->len) mean that the packet doesn't have no data
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800136 * except of IPv6 & ext headers. but it's tracked anyway. - YK
137 */
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -0700138 if ((protoff < 0) || (protoff > skb->len)) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700139 pr_debug("ip6_conntrack_core: can't find proto in pkt\n");
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800140 return -NF_ACCEPT;
141 }
142
143 *dataoff = protoff;
144 *protonum = pnum;
145 return NF_ACCEPT;
146}
147
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800148static unsigned int ipv6_confirm(unsigned int hooknum,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700149 struct sk_buff *skb,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800150 const struct net_device *in,
151 const struct net_device *out,
152 int (*okfn)(struct sk_buff *))
153{
154 struct nf_conn *ct;
Harald Weltedc808fe2006-03-20 17:56:32 -0800155 struct nf_conn_help *help;
Patrick McHarrdy3c158f72007-06-05 12:55:27 -0700156 struct nf_conntrack_helper *helper;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800157 enum ip_conntrack_info ctinfo;
Harald Weltedc808fe2006-03-20 17:56:32 -0800158 unsigned int ret, protoff;
Herbert Xu3db05fe2007-10-15 00:53:15 -0700159 unsigned int extoff = (u8 *)(ipv6_hdr(skb) + 1) - skb->data;
160 unsigned char pnum = ipv6_hdr(skb)->nexthdr;
Harald Weltedc808fe2006-03-20 17:56:32 -0800161
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800162
163 /* This is where we call the helper: as the packet goes out. */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700164 ct = nf_ct_get(skb, &ctinfo);
Patrick McHardy6442f1c2006-05-29 18:21:53 -0700165 if (!ct || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY)
Harald Weltedc808fe2006-03-20 17:56:32 -0800166 goto out;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800167
Harald Weltedc808fe2006-03-20 17:56:32 -0800168 help = nfct_help(ct);
Patrick McHarrdy3c158f72007-06-05 12:55:27 -0700169 if (!help)
170 goto out;
171 /* rcu_read_lock()ed by nf_hook_slow */
172 helper = rcu_dereference(help->helper);
173 if (!helper)
Harald Weltedc808fe2006-03-20 17:56:32 -0800174 goto out;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800175
Herbert Xu3db05fe2007-10-15 00:53:15 -0700176 protoff = nf_ct_ipv6_skip_exthdr(skb, extoff, &pnum,
177 skb->len - extoff);
178 if (protoff > skb->len || pnum == NEXTHDR_FRAGMENT) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700179 pr_debug("proto header not found\n");
Harald Weltedc808fe2006-03-20 17:56:32 -0800180 return NF_ACCEPT;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800181 }
182
Herbert Xu3db05fe2007-10-15 00:53:15 -0700183 ret = helper->help(skb, protoff, ct, ctinfo);
Harald Weltedc808fe2006-03-20 17:56:32 -0800184 if (ret != NF_ACCEPT)
185 return ret;
186out:
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800187 /* We've seen it coming out the other side: confirm it */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700188 return nf_conntrack_confirm(skb);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800189}
190
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800191static unsigned int ipv6_defrag(unsigned int hooknum,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700192 struct sk_buff *skb,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800193 const struct net_device *in,
194 const struct net_device *out,
195 int (*okfn)(struct sk_buff *))
196{
197 struct sk_buff *reasm;
198
199 /* Previously seen (loopback)? */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700200 if (skb->nfct)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800201 return NF_ACCEPT;
202
Herbert Xu3db05fe2007-10-15 00:53:15 -0700203 reasm = nf_ct_frag6_gather(skb);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800204
205 /* queued */
206 if (reasm == NULL)
207 return NF_STOLEN;
208
209 /* error occured or not fragmented */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700210 if (reasm == skb)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800211 return NF_ACCEPT;
212
213 nf_ct_frag6_output(hooknum, reasm, (struct net_device *)in,
214 (struct net_device *)out, okfn);
215
216 return NF_STOLEN;
217}
218
219static unsigned int ipv6_conntrack_in(unsigned int hooknum,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700220 struct sk_buff *skb,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800221 const struct net_device *in,
222 const struct net_device *out,
223 int (*okfn)(struct sk_buff *))
224{
Herbert Xu3db05fe2007-10-15 00:53:15 -0700225 struct sk_buff *reasm = skb->nfct_reasm;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800226
227 /* This packet is fragmented and has reassembled packet. */
228 if (reasm) {
229 /* Reassembled packet isn't parsed yet ? */
230 if (!reasm->nfct) {
231 unsigned int ret;
232
Herbert Xu3db05fe2007-10-15 00:53:15 -0700233 ret = nf_conntrack_in(PF_INET6, hooknum, reasm);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800234 if (ret != NF_ACCEPT)
235 return ret;
236 }
237 nf_conntrack_get(reasm->nfct);
Herbert Xu3db05fe2007-10-15 00:53:15 -0700238 skb->nfct = reasm->nfct;
239 skb->nfctinfo = reasm->nfctinfo;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800240 return NF_ACCEPT;
241 }
242
Herbert Xu3db05fe2007-10-15 00:53:15 -0700243 return nf_conntrack_in(PF_INET6, hooknum, skb);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800244}
245
246static unsigned int ipv6_conntrack_local(unsigned int hooknum,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700247 struct sk_buff *skb,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800248 const struct net_device *in,
249 const struct net_device *out,
250 int (*okfn)(struct sk_buff *))
251{
252 /* root is playing with raw sockets. */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700253 if (skb->len < sizeof(struct ipv6hdr)) {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800254 if (net_ratelimit())
255 printk("ipv6_conntrack_local: packet too short\n");
256 return NF_ACCEPT;
257 }
Herbert Xu3db05fe2007-10-15 00:53:15 -0700258 return ipv6_conntrack_in(hooknum, skb, in, out, okfn);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800259}
260
Patrick McHardy964ddaa2006-04-06 14:09:49 -0700261static struct nf_hook_ops ipv6_conntrack_ops[] = {
262 {
263 .hook = ipv6_defrag,
264 .owner = THIS_MODULE,
265 .pf = PF_INET6,
266 .hooknum = NF_IP6_PRE_ROUTING,
267 .priority = NF_IP6_PRI_CONNTRACK_DEFRAG,
268 },
269 {
270 .hook = ipv6_conntrack_in,
271 .owner = THIS_MODULE,
272 .pf = PF_INET6,
273 .hooknum = NF_IP6_PRE_ROUTING,
274 .priority = NF_IP6_PRI_CONNTRACK,
275 },
276 {
277 .hook = ipv6_conntrack_local,
278 .owner = THIS_MODULE,
279 .pf = PF_INET6,
280 .hooknum = NF_IP6_LOCAL_OUT,
281 .priority = NF_IP6_PRI_CONNTRACK,
282 },
283 {
284 .hook = ipv6_defrag,
285 .owner = THIS_MODULE,
286 .pf = PF_INET6,
287 .hooknum = NF_IP6_LOCAL_OUT,
288 .priority = NF_IP6_PRI_CONNTRACK_DEFRAG,
289 },
290 {
291 .hook = ipv6_confirm,
292 .owner = THIS_MODULE,
293 .pf = PF_INET6,
294 .hooknum = NF_IP6_POST_ROUTING,
295 .priority = NF_IP6_PRI_LAST,
296 },
297 {
298 .hook = ipv6_confirm,
299 .owner = THIS_MODULE,
300 .pf = PF_INET6,
301 .hooknum = NF_IP6_LOCAL_IN,
302 .priority = NF_IP6_PRI_LAST-1,
303 },
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800304};
305
306#ifdef CONFIG_SYSCTL
Patrick McHardy933a41e2006-11-29 02:35:18 +0100307static ctl_table nf_ct_ipv6_sysctl_table[] = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800308 {
309 .ctl_name = NET_NF_CONNTRACK_FRAG6_TIMEOUT,
310 .procname = "nf_conntrack_frag6_timeout",
Pavel Emelyanov04128f22007-10-15 02:33:45 -0700311 .data = &nf_frags_ctl.timeout,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800312 .maxlen = sizeof(unsigned int),
313 .mode = 0644,
314 .proc_handler = &proc_dointvec_jiffies,
315 },
316 {
317 .ctl_name = NET_NF_CONNTRACK_FRAG6_LOW_THRESH,
318 .procname = "nf_conntrack_frag6_low_thresh",
Pavel Emelyanov04128f22007-10-15 02:33:45 -0700319 .data = &nf_frags_ctl.low_thresh,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800320 .maxlen = sizeof(unsigned int),
321 .mode = 0644,
Yasuyuki Kozakai7686a022005-11-14 15:27:43 -0800322 .proc_handler = &proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800323 },
324 {
325 .ctl_name = NET_NF_CONNTRACK_FRAG6_HIGH_THRESH,
326 .procname = "nf_conntrack_frag6_high_thresh",
Pavel Emelyanov04128f22007-10-15 02:33:45 -0700327 .data = &nf_frags_ctl.high_thresh,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Yasuyuki Kozakai7686a022005-11-14 15:27:43 -0800330 .proc_handler = &proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800331 },
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900332 { .ctl_name = 0 }
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800333};
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800334#endif
335
Patrick McHardye281db5c2007-03-04 15:57:25 -0800336#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800337
338#include <linux/netfilter/nfnetlink.h>
339#include <linux/netfilter/nfnetlink_conntrack.h>
340
Patrick McHardyfdf70832007-09-28 14:37:41 -0700341static int ipv6_tuple_to_nlattr(struct sk_buff *skb,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800342 const struct nf_conntrack_tuple *tuple)
343{
Patrick McHardydf6fb862007-09-28 14:37:03 -0700344 NLA_PUT(skb, CTA_IP_V6_SRC, sizeof(u_int32_t) * 4,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800345 &tuple->src.u3.ip6);
Patrick McHardydf6fb862007-09-28 14:37:03 -0700346 NLA_PUT(skb, CTA_IP_V6_DST, sizeof(u_int32_t) * 4,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800347 &tuple->dst.u3.ip6);
348 return 0;
349
Patrick McHardydf6fb862007-09-28 14:37:03 -0700350nla_put_failure:
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800351 return -1;
352}
353
Patrick McHardyf73e9242007-09-28 14:39:55 -0700354static const struct nla_policy ipv6_nla_policy[CTA_IP_MAX+1] = {
355 [CTA_IP_V6_SRC] = { .len = sizeof(u_int32_t)*4 },
356 [CTA_IP_V6_DST] = { .len = sizeof(u_int32_t)*4 },
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800357};
358
Patrick McHardyfdf70832007-09-28 14:37:41 -0700359static int ipv6_nlattr_to_tuple(struct nlattr *tb[],
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800360 struct nf_conntrack_tuple *t)
361{
Patrick McHardydf6fb862007-09-28 14:37:03 -0700362 if (!tb[CTA_IP_V6_SRC] || !tb[CTA_IP_V6_DST])
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800363 return -EINVAL;
364
Patrick McHardydf6fb862007-09-28 14:37:03 -0700365 memcpy(&t->src.u3.ip6, nla_data(tb[CTA_IP_V6_SRC]),
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800366 sizeof(u_int32_t) * 4);
Patrick McHardydf6fb862007-09-28 14:37:03 -0700367 memcpy(&t->dst.u3.ip6, nla_data(tb[CTA_IP_V6_DST]),
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800368 sizeof(u_int32_t) * 4);
369
370 return 0;
371}
372#endif
373
Patrick McHardy61075af2007-07-14 20:48:19 -0700374struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6 __read_mostly = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800375 .l3proto = PF_INET6,
376 .name = "ipv6",
377 .pkt_to_tuple = ipv6_pkt_to_tuple,
378 .invert_tuple = ipv6_invert_tuple,
379 .print_tuple = ipv6_print_tuple,
380 .print_conntrack = ipv6_print_conntrack,
Yasuyuki Kozakaiffc30692007-07-14 20:44:50 -0700381 .get_l4proto = ipv6_get_l4proto,
Patrick McHardye281db5c2007-03-04 15:57:25 -0800382#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
Patrick McHardyfdf70832007-09-28 14:37:41 -0700383 .tuple_to_nlattr = ipv6_tuple_to_nlattr,
384 .nlattr_to_tuple = ipv6_nlattr_to_tuple,
Patrick McHardyf73e9242007-09-28 14:39:55 -0700385 .nla_policy = ipv6_nla_policy,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800386#endif
Patrick McHardy933a41e2006-11-29 02:35:18 +0100387#ifdef CONFIG_SYSCTL
388 .ctl_table_path = nf_net_netfilter_sysctl_path,
389 .ctl_table = nf_ct_ipv6_sysctl_table,
390#endif
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800391 .me = THIS_MODULE,
392};
393
Patrick McHardy32292a72006-04-06 14:11:30 -0700394MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET6));
395MODULE_LICENSE("GPL");
396MODULE_AUTHOR("Yasuyuki KOZAKAI @USAGI <yasuyuki.kozakai@toshiba.co.jp>");
397
398static int __init nf_conntrack_l3proto_ipv6_init(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800399{
400 int ret = 0;
401
Patrick McHardy32292a72006-04-06 14:11:30 -0700402 need_conntrack();
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800403
404 ret = nf_ct_frag6_init();
405 if (ret < 0) {
406 printk("nf_conntrack_ipv6: can't initialize frag6.\n");
Patrick McHardy32292a72006-04-06 14:11:30 -0700407 return ret;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800408 }
Martin Josefsson605dcad2006-11-29 02:35:06 +0100409 ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_tcp6);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800410 if (ret < 0) {
411 printk("nf_conntrack_ipv6: can't register tcp.\n");
412 goto cleanup_frag6;
413 }
414
Martin Josefsson605dcad2006-11-29 02:35:06 +0100415 ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_udp6);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800416 if (ret < 0) {
417 printk("nf_conntrack_ipv6: can't register udp.\n");
418 goto cleanup_tcp;
419 }
420
Martin Josefsson605dcad2006-11-29 02:35:06 +0100421 ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_icmpv6);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800422 if (ret < 0) {
423 printk("nf_conntrack_ipv6: can't register icmpv6.\n");
424 goto cleanup_udp;
425 }
426
427 ret = nf_conntrack_l3proto_register(&nf_conntrack_l3proto_ipv6);
428 if (ret < 0) {
429 printk("nf_conntrack_ipv6: can't register ipv6\n");
430 goto cleanup_icmpv6;
431 }
432
Patrick McHardy964ddaa2006-04-06 14:09:49 -0700433 ret = nf_register_hooks(ipv6_conntrack_ops,
434 ARRAY_SIZE(ipv6_conntrack_ops));
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800435 if (ret < 0) {
436 printk("nf_conntrack_ipv6: can't register pre-routing defrag "
437 "hook.\n");
438 goto cleanup_ipv6;
439 }
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800440 return ret;
441
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800442 cleanup_ipv6:
443 nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv6);
444 cleanup_icmpv6:
Martin Josefsson605dcad2006-11-29 02:35:06 +0100445 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_icmpv6);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800446 cleanup_udp:
Martin Josefsson605dcad2006-11-29 02:35:06 +0100447 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_udp6);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800448 cleanup_tcp:
Martin Josefsson605dcad2006-11-29 02:35:06 +0100449 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_tcp6);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800450 cleanup_frag6:
451 nf_ct_frag6_cleanup();
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800452 return ret;
453}
454
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800455static void __exit nf_conntrack_l3proto_ipv6_fini(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800456{
Patrick McHardy32292a72006-04-06 14:11:30 -0700457 synchronize_net();
Patrick McHardy32292a72006-04-06 14:11:30 -0700458 nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops));
459 nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv6);
Martin Josefsson605dcad2006-11-29 02:35:06 +0100460 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_icmpv6);
461 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_udp6);
462 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_tcp6);
Patrick McHardy32292a72006-04-06 14:11:30 -0700463 nf_ct_frag6_cleanup();
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800464}
465
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800466module_init(nf_conntrack_l3proto_ipv6_init);
467module_exit(nf_conntrack_l3proto_ipv6_fini);