Merge branch 'master' into upstream
[linux-drm-fsl-dcu.git] / net / ipv4 / netfilter / ip_nat_core.c
1 /* NAT for netfilter; shared with compatibility layer. */
2
3 /* (C) 1999-2001 Paul `Rusty' Russell
4  * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/timer.h>
14 #include <linux/skbuff.h>
15 #include <linux/netfilter_ipv4.h>
16 #include <linux/vmalloc.h>
17 #include <net/checksum.h>
18 #include <net/icmp.h>
19 #include <net/ip.h>
20 #include <net/tcp.h>  /* For tcp_prot in getorigdst */
21 #include <linux/icmp.h>
22 #include <linux/udp.h>
23 #include <linux/jhash.h>
24
25 #include <linux/netfilter_ipv4/ip_conntrack.h>
26 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
27 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
28 #include <linux/netfilter_ipv4/ip_nat.h>
29 #include <linux/netfilter_ipv4/ip_nat_protocol.h>
30 #include <linux/netfilter_ipv4/ip_nat_core.h>
31 #include <linux/netfilter_ipv4/ip_nat_helper.h>
32 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
33
34 #if 0
35 #define DEBUGP printk
36 #else
37 #define DEBUGP(format, args...)
38 #endif
39
40 DEFINE_RWLOCK(ip_nat_lock);
41
42 /* Calculated at init based on memory size */
43 static unsigned int ip_nat_htable_size;
44
45 static struct list_head *bysource;
46
47 #define MAX_IP_NAT_PROTO 256
48 static struct ip_nat_protocol *ip_nat_protos[MAX_IP_NAT_PROTO];
49
50 static inline struct ip_nat_protocol *
51 __ip_nat_proto_find(u_int8_t protonum)
52 {
53         return ip_nat_protos[protonum];
54 }
55
56 struct ip_nat_protocol *
57 ip_nat_proto_find_get(u_int8_t protonum)
58 {
59         struct ip_nat_protocol *p;
60
61         /* we need to disable preemption to make sure 'p' doesn't get
62          * removed until we've grabbed the reference */
63         preempt_disable();
64         p = __ip_nat_proto_find(protonum);
65         if (!try_module_get(p->me))
66                 p = &ip_nat_unknown_protocol;
67         preempt_enable();
68
69         return p;
70 }
71 EXPORT_SYMBOL_GPL(ip_nat_proto_find_get);
72
73 void
74 ip_nat_proto_put(struct ip_nat_protocol *p)
75 {
76         module_put(p->me);
77 }
78 EXPORT_SYMBOL_GPL(ip_nat_proto_put);
79
80 /* We keep an extra hash for each conntrack, for fast searching. */
81 static inline unsigned int
82 hash_by_src(const struct ip_conntrack_tuple *tuple)
83 {
84         /* Original src, to ensure we map it consistently if poss. */
85         return jhash_3words((__force u32)tuple->src.ip, tuple->src.u.all,
86                             tuple->dst.protonum, 0) % ip_nat_htable_size;
87 }
88
89 /* Noone using conntrack by the time this called. */
90 static void ip_nat_cleanup_conntrack(struct ip_conntrack *conn)
91 {
92         if (!(conn->status & IPS_NAT_DONE_MASK))
93                 return;
94
95         write_lock_bh(&ip_nat_lock);
96         list_del(&conn->nat.info.bysource);
97         write_unlock_bh(&ip_nat_lock);
98 }
99
100 /* Is this tuple already taken? (not by us) */
101 int
102 ip_nat_used_tuple(const struct ip_conntrack_tuple *tuple,
103                   const struct ip_conntrack *ignored_conntrack)
104 {
105         /* Conntrack tracking doesn't keep track of outgoing tuples; only
106            incoming ones.  NAT means they don't have a fixed mapping,
107            so we invert the tuple and look for the incoming reply.
108
109            We could keep a separate hash if this proves too slow. */
110         struct ip_conntrack_tuple reply;
111
112         invert_tuplepr(&reply, tuple);
113         return ip_conntrack_tuple_taken(&reply, ignored_conntrack);
114 }
115 EXPORT_SYMBOL(ip_nat_used_tuple);
116
117 /* If we source map this tuple so reply looks like reply_tuple, will
118  * that meet the constraints of range. */
119 static int
120 in_range(const struct ip_conntrack_tuple *tuple,
121          const struct ip_nat_range *range)
122 {
123         struct ip_nat_protocol *proto = 
124                                 __ip_nat_proto_find(tuple->dst.protonum);
125
126         /* If we are supposed to map IPs, then we must be in the
127            range specified, otherwise let this drag us onto a new src IP. */
128         if (range->flags & IP_NAT_RANGE_MAP_IPS) {
129                 if (ntohl(tuple->src.ip) < ntohl(range->min_ip)
130                     || ntohl(tuple->src.ip) > ntohl(range->max_ip))
131                         return 0;
132         }
133
134         if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED)
135             || proto->in_range(tuple, IP_NAT_MANIP_SRC,
136                                &range->min, &range->max))
137                 return 1;
138
139         return 0;
140 }
141
142 static inline int
143 same_src(const struct ip_conntrack *ct,
144          const struct ip_conntrack_tuple *tuple)
145 {
146         return (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum
147                 == tuple->dst.protonum
148                 && ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip
149                 == tuple->src.ip
150                 && ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.all
151                 == tuple->src.u.all);
152 }
153
154 /* Only called for SRC manip */
155 static int
156 find_appropriate_src(const struct ip_conntrack_tuple *tuple,
157                      struct ip_conntrack_tuple *result,
158                      const struct ip_nat_range *range)
159 {
160         unsigned int h = hash_by_src(tuple);
161         struct ip_conntrack *ct;
162
163         read_lock_bh(&ip_nat_lock);
164         list_for_each_entry(ct, &bysource[h], nat.info.bysource) {
165                 if (same_src(ct, tuple)) {
166                         /* Copy source part from reply tuple. */
167                         invert_tuplepr(result,
168                                        &ct->tuplehash[IP_CT_DIR_REPLY].tuple);
169                         result->dst = tuple->dst;
170
171                         if (in_range(result, range)) {
172                                 read_unlock_bh(&ip_nat_lock);
173                                 return 1;
174                         }
175                 }
176         }
177         read_unlock_bh(&ip_nat_lock);
178         return 0;
179 }
180
181 /* For [FUTURE] fragmentation handling, we want the least-used
182    src-ip/dst-ip/proto triple.  Fairness doesn't come into it.  Thus
183    if the range specifies 1.2.3.4 ports 10000-10005 and 1.2.3.5 ports
184    1-65535, we don't do pro-rata allocation based on ports; we choose
185    the ip with the lowest src-ip/dst-ip/proto usage.
186 */
187 static void
188 find_best_ips_proto(struct ip_conntrack_tuple *tuple,
189                     const struct ip_nat_range *range,
190                     const struct ip_conntrack *conntrack,
191                     enum ip_nat_manip_type maniptype)
192 {
193         __be32 *var_ipp;
194         /* Host order */
195         u_int32_t minip, maxip, j;
196
197         /* No IP mapping?  Do nothing. */
198         if (!(range->flags & IP_NAT_RANGE_MAP_IPS))
199                 return;
200
201         if (maniptype == IP_NAT_MANIP_SRC)
202                 var_ipp = &tuple->src.ip;
203         else
204                 var_ipp = &tuple->dst.ip;
205
206         /* Fast path: only one choice. */
207         if (range->min_ip == range->max_ip) {
208                 *var_ipp = range->min_ip;
209                 return;
210         }
211
212         /* Hashing source and destination IPs gives a fairly even
213          * spread in practice (if there are a small number of IPs
214          * involved, there usually aren't that many connections
215          * anyway).  The consistency means that servers see the same
216          * client coming from the same IP (some Internet Banking sites
217          * like this), even across reboots. */
218         minip = ntohl(range->min_ip);
219         maxip = ntohl(range->max_ip);
220         j = jhash_2words((__force u32)tuple->src.ip, (__force u32)tuple->dst.ip, 0);
221         *var_ipp = htonl(minip + j % (maxip - minip + 1));
222 }
223
224 /* Manipulate the tuple into the range given.  For NF_IP_POST_ROUTING,
225  * we change the source to map into the range.  For NF_IP_PRE_ROUTING
226  * and NF_IP_LOCAL_OUT, we change the destination to map into the
227  * range.  It might not be possible to get a unique tuple, but we try.
228  * At worst (or if we race), we will end up with a final duplicate in
229  * __ip_conntrack_confirm and drop the packet. */
230 static void
231 get_unique_tuple(struct ip_conntrack_tuple *tuple,
232                  const struct ip_conntrack_tuple *orig_tuple,
233                  const struct ip_nat_range *range,
234                  struct ip_conntrack *conntrack,
235                  enum ip_nat_manip_type maniptype)
236 {
237         struct ip_nat_protocol *proto;
238
239         /* 1) If this srcip/proto/src-proto-part is currently mapped,
240            and that same mapping gives a unique tuple within the given
241            range, use that.
242
243            This is only required for source (ie. NAT/masq) mappings.
244            So far, we don't do local source mappings, so multiple
245            manips not an issue.  */
246         if (maniptype == IP_NAT_MANIP_SRC) {
247                 if (find_appropriate_src(orig_tuple, tuple, range)) {
248                         DEBUGP("get_unique_tuple: Found current src map\n");
249                         if (!ip_nat_used_tuple(tuple, conntrack))
250                                 return;
251                 }
252         }
253
254         /* 2) Select the least-used IP/proto combination in the given
255            range. */
256         *tuple = *orig_tuple;
257         find_best_ips_proto(tuple, range, conntrack, maniptype);
258
259         /* 3) The per-protocol part of the manip is made to map into
260            the range to make a unique tuple. */
261
262         proto = ip_nat_proto_find_get(orig_tuple->dst.protonum);
263
264         /* Only bother mapping if it's not already in range and unique */
265         if ((!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED)
266              || proto->in_range(tuple, maniptype, &range->min, &range->max))
267             && !ip_nat_used_tuple(tuple, conntrack)) {
268                 ip_nat_proto_put(proto);
269                 return;
270         }
271
272         /* Last change: get protocol to try to obtain unique tuple. */
273         proto->unique_tuple(tuple, range, maniptype, conntrack);
274
275         ip_nat_proto_put(proto);
276 }
277
278 unsigned int
279 ip_nat_setup_info(struct ip_conntrack *conntrack,
280                   const struct ip_nat_range *range,
281                   unsigned int hooknum)
282 {
283         struct ip_conntrack_tuple curr_tuple, new_tuple;
284         struct ip_nat_info *info = &conntrack->nat.info;
285         int have_to_hash = !(conntrack->status & IPS_NAT_DONE_MASK);
286         enum ip_nat_manip_type maniptype = HOOK2MANIP(hooknum);
287
288         IP_NF_ASSERT(hooknum == NF_IP_PRE_ROUTING
289                      || hooknum == NF_IP_POST_ROUTING
290                      || hooknum == NF_IP_LOCAL_IN
291                      || hooknum == NF_IP_LOCAL_OUT);
292         BUG_ON(ip_nat_initialized(conntrack, maniptype));
293
294         /* What we've got will look like inverse of reply. Normally
295            this is what is in the conntrack, except for prior
296            manipulations (future optimization: if num_manips == 0,
297            orig_tp =
298            conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple) */
299         invert_tuplepr(&curr_tuple,
300                        &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple);
301
302         get_unique_tuple(&new_tuple, &curr_tuple, range, conntrack, maniptype);
303
304         if (!ip_ct_tuple_equal(&new_tuple, &curr_tuple)) {
305                 struct ip_conntrack_tuple reply;
306
307                 /* Alter conntrack table so will recognize replies. */
308                 invert_tuplepr(&reply, &new_tuple);
309                 ip_conntrack_alter_reply(conntrack, &reply);
310
311                 /* Non-atomic: we own this at the moment. */
312                 if (maniptype == IP_NAT_MANIP_SRC)
313                         conntrack->status |= IPS_SRC_NAT;
314                 else
315                         conntrack->status |= IPS_DST_NAT;
316         }
317
318         /* Place in source hash if this is the first time. */
319         if (have_to_hash) {
320                 unsigned int srchash
321                         = hash_by_src(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
322                                       .tuple);
323                 write_lock_bh(&ip_nat_lock);
324                 list_add(&info->bysource, &bysource[srchash]);
325                 write_unlock_bh(&ip_nat_lock);
326         }
327
328         /* It's done. */
329         if (maniptype == IP_NAT_MANIP_DST)
330                 set_bit(IPS_DST_NAT_DONE_BIT, &conntrack->status);
331         else
332                 set_bit(IPS_SRC_NAT_DONE_BIT, &conntrack->status);
333
334         return NF_ACCEPT;
335 }
336 EXPORT_SYMBOL(ip_nat_setup_info);
337
338 /* Returns true if succeeded. */
339 static int
340 manip_pkt(u_int16_t proto,
341           struct sk_buff **pskb,
342           unsigned int iphdroff,
343           const struct ip_conntrack_tuple *target,
344           enum ip_nat_manip_type maniptype)
345 {
346         struct iphdr *iph;
347         struct ip_nat_protocol *p;
348
349         if (!skb_make_writable(pskb, iphdroff + sizeof(*iph)))
350                 return 0;
351
352         iph = (void *)(*pskb)->data + iphdroff;
353
354         /* Manipulate protcol part. */
355         p = ip_nat_proto_find_get(proto);
356         if (!p->manip_pkt(pskb, iphdroff, target, maniptype)) {
357                 ip_nat_proto_put(p);
358                 return 0;
359         }
360         ip_nat_proto_put(p);
361
362         iph = (void *)(*pskb)->data + iphdroff;
363
364         if (maniptype == IP_NAT_MANIP_SRC) {
365                 iph->check = nf_csum_update(~iph->saddr, target->src.ip,
366                                             iph->check);
367                 iph->saddr = target->src.ip;
368         } else {
369                 iph->check = nf_csum_update(~iph->daddr, target->dst.ip,
370                                             iph->check);
371                 iph->daddr = target->dst.ip;
372         }
373         return 1;
374 }
375
376 /* Do packet manipulations according to ip_nat_setup_info. */
377 unsigned int ip_nat_packet(struct ip_conntrack *ct,
378                            enum ip_conntrack_info ctinfo,
379                            unsigned int hooknum,
380                            struct sk_buff **pskb)
381 {
382         enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
383         unsigned long statusbit;
384         enum ip_nat_manip_type mtype = HOOK2MANIP(hooknum);
385
386         if (mtype == IP_NAT_MANIP_SRC)
387                 statusbit = IPS_SRC_NAT;
388         else
389                 statusbit = IPS_DST_NAT;
390
391         /* Invert if this is reply dir. */
392         if (dir == IP_CT_DIR_REPLY)
393                 statusbit ^= IPS_NAT_MASK;
394
395         /* Non-atomic: these bits don't change. */
396         if (ct->status & statusbit) {
397                 struct ip_conntrack_tuple target;
398
399                 /* We are aiming to look like inverse of other direction. */
400                 invert_tuplepr(&target, &ct->tuplehash[!dir].tuple);
401
402                 if (!manip_pkt(target.dst.protonum, pskb, 0, &target, mtype))
403                         return NF_DROP;
404         }
405         return NF_ACCEPT;
406 }
407 EXPORT_SYMBOL_GPL(ip_nat_packet);
408
409 /* Dir is direction ICMP is coming from (opposite to packet it contains) */
410 int ip_nat_icmp_reply_translation(struct ip_conntrack *ct,
411                                   enum ip_conntrack_info ctinfo,
412                                   unsigned int hooknum,
413                                   struct sk_buff **pskb)
414 {
415         struct {
416                 struct icmphdr icmp;
417                 struct iphdr ip;
418         } *inside;
419         struct ip_conntrack_tuple inner, target;
420         int hdrlen = (*pskb)->nh.iph->ihl * 4;
421         enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
422         unsigned long statusbit;
423         enum ip_nat_manip_type manip = HOOK2MANIP(hooknum);
424
425         if (!skb_make_writable(pskb, hdrlen + sizeof(*inside)))
426                 return 0;
427
428         inside = (void *)(*pskb)->data + (*pskb)->nh.iph->ihl*4;
429
430         /* We're actually going to mangle it beyond trivial checksum
431            adjustment, so make sure the current checksum is correct. */
432         if (nf_ip_checksum(*pskb, hooknum, hdrlen, 0))
433                 return 0;
434
435         /* Must be RELATED */
436         IP_NF_ASSERT((*pskb)->nfctinfo == IP_CT_RELATED ||
437                      (*pskb)->nfctinfo == IP_CT_RELATED+IP_CT_IS_REPLY);
438
439         /* Redirects on non-null nats must be dropped, else they'll
440            start talking to each other without our translation, and be
441            confused... --RR */
442         if (inside->icmp.type == ICMP_REDIRECT) {
443                 /* If NAT isn't finished, assume it and drop. */
444                 if ((ct->status & IPS_NAT_DONE_MASK) != IPS_NAT_DONE_MASK)
445                         return 0;
446
447                 if (ct->status & IPS_NAT_MASK)
448                         return 0;
449         }
450
451         DEBUGP("icmp_reply_translation: translating error %p manp %u dir %s\n",
452                *pskb, manip, dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY");
453
454         if (!ip_ct_get_tuple(&inside->ip, *pskb, (*pskb)->nh.iph->ihl*4 +
455                              sizeof(struct icmphdr) + inside->ip.ihl*4,
456                              &inner,
457                              __ip_conntrack_proto_find(inside->ip.protocol)))
458                 return 0;
459
460         /* Change inner back to look like incoming packet.  We do the
461            opposite manip on this hook to normal, because it might not
462            pass all hooks (locally-generated ICMP).  Consider incoming
463            packet: PREROUTING (DST manip), routing produces ICMP, goes
464            through POSTROUTING (which must correct the DST manip). */
465         if (!manip_pkt(inside->ip.protocol, pskb,
466                        (*pskb)->nh.iph->ihl*4
467                        + sizeof(inside->icmp),
468                        &ct->tuplehash[!dir].tuple,
469                        !manip))
470                 return 0;
471
472         if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
473                 /* Reloading "inside" here since manip_pkt inner. */
474                 inside = (void *)(*pskb)->data + (*pskb)->nh.iph->ihl*4;
475                 inside->icmp.checksum = 0;
476                 inside->icmp.checksum = csum_fold(skb_checksum(*pskb, hdrlen,
477                                                                (*pskb)->len - hdrlen,
478                                                                0));
479         }
480
481         /* Change outer to look the reply to an incoming packet
482          * (proto 0 means don't invert per-proto part). */
483         if (manip == IP_NAT_MANIP_SRC)
484                 statusbit = IPS_SRC_NAT;
485         else
486                 statusbit = IPS_DST_NAT;
487
488         /* Invert if this is reply dir. */
489         if (dir == IP_CT_DIR_REPLY)
490                 statusbit ^= IPS_NAT_MASK;
491
492         if (ct->status & statusbit) {
493                 invert_tuplepr(&target, &ct->tuplehash[!dir].tuple);
494                 if (!manip_pkt(0, pskb, 0, &target, manip))
495                         return 0;
496         }
497
498         return 1;
499 }
500 EXPORT_SYMBOL_GPL(ip_nat_icmp_reply_translation);
501
502 /* Protocol registration. */
503 int ip_nat_protocol_register(struct ip_nat_protocol *proto)
504 {
505         int ret = 0;
506
507         write_lock_bh(&ip_nat_lock);
508         if (ip_nat_protos[proto->protonum] != &ip_nat_unknown_protocol) {
509                 ret = -EBUSY;
510                 goto out;
511         }
512         ip_nat_protos[proto->protonum] = proto;
513  out:
514         write_unlock_bh(&ip_nat_lock);
515         return ret;
516 }
517 EXPORT_SYMBOL(ip_nat_protocol_register);
518
519 /* Noone stores the protocol anywhere; simply delete it. */
520 void ip_nat_protocol_unregister(struct ip_nat_protocol *proto)
521 {
522         write_lock_bh(&ip_nat_lock);
523         ip_nat_protos[proto->protonum] = &ip_nat_unknown_protocol;
524         write_unlock_bh(&ip_nat_lock);
525
526         /* Someone could be still looking at the proto in a bh. */
527         synchronize_net();
528 }
529 EXPORT_SYMBOL(ip_nat_protocol_unregister);
530
531 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
532     defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
533 int
534 ip_nat_port_range_to_nfattr(struct sk_buff *skb, 
535                             const struct ip_nat_range *range)
536 {
537         NFA_PUT(skb, CTA_PROTONAT_PORT_MIN, sizeof(__be16),
538                 &range->min.tcp.port);
539         NFA_PUT(skb, CTA_PROTONAT_PORT_MAX, sizeof(__be16),
540                 &range->max.tcp.port);
541
542         return 0;
543
544 nfattr_failure:
545         return -1;
546 }
547
548 int
549 ip_nat_port_nfattr_to_range(struct nfattr *tb[], struct ip_nat_range *range)
550 {
551         int ret = 0;
552         
553         /* we have to return whether we actually parsed something or not */
554
555         if (tb[CTA_PROTONAT_PORT_MIN-1]) {
556                 ret = 1;
557                 range->min.tcp.port = 
558                         *(__be16 *)NFA_DATA(tb[CTA_PROTONAT_PORT_MIN-1]);
559         }
560         
561         if (!tb[CTA_PROTONAT_PORT_MAX-1]) {
562                 if (ret) 
563                         range->max.tcp.port = range->min.tcp.port;
564         } else {
565                 ret = 1;
566                 range->max.tcp.port = 
567                         *(__be16 *)NFA_DATA(tb[CTA_PROTONAT_PORT_MAX-1]);
568         }
569
570         return ret;
571 }
572 EXPORT_SYMBOL_GPL(ip_nat_port_nfattr_to_range);
573 EXPORT_SYMBOL_GPL(ip_nat_port_range_to_nfattr);
574 #endif
575
576 static int __init ip_nat_init(void)
577 {
578         size_t i;
579
580         /* Leave them the same for the moment. */
581         ip_nat_htable_size = ip_conntrack_htable_size;
582
583         /* One vmalloc for both hash tables */
584         bysource = vmalloc(sizeof(struct list_head) * ip_nat_htable_size);
585         if (!bysource)
586                 return -ENOMEM;
587
588         /* Sew in builtin protocols. */
589         write_lock_bh(&ip_nat_lock);
590         for (i = 0; i < MAX_IP_NAT_PROTO; i++)
591                 ip_nat_protos[i] = &ip_nat_unknown_protocol;
592         ip_nat_protos[IPPROTO_TCP] = &ip_nat_protocol_tcp;
593         ip_nat_protos[IPPROTO_UDP] = &ip_nat_protocol_udp;
594         ip_nat_protos[IPPROTO_ICMP] = &ip_nat_protocol_icmp;
595         write_unlock_bh(&ip_nat_lock);
596
597         for (i = 0; i < ip_nat_htable_size; i++) {
598                 INIT_LIST_HEAD(&bysource[i]);
599         }
600
601         /* FIXME: Man, this is a hack.  <SIGH> */
602         IP_NF_ASSERT(ip_conntrack_destroyed == NULL);
603         ip_conntrack_destroyed = &ip_nat_cleanup_conntrack;
604
605         /* Initialize fake conntrack so that NAT will skip it */
606         ip_conntrack_untracked.status |= IPS_NAT_DONE_MASK;
607         return 0;
608 }
609
610 /* Clear NAT section of all conntracks, in case we're loaded again. */
611 static int clean_nat(struct ip_conntrack *i, void *data)
612 {
613         memset(&i->nat, 0, sizeof(i->nat));
614         i->status &= ~(IPS_NAT_MASK | IPS_NAT_DONE_MASK | IPS_SEQ_ADJUST);
615         return 0;
616 }
617
618 static void __exit ip_nat_cleanup(void)
619 {
620         ip_ct_iterate_cleanup(&clean_nat, NULL);
621         ip_conntrack_destroyed = NULL;
622         vfree(bysource);
623 }
624
625 MODULE_LICENSE("GPL");
626
627 module_init(ip_nat_init);
628 module_exit(ip_nat_cleanup);