17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (C) 1993-2001 by Darren Reed.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
57c478bd9Sstevel@tonic-gate  *
67c478bd9Sstevel@tonic-gate  * Added redirect stuff and a variety of bug fixes. (mcn@EnGarde.com)
7*f4b3ec61Sdh  *
8*f4b3ec61Sdh  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
9*f4b3ec61Sdh  * Use is subject to license terms.
107c478bd9Sstevel@tonic-gate  */
11*f4b3ec61Sdh 
12*f4b3ec61Sdh #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*f4b3ec61Sdh 
147c478bd9Sstevel@tonic-gate #include "ipf.h"
157c478bd9Sstevel@tonic-gate #include "kmem.h"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate #if !defined(lint)
18ab25eeb5Syz static const char rcsid[] = "@(#)$Id: getnattype.c,v 1.3 2004/01/17 17:26:07 darrenr Exp $";
197c478bd9Sstevel@tonic-gate #endif
207c478bd9Sstevel@tonic-gate 
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Get a nat filter type given its kernel address.
247c478bd9Sstevel@tonic-gate  */
getnattype(nat,alive)25*f4b3ec61Sdh char *getnattype(nat, alive)
26*f4b3ec61Sdh nat_t *nat;
27*f4b3ec61Sdh int alive;
287c478bd9Sstevel@tonic-gate {
297c478bd9Sstevel@tonic-gate 	static char unknownbuf[20];
30*f4b3ec61Sdh 	ipnat_t *ipn, ipnatbuff;
317c478bd9Sstevel@tonic-gate 	char *which;
32*f4b3ec61Sdh 	int type;
337c478bd9Sstevel@tonic-gate 
34*f4b3ec61Sdh 	if (!nat)
357c478bd9Sstevel@tonic-gate 		return "???";
36*f4b3ec61Sdh 	if (alive) {
37*f4b3ec61Sdh 		type = nat->nat_redir;
38*f4b3ec61Sdh 	} else {
39*f4b3ec61Sdh 		ipn = nat->nat_ptr;
40*f4b3ec61Sdh 		if (kmemcpy((char *)&ipnatbuff, (long)ipn, sizeof(ipnatbuff)))
41*f4b3ec61Sdh 			return "!!!";
42*f4b3ec61Sdh 		type = ipnatbuff.in_redir;
43*f4b3ec61Sdh 	}
447c478bd9Sstevel@tonic-gate 
45*f4b3ec61Sdh 	switch (type)
467c478bd9Sstevel@tonic-gate 	{
477c478bd9Sstevel@tonic-gate 	case NAT_MAP :
487c478bd9Sstevel@tonic-gate 		which = "MAP";
497c478bd9Sstevel@tonic-gate 		break;
507c478bd9Sstevel@tonic-gate 	case NAT_MAPBLK :
517c478bd9Sstevel@tonic-gate 		which = "MAP-BLOCK";
527c478bd9Sstevel@tonic-gate 		break;
537c478bd9Sstevel@tonic-gate 	case NAT_REDIRECT :
547c478bd9Sstevel@tonic-gate 		which = "RDR";
557c478bd9Sstevel@tonic-gate 		break;
567c478bd9Sstevel@tonic-gate 	case NAT_BIMAP :
577c478bd9Sstevel@tonic-gate 		which = "BIMAP";
587c478bd9Sstevel@tonic-gate 		break;
597c478bd9Sstevel@tonic-gate 	default :
60*f4b3ec61Sdh 		sprintf(unknownbuf, "unknown(%04x)", type & 0xffffffff);
617c478bd9Sstevel@tonic-gate 		which = unknownbuf;
627c478bd9Sstevel@tonic-gate 		break;
637c478bd9Sstevel@tonic-gate 	}
647c478bd9Sstevel@tonic-gate 	return which;
657c478bd9Sstevel@tonic-gate }
66