xref: /freebsd/sbin/ipf/libipf/printnatfield.c (revision 41edb306f05651fcaf6c74f9e3557f59f80292e1)
1*41edb306SCy Schubert /*
2*41edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
3*41edb306SCy Schubert  *
4*41edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
5*41edb306SCy Schubert  *
6*41edb306SCy Schubert  * $Id: printnatfield.c,v 1.6.2.2 2012/01/26 05:44:26 darren_r Exp $
7*41edb306SCy Schubert  */
8*41edb306SCy Schubert 
9*41edb306SCy Schubert #include "ipf.h"
10*41edb306SCy Schubert 
11*41edb306SCy Schubert wordtab_t natfields[] = {
12*41edb306SCy Schubert 	{ "all",	-2 },
13*41edb306SCy Schubert 	{ "ifp0",	1 },
14*41edb306SCy Schubert 	{ "ifp1",	2 },
15*41edb306SCy Schubert 	{ "mtu0",	3 },
16*41edb306SCy Schubert 	{ "mtu1",	4 },
17*41edb306SCy Schubert 	{ "ifname0",	5 },
18*41edb306SCy Schubert 	{ "ifname1",	6 },
19*41edb306SCy Schubert 	{ "sumd0",	7 },
20*41edb306SCy Schubert 	{ "sumd1",	8 },
21*41edb306SCy Schubert 	{ "pkts0",	9 },
22*41edb306SCy Schubert 	{ "pkts1",	10 },
23*41edb306SCy Schubert 	{ "bytes0",	11 },
24*41edb306SCy Schubert 	{ "bytes1",	12 },
25*41edb306SCy Schubert 	{ "proto0",	13 },
26*41edb306SCy Schubert 	{ "proto1",	14 },
27*41edb306SCy Schubert 	{ "hash0",	15 },
28*41edb306SCy Schubert 	{ "hash1",	16 },
29*41edb306SCy Schubert 	{ "ref",	17 },
30*41edb306SCy Schubert 	{ "rev",	18 },
31*41edb306SCy Schubert 	{ "v0",		19 },
32*41edb306SCy Schubert 	{ "redir",	20 },
33*41edb306SCy Schubert 	{ "use",	21 },
34*41edb306SCy Schubert 	{ "ipsumd",	22 },
35*41edb306SCy Schubert 	{ "dir",	23 },
36*41edb306SCy Schubert 	{ "olddstip",	24 },
37*41edb306SCy Schubert 	{ "oldsrcip",	25 },
38*41edb306SCy Schubert 	{ "newdstip",	26 },
39*41edb306SCy Schubert 	{ "newsrcip",	27 },
40*41edb306SCy Schubert 	{ "olddport",	28 },
41*41edb306SCy Schubert 	{ "oldsport",	29 },
42*41edb306SCy Schubert 	{ "newdport",	30 },
43*41edb306SCy Schubert 	{ "newsport",	31 },
44*41edb306SCy Schubert 	{ "age",	32 },
45*41edb306SCy Schubert 	{ "v1",		33 },
46*41edb306SCy Schubert 	{ NULL, 0 }
47*41edb306SCy Schubert };
48*41edb306SCy Schubert 
49*41edb306SCy Schubert 
50*41edb306SCy Schubert void
51*41edb306SCy Schubert printnatfield(n, fieldnum)
52*41edb306SCy Schubert 	nat_t *n;
53*41edb306SCy Schubert 	int fieldnum;
54*41edb306SCy Schubert {
55*41edb306SCy Schubert 	int i;
56*41edb306SCy Schubert 
57*41edb306SCy Schubert 	switch (fieldnum)
58*41edb306SCy Schubert 	{
59*41edb306SCy Schubert 	case -2 :
60*41edb306SCy Schubert 		for (i = 1; natfields[i].w_word != NULL; i++) {
61*41edb306SCy Schubert 			if (natfields[i].w_value > 0) {
62*41edb306SCy Schubert 				printnatfield(n, i);
63*41edb306SCy Schubert 				if (natfields[i + 1].w_value > 0)
64*41edb306SCy Schubert 					putchar('\t');
65*41edb306SCy Schubert 			}
66*41edb306SCy Schubert 		}
67*41edb306SCy Schubert 		break;
68*41edb306SCy Schubert 
69*41edb306SCy Schubert 	case 1:
70*41edb306SCy Schubert 		PRINTF("%#lx", (u_long)n->nat_ifps[0]);
71*41edb306SCy Schubert 		break;
72*41edb306SCy Schubert 
73*41edb306SCy Schubert 	case 2:
74*41edb306SCy Schubert 		PRINTF("%#lx", (u_long)n->nat_ifps[1]);
75*41edb306SCy Schubert 		break;
76*41edb306SCy Schubert 
77*41edb306SCy Schubert 	case 3:
78*41edb306SCy Schubert 		PRINTF("%d", n->nat_mtu[0]);
79*41edb306SCy Schubert 		break;
80*41edb306SCy Schubert 
81*41edb306SCy Schubert 	case 4:
82*41edb306SCy Schubert 		PRINTF("%d", n->nat_mtu[1]);
83*41edb306SCy Schubert 		break;
84*41edb306SCy Schubert 
85*41edb306SCy Schubert 	case 5:
86*41edb306SCy Schubert 		PRINTF("%s", n->nat_ifnames[0]);
87*41edb306SCy Schubert 		break;
88*41edb306SCy Schubert 
89*41edb306SCy Schubert 	case 6:
90*41edb306SCy Schubert 		PRINTF("%s", n->nat_ifnames[1]);
91*41edb306SCy Schubert 		break;
92*41edb306SCy Schubert 
93*41edb306SCy Schubert 	case 7:
94*41edb306SCy Schubert 		PRINTF("%d", n->nat_sumd[0]);
95*41edb306SCy Schubert 		break;
96*41edb306SCy Schubert 
97*41edb306SCy Schubert 	case 8:
98*41edb306SCy Schubert 		PRINTF("%d", n->nat_sumd[1]);
99*41edb306SCy Schubert 		break;
100*41edb306SCy Schubert 
101*41edb306SCy Schubert 	case 9:
102*41edb306SCy Schubert #ifdef USE_QUAD_T
103*41edb306SCy Schubert 		PRINTF("%"PRIu64"", n->nat_pkts[0]);
104*41edb306SCy Schubert #else
105*41edb306SCy Schubert 		PRINTF("%lu", n->nat_pkts[0]);
106*41edb306SCy Schubert #endif
107*41edb306SCy Schubert 		break;
108*41edb306SCy Schubert 
109*41edb306SCy Schubert 	case 10:
110*41edb306SCy Schubert #ifdef USE_QUAD_T
111*41edb306SCy Schubert 		PRINTF("%"PRIu64"", n->nat_pkts[1]);
112*41edb306SCy Schubert #else
113*41edb306SCy Schubert 		PRINTF("%lu", n->nat_pkts[1]);
114*41edb306SCy Schubert #endif
115*41edb306SCy Schubert 		break;
116*41edb306SCy Schubert 
117*41edb306SCy Schubert 	case 11:
118*41edb306SCy Schubert #ifdef USE_QUAD_T
119*41edb306SCy Schubert 		PRINTF("%"PRIu64"", n->nat_bytes[0]);
120*41edb306SCy Schubert #else
121*41edb306SCy Schubert 		PRINTF("%lu", n->nat_bytes[0]);
122*41edb306SCy Schubert #endif
123*41edb306SCy Schubert 		break;
124*41edb306SCy Schubert 
125*41edb306SCy Schubert 	case 12:
126*41edb306SCy Schubert #ifdef USE_QUAD_T
127*41edb306SCy Schubert 		PRINTF("%"PRIu64"", n->nat_bytes[1]);
128*41edb306SCy Schubert #else
129*41edb306SCy Schubert 		PRINTF("%lu", n->nat_bytes[1]);
130*41edb306SCy Schubert #endif
131*41edb306SCy Schubert 		break;
132*41edb306SCy Schubert 
133*41edb306SCy Schubert 	case 13:
134*41edb306SCy Schubert 		PRINTF("%d", n->nat_pr[0]);
135*41edb306SCy Schubert 		break;
136*41edb306SCy Schubert 
137*41edb306SCy Schubert 	case 14:
138*41edb306SCy Schubert 		PRINTF("%d", n->nat_pr[1]);
139*41edb306SCy Schubert 		break;
140*41edb306SCy Schubert 
141*41edb306SCy Schubert 	case 15:
142*41edb306SCy Schubert 		PRINTF("%u", n->nat_hv[0]);
143*41edb306SCy Schubert 		break;
144*41edb306SCy Schubert 
145*41edb306SCy Schubert 	case 16:
146*41edb306SCy Schubert 		PRINTF("%u", n->nat_hv[1]);
147*41edb306SCy Schubert 		break;
148*41edb306SCy Schubert 
149*41edb306SCy Schubert 	case 17:
150*41edb306SCy Schubert 		PRINTF("%d", n->nat_ref);
151*41edb306SCy Schubert 		break;
152*41edb306SCy Schubert 
153*41edb306SCy Schubert 	case 18:
154*41edb306SCy Schubert 		PRINTF("%d", n->nat_rev);
155*41edb306SCy Schubert 		break;
156*41edb306SCy Schubert 
157*41edb306SCy Schubert 	case 19:
158*41edb306SCy Schubert 		PRINTF("%d", n->nat_v[0]);
159*41edb306SCy Schubert 		break;
160*41edb306SCy Schubert 
161*41edb306SCy Schubert 	case 33:
162*41edb306SCy Schubert 		PRINTF("%d", n->nat_v[0]);
163*41edb306SCy Schubert 		break;
164*41edb306SCy Schubert 
165*41edb306SCy Schubert 	case 20:
166*41edb306SCy Schubert 		PRINTF("%d", n->nat_redir);
167*41edb306SCy Schubert 		break;
168*41edb306SCy Schubert 
169*41edb306SCy Schubert 	case 21:
170*41edb306SCy Schubert 		PRINTF("%d", n->nat_use);
171*41edb306SCy Schubert 		break;
172*41edb306SCy Schubert 
173*41edb306SCy Schubert 	case 22:
174*41edb306SCy Schubert 		PRINTF("%u", n->nat_ipsumd);
175*41edb306SCy Schubert 		break;
176*41edb306SCy Schubert 
177*41edb306SCy Schubert 	case 23:
178*41edb306SCy Schubert 		PRINTF("%d", n->nat_dir);
179*41edb306SCy Schubert 		break;
180*41edb306SCy Schubert 
181*41edb306SCy Schubert 	case 24:
182*41edb306SCy Schubert 		PRINTF("%s", hostname(n->nat_v[0], &n->nat_odstip));
183*41edb306SCy Schubert 		break;
184*41edb306SCy Schubert 
185*41edb306SCy Schubert 	case 25:
186*41edb306SCy Schubert 		PRINTF("%s", hostname(n->nat_v[0], &n->nat_osrcip));
187*41edb306SCy Schubert 		break;
188*41edb306SCy Schubert 
189*41edb306SCy Schubert 	case 26:
190*41edb306SCy Schubert 		PRINTF("%s", hostname(n->nat_v[1], &n->nat_ndstip));
191*41edb306SCy Schubert 		break;
192*41edb306SCy Schubert 
193*41edb306SCy Schubert 	case 27:
194*41edb306SCy Schubert 		PRINTF("%s", hostname(n->nat_v[1], &n->nat_nsrcip));
195*41edb306SCy Schubert 		break;
196*41edb306SCy Schubert 
197*41edb306SCy Schubert 	case 28:
198*41edb306SCy Schubert 		PRINTF("%hu", ntohs(n->nat_odport));
199*41edb306SCy Schubert 		break;
200*41edb306SCy Schubert 
201*41edb306SCy Schubert 	case 29:
202*41edb306SCy Schubert 		PRINTF("%hu", ntohs(n->nat_osport));
203*41edb306SCy Schubert 		break;
204*41edb306SCy Schubert 
205*41edb306SCy Schubert 	case 30:
206*41edb306SCy Schubert 		PRINTF("%hu", ntohs(n->nat_ndport));
207*41edb306SCy Schubert 		break;
208*41edb306SCy Schubert 
209*41edb306SCy Schubert 	case 31:
210*41edb306SCy Schubert 		PRINTF("%hu", ntohs(n->nat_nsport));
211*41edb306SCy Schubert 		break;
212*41edb306SCy Schubert 
213*41edb306SCy Schubert 	case 32:
214*41edb306SCy Schubert 		PRINTF("%u", n->nat_age);
215*41edb306SCy Schubert 		break;
216*41edb306SCy Schubert 
217*41edb306SCy Schubert 	default:
218*41edb306SCy Schubert 		break;
219*41edb306SCy Schubert 	}
220*41edb306SCy Schubert }
221