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