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