Home | History | Annotate | Download | only in snoop
      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 (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 
     26 #include <string.h>
     27 #include <sys/types.h>
     28 #include <sys/tiuser.h>
     29 #include <rpc/types.h>
     30 #include <rpc/xdr.h>
     31 #include <rpc/auth.h>
     32 #include <rpc/clnt.h>
     33 #include <rpc/rpc_msg.h>
     34 #include "snoop.h"
     35 
     36 #define	RPC_TRANSIENT_START	0x40000000
     37 #define	RPC_TRANSIENT_END	0x5fffffff
     38 
     39 int rpcsec_gss_control_proc(int type, int flags, int xid);
     40 
     41 int rpcsec_gss_pre_proto(int type, int flags, int xid,
     42 				int prog, int vers, int proc);
     43 
     44 void rpcsec_gss_post_proto(int flags, int xid);
     45 
     46 void
     47 protoprint(flags, type, xid, prog, vers, proc, data, len)
     48 	ulong_t xid;
     49 	int flags, type, prog, vers, proc;
     50 	char *data;
     51 	int len;
     52 {
     53 	char *name;
     54 	void (*interpreter)(int, int, int, int, int, char *, int);
     55 
     56 	switch (prog) {
     57 	case 100000:	interpreter = interpret_pmap;		break;
     58 	case 100001:	interpreter = interpret_rstat;		break;
     59 	case 100003:	interpreter = interpret_nfs;		break;
     60 	case 100004:	interpreter = interpret_nis;		break;
     61 	case 100005:	interpreter = interpret_mount;		break;
     62 	case 100007:	interpreter = interpret_nisbind;	break;
     63 	case 100011:	interpreter = interpret_rquota;		break;
     64 	case 100021:	interpreter = interpret_nlm;		break;
     65 	case 100026:	interpreter = interpret_bparam;		break;
     66 	case 100227:	interpreter = interpret_nfs_acl;	break;
     67 	case 100300:	interpreter = interpret_nisplus;	break;
     68 	case 100302:	interpreter = interpret_nisp_cb;	break;
     69 	case 104000:	interpreter = interpret_pnfsctlmds;	break;
     70 	case 104001:	interpreter = interpret_pnfsctlds;	break;
     71 	case 104002:	interpreter = interpret_pnfsctlmv;	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