ip_fw_nat.c revision 200598
1/*-
2 * Copyright (c) 2008 Paolo Pisati
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/netinet/ipfw/ip_fw_nat.c 200598 2009-12-16 03:26:37Z imp $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/condvar.h>
33#include <sys/eventhandler.h>
34#include <sys/malloc.h>
35#include <sys/mbuf.h>
36#include <sys/kernel.h>
37#include <sys/lock.h>
38#include <sys/jail.h>
39#include <sys/module.h>
40#include <sys/priv.h>
41#include <sys/proc.h>
42#include <sys/rwlock.h>
43#include <sys/socket.h>
44#include <sys/socketvar.h>
45#include <sys/sysctl.h>
46#include <sys/syslog.h>
47#include <sys/ucred.h>
48
49#define        IPFW_INTERNAL   /* Access to protected data structures in ip_fw.h. */
50
51#include <netinet/libalias/alias.h>
52#include <netinet/libalias/alias_local.h>
53
54#include <net/if.h>
55#include <netinet/in.h>
56#include <netinet/ip.h>
57#include <netinet/ip_var.h>
58#include <netinet/ip_icmp.h>
59#include <netinet/ip_fw.h>
60#include <netinet/ipfw/ip_fw_private.h>
61#include <netinet/tcp.h>
62#include <netinet/tcp_timer.h>
63#include <netinet/tcp_var.h>
64#include <netinet/tcpip.h>
65#include <netinet/udp.h>
66#include <netinet/udp_var.h>
67
68#include <machine/in_cksum.h>	/* XXX for in_cksum */
69
70static VNET_DEFINE(eventhandler_tag, ifaddr_event_tag);
71#define	V_ifaddr_event_tag	VNET(ifaddr_event_tag)
72
73static void
74ifaddr_change(void *arg __unused, struct ifnet *ifp)
75{
76	struct cfg_nat *ptr;
77	struct ifaddr *ifa;
78
79	IPFW_WLOCK(&V_layer3_chain);
80	/* Check every nat entry... */
81	LIST_FOREACH(ptr, &V_layer3_chain.nat, _next) {
82		/* ...using nic 'ifp->if_xname' as dynamic alias address. */
83		if (strncmp(ptr->if_name, ifp->if_xname, IF_NAMESIZE) == 0) {
84			if_addr_rlock(ifp);
85			TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
86				if (ifa->ifa_addr == NULL)
87					continue;
88				if (ifa->ifa_addr->sa_family != AF_INET)
89					continue;
90				ptr->ip = ((struct sockaddr_in *)
91				    (ifa->ifa_addr))->sin_addr;
92				LibAliasSetAddress(ptr->lib, ptr->ip);
93			}
94			if_addr_runlock(ifp);
95		}
96	}
97	IPFW_WUNLOCK(&V_layer3_chain);
98}
99
100static void
101flush_nat_ptrs(const int i)
102{
103	struct ip_fw *rule;
104
105	IPFW_WLOCK_ASSERT(&V_layer3_chain);
106	for (rule = V_layer3_chain.rules; rule; rule = rule->next) {
107		ipfw_insn_nat *cmd = (ipfw_insn_nat *)ACTION_PTR(rule);
108		if (cmd->o.opcode != O_NAT)
109			continue;
110		if (cmd->nat != NULL && cmd->nat->id == i)
111			cmd->nat = NULL;
112	}
113}
114
115#define HOOK_NAT(b, p) do {				\
116		IPFW_WLOCK_ASSERT(&V_layer3_chain);	\
117		LIST_INSERT_HEAD(b, p, _next);		\
118	} while (0)
119
120#define UNHOOK_NAT(p) do {				\
121		IPFW_WLOCK_ASSERT(&V_layer3_chain);	\
122		LIST_REMOVE(p, _next);			\
123	} while (0)
124
125#define HOOK_REDIR(b, p) do {			\
126		LIST_INSERT_HEAD(b, p, _next);	\
127	} while (0)
128
129#define HOOK_SPOOL(b, p) do {			\
130		LIST_INSERT_HEAD(b, p, _next);	\
131	} while (0)
132
133static void
134del_redir_spool_cfg(struct cfg_nat *n, struct redir_chain *head)
135{
136	struct cfg_redir *r, *tmp_r;
137	struct cfg_spool *s, *tmp_s;
138	int i, num;
139
140	LIST_FOREACH_SAFE(r, head, _next, tmp_r) {
141		num = 1; /* Number of alias_link to delete. */
142		switch (r->mode) {
143		case REDIR_PORT:
144			num = r->pport_cnt;
145			/* FALLTHROUGH */
146		case REDIR_ADDR:
147		case REDIR_PROTO:
148			/* Delete all libalias redirect entry. */
149			for (i = 0; i < num; i++)
150				LibAliasRedirectDelete(n->lib, r->alink[i]);
151			/* Del spool cfg if any. */
152			LIST_FOREACH_SAFE(s, &r->spool_chain, _next, tmp_s) {
153				LIST_REMOVE(s, _next);
154				free(s, M_IPFW);
155			}
156			free(r->alink, M_IPFW);
157			LIST_REMOVE(r, _next);
158			free(r, M_IPFW);
159			break;
160		default:
161			printf("unknown redirect mode: %u\n", r->mode);
162			/* XXX - panic?!?!? */
163			break;
164		}
165	}
166}
167
168static int
169add_redir_spool_cfg(char *buf, struct cfg_nat *ptr)
170{
171	struct cfg_redir *r, *ser_r;
172	struct cfg_spool *s, *ser_s;
173	int cnt, off, i;
174	char *panic_err;
175
176	for (cnt = 0, off = 0; cnt < ptr->redir_cnt; cnt++) {
177		ser_r = (struct cfg_redir *)&buf[off];
178		r = malloc(SOF_REDIR, M_IPFW, M_WAITOK | M_ZERO);
179		memcpy(r, ser_r, SOF_REDIR);
180		LIST_INIT(&r->spool_chain);
181		off += SOF_REDIR;
182		r->alink = malloc(sizeof(struct alias_link *) * r->pport_cnt,
183		    M_IPFW, M_WAITOK | M_ZERO);
184		switch (r->mode) {
185		case REDIR_ADDR:
186			r->alink[0] = LibAliasRedirectAddr(ptr->lib, r->laddr,
187			    r->paddr);
188			break;
189		case REDIR_PORT:
190			for (i = 0 ; i < r->pport_cnt; i++) {
191				/* If remotePort is all ports, set it to 0. */
192				u_short remotePortCopy = r->rport + i;
193				if (r->rport_cnt == 1 && r->rport == 0)
194					remotePortCopy = 0;
195				r->alink[i] = LibAliasRedirectPort(ptr->lib,
196				    r->laddr, htons(r->lport + i), r->raddr,
197				    htons(remotePortCopy), r->paddr,
198				    htons(r->pport + i), r->proto);
199				if (r->alink[i] == NULL) {
200					r->alink[0] = NULL;
201					break;
202				}
203			}
204			break;
205		case REDIR_PROTO:
206			r->alink[0] = LibAliasRedirectProto(ptr->lib ,r->laddr,
207			    r->raddr, r->paddr, r->proto);
208			break;
209		default:
210			printf("unknown redirect mode: %u\n", r->mode);
211			break;
212		}
213		if (r->alink[0] == NULL) {
214			panic_err = "LibAliasRedirect* returned NULL";
215			goto bad;
216		} else /* LSNAT handling. */
217			for (i = 0; i < r->spool_cnt; i++) {
218				ser_s = (struct cfg_spool *)&buf[off];
219				s = malloc(SOF_REDIR, M_IPFW,
220				    M_WAITOK | M_ZERO);
221				memcpy(s, ser_s, SOF_SPOOL);
222				LibAliasAddServer(ptr->lib, r->alink[0],
223				    s->addr, htons(s->port));
224				off += SOF_SPOOL;
225				/* Hook spool entry. */
226				HOOK_SPOOL(&r->spool_chain, s);
227			}
228		/* And finally hook this redir entry. */
229		HOOK_REDIR(&ptr->redir_chain, r);
230	}
231	return (1);
232bad:
233	/* something really bad happened: panic! */
234	panic("%s\n", panic_err);
235}
236
237static int
238ipfw_nat(struct ip_fw_args *args, struct cfg_nat *t, struct mbuf *m)
239{
240	struct mbuf *mcl;
241	struct ip *ip;
242	/* XXX - libalias duct tape */
243	int ldt, retval;
244	char *c;
245
246	ldt = 0;
247	retval = 0;
248	if ((mcl = m_megapullup(m, m->m_pkthdr.len)) ==
249	    NULL)
250		goto badnat;
251	ip = mtod(mcl, struct ip *);
252	if (args->eh == NULL) {
253		ip->ip_len = htons(ip->ip_len);
254		ip->ip_off = htons(ip->ip_off);
255	}
256
257	/*
258	 * XXX - Libalias checksum offload 'duct tape':
259	 *
260	 * locally generated packets have only
261	 * pseudo-header checksum calculated
262	 * and libalias will screw it[1], so
263	 * mark them for later fix.  Moreover
264	 * there are cases when libalias
265	 * modify tcp packet data[2], mark it
266	 * for later fix too.
267	 *
268	 * [1] libalias was never meant to run
269	 * in kernel, so it doesn't have any
270	 * knowledge about checksum
271	 * offloading, and it expects a packet
272	 * with a full internet
273	 * checksum. Unfortunately, packets
274	 * generated locally will have just the
275	 * pseudo header calculated, and when
276	 * libalias tries to adjust the
277	 * checksum it will actually screw it.
278	 *
279	 * [2] when libalias modify tcp's data
280	 * content, full TCP checksum has to
281	 * be recomputed: the problem is that
282	 * libalias doesn't have any idea
283	 * about checksum offloading To
284	 * workaround this, we do not do
285	 * checksumming in LibAlias, but only
286	 * mark the packets in th_x2 field. If
287	 * we receive a marked packet, we
288	 * calculate correct checksum for it
289	 * aware of offloading.  Why such a
290	 * terrible hack instead of
291	 * recalculating checksum for each
292	 * packet?  Because the previous
293	 * checksum was not checked!
294	 * Recalculating checksums for EVERY
295	 * packet will hide ALL transmission
296	 * errors. Yes, marked packets still
297	 * suffer from this problem. But,
298	 * sigh, natd(8) has this problem,
299	 * too.
300	 *
301	 * TODO: -make libalias mbuf aware (so
302	 * it can handle delayed checksum and tso)
303	 */
304
305	if (mcl->m_pkthdr.rcvif == NULL &&
306	    mcl->m_pkthdr.csum_flags &
307	    CSUM_DELAY_DATA)
308		ldt = 1;
309
310	c = mtod(mcl, char *);
311	if (args->oif == NULL)
312		retval = LibAliasIn(t->lib, c,
313			mcl->m_len + M_TRAILINGSPACE(mcl));
314	else
315		retval = LibAliasOut(t->lib, c,
316			mcl->m_len + M_TRAILINGSPACE(mcl));
317	if (retval == PKT_ALIAS_RESPOND) {
318	  m->m_flags |= M_SKIP_FIREWALL;
319	  retval = PKT_ALIAS_OK;
320	}
321	if (retval != PKT_ALIAS_OK &&
322	    retval != PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
323		/* XXX - should i add some logging? */
324		m_free(mcl);
325	badnat:
326		args->m = NULL;
327		return (IP_FW_DENY);
328	}
329	mcl->m_pkthdr.len = mcl->m_len =
330	    ntohs(ip->ip_len);
331
332	/*
333	 * XXX - libalias checksum offload
334	 * 'duct tape' (see above)
335	 */
336
337	if ((ip->ip_off & htons(IP_OFFMASK)) == 0 &&
338	    ip->ip_p == IPPROTO_TCP) {
339		struct tcphdr 	*th;
340
341		th = (struct tcphdr *)(ip + 1);
342		if (th->th_x2)
343			ldt = 1;
344	}
345
346	if (ldt) {
347		struct tcphdr 	*th;
348		struct udphdr 	*uh;
349		u_short cksum;
350
351		ip->ip_len = ntohs(ip->ip_len);
352		cksum = in_pseudo(
353		    ip->ip_src.s_addr,
354		    ip->ip_dst.s_addr,
355		    htons(ip->ip_p + ip->ip_len - (ip->ip_hl << 2))
356		);
357
358		switch (ip->ip_p) {
359		case IPPROTO_TCP:
360			th = (struct tcphdr *)(ip + 1);
361			/*
362			 * Maybe it was set in
363			 * libalias...
364			 */
365			th->th_x2 = 0;
366			th->th_sum = cksum;
367			mcl->m_pkthdr.csum_data =
368			    offsetof(struct tcphdr, th_sum);
369			break;
370		case IPPROTO_UDP:
371			uh = (struct udphdr *)(ip + 1);
372			uh->uh_sum = cksum;
373			mcl->m_pkthdr.csum_data =
374			    offsetof(struct udphdr, uh_sum);
375			break;
376		}
377		/*
378		 * No hw checksum offloading: do it
379		 * by ourself.
380		 */
381		if ((mcl->m_pkthdr.csum_flags &
382		     CSUM_DELAY_DATA) == 0) {
383			in_delayed_cksum(mcl);
384			mcl->m_pkthdr.csum_flags &=
385			    ~CSUM_DELAY_DATA;
386		}
387		ip->ip_len = htons(ip->ip_len);
388	}
389
390	if (args->eh == NULL) {
391		ip->ip_len = ntohs(ip->ip_len);
392		ip->ip_off = ntohs(ip->ip_off);
393	}
394
395	args->m = mcl;
396	return (IP_FW_NAT);
397}
398
399#define LOOKUP_NAT(head, i, p) do {			\
400		LIST_FOREACH((p), head, _next) {	\
401			if ((p)->id == (i)) {		\
402				break;			\
403			}				\
404		}					\
405	} while (0)
406
407static struct cfg_nat *
408lookup_nat(struct nat_list *l, int nat_id)
409{
410	struct cfg_nat *res;
411
412	LOOKUP_NAT(l, nat_id, res);
413	return res;
414}
415
416static int
417ipfw_nat_cfg(struct sockopt *sopt)
418{
419	struct cfg_nat *ptr, *ser_n;
420	char *buf;
421
422	buf = malloc(NAT_BUF_LEN, M_IPFW, M_WAITOK | M_ZERO);
423	sooptcopyin(sopt, buf, NAT_BUF_LEN,
424	    sizeof(struct cfg_nat));
425	ser_n = (struct cfg_nat *)buf;
426
427	/*
428	 * Find/create nat rule.
429	 */
430	IPFW_WLOCK(&V_layer3_chain);
431	LOOKUP_NAT(&V_layer3_chain.nat, ser_n->id, ptr);
432	if (ptr == NULL) {
433		/* New rule: allocate and init new instance. */
434		ptr = malloc(sizeof(struct cfg_nat),
435		    M_IPFW, M_NOWAIT | M_ZERO);
436		if (ptr == NULL) {
437			IPFW_WUNLOCK(&V_layer3_chain);
438			free(buf, M_IPFW);
439			return (ENOSPC);
440		}
441		ptr->lib = LibAliasInit(NULL);
442		if (ptr->lib == NULL) {
443			IPFW_WUNLOCK(&V_layer3_chain);
444			free(ptr, M_IPFW);
445			free(buf, M_IPFW);
446			return (EINVAL);
447		}
448		LIST_INIT(&ptr->redir_chain);
449	} else {
450		/* Entry already present: temporarly unhook it. */
451		UNHOOK_NAT(ptr);
452		flush_nat_ptrs(ser_n->id);
453	}
454	IPFW_WUNLOCK(&V_layer3_chain);
455
456	/*
457	 * Basic nat configuration.
458	 */
459	ptr->id = ser_n->id;
460	/*
461	 * XXX - what if this rule doesn't nat any ip and just
462	 * redirect?
463	 * do we set aliasaddress to 0.0.0.0?
464	 */
465	ptr->ip = ser_n->ip;
466	ptr->redir_cnt = ser_n->redir_cnt;
467	ptr->mode = ser_n->mode;
468	LibAliasSetMode(ptr->lib, ser_n->mode, ser_n->mode);
469	LibAliasSetAddress(ptr->lib, ptr->ip);
470	memcpy(ptr->if_name, ser_n->if_name, IF_NAMESIZE);
471
472	/*
473	 * Redir and LSNAT configuration.
474	 */
475	/* Delete old cfgs. */
476	del_redir_spool_cfg(ptr, &ptr->redir_chain);
477	/* Add new entries. */
478	add_redir_spool_cfg(&buf[(sizeof(struct cfg_nat))], ptr);
479	free(buf, M_IPFW);
480	IPFW_WLOCK(&V_layer3_chain);
481	HOOK_NAT(&V_layer3_chain.nat, ptr);
482	IPFW_WUNLOCK(&V_layer3_chain);
483	return (0);
484}
485
486static int
487ipfw_nat_del(struct sockopt *sopt)
488{
489	struct cfg_nat *ptr;
490	int i;
491
492	sooptcopyin(sopt, &i, sizeof i, sizeof i);
493	IPFW_WLOCK(&V_layer3_chain);
494	LOOKUP_NAT(&V_layer3_chain.nat, i, ptr);
495	if (ptr == NULL) {
496		IPFW_WUNLOCK(&V_layer3_chain);
497		return (EINVAL);
498	}
499	UNHOOK_NAT(ptr);
500	flush_nat_ptrs(i);
501	IPFW_WUNLOCK(&V_layer3_chain);
502	del_redir_spool_cfg(ptr, &ptr->redir_chain);
503	LibAliasUninit(ptr->lib);
504	free(ptr, M_IPFW);
505	return (0);
506}
507
508static int
509ipfw_nat_get_cfg(struct sockopt *sopt)
510{
511	uint8_t *data;
512	struct cfg_nat *n;
513	struct cfg_redir *r;
514	struct cfg_spool *s;
515	int nat_cnt, off;
516
517	nat_cnt = 0;
518	off = sizeof(nat_cnt);
519
520	data = malloc(NAT_BUF_LEN, M_IPFW, M_WAITOK | M_ZERO);
521	IPFW_RLOCK(&V_layer3_chain);
522	/* Serialize all the data. */
523	LIST_FOREACH(n, &V_layer3_chain.nat, _next) {
524		nat_cnt++;
525		if (off + SOF_NAT < NAT_BUF_LEN) {
526			bcopy(n, &data[off], SOF_NAT);
527			off += SOF_NAT;
528			LIST_FOREACH(r, &n->redir_chain, _next) {
529				if (off + SOF_REDIR < NAT_BUF_LEN) {
530					bcopy(r, &data[off],
531					    SOF_REDIR);
532					off += SOF_REDIR;
533					LIST_FOREACH(s, &r->spool_chain,
534					    _next) {
535						if (off + SOF_SPOOL <
536						    NAT_BUF_LEN) {
537							bcopy(s, &data[off],
538							    SOF_SPOOL);
539							off += SOF_SPOOL;
540						} else
541							goto nospace;
542					}
543				} else
544					goto nospace;
545			}
546		} else
547			goto nospace;
548	}
549	bcopy(&nat_cnt, data, sizeof(nat_cnt));
550	IPFW_RUNLOCK(&V_layer3_chain);
551	sooptcopyout(sopt, data, NAT_BUF_LEN);
552	free(data, M_IPFW);
553	return (0);
554nospace:
555	IPFW_RUNLOCK(&V_layer3_chain);
556	printf("serialized data buffer not big enough:"
557	    "please increase NAT_BUF_LEN\n");
558	free(data, M_IPFW);
559	return (ENOSPC);
560}
561
562static int
563ipfw_nat_get_log(struct sockopt *sopt)
564{
565	uint8_t *data;
566	struct cfg_nat *ptr;
567	int i, size, cnt, sof;
568
569	data = NULL;
570	sof = LIBALIAS_BUF_SIZE;
571	cnt = 0;
572
573	IPFW_RLOCK(&V_layer3_chain);
574	size = i = 0;
575	LIST_FOREACH(ptr, &V_layer3_chain.nat, _next) {
576		if (ptr->lib->logDesc == NULL)
577			continue;
578		cnt++;
579		size = cnt * (sof + sizeof(int));
580		data = realloc(data, size, M_IPFW, M_NOWAIT | M_ZERO);
581		if (data == NULL) {
582			IPFW_RUNLOCK(&V_layer3_chain);
583			return (ENOSPC);
584		}
585		bcopy(&ptr->id, &data[i], sizeof(int));
586		i += sizeof(int);
587		bcopy(ptr->lib->logDesc, &data[i], sof);
588		i += sof;
589	}
590	IPFW_RUNLOCK(&V_layer3_chain);
591	sooptcopyout(sopt, data, size);
592	free(data, M_IPFW);
593	return(0);
594}
595
596static void
597ipfw_nat_init(void)
598{
599
600	IPFW_WLOCK(&V_layer3_chain);
601	/* init ipfw hooks */
602	ipfw_nat_ptr = ipfw_nat;
603	lookup_nat_ptr = lookup_nat;
604	ipfw_nat_cfg_ptr = ipfw_nat_cfg;
605	ipfw_nat_del_ptr = ipfw_nat_del;
606	ipfw_nat_get_cfg_ptr = ipfw_nat_get_cfg;
607	ipfw_nat_get_log_ptr = ipfw_nat_get_log;
608	IPFW_WUNLOCK(&V_layer3_chain);
609	V_ifaddr_event_tag = EVENTHANDLER_REGISTER(ifaddr_event, ifaddr_change,
610	    NULL, EVENTHANDLER_PRI_ANY);
611}
612
613static void
614ipfw_nat_destroy(void)
615{
616	struct ip_fw *rule;
617	struct cfg_nat *ptr, *ptr_temp;
618
619	IPFW_WLOCK(&V_layer3_chain);
620	LIST_FOREACH_SAFE(ptr, &V_layer3_chain.nat, _next, ptr_temp) {
621		LIST_REMOVE(ptr, _next);
622		del_redir_spool_cfg(ptr, &ptr->redir_chain);
623		LibAliasUninit(ptr->lib);
624		free(ptr, M_IPFW);
625	}
626	EVENTHANDLER_DEREGISTER(ifaddr_event, V_ifaddr_event_tag);
627	/* flush all nat ptrs */
628	for (rule = V_layer3_chain.rules; rule; rule = rule->next) {
629		ipfw_insn_nat *cmd = (ipfw_insn_nat *)ACTION_PTR(rule);
630		if (cmd->o.opcode == O_NAT)
631			cmd->nat = NULL;
632	}
633	/* deregister ipfw_nat */
634	ipfw_nat_ptr = NULL;
635	lookup_nat_ptr = NULL;
636	ipfw_nat_cfg_ptr = NULL;
637	ipfw_nat_del_ptr = NULL;
638	ipfw_nat_get_cfg_ptr = NULL;
639	ipfw_nat_get_log_ptr = NULL;
640	IPFW_WUNLOCK(&V_layer3_chain);
641}
642
643static int
644ipfw_nat_modevent(module_t mod, int type, void *unused)
645{
646	int err = 0;
647
648	switch (type) {
649	case MOD_LOAD:
650		ipfw_nat_init();
651		break;
652
653	case MOD_UNLOAD:
654		ipfw_nat_destroy();
655		break;
656
657	default:
658		return EOPNOTSUPP;
659		break;
660	}
661	return err;
662}
663
664static moduledata_t ipfw_nat_mod = {
665	"ipfw_nat",
666	ipfw_nat_modevent,
667	0
668};
669
670DECLARE_MODULE(ipfw_nat, ipfw_nat_mod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY);
671MODULE_DEPEND(ipfw_nat, libalias, 1, 1, 1);
672MODULE_DEPEND(ipfw_nat, ipfw, 2, 2, 2);
673MODULE_VERSION(ipfw_nat, 1);
674