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