svc.h revision 244008
11844Swollman/* $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $ */ 250476Speter 31638Srgrimes/* 494940Sru * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 51638Srgrimes * unrestricted use provided that this legend is included on all tape 6103713Smarkm * media and as a part of the software program in whole or part. Users 71638Srgrimes * may copy or modify Sun RPC without charge, but are not authorized 8133653Sru * to license or distribute it to anyone else except as part of a product or 9119607Sru * program developed by the user. 10119607Sru * 11119607Sru * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12119607Sru * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 13119607Sru * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14119607Sru * 15119607Sru * Sun RPC is provided with no support and without any obligation on the 16119607Sru * part of Sun Microsystems, Inc. to assist in its use, correction, 17119607Sru * modification or enhancement. 18117034Sgordon * 19119607Sru * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 201638Srgrimes * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 212827Sjkh * OR ANY PART THEREOF. 221638Srgrimes * 232827Sjkh * In no event will Sun Microsystems, Inc. be liable for any lost revenue 241638Srgrimes * or profits or other special, indirect and consequential damages, even if 25125474Sru * Sun has been advised of the possibility of such damages. 261844Swollman * 271844Swollman * Sun Microsystems, Inc. 281638Srgrimes * 2550 Garcia Avenue 2994424Sru * Mountain View, California 94043 3094424Sru * 3194424Sru * from: @(#)svc.h 1.35 88/12/17 SMI 3294424Sru * from: @(#)svc.h 1.27 94/04/25 SMI 331638Srgrimes * $FreeBSD: head/sys/rpc/svc.h 244008 2012-12-08 00:29:16Z rmacklem $ 341638Srgrimes */ 351638Srgrimes 3636054Sbde/* 37125119Sru * svc.h, Server-side remote procedure call interface. 3836054Sbde * 3936054Sbde * Copyright (C) 1986-1993 by Sun Microsystems, Inc. 4036054Sbde */ 4136054Sbde 421844Swollman#ifndef _RPC_SVC_H 431638Srgrimes#define _RPC_SVC_H 4494518Sru#include <sys/cdefs.h> 4594518Sru 4694518Sru#ifdef _KERNEL 4794518Sru#include <sys/queue.h> 4894518Sru#include <sys/_lock.h> 4994518Sru#include <sys/_mutex.h> 5094518Sru#include <sys/_sx.h> 518321Sbde#include <sys/condvar.h> 521844Swollman#include <sys/sysctl.h> 5394518Sru#endif 5494424Sru 5594424Sru/* 5694424Sru * This interface must manage two items concerning remote procedure calling: 572351Sbde * 5894424Sru * 1) An arbitrary number of transport connections upon which rpc requests 591638Srgrimes * are received. The two most notable transports are TCP and UDP; they are 602351Sbde * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; 612351Sbde * they in turn call xprt_register and xprt_unregister. 622351Sbde * 632351Sbde * 2) An arbitrary number of locally registered services. Services are 642351Sbde * described by the following four data: program number, version number, 652351Sbde * "service dispatch" function, a transport handle, and a boolean that 6633624Seivind * indicates whether or not the exported program should be registered with a 6734081Sbde * local binder service; if true the program's number and version and the 6894497Sru * port number from the transport handle are registered with the binder. 6994497Sru * These data are registered with the rpc svc system via svc_register. 7094497Sru * 7194410Sru * A service's dispatch function is called whenever an rpc request comes in 7233624Seivind * on a transport. The request's program and version numbers must match 7394518Sru * those of the registered service. The dispatch function is passed two 741638Srgrimes * parameters, struct svc_req * and SVCXPRT *, defined below. 751638Srgrimes */ 761638Srgrimes 7774806Sru/* 7874806Sru * Service control requests 791638Srgrimes */ 8058493Sru#define SVCGET_VERSQUIET 1 8174806Sru#define SVCSET_VERSQUIET 2 8274941Sru#define SVCGET_CONNMAXREC 3 8374941Sru#define SVCSET_CONNMAXREC 4 841638Srgrimes 851638Srgrimes/* 861638Srgrimes * Operations for rpc_control(). 8797769Sru */ 8874806Sru#define RPC_SVC_CONNMAXREC_SET 0 /* set max rec size, enable nonblock */ 8996164Sru#define RPC_SVC_CONNMAXREC_GET 1 9074806Sru 911638Srgrimesenum xprt_stat { 92119607Sru XPRT_DIED, 93119607Sru XPRT_MOREREQS, 94119607Sru XPRT_IDLE 951638Srgrimes}; 96119607Sru 97119607Srustruct __rpc_svcxprt; 98119607Srustruct mbuf; 99119607Sru 100125620Srustruct xp_ops { 101125620Sru#ifdef _KERNEL 10255670Sbde /* receive incoming requests */ 10324750Sbde bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *, 104125620Sru struct sockaddr **, struct mbuf **); 105125620Sru /* get transport status */ 106125620Sru enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *); 107125620Sru /* send reply */ 108125620Sru bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *, 10946541Sbde struct sockaddr *, struct mbuf *); 11094497Sru /* destroy this struct */ 11194497Sru void (*xp_destroy)(struct __rpc_svcxprt *); 11224750Sbde /* catch-all function */ 11328945Speter bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, void *); 114125620Sru#else 11524750Sbde /* receive incoming requests */ 1161638Srgrimes bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *); 1171638Srgrimes /* get transport status */ 11849328Shoek enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *); 11949328Shoek /* get arguments */ 12049328Shoek bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, void *); 12149328Shoek /* send reply */ 12249328Shoek bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *); 123125620Sru /* free mem allocated for args */ 12496163Sru bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, void *); 12599343Sru /* destroy this struct */ 12696163Sru void (*xp_destroy)(struct __rpc_svcxprt *); 1271638Srgrimes#endif 12875083Sru}; 129100872Sru 13075083Sru#ifndef _KERNEL 13175083Srustruct xp_ops2 { 132100872Sru /* catch-all function */ 13349328Shoek bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int, void *); 1341638Srgrimes}; 13575083Sru#endif 13695734Sru 1371638Srgrimes#ifdef _KERNEL 13875284Srustruct __rpc_svcpool; 13975284Srustruct __rpc_svcthread; 14099343Sru#endif 14175284Sru 14275284Sru/* 14375284Sru * Server side transport handle. In the kernel, transports have a 14475284Sru * reference count which tracks the number of currently assigned 14575284Sru * worker threads plus one for the service pool's reference. 14675284Sru */ 14775284Srutypedef struct __rpc_svcxprt { 14875284Sru#ifdef _KERNEL 14975284Sru volatile u_int xp_refs; 15075284Sru struct sx xp_lock; 15175284Sru struct __rpc_svcpool *xp_pool; /* owning pool (see below) */ 15275284Sru TAILQ_ENTRY(__rpc_svcxprt) xp_link; 15375284Sru TAILQ_ENTRY(__rpc_svcxprt) xp_alink; 15475284Sru bool_t xp_registered; /* xprt_register has been called */ 15575284Sru bool_t xp_active; /* xprt_active has been called */ 15675284Sru struct __rpc_svcthread *xp_thread; /* assigned service thread */ 15788055Sru struct socket* xp_socket; 15888055Sru const struct xp_ops *xp_ops; 159100872Sru char *xp_netid; /* network token */ 16075284Sru struct sockaddr_storage xp_ltaddr; /* local transport address */ 16194954Sru struct sockaddr_storage xp_rtaddr; /* remote transport address */ 16275284Sru void *xp_p1; /* private: for use by svc ops */ 16375284Sru void *xp_p2; /* private: for use by svc ops */ 16475284Sru void *xp_p3; /* private: for use by svc lib */ 16575284Sru int xp_type; /* transport type */ 16699257Sru int xp_idletimeout; /* idle time before closing */ 16799257Sru time_t xp_lastactive; /* time of last RPC */ 16899257Sru u_int64_t xp_sockref; /* set by nfsv4 to identify socket */ 16997769Sru int xp_upcallset; /* socket upcall is set up */ 17096668Sru#else 17199256Sru int xp_fd; 17296462Sru u_short xp_port; /* associated port number */ 17396163Sru const struct xp_ops *xp_ops; 17496164Sru int xp_addrlen; /* length of remote address */ 17599343Sru struct sockaddr_in xp_raddr; /* remote addr. (backward ABI compat) */ 17696163Sru /* XXX - fvdl stick this here for ABI backward compat reasons */ 17796163Sru const struct xp_ops2 *xp_ops2; 1781844Swollman char *xp_tp; /* transport provider device name */ 1791638Srgrimes char *xp_netid; /* network token */ 1801638Srgrimes struct netbuf xp_ltaddr; /* local transport address */ 181103713Smarkm struct netbuf xp_rtaddr; /* remote transport address */ 1821638Srgrimes struct opaque_auth xp_verf; /* raw response verifier */ 183103713Smarkm void *xp_p1; /* private: for use by svc ops */ 1841638Srgrimes void *xp_p2; /* private: for use by svc ops */ 1851638Srgrimes void *xp_p3; /* private: for use by svc lib */ 1861638Srgrimes int xp_type; /* transport type */ 1871638Srgrimes#endif 1881638Srgrimes} SVCXPRT; 18974842Sru 1901844Swollman/* 1911844Swollman * Interface to server-side authentication flavors. 19234081Sbde */ 19394113Srutypedef struct __rpc_svcauth { 19434087Sbde struct svc_auth_ops { 19534081Sbde#ifdef _KERNEL 19634081Sbde int (*svc_ah_wrap)(struct __rpc_svcauth *, struct mbuf **); 19716663Sjkh int (*svc_ah_unwrap)(struct __rpc_svcauth *, struct mbuf **); 19876861Skris void (*svc_ah_release)(struct __rpc_svcauth *); 19976861Skris#else 200 int (*svc_ah_wrap)(struct __rpc_svcauth *, XDR *, 201 xdrproc_t, caddr_t); 202 int (*svc_ah_unwrap)(struct __rpc_svcauth *, XDR *, 203 xdrproc_t, caddr_t); 204#endif 205 } *svc_ah_ops; 206 void *svc_ah_private; 207} SVCAUTH; 208 209/* 210 * Server transport extensions (accessed via xp_p3). 211 */ 212typedef struct __rpc_svcxprt_ext { 213 int xp_flags; /* versquiet */ 214 SVCAUTH xp_auth; /* interface to auth methods */ 215} SVCXPRT_EXT; 216 217#ifdef _KERNEL 218 219/* 220 * The services list 221 * Each entry represents a set of procedures (an rpc program). 222 * The dispatch routine takes request structs and runs the 223 * apropriate procedure. 224 */ 225struct svc_callout { 226 TAILQ_ENTRY(svc_callout) sc_link; 227 rpcprog_t sc_prog; 228 rpcvers_t sc_vers; 229 char *sc_netid; 230 void (*sc_dispatch)(struct svc_req *, SVCXPRT *); 231}; 232TAILQ_HEAD(svc_callout_list, svc_callout); 233 234struct __rpc_svcthread; 235 236/* 237 * Service request 238 */ 239struct svc_req { 240 STAILQ_ENTRY(svc_req) rq_link; /* list of requests for a thread */ 241 struct __rpc_svcthread *rq_thread; /* thread which is to execute this */ 242 uint32_t rq_xid; /* RPC transaction ID */ 243 uint32_t rq_prog; /* service program number */ 244 uint32_t rq_vers; /* service protocol version */ 245 uint32_t rq_proc; /* the desired procedure */ 246 size_t rq_size; /* space used by request */ 247 struct mbuf *rq_args; /* XDR-encoded procedure arguments */ 248 struct opaque_auth rq_cred; /* raw creds from the wire */ 249 struct opaque_auth rq_verf; /* verifier for the reply */ 250 void *rq_clntcred; /* read only cooked cred */ 251 SVCAUTH rq_auth; /* interface to auth methods */ 252 SVCXPRT *rq_xprt; /* associated transport */ 253 struct sockaddr *rq_addr; /* reply address or NULL if connected */ 254 void *rq_p1; /* application workspace */ 255 int rq_p2; /* application workspace */ 256 uint64_t rq_p3; /* application workspace */ 257 char rq_credarea[3*MAX_AUTH_BYTES]; 258}; 259STAILQ_HEAD(svc_reqlist, svc_req); 260 261#define svc_getrpccaller(rq) \ 262 ((rq)->rq_addr ? (rq)->rq_addr : \ 263 (struct sockaddr *) &(rq)->rq_xprt->xp_rtaddr) 264 265/* 266 * This structure is used to manage a thread which is executing 267 * requests from a service pool. A service thread is in one of three 268 * states: 269 * 270 * SVCTHREAD_SLEEPING waiting for a request to process 271 * SVCTHREAD_ACTIVE processing a request 272 * SVCTHREAD_EXITING exiting after finishing current request 273 * 274 * Threads which have no work to process sleep on the pool's sp_active 275 * list. When a transport becomes active, it is assigned a service 276 * thread to read and execute pending RPCs. 277 */ 278typedef struct __rpc_svcthread { 279 SVCXPRT *st_xprt; /* transport we are processing */ 280 struct svc_reqlist st_reqs; /* RPC requests to execute */ 281 int st_reqcount; /* number of queued reqs */ 282 struct cv st_cond; /* sleeping for work */ 283 LIST_ENTRY(__rpc_svcthread) st_link; /* all threads list */ 284 LIST_ENTRY(__rpc_svcthread) st_ilink; /* idle threads list */ 285 LIST_ENTRY(__rpc_svcthread) st_alink; /* application thread list */ 286} SVCTHREAD; 287LIST_HEAD(svcthread_list, __rpc_svcthread); 288 289/* 290 * In the kernel, we can't use global variables to store lists of 291 * transports etc. since otherwise we could not have two unrelated RPC 292 * services running, each on its own thread. We solve this by 293 * importing a tiny part of a Solaris kernel concept, SVCPOOL. 294 * 295 * A service pool contains a set of transports and service callbacks 296 * for a set of related RPC services. The pool handle should be passed 297 * when creating new transports etc. Future work may include extending 298 * this to support something similar to the Solaris multi-threaded RPC 299 * server. 300 */ 301TAILQ_HEAD(svcxprt_list, __rpc_svcxprt); 302enum svcpool_state { 303 SVCPOOL_INIT, /* svc_run not called yet */ 304 SVCPOOL_ACTIVE, /* normal running state */ 305 SVCPOOL_THREADWANTED, /* new service thread requested */ 306 SVCPOOL_THREADSTARTING, /* new service thread started */ 307 SVCPOOL_CLOSING /* svc_exit called */ 308}; 309typedef SVCTHREAD *pool_assign_fn(SVCTHREAD *, struct svc_req *); 310typedef void pool_done_fn(SVCTHREAD *, struct svc_req *); 311typedef struct __rpc_svcpool { 312 struct mtx sp_lock; /* protect the transport lists */ 313 const char *sp_name; /* pool name (e.g. "nfsd", "NLM" */ 314 enum svcpool_state sp_state; /* current pool state */ 315 struct proc *sp_proc; /* process which is in svc_run */ 316 struct svcxprt_list sp_xlist; /* all transports in the pool */ 317 struct svcxprt_list sp_active; /* transports needing service */ 318 struct svc_callout_list sp_callouts; /* (prog,vers)->dispatch list */ 319 struct svcthread_list sp_threads; /* service threads */ 320 struct svcthread_list sp_idlethreads; /* idle service threads */ 321 int sp_minthreads; /* minimum service thread count */ 322 int sp_maxthreads; /* maximum service thread count */ 323 int sp_threadcount; /* current service thread count */ 324 time_t sp_lastcreatetime; /* when we last started a thread */ 325 time_t sp_lastidlecheck; /* when we last checked idle transports */ 326 327 /* 328 * Hooks to allow an application to control request to thread 329 * placement. 330 */ 331 pool_assign_fn *sp_assign; 332 pool_done_fn *sp_done; 333 334 /* 335 * These variables are used to put an upper bound on the 336 * amount of memory used by RPC requests which are queued 337 * waiting for execution. 338 */ 339 unsigned int sp_space_low; 340 unsigned int sp_space_high; 341 unsigned int sp_space_used; 342 unsigned int sp_space_used_highest; 343 bool_t sp_space_throttled; 344 int sp_space_throttle_count; 345 346 struct replay_cache *sp_rcache; /* optional replay cache */ 347 struct sysctl_ctx_list sp_sysctl; 348} SVCPOOL; 349 350#else 351 352/* 353 * Service request 354 */ 355struct svc_req { 356 uint32_t rq_prog; /* service program number */ 357 uint32_t rq_vers; /* service protocol version */ 358 uint32_t rq_proc; /* the desired procedure */ 359 struct opaque_auth rq_cred; /* raw creds from the wire */ 360 void *rq_clntcred; /* read only cooked cred */ 361 SVCXPRT *rq_xprt; /* associated transport */ 362}; 363 364/* 365 * Approved way of getting address of caller 366 */ 367#define svc_getrpccaller(x) (&(x)->xp_rtaddr) 368 369#endif 370 371/* 372 * Operations defined on an SVCXPRT handle 373 * 374 * SVCXPRT *xprt; 375 * struct rpc_msg *msg; 376 * xdrproc_t xargs; 377 * void * argsp; 378 */ 379#ifdef _KERNEL 380 381#define SVC_ACQUIRE(xprt) \ 382 refcount_acquire(&(xprt)->xp_refs) 383 384#define SVC_RELEASE(xprt) \ 385 if (refcount_release(&(xprt)->xp_refs)) \ 386 SVC_DESTROY(xprt) 387 388#define SVC_RECV(xprt, msg, addr, args) \ 389 (*(xprt)->xp_ops->xp_recv)((xprt), (msg), (addr), (args)) 390 391#define SVC_STAT(xprt) \ 392 (*(xprt)->xp_ops->xp_stat)(xprt) 393 394#define SVC_REPLY(xprt, msg, addr, m) \ 395 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg), (addr), (m)) 396 397#define SVC_DESTROY(xprt) \ 398 (*(xprt)->xp_ops->xp_destroy)(xprt) 399 400#define SVC_CONTROL(xprt, rq, in) \ 401 (*(xprt)->xp_ops->xp_control)((xprt), (rq), (in)) 402 403#else 404 405#define SVC_RECV(xprt, msg) \ 406 (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 407#define svc_recv(xprt, msg) \ 408 (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 409 410#define SVC_STAT(xprt) \ 411 (*(xprt)->xp_ops->xp_stat)(xprt) 412#define svc_stat(xprt) \ 413 (*(xprt)->xp_ops->xp_stat)(xprt) 414 415#define SVC_GETARGS(xprt, xargs, argsp) \ 416 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 417#define svc_getargs(xprt, xargs, argsp) \ 418 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 419 420#define SVC_REPLY(xprt, msg) \ 421 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 422#define svc_reply(xprt, msg) \ 423 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 424 425#define SVC_FREEARGS(xprt, xargs, argsp) \ 426 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 427#define svc_freeargs(xprt, xargs, argsp) \ 428 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 429 430#define SVC_DESTROY(xprt) \ 431 (*(xprt)->xp_ops->xp_destroy)(xprt) 432#define svc_destroy(xprt) \ 433 (*(xprt)->xp_ops->xp_destroy)(xprt) 434 435#define SVC_CONTROL(xprt, rq, in) \ 436 (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in)) 437 438#endif 439 440#define SVC_EXT(xprt) \ 441 ((SVCXPRT_EXT *) xprt->xp_p3) 442 443#define SVC_AUTH(xprt) \ 444 (SVC_EXT(xprt)->xp_auth) 445 446/* 447 * Operations defined on an SVCAUTH handle 448 */ 449#ifdef _KERNEL 450#define SVCAUTH_WRAP(auth, mp) \ 451 ((auth)->svc_ah_ops->svc_ah_wrap(auth, mp)) 452#define SVCAUTH_UNWRAP(auth, mp) \ 453 ((auth)->svc_ah_ops->svc_ah_unwrap(auth, mp)) 454#define SVCAUTH_RELEASE(auth) \ 455 ((auth)->svc_ah_ops->svc_ah_release(auth)) 456#else 457#define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere) \ 458 ((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere)) 459#define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \ 460 ((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere)) 461#endif 462 463/* 464 * Service registration 465 * 466 * svc_reg(xprt, prog, vers, dispatch, nconf) 467 * const SVCXPRT *xprt; 468 * const rpcprog_t prog; 469 * const rpcvers_t vers; 470 * const void (*dispatch)(); 471 * const struct netconfig *nconf; 472 */ 473 474__BEGIN_DECLS 475extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t, 476 void (*)(struct svc_req *, SVCXPRT *), 477 const struct netconfig *); 478__END_DECLS 479 480/* 481 * Service un-registration 482 * 483 * svc_unreg(prog, vers) 484 * const rpcprog_t prog; 485 * const rpcvers_t vers; 486 */ 487 488__BEGIN_DECLS 489#ifdef _KERNEL 490extern void svc_unreg(SVCPOOL *, const rpcprog_t, const rpcvers_t); 491#else 492extern void svc_unreg(const rpcprog_t, const rpcvers_t); 493#endif 494__END_DECLS 495 496/* 497 * Transport registration. 498 * 499 * xprt_register(xprt) 500 * SVCXPRT *xprt; 501 */ 502__BEGIN_DECLS 503extern void xprt_register(SVCXPRT *); 504__END_DECLS 505 506/* 507 * Transport un-register 508 * 509 * xprt_unregister(xprt) 510 * SVCXPRT *xprt; 511 */ 512__BEGIN_DECLS 513extern void xprt_unregister(SVCXPRT *); 514extern void __xprt_unregister_unlocked(SVCXPRT *); 515__END_DECLS 516 517#ifdef _KERNEL 518 519/* 520 * Called when a transport has pending requests. 521 */ 522__BEGIN_DECLS 523extern void xprt_active(SVCXPRT *); 524extern void xprt_inactive(SVCXPRT *); 525extern void xprt_inactive_locked(SVCXPRT *); 526__END_DECLS 527 528#endif 529 530/* 531 * When the service routine is called, it must first check to see if it 532 * knows about the procedure; if not, it should call svcerr_noproc 533 * and return. If so, it should deserialize its arguments via 534 * SVC_GETARGS (defined above). If the deserialization does not work, 535 * svcerr_decode should be called followed by a return. Successful 536 * decoding of the arguments should be followed the execution of the 537 * procedure's code and a call to svc_sendreply. 538 * 539 * Also, if the service refuses to execute the procedure due to too- 540 * weak authentication parameters, svcerr_weakauth should be called. 541 * Note: do not confuse access-control failure with weak authentication! 542 * 543 * NB: In pure implementations of rpc, the caller always waits for a reply 544 * msg. This message is sent when svc_sendreply is called. 545 * Therefore pure service implementations should always call 546 * svc_sendreply even if the function logically returns void; use 547 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows 548 * for the abuse of pure rpc via batched calling or pipelining. In the 549 * case of a batched call, svc_sendreply should NOT be called since 550 * this would send a return message, which is what batching tries to avoid. 551 * It is the service/protocol writer's responsibility to know which calls are 552 * batched and which are not. Warning: responding to batch calls may 553 * deadlock the caller and server processes! 554 */ 555 556__BEGIN_DECLS 557#ifdef _KERNEL 558extern bool_t svc_sendreply(struct svc_req *, xdrproc_t, void *); 559extern bool_t svc_sendreply_mbuf(struct svc_req *, struct mbuf *); 560extern void svcerr_decode(struct svc_req *); 561extern void svcerr_weakauth(struct svc_req *); 562extern void svcerr_noproc(struct svc_req *); 563extern void svcerr_progvers(struct svc_req *, rpcvers_t, rpcvers_t); 564extern void svcerr_auth(struct svc_req *, enum auth_stat); 565extern void svcerr_noprog(struct svc_req *); 566extern void svcerr_systemerr(struct svc_req *); 567#else 568extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *); 569extern void svcerr_decode(SVCXPRT *); 570extern void svcerr_weakauth(SVCXPRT *); 571extern void svcerr_noproc(SVCXPRT *); 572extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t); 573extern void svcerr_auth(SVCXPRT *, enum auth_stat); 574extern void svcerr_noprog(SVCXPRT *); 575extern void svcerr_systemerr(SVCXPRT *); 576#endif 577extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t, 578 char *(*)(char *), xdrproc_t, xdrproc_t, 579 char *); 580__END_DECLS 581 582/* 583 * Lowest level dispatching -OR- who owns this process anyway. 584 * Somebody has to wait for incoming requests and then call the correct 585 * service routine. The routine svc_run does infinite waiting; i.e., 586 * svc_run never returns. 587 * Since another (co-existant) package may wish to selectively wait for 588 * incoming calls or other events outside of the rpc architecture, the 589 * routine svc_getreq is provided. It must be passed readfds, the 590 * "in-place" results of a select system call (see select, section 2). 591 */ 592 593#ifndef _KERNEL 594/* 595 * Global keeper of rpc service descriptors in use 596 * dynamic; must be inspected before each call to select 597 */ 598extern int svc_maxfd; 599#ifdef FD_SETSIZE 600extern fd_set svc_fdset; 601#define svc_fds svc_fdset.fds_bits[0] /* compatibility */ 602#else 603extern int svc_fds; 604#endif /* def FD_SETSIZE */ 605#endif 606 607/* 608 * a small program implemented by the svc_rpc implementation itself; 609 * also see clnt.h for protocol numbers. 610 */ 611__BEGIN_DECLS 612extern void rpctest_service(void); 613__END_DECLS 614 615__BEGIN_DECLS 616extern SVCXPRT *svc_xprt_alloc(void); 617extern void svc_xprt_free(SVCXPRT *); 618#ifndef _KERNEL 619extern void svc_getreq(int); 620extern void svc_getreqset(fd_set *); 621extern void svc_getreq_common(int); 622struct pollfd; 623extern void svc_getreq_poll(struct pollfd *, int); 624extern void svc_run(void); 625extern void svc_exit(void); 626#else 627extern void svc_run(SVCPOOL *); 628extern void svc_exit(SVCPOOL *); 629extern bool_t svc_getargs(struct svc_req *, xdrproc_t, void *); 630extern bool_t svc_freeargs(struct svc_req *, xdrproc_t, void *); 631extern void svc_freereq(struct svc_req *); 632 633#endif 634__END_DECLS 635 636/* 637 * Socket to use on svcxxx_create call to get default socket 638 */ 639#define RPC_ANYSOCK -1 640#define RPC_ANYFD RPC_ANYSOCK 641 642/* 643 * These are the existing service side transport implementations 644 */ 645 646__BEGIN_DECLS 647 648#ifdef _KERNEL 649 650/* 651 * Create a new service pool. 652 */ 653extern SVCPOOL* svcpool_create(const char *name, 654 struct sysctl_oid_list *sysctl_base); 655 656/* 657 * Destroy a service pool, including all registered transports. 658 */ 659extern void svcpool_destroy(SVCPOOL *pool); 660 661/* 662 * Transport independent svc_create routine. 663 */ 664extern int svc_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *), 665 const rpcprog_t, const rpcvers_t, const char *); 666/* 667 * void (*dispatch)(); -- dispatch routine 668 * const rpcprog_t prognum; -- program number 669 * const rpcvers_t versnum; -- version number 670 * const char *nettype; -- network type 671 */ 672 673 674/* 675 * Generic server creation routine. It takes a netconfig structure 676 * instead of a nettype. 677 */ 678 679extern SVCXPRT *svc_tp_create(SVCPOOL *, void (*)(struct svc_req *, SVCXPRT *), 680 const rpcprog_t, const rpcvers_t, const char *uaddr, 681 const struct netconfig *); 682 /* 683 * void (*dispatch)(); -- dispatch routine 684 * const rpcprog_t prognum; -- program number 685 * const rpcvers_t versnum; -- version number 686 * const char *uaddr; -- universal address of service 687 * const struct netconfig *nconf; -- netconfig structure 688 */ 689 690extern SVCXPRT *svc_dg_create(SVCPOOL *, struct socket *, 691 const size_t, const size_t); 692 /* 693 * struct socket *; -- open connection 694 * const size_t sendsize; -- max send size 695 * const size_t recvsize; -- max recv size 696 */ 697 698extern SVCXPRT *svc_vc_create(SVCPOOL *, struct socket *, 699 const size_t, const size_t); 700 /* 701 * struct socket *; -- open connection 702 * const size_t sendsize; -- max send size 703 * const size_t recvsize; -- max recv size 704 */ 705 706extern SVCXPRT *svc_vc_create_backchannel(SVCPOOL *); 707 708/* 709 * Generic TLI create routine 710 */ 711extern SVCXPRT *svc_tli_create(SVCPOOL *, struct socket *, 712 const struct netconfig *, const struct t_bind *, const size_t, const size_t); 713/* 714 * struct socket * so; -- connection end point 715 * const struct netconfig *nconf; -- netconfig structure for network 716 * const struct t_bind *bindaddr; -- local bind address 717 * const size_t sendsz; -- max sendsize 718 * const size_t recvsz; -- max recvsize 719 */ 720 721#else /* !_KERNEL */ 722 723/* 724 * Transport independent svc_create routine. 725 */ 726extern int svc_create(void (*)(struct svc_req *, SVCXPRT *), 727 const rpcprog_t, const rpcvers_t, const char *); 728/* 729 * void (*dispatch)(); -- dispatch routine 730 * const rpcprog_t prognum; -- program number 731 * const rpcvers_t versnum; -- version number 732 * const char *nettype; -- network type 733 */ 734 735 736/* 737 * Generic server creation routine. It takes a netconfig structure 738 * instead of a nettype. 739 */ 740 741extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *), 742 const rpcprog_t, const rpcvers_t, 743 const struct netconfig *); 744 /* 745 * void (*dispatch)(); -- dispatch routine 746 * const rpcprog_t prognum; -- program number 747 * const rpcvers_t versnum; -- version number 748 * const struct netconfig *nconf; -- netconfig structure 749 */ 750 751/* 752 * Generic TLI create routine 753 */ 754extern SVCXPRT *svc_tli_create(const int, const struct netconfig *, 755 const struct t_bind *, const u_int, 756 const u_int); 757/* 758 * const int fd; -- connection end point 759 * const struct netconfig *nconf; -- netconfig structure for network 760 * const struct t_bind *bindaddr; -- local bind address 761 * const u_int sendsz; -- max sendsize 762 * const u_int recvsz; -- max recvsize 763 */ 764 765/* 766 * Connectionless and connectionful create routines 767 */ 768 769extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int); 770/* 771 * const int fd; -- open connection end point 772 * const u_int sendsize; -- max send size 773 * const u_int recvsize; -- max recv size 774 */ 775 776/* 777 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create(). 778 */ 779extern SVCXPRT *svcunix_create(int, u_int, u_int, char *); 780 781extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int); 782 /* 783 * const int fd; -- open connection 784 * const u_int sendsize; -- max send size 785 * const u_int recvsize; -- max recv size 786 */ 787 788 789/* 790 * the routine takes any *open* connection 791 * descriptor as its first input and is used for open connections. 792 */ 793extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int); 794/* 795 * const int fd; -- open connection end point 796 * const u_int sendsize; -- max send size 797 * const u_int recvsize; -- max recv size 798 */ 799 800/* 801 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create(). 802 */ 803extern SVCXPRT *svcunixfd_create(int, u_int, u_int); 804 805/* 806 * Memory based rpc (for speed check and testing) 807 */ 808extern SVCXPRT *svc_raw_create(void); 809 810/* 811 * svc_dg_enable_cache() enables the cache on dg transports. 812 */ 813int svc_dg_enablecache(SVCXPRT *, const u_int); 814 815int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid); 816 817#endif /* !_KERNEL */ 818 819__END_DECLS 820 821#ifndef _KERNEL 822/* for backward compatibility */ 823#include <rpc/svc_soc.h> 824#endif 825 826#endif /* !_RPC_SVC_H */ 827