rpcb_stat.c revision 272345
11541Srgrimes/* $NetBSD: rpcb_stat.c,v 1.1 2010/07/26 15:53:00 pooka Exp $ */ 21541Srgrimes 31541Srgrimes/* 41541Srgrimes * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 51541Srgrimes * unrestricted use provided that this legend is included on all tape 61541Srgrimes * media and as a part of the software program in whole or part. Users 71541Srgrimes * may copy or modify Sun RPC without charge, but are not authorized 81541Srgrimes * to license or distribute it to anyone else except as part of a product or 91541Srgrimes * program developed by the user. 101541Srgrimes * 111541Srgrimes * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 121541Srgrimes * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 131541Srgrimes * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 141541Srgrimes * 151541Srgrimes * Sun RPC is provided with no support and without any obligation on the 161541Srgrimes * part of Sun Microsystems, Inc. to assist in its use, correction, 171541Srgrimes * modification or enhancement. 181541Srgrimes * 191541Srgrimes * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 201541Srgrimes * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 211541Srgrimes * OR ANY PART THEREOF. 221541Srgrimes * 231541Srgrimes * In no event will Sun Microsystems, Inc. be liable for any lost revenue 241541Srgrimes * or profits or other special, indirect and consequential damages, even if 251541Srgrimes * Sun has been advised of the possibility of such damages. 261541Srgrimes * 271541Srgrimes * Sun Microsystems, Inc. 281541Srgrimes * 2550 Garcia Avenue 291541Srgrimes * Mountain View, California 94043 301541Srgrimes */ 311541Srgrimes/* #pragma ident "@(#)rpcb_stat.c 1.7 94/04/25 SMI" */ 321541Srgrimes 331541Srgrimes/* 341541Srgrimes * rpcb_stat.c 351541Srgrimes * Allows for gathering of statistics 3622521Sdyson * 371541Srgrimes * Copyright (c) 1990 by Sun Microsystems, Inc. 3822521Sdyson */ 3922521Sdyson 4022521Sdyson#include <stdio.h> 4122521Sdyson#include <netconfig.h> 4222521Sdyson#include <rpc/rpc.h> 4350477Speter#include <rpc/rpcb_prot.h> 441541Srgrimes#include <sys/stat.h> 451541Srgrimes#ifdef PORTMAP 461541Srgrimes#include <rpc/pmap_prot.h> 471541Srgrimes#endif 481541Srgrimes#include <stdlib.h> 4977130Sru#include <string.h> 501541Srgrimes#include "rpcbind.h" 5196755Strhodes 521541Srgrimesstatic rpcb_stat_byvers inf; 5396755Strhodes 541541Srgrimesvoid 5535256Sdesrpcbs_init(void) 561541Srgrimes{ 571541Srgrimes 581541Srgrimes} 591541Srgrimes 6096755Strhodesvoid 611541Srgrimesrpcbs_procinfo(rpcvers_t rtype, rpcproc_t proc) 621541Srgrimes{ 6396755Strhodes switch (rtype + 2) { 641541Srgrimes#ifdef PORTMAP 651541Srgrimes case PMAPVERS: /* version 2 */ 661541Srgrimes if (proc > rpcb_highproc_2) 671541Srgrimes return; 681541Srgrimes break; 691541Srgrimes#endif 701541Srgrimes case RPCBVERS: /* version 3 */ 711541Srgrimes if (proc > rpcb_highproc_3) 7277130Sru return; 7377130Sru break; 741541Srgrimes case RPCBVERS4: /* version 4 */ 751541Srgrimes if (proc > rpcb_highproc_4) 761541Srgrimes return; 771541Srgrimes break; 781541Srgrimes default: return; 791541Srgrimes } 801541Srgrimes inf[rtype].info[proc]++; 811541Srgrimes return; 8296755Strhodes} 831541Srgrimes 841541Srgrimesvoid 8526963Salexrpcbs_set(rpcvers_t rtype, bool_t success) 861541Srgrimes{ 871541Srgrimes if ((rtype >= RPCBVERS_STAT) || (success == FALSE)) 881541Srgrimes return; 891541Srgrimes inf[rtype].setinfo++; 901541Srgrimes return; 911541Srgrimes} 921541Srgrimes 931541Srgrimesvoid 941541Srgrimesrpcbs_unset(rpcvers_t rtype, bool_t success) 951541Srgrimes{ 9622521Sdyson if ((rtype >= RPCBVERS_STAT) || (success == FALSE)) 9722521Sdyson return; 9822521Sdyson inf[rtype].unsetinfo++; 9922521Sdyson return; 10022521Sdyson} 1011541Srgrimes 10222521Sdysonvoid 10322521Sdysonrpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers, 10422521Sdyson const char *netid, const char *uaddr) 10522521Sdyson{ 10622521Sdyson rpcbs_addrlist *al; 10722521Sdyson struct netconfig *nconf; 10822521Sdyson 10922521Sdyson if (rtype >= RPCBVERS_STAT) 11022521Sdyson return; 1111541Srgrimes for (al = inf[rtype].addrinfo; al; al = al->next) { 1121541Srgrimes 1131541Srgrimes if(al->netid == NULL) 1141541Srgrimes return; 1151541Srgrimes if ((al->prog == prog) && (al->vers == vers) && 1161541Srgrimes (strcmp(al->netid, netid) == 0)) { 1171541Srgrimes if ((uaddr == NULL) || (uaddr[0] == 0)) 1181541Srgrimes al->failure++; 1191541Srgrimes else 1201541Srgrimes al->success++; 1211541Srgrimes return; 1221541Srgrimes } 1231541Srgrimes } 1241541Srgrimes nconf = rpcbind_get_conf(netid); 1258876Srgrimes if (nconf == NULL) { 1261541Srgrimes return; 1271541Srgrimes } 1281541Srgrimes al = (rpcbs_addrlist *) malloc(sizeof (rpcbs_addrlist)); 1291541Srgrimes if (al == NULL) { 13077130Sru return; 1311541Srgrimes } 1321541Srgrimes al->prog = prog; 1331541Srgrimes al->vers = vers; 1341541Srgrimes al->netid = nconf->nc_netid; 1358876Srgrimes if ((uaddr == NULL) || (uaddr[0] == 0)) { 1361541Srgrimes al->failure = 1; 1371541Srgrimes al->success = 0; 1381541Srgrimes } else { 1391541Srgrimes al->failure = 0; 1401541Srgrimes al->success = 1; 1411541Srgrimes } 1421541Srgrimes al->next = inf[rtype].addrinfo; 1431541Srgrimes inf[rtype].addrinfo = al; 14496755Strhodes} 1451541Srgrimes 1461541Srgrimesvoid 1471541Srgrimesrpcbs_rmtcall(rpcvers_t rtype, rpcproc_t rpcbproc, rpcprog_t prog, 1481541Srgrimes rpcvers_t vers, rpcproc_t proc, char *netid, rpcblist_ptr rbl) 1498876Srgrimes{ 1501541Srgrimes rpcbs_rmtcalllist *rl; 1511541Srgrimes struct netconfig *nconf; 1521541Srgrimes 1531541Srgrimes if (rtype >= RPCBVERS_STAT) 1541541Srgrimes return; 1558876Srgrimes for (rl = inf[rtype].rmtinfo; rl; rl = rl->next) { 1561541Srgrimes 1571541Srgrimes if(rl->netid == NULL) 1581541Srgrimes return; 1591541Srgrimes 1601541Srgrimes if ((rl->prog == prog) && (rl->vers == vers) && 1611541Srgrimes (rl->proc == proc) && 1621541Srgrimes (strcmp(rl->netid, netid) == 0)) { 1631541Srgrimes if ((rbl == NULL) || 16426964Salex (rbl->rpcb_map.r_vers != vers)) 1651541Srgrimes rl->failure++; 1661541Srgrimes else 1671541Srgrimes rl->success++; 16826964Salex if (rpcbproc == RPCBPROC_INDIRECT) 1691541Srgrimes rl->indirect++; 1701541Srgrimes return; 1711541Srgrimes } 17226964Salex } 1731541Srgrimes nconf = rpcbind_get_conf(netid); 1741541Srgrimes if (nconf == NULL) { 1751541Srgrimes return; 1761541Srgrimes } 1771541Srgrimes rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist)); 17876166Smarkm if (rl == NULL) { 1792960Swollman return; 18076166Smarkm } 18176166Smarkm rl->prog = prog; 18276166Smarkm rl->vers = vers; 18376166Smarkm rl->proc = proc; 18476166Smarkm rl->netid = nconf->nc_netid; 18512769Sphk if ((rbl == NULL) || 1861541Srgrimes (rbl->rpcb_map.r_vers != vers)) { 18776166Smarkm rl->failure = 1; 18877031Sru rl->success = 0; 1891541Srgrimes } else { 19066356Sbp rl->failure = 0; 19166356Sbp rl->success = 1; 19266356Sbp } 19366356Sbp rl->indirect = 1; 19466356Sbp rl->next = inf[rtype].rmtinfo; 19512769Sphk inf[rtype].rmtinfo = rl; 19612769Sphk return; 19712769Sphk} 1981541Srgrimes 19965464Sbp/* 20066356Sbp */ 20166356Sbpvoid * 20265464Sbprpcbproc_getstat(void *arg, struct svc_req *req, SVCXPRT *xprt, 20366356Sbp rpcvers_t versnum) 20465464Sbp{ 20566356Sbp return (void *)&inf; 20665464Sbp} 20765464Sbp