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