xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rpcprint.c (revision 8b80e8cb6855118d46f605e91b5ed4ce83417395)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1991-2001, 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <string.h>
30 #include <sys/types.h>
31 #include <sys/tiuser.h>
32 #include <rpc/types.h>
33 #include <rpc/xdr.h>
34 #include <rpc/auth.h>
35 #include <rpc/clnt.h>
36 #include <rpc/rpc_msg.h>
37 #include "snoop.h"
38 
39 #define	RPC_TRANSIENT_START	0x40000000
40 #define	RPC_TRANSIENT_END	0x5fffffff
41 
42 int rpcsec_gss_control_proc(int type, int flags, int xid);
43 
44 int rpcsec_gss_pre_proto(int type, int flags, int xid,
45 				int prog, int vers, int proc);
46 
47 void rpcsec_gss_post_proto(int flags, int xid);
48 
49 void
50 protoprint(flags, type, xid, prog, vers, proc, data, len)
51 	ulong_t xid;
52 	int flags, type, prog, vers, proc;
53 	char *data;
54 	int len;
55 {
56 	char *name;
57 	void (*interpreter)(int, int, int, int, int, char *, int);
58 
59 	switch (prog) {
60 	case 100000:	interpreter = interpret_pmap;		break;
61 	case 100001:	interpreter = interpret_rstat;		break;
62 	case 100003:	interpreter = interpret_nfs;		break;
63 	case 100004:	interpreter = interpret_nis;		break;
64 	case 100005:	interpreter = interpret_mount;		break;
65 	case 100007:	interpreter = interpret_nisbind;	break;
66 	case 100011:	interpreter = interpret_rquota;		break;
67 	case 100021:	interpreter = interpret_nlm;		break;
68 	case 100026:	interpreter = interpret_bparam;		break;
69 	case 100227:	interpreter = interpret_nfs_acl;	break;
70 	case 100300:	interpreter = interpret_nisplus;	break;
71 	case 100302:	interpreter = interpret_nisp_cb;	break;
72 	case 150006:	interpreter = interpret_solarnet_fw;	break;
73 	default:	interpreter = NULL;
74 	}
75 
76 	/*
77 	 * if rpc in transient range and proc is 0 or 1, then
78 	 * guess that it is the nfsv4 callback protocol
79 	 */
80 	if (prog >= RPC_TRANSIENT_START && prog <= RPC_TRANSIENT_END &&
81 	    (proc == 0 || proc == 1))
82 		interpreter = interpret_nfs4_cb;
83 
84 	/*
85 	 *  If the RPC header indicates it's using the RPCSEC_GSS_*
86 	 *  control procedure, print it.
87 	 */
88 	if (rpcsec_gss_control_proc(type, flags, xid)) {
89 			return;
90 	}
91 
92 	if (interpreter == NULL) {
93 		if (!(flags & F_SUM))
94 			return;
95 		name = nameof_prog(prog);
96 		if (*name == '?' || strcmp(name, "transient") == 0)
97 			return;
98 		(void) sprintf(get_sum_line(), "%s %c",
99 			name,
100 			type == CALL ? 'C' : 'R');
101 	} else {
102 		/* Pre-processing based on different RPCSEC_GSS services. */
103 		if (rpcsec_gss_pre_proto(type, flags, xid, prog, vers, proc))
104 			return;
105 
106 		(*interpreter) (flags, type, xid, vers, proc, data, len);
107 
108 		/* Post-processing based on different RPCSEC_GSS services. */
109 		rpcsec_gss_post_proto(flags, xid);
110 	}
111 }
112