Home | History | Annotate | Line # | Download | only in rpcbind
rpcb_stat.c revision 1.6.2.1
      1  1.6.2.1  pgoyette /*	$NetBSD: rpcb_stat.c,v 1.6.2.1 2019/01/18 08:51:02 pgoyette Exp $	*/
      2      1.6  christos /* $FreeBSD: head/usr.sbin/rpcbind/rpcb_stat.c 301605 2016-06-08 12:45:22Z ngie $ */
      3      1.1      fvdl 
      4      1.6  christos /*-
      5      1.6  christos  * Copyright (c) 2009, Sun Microsystems, Inc.
      6      1.6  christos  * All rights reserved.
      7      1.6  christos  *
      8      1.6  christos  * Redistribution and use in source and binary forms, with or without
      9      1.6  christos  * modification, are permitted provided that the following conditions are met:
     10      1.6  christos  * - Redistributions of source code must retain the above copyright notice,
     11      1.6  christos  *   this list of conditions and the following disclaimer.
     12      1.6  christos  * - Redistributions in binary form must reproduce the above copyright notice,
     13      1.6  christos  *   this list of conditions and the following disclaimer in the documentation
     14      1.6  christos  *   and/or other materials provided with the distribution.
     15      1.6  christos  * - Neither the name of Sun Microsystems, Inc. nor the names of its
     16      1.6  christos  *   contributors may be used to endorse or promote products derived
     17      1.6  christos  *   from this software without specific prior written permission.
     18      1.6  christos  *
     19      1.6  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     20      1.6  christos  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21      1.6  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22      1.6  christos  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
     23      1.6  christos  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.6  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.6  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.6  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.6  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.6  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.6  christos  * POSSIBILITY OF SUCH DAMAGE.
     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.5  christos rpcbs_init(void)
     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.5  christos rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers,
    104      1.5  christos     const char *netid, const 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.3      fvdl 			if ((uaddr == NULL) || (uaddr[0] == 0))
    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.6.2.1  pgoyette 	al = malloc(sizeof(*al));
    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.3      fvdl 	if ((uaddr == NULL) || (uaddr[0] == 0)) {
    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.4      elad 	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.6.2.1  pgoyette 	rl = malloc(sizeof(*rl));
    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 void *
    200      1.6  christos rpcbproc_getstat(void *arg __unused, struct svc_req *req __unused,
    201      1.6  christos     SVCXPRT *xprt __unused, rpcvers_t versnum __unused)
    202      1.1      fvdl {
    203      1.1      fvdl 	return (void *)&inf;
    204      1.1      fvdl }
    205