xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rpcprint.c (revision 11262:b7ebfbf2359e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*11262SRajagopal.Andra@Sun.COM  * Common Development and Distribution License (the "License").
6*11262SRajagopal.Andra@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11262SRajagopal.Andra@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <string.h>
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/tiuser.h>
290Sstevel@tonic-gate #include <rpc/types.h>
300Sstevel@tonic-gate #include <rpc/xdr.h>
310Sstevel@tonic-gate #include <rpc/auth.h>
320Sstevel@tonic-gate #include <rpc/clnt.h>
330Sstevel@tonic-gate #include <rpc/rpc_msg.h>
340Sstevel@tonic-gate #include "snoop.h"
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #define	RPC_TRANSIENT_START	0x40000000
370Sstevel@tonic-gate #define	RPC_TRANSIENT_END	0x5fffffff
380Sstevel@tonic-gate 
390Sstevel@tonic-gate int rpcsec_gss_control_proc(int type, int flags, int xid);
400Sstevel@tonic-gate 
410Sstevel@tonic-gate int rpcsec_gss_pre_proto(int type, int flags, int xid,
420Sstevel@tonic-gate 				int prog, int vers, int proc);
430Sstevel@tonic-gate 
440Sstevel@tonic-gate void rpcsec_gss_post_proto(int flags, int xid);
450Sstevel@tonic-gate 
460Sstevel@tonic-gate void
protoprint(flags,type,xid,prog,vers,proc,data,len)470Sstevel@tonic-gate protoprint(flags, type, xid, prog, vers, proc, data, len)
480Sstevel@tonic-gate 	ulong_t xid;
490Sstevel@tonic-gate 	int flags, type, prog, vers, proc;
500Sstevel@tonic-gate 	char *data;
510Sstevel@tonic-gate 	int len;
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	char *name;
540Sstevel@tonic-gate 	void (*interpreter)(int, int, int, int, int, char *, int);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	switch (prog) {
570Sstevel@tonic-gate 	case 100000:	interpreter = interpret_pmap;		break;
580Sstevel@tonic-gate 	case 100001:	interpreter = interpret_rstat;		break;
590Sstevel@tonic-gate 	case 100003:	interpreter = interpret_nfs;		break;
600Sstevel@tonic-gate 	case 100004:	interpreter = interpret_nis;		break;
610Sstevel@tonic-gate 	case 100005:	interpreter = interpret_mount;		break;
620Sstevel@tonic-gate 	case 100007:	interpreter = interpret_nisbind;	break;
630Sstevel@tonic-gate 	case 100011:	interpreter = interpret_rquota;		break;
640Sstevel@tonic-gate 	case 100021:	interpreter = interpret_nlm;		break;
650Sstevel@tonic-gate 	case 100026:	interpreter = interpret_bparam;		break;
660Sstevel@tonic-gate 	case 100227:	interpreter = interpret_nfs_acl;	break;
670Sstevel@tonic-gate 	case 150006:	interpreter = interpret_solarnet_fw;	break;
680Sstevel@tonic-gate 	default:	interpreter = NULL;
690Sstevel@tonic-gate 	}
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	/*
720Sstevel@tonic-gate 	 * if rpc in transient range and proc is 0 or 1, then
730Sstevel@tonic-gate 	 * guess that it is the nfsv4 callback protocol
740Sstevel@tonic-gate 	 */
750Sstevel@tonic-gate 	if (prog >= RPC_TRANSIENT_START && prog <= RPC_TRANSIENT_END &&
760Sstevel@tonic-gate 	    (proc == 0 || proc == 1))
770Sstevel@tonic-gate 		interpreter = interpret_nfs4_cb;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	/*
800Sstevel@tonic-gate 	 *  If the RPC header indicates it's using the RPCSEC_GSS_*
810Sstevel@tonic-gate 	 *  control procedure, print it.
820Sstevel@tonic-gate 	 */
830Sstevel@tonic-gate 	if (rpcsec_gss_control_proc(type, flags, xid)) {
840Sstevel@tonic-gate 			return;
850Sstevel@tonic-gate 	}
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	if (interpreter == NULL) {
880Sstevel@tonic-gate 		if (!(flags & F_SUM))
890Sstevel@tonic-gate 			return;
900Sstevel@tonic-gate 		name = nameof_prog(prog);
910Sstevel@tonic-gate 		if (*name == '?' || strcmp(name, "transient") == 0)
920Sstevel@tonic-gate 			return;
930Sstevel@tonic-gate 		(void) sprintf(get_sum_line(), "%s %c",
940Sstevel@tonic-gate 			name,
950Sstevel@tonic-gate 			type == CALL ? 'C' : 'R');
960Sstevel@tonic-gate 	} else {
970Sstevel@tonic-gate 		/* Pre-processing based on different RPCSEC_GSS services. */
980Sstevel@tonic-gate 		if (rpcsec_gss_pre_proto(type, flags, xid, prog, vers, proc))
990Sstevel@tonic-gate 			return;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 		(*interpreter) (flags, type, xid, vers, proc, data, len);
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 		/* Post-processing based on different RPCSEC_GSS services. */
1040Sstevel@tonic-gate 		rpcsec_gss_post_proto(flags, xid);
1050Sstevel@tonic-gate 	}
1060Sstevel@tonic-gate }
107