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