xref: /titanic_52/usr/src/cmd/rpcbind/rpcb_stat.c (revision 9e39c5ba00a55fa05777cc94b148296af305e135)
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  * rpcb_stat.c
24  * Allows for gathering of statistics
25  *
26  * Copyright (c) 1990 by Sun Microsystems, Inc.
27  */
28 
29 #include <stdio.h>
30 #include <netconfig.h>
31 #include <rpc/rpc.h>
32 #include <rpc/rpcb_prot.h>
33 #include <sys/stat.h>
34 #ifdef PORTMAP
35 #include <rpc/pmap_prot.h>
36 #endif
37 #include <stdlib.h>
38 #include "rpcbind.h"
39 
40 static rpcb_stat_byvers inf;
41 
42 void
43 rpcbs_init()
44 {
45 
46 }
47 
48 void
49 rpcbs_procinfo(rtype, proc)
50 	u_long rtype;
51 	u_long proc;
52 {
53 	switch (rtype + 2) {
54 #ifdef PORTMAP
55 	case PMAPVERS:		/* version 2 */
56 		if (proc > rpcb_highproc_2)
57 			return;
58 		break;
59 #endif
60 	case RPCBVERS:		/* version 3 */
61 		if (proc > rpcb_highproc_3)
62 			return;
63 		break;
64 	case RPCBVERS4:		/* version 4 */
65 		if (proc > rpcb_highproc_4)
66 			return;
67 		break;
68 	default: return;
69 	}
70 	inf[rtype].info[proc]++;
71 	return;
72 }
73 
74 void
75 rpcbs_set(rtype, success)
76 	u_long rtype;
77 	bool_t success;
78 {
79 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
80 		return;
81 	inf[rtype].setinfo++;
82 	return;
83 }
84 
85 void
86 rpcbs_unset(rtype, success)
87 	u_long rtype;
88 	bool_t success;
89 {
90 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
91 		return;
92 	inf[rtype].unsetinfo++;
93 	return;
94 }
95 
96 void
97 rpcbs_getaddr(rtype, prog, vers, netid, uaddr)
98 	u_long rtype;
99 	u_long prog;
100 	u_long vers;
101 	char *netid;
102 	char *uaddr;
103 {
104 	rpcbs_addrlist *al;
105 	struct netconfig *nconf;
106 
107 	if (rtype >= RPCBVERS_STAT)
108 		return;
109 	for (al = inf[rtype].addrinfo; al; al = al->next) {
110 
111 		if(al->netid == NULL)
112 			return;
113 		if ((al->prog == prog) && (al->vers == vers) &&
114 		    (strcmp(al->netid, netid) == 0)) {
115 			if ((uaddr == NULL) || (uaddr[0] == NULL))
116 				al->failure++;
117 			else
118 				al->success++;
119 			return;
120 		}
121 	}
122 	nconf = rpcbind_get_conf(netid);
123 	if (nconf == NULL) {
124 		return;
125 	}
126 	al = (rpcbs_addrlist *) malloc(sizeof (rpcbs_addrlist));
127 	if (al == NULL) {
128 		return;
129 	}
130 	al->prog = prog;
131 	al->vers = vers;
132 	al->netid = nconf->nc_netid;
133 	if ((uaddr == NULL) || (uaddr[0] == NULL)) {
134 		al->failure = 1;
135 		al->success = 0;
136 	} else {
137 		al->failure = 0;
138 		al->success = 1;
139 	}
140 	al->next = inf[rtype].addrinfo;
141 	inf[rtype].addrinfo = al;
142 }
143 
144 void
145 rpcbs_rmtcall(rtype, rpcbproc, prog, vers, proc, netid, rbl)
146 	u_long rtype;
147 	u_long rpcbproc; /* rpcbind proc number on which this was called */
148 	u_long prog;
149 	u_long vers;
150 	u_long proc;
151 	char *netid;
152 	rpcblist_ptr rbl;
153 {
154 	rpcbs_rmtcalllist *rl;
155 	struct netconfig *nconf;
156 
157 	if (rtype > RPCBVERS_STAT)
158 		return;
159 	for (rl = inf[rtype].rmtinfo; rl; rl = rl->next) {
160 
161 		if(rl->netid == NULL)
162 			return;
163 
164 		if ((rl->prog == prog) && (rl->vers == vers) &&
165 		    (rl->proc == proc) &&
166 		    (strcmp(rl->netid, netid) == 0)) {
167 			if ((rbl == NULL) ||
168 			    (rbl->rpcb_map.r_vers != vers))
169 				rl->failure++;
170 			else
171 				rl->success++;
172 			if (rpcbproc == RPCBPROC_INDIRECT)
173 				rl->indirect++;
174 			return;
175 		}
176 	}
177 	nconf = rpcbind_get_conf(netid);
178 	if (nconf == NULL) {
179 		return;
180 	}
181 	rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist));
182 	if (rl == NULL) {
183 		return;
184 	}
185 	rl->prog = prog;
186 	rl->vers = vers;
187 	rl->proc = proc;
188 	rl->netid = nconf->nc_netid;
189 	if ((rbl == NULL) ||
190 		    (rbl->rpcb_map.r_vers != vers)) {
191 		rl->failure = 1;
192 		rl->success = 0;
193 	} else {
194 		rl->failure = 0;
195 		rl->success = 1;
196 	}
197 	rl->indirect = 1;
198 	rl->next = inf[rtype].rmtinfo;
199 	inf[rtype].rmtinfo = rl;
200 	return;
201 }
202 
203 /*
204  */
205 rpcb_stat_byvers *
206 rpcbproc_getstat()
207 {
208 	return (&inf);
209 }
210