xref: /netbsd-src/external/bsd/ipf/dist/lib/getnattype.c (revision 07967fb18af5b87d2d477c5b3e1e438bf0c293fb)
1 /*	$NetBSD: getnattype.c,v 1.3 2018/02/04 08:19:42 mrg Exp $	*/
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * Added redirect stuff and a variety of bug fixes. (mcn@EnGarde.com)
9  */
10 #include "ipf.h"
11 #include "kmem.h"
12 
13 #if !defined(lint)
14 static __attribute__((__used__)) const char rcsid[] = "@(#)Id: getnattype.c,v 1.1.1.2 2012/07/22 13:44:38 darrenr Exp $";
15 #endif
16 
17 
18 /*
19  * Get a nat filter type given its kernel address.
20  */
21 char *
getnattype(nat)22 getnattype(nat)
23 	nat_t *nat;
24 {
25 	static char unknownbuf[20];
26 	char *which;
27 
28 	if (!nat)
29 		return "???";
30 
31 	switch (nat->nat_redir)
32 	{
33 	case NAT_MAP :
34 		which = "MAP";
35 		break;
36 	case NAT_MAPBLK :
37 		which = "MAP-BLOCK";
38 		break;
39 	case NAT_REDIRECT :
40 		which = "RDR";
41 		break;
42 	case NAT_MAP|NAT_REWRITE :
43 		which = "RWR-MAP";
44 		break;
45 	case NAT_REDIRECT|NAT_REWRITE :
46 		which = "RWR-RDR";
47 		break;
48 	case NAT_BIMAP :
49 		which = "BIMAP";
50 		break;
51 	case NAT_REDIRECT|NAT_DIVERTUDP :
52 		which = "DIV-RDR";
53 		break;
54 	case NAT_MAP|NAT_DIVERTUDP :
55 		which = "DIV-MAP";
56 		break;
57 	case NAT_REDIRECT|NAT_ENCAP :
58 		which = "ENC-RDR";
59 		break;
60 	case NAT_MAP|NAT_ENCAP :
61 		which = "ENC-MAP";
62 		break;
63 	default :
64 		sprintf(unknownbuf, "unknown(%04x)",
65 			nat->nat_redir & 0xffffffff);
66 		which = unknownbuf;
67 		break;
68 	}
69 	return which;
70 }
71