xref: /illumos-gate/usr/src/cmd/ipf/lib/nat_setgroupmap.c (revision f17620a4f72a29025a22655ba8735ccd20ae174f)
1 /*
2  * Copyright (C) 1993-2001 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
7  * Use is subject to license terms.
8  */
9 
10 #include "ipf.h"
11 
12 void nat_setgroupmap(n)
13 ipnat_t *n;
14 {
15 	if (n->in_outmsk == n->in_inmsk)
16 		n->in_ippip = 1;
17 	else if (n->in_flags & IPN_AUTOPORTMAP) {
18 		n->in_ippip = ~ntohl(n->in_inmsk);
19 		if (n->in_outmsk != 0xffffffff)
20 			n->in_ippip /= (~ntohl(n->in_outmsk) + 1);
21 		n->in_ippip++;
22 		if (n->in_ippip == 0)
23 			n->in_ippip = 1;
24 		n->in_ppip = USABLE_PORTS / n->in_ippip;
25 	} else {
26 		n->in_space = USABLE_PORTS * ~ntohl(n->in_outmsk);
27 		n->in_nip = 0;
28 		if (!(n->in_ppip = n->in_pmin))
29 			n->in_ppip = 1;
30 		n->in_ippip = USABLE_PORTS / n->in_ppip;
31 	}
32 }
33