xref: /netbsd-src/lib/libc/rpc/svc.c (revision 481fca6e59249d8ffcf24fef7cfbe7b131bfb080)
1 /*	$NetBSD: svc.c,v 1.21 2000/07/06 03:10:35 christos 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.21 2000/07/06 03:10:35 christos 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	RQCRED_SIZE	400		/* this size is excessive */
91 
92 #define SVC_VERSQUIET 0x0001		/* keep quiet about vers mismatch */
93 #define version_keepquiet(xp) ((u_long)(xp)->xp_p3 & SVC_VERSQUIET)
94 
95 #define max(a, b) (a > b ? a : b)
96 
97 /*
98  * The services list
99  * Each entry represents a set of procedures (an rpc program).
100  * The dispatch routine takes request structs and runs the
101  * apropriate procedure.
102  */
103 static struct svc_callout {
104 	struct svc_callout *sc_next;
105 	rpcprog_t	    sc_prog;
106 	rpcvers_t	    sc_vers;
107 	char		   *sc_netid;
108 	void		    (*sc_dispatch) __P((struct svc_req *, SVCXPRT *));
109 } *svc_head;
110 
111 #ifdef __REENT
112 extern rwlock_t svc_lock;
113 extern rwlock_t svc_fd_lock;
114 #endif
115 
116 static struct svc_callout *svc_find __P((rpcprog_t, rpcvers_t,
117 					 struct svc_callout **, char *));
118 
119 /* ***************  SVCXPRT related stuff **************** */
120 
121 /*
122  * Activate a transport handle.
123  */
124 void
125 xprt_register(xprt)
126 	SVCXPRT *xprt;
127 {
128 	int sock;
129 
130 	_DIAGASSERT(xprt != NULL);
131 
132 	sock = xprt->xp_fd;
133 
134 	rwlock_wrlock(&svc_fd_lock);
135 	if (xports == NULL) {
136 		xports = (SVCXPRT **)
137 			mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *));
138 		if (xports == NULL)
139 			return;
140 		memset(xports, '\0', FD_SETSIZE * sizeof(SVCXPRT *));
141 	}
142 	if (sock < FD_SETSIZE) {
143 		xports[sock] = xprt;
144 		FD_SET(sock, &svc_fdset);
145 		svc_maxfd = max(svc_maxfd, sock);
146 	}
147 	rwlock_unlock(&svc_fd_lock);
148 }
149 
150 /*
151  * De-activate a transport handle.
152  */
153 void
154 xprt_unregister(xprt)
155 	SVCXPRT *xprt;
156 {
157 	int sock;
158 
159 	_DIAGASSERT(xprt != NULL);
160 
161 	sock = xprt->xp_fd;
162 
163 	rwlock_wrlock(&svc_fd_lock);
164 	if ((sock < FD_SETSIZE) && (xports[sock] == xprt)) {
165 		xports[sock] = NULL;
166 		FD_CLR(sock, &svc_fdset);
167 		if (sock >= svc_maxfd) {
168 			for (svc_maxfd--; svc_maxfd>=0; svc_maxfd--)
169 				if (xports[svc_maxfd])
170 					break;
171 		}
172 	}
173 	rwlock_unlock(&svc_fd_lock);
174 }
175 
176 /*
177  * Add a service program to the callout list.
178  * The dispatch routine will be called when a rpc request for this
179  * program number comes in.
180  */
181 bool_t
182 svc_reg(xprt, prog, vers, dispatch, nconf)
183 	SVCXPRT *xprt;
184 	const rpcprog_t prog;
185 	const rpcvers_t vers;
186 	void (*dispatch) __P((struct svc_req *, SVCXPRT *));
187 	const struct netconfig *nconf;
188 {
189 	bool_t dummy;
190 	struct svc_callout *prev;
191 	struct svc_callout *s;
192 	struct netconfig *tnconf;
193 	char *netid = NULL;
194 	int flag = 0;
195 
196 /* VARIABLES PROTECTED BY svc_lock: s, prev, svc_head */
197 
198 	if (xprt->xp_netid) {
199 		netid = strdup(xprt->xp_netid);
200 		flag = 1;
201 	} else if (nconf && nconf->nc_netid) {
202 		netid = strdup(nconf->nc_netid);
203 		flag = 1;
204 	} else if ((tnconf = __rpcgettp(xprt->xp_fd)) != NULL) {
205 		netid = strdup(tnconf->nc_netid);
206 		flag = 1;
207 		freenetconfigent(tnconf);
208 	} /* must have been created with svc_raw_create */
209 	if ((netid == NULL) && (flag == 1)) {
210 		return (FALSE);
211 	}
212 
213 	rwlock_wrlock(&svc_lock);
214 	if ((s = svc_find(prog, vers, &prev, netid)) != NULL) {
215 		if (netid)
216 			free(netid);
217 		if (s->sc_dispatch == dispatch)
218 			goto rpcb_it; /* he is registering another xptr */
219 		rwlock_unlock(&svc_lock);
220 		return (FALSE);
221 	}
222 	s = mem_alloc(sizeof (struct svc_callout));
223 	if (s == NULL) {
224 		if (netid)
225 			free(netid);
226 		rwlock_unlock(&svc_lock);
227 		return (FALSE);
228 	}
229 
230 	s->sc_prog = prog;
231 	s->sc_vers = vers;
232 	s->sc_dispatch = dispatch;
233 	s->sc_netid = netid;
234 	s->sc_next = svc_head;
235 	svc_head = s;
236 
237 	if ((xprt->xp_netid == NULL) && (flag == 1) && netid)
238 		((SVCXPRT *) xprt)->xp_netid = strdup(netid);
239 
240 rpcb_it:
241 	rwlock_unlock(&svc_lock);
242 	/* now register the information with the local binder service */
243 	if (nconf) {
244 		/*LINTED const castaway*/
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 	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) {
267 		if (prev == NULL) {
268 			svc_head = s->sc_next;
269 		} else {
270 			prev->sc_next = s->sc_next;
271 		}
272 		s->sc_next = NULL;
273 		if (s->sc_netid)
274 			mem_free(s->sc_netid, sizeof (s->sc_netid) + 1);
275 		mem_free(s, sizeof (struct svc_callout));
276 	}
277 	rwlock_unlock(&svc_lock);
278 }
279 
280 /* ********************** CALLOUT list related stuff ************* */
281 
282 #ifdef PORTMAP
283 /*
284  * Add a service program to the callout list.
285  * The dispatch routine will be called when a rpc request for this
286  * program number comes in.
287  */
288 bool_t
289 svc_register(xprt, prog, vers, dispatch, protocol)
290 	SVCXPRT *xprt;
291 	u_long prog;
292 	u_long vers;
293 	void (*dispatch) __P((struct svc_req *, SVCXPRT *));
294 	int protocol;
295 {
296 	struct svc_callout *prev;
297 	struct svc_callout *s;
298 
299 	_DIAGASSERT(xprt != NULL);
300 	_DIAGASSERT(dispatch != NULL);
301 
302 	if ((s = svc_find((rpcprog_t)prog, (rpcvers_t)vers, &prev, NULL)) !=
303 	    NULL) {
304 		if (s->sc_dispatch == dispatch)
305 			goto pmap_it;  /* he is registering another xptr */
306 		return (FALSE);
307 	}
308 	s = mem_alloc(sizeof(struct svc_callout));
309 	if (s == NULL) {
310 		return (FALSE);
311 	}
312 	s->sc_prog = (rpcprog_t)prog;
313 	s->sc_vers = (rpcvers_t)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((rpcprog_t)prog, (rpcvers_t)vers, &prev, NULL)) ==
337 	    NULL)
338 		return;
339 	if (prev == NULL) {
340 		svc_head = s->sc_next;
341 	} else {
342 		prev->sc_next = s->sc_next;
343 	}
344 	s->sc_next = NULL;
345 	mem_free(s, sizeof(struct svc_callout));
346 	/* now unregister the information with the local binder service */
347 	(void)pmap_unset(prog, vers);
348 }
349 #endif /* PORTMAP */
350 
351 /*
352  * Search the callout list for a program number, return the callout
353  * struct.
354  */
355 static struct svc_callout *
356 svc_find(prog, vers, prev, netid)
357 	rpcprog_t prog;
358 	rpcvers_t vers;
359 	struct svc_callout **prev;
360 	char *netid;
361 {
362 	struct svc_callout *s, *p;
363 
364 	_DIAGASSERT(prev != NULL);
365 
366 	p = NULL;
367 	for (s = svc_head; s != NULL; s = s->sc_next) {
368 		if (((s->sc_prog == prog) && (s->sc_vers == vers)) &&
369 		    ((netid == NULL) || (s->sc_netid == NULL) ||
370 		    (strcmp(netid, s->sc_netid) == 0)))
371 			break;
372 		p = s;
373 	}
374 	*prev = p;
375 	return (s);
376 }
377 
378 /* ******************* REPLY GENERATION ROUTINES  ************ */
379 
380 /*
381  * Send a reply to an rpc request
382  */
383 bool_t
384 svc_sendreply(xprt, xdr_results, xdr_location)
385 	SVCXPRT *xprt;
386 	xdrproc_t xdr_results;
387 	caddr_t xdr_location;
388 {
389 	struct rpc_msg rply;
390 
391 	_DIAGASSERT(xprt != NULL);
392 
393 	rply.rm_direction = REPLY;
394 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
395 	rply.acpted_rply.ar_verf = xprt->xp_verf;
396 	rply.acpted_rply.ar_stat = SUCCESS;
397 	rply.acpted_rply.ar_results.where = xdr_location;
398 	rply.acpted_rply.ar_results.proc = xdr_results;
399 	return (SVC_REPLY(xprt, &rply));
400 }
401 
402 /*
403  * No procedure error reply
404  */
405 void
406 svcerr_noproc(xprt)
407 	SVCXPRT *xprt;
408 {
409 	struct rpc_msg rply;
410 
411 	_DIAGASSERT(xprt != NULL);
412 
413 	rply.rm_direction = REPLY;
414 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
415 	rply.acpted_rply.ar_verf = xprt->xp_verf;
416 	rply.acpted_rply.ar_stat = PROC_UNAVAIL;
417 	SVC_REPLY(xprt, &rply);
418 }
419 
420 /*
421  * Can't decode args error reply
422  */
423 void
424 svcerr_decode(xprt)
425 	SVCXPRT *xprt;
426 {
427 	struct rpc_msg rply;
428 
429 	_DIAGASSERT(xprt != NULL);
430 
431 	rply.rm_direction = REPLY;
432 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
433 	rply.acpted_rply.ar_verf = xprt->xp_verf;
434 	rply.acpted_rply.ar_stat = GARBAGE_ARGS;
435 	SVC_REPLY(xprt, &rply);
436 }
437 
438 /*
439  * Some system error
440  */
441 void
442 svcerr_systemerr(xprt)
443 	SVCXPRT *xprt;
444 {
445 	struct rpc_msg rply;
446 
447 	_DIAGASSERT(xprt != NULL);
448 
449 	rply.rm_direction = REPLY;
450 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
451 	rply.acpted_rply.ar_verf = xprt->xp_verf;
452 	rply.acpted_rply.ar_stat = SYSTEM_ERR;
453 	SVC_REPLY(xprt, &rply);
454 }
455 
456 #if 0
457 /*
458  * Tell RPC package to not complain about version errors to the client.	 This
459  * is useful when revving broadcast protocols that sit on a fixed address.
460  * There is really one (or should be only one) example of this kind of
461  * protocol: the portmapper (or rpc binder).
462  */
463 void
464 __svc_versquiet_on(xprt)
465 	SVCXPRT *xprt;
466 {
467 	u_long	tmp;
468 
469 	tmp = ((u_long) xprt->xp_p3) | SVC_VERSQUIET;
470 	xprt->xp_p3 = (caddr_t) tmp;
471 }
472 
473 void
474 __svc_versquiet_off(xprt)
475 	SVCXPRT *xprt;
476 {
477 	u_long	tmp;
478 
479 	tmp = ((u_long) xprt->xp_p3) & ~SVC_VERSQUIET;
480 	xprt->xp_p3 = (caddr_t) tmp;
481 }
482 
483 void
484 svc_versquiet(xprt)
485 	SVCXPRT *xprt;
486 {
487 	__svc_versquiet_on(xprt);
488 }
489 
490 int
491 __svc_versquiet_get(xprt)
492 	SVCXPRT *xprt;
493 {
494 	return ((int) xprt->xp_p3) & SVC_VERSQUIET;
495 }
496 #endif
497 
498 /*
499  * Authentication error reply
500  */
501 void
502 svcerr_auth(xprt, why)
503 	SVCXPRT *xprt;
504 	enum auth_stat why;
505 {
506 	struct rpc_msg rply;
507 
508 	_DIAGASSERT(xprt != NULL);
509 
510 	rply.rm_direction = REPLY;
511 	rply.rm_reply.rp_stat = MSG_DENIED;
512 	rply.rjcted_rply.rj_stat = AUTH_ERROR;
513 	rply.rjcted_rply.rj_why = why;
514 	SVC_REPLY(xprt, &rply);
515 }
516 
517 /*
518  * Auth too weak error reply
519  */
520 void
521 svcerr_weakauth(xprt)
522 	SVCXPRT *xprt;
523 {
524 
525 	_DIAGASSERT(xprt != NULL);
526 
527 	svcerr_auth(xprt, AUTH_TOOWEAK);
528 }
529 
530 /*
531  * Program unavailable error reply
532  */
533 void
534 svcerr_noprog(xprt)
535 	SVCXPRT *xprt;
536 {
537 	struct rpc_msg rply;
538 
539 	_DIAGASSERT(xprt != NULL);
540 
541 	rply.rm_direction = REPLY;
542 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
543 	rply.acpted_rply.ar_verf = xprt->xp_verf;
544 	rply.acpted_rply.ar_stat = PROG_UNAVAIL;
545 	SVC_REPLY(xprt, &rply);
546 }
547 
548 /*
549  * Program version mismatch error reply
550  */
551 void
552 svcerr_progvers(xprt, low_vers, high_vers)
553 	SVCXPRT *xprt;
554 	rpcvers_t low_vers;
555 	rpcvers_t high_vers;
556 {
557 	struct rpc_msg rply;
558 
559 	_DIAGASSERT(xprt != NULL);
560 
561 	rply.rm_direction = REPLY;
562 	rply.rm_reply.rp_stat = MSG_ACCEPTED;
563 	rply.acpted_rply.ar_verf = xprt->xp_verf;
564 	rply.acpted_rply.ar_stat = PROG_MISMATCH;
565 	rply.acpted_rply.ar_vers.low = (u_int32_t)low_vers;
566 	rply.acpted_rply.ar_vers.high = (u_int32_t)high_vers;
567 	SVC_REPLY(xprt, &rply);
568 }
569 
570 /* ******************* SERVER INPUT STUFF ******************* */
571 
572 /*
573  * Get server side input from some transport.
574  *
575  * Statement of authentication parameters management:
576  * This function owns and manages all authentication parameters, specifically
577  * the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
578  * the "cooked" credentials (rqst->rq_clntcred).
579  * However, this function does not know the structure of the cooked
580  * credentials, so it make the following assumptions:
581  *   a) the structure is contiguous (no pointers), and
582  *   b) the cred structure size does not exceed RQCRED_SIZE bytes.
583  * In all events, all three parameters are freed upon exit from this routine.
584  * The storage is trivially management on the call stack in user land, but
585  * is mallocated in kernel land.
586  */
587 
588 void
589 svc_getreq(rdfds)
590 	int rdfds;
591 {
592 	fd_set readfds;
593 
594 	FD_ZERO(&readfds);
595 	readfds.fds_bits[0] = rdfds;
596 	svc_getreqset(&readfds);
597 }
598 
599 void
600 svc_getreqset(readfds)
601 	fd_set *readfds;
602 {
603 	int bit, fd;
604 	int32_t mask, *maskp;
605 	int sock;
606 
607 	_DIAGASSERT(readfds != NULL);
608 
609 	maskp = readfds->fds_bits;
610 	for (sock = 0; sock < FD_SETSIZE; sock += NFDBITS) {
611 	    for (mask = *maskp++; (bit = ffs(mask)) != 0;
612 		mask ^= (1 << (bit - 1))) {
613 		/* sock has input waiting */
614 		fd = sock + bit - 1;
615 		svc_getreq_common(fd);
616 	    }
617 	}
618 }
619 
620 void
621 svc_getreq_common(fd)
622 	int fd;
623 {
624 	SVCXPRT *xprt;
625 	struct svc_req r;
626 	struct rpc_msg msg;
627 	int prog_found;
628 	rpcvers_t low_vers;
629 	rpcvers_t high_vers;
630 	enum xprt_stat stat;
631 	char cred_area[2*MAX_AUTH_BYTES + RQCRED_SIZE];
632 
633 	msg.rm_call.cb_cred.oa_base = cred_area;
634 	msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
635 	r.rq_clntcred = &(cred_area[2*MAX_AUTH_BYTES]);
636 
637 	rwlock_rdlock(&svc_fd_lock);
638 	xprt = xports[fd];
639 	rwlock_unlock(&svc_fd_lock);
640 	if (xprt == NULL)
641 		/* But do we control sock? */
642 		return;
643 	/* now receive msgs from xprtprt (support batch calls) */
644 	do {
645 		if (SVC_RECV(xprt, &msg)) {
646 
647 			/* now find the exported program and call it */
648 			struct svc_callout *s;
649 			enum auth_stat why;
650 
651 			r.rq_xprt = xprt;
652 			r.rq_prog = msg.rm_call.cb_prog;
653 			r.rq_vers = msg.rm_call.cb_vers;
654 			r.rq_proc = msg.rm_call.cb_proc;
655 			r.rq_cred = msg.rm_call.cb_cred;
656 			/* first authenticate the message */
657 			if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
658 				svcerr_auth(xprt, why);
659 				goto call_done;
660 			}
661 			/* now match message with a registered service*/
662 			prog_found = FALSE;
663 			low_vers = (rpcvers_t) -1L;
664 			high_vers = (rpcvers_t) 0L;
665 			for (s = svc_head; s != NULL; s = s->sc_next) {
666 				if (s->sc_prog == r.rq_prog) {
667 					if (s->sc_vers == r.rq_vers) {
668 						(*s->sc_dispatch)(&r, xprt);
669 						goto call_done;
670 					}  /* found correct version */
671 					prog_found = TRUE;
672 					if (s->sc_vers < low_vers)
673 						low_vers = s->sc_vers;
674 					if (s->sc_vers > high_vers)
675 						high_vers = s->sc_vers;
676 				}   /* found correct program */
677 			}
678 			/*
679 			 * if we got here, the program or version
680 			 * is not served ...
681 			 */
682 			if (prog_found)
683 				svcerr_progvers(xprt, low_vers, high_vers);
684 			else
685 				 svcerr_noprog(xprt);
686 			/* Fall through to ... */
687 		}
688 		/*
689 		 * Check if the xprt has been disconnected in a
690 		 * recursive call in the service dispatch routine.
691 		 * If so, then break.
692 		 */
693 		rwlock_rdlock(&svc_fd_lock);
694 		if (xprt != xports[fd]) {
695 			rwlock_unlock(&svc_fd_lock);
696 			break;
697 		}
698 		rwlock_unlock(&svc_fd_lock);
699 call_done:
700 		if ((stat = SVC_STAT(xprt)) == XPRT_DIED){
701 			SVC_DESTROY(xprt);
702 			break;
703 		}
704 	} while (stat == XPRT_MOREREQS);
705 }
706 
707 
708 void
709 svc_getreq_poll(pfdp, pollretval)
710 	struct pollfd	*pfdp;
711 	int	pollretval;
712 {
713 	int i;
714 	int fds_found;
715 
716 	for (i = fds_found = 0; fds_found < pollretval; i++) {
717 		struct pollfd *p = &pfdp[i];
718 
719 		if (p->revents) {
720 			/* fd has input waiting */
721 			fds_found++;
722 			/*
723 			 *	We assume that this function is only called
724 			 *	via someone select()ing from svc_fdset or
725 			 *	poll()ing from svc_pollset[].  Thus it's safe
726 			 *	to handle the POLLNVAL event by simply turning
727 			 *	the corresponding bit off in svc_fdset.  The
728 			 *	svc_pollset[] array is derived from svc_fdset
729 			 *	and so will also be updated eventually.
730 			 *
731 			 *	XXX Should we do an xprt_unregister() instead?
732 			 */
733 			if (p->revents & POLLNVAL) {
734 				rwlock_wrlock(&svc_fd_lock);
735 				FD_CLR(p->fd, &svc_fdset);
736 				rwlock_unlock(&svc_fd_lock);
737 			} else
738 				svc_getreq_common(p->fd);
739 		}
740 	}
741 }
742