xref: /freebsd/sbin/ipf/libipf/printnatfield.c (revision efeb8bffe34422937c7f8df836afb5b817366d16)
141edb306SCy Schubert /*
241edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
341edb306SCy Schubert  *
441edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
541edb306SCy Schubert  *
641edb306SCy Schubert  * $Id: printnatfield.c,v 1.6.2.2 2012/01/26 05:44:26 darren_r Exp $
741edb306SCy Schubert  */
841edb306SCy Schubert 
941edb306SCy Schubert #include "ipf.h"
1041edb306SCy Schubert 
1141edb306SCy Schubert wordtab_t natfields[] = {
1241edb306SCy Schubert 	{ "all",	-2 },
1341edb306SCy Schubert 	{ "ifp0",	1 },
1441edb306SCy Schubert 	{ "ifp1",	2 },
1541edb306SCy Schubert 	{ "mtu0",	3 },
1641edb306SCy Schubert 	{ "mtu1",	4 },
1741edb306SCy Schubert 	{ "ifname0",	5 },
1841edb306SCy Schubert 	{ "ifname1",	6 },
1941edb306SCy Schubert 	{ "sumd0",	7 },
2041edb306SCy Schubert 	{ "sumd1",	8 },
2141edb306SCy Schubert 	{ "pkts0",	9 },
2241edb306SCy Schubert 	{ "pkts1",	10 },
2341edb306SCy Schubert 	{ "bytes0",	11 },
2441edb306SCy Schubert 	{ "bytes1",	12 },
2541edb306SCy Schubert 	{ "proto0",	13 },
2641edb306SCy Schubert 	{ "proto1",	14 },
2741edb306SCy Schubert 	{ "hash0",	15 },
2841edb306SCy Schubert 	{ "hash1",	16 },
2941edb306SCy Schubert 	{ "ref",	17 },
3041edb306SCy Schubert 	{ "rev",	18 },
3141edb306SCy Schubert 	{ "v0",		19 },
3241edb306SCy Schubert 	{ "redir",	20 },
3341edb306SCy Schubert 	{ "use",	21 },
3441edb306SCy Schubert 	{ "ipsumd",	22 },
3541edb306SCy Schubert 	{ "dir",	23 },
3641edb306SCy Schubert 	{ "olddstip",	24 },
3741edb306SCy Schubert 	{ "oldsrcip",	25 },
3841edb306SCy Schubert 	{ "newdstip",	26 },
3941edb306SCy Schubert 	{ "newsrcip",	27 },
4041edb306SCy Schubert 	{ "olddport",	28 },
4141edb306SCy Schubert 	{ "oldsport",	29 },
4241edb306SCy Schubert 	{ "newdport",	30 },
4341edb306SCy Schubert 	{ "newsport",	31 },
4441edb306SCy Schubert 	{ "age",	32 },
4541edb306SCy Schubert 	{ "v1",		33 },
4641edb306SCy Schubert 	{ NULL, 0 }
4741edb306SCy Schubert };
4841edb306SCy Schubert 
4941edb306SCy Schubert 
5041edb306SCy Schubert void
printnatfield(nat_t * n,int fieldnum)51*efeb8bffSCy Schubert printnatfield( nat_t *n, int fieldnum)
5241edb306SCy Schubert {
5341edb306SCy Schubert 	int i;
5441edb306SCy Schubert 
5541edb306SCy Schubert 	switch (fieldnum)
5641edb306SCy Schubert 	{
5741edb306SCy Schubert 	case -2 :
5841edb306SCy Schubert 		for (i = 1; natfields[i].w_word != NULL; i++) {
5941edb306SCy Schubert 			if (natfields[i].w_value > 0) {
6041edb306SCy Schubert 				printnatfield(n, i);
6141edb306SCy Schubert 				if (natfields[i + 1].w_value > 0)
6241edb306SCy Schubert 					putchar('\t');
6341edb306SCy Schubert 			}
6441edb306SCy Schubert 		}
6541edb306SCy Schubert 		break;
6641edb306SCy Schubert 
6741edb306SCy Schubert 	case 1:
6841edb306SCy Schubert 		PRINTF("%#lx", (u_long)n->nat_ifps[0]);
6941edb306SCy Schubert 		break;
7041edb306SCy Schubert 
7141edb306SCy Schubert 	case 2:
7241edb306SCy Schubert 		PRINTF("%#lx", (u_long)n->nat_ifps[1]);
7341edb306SCy Schubert 		break;
7441edb306SCy Schubert 
7541edb306SCy Schubert 	case 3:
7641edb306SCy Schubert 		PRINTF("%d", n->nat_mtu[0]);
7741edb306SCy Schubert 		break;
7841edb306SCy Schubert 
7941edb306SCy Schubert 	case 4:
8041edb306SCy Schubert 		PRINTF("%d", n->nat_mtu[1]);
8141edb306SCy Schubert 		break;
8241edb306SCy Schubert 
8341edb306SCy Schubert 	case 5:
8441edb306SCy Schubert 		PRINTF("%s", n->nat_ifnames[0]);
8541edb306SCy Schubert 		break;
8641edb306SCy Schubert 
8741edb306SCy Schubert 	case 6:
8841edb306SCy Schubert 		PRINTF("%s", n->nat_ifnames[1]);
8941edb306SCy Schubert 		break;
9041edb306SCy Schubert 
9141edb306SCy Schubert 	case 7:
9241edb306SCy Schubert 		PRINTF("%d", n->nat_sumd[0]);
9341edb306SCy Schubert 		break;
9441edb306SCy Schubert 
9541edb306SCy Schubert 	case 8:
9641edb306SCy Schubert 		PRINTF("%d", n->nat_sumd[1]);
9741edb306SCy Schubert 		break;
9841edb306SCy Schubert 
9941edb306SCy Schubert 	case 9:
10041edb306SCy Schubert #ifdef USE_QUAD_T
10141edb306SCy Schubert 		PRINTF("%"PRIu64"", n->nat_pkts[0]);
10241edb306SCy Schubert #else
10341edb306SCy Schubert 		PRINTF("%lu", n->nat_pkts[0]);
10441edb306SCy Schubert #endif
10541edb306SCy Schubert 		break;
10641edb306SCy Schubert 
10741edb306SCy Schubert 	case 10:
10841edb306SCy Schubert #ifdef USE_QUAD_T
10941edb306SCy Schubert 		PRINTF("%"PRIu64"", n->nat_pkts[1]);
11041edb306SCy Schubert #else
11141edb306SCy Schubert 		PRINTF("%lu", n->nat_pkts[1]);
11241edb306SCy Schubert #endif
11341edb306SCy Schubert 		break;
11441edb306SCy Schubert 
11541edb306SCy Schubert 	case 11:
11641edb306SCy Schubert #ifdef USE_QUAD_T
11741edb306SCy Schubert 		PRINTF("%"PRIu64"", n->nat_bytes[0]);
11841edb306SCy Schubert #else
11941edb306SCy Schubert 		PRINTF("%lu", n->nat_bytes[0]);
12041edb306SCy Schubert #endif
12141edb306SCy Schubert 		break;
12241edb306SCy Schubert 
12341edb306SCy Schubert 	case 12:
12441edb306SCy Schubert #ifdef USE_QUAD_T
12541edb306SCy Schubert 		PRINTF("%"PRIu64"", n->nat_bytes[1]);
12641edb306SCy Schubert #else
12741edb306SCy Schubert 		PRINTF("%lu", n->nat_bytes[1]);
12841edb306SCy Schubert #endif
12941edb306SCy Schubert 		break;
13041edb306SCy Schubert 
13141edb306SCy Schubert 	case 13:
13241edb306SCy Schubert 		PRINTF("%d", n->nat_pr[0]);
13341edb306SCy Schubert 		break;
13441edb306SCy Schubert 
13541edb306SCy Schubert 	case 14:
13641edb306SCy Schubert 		PRINTF("%d", n->nat_pr[1]);
13741edb306SCy Schubert 		break;
13841edb306SCy Schubert 
13941edb306SCy Schubert 	case 15:
14041edb306SCy Schubert 		PRINTF("%u", n->nat_hv[0]);
14141edb306SCy Schubert 		break;
14241edb306SCy Schubert 
14341edb306SCy Schubert 	case 16:
14441edb306SCy Schubert 		PRINTF("%u", n->nat_hv[1]);
14541edb306SCy Schubert 		break;
14641edb306SCy Schubert 
14741edb306SCy Schubert 	case 17:
14841edb306SCy Schubert 		PRINTF("%d", n->nat_ref);
14941edb306SCy Schubert 		break;
15041edb306SCy Schubert 
15141edb306SCy Schubert 	case 18:
15241edb306SCy Schubert 		PRINTF("%d", n->nat_rev);
15341edb306SCy Schubert 		break;
15441edb306SCy Schubert 
15541edb306SCy Schubert 	case 19:
15641edb306SCy Schubert 		PRINTF("%d", n->nat_v[0]);
15741edb306SCy Schubert 		break;
15841edb306SCy Schubert 
15941edb306SCy Schubert 	case 33:
16041edb306SCy Schubert 		PRINTF("%d", n->nat_v[0]);
16141edb306SCy Schubert 		break;
16241edb306SCy Schubert 
16341edb306SCy Schubert 	case 20:
16441edb306SCy Schubert 		PRINTF("%d", n->nat_redir);
16541edb306SCy Schubert 		break;
16641edb306SCy Schubert 
16741edb306SCy Schubert 	case 21:
16841edb306SCy Schubert 		PRINTF("%d", n->nat_use);
16941edb306SCy Schubert 		break;
17041edb306SCy Schubert 
17141edb306SCy Schubert 	case 22:
17241edb306SCy Schubert 		PRINTF("%u", n->nat_ipsumd);
17341edb306SCy Schubert 		break;
17441edb306SCy Schubert 
17541edb306SCy Schubert 	case 23:
17641edb306SCy Schubert 		PRINTF("%d", n->nat_dir);
17741edb306SCy Schubert 		break;
17841edb306SCy Schubert 
17941edb306SCy Schubert 	case 24:
18041edb306SCy Schubert 		PRINTF("%s", hostname(n->nat_v[0], &n->nat_odstip));
18141edb306SCy Schubert 		break;
18241edb306SCy Schubert 
18341edb306SCy Schubert 	case 25:
18441edb306SCy Schubert 		PRINTF("%s", hostname(n->nat_v[0], &n->nat_osrcip));
18541edb306SCy Schubert 		break;
18641edb306SCy Schubert 
18741edb306SCy Schubert 	case 26:
18841edb306SCy Schubert 		PRINTF("%s", hostname(n->nat_v[1], &n->nat_ndstip));
18941edb306SCy Schubert 		break;
19041edb306SCy Schubert 
19141edb306SCy Schubert 	case 27:
19241edb306SCy Schubert 		PRINTF("%s", hostname(n->nat_v[1], &n->nat_nsrcip));
19341edb306SCy Schubert 		break;
19441edb306SCy Schubert 
19541edb306SCy Schubert 	case 28:
19641edb306SCy Schubert 		PRINTF("%hu", ntohs(n->nat_odport));
19741edb306SCy Schubert 		break;
19841edb306SCy Schubert 
19941edb306SCy Schubert 	case 29:
20041edb306SCy Schubert 		PRINTF("%hu", ntohs(n->nat_osport));
20141edb306SCy Schubert 		break;
20241edb306SCy Schubert 
20341edb306SCy Schubert 	case 30:
20441edb306SCy Schubert 		PRINTF("%hu", ntohs(n->nat_ndport));
20541edb306SCy Schubert 		break;
20641edb306SCy Schubert 
20741edb306SCy Schubert 	case 31:
20841edb306SCy Schubert 		PRINTF("%hu", ntohs(n->nat_nsport));
20941edb306SCy Schubert 		break;
21041edb306SCy Schubert 
21141edb306SCy Schubert 	case 32:
21241edb306SCy Schubert 		PRINTF("%u", n->nat_age);
21341edb306SCy Schubert 		break;
21441edb306SCy Schubert 
21541edb306SCy Schubert 	default:
21641edb306SCy Schubert 		break;
21741edb306SCy Schubert 	}
21841edb306SCy Schubert }
219