Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 10 | */ |
| 11 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 19 | #include <net/ipv6.h> |
Pavel Emelyanov | 04128f2 | 2007-10-15 02:33:45 -0700 | [diff] [blame] | 20 | #include <net/inet_frag.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 21 | |
Patrick McHardy | 8fa9ff6 | 2009-12-15 16:59:59 +0100 | [diff] [blame] | 22 | #include <linux/netfilter_bridge.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 23 | #include <linux/netfilter_ipv6.h> |
Florian Westphal | 121d1e0 | 2012-10-30 01:08:49 +0000 | [diff] [blame] | 24 | #include <linux/netfilter_ipv6/ip6_tables.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 25 | #include <net/netfilter/nf_conntrack.h> |
| 26 | #include <net/netfilter/nf_conntrack_helper.h> |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 27 | #include <net/netfilter/nf_conntrack_l4proto.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 28 | #include <net/netfilter/nf_conntrack_l3proto.h> |
| 29 | #include <net/netfilter/nf_conntrack_core.h> |
Patrick McHardy | 5d0aa2c | 2010-02-15 18:13:33 +0100 | [diff] [blame] | 30 | #include <net/netfilter/nf_conntrack_zones.h> |
Christoph Paasch | 9d2493f | 2009-03-16 15:15:35 +0100 | [diff] [blame] | 31 | #include <net/netfilter/ipv6/nf_conntrack_ipv6.h> |
Patrick McHardy | 58a317f | 2012-08-26 19:14:12 +0200 | [diff] [blame] | 32 | #include <net/netfilter/nf_nat_helper.h> |
Balazs Scheidler | e97c3e2 | 2010-10-21 16:03:43 +0200 | [diff] [blame] | 33 | #include <net/netfilter/ipv6/nf_defrag_ipv6.h> |
Patrick McHardy | 74f7a65 | 2009-08-25 15:33:08 +0200 | [diff] [blame] | 34 | #include <net/netfilter/nf_log.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 35 | |
Jan Engelhardt | 8ce8439 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 36 | static bool ipv6_pkt_to_tuple(const struct sk_buff *skb, unsigned int nhoff, |
| 37 | struct nf_conntrack_tuple *tuple) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 38 | { |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 39 | const u_int32_t *ap; |
| 40 | u_int32_t _addrs[8]; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 41 | |
| 42 | ap = skb_header_pointer(skb, nhoff + offsetof(struct ipv6hdr, saddr), |
| 43 | sizeof(_addrs), _addrs); |
| 44 | if (ap == NULL) |
Jan Engelhardt | 8ce8439 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 45 | return false; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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 | |
Jan Engelhardt | 8ce8439 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 50 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Jan Engelhardt | 8ce8439 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 53 | static bool ipv6_invert_tuple(struct nf_conntrack_tuple *tuple, |
| 54 | const struct nf_conntrack_tuple *orig) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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 | |
Jan Engelhardt | 8ce8439 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 59 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static int ipv6_print_tuple(struct seq_file *s, |
| 63 | const struct nf_conntrack_tuple *tuple) |
| 64 | { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 65 | return seq_printf(s, "src=%pI6 dst=%pI6 ", |
Harvey Harrison | 0c6ce78 | 2008-10-28 16:09:23 -0700 | [diff] [blame] | 66 | tuple->src.u3.ip6, tuple->dst.u3.ip6); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Yasuyuki Kozakai | ffc3069 | 2007-07-14 20:44:50 -0700 | [diff] [blame] | 69 | static int ipv6_get_l4proto(const struct sk_buff *skb, unsigned int nhoff, |
| 70 | unsigned int *dataoff, u_int8_t *protonum) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 71 | { |
Yasuyuki Kozakai | ffc3069 | 2007-07-14 20:44:50 -0700 | [diff] [blame] | 72 | unsigned int extoff = nhoff + sizeof(struct ipv6hdr); |
Patrick McHardy | 2b60af0 | 2012-08-26 19:13:59 +0200 | [diff] [blame] | 73 | __be16 frag_off; |
Yasuyuki Kozakai | ffc3069 | 2007-07-14 20:44:50 -0700 | [diff] [blame] | 74 | int protoff; |
Patrick McHardy | 2b60af0 | 2012-08-26 19:13:59 +0200 | [diff] [blame] | 75 | u8 nexthdr; |
Yasuyuki Kozakai | ffc3069 | 2007-07-14 20:44:50 -0700 | [diff] [blame] | 76 | |
| 77 | if (skb_copy_bits(skb, nhoff + offsetof(struct ipv6hdr, nexthdr), |
Patrick McHardy | 2b60af0 | 2012-08-26 19:13:59 +0200 | [diff] [blame] | 78 | &nexthdr, sizeof(nexthdr)) != 0) { |
Yasuyuki Kozakai | ffc3069 | 2007-07-14 20:44:50 -0700 | [diff] [blame] | 79 | pr_debug("ip6_conntrack_core: can't get nexthdr\n"); |
| 80 | return -NF_ACCEPT; |
| 81 | } |
Patrick McHardy | 2b60af0 | 2012-08-26 19:13:59 +0200 | [diff] [blame] | 82 | protoff = ipv6_skip_exthdr(skb, extoff, &nexthdr, &frag_off); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 83 | /* |
Florent Fourcot | d7a769f | 2012-12-14 00:53:33 +0000 | [diff] [blame] | 84 | * (protoff == skb->len) means the packet has not data, just |
| 85 | * IPv6 and possibly extensions headers, but it is tracked anyway |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 86 | */ |
Patrick McHardy | 2b60af0 | 2012-08-26 19:13:59 +0200 | [diff] [blame] | 87 | if (protoff < 0 || (frag_off & htons(~0x7)) != 0) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 88 | pr_debug("ip6_conntrack_core: can't find proto in pkt\n"); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 89 | return -NF_ACCEPT; |
| 90 | } |
| 91 | |
| 92 | *dataoff = protoff; |
Patrick McHardy | 2b60af0 | 2012-08-26 19:13:59 +0200 | [diff] [blame] | 93 | *protonum = nexthdr; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 94 | return NF_ACCEPT; |
| 95 | } |
| 96 | |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 97 | static 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 *)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 102 | { |
| 103 | struct nf_conn *ct; |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 104 | const struct nf_conn_help *help; |
| 105 | const struct nf_conntrack_helper *helper; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 106 | enum ip_conntrack_info ctinfo; |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 107 | __be16 frag_off; |
| 108 | int protoff; |
| 109 | u8 nexthdr; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 110 | |
| 111 | /* This is where we call the helper: as the packet goes out. */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 112 | ct = nf_ct_get(skb, &ctinfo); |
Eric Dumazet | fb04883 | 2011-05-19 15:44:27 +0200 | [diff] [blame] | 113 | if (!ct || ctinfo == IP_CT_RELATED_REPLY) |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 114 | return NF_ACCEPT; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 115 | |
Harald Welte | dc808fe | 2006-03-20 17:56:32 -0800 | [diff] [blame] | 116 | help = nfct_help(ct); |
Patrick McHarrdy | 3c158f7 | 2007-06-05 12:55:27 -0700 | [diff] [blame] | 117 | if (!help) |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 118 | return NF_ACCEPT; |
Patrick McHarrdy | 3c158f7 | 2007-06-05 12:55:27 -0700 | [diff] [blame] | 119 | /* rcu_read_lock()ed by nf_hook_slow */ |
| 120 | helper = rcu_dereference(help->helper); |
| 121 | if (!helper) |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 122 | return NF_ACCEPT; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 123 | |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 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) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 128 | pr_debug("proto header not found\n"); |
Harald Welte | dc808fe | 2006-03-20 17:56:32 -0800 | [diff] [blame] | 129 | return NF_ACCEPT; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Pablo Neira Ayuso | b20ab9cc | 2013-02-10 18:56:56 +0100 | [diff] [blame] | 132 | return helper->help(skb, protoff, ct, ctinfo); |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static 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 | { |
Patrick McHardy | 58a317f | 2012-08-26 19:14:12 +0200 | [diff] [blame] | 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 | } |
| 170 | out: |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 171 | /* We've seen it coming out the other side: confirm it */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 172 | return nf_conntrack_confirm(skb); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Alexey Dobriyan | a702a65 | 2008-10-08 11:35:04 +0200 | [diff] [blame] | 175 | static unsigned int __ipv6_conntrack_in(struct net *net, |
| 176 | unsigned int hooknum, |
| 177 | struct sk_buff *skb, |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 178 | const struct net_device *in, |
| 179 | const struct net_device *out, |
Alexey Dobriyan | a702a65 | 2008-10-08 11:35:04 +0200 | [diff] [blame] | 180 | int (*okfn)(struct sk_buff *)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 181 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 182 | struct sk_buff *reasm = skb->nfct_reasm; |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 183 | const struct nf_conn_help *help; |
| 184 | struct nf_conn *ct; |
| 185 | enum ip_conntrack_info ctinfo; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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 | |
Alexey Dobriyan | a702a65 | 2008-10-08 11:35:04 +0200 | [diff] [blame] | 193 | ret = nf_conntrack_in(net, PF_INET6, hooknum, reasm); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 194 | if (ret != NF_ACCEPT) |
| 195 | return ret; |
| 196 | } |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 197 | |
| 198 | /* Conntrack helpers need the entire reassembled packet in the |
Patrick McHardy | 58a317f | 2012-08-26 19:14:12 +0200 | [diff] [blame] | 199 | * POST_ROUTING hook. In case of unconfirmed connections NAT |
| 200 | * might reassign a helper, so the entire packet is also |
| 201 | * required. |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 202 | */ |
| 203 | ct = nf_ct_get(reasm, &ctinfo); |
| 204 | if (ct != NULL && !nf_ct_is_untracked(ct)) { |
| 205 | help = nfct_help(ct); |
Patrick McHardy | 58a317f | 2012-08-26 19:14:12 +0200 | [diff] [blame] | 206 | if ((help && help->helper) || !nf_ct_is_confirmed(ct)) { |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 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 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 216 | nf_conntrack_get(reasm->nfct); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 217 | skb->nfct = reasm->nfct; |
| 218 | skb->nfctinfo = reasm->nfctinfo; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 219 | return NF_ACCEPT; |
| 220 | } |
| 221 | |
Alexey Dobriyan | a702a65 | 2008-10-08 11:35:04 +0200 | [diff] [blame] | 222 | return nf_conntrack_in(net, PF_INET6, hooknum, skb); |
| 223 | } |
| 224 | |
| 225 | static 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 | { |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 231 | return __ipv6_conntrack_in(dev_net(in), hooknum, skb, in, out, okfn); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static unsigned int ipv6_conntrack_local(unsigned int hooknum, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 235 | struct sk_buff *skb, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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. */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 241 | if (skb->len < sizeof(struct ipv6hdr)) { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 242 | net_notice_ratelimited("ipv6_conntrack_local: packet too short\n"); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 243 | return NF_ACCEPT; |
| 244 | } |
Patrick McHardy | 4cdd3408 | 2012-08-26 19:13:58 +0200 | [diff] [blame] | 245 | return __ipv6_conntrack_in(dev_net(out), hooknum, skb, in, out, okfn); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Patrick McHardy | 1999414 | 2007-12-05 01:23:00 -0800 | [diff] [blame] | 248 | static struct nf_hook_ops ipv6_conntrack_ops[] __read_mostly = { |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 249 | { |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 250 | .hook = ipv6_conntrack_in, |
| 251 | .owner = THIS_MODULE, |
Jan Engelhardt | 57750a2 | 2009-06-13 06:22:18 +0200 | [diff] [blame] | 252 | .pf = NFPROTO_IPV6, |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 253 | .hooknum = NF_INET_PRE_ROUTING, |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 254 | .priority = NF_IP6_PRI_CONNTRACK, |
| 255 | }, |
| 256 | { |
| 257 | .hook = ipv6_conntrack_local, |
| 258 | .owner = THIS_MODULE, |
Jan Engelhardt | 57750a2 | 2009-06-13 06:22:18 +0200 | [diff] [blame] | 259 | .pf = NFPROTO_IPV6, |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 260 | .hooknum = NF_INET_LOCAL_OUT, |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 261 | .priority = NF_IP6_PRI_CONNTRACK, |
| 262 | }, |
| 263 | { |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 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 | }, |
| 270 | { |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 271 | .hook = ipv6_confirm, |
| 272 | .owner = THIS_MODULE, |
Jan Engelhardt | 57750a2 | 2009-06-13 06:22:18 +0200 | [diff] [blame] | 273 | .pf = NFPROTO_IPV6, |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 274 | .hooknum = NF_INET_POST_ROUTING, |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 275 | .priority = NF_IP6_PRI_LAST, |
| 276 | }, |
| 277 | { |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 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 | }, |
| 284 | { |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 285 | .hook = ipv6_confirm, |
| 286 | .owner = THIS_MODULE, |
Jan Engelhardt | 57750a2 | 2009-06-13 06:22:18 +0200 | [diff] [blame] | 287 | .pf = NFPROTO_IPV6, |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 288 | .hooknum = NF_INET_LOCAL_IN, |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 289 | .priority = NF_IP6_PRI_LAST-1, |
| 290 | }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 291 | }; |
| 292 | |
Florian Westphal | 121d1e0 | 2012-10-30 01:08:49 +0000 | [diff] [blame] | 293 | static int |
| 294 | ipv6_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)); |
Florian Westphal | 121d1e0 | 2012-10-30 01:08:49 +0000 | [diff] [blame] | 331 | |
| 332 | nf_ct_put(ct); |
Hannes Frederic Sowa | d00bd3d | 2013-03-12 11:21:36 +0000 | [diff] [blame] | 333 | sin6.sin6_scope_id = ipv6_iface_scope_id(&sin6.sin6_addr, |
| 334 | sk->sk_bound_dev_if); |
Florian Westphal | 121d1e0 | 2012-10-30 01:08:49 +0000 | [diff] [blame] | 335 | return copy_to_user(user, &sin6, sizeof(sin6)) ? -EFAULT : 0; |
| 336 | } |
| 337 | |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 338 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 339 | |
| 340 | #include <linux/netfilter/nfnetlink.h> |
| 341 | #include <linux/netfilter/nfnetlink_conntrack.h> |
| 342 | |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 343 | static int ipv6_tuple_to_nlattr(struct sk_buff *skb, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 344 | const struct nf_conntrack_tuple *tuple) |
| 345 | { |
David S. Miller | e549a6b | 2012-04-01 20:28:52 -0400 | [diff] [blame] | 346 | if (nla_put(skb, CTA_IP_V6_SRC, sizeof(u_int32_t) * 4, |
| 347 | &tuple->src.u3.ip6) || |
| 348 | nla_put(skb, CTA_IP_V6_DST, sizeof(u_int32_t) * 4, |
| 349 | &tuple->dst.u3.ip6)) |
| 350 | goto nla_put_failure; |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 351 | return 0; |
| 352 | |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 353 | nla_put_failure: |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 354 | return -1; |
| 355 | } |
| 356 | |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 357 | static const struct nla_policy ipv6_nla_policy[CTA_IP_MAX+1] = { |
| 358 | [CTA_IP_V6_SRC] = { .len = sizeof(u_int32_t)*4 }, |
| 359 | [CTA_IP_V6_DST] = { .len = sizeof(u_int32_t)*4 }, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 360 | }; |
| 361 | |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 362 | static int ipv6_nlattr_to_tuple(struct nlattr *tb[], |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 363 | struct nf_conntrack_tuple *t) |
| 364 | { |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 365 | if (!tb[CTA_IP_V6_SRC] || !tb[CTA_IP_V6_DST]) |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 366 | return -EINVAL; |
| 367 | |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 368 | memcpy(&t->src.u3.ip6, nla_data(tb[CTA_IP_V6_SRC]), |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 369 | sizeof(u_int32_t) * 4); |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 370 | memcpy(&t->dst.u3.ip6, nla_data(tb[CTA_IP_V6_DST]), |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 371 | sizeof(u_int32_t) * 4); |
| 372 | |
| 373 | return 0; |
| 374 | } |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 375 | |
| 376 | static int ipv6_nlattr_tuple_size(void) |
| 377 | { |
| 378 | return nla_policy_len(ipv6_nla_policy, CTA_IP_MAX + 1); |
| 379 | } |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 380 | #endif |
| 381 | |
Patrick McHardy | 61075af | 2007-07-14 20:48:19 -0700 | [diff] [blame] | 382 | struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6 __read_mostly = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 383 | .l3proto = PF_INET6, |
| 384 | .name = "ipv6", |
| 385 | .pkt_to_tuple = ipv6_pkt_to_tuple, |
| 386 | .invert_tuple = ipv6_invert_tuple, |
| 387 | .print_tuple = ipv6_print_tuple, |
Yasuyuki Kozakai | ffc3069 | 2007-07-14 20:44:50 -0700 | [diff] [blame] | 388 | .get_l4proto = ipv6_get_l4proto, |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 389 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 390 | .tuple_to_nlattr = ipv6_tuple_to_nlattr, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 391 | .nlattr_tuple_size = ipv6_nlattr_tuple_size, |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 392 | .nlattr_to_tuple = ipv6_nlattr_to_tuple, |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 393 | .nla_policy = ipv6_nla_policy, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 394 | #endif |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 395 | .me = THIS_MODULE, |
| 396 | }; |
| 397 | |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 398 | MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET6)); |
| 399 | MODULE_LICENSE("GPL"); |
| 400 | MODULE_AUTHOR("Yasuyuki KOZAKAI @USAGI <yasuyuki.kozakai@toshiba.co.jp>"); |
| 401 | |
Florian Westphal | 121d1e0 | 2012-10-30 01:08:49 +0000 | [diff] [blame] | 402 | static struct nf_sockopt_ops so_getorigdst6 = { |
| 403 | .pf = NFPROTO_IPV6, |
| 404 | .get_optmin = IP6T_SO_ORIGINAL_DST, |
| 405 | .get_optmax = IP6T_SO_ORIGINAL_DST + 1, |
| 406 | .get = ipv6_getorigdst, |
| 407 | .owner = THIS_MODULE, |
| 408 | }; |
| 409 | |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 410 | static int ipv6_net_init(struct net *net) |
| 411 | { |
| 412 | int ret = 0; |
| 413 | |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 414 | ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_tcp6); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 415 | if (ret < 0) { |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 416 | pr_err("nf_conntrack_tcp6: pernet registration failed\n"); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 417 | goto out; |
| 418 | } |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 419 | ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udp6); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 420 | if (ret < 0) { |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 421 | pr_err("nf_conntrack_udp6: pernet registration failed\n"); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 422 | goto cleanup_tcp6; |
| 423 | } |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 424 | ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_icmpv6); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 425 | if (ret < 0) { |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 426 | pr_err("nf_conntrack_icmp6: pernet registration failed\n"); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 427 | goto cleanup_udp6; |
| 428 | } |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 429 | ret = nf_ct_l3proto_pernet_register(net, &nf_conntrack_l3proto_ipv6); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 430 | if (ret < 0) { |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 431 | pr_err("nf_conntrack_ipv6: pernet registration failed.\n"); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 432 | goto cleanup_icmpv6; |
| 433 | } |
| 434 | return 0; |
| 435 | cleanup_icmpv6: |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 436 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_icmpv6); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 437 | cleanup_udp6: |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 438 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udp6); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 439 | cleanup_tcp6: |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 440 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_tcp6); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 441 | out: |
| 442 | return ret; |
| 443 | } |
| 444 | |
| 445 | static void ipv6_net_exit(struct net *net) |
| 446 | { |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 447 | nf_ct_l3proto_pernet_unregister(net, &nf_conntrack_l3proto_ipv6); |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 448 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_icmpv6); |
| 449 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udp6); |
| 450 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_tcp6); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static struct pernet_operations ipv6_net_ops = { |
| 454 | .init = ipv6_net_init, |
| 455 | .exit = ipv6_net_exit, |
| 456 | }; |
| 457 | |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 458 | static int __init nf_conntrack_l3proto_ipv6_init(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 459 | { |
| 460 | int ret = 0; |
| 461 | |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 462 | need_conntrack(); |
Balazs Scheidler | e97c3e2 | 2010-10-21 16:03:43 +0200 | [diff] [blame] | 463 | nf_defrag_ipv6_enable(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 464 | |
Florian Westphal | 121d1e0 | 2012-10-30 01:08:49 +0000 | [diff] [blame] | 465 | ret = nf_register_sockopt(&so_getorigdst6); |
| 466 | if (ret < 0) { |
| 467 | pr_err("Unable to register netfilter socket option\n"); |
| 468 | return ret; |
| 469 | } |
| 470 | |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 471 | ret = register_pernet_subsys(&ipv6_net_ops); |
| 472 | if (ret < 0) |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 473 | goto cleanup_sockopt; |
| 474 | |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 475 | ret = nf_register_hooks(ipv6_conntrack_ops, |
| 476 | ARRAY_SIZE(ipv6_conntrack_ops)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 477 | if (ret < 0) { |
Stephen Hemminger | 654d0fb | 2010-05-13 15:02:08 +0200 | [diff] [blame] | 478 | pr_err("nf_conntrack_ipv6: can't register pre-routing defrag " |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 479 | "hook.\n"); |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 480 | goto cleanup_pernet; |
| 481 | } |
| 482 | |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 483 | ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_tcp6); |
| 484 | if (ret < 0) { |
| 485 | pr_err("nf_conntrack_ipv6: can't register tcp6 proto.\n"); |
| 486 | goto cleanup_hooks; |
| 487 | } |
| 488 | |
| 489 | ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udp6); |
| 490 | if (ret < 0) { |
| 491 | pr_err("nf_conntrack_ipv6: can't register udp6 proto.\n"); |
| 492 | goto cleanup_tcp6; |
| 493 | } |
| 494 | |
| 495 | ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_icmpv6); |
| 496 | if (ret < 0) { |
| 497 | pr_err("nf_conntrack_ipv6: can't register icmpv6 proto.\n"); |
| 498 | goto cleanup_udp6; |
| 499 | } |
| 500 | |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 501 | ret = nf_ct_l3proto_register(&nf_conntrack_l3proto_ipv6); |
| 502 | if (ret < 0) { |
| 503 | pr_err("nf_conntrack_ipv6: can't register ipv6 proto.\n"); |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 504 | goto cleanup_icmpv6; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 505 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 506 | return ret; |
| 507 | |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 508 | cleanup_icmpv6: |
| 509 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_icmpv6); |
| 510 | cleanup_udp6: |
| 511 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udp6); |
| 512 | cleanup_tcp6: |
| 513 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_tcp6); |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 514 | cleanup_hooks: |
| 515 | nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops)); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 516 | cleanup_pernet: |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 517 | unregister_pernet_subsys(&ipv6_net_ops); |
| 518 | cleanup_sockopt: |
Florian Westphal | 121d1e0 | 2012-10-30 01:08:49 +0000 | [diff] [blame] | 519 | nf_unregister_sockopt(&so_getorigdst6); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 520 | return ret; |
| 521 | } |
| 522 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 523 | static void __exit nf_conntrack_l3proto_ipv6_fini(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 524 | { |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 525 | synchronize_net(); |
Gao feng | 6330750 | 2013-01-21 22:10:33 +0000 | [diff] [blame] | 526 | nf_ct_l3proto_unregister(&nf_conntrack_l3proto_ipv6); |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 527 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_tcp6); |
| 528 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udp6); |
| 529 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_icmpv6); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 530 | nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops)); |
Gao feng | a7c439d | 2012-05-28 21:04:17 +0000 | [diff] [blame] | 531 | unregister_pernet_subsys(&ipv6_net_ops); |
Florian Westphal | 121d1e0 | 2012-10-30 01:08:49 +0000 | [diff] [blame] | 532 | nf_unregister_sockopt(&so_getorigdst6); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 535 | module_init(nf_conntrack_l3proto_ipv6_init); |
| 536 | module_exit(nf_conntrack_l3proto_ipv6_fini); |