Home | History | Annotate | Line # | Download | only in rpcbind
rpcb_stat.c revision 1.2
      1  1.2  matt /*	$NetBSD: rpcb_stat.c,v 1.2 2000/07/04 20:27:40 matt Exp $	*/
      2  1.1  fvdl 
      3  1.1  fvdl /*
      4  1.1  fvdl  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5  1.1  fvdl  * unrestricted use provided that this legend is included on all tape
      6  1.1  fvdl  * media and as a part of the software program in whole or part.  Users
      7  1.1  fvdl  * may copy or modify Sun RPC without charge, but are not authorized
      8  1.1  fvdl  * to license or distribute it to anyone else except as part of a product or
      9  1.1  fvdl  * program developed by the user.
     10  1.1  fvdl  *
     11  1.1  fvdl  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12  1.1  fvdl  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13  1.1  fvdl  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14  1.1  fvdl  *
     15  1.1  fvdl  * Sun RPC is provided with no support and without any obligation on the
     16  1.1  fvdl  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17  1.1  fvdl  * modification or enhancement.
     18  1.1  fvdl  *
     19  1.1  fvdl  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20  1.1  fvdl  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21  1.1  fvdl  * OR ANY PART THEREOF.
     22  1.1  fvdl  *
     23  1.1  fvdl  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24  1.1  fvdl  * or profits or other special, indirect and consequential damages, even if
     25  1.1  fvdl  * Sun has been advised of the possibility of such damages.
     26  1.1  fvdl  *
     27  1.1  fvdl  * Sun Microsystems, Inc.
     28  1.1  fvdl  * 2550 Garcia Avenue
     29  1.1  fvdl  * Mountain View, California  94043
     30  1.1  fvdl  */
     31  1.1  fvdl /* #pragma ident   "@(#)rpcb_stat.c 1.7     94/04/25 SMI" */
     32  1.1  fvdl 
     33  1.1  fvdl /*
     34  1.1  fvdl  * rpcb_stat.c
     35  1.1  fvdl  * Allows for gathering of statistics
     36  1.1  fvdl  *
     37  1.1  fvdl  * Copyright (c) 1990 by Sun Microsystems, Inc.
     38  1.1  fvdl  */
     39  1.1  fvdl 
     40  1.1  fvdl #include <stdio.h>
     41  1.1  fvdl #include <netconfig.h>
     42  1.1  fvdl #include <rpc/rpc.h>
     43  1.1  fvdl #include <rpc/rpcb_prot.h>
     44  1.1  fvdl #include <sys/stat.h>
     45  1.1  fvdl #ifdef PORTMAP
     46  1.1  fvdl #include <rpc/pmap_prot.h>
     47  1.1  fvdl #endif
     48  1.1  fvdl #include <stdlib.h>
     49  1.2  matt #include <string.h>
     50  1.1  fvdl #include "rpcbind.h"
     51  1.1  fvdl 
     52  1.1  fvdl static rpcb_stat_byvers inf;
     53  1.1  fvdl 
     54  1.1  fvdl void
     55  1.1  fvdl rpcbs_init()
     56  1.1  fvdl {
     57  1.1  fvdl 
     58  1.1  fvdl }
     59  1.1  fvdl 
     60  1.1  fvdl void
     61  1.1  fvdl rpcbs_procinfo(rpcvers_t rtype, rpcproc_t proc)
     62  1.1  fvdl {
     63  1.1  fvdl 	switch (rtype + 2) {
     64  1.1  fvdl #ifdef PORTMAP
     65  1.1  fvdl 	case PMAPVERS:		/* version 2 */
     66  1.1  fvdl 		if (proc > rpcb_highproc_2)
     67  1.1  fvdl 			return;
     68  1.1  fvdl 		break;
     69  1.1  fvdl #endif
     70  1.1  fvdl 	case RPCBVERS:		/* version 3 */
     71  1.1  fvdl 		if (proc > rpcb_highproc_3)
     72  1.1  fvdl 			return;
     73  1.1  fvdl 		break;
     74  1.1  fvdl 	case RPCBVERS4:		/* version 4 */
     75  1.1  fvdl 		if (proc > rpcb_highproc_4)
     76  1.1  fvdl 			return;
     77  1.1  fvdl 		break;
     78  1.1  fvdl 	default: return;
     79  1.1  fvdl 	}
     80  1.1  fvdl 	inf[rtype].info[proc]++;
     81  1.1  fvdl 	return;
     82  1.1  fvdl }
     83  1.1  fvdl 
     84  1.1  fvdl void
     85  1.1  fvdl rpcbs_set(rpcvers_t rtype, bool_t success)
     86  1.1  fvdl {
     87  1.1  fvdl 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
     88  1.1  fvdl 		return;
     89  1.1  fvdl 	inf[rtype].setinfo++;
     90  1.1  fvdl 	return;
     91  1.1  fvdl }
     92  1.1  fvdl 
     93  1.1  fvdl void
     94  1.1  fvdl rpcbs_unset(rpcvers_t rtype, bool_t success)
     95  1.1  fvdl {
     96  1.1  fvdl 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
     97  1.1  fvdl 		return;
     98  1.1  fvdl 	inf[rtype].unsetinfo++;
     99  1.1  fvdl 	return;
    100  1.1  fvdl }
    101  1.1  fvdl 
    102  1.1  fvdl void
    103  1.1  fvdl rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers, char *netid,
    104  1.1  fvdl 	      char *uaddr)
    105  1.1  fvdl {
    106  1.1  fvdl 	rpcbs_addrlist *al;
    107  1.1  fvdl 	struct netconfig *nconf;
    108  1.1  fvdl 
    109  1.1  fvdl 	if (rtype >= RPCBVERS_STAT)
    110  1.1  fvdl 		return;
    111  1.1  fvdl 	for (al = inf[rtype].addrinfo; al; al = al->next) {
    112  1.1  fvdl 
    113  1.1  fvdl 		if(al->netid == NULL)
    114  1.1  fvdl 			return;
    115  1.1  fvdl 		if ((al->prog == prog) && (al->vers == vers) &&
    116  1.1  fvdl 		    (strcmp(al->netid, netid) == 0)) {
    117  1.1  fvdl 			if ((uaddr == NULL) || (uaddr[0] == NULL))
    118  1.1  fvdl 				al->failure++;
    119  1.1  fvdl 			else
    120  1.1  fvdl 				al->success++;
    121  1.1  fvdl 			return;
    122  1.1  fvdl 		}
    123  1.1  fvdl 	}
    124  1.1  fvdl 	nconf = rpcbind_get_conf(netid);
    125  1.1  fvdl 	if (nconf == NULL) {
    126  1.1  fvdl 		return;
    127  1.1  fvdl 	}
    128  1.1  fvdl 	al = (rpcbs_addrlist *) malloc(sizeof (rpcbs_addrlist));
    129  1.1  fvdl 	if (al == NULL) {
    130  1.1  fvdl 		return;
    131  1.1  fvdl 	}
    132  1.1  fvdl 	al->prog = prog;
    133  1.1  fvdl 	al->vers = vers;
    134  1.1  fvdl 	al->netid = nconf->nc_netid;
    135  1.1  fvdl 	if ((uaddr == NULL) || (uaddr[0] == NULL)) {
    136  1.1  fvdl 		al->failure = 1;
    137  1.1  fvdl 		al->success = 0;
    138  1.1  fvdl 	} else {
    139  1.1  fvdl 		al->failure = 0;
    140  1.1  fvdl 		al->success = 1;
    141  1.1  fvdl 	}
    142  1.1  fvdl 	al->next = inf[rtype].addrinfo;
    143  1.1  fvdl 	inf[rtype].addrinfo = al;
    144  1.1  fvdl }
    145  1.1  fvdl 
    146  1.1  fvdl void
    147  1.1  fvdl rpcbs_rmtcall(rpcvers_t rtype, rpcproc_t rpcbproc, rpcprog_t prog,
    148  1.1  fvdl 	      rpcvers_t vers, rpcproc_t proc, char *netid, rpcblist_ptr rbl)
    149  1.1  fvdl {
    150  1.1  fvdl 	rpcbs_rmtcalllist *rl;
    151  1.1  fvdl 	struct netconfig *nconf;
    152  1.1  fvdl 
    153  1.1  fvdl 	if (rtype > RPCBVERS_STAT)
    154  1.1  fvdl 		return;
    155  1.1  fvdl 	for (rl = inf[rtype].rmtinfo; rl; rl = rl->next) {
    156  1.1  fvdl 
    157  1.1  fvdl 		if(rl->netid == NULL)
    158  1.1  fvdl 			return;
    159  1.1  fvdl 
    160  1.1  fvdl 		if ((rl->prog == prog) && (rl->vers == vers) &&
    161  1.1  fvdl 		    (rl->proc == proc) &&
    162  1.1  fvdl 		    (strcmp(rl->netid, netid) == 0)) {
    163  1.1  fvdl 			if ((rbl == NULL) ||
    164  1.1  fvdl 			    (rbl->rpcb_map.r_vers != vers))
    165  1.1  fvdl 				rl->failure++;
    166  1.1  fvdl 			else
    167  1.1  fvdl 				rl->success++;
    168  1.1  fvdl 			if (rpcbproc == RPCBPROC_INDIRECT)
    169  1.1  fvdl 				rl->indirect++;
    170  1.1  fvdl 			return;
    171  1.1  fvdl 		}
    172  1.1  fvdl 	}
    173  1.1  fvdl 	nconf = rpcbind_get_conf(netid);
    174  1.1  fvdl 	if (nconf == NULL) {
    175  1.1  fvdl 		return;
    176  1.1  fvdl 	}
    177  1.1  fvdl 	rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist));
    178  1.1  fvdl 	if (rl == NULL) {
    179  1.1  fvdl 		return;
    180  1.1  fvdl 	}
    181  1.1  fvdl 	rl->prog = prog;
    182  1.1  fvdl 	rl->vers = vers;
    183  1.1  fvdl 	rl->proc = proc;
    184  1.1  fvdl 	rl->netid = nconf->nc_netid;
    185  1.1  fvdl 	if ((rbl == NULL) ||
    186  1.1  fvdl 		    (rbl->rpcb_map.r_vers != vers)) {
    187  1.1  fvdl 		rl->failure = 1;
    188  1.1  fvdl 		rl->success = 0;
    189  1.1  fvdl 	} else {
    190  1.1  fvdl 		rl->failure = 0;
    191  1.1  fvdl 		rl->success = 1;
    192  1.1  fvdl 	}
    193  1.1  fvdl 	rl->indirect = 1;
    194  1.1  fvdl 	rl->next = inf[rtype].rmtinfo;
    195  1.1  fvdl 	inf[rtype].rmtinfo = rl;
    196  1.1  fvdl 	return;
    197  1.1  fvdl }
    198  1.1  fvdl 
    199  1.1  fvdl /*
    200  1.1  fvdl  */
    201  1.1  fvdl void *
    202  1.1  fvdl rpcbproc_getstat(void *arg, struct svc_req *req, SVCXPRT *xprt,
    203  1.1  fvdl 		 rpcvers_t versnum)
    204  1.1  fvdl {
    205  1.1  fvdl 	return (void *)&inf;
    206  1.1  fvdl }
    207