xref: /freebsd/sbin/ipf/libipf/printaps.c (revision 51e16cb8fc536913f490ac6bc9c17e92ebd0411b)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  *
741edb306SCy Schubert  * Added redirect stuff and a variety of bug fixes. (mcn@EnGarde.com)
841edb306SCy Schubert  */
941edb306SCy Schubert 
1041edb306SCy Schubert #include "ipf.h"
1141edb306SCy Schubert #include "kmem.h"
1241edb306SCy Schubert 
1341edb306SCy Schubert 
1441edb306SCy Schubert 
1541edb306SCy Schubert 
1641edb306SCy Schubert void
printaps(ap_session_t * aps,int opts,int proto)17*efeb8bffSCy Schubert printaps(ap_session_t *aps, int opts, int proto)
1841edb306SCy Schubert {
1941edb306SCy Schubert 	ipsec_pxy_t ipsec;
2041edb306SCy Schubert 	ap_session_t ap;
2141edb306SCy Schubert 	ftpinfo_t ftp;
2241edb306SCy Schubert 	aproxy_t apr;
2341edb306SCy Schubert 	raudio_t ra;
2441edb306SCy Schubert 
2541edb306SCy Schubert 	if (kmemcpy((char *)&ap, (long)aps, sizeof(ap)))
2641edb306SCy Schubert 		return;
2741edb306SCy Schubert 	if (kmemcpy((char *)&apr, (long)ap.aps_apr, sizeof(apr)))
2841edb306SCy Schubert 		return;
2941edb306SCy Schubert 	PRINTF("\tproxy %s/%d use %d flags %x\n", apr.apr_label,
3041edb306SCy Schubert 		apr.apr_p, apr.apr_ref, apr.apr_flags);
3141edb306SCy Schubert #ifdef	USE_QUAD_T
3241edb306SCy Schubert 	PRINTF("\tbytes %"PRIu64" pkts %"PRIu64"",
3341edb306SCy Schubert 		(unsigned long long)ap.aps_bytes,
3441edb306SCy Schubert 		(unsigned long long)ap.aps_pkts);
3541edb306SCy Schubert #else
3641edb306SCy Schubert 	PRINTF("\tbytes %lu pkts %lu", ap.aps_bytes, ap.aps_pkts);
3741edb306SCy Schubert #endif
3841edb306SCy Schubert 	PRINTF(" data %s\n", ap.aps_data ? "YES" : "NO");
3941edb306SCy Schubert 	if ((proto == IPPROTO_TCP) && (opts & OPT_VERBOSE)) {
4041edb306SCy Schubert 		PRINTF("\t\tstate[%u,%u], sel[%d,%d]\n",
4141edb306SCy Schubert 			ap.aps_state[0], ap.aps_state[1],
4241edb306SCy Schubert 			ap.aps_sel[0], ap.aps_sel[1]);
4341edb306SCy Schubert #if (defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011)) || \
4441edb306SCy Schubert     defined(__FreeBSD__)
4541edb306SCy Schubert 		PRINTF("\t\tseq: off %hd/%hd min %x/%x\n",
4641edb306SCy Schubert 			ap.aps_seqoff[0], ap.aps_seqoff[1],
4741edb306SCy Schubert 			ap.aps_seqmin[0], ap.aps_seqmin[1]);
4841edb306SCy Schubert 		PRINTF("\t\tack: off %hd/%hd min %x/%x\n",
4941edb306SCy Schubert 			ap.aps_ackoff[0], ap.aps_ackoff[1],
5041edb306SCy Schubert 			ap.aps_ackmin[0], ap.aps_ackmin[1]);
5141edb306SCy Schubert #else
5241edb306SCy Schubert 		PRINTF("\t\tseq: off %hd/%hd min %lx/%lx\n",
5341edb306SCy Schubert 			ap.aps_seqoff[0], ap.aps_seqoff[1],
5441edb306SCy Schubert 			ap.aps_seqmin[0], ap.aps_seqmin[1]);
5541edb306SCy Schubert 		PRINTF("\t\tack: off %hd/%hd min %lx/%lx\n",
5641edb306SCy Schubert 			ap.aps_ackoff[0], ap.aps_ackoff[1],
5741edb306SCy Schubert 			ap.aps_ackmin[0], ap.aps_ackmin[1]);
5841edb306SCy Schubert #endif
5941edb306SCy Schubert 	}
6041edb306SCy Schubert 
6141edb306SCy Schubert 	if (!strcmp(apr.apr_label, "raudio") && ap.aps_psiz == sizeof(ra)) {
6241edb306SCy Schubert 		if (kmemcpy((char *)&ra, (long)ap.aps_data, sizeof(ra)))
6341edb306SCy Schubert 			return;
6441edb306SCy Schubert 		PRINTF("\tReal Audio Proxy:\n");
6541edb306SCy Schubert 		PRINTF("\t\tSeen PNA: %d\tVersion: %d\tEOS: %d\n",
6641edb306SCy Schubert 			ra.rap_seenpna, ra.rap_version, ra.rap_eos);
6741edb306SCy Schubert 		PRINTF("\t\tMode: %#x\tSBF: %#x\n", ra.rap_mode, ra.rap_sbf);
6841edb306SCy Schubert 		PRINTF("\t\tPorts:pl %hu, pr %hu, sr %hu\n",
6941edb306SCy Schubert 			ra.rap_plport, ra.rap_prport, ra.rap_srport);
7041edb306SCy Schubert 	} else if (!strcmp(apr.apr_label, "ftp") &&
7141edb306SCy Schubert 		   (ap.aps_psiz == sizeof(ftp))) {
7241edb306SCy Schubert 		if (kmemcpy((char *)&ftp, (long)ap.aps_data, sizeof(ftp)))
7341edb306SCy Schubert 			return;
7441edb306SCy Schubert 		PRINTF("\tFTP Proxy:\n");
7541edb306SCy Schubert 		PRINTF("\t\tpassok: %d\n", ftp.ftp_passok);
7641edb306SCy Schubert 		ftp.ftp_side[0].ftps_buf[FTP_BUFSZ - 1] = '\0';
7741edb306SCy Schubert 		ftp.ftp_side[1].ftps_buf[FTP_BUFSZ - 1] = '\0';
7841edb306SCy Schubert 		PRINTF("\tClient:\n");
7941edb306SCy Schubert 		PRINTF("\t\tseq %x (ack %x) len %d junk %d cmds %d\n",
8041edb306SCy Schubert 			ftp.ftp_side[0].ftps_seq[0],
8141edb306SCy Schubert 			ftp.ftp_side[0].ftps_seq[1],
8241edb306SCy Schubert 			ftp.ftp_side[0].ftps_len, ftp.ftp_side[0].ftps_junk,
8341edb306SCy Schubert 			ftp.ftp_side[0].ftps_cmds);
8441edb306SCy Schubert 		PRINTF("\t\tbuf [");
8541edb306SCy Schubert 		printbuf(ftp.ftp_side[0].ftps_buf, FTP_BUFSZ, 1);
8641edb306SCy Schubert 		PRINTF("]\n\tServer:\n");
8741edb306SCy Schubert 		PRINTF("\t\tseq %x (ack %x) len %d junk %d cmds %d\n",
8841edb306SCy Schubert 			ftp.ftp_side[1].ftps_seq[0],
8941edb306SCy Schubert 			ftp.ftp_side[1].ftps_seq[1],
9041edb306SCy Schubert 			ftp.ftp_side[1].ftps_len, ftp.ftp_side[1].ftps_junk,
9141edb306SCy Schubert 			ftp.ftp_side[1].ftps_cmds);
9241edb306SCy Schubert 		PRINTF("\t\tbuf [");
9341edb306SCy Schubert 		printbuf(ftp.ftp_side[1].ftps_buf, FTP_BUFSZ, 1);
9441edb306SCy Schubert 		PRINTF("]\n");
9541edb306SCy Schubert 	} else if (!strcmp(apr.apr_label, "ipsec") &&
9641edb306SCy Schubert 		   (ap.aps_psiz == sizeof(ipsec))) {
9741edb306SCy Schubert 		if (kmemcpy((char *)&ipsec, (long)ap.aps_data, sizeof(ipsec)))
9841edb306SCy Schubert 			return;
9941edb306SCy Schubert 		PRINTF("\tIPSec Proxy:\n");
10041edb306SCy Schubert 		PRINTF("\t\tICookie %08x%08x RCookie %08x%08x %s\n",
10141edb306SCy Schubert 			(u_int)ntohl(ipsec.ipsc_icookie[0]),
10241edb306SCy Schubert 			(u_int)ntohl(ipsec.ipsc_icookie[1]),
10341edb306SCy Schubert 			(u_int)ntohl(ipsec.ipsc_rcookie[0]),
10441edb306SCy Schubert 			(u_int)ntohl(ipsec.ipsc_rcookie[1]),
10541edb306SCy Schubert 			ipsec.ipsc_rckset ? "(Set)" : "(Not set)");
10641edb306SCy Schubert 	}
10741edb306SCy Schubert }
108