xref: /titanic_41/usr/src/cmd/ipf/lib/common/nat_setgroupmap.c (revision d5ace9454616652a717c9831d949dffa319381f9)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11 
12 #include "ipf.h"
13 
14 void nat_setgroupmap(n)
15 ipnat_t *n;
16 {
17 	if (n->in_outmsk == n->in_inmsk)
18 		n->in_ippip = 1;
19 	else if (n->in_flags & IPN_AUTOPORTMAP) {
20 		n->in_ippip = ~ntohl(n->in_inmsk);
21 		if (n->in_outmsk != 0xffffffff)
22 			n->in_ippip /= (~ntohl(n->in_outmsk) + 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_outmsk);
29 		n->in_nip = 0;
30 		if (!(n->in_ppip = n->in_pmin))
31 			n->in_ppip = 1;
32 		n->in_ippip = USABLE_PORTS / n->in_ppip;
33 	}
34 }
35