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