xref: /freebsd/sbin/ipf/libipf/printaps.c (revision 19fae0f66023a97a9b464b3beeeabb2081f575b3)
1 /*	$FreeBSD$	*/
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 
11 #include "ipf.h"
12 #include "kmem.h"
13 
14 
15 #if !defined(lint)
16 static const char rcsid[] = "@(#)$Id$";
17 #endif
18 
19 
20 void
21 printaps(ap_session_t *aps, int opts, int proto)
22 {
23 	ipsec_pxy_t ipsec;
24 	ap_session_t ap;
25 	ftpinfo_t ftp;
26 	aproxy_t apr;
27 	raudio_t ra;
28 
29 	if (kmemcpy((char *)&ap, (long)aps, sizeof(ap)))
30 		return;
31 	if (kmemcpy((char *)&apr, (long)ap.aps_apr, sizeof(apr)))
32 		return;
33 	PRINTF("\tproxy %s/%d use %d flags %x\n", apr.apr_label,
34 		apr.apr_p, apr.apr_ref, apr.apr_flags);
35 #ifdef	USE_QUAD_T
36 	PRINTF("\tbytes %"PRIu64" pkts %"PRIu64"",
37 		(unsigned long long)ap.aps_bytes,
38 		(unsigned long long)ap.aps_pkts);
39 #else
40 	PRINTF("\tbytes %lu pkts %lu", ap.aps_bytes, ap.aps_pkts);
41 #endif
42 	PRINTF(" data %s\n", ap.aps_data ? "YES" : "NO");
43 	if ((proto == IPPROTO_TCP) && (opts & OPT_VERBOSE)) {
44 		PRINTF("\t\tstate[%u,%u], sel[%d,%d]\n",
45 			ap.aps_state[0], ap.aps_state[1],
46 			ap.aps_sel[0], ap.aps_sel[1]);
47 #if (defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011)) || \
48     defined(__FreeBSD__)
49 		PRINTF("\t\tseq: off %hd/%hd min %x/%x\n",
50 			ap.aps_seqoff[0], ap.aps_seqoff[1],
51 			ap.aps_seqmin[0], ap.aps_seqmin[1]);
52 		PRINTF("\t\tack: off %hd/%hd min %x/%x\n",
53 			ap.aps_ackoff[0], ap.aps_ackoff[1],
54 			ap.aps_ackmin[0], ap.aps_ackmin[1]);
55 #else
56 		PRINTF("\t\tseq: off %hd/%hd min %lx/%lx\n",
57 			ap.aps_seqoff[0], ap.aps_seqoff[1],
58 			ap.aps_seqmin[0], ap.aps_seqmin[1]);
59 		PRINTF("\t\tack: off %hd/%hd min %lx/%lx\n",
60 			ap.aps_ackoff[0], ap.aps_ackoff[1],
61 			ap.aps_ackmin[0], ap.aps_ackmin[1]);
62 #endif
63 	}
64 
65 	if (!strcmp(apr.apr_label, "raudio") && ap.aps_psiz == sizeof(ra)) {
66 		if (kmemcpy((char *)&ra, (long)ap.aps_data, sizeof(ra)))
67 			return;
68 		PRINTF("\tReal Audio Proxy:\n");
69 		PRINTF("\t\tSeen PNA: %d\tVersion: %d\tEOS: %d\n",
70 			ra.rap_seenpna, ra.rap_version, ra.rap_eos);
71 		PRINTF("\t\tMode: %#x\tSBF: %#x\n", ra.rap_mode, ra.rap_sbf);
72 		PRINTF("\t\tPorts:pl %hu, pr %hu, sr %hu\n",
73 			ra.rap_plport, ra.rap_prport, ra.rap_srport);
74 	} else if (!strcmp(apr.apr_label, "ftp") &&
75 		   (ap.aps_psiz == sizeof(ftp))) {
76 		if (kmemcpy((char *)&ftp, (long)ap.aps_data, sizeof(ftp)))
77 			return;
78 		PRINTF("\tFTP Proxy:\n");
79 		PRINTF("\t\tpassok: %d\n", ftp.ftp_passok);
80 		ftp.ftp_side[0].ftps_buf[FTP_BUFSZ - 1] = '\0';
81 		ftp.ftp_side[1].ftps_buf[FTP_BUFSZ - 1] = '\0';
82 		PRINTF("\tClient:\n");
83 		PRINTF("\t\tseq %x (ack %x) len %d junk %d cmds %d\n",
84 			ftp.ftp_side[0].ftps_seq[0],
85 			ftp.ftp_side[0].ftps_seq[1],
86 			ftp.ftp_side[0].ftps_len, ftp.ftp_side[0].ftps_junk,
87 			ftp.ftp_side[0].ftps_cmds);
88 		PRINTF("\t\tbuf [");
89 		printbuf(ftp.ftp_side[0].ftps_buf, FTP_BUFSZ, 1);
90 		PRINTF("]\n\tServer:\n");
91 		PRINTF("\t\tseq %x (ack %x) len %d junk %d cmds %d\n",
92 			ftp.ftp_side[1].ftps_seq[0],
93 			ftp.ftp_side[1].ftps_seq[1],
94 			ftp.ftp_side[1].ftps_len, ftp.ftp_side[1].ftps_junk,
95 			ftp.ftp_side[1].ftps_cmds);
96 		PRINTF("\t\tbuf [");
97 		printbuf(ftp.ftp_side[1].ftps_buf, FTP_BUFSZ, 1);
98 		PRINTF("]\n");
99 	} else if (!strcmp(apr.apr_label, "ipsec") &&
100 		   (ap.aps_psiz == sizeof(ipsec))) {
101 		if (kmemcpy((char *)&ipsec, (long)ap.aps_data, sizeof(ipsec)))
102 			return;
103 		PRINTF("\tIPSec Proxy:\n");
104 		PRINTF("\t\tICookie %08x%08x RCookie %08x%08x %s\n",
105 			(u_int)ntohl(ipsec.ipsc_icookie[0]),
106 			(u_int)ntohl(ipsec.ipsc_icookie[1]),
107 			(u_int)ntohl(ipsec.ipsc_rcookie[0]),
108 			(u_int)ntohl(ipsec.ipsc_rcookie[1]),
109 			ipsec.ipsc_rckset ? "(Set)" : "(Not set)");
110 	}
111 }
112