Home | History | Annotate | Line # | Download | only in rpc
svc.c revision 1.19.2.1
      1 /*	$NetBSD: svc.c,v 1.19.2.1 2000/06/23 16:17:50 minoura Exp $	*/
      2 
      3 /*
      4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5  * unrestricted use provided that this legend is included on all tape
      6  * media and as a part of the software program in whole or part.  Users
      7  * may copy or modify Sun RPC without charge, but are not authorized
      8  * to license or distribute it to anyone else except as part of a product or
      9  * program developed by the user.
     10  *
     11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14  *
     15  * Sun RPC is provided with no support and without any obligation on the
     16  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17  * modification or enhancement.
     18  *
     19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21  * OR ANY PART THEREOF.
     22  *
     23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24  * or profits or other special, indirect and consequential damages, even if
     25  * Sun has been advised of the possibility of such damages.
     26  *
     27  * Sun Microsystems, Inc.
     28  * 2550 Garcia Avenue
     29  * Mountain View, California  94043
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #if defined(LIBC_SCCS) && !defined(lint)
     34 #if 0
     35 static char *sccsid = "@(#)svc.c 1.44 88/02/08 Copyr 1984 Sun Micro";
     36 static char *sccsid = "@(#)svc.c	2.4 88/08/11 4.0 RPCSRC";
     37 #else
     38 __RCSID("$NetBSD: svc.c,v 1.19.2.1 2000/06/23 16:17:50 minoura Exp $");
     39 #endif
     40 #endif
     41 
     42 /*
     43  * svc.c, Server-side remote procedure call interface.
     44  *
     45  * There are two sets of procedures here.  The xprt routines are
     46  * for handling transport handles.  The svc routines handle the
     47  * list of service routines.
     48  *
     49  * Copyright (C) 1984, Sun Microsystems, Inc.
     50  */
     51 
     52 #include "namespace.h"
     53 #include "reentrant.h"
     54 #include <sys/types.h>
     55 #include <sys/poll.h>
     56 #include <assert.h>
     57 #include <errno.h>
     58 #include <stdlib.h>
     59 #include <string.h>
     60 
     61 #include <rpc/rpc.h>
     62 #ifdef PORTMAP
     63 #include <rpc/pmap_clnt.h>
     64 #endif
     65 
     66 #include "rpc_com.h"
     67 
     68 #ifdef __weak_alias
     69 __weak_alias(svc_getreq,_svc_getreq)
     70 __weak_alias(svc_getreqset,_svc_getreqset)
     71 __weak_alias(svc_getreq_common,_svc_getreq_common)
     72 __weak_alias(svc_register,_svc_register)
     73 __weak_alias(svc_reg,_svc_reg)
     74 __weak_alias(svc_unreg,_svc_unreg)
     75 __weak_alias(svc_sendreply,_svc_sendreply)
     76 __weak_alias(svc_unregister,_svc_unregister)
     77 __weak_alias(svcerr_auth,_svcerr_auth)
     78 __weak_alias(svcerr_decode,_svcerr_decode)
     79 __weak_alias(svcerr_noproc,_svcerr_noproc)
     80 __weak_alias(svcerr_noprog,_svcerr_noprog)
     81 __weak_alias(svcerr_progvers,_svcerr_progvers)
     82 __weak_alias(svcerr_systemerr,_svcerr_systemerr)
     83 __weak_alias(svcerr_weakauth,_svcerr_weakauth)
     84 __weak_alias(xprt_register,_xprt_register)
     85 __weak_alias(xprt_unregister,_xprt_unregister)
     86 #endif
     87 
     88 static SVCXPRT **xports;
     89 
     90 #define NULL_SVC ((struct svc_callout *)0)
     91 #define	RQCRED_SIZE	400		/* this size is excessive */
     92 
     93 #define SVC_VERSQUIET 0x0001		/* keep quiet about vers mismatch */
     94 #define version_keepquiet(xp) ((u_long)(xp)->xp_p3 & SVC_VERSQUIET)
     95 
     96 #define max(a, b) (a > b ? a : b)
     97 
     98 /*
     99  * The services list
    100  * Each entry represents a set of procedures (an rpc program).
    101  * The dispatch routine takes request structs and runs the
    102  * apropriate procedure.
    103  */
    104 static struct svc_callout {
    105 	struct svc_callout *sc_next;
    106 	rpcprog_t	    sc_prog;
    107 	rpcvers_t	    sc_vers;
    108 	char		   *sc_netid;
    109 	void		    (*sc_dispatch) __P((struct svc_req *, SVCXPRT *));
    110 } *svc_head;
    111 
    112 #ifdef __REENT
    113 extern rwlock_t svc_lock;
    114 extern rwlock_t svc_fd_lock;
    115 #endif
    116 
    117 static struct svc_callout *svc_find __P((rpcprog_t, rpcvers_t,
    118 					 struct svc_callout **, char *));
    119 
    120 /* ***************  SVCXPRT related stuff **************** */
    121 
    122 /*
    123  * Activate a transport handle.
    124  */
    125 void
    126 xprt_register(xprt)
    127 	SVCXPRT *xprt;
    128 {
    129 	int sock;
    130 
    131 	_DIAGASSERT(xprt != NULL);
    132 
    133 	sock = xprt->xp_fd;
    134 
    135 	rwlock_wrlock(&svc_fd_lock);
    136 	if (xports == NULL) {
    137 		xports = (SVCXPRT **)
    138 			mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *));
    139 		if (xports == NULL)
    140 			return;
    141 		memset(xports, '\0', FD_SETSIZE * sizeof(SVCXPRT *));
    142 	}
    143 	if (sock < FD_SETSIZE) {
    144 		xports[sock] = xprt;
    145 		FD_SET(sock, &svc_fdset);
    146 		svc_maxfd = max(svc_maxfd, sock);
    147 	}
    148 	rwlock_unlock(&svc_fd_lock);
    149 }
    150 
    151 /*
    152  * De-activate a transport handle.
    153  */
    154 void
    155 xprt_unregister(xprt)
    156 	SVCXPRT *xprt;
    157 {
    158 	int sock;
    159 
    160 	_DIAGASSERT(xprt != NULL);
    161 
    162 	sock = xprt->xp_fd;
    163 
    164 	rwlock_wrlock(&svc_fd_lock);
    165 	if ((sock < FD_SETSIZE) && (xports[sock] == xprt)) {
    166 		xports[sock] = (SVCXPRT *)0;
    167 		FD_CLR(sock, &svc_fdset);
    168 		if (sock >= svc_maxfd) {
    169 			for (svc_maxfd--; svc_maxfd>=0; svc_maxfd--)
    170 				if (xports[svc_maxfd])
    171 					break;
    172 		}
    173 	}
    174 	rwlock_unlock(&svc_fd_lock);
    175 }
    176 
    177 /*
    178  * Add a service program to the callout list.
    179  * The dispatch routine will be called when a rpc request for this
    180  * program number comes in.
    181  */
    182 bool_t
    183 svc_reg(xprt, prog, vers, dispatch, nconf)
    184 	SVCXPRT *xprt;
    185 	const rpcprog_t prog;
    186 	const rpcvers_t vers;
    187 	void (*dispatch) __P((struct svc_req *, SVCXPRT *));
    188 	const struct netconfig *nconf;
    189 {
    190 	bool_t dummy;
    191 	struct svc_callout *prev;
    192 	register struct svc_callout *s;
    193 	struct netconfig *tnconf;
    194 	register char *netid = NULL;
    195 	int flag = 0;
    196 
    197 /* VARIABLES PROTECTED BY svc_lock: s, prev, svc_head */
    198 
    199 	if (xprt->xp_netid) {
    200 		netid = strdup(xprt->xp_netid);
    201 		flag = 1;
    202 	} else if (nconf && nconf->nc_netid) {
    203 		netid = strdup(nconf->nc_netid);
    204 		flag = 1;
    205 	} else if ((tnconf = __rpcgettp(xprt->xp_fd)) != NULL) {
    206 		netid = strdup(tnconf->nc_netid);
    207 		flag = 1;
    208 		freenetconfigent(tnconf);
    209 	} /* must have been created with svc_raw_create */
    210 	if ((netid == NULL) && (flag == 1)) {
    211 		return (FALSE);
    212 	}
    213 
    214 	rwlock_wrlock(&svc_lock);
    215 	if ((s = svc_find(prog, vers, &prev, netid)) != NULL_SVC) {
    216 		if (netid)
    217 			free(netid);
    218 		if (s->sc_dispatch == dispatch)
    219 			goto rpcb_it; /* he is registering another xptr */
    220 		rwlock_unlock(&svc_lock);
    221 		return (FALSE);
    222 	}
    223 	s = (struct svc_callout *)mem_alloc(sizeof (struct svc_callout));
    224 	if (s == (struct svc_callout *)NULL) {
    225 		if (netid)
    226 			free(netid);
    227 		rwlock_unlock(&svc_lock);
    228 		return (FALSE);
    229 	}
    230 
    231 	s->sc_prog = prog;
    232 	s->sc_vers = vers;
    233 	s->sc_dispatch = dispatch;
    234 	s->sc_netid = netid;
    235 	s->sc_next = svc_head;
    236 	svc_head = s;
    237 
    238 	if ((xprt->xp_netid == NULL) && (flag == 1) && netid)
    239 		((SVCXPRT *) xprt)->xp_netid = strdup(netid);
    240 
    241 rpcb_it:
    242 	rwlock_unlock(&svc_lock);
    243 	/* now register the information with the local binder service */
    244 	if (nconf) {
    245 		dummy = rpcb_set(prog, vers, (struct netconfig *) nconf,
    246 		&((SVCXPRT *) xprt)->xp_ltaddr);
    247 		return (dummy);
    248 	}
    249 	return (TRUE);
    250 }
    251 
    252 /*
    253  * Remove a service program from the callout list.
    254  */
    255 void
    256 svc_unreg(prog, vers)
    257 	const rpcprog_t prog;
    258 	const rpcvers_t vers;
    259 {
    260 	struct svc_callout *prev;
    261 	register struct svc_callout *s;
    262 
    263 	/* unregister the information anyway */
    264 	(void) rpcb_unset(prog, vers, NULL);
    265 	rwlock_wrlock(&svc_lock);
    266 	while ((s = svc_find(prog, vers, &prev, NULL)) != NULL_SVC) {
    267 		if (prev == NULL_SVC) {
    268 			svc_head = s->sc_next;
    269 		} else {
    270 			prev->sc_next = s->sc_next;
    271 		}
    272 		s->sc_next = NULL_SVC;
    273 		if (s->sc_netid)
    274 			mem_free((char *)s->sc_netid,
    275 					(u_int)sizeof (s->sc_netid) + 1);
    276 		mem_free((char *)s, (u_int) sizeof (struct svc_callout));
    277 	}
    278 	rwlock_unlock(&svc_lock);
    279 }
    280 
    281 /* ********************** CALLOUT list related stuff ************* */
    282 
    283 #ifdef PORTMAP
    284 /*
    285  * Add a service program to the callout list.
    286  * The dispatch routine will be called when a rpc request for this
    287  * program number comes in.
    288  */
    289 bool_t
    290 svc_register(xprt, prog, vers, dispatch, protocol)
    291 	SVCXPRT *xprt;
    292 	u_long prog;
    293 	u_long vers;
    294 	void (*dispatch) __P((struct svc_req *, SVCXPRT *));
    295 	int protocol;
    296 {
    297 	struct svc_callout *prev;
    298 	struct svc_callout *s;
    299 
    300 	_DIAGASSERT(xprt != NULL);
    301 	_DIAGASSERT(dispatch != NULL);
    302 
    303 	if ((s = svc_find(prog, vers, &prev, NULL)) != NULL_SVC) {
    304 		if (s->sc_dispatch == dispatch)
    305 			goto pmap_it;  /* he is registering another xptr */
    306 		return (FALSE);
    307 	}
    308 	s = (struct svc_callout *)mem_alloc(sizeof(struct svc_callout));
    309 	if (s == (struct svc_callout *)0) {
    310 		return (FALSE);
    311 	}
    312 	s->sc_prog = prog;
    313 	s->sc_vers = vers;
    314 	s->sc_dispatch = dispatch;
    315 	s->sc_next = svc_head;
    316 	svc_head = s;
    317 pmap_it:
    318 	/* now register the information with the local binder service */
    319 	if (protocol) {
    320 		return (pmap_set(prog, vers, protocol, xprt->xp_port));
    321 	}
    322 	return (TRUE);
    323 }
    324 
    325 /*
    326  * Remove a service program from the callout list.
    327  */
    328 void
    329 svc_unregister(prog, vers)
    330 	u_long prog;
    331 	u_long vers;
    332 {
    333 	struct svc_callout *prev;
    334 	struct svc_callout *s;
    335 
    336 	if ((s = svc_find(prog, vers, &prev, NULL)) == NULL_SVC)
    337 		return;
    338 	if (prev == NULL_SVC) {
    339 		svc_head = s->sc_next;
    340 	} else {
    341 		prev->sc_next = s->sc_next;
    342 	}
    343 	s->sc_next = NULL_SVC;
    344 	mem_free(s, sizeof(struct svc_callout));
    345 	/* now unregister the information with the local binder service */
    346 	(void)pmap_unset(prog, vers);
    347 }
    348 #endif /* PORTMAP */
    349 
    350 /*
    351  * Search the callout list for a program number, return the callout
    352  * struct.
    353  */
    354 static struct svc_callout *
    355 svc_find(prog, vers, prev, netid)
    356 	rpcprog_t prog;
    357 	rpcvers_t vers;
    358 	struct svc_callout **prev;
    359 	char *netid;
    360 {
    361 	struct svc_callout *s, *p;
    362 
    363 	_DIAGASSERT(prev != NULL);
    364 
    365 	p = NULL_SVC;
    366 	for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
    367 		if (((s->sc_prog == prog) && (s->sc_vers == vers)) &&
    368 		    ((netid == NULL) || (s->sc_netid == NULL) ||
    369 		    (strcmp(netid, s->sc_netid) == 0)))
    370 			break;
    371 		p = s;
    372 	}
    373 	*prev = p;
    374 	return (s);
    375 }
    376 
    377 /* ******************* REPLY GENERATION ROUTINES  ************ */
    378 
    379 /*
    380  * Send a reply to an rpc request
    381  */
    382 bool_t
    383 svc_sendreply(xprt, xdr_results, xdr_location)
    384 	SVCXPRT *xprt;
    385 	xdrproc_t xdr_results;
    386 	caddr_t xdr_location;
    387 {
    388 	struct rpc_msg rply;
    389 
    390 	_DIAGASSERT(xprt != NULL);
    391 
    392 	rply.rm_direction = REPLY;
    393 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
    394 	rply.acpted_rply.ar_verf = xprt->xp_verf;
    395 	rply.acpted_rply.ar_stat = SUCCESS;
    396 	rply.acpted_rply.ar_results.where = xdr_location;
    397 	rply.acpted_rply.ar_results.proc = xdr_results;
    398 	return (SVC_REPLY(xprt, &rply));
    399 }
    400 
    401 /*
    402  * No procedure error reply
    403  */
    404 void
    405 svcerr_noproc(xprt)
    406 	SVCXPRT *xprt;
    407 {
    408 	struct rpc_msg rply;
    409 
    410 	_DIAGASSERT(xprt != NULL);
    411 
    412 	rply.rm_direction = REPLY;
    413 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
    414 	rply.acpted_rply.ar_verf = xprt->xp_verf;
    415 	rply.acpted_rply.ar_stat = PROC_UNAVAIL;
    416 	SVC_REPLY(xprt, &rply);
    417 }
    418 
    419 /*
    420  * Can't decode args error reply
    421  */
    422 void
    423 svcerr_decode(xprt)
    424 	SVCXPRT *xprt;
    425 {
    426 	struct rpc_msg rply;
    427 
    428 	_DIAGASSERT(xprt != NULL);
    429 
    430 	rply.rm_direction = REPLY;
    431 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
    432 	rply.acpted_rply.ar_verf = xprt->xp_verf;
    433 	rply.acpted_rply.ar_stat = GARBAGE_ARGS;
    434 	SVC_REPLY(xprt, &rply);
    435 }
    436 
    437 /*
    438  * Some system error
    439  */
    440 void
    441 svcerr_systemerr(xprt)
    442 	SVCXPRT *xprt;
    443 {
    444 	struct rpc_msg rply;
    445 
    446 	_DIAGASSERT(xprt != NULL);
    447 
    448 	rply.rm_direction = REPLY;
    449 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
    450 	rply.acpted_rply.ar_verf = xprt->xp_verf;
    451 	rply.acpted_rply.ar_stat = SYSTEM_ERR;
    452 	SVC_REPLY(xprt, &rply);
    453 }
    454 
    455 #if 0
    456 /*
    457  * Tell RPC package to not complain about version errors to the client.	 This
    458  * is useful when revving broadcast protocols that sit on a fixed address.
    459  * There is really one (or should be only one) example of this kind of
    460  * protocol: the portmapper (or rpc binder).
    461  */
    462 void
    463 __svc_versquiet_on(xprt)
    464 	register SVCXPRT *xprt;
    465 {
    466 	u_long	tmp;
    467 
    468 	tmp = ((u_long) xprt->xp_p3) | SVC_VERSQUIET;
    469 	xprt->xp_p3 = (caddr_t) tmp;
    470 }
    471 
    472 void
    473 __svc_versquiet_off(xprt)
    474 	register SVCXPRT *xprt;
    475 {
    476 	u_long	tmp;
    477 
    478 	tmp = ((u_long) xprt->xp_p3) & ~SVC_VERSQUIET;
    479 	xprt->xp_p3 = (caddr_t) tmp;
    480 }
    481 
    482 void
    483 svc_versquiet(xprt)
    484 	register SVCXPRT *xprt;
    485 {
    486 	__svc_versquiet_on(xprt);
    487 }
    488 
    489 int
    490 __svc_versquiet_get(xprt)
    491 	register SVCXPRT *xprt;
    492 {
    493 	return ((int) xprt->xp_p3) & SVC_VERSQUIET;
    494 }
    495 #endif
    496 
    497 /*
    498  * Authentication error reply
    499  */
    500 void
    501 svcerr_auth(xprt, why)
    502 	SVCXPRT *xprt;
    503 	enum auth_stat why;
    504 {
    505 	struct rpc_msg rply;
    506 
    507 	_DIAGASSERT(xprt != NULL);
    508 
    509 	rply.rm_direction = REPLY;
    510 	rply.rm_reply.rp_stat = MSG_DENIED;
    511 	rply.rjcted_rply.rj_stat = AUTH_ERROR;
    512 	rply.rjcted_rply.rj_why = why;
    513 	SVC_REPLY(xprt, &rply);
    514 }
    515 
    516 /*
    517  * Auth too weak error reply
    518  */
    519 void
    520 svcerr_weakauth(xprt)
    521 	SVCXPRT *xprt;
    522 {
    523 
    524 	_DIAGASSERT(xprt != NULL);
    525 
    526 	svcerr_auth(xprt, AUTH_TOOWEAK);
    527 }
    528 
    529 /*
    530  * Program unavailable error reply
    531  */
    532 void
    533 svcerr_noprog(xprt)
    534 	SVCXPRT *xprt;
    535 {
    536 	struct rpc_msg rply;
    537 
    538 	_DIAGASSERT(xprt != NULL);
    539 
    540 	rply.rm_direction = REPLY;
    541 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
    542 	rply.acpted_rply.ar_verf = xprt->xp_verf;
    543 	rply.acpted_rply.ar_stat = PROG_UNAVAIL;
    544 	SVC_REPLY(xprt, &rply);
    545 }
    546 
    547 /*
    548  * Program version mismatch error reply
    549  */
    550 void
    551 svcerr_progvers(xprt, low_vers, high_vers)
    552 	SVCXPRT *xprt;
    553 	rpcvers_t low_vers;
    554 	rpcvers_t high_vers;
    555 {
    556 	struct rpc_msg rply;
    557 
    558 	_DIAGASSERT(xprt != NULL);
    559 
    560 	rply.rm_direction = REPLY;
    561 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
    562 	rply.acpted_rply.ar_verf = xprt->xp_verf;
    563 	rply.acpted_rply.ar_stat = PROG_MISMATCH;
    564 	rply.acpted_rply.ar_vers.low = (u_int32_t)low_vers;
    565 	rply.acpted_rply.ar_vers.high = (u_int32_t)high_vers;
    566 	SVC_REPLY(xprt, &rply);
    567 }
    568 
    569 /* ******************* SERVER INPUT STUFF ******************* */
    570 
    571 /*
    572  * Get server side input from some transport.
    573  *
    574  * Statement of authentication parameters management:
    575  * This function owns and manages all authentication parameters, specifically
    576  * the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
    577  * the "cooked" credentials (rqst->rq_clntcred).
    578  * However, this function does not know the structure of the cooked
    579  * credentials, so it make the following assumptions:
    580  *   a) the structure is contiguous (no pointers), and
    581  *   b) the cred structure size does not exceed RQCRED_SIZE bytes.
    582  * In all events, all three parameters are freed upon exit from this routine.
    583  * The storage is trivially management on the call stack in user land, but
    584  * is mallocated in kernel land.
    585  */
    586 
    587 void
    588 svc_getreq(rdfds)
    589 	int rdfds;
    590 {
    591 	fd_set readfds;
    592 
    593 	FD_ZERO(&readfds);
    594 	readfds.fds_bits[0] = rdfds;
    595 	svc_getreqset(&readfds);
    596 }
    597 
    598 void
    599 svc_getreqset(readfds)
    600 	fd_set *readfds;
    601 {
    602 	int bit, fd;
    603 	int32_t mask, *maskp;
    604 	int sock;
    605 
    606 	_DIAGASSERT(readfds != NULL);
    607 
    608 	maskp = readfds->fds_bits;
    609 	for (sock = 0; sock < FD_SETSIZE; sock += NFDBITS) {
    610 	    for (mask = *maskp++; (bit = ffs(mask)) != 0;
    611 		mask ^= (1 << (bit - 1))) {
    612 		/* sock has input waiting */
    613 		fd = sock + bit - 1;
    614 		svc_getreq_common(fd);
    615 	    }
    616 	}
    617 }
    618 
    619 void
    620 svc_getreq_common(fd)
    621 	int fd;
    622 {
    623 	SVCXPRT *xprt;
    624 	struct svc_req r;
    625 	struct rpc_msg msg;
    626 	int prog_found;
    627 	rpcvers_t low_vers;
    628 	rpcvers_t high_vers;
    629 	enum xprt_stat stat;
    630 	char cred_area[2*MAX_AUTH_BYTES + RQCRED_SIZE];
    631 
    632 	msg.rm_call.cb_cred.oa_base = cred_area;
    633 	msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
    634 	r.rq_clntcred = &(cred_area[2*MAX_AUTH_BYTES]);
    635 
    636 	rwlock_rdlock(&svc_fd_lock);
    637 	xprt = xports[fd];
    638 	rwlock_unlock(&svc_fd_lock);
    639 	if (xprt == NULL)
    640 		/* But do we control sock? */
    641 		return;
    642 	/* now receive msgs from xprtprt (support batch calls) */
    643 	do {
    644 		if (SVC_RECV(xprt, &msg)) {
    645 
    646 			/* now find the exported program and call it */
    647 			struct svc_callout *s;
    648 			enum auth_stat why;
    649 
    650 			r.rq_xprt = xprt;
    651 			r.rq_prog = msg.rm_call.cb_prog;
    652 			r.rq_vers = msg.rm_call.cb_vers;
    653 			r.rq_proc = msg.rm_call.cb_proc;
    654 			r.rq_cred = msg.rm_call.cb_cred;
    655 			/* first authenticate the message */
    656 			if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
    657 				svcerr_auth(xprt, why);
    658 				goto call_done;
    659 			}
    660 			/* now match message with a registered service*/
    661 			prog_found = FALSE;
    662 			low_vers = (rpcvers_t) -1L;
    663 			high_vers = (rpcvers_t) 0L;
    664 			for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
    665 				if (s->sc_prog == r.rq_prog) {
    666 					if (s->sc_vers == r.rq_vers) {
    667 						(*s->sc_dispatch)(&r, xprt);
    668 						goto call_done;
    669 					}  /* found correct version */
    670 					prog_found = TRUE;
    671 					if (s->sc_vers < low_vers)
    672 						low_vers = s->sc_vers;
    673 					if (s->sc_vers > high_vers)
    674 						high_vers = s->sc_vers;
    675 				}   /* found correct program */
    676 			}
    677 			/*
    678 			 * if we got here, the program or version
    679 			 * is not served ...
    680 			 */
    681 			if (prog_found)
    682 				svcerr_progvers(xprt, low_vers, high_vers);
    683 			else
    684 				 svcerr_noprog(xprt);
    685 			/* Fall through to ... */
    686 		}
    687 		/*
    688 		 * Check if the xprt has been disconnected in a
    689 		 * recursive call in the service dispatch routine.
    690 		 * If so, then break.
    691 		 */
    692 		rwlock_rdlock(&svc_fd_lock);
    693 		if (xprt != xports[fd]) {
    694 			rwlock_unlock(&svc_fd_lock);
    695 			break;
    696 		}
    697 		rwlock_unlock(&svc_fd_lock);
    698 call_done:
    699 		if ((stat = SVC_STAT(xprt)) == XPRT_DIED){
    700 			SVC_DESTROY(xprt);
    701 			break;
    702 		}
    703 	} while (stat == XPRT_MOREREQS);
    704 }
    705 
    706 
    707 void
    708 svc_getreq_poll(pfdp, pollretval)
    709 	struct pollfd	*pfdp;
    710 	int	pollretval;
    711 {
    712 	int i;
    713 	int fds_found;
    714 
    715 	for (i = fds_found = 0; fds_found < pollretval; i++) {
    716 		register struct pollfd *p = &pfdp[i];
    717 
    718 		if (p->revents) {
    719 			/* fd has input waiting */
    720 			fds_found++;
    721 			/*
    722 			 *	We assume that this function is only called
    723 			 *	via someone select()ing from svc_fdset or
    724 			 *	poll()ing from svc_pollset[].  Thus it's safe
    725 			 *	to handle the POLLNVAL event by simply turning
    726 			 *	the corresponding bit off in svc_fdset.  The
    727 			 *	svc_pollset[] array is derived from svc_fdset
    728 			 *	and so will also be updated eventually.
    729 			 *
    730 			 *	XXX Should we do an xprt_unregister() instead?
    731 			 */
    732 			if (p->revents & POLLNVAL) {
    733 				rwlock_wrlock(&svc_fd_lock);
    734 				FD_CLR(p->fd, &svc_fdset);
    735 				rwlock_unlock(&svc_fd_lock);
    736 			} else
    737 				svc_getreq_common(p->fd);
    738 		}
    739 	}
    740 }
    741