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