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