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