xref: /titanic_50/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rpcprint.c (revision 36e852a172cba914383d7341c988128b2c667fbd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*36e852a1SRaja Andra  * Common Development and Distribution License (the "License").
6*36e852a1SRaja Andra  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*36e852a1SRaja Andra  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <string.h>
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
297c478bd9Sstevel@tonic-gate #include <rpc/types.h>
307c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
317c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
327c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
337c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
347c478bd9Sstevel@tonic-gate #include "snoop.h"
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #define	RPC_TRANSIENT_START	0x40000000
377c478bd9Sstevel@tonic-gate #define	RPC_TRANSIENT_END	0x5fffffff
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate int rpcsec_gss_control_proc(int type, int flags, int xid);
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate int rpcsec_gss_pre_proto(int type, int flags, int xid,
427c478bd9Sstevel@tonic-gate 				int prog, int vers, int proc);
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate void rpcsec_gss_post_proto(int flags, int xid);
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate void
protoprint(flags,type,xid,prog,vers,proc,data,len)477c478bd9Sstevel@tonic-gate protoprint(flags, type, xid, prog, vers, proc, data, len)
487c478bd9Sstevel@tonic-gate 	ulong_t xid;
497c478bd9Sstevel@tonic-gate 	int flags, type, prog, vers, proc;
507c478bd9Sstevel@tonic-gate 	char *data;
517c478bd9Sstevel@tonic-gate 	int len;
527c478bd9Sstevel@tonic-gate {
537c478bd9Sstevel@tonic-gate 	char *name;
547c478bd9Sstevel@tonic-gate 	void (*interpreter)(int, int, int, int, int, char *, int);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 	switch (prog) {
577c478bd9Sstevel@tonic-gate 	case 100000:	interpreter = interpret_pmap;		break;
587c478bd9Sstevel@tonic-gate 	case 100001:	interpreter = interpret_rstat;		break;
597c478bd9Sstevel@tonic-gate 	case 100003:	interpreter = interpret_nfs;		break;
607c478bd9Sstevel@tonic-gate 	case 100004:	interpreter = interpret_nis;		break;
617c478bd9Sstevel@tonic-gate 	case 100005:	interpreter = interpret_mount;		break;
627c478bd9Sstevel@tonic-gate 	case 100007:	interpreter = interpret_nisbind;	break;
637c478bd9Sstevel@tonic-gate 	case 100011:	interpreter = interpret_rquota;		break;
647c478bd9Sstevel@tonic-gate 	case 100021:	interpreter = interpret_nlm;		break;
657c478bd9Sstevel@tonic-gate 	case 100026:	interpreter = interpret_bparam;		break;
667c478bd9Sstevel@tonic-gate 	case 100227:	interpreter = interpret_nfs_acl;	break;
677c478bd9Sstevel@tonic-gate 	case 150006:	interpreter = interpret_solarnet_fw;	break;
687c478bd9Sstevel@tonic-gate 	default:	interpreter = NULL;
697c478bd9Sstevel@tonic-gate 	}
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	/*
727c478bd9Sstevel@tonic-gate 	 * if rpc in transient range and proc is 0 or 1, then
737c478bd9Sstevel@tonic-gate 	 * guess that it is the nfsv4 callback protocol
747c478bd9Sstevel@tonic-gate 	 */
757c478bd9Sstevel@tonic-gate 	if (prog >= RPC_TRANSIENT_START && prog <= RPC_TRANSIENT_END &&
767c478bd9Sstevel@tonic-gate 	    (proc == 0 || proc == 1))
777c478bd9Sstevel@tonic-gate 		interpreter = interpret_nfs4_cb;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	/*
807c478bd9Sstevel@tonic-gate 	 *  If the RPC header indicates it's using the RPCSEC_GSS_*
817c478bd9Sstevel@tonic-gate 	 *  control procedure, print it.
827c478bd9Sstevel@tonic-gate 	 */
837c478bd9Sstevel@tonic-gate 	if (rpcsec_gss_control_proc(type, flags, xid)) {
847c478bd9Sstevel@tonic-gate 			return;
857c478bd9Sstevel@tonic-gate 	}
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	if (interpreter == NULL) {
887c478bd9Sstevel@tonic-gate 		if (!(flags & F_SUM))
897c478bd9Sstevel@tonic-gate 			return;
907c478bd9Sstevel@tonic-gate 		name = nameof_prog(prog);
917c478bd9Sstevel@tonic-gate 		if (*name == '?' || strcmp(name, "transient") == 0)
927c478bd9Sstevel@tonic-gate 			return;
937c478bd9Sstevel@tonic-gate 		(void) sprintf(get_sum_line(), "%s %c",
947c478bd9Sstevel@tonic-gate 			name,
957c478bd9Sstevel@tonic-gate 			type == CALL ? 'C' : 'R');
967c478bd9Sstevel@tonic-gate 	} else {
977c478bd9Sstevel@tonic-gate 		/* Pre-processing based on different RPCSEC_GSS services. */
987c478bd9Sstevel@tonic-gate 		if (rpcsec_gss_pre_proto(type, flags, xid, prog, vers, proc))
997c478bd9Sstevel@tonic-gate 			return;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 		(*interpreter) (flags, type, xid, vers, proc, data, len);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 		/* Post-processing based on different RPCSEC_GSS services. */
1047c478bd9Sstevel@tonic-gate 		rpcsec_gss_post_proto(flags, xid);
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate }
107