xref: /titanic_50/usr/src/cmd/rpcbind/rpcb_stat.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * rpcb_stat.c
24*7c478bd9Sstevel@tonic-gate  * Allows for gathering of statistics
25*7c478bd9Sstevel@tonic-gate  *
26*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1990 by Sun Microsystems, Inc.
27*7c478bd9Sstevel@tonic-gate  */
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <netconfig.h>
31*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
32*7c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
34*7c478bd9Sstevel@tonic-gate #ifdef PORTMAP
35*7c478bd9Sstevel@tonic-gate #include <rpc/pmap_prot.h>
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
38*7c478bd9Sstevel@tonic-gate #include "rpcbind.h"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate static rpcb_stat_byvers inf;
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate void
43*7c478bd9Sstevel@tonic-gate rpcbs_init()
44*7c478bd9Sstevel@tonic-gate {
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate }
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate void
49*7c478bd9Sstevel@tonic-gate rpcbs_procinfo(rtype, proc)
50*7c478bd9Sstevel@tonic-gate 	u_long rtype;
51*7c478bd9Sstevel@tonic-gate 	u_long proc;
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 	switch (rtype + 2) {
54*7c478bd9Sstevel@tonic-gate #ifdef PORTMAP
55*7c478bd9Sstevel@tonic-gate 	case PMAPVERS:		/* version 2 */
56*7c478bd9Sstevel@tonic-gate 		if (proc > rpcb_highproc_2)
57*7c478bd9Sstevel@tonic-gate 			return;
58*7c478bd9Sstevel@tonic-gate 		break;
59*7c478bd9Sstevel@tonic-gate #endif
60*7c478bd9Sstevel@tonic-gate 	case RPCBVERS:		/* version 3 */
61*7c478bd9Sstevel@tonic-gate 		if (proc > rpcb_highproc_3)
62*7c478bd9Sstevel@tonic-gate 			return;
63*7c478bd9Sstevel@tonic-gate 		break;
64*7c478bd9Sstevel@tonic-gate 	case RPCBVERS4:		/* version 4 */
65*7c478bd9Sstevel@tonic-gate 		if (proc > rpcb_highproc_4)
66*7c478bd9Sstevel@tonic-gate 			return;
67*7c478bd9Sstevel@tonic-gate 		break;
68*7c478bd9Sstevel@tonic-gate 	default: return;
69*7c478bd9Sstevel@tonic-gate 	}
70*7c478bd9Sstevel@tonic-gate 	inf[rtype].info[proc]++;
71*7c478bd9Sstevel@tonic-gate 	return;
72*7c478bd9Sstevel@tonic-gate }
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate void
75*7c478bd9Sstevel@tonic-gate rpcbs_set(rtype, success)
76*7c478bd9Sstevel@tonic-gate 	u_long rtype;
77*7c478bd9Sstevel@tonic-gate 	bool_t success;
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
80*7c478bd9Sstevel@tonic-gate 		return;
81*7c478bd9Sstevel@tonic-gate 	inf[rtype].setinfo++;
82*7c478bd9Sstevel@tonic-gate 	return;
83*7c478bd9Sstevel@tonic-gate }
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate void
86*7c478bd9Sstevel@tonic-gate rpcbs_unset(rtype, success)
87*7c478bd9Sstevel@tonic-gate 	u_long rtype;
88*7c478bd9Sstevel@tonic-gate 	bool_t success;
89*7c478bd9Sstevel@tonic-gate {
90*7c478bd9Sstevel@tonic-gate 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
91*7c478bd9Sstevel@tonic-gate 		return;
92*7c478bd9Sstevel@tonic-gate 	inf[rtype].unsetinfo++;
93*7c478bd9Sstevel@tonic-gate 	return;
94*7c478bd9Sstevel@tonic-gate }
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate void
97*7c478bd9Sstevel@tonic-gate rpcbs_getaddr(rtype, prog, vers, netid, uaddr)
98*7c478bd9Sstevel@tonic-gate 	u_long rtype;
99*7c478bd9Sstevel@tonic-gate 	u_long prog;
100*7c478bd9Sstevel@tonic-gate 	u_long vers;
101*7c478bd9Sstevel@tonic-gate 	char *netid;
102*7c478bd9Sstevel@tonic-gate 	char *uaddr;
103*7c478bd9Sstevel@tonic-gate {
104*7c478bd9Sstevel@tonic-gate 	rpcbs_addrlist *al;
105*7c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	if (rtype >= RPCBVERS_STAT)
108*7c478bd9Sstevel@tonic-gate 		return;
109*7c478bd9Sstevel@tonic-gate 	for (al = inf[rtype].addrinfo; al; al = al->next) {
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 		if(al->netid == NULL)
112*7c478bd9Sstevel@tonic-gate 			return;
113*7c478bd9Sstevel@tonic-gate 		if ((al->prog == prog) && (al->vers == vers) &&
114*7c478bd9Sstevel@tonic-gate 		    (strcmp(al->netid, netid) == 0)) {
115*7c478bd9Sstevel@tonic-gate 			if ((uaddr == NULL) || (uaddr[0] == NULL))
116*7c478bd9Sstevel@tonic-gate 				al->failure++;
117*7c478bd9Sstevel@tonic-gate 			else
118*7c478bd9Sstevel@tonic-gate 				al->success++;
119*7c478bd9Sstevel@tonic-gate 			return;
120*7c478bd9Sstevel@tonic-gate 		}
121*7c478bd9Sstevel@tonic-gate 	}
122*7c478bd9Sstevel@tonic-gate 	nconf = rpcbind_get_conf(netid);
123*7c478bd9Sstevel@tonic-gate 	if (nconf == NULL) {
124*7c478bd9Sstevel@tonic-gate 		return;
125*7c478bd9Sstevel@tonic-gate 	}
126*7c478bd9Sstevel@tonic-gate 	al = (rpcbs_addrlist *) malloc(sizeof (rpcbs_addrlist));
127*7c478bd9Sstevel@tonic-gate 	if (al == NULL) {
128*7c478bd9Sstevel@tonic-gate 		return;
129*7c478bd9Sstevel@tonic-gate 	}
130*7c478bd9Sstevel@tonic-gate 	al->prog = prog;
131*7c478bd9Sstevel@tonic-gate 	al->vers = vers;
132*7c478bd9Sstevel@tonic-gate 	al->netid = nconf->nc_netid;
133*7c478bd9Sstevel@tonic-gate 	if ((uaddr == NULL) || (uaddr[0] == NULL)) {
134*7c478bd9Sstevel@tonic-gate 		al->failure = 1;
135*7c478bd9Sstevel@tonic-gate 		al->success = 0;
136*7c478bd9Sstevel@tonic-gate 	} else {
137*7c478bd9Sstevel@tonic-gate 		al->failure = 0;
138*7c478bd9Sstevel@tonic-gate 		al->success = 1;
139*7c478bd9Sstevel@tonic-gate 	}
140*7c478bd9Sstevel@tonic-gate 	al->next = inf[rtype].addrinfo;
141*7c478bd9Sstevel@tonic-gate 	inf[rtype].addrinfo = al;
142*7c478bd9Sstevel@tonic-gate }
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate void
145*7c478bd9Sstevel@tonic-gate rpcbs_rmtcall(rtype, rpcbproc, prog, vers, proc, netid, rbl)
146*7c478bd9Sstevel@tonic-gate 	u_long rtype;
147*7c478bd9Sstevel@tonic-gate 	u_long rpcbproc; /* rpcbind proc number on which this was called */
148*7c478bd9Sstevel@tonic-gate 	u_long prog;
149*7c478bd9Sstevel@tonic-gate 	u_long vers;
150*7c478bd9Sstevel@tonic-gate 	u_long proc;
151*7c478bd9Sstevel@tonic-gate 	char *netid;
152*7c478bd9Sstevel@tonic-gate 	rpcblist_ptr rbl;
153*7c478bd9Sstevel@tonic-gate {
154*7c478bd9Sstevel@tonic-gate 	rpcbs_rmtcalllist *rl;
155*7c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 	if (rtype > RPCBVERS_STAT)
158*7c478bd9Sstevel@tonic-gate 		return;
159*7c478bd9Sstevel@tonic-gate 	for (rl = inf[rtype].rmtinfo; rl; rl = rl->next) {
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 		if(rl->netid == NULL)
162*7c478bd9Sstevel@tonic-gate 			return;
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 		if ((rl->prog == prog) && (rl->vers == vers) &&
165*7c478bd9Sstevel@tonic-gate 		    (rl->proc == proc) &&
166*7c478bd9Sstevel@tonic-gate 		    (strcmp(rl->netid, netid) == 0)) {
167*7c478bd9Sstevel@tonic-gate 			if ((rbl == NULL) ||
168*7c478bd9Sstevel@tonic-gate 			    (rbl->rpcb_map.r_vers != vers))
169*7c478bd9Sstevel@tonic-gate 				rl->failure++;
170*7c478bd9Sstevel@tonic-gate 			else
171*7c478bd9Sstevel@tonic-gate 				rl->success++;
172*7c478bd9Sstevel@tonic-gate 			if (rpcbproc == RPCBPROC_INDIRECT)
173*7c478bd9Sstevel@tonic-gate 				rl->indirect++;
174*7c478bd9Sstevel@tonic-gate 			return;
175*7c478bd9Sstevel@tonic-gate 		}
176*7c478bd9Sstevel@tonic-gate 	}
177*7c478bd9Sstevel@tonic-gate 	nconf = rpcbind_get_conf(netid);
178*7c478bd9Sstevel@tonic-gate 	if (nconf == NULL) {
179*7c478bd9Sstevel@tonic-gate 		return;
180*7c478bd9Sstevel@tonic-gate 	}
181*7c478bd9Sstevel@tonic-gate 	rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist));
182*7c478bd9Sstevel@tonic-gate 	if (rl == NULL) {
183*7c478bd9Sstevel@tonic-gate 		return;
184*7c478bd9Sstevel@tonic-gate 	}
185*7c478bd9Sstevel@tonic-gate 	rl->prog = prog;
186*7c478bd9Sstevel@tonic-gate 	rl->vers = vers;
187*7c478bd9Sstevel@tonic-gate 	rl->proc = proc;
188*7c478bd9Sstevel@tonic-gate 	rl->netid = nconf->nc_netid;
189*7c478bd9Sstevel@tonic-gate 	if ((rbl == NULL) ||
190*7c478bd9Sstevel@tonic-gate 		    (rbl->rpcb_map.r_vers != vers)) {
191*7c478bd9Sstevel@tonic-gate 		rl->failure = 1;
192*7c478bd9Sstevel@tonic-gate 		rl->success = 0;
193*7c478bd9Sstevel@tonic-gate 	} else {
194*7c478bd9Sstevel@tonic-gate 		rl->failure = 0;
195*7c478bd9Sstevel@tonic-gate 		rl->success = 1;
196*7c478bd9Sstevel@tonic-gate 	}
197*7c478bd9Sstevel@tonic-gate 	rl->indirect = 1;
198*7c478bd9Sstevel@tonic-gate 	rl->next = inf[rtype].rmtinfo;
199*7c478bd9Sstevel@tonic-gate 	inf[rtype].rmtinfo = rl;
200*7c478bd9Sstevel@tonic-gate 	return;
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate /*
204*7c478bd9Sstevel@tonic-gate  */
205*7c478bd9Sstevel@tonic-gate rpcb_stat_byvers *
206*7c478bd9Sstevel@tonic-gate rpcbproc_getstat()
207*7c478bd9Sstevel@tonic-gate {
208*7c478bd9Sstevel@tonic-gate 	return (&inf);
209*7c478bd9Sstevel@tonic-gate }
210