xref: /netbsd-src/usr.sbin/rpcbind/rpcb_stat.c (revision 4472dbe5e3bd91ef2540bada7a7ca7384627ff9b)
1 /*	$NetBSD: rpcb_stat.c,v 1.1 2000/06/02 23:15:41 fvdl Exp $	*/
2 
3 /*
4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5  * unrestricted use provided that this legend is included on all tape
6  * media and as a part of the software program in whole or part.  Users
7  * may copy or modify Sun RPC without charge, but are not authorized
8  * to license or distribute it to anyone else except as part of a product or
9  * program developed by the user.
10  *
11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14  *
15  * Sun RPC is provided with no support and without any obligation on the
16  * part of Sun Microsystems, Inc. to assist in its use, correction,
17  * modification or enhancement.
18  *
19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21  * OR ANY PART THEREOF.
22  *
23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24  * or profits or other special, indirect and consequential damages, even if
25  * Sun has been advised of the possibility of such damages.
26  *
27  * Sun Microsystems, Inc.
28  * 2550 Garcia Avenue
29  * Mountain View, California  94043
30  */
31 /* #pragma ident   "@(#)rpcb_stat.c 1.7     94/04/25 SMI" */
32 
33 /*
34  * rpcb_stat.c
35  * Allows for gathering of statistics
36  *
37  * Copyright (c) 1990 by Sun Microsystems, Inc.
38  */
39 
40 #include <stdio.h>
41 #include <netconfig.h>
42 #include <rpc/rpc.h>
43 #include <rpc/rpcb_prot.h>
44 #include <sys/stat.h>
45 #ifdef PORTMAP
46 #include <rpc/pmap_prot.h>
47 #endif
48 #include <stdlib.h>
49 #include "rpcbind.h"
50 
51 static rpcb_stat_byvers inf;
52 
53 void
54 rpcbs_init()
55 {
56 
57 }
58 
59 void
60 rpcbs_procinfo(rpcvers_t rtype, rpcproc_t proc)
61 {
62 	switch (rtype + 2) {
63 #ifdef PORTMAP
64 	case PMAPVERS:		/* version 2 */
65 		if (proc > rpcb_highproc_2)
66 			return;
67 		break;
68 #endif
69 	case RPCBVERS:		/* version 3 */
70 		if (proc > rpcb_highproc_3)
71 			return;
72 		break;
73 	case RPCBVERS4:		/* version 4 */
74 		if (proc > rpcb_highproc_4)
75 			return;
76 		break;
77 	default: return;
78 	}
79 	inf[rtype].info[proc]++;
80 	return;
81 }
82 
83 void
84 rpcbs_set(rpcvers_t rtype, bool_t success)
85 {
86 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
87 		return;
88 	inf[rtype].setinfo++;
89 	return;
90 }
91 
92 void
93 rpcbs_unset(rpcvers_t rtype, bool_t success)
94 {
95 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
96 		return;
97 	inf[rtype].unsetinfo++;
98 	return;
99 }
100 
101 void
102 rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers, char *netid,
103 	      char *uaddr)
104 {
105 	rpcbs_addrlist *al;
106 	struct netconfig *nconf;
107 
108 	if (rtype >= RPCBVERS_STAT)
109 		return;
110 	for (al = inf[rtype].addrinfo; al; al = al->next) {
111 
112 		if(al->netid == NULL)
113 			return;
114 		if ((al->prog == prog) && (al->vers == vers) &&
115 		    (strcmp(al->netid, netid) == 0)) {
116 			if ((uaddr == NULL) || (uaddr[0] == NULL))
117 				al->failure++;
118 			else
119 				al->success++;
120 			return;
121 		}
122 	}
123 	nconf = rpcbind_get_conf(netid);
124 	if (nconf == NULL) {
125 		return;
126 	}
127 	al = (rpcbs_addrlist *) malloc(sizeof (rpcbs_addrlist));
128 	if (al == NULL) {
129 		return;
130 	}
131 	al->prog = prog;
132 	al->vers = vers;
133 	al->netid = nconf->nc_netid;
134 	if ((uaddr == NULL) || (uaddr[0] == NULL)) {
135 		al->failure = 1;
136 		al->success = 0;
137 	} else {
138 		al->failure = 0;
139 		al->success = 1;
140 	}
141 	al->next = inf[rtype].addrinfo;
142 	inf[rtype].addrinfo = al;
143 }
144 
145 void
146 rpcbs_rmtcall(rpcvers_t rtype, rpcproc_t rpcbproc, rpcprog_t prog,
147 	      rpcvers_t vers, rpcproc_t proc, char *netid, rpcblist_ptr rbl)
148 {
149 	rpcbs_rmtcalllist *rl;
150 	struct netconfig *nconf;
151 
152 	if (rtype > RPCBVERS_STAT)
153 		return;
154 	for (rl = inf[rtype].rmtinfo; rl; rl = rl->next) {
155 
156 		if(rl->netid == NULL)
157 			return;
158 
159 		if ((rl->prog == prog) && (rl->vers == vers) &&
160 		    (rl->proc == proc) &&
161 		    (strcmp(rl->netid, netid) == 0)) {
162 			if ((rbl == NULL) ||
163 			    (rbl->rpcb_map.r_vers != vers))
164 				rl->failure++;
165 			else
166 				rl->success++;
167 			if (rpcbproc == RPCBPROC_INDIRECT)
168 				rl->indirect++;
169 			return;
170 		}
171 	}
172 	nconf = rpcbind_get_conf(netid);
173 	if (nconf == NULL) {
174 		return;
175 	}
176 	rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist));
177 	if (rl == NULL) {
178 		return;
179 	}
180 	rl->prog = prog;
181 	rl->vers = vers;
182 	rl->proc = proc;
183 	rl->netid = nconf->nc_netid;
184 	if ((rbl == NULL) ||
185 		    (rbl->rpcb_map.r_vers != vers)) {
186 		rl->failure = 1;
187 		rl->success = 0;
188 	} else {
189 		rl->failure = 0;
190 		rl->success = 1;
191 	}
192 	rl->indirect = 1;
193 	rl->next = inf[rtype].rmtinfo;
194 	inf[rtype].rmtinfo = rl;
195 	return;
196 }
197 
198 /*
199  */
200 void *
201 rpcbproc_getstat(void *arg, struct svc_req *req, SVCXPRT *xprt,
202 		 rpcvers_t versnum)
203 {
204 	return (void *)&inf;
205 }
206