xref: /freebsd/sbin/ipf/libipf/nat_setgroupmap.c (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1 /*	$FreeBSD$	*/
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  */
8 #if !defined(lint)
9 static const char rcsid[] = "@(#)$Id$";
10 #endif
11 
12 #include "ipf.h"
13 
14 void
15 nat_setgroupmap(ipnat_t *n)
16 {
17 	if (n->in_nsrcmsk == n->in_osrcmsk)
18 		n->in_ippip = 1;
19 	else if (n->in_flags & IPN_AUTOPORTMAP) {
20 		n->in_ippip = ~ntohl(n->in_osrcmsk);
21 		if (n->in_nsrcmsk != 0xffffffff)
22 			n->in_ippip /= (~ntohl(n->in_nsrcmsk) + 1);
23 		n->in_ippip++;
24 		if (n->in_ippip == 0)
25 			n->in_ippip = 1;
26 		n->in_ppip = USABLE_PORTS / n->in_ippip;
27 	} else {
28 		n->in_space = USABLE_PORTS * ~ntohl(n->in_nsrcmsk);
29 		n->in_snip = 0;
30 		if (!(n->in_ppip = n->in_spmin))
31 			n->in_ppip = 1;
32 		n->in_ippip = USABLE_PORTS / n->in_ppip;
33 	}
34 }
35