1 /* 2 * $NetBSD: rpcb_stat.c,v 1.2 2000/07/04 20:27:40 matt Exp $ 3 * $FreeBSD$ 4 */ 5 /*- 6 * SPDX-License-Identifier: BSD-3-Clause 7 * 8 * Copyright (c) 2009, Sun Microsystems, Inc. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions are met: 13 * - Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * - Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * - Neither the name of Sun Microsystems, Inc. nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 * POSSIBILITY OF SUCH DAMAGE. 33 */ 34 /* #pragma ident "@(#)rpcb_stat.c 1.7 94/04/25 SMI" */ 35 36 /* 37 * rpcb_stat.c 38 * Allows for gathering of statistics 39 * 40 * Copyright (c) 1990 by Sun Microsystems, Inc. 41 */ 42 43 #include <stdio.h> 44 #include <netconfig.h> 45 #include <rpc/rpc.h> 46 #include <rpc/rpcb_prot.h> 47 #include <sys/stat.h> 48 #ifdef PORTMAP 49 #include <rpc/pmap_prot.h> 50 #endif 51 #include <stdlib.h> 52 #include <string.h> 53 #include "rpcbind.h" 54 55 static rpcb_stat_byvers inf; 56 57 void 58 rpcbs_init(void) 59 { 60 61 } 62 63 void 64 rpcbs_procinfo(rpcvers_t rtype, rpcproc_t proc) 65 { 66 switch (rtype + 2) { 67 #ifdef PORTMAP 68 case PMAPVERS: /* version 2 */ 69 if (proc > rpcb_highproc_2) 70 return; 71 break; 72 #endif 73 case RPCBVERS: /* version 3 */ 74 if (proc > rpcb_highproc_3) 75 return; 76 break; 77 case RPCBVERS4: /* version 4 */ 78 if (proc > rpcb_highproc_4) 79 return; 80 break; 81 default: return; 82 } 83 inf[rtype].info[proc]++; 84 return; 85 } 86 87 void 88 rpcbs_set(rpcvers_t rtype, bool_t success) 89 { 90 if ((rtype >= RPCBVERS_STAT) || (success == FALSE)) 91 return; 92 inf[rtype].setinfo++; 93 return; 94 } 95 96 void 97 rpcbs_unset(rpcvers_t rtype, bool_t success) 98 { 99 if ((rtype >= RPCBVERS_STAT) || (success == FALSE)) 100 return; 101 inf[rtype].unsetinfo++; 102 return; 103 } 104 105 void 106 rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers, char *netid, 107 char *uaddr) 108 { 109 rpcbs_addrlist *al; 110 struct netconfig *nconf; 111 112 if (rtype >= RPCBVERS_STAT) 113 return; 114 for (al = inf[rtype].addrinfo; al; al = al->next) { 115 116 if(al->netid == NULL) 117 return; 118 if ((al->prog == prog) && (al->vers == vers) && 119 (strcmp(al->netid, netid) == 0)) { 120 if ((uaddr == NULL) || (uaddr[0] == 0)) 121 al->failure++; 122 else 123 al->success++; 124 return; 125 } 126 } 127 nconf = rpcbind_get_conf(netid); 128 if (nconf == NULL) { 129 return; 130 } 131 al = (rpcbs_addrlist *) malloc(sizeof (rpcbs_addrlist)); 132 if (al == NULL) { 133 return; 134 } 135 al->prog = prog; 136 al->vers = vers; 137 al->netid = nconf->nc_netid; 138 if ((uaddr == NULL) || (uaddr[0] == 0)) { 139 al->failure = 1; 140 al->success = 0; 141 } else { 142 al->failure = 0; 143 al->success = 1; 144 } 145 al->next = inf[rtype].addrinfo; 146 inf[rtype].addrinfo = al; 147 } 148 149 void 150 rpcbs_rmtcall(rpcvers_t rtype, rpcproc_t rpcbproc, rpcprog_t prog, 151 rpcvers_t vers, rpcproc_t proc, char *netid, rpcblist_ptr rbl) 152 { 153 rpcbs_rmtcalllist *rl; 154 struct netconfig *nconf; 155 156 if (rtype >= RPCBVERS_STAT) 157 return; 158 for (rl = inf[rtype].rmtinfo; rl; rl = rl->next) { 159 160 if(rl->netid == NULL) 161 return; 162 163 if ((rl->prog == prog) && (rl->vers == vers) && 164 (rl->proc == proc) && 165 (strcmp(rl->netid, netid) == 0)) { 166 if ((rbl == NULL) || 167 (rbl->rpcb_map.r_vers != vers)) 168 rl->failure++; 169 else 170 rl->success++; 171 if (rpcbproc == RPCBPROC_INDIRECT) 172 rl->indirect++; 173 return; 174 } 175 } 176 nconf = rpcbind_get_conf(netid); 177 if (nconf == NULL) { 178 return; 179 } 180 rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist)); 181 if (rl == NULL) { 182 return; 183 } 184 rl->prog = prog; 185 rl->vers = vers; 186 rl->proc = proc; 187 rl->netid = nconf->nc_netid; 188 if ((rbl == NULL) || 189 (rbl->rpcb_map.r_vers != vers)) { 190 rl->failure = 1; 191 rl->success = 0; 192 } else { 193 rl->failure = 0; 194 rl->success = 1; 195 } 196 rl->indirect = 1; 197 rl->next = inf[rtype].rmtinfo; 198 inf[rtype].rmtinfo = rl; 199 return; 200 } 201 202 void * 203 rpcbproc_getstat(void *arg __unused, struct svc_req *req __unused, 204 SVCXPRT *xprt __unused, rpcvers_t versnum __unused) 205 { 206 return (void *)&inf; 207 } 208