xref: /netbsd-src/external/bsd/ipf/dist/lib/printaps.c (revision 07967fb18af5b87d2d477c5b3e1e438bf0c293fb)
1*07967fb1Smrg /*	$NetBSD: printaps.c,v 1.5 2018/02/04 08:19:42 mrg Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4bc4097aaSchristos  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
8bc4097aaSchristos  * Added redirect stuff and a variety of bug fixes. (mcn@EnGarde.com)
9bc4097aaSchristos  */
10bc4097aaSchristos 
11bc4097aaSchristos #include "ipf.h"
12bc4097aaSchristos #include "kmem.h"
13bc4097aaSchristos 
14bc4097aaSchristos 
15bc4097aaSchristos #if !defined(lint)
16*07967fb1Smrg static __attribute__((__used__)) const char rcsid[] = "@(#)Id: printaps.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $";
17bc4097aaSchristos #endif
18bc4097aaSchristos 
19bc4097aaSchristos 
20bc4097aaSchristos void
printaps(aps,opts,proto)21bc4097aaSchristos printaps(aps, opts, proto)
22bc4097aaSchristos 	ap_session_t *aps;
23bc4097aaSchristos 	int opts, proto;
24bc4097aaSchristos {
25bc4097aaSchristos 	ipsec_pxy_t ipsec;
26bc4097aaSchristos 	ap_session_t ap;
27bc4097aaSchristos 	ftpinfo_t ftp;
28bc4097aaSchristos 	aproxy_t apr;
29bc4097aaSchristos 	raudio_t ra;
30bc4097aaSchristos 
31bc4097aaSchristos 	if (kmemcpy((char *)&ap, (long)aps, sizeof(ap)))
32bc4097aaSchristos 		return;
33bc4097aaSchristos 	if (kmemcpy((char *)&apr, (long)ap.aps_apr, sizeof(apr)))
34bc4097aaSchristos 		return;
35bc4097aaSchristos 	PRINTF("\tproxy %s/%d use %d flags %x\n", apr.apr_label,
36bc4097aaSchristos 		apr.apr_p, apr.apr_ref, apr.apr_flags);
37bc4097aaSchristos #ifdef	USE_QUAD_T
3813885a66Sdarrenr 	PRINTF("\tbytes %"PRIu64" pkts %"PRIu64"",
39e45fceb3Smartin 		(uint64_t)ap.aps_bytes,
40e45fceb3Smartin 		(uint64_t)ap.aps_pkts);
41bc4097aaSchristos #else
4213885a66Sdarrenr 	PRINTF("\tbytes %lu pkts %lu", ap.aps_bytes, ap.aps_pkts);
43bc4097aaSchristos #endif
44bc4097aaSchristos 	PRINTF(" data %s\n", ap.aps_data ? "YES" : "NO");
45bc4097aaSchristos 	if ((proto == IPPROTO_TCP) && (opts & OPT_VERBOSE)) {
46bc4097aaSchristos 		PRINTF("\t\tstate[%u,%u], sel[%d,%d]\n",
47bc4097aaSchristos 			ap.aps_state[0], ap.aps_state[1],
48bc4097aaSchristos 			ap.aps_sel[0], ap.aps_sel[1]);
49bc4097aaSchristos #if (defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011)) || \
50bc4097aaSchristos     (__FreeBSD_version >= 300000) || defined(OpenBSD)
51bc4097aaSchristos 		PRINTF("\t\tseq: off %hd/%hd min %x/%x\n",
52bc4097aaSchristos 			ap.aps_seqoff[0], ap.aps_seqoff[1],
53bc4097aaSchristos 			ap.aps_seqmin[0], ap.aps_seqmin[1]);
54bc4097aaSchristos 		PRINTF("\t\tack: off %hd/%hd min %x/%x\n",
55bc4097aaSchristos 			ap.aps_ackoff[0], ap.aps_ackoff[1],
56bc4097aaSchristos 			ap.aps_ackmin[0], ap.aps_ackmin[1]);
57bc4097aaSchristos #else
58bc4097aaSchristos 		PRINTF("\t\tseq: off %hd/%hd min %lx/%lx\n",
59bc4097aaSchristos 			ap.aps_seqoff[0], ap.aps_seqoff[1],
60bc4097aaSchristos 			ap.aps_seqmin[0], ap.aps_seqmin[1]);
61bc4097aaSchristos 		PRINTF("\t\tack: off %hd/%hd min %lx/%lx\n",
62bc4097aaSchristos 			ap.aps_ackoff[0], ap.aps_ackoff[1],
63bc4097aaSchristos 			ap.aps_ackmin[0], ap.aps_ackmin[1]);
64bc4097aaSchristos #endif
65bc4097aaSchristos 	}
66bc4097aaSchristos 
67bc4097aaSchristos 	if (!strcmp(apr.apr_label, "raudio") && ap.aps_psiz == sizeof(ra)) {
68bc4097aaSchristos 		if (kmemcpy((char *)&ra, (long)ap.aps_data, sizeof(ra)))
69bc4097aaSchristos 			return;
70bc4097aaSchristos 		PRINTF("\tReal Audio Proxy:\n");
71bc4097aaSchristos 		PRINTF("\t\tSeen PNA: %d\tVersion: %d\tEOS: %d\n",
72bc4097aaSchristos 			ra.rap_seenpna, ra.rap_version, ra.rap_eos);
73bc4097aaSchristos 		PRINTF("\t\tMode: %#x\tSBF: %#x\n", ra.rap_mode, ra.rap_sbf);
74bc4097aaSchristos 		PRINTF("\t\tPorts:pl %hu, pr %hu, sr %hu\n",
75bc4097aaSchristos 			ra.rap_plport, ra.rap_prport, ra.rap_srport);
76bc4097aaSchristos 	} else if (!strcmp(apr.apr_label, "ftp") &&
77bc4097aaSchristos 		   (ap.aps_psiz == sizeof(ftp))) {
78bc4097aaSchristos 		if (kmemcpy((char *)&ftp, (long)ap.aps_data, sizeof(ftp)))
79bc4097aaSchristos 			return;
80bc4097aaSchristos 		PRINTF("\tFTP Proxy:\n");
81bc4097aaSchristos 		PRINTF("\t\tpassok: %d\n", ftp.ftp_passok);
82bc4097aaSchristos 		ftp.ftp_side[0].ftps_buf[FTP_BUFSZ - 1] = '\0';
83bc4097aaSchristos 		ftp.ftp_side[1].ftps_buf[FTP_BUFSZ - 1] = '\0';
84bc4097aaSchristos 		PRINTF("\tClient:\n");
85bc4097aaSchristos 		PRINTF("\t\tseq %x (ack %x) len %d junk %d cmds %d\n",
86bc4097aaSchristos 			ftp.ftp_side[0].ftps_seq[0],
87bc4097aaSchristos 			ftp.ftp_side[0].ftps_seq[1],
88bc4097aaSchristos 			ftp.ftp_side[0].ftps_len, ftp.ftp_side[0].ftps_junk,
89bc4097aaSchristos 			ftp.ftp_side[0].ftps_cmds);
90bc4097aaSchristos 		PRINTF("\t\tbuf [");
91bc4097aaSchristos 		printbuf(ftp.ftp_side[0].ftps_buf, FTP_BUFSZ, 1);
92bc4097aaSchristos 		PRINTF("]\n\tServer:\n");
93bc4097aaSchristos 		PRINTF("\t\tseq %x (ack %x) len %d junk %d cmds %d\n",
94bc4097aaSchristos 			ftp.ftp_side[1].ftps_seq[0],
95bc4097aaSchristos 			ftp.ftp_side[1].ftps_seq[1],
96bc4097aaSchristos 			ftp.ftp_side[1].ftps_len, ftp.ftp_side[1].ftps_junk,
97bc4097aaSchristos 			ftp.ftp_side[1].ftps_cmds);
98bc4097aaSchristos 		PRINTF("\t\tbuf [");
99bc4097aaSchristos 		printbuf(ftp.ftp_side[1].ftps_buf, FTP_BUFSZ, 1);
100bc4097aaSchristos 		PRINTF("]\n");
101bc4097aaSchristos 	} else if (!strcmp(apr.apr_label, "ipsec") &&
102bc4097aaSchristos 		   (ap.aps_psiz == sizeof(ipsec))) {
103bc4097aaSchristos 		if (kmemcpy((char *)&ipsec, (long)ap.aps_data, sizeof(ipsec)))
104bc4097aaSchristos 			return;
105bc4097aaSchristos 		PRINTF("\tIPSec Proxy:\n");
106bc4097aaSchristos 		PRINTF("\t\tICookie %08x%08x RCookie %08x%08x %s\n",
107bc4097aaSchristos 			(u_int)ntohl(ipsec.ipsc_icookie[0]),
108bc4097aaSchristos 			(u_int)ntohl(ipsec.ipsc_icookie[1]),
109bc4097aaSchristos 			(u_int)ntohl(ipsec.ipsc_rcookie[0]),
110bc4097aaSchristos 			(u_int)ntohl(ipsec.ipsc_rcookie[1]),
111bc4097aaSchristos 			ipsec.ipsc_rckset ? "(Set)" : "(Not set)");
112bc4097aaSchristos 	}
113bc4097aaSchristos }
114