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 /* #pragma ident "@(#)rpcb_stat.c 1.7 94/04/25 SMI" */ 34 35 /* 36 * rpcb_stat.c 37 * Allows for gathering of statistics 38 * 39 * Copyright (c) 1990 by Sun Microsystems, Inc. 40 */ 41 42 #include <netconfig.h> 43 #include <rpc/rpc.h> 44 #include <rpc/rpcb_prot.h> 45 #include <sys/stat.h> 46 #ifdef PORTMAP 47 #include <rpc/pmap_prot.h> 48 #endif 49 #include <stdlib.h> 50 #include <string.h> 51 #include "rpcbind.h" 52 53 static rpcb_stat_byvers inf; 54 55 void 56 rpcbs_init(void) 57 { 58 59 } 60 61 void 62 rpcbs_procinfo(rpcvers_t rtype, rpcproc_t proc) 63 { 64 switch (rtype + 2) { 65 #ifdef PORTMAP 66 case PMAPVERS: /* version 2 */ 67 if (proc > rpcb_highproc_2) 68 return; 69 break; 70 #endif 71 case RPCBVERS: /* version 3 */ 72 if (proc > rpcb_highproc_3) 73 return; 74 break; 75 case RPCBVERS4: /* version 4 */ 76 if (proc > rpcb_highproc_4) 77 return; 78 break; 79 default: return; 80 } 81 inf[rtype].info[proc]++; 82 } 83 84 void 85 rpcbs_set(rpcvers_t rtype, bool_t success) 86 { 87 if ((rtype >= RPCBVERS_STAT) || (success == FALSE)) 88 return; 89 inf[rtype].setinfo++; 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 } 99 100 void 101 rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers, 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] == 0)) 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] == 0)) { 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(rpcvers_t rtype, rpcproc_t rpcbproc, rpcprog_t prog, 146 rpcvers_t vers, rpcproc_t proc, char *netid, rpcblist_ptr rbl) 147 { 148 rpcbs_rmtcalllist *rl; 149 struct netconfig *nconf; 150 151 if (rtype >= RPCBVERS_STAT) 152 return; 153 for (rl = inf[rtype].rmtinfo; rl; rl = rl->next) { 154 155 if(rl->netid == NULL) 156 return; 157 158 if ((rl->prog == prog) && (rl->vers == vers) && 159 (rl->proc == proc) && 160 (strcmp(rl->netid, netid) == 0)) { 161 if ((rbl == NULL) || 162 (rbl->rpcb_map.r_vers != vers)) 163 rl->failure++; 164 else 165 rl->success++; 166 if (rpcbproc == RPCBPROC_INDIRECT) 167 rl->indirect++; 168 return; 169 } 170 } 171 nconf = rpcbind_get_conf(netid); 172 if (nconf == NULL) { 173 return; 174 } 175 rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist)); 176 if (rl == NULL) { 177 return; 178 } 179 rl->prog = prog; 180 rl->vers = vers; 181 rl->proc = proc; 182 rl->netid = nconf->nc_netid; 183 if ((rbl == NULL) || 184 (rbl->rpcb_map.r_vers != vers)) { 185 rl->failure = 1; 186 rl->success = 0; 187 } else { 188 rl->failure = 0; 189 rl->success = 1; 190 } 191 rl->indirect = 1; 192 rl->next = inf[rtype].rmtinfo; 193 inf[rtype].rmtinfo = rl; 194 } 195 196 void * 197 rpcbproc_getstat(void *arg __unused, struct svc_req *req __unused, 198 SVCXPRT *xprt __unused, rpcvers_t versnum __unused) 199 { 200 return (void *)&inf; 201 } 202