Home | History | Annotate | Line # | Download | only in rpcbind
rpcb_stat.c revision 1.1
      1  1.1  fvdl /*	$NetBSD: rpcb_stat.c,v 1.1 2000/06/02 23:15:41 fvdl 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.1  fvdl #include "rpcbind.h"
     50  1.1  fvdl 
     51  1.1  fvdl static rpcb_stat_byvers inf;
     52  1.1  fvdl 
     53  1.1  fvdl void
     54  1.1  fvdl rpcbs_init()
     55  1.1  fvdl {
     56  1.1  fvdl 
     57  1.1  fvdl }
     58  1.1  fvdl 
     59  1.1  fvdl void
     60  1.1  fvdl rpcbs_procinfo(rpcvers_t rtype, rpcproc_t proc)
     61  1.1  fvdl {
     62  1.1  fvdl 	switch (rtype + 2) {
     63  1.1  fvdl #ifdef PORTMAP
     64  1.1  fvdl 	case PMAPVERS:		/* version 2 */
     65  1.1  fvdl 		if (proc > rpcb_highproc_2)
     66  1.1  fvdl 			return;
     67  1.1  fvdl 		break;
     68  1.1  fvdl #endif
     69  1.1  fvdl 	case RPCBVERS:		/* version 3 */
     70  1.1  fvdl 		if (proc > rpcb_highproc_3)
     71  1.1  fvdl 			return;
     72  1.1  fvdl 		break;
     73  1.1  fvdl 	case RPCBVERS4:		/* version 4 */
     74  1.1  fvdl 		if (proc > rpcb_highproc_4)
     75  1.1  fvdl 			return;
     76  1.1  fvdl 		break;
     77  1.1  fvdl 	default: return;
     78  1.1  fvdl 	}
     79  1.1  fvdl 	inf[rtype].info[proc]++;
     80  1.1  fvdl 	return;
     81  1.1  fvdl }
     82  1.1  fvdl 
     83  1.1  fvdl void
     84  1.1  fvdl rpcbs_set(rpcvers_t rtype, bool_t success)
     85  1.1  fvdl {
     86  1.1  fvdl 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
     87  1.1  fvdl 		return;
     88  1.1  fvdl 	inf[rtype].setinfo++;
     89  1.1  fvdl 	return;
     90  1.1  fvdl }
     91  1.1  fvdl 
     92  1.1  fvdl void
     93  1.1  fvdl rpcbs_unset(rpcvers_t rtype, bool_t success)
     94  1.1  fvdl {
     95  1.1  fvdl 	if ((rtype >= RPCBVERS_STAT) || (success == FALSE))
     96  1.1  fvdl 		return;
     97  1.1  fvdl 	inf[rtype].unsetinfo++;
     98  1.1  fvdl 	return;
     99  1.1  fvdl }
    100  1.1  fvdl 
    101  1.1  fvdl void
    102  1.1  fvdl rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers, char *netid,
    103  1.1  fvdl 	      char *uaddr)
    104  1.1  fvdl {
    105  1.1  fvdl 	rpcbs_addrlist *al;
    106  1.1  fvdl 	struct netconfig *nconf;
    107  1.1  fvdl 
    108  1.1  fvdl 	if (rtype >= RPCBVERS_STAT)
    109  1.1  fvdl 		return;
    110  1.1  fvdl 	for (al = inf[rtype].addrinfo; al; al = al->next) {
    111  1.1  fvdl 
    112  1.1  fvdl 		if(al->netid == NULL)
    113  1.1  fvdl 			return;
    114  1.1  fvdl 		if ((al->prog == prog) && (al->vers == vers) &&
    115  1.1  fvdl 		    (strcmp(al->netid, netid) == 0)) {
    116  1.1  fvdl 			if ((uaddr == NULL) || (uaddr[0] == NULL))
    117  1.1  fvdl 				al->failure++;
    118  1.1  fvdl 			else
    119  1.1  fvdl 				al->success++;
    120  1.1  fvdl 			return;
    121  1.1  fvdl 		}
    122  1.1  fvdl 	}
    123  1.1  fvdl 	nconf = rpcbind_get_conf(netid);
    124  1.1  fvdl 	if (nconf == NULL) {
    125  1.1  fvdl 		return;
    126  1.1  fvdl 	}
    127  1.1  fvdl 	al = (rpcbs_addrlist *) malloc(sizeof (rpcbs_addrlist));
    128  1.1  fvdl 	if (al == NULL) {
    129  1.1  fvdl 		return;
    130  1.1  fvdl 	}
    131  1.1  fvdl 	al->prog = prog;
    132  1.1  fvdl 	al->vers = vers;
    133  1.1  fvdl 	al->netid = nconf->nc_netid;
    134  1.1  fvdl 	if ((uaddr == NULL) || (uaddr[0] == NULL)) {
    135  1.1  fvdl 		al->failure = 1;
    136  1.1  fvdl 		al->success = 0;
    137  1.1  fvdl 	} else {
    138  1.1  fvdl 		al->failure = 0;
    139  1.1  fvdl 		al->success = 1;
    140  1.1  fvdl 	}
    141  1.1  fvdl 	al->next = inf[rtype].addrinfo;
    142  1.1  fvdl 	inf[rtype].addrinfo = al;
    143  1.1  fvdl }
    144  1.1  fvdl 
    145  1.1  fvdl void
    146  1.1  fvdl rpcbs_rmtcall(rpcvers_t rtype, rpcproc_t rpcbproc, rpcprog_t prog,
    147  1.1  fvdl 	      rpcvers_t vers, rpcproc_t proc, char *netid, rpcblist_ptr rbl)
    148  1.1  fvdl {
    149  1.1  fvdl 	rpcbs_rmtcalllist *rl;
    150  1.1  fvdl 	struct netconfig *nconf;
    151  1.1  fvdl 
    152  1.1  fvdl 	if (rtype > RPCBVERS_STAT)
    153  1.1  fvdl 		return;
    154  1.1  fvdl 	for (rl = inf[rtype].rmtinfo; rl; rl = rl->next) {
    155  1.1  fvdl 
    156  1.1  fvdl 		if(rl->netid == NULL)
    157  1.1  fvdl 			return;
    158  1.1  fvdl 
    159  1.1  fvdl 		if ((rl->prog == prog) && (rl->vers == vers) &&
    160  1.1  fvdl 		    (rl->proc == proc) &&
    161  1.1  fvdl 		    (strcmp(rl->netid, netid) == 0)) {
    162  1.1  fvdl 			if ((rbl == NULL) ||
    163  1.1  fvdl 			    (rbl->rpcb_map.r_vers != vers))
    164  1.1  fvdl 				rl->failure++;
    165  1.1  fvdl 			else
    166  1.1  fvdl 				rl->success++;
    167  1.1  fvdl 			if (rpcbproc == RPCBPROC_INDIRECT)
    168  1.1  fvdl 				rl->indirect++;
    169  1.1  fvdl 			return;
    170  1.1  fvdl 		}
    171  1.1  fvdl 	}
    172  1.1  fvdl 	nconf = rpcbind_get_conf(netid);
    173  1.1  fvdl 	if (nconf == NULL) {
    174  1.1  fvdl 		return;
    175  1.1  fvdl 	}
    176  1.1  fvdl 	rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist));
    177  1.1  fvdl 	if (rl == NULL) {
    178  1.1  fvdl 		return;
    179  1.1  fvdl 	}
    180  1.1  fvdl 	rl->prog = prog;
    181  1.1  fvdl 	rl->vers = vers;
    182  1.1  fvdl 	rl->proc = proc;
    183  1.1  fvdl 	rl->netid = nconf->nc_netid;
    184  1.1  fvdl 	if ((rbl == NULL) ||
    185  1.1  fvdl 		    (rbl->rpcb_map.r_vers != vers)) {
    186  1.1  fvdl 		rl->failure = 1;
    187  1.1  fvdl 		rl->success = 0;
    188  1.1  fvdl 	} else {
    189  1.1  fvdl 		rl->failure = 0;
    190  1.1  fvdl 		rl->success = 1;
    191  1.1  fvdl 	}
    192  1.1  fvdl 	rl->indirect = 1;
    193  1.1  fvdl 	rl->next = inf[rtype].rmtinfo;
    194  1.1  fvdl 	inf[rtype].rmtinfo = rl;
    195  1.1  fvdl 	return;
    196  1.1  fvdl }
    197  1.1  fvdl 
    198  1.1  fvdl /*
    199  1.1  fvdl  */
    200  1.1  fvdl void *
    201  1.1  fvdl rpcbproc_getstat(void *arg, struct svc_req *req, SVCXPRT *xprt,
    202  1.1  fvdl 		 rpcvers_t versnum)
    203  1.1  fvdl {
    204  1.1  fvdl 	return (void *)&inf;
    205  1.1  fvdl }
    206