1dba7a33eSGarrett Wollman /* 2dba7a33eSGarrett Wollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3dba7a33eSGarrett Wollman * unrestricted use provided that this legend is included on all tape 4dba7a33eSGarrett Wollman * media and as a part of the software program in whole or part. Users 5dba7a33eSGarrett Wollman * may copy or modify Sun RPC without charge, but are not authorized 6dba7a33eSGarrett Wollman * to license or distribute it to anyone else except as part of a product or 7dba7a33eSGarrett Wollman * program developed by the user. 8dba7a33eSGarrett Wollman * 9dba7a33eSGarrett Wollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1071d9c781SMike Pritchard * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 11dba7a33eSGarrett Wollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12dba7a33eSGarrett Wollman * 13dba7a33eSGarrett Wollman * Sun RPC is provided with no support and without any obligation on the 14dba7a33eSGarrett Wollman * part of Sun Microsystems, Inc. to assist in its use, correction, 15dba7a33eSGarrett Wollman * modification or enhancement. 16dba7a33eSGarrett Wollman * 17dba7a33eSGarrett Wollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18dba7a33eSGarrett Wollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19dba7a33eSGarrett Wollman * OR ANY PART THEREOF. 20dba7a33eSGarrett Wollman * 21dba7a33eSGarrett Wollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22dba7a33eSGarrett Wollman * or profits or other special, indirect and consequential damages, even if 23dba7a33eSGarrett Wollman * Sun has been advised of the possibility of such damages. 24dba7a33eSGarrett Wollman * 25dba7a33eSGarrett Wollman * Sun Microsystems, Inc. 26dba7a33eSGarrett Wollman * 2550 Garcia Avenue 27dba7a33eSGarrett Wollman * Mountain View, California 94043 2886b9a9ccSGarrett Wollman * 2986b9a9ccSGarrett Wollman * from: @(#)svc.h 1.20 88/02/08 SMI 3086b9a9ccSGarrett Wollman * from: @(#)svc.h 2.2 88/07/29 4.0 RPCSRC 3170de0abfSPeter Wemm * $Id: svc.h,v 1.5 1996/01/30 23:32:29 mpp Exp $ 32dba7a33eSGarrett Wollman */ 33dba7a33eSGarrett Wollman 34dba7a33eSGarrett Wollman /* 35dba7a33eSGarrett Wollman * svc.h, Server-side remote procedure call interface. 36dba7a33eSGarrett Wollman * 37dba7a33eSGarrett Wollman * Copyright (C) 1984, Sun Microsystems, Inc. 38dba7a33eSGarrett Wollman */ 39dba7a33eSGarrett Wollman 4086b9a9ccSGarrett Wollman #ifndef _RPC_SVC_H 4186b9a9ccSGarrett Wollman #define _RPC_SVC_H 4286b9a9ccSGarrett Wollman #include <sys/cdefs.h> 43dba7a33eSGarrett Wollman 44dba7a33eSGarrett Wollman /* 45dba7a33eSGarrett Wollman * This interface must manage two items concerning remote procedure calling: 46dba7a33eSGarrett Wollman * 47dba7a33eSGarrett Wollman * 1) An arbitrary number of transport connections upon which rpc requests 48dba7a33eSGarrett Wollman * are received. The two most notable transports are TCP and UDP; they are 49dba7a33eSGarrett Wollman * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; 50dba7a33eSGarrett Wollman * they in turn call xprt_register and xprt_unregister. 51dba7a33eSGarrett Wollman * 52dba7a33eSGarrett Wollman * 2) An arbitrary number of locally registered services. Services are 53dba7a33eSGarrett Wollman * described by the following four data: program number, version number, 54dba7a33eSGarrett Wollman * "service dispatch" function, a transport handle, and a boolean that 55dba7a33eSGarrett Wollman * indicates whether or not the exported program should be registered with a 56dba7a33eSGarrett Wollman * local binder service; if true the program's number and version and the 57dba7a33eSGarrett Wollman * port number from the transport handle are registered with the binder. 58dba7a33eSGarrett Wollman * These data are registered with the rpc svc system via svc_register. 59dba7a33eSGarrett Wollman * 60dba7a33eSGarrett Wollman * A service's dispatch function is called whenever an rpc request comes in 61dba7a33eSGarrett Wollman * on a transport. The request's program and version numbers must match 62dba7a33eSGarrett Wollman * those of the registered service. The dispatch function is passed two 63dba7a33eSGarrett Wollman * parameters, struct svc_req * and SVCXPRT *, defined below. 64dba7a33eSGarrett Wollman */ 65dba7a33eSGarrett Wollman 66dba7a33eSGarrett Wollman enum xprt_stat { 67dba7a33eSGarrett Wollman XPRT_DIED, 68dba7a33eSGarrett Wollman XPRT_MOREREQS, 69dba7a33eSGarrett Wollman XPRT_IDLE 70dba7a33eSGarrett Wollman }; 71dba7a33eSGarrett Wollman 72dba7a33eSGarrett Wollman /* 73dba7a33eSGarrett Wollman * Server side transport handle 74dba7a33eSGarrett Wollman */ 7570de0abfSPeter Wemm typedef struct __rpc_svcxprt { 76dba7a33eSGarrett Wollman int xp_sock; 77dba7a33eSGarrett Wollman u_short xp_port; /* associated port number */ 78dba7a33eSGarrett Wollman struct xp_ops { 7970de0abfSPeter Wemm /* receive incoming requests */ 8070de0abfSPeter Wemm bool_t (*xp_recv) __P((struct __rpc_svcxprt *, 8170de0abfSPeter Wemm struct rpc_msg *)); 8270de0abfSPeter Wemm /* get transport status */ 8370de0abfSPeter Wemm enum xprt_stat (*xp_stat) __P((struct __rpc_svcxprt *)); 8470de0abfSPeter Wemm /* get arguments */ 8570de0abfSPeter Wemm bool_t (*xp_getargs) __P((struct __rpc_svcxprt *, xdrproc_t, 8670de0abfSPeter Wemm caddr_t)); 8770de0abfSPeter Wemm /* send reply */ 8870de0abfSPeter Wemm bool_t (*xp_reply) __P((struct __rpc_svcxprt *, 8970de0abfSPeter Wemm struct rpc_msg *)); 9070de0abfSPeter Wemm /* free mem allocated for args */ 9170de0abfSPeter Wemm bool_t (*xp_freeargs) __P((struct __rpc_svcxprt *, xdrproc_t, 9270de0abfSPeter Wemm caddr_t)); 9370de0abfSPeter Wemm /* destroy this struct */ 9470de0abfSPeter Wemm void (*xp_destroy) __P((struct __rpc_svcxprt *)); 95dba7a33eSGarrett Wollman } *xp_ops; 96dba7a33eSGarrett Wollman int xp_addrlen; /* length of remote address */ 97dba7a33eSGarrett Wollman struct sockaddr_in xp_raddr; /* remote address */ 98dba7a33eSGarrett Wollman struct opaque_auth xp_verf; /* raw response verifier */ 99dba7a33eSGarrett Wollman caddr_t xp_p1; /* private */ 100dba7a33eSGarrett Wollman caddr_t xp_p2; /* private */ 101dba7a33eSGarrett Wollman } SVCXPRT; 102dba7a33eSGarrett Wollman 103dba7a33eSGarrett Wollman /* 104dba7a33eSGarrett Wollman * Approved way of getting address of caller 105dba7a33eSGarrett Wollman */ 106dba7a33eSGarrett Wollman #define svc_getcaller(x) (&(x)->xp_raddr) 107dba7a33eSGarrett Wollman 108dba7a33eSGarrett Wollman /* 109dba7a33eSGarrett Wollman * Operations defined on an SVCXPRT handle 110dba7a33eSGarrett Wollman * 111dba7a33eSGarrett Wollman * SVCXPRT *xprt; 112dba7a33eSGarrett Wollman * struct rpc_msg *msg; 113dba7a33eSGarrett Wollman * xdrproc_t xargs; 114dba7a33eSGarrett Wollman * caddr_t argsp; 115dba7a33eSGarrett Wollman */ 116dba7a33eSGarrett Wollman #define SVC_RECV(xprt, msg) \ 117dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 118dba7a33eSGarrett Wollman #define svc_recv(xprt, msg) \ 119dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 120dba7a33eSGarrett Wollman 121dba7a33eSGarrett Wollman #define SVC_STAT(xprt) \ 122dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_stat)(xprt) 123dba7a33eSGarrett Wollman #define svc_stat(xprt) \ 124dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_stat)(xprt) 125dba7a33eSGarrett Wollman 126dba7a33eSGarrett Wollman #define SVC_GETARGS(xprt, xargs, argsp) \ 127dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 128dba7a33eSGarrett Wollman #define svc_getargs(xprt, xargs, argsp) \ 129dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 130dba7a33eSGarrett Wollman 131dba7a33eSGarrett Wollman #define SVC_REPLY(xprt, msg) \ 132dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 133dba7a33eSGarrett Wollman #define svc_reply(xprt, msg) \ 134dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 135dba7a33eSGarrett Wollman 136dba7a33eSGarrett Wollman #define SVC_FREEARGS(xprt, xargs, argsp) \ 137dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 138dba7a33eSGarrett Wollman #define svc_freeargs(xprt, xargs, argsp) \ 139dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 140dba7a33eSGarrett Wollman 141dba7a33eSGarrett Wollman #define SVC_DESTROY(xprt) \ 142dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_destroy)(xprt) 143dba7a33eSGarrett Wollman #define svc_destroy(xprt) \ 144dba7a33eSGarrett Wollman (*(xprt)->xp_ops->xp_destroy)(xprt) 145dba7a33eSGarrett Wollman 146dba7a33eSGarrett Wollman 147dba7a33eSGarrett Wollman /* 148dba7a33eSGarrett Wollman * Service request 149dba7a33eSGarrett Wollman */ 150dba7a33eSGarrett Wollman struct svc_req { 15170de0abfSPeter Wemm u_int32_t rq_prog; /* service program number */ 15270de0abfSPeter Wemm u_int32_t rq_vers; /* service protocol version */ 15370de0abfSPeter Wemm u_int32_t rq_proc; /* the desired procedure */ 154dba7a33eSGarrett Wollman struct opaque_auth rq_cred; /* raw creds from the wire */ 155dba7a33eSGarrett Wollman caddr_t rq_clntcred; /* read only cooked cred */ 156dba7a33eSGarrett Wollman SVCXPRT *rq_xprt; /* associated transport */ 157dba7a33eSGarrett Wollman }; 158dba7a33eSGarrett Wollman 159dba7a33eSGarrett Wollman 160dba7a33eSGarrett Wollman /* 161dba7a33eSGarrett Wollman * Service registration 162dba7a33eSGarrett Wollman * 163dba7a33eSGarrett Wollman * svc_register(xprt, prog, vers, dispatch, protocol) 164dba7a33eSGarrett Wollman * SVCXPRT *xprt; 165dba7a33eSGarrett Wollman * u_long prog; 166dba7a33eSGarrett Wollman * u_long vers; 167dba7a33eSGarrett Wollman * void (*dispatch)(); 16870de0abfSPeter Wemm * int protocol; (like TCP or UDP, zero means do not register) 169dba7a33eSGarrett Wollman */ 17086b9a9ccSGarrett Wollman __BEGIN_DECLS 17170de0abfSPeter Wemm extern bool_t svc_register __P((SVCXPRT *, u_long, u_long, 17270de0abfSPeter Wemm void (*) __P((struct svc_req *, SVCXPRT *)), int)); 17386b9a9ccSGarrett Wollman __END_DECLS 174dba7a33eSGarrett Wollman 175dba7a33eSGarrett Wollman /* 176dba7a33eSGarrett Wollman * Service un-registration 177dba7a33eSGarrett Wollman * 178dba7a33eSGarrett Wollman * svc_unregister(prog, vers) 179dba7a33eSGarrett Wollman * u_long prog; 180dba7a33eSGarrett Wollman * u_long vers; 181dba7a33eSGarrett Wollman */ 18286b9a9ccSGarrett Wollman __BEGIN_DECLS 18386b9a9ccSGarrett Wollman extern void svc_unregister __P((u_long, u_long)); 18486b9a9ccSGarrett Wollman __END_DECLS 185dba7a33eSGarrett Wollman 186dba7a33eSGarrett Wollman /* 187dba7a33eSGarrett Wollman * Transport registration. 188dba7a33eSGarrett Wollman * 189dba7a33eSGarrett Wollman * xprt_register(xprt) 190dba7a33eSGarrett Wollman * SVCXPRT *xprt; 191dba7a33eSGarrett Wollman */ 19286b9a9ccSGarrett Wollman __BEGIN_DECLS 19386b9a9ccSGarrett Wollman extern void xprt_register __P((SVCXPRT *)); 19486b9a9ccSGarrett Wollman __END_DECLS 195dba7a33eSGarrett Wollman 196dba7a33eSGarrett Wollman /* 197dba7a33eSGarrett Wollman * Transport un-register 198dba7a33eSGarrett Wollman * 199dba7a33eSGarrett Wollman * xprt_unregister(xprt) 200dba7a33eSGarrett Wollman * SVCXPRT *xprt; 201dba7a33eSGarrett Wollman */ 20286b9a9ccSGarrett Wollman __BEGIN_DECLS 20386b9a9ccSGarrett Wollman extern void xprt_unregister __P((SVCXPRT *)); 20486b9a9ccSGarrett Wollman __END_DECLS 205dba7a33eSGarrett Wollman 206dba7a33eSGarrett Wollman 207dba7a33eSGarrett Wollman 208dba7a33eSGarrett Wollman 209dba7a33eSGarrett Wollman /* 210dba7a33eSGarrett Wollman * When the service routine is called, it must first check to see if it 211dba7a33eSGarrett Wollman * knows about the procedure; if not, it should call svcerr_noproc 212dba7a33eSGarrett Wollman * and return. If so, it should deserialize its arguments via 213dba7a33eSGarrett Wollman * SVC_GETARGS (defined above). If the deserialization does not work, 214dba7a33eSGarrett Wollman * svcerr_decode should be called followed by a return. Successful 215dba7a33eSGarrett Wollman * decoding of the arguments should be followed the execution of the 216dba7a33eSGarrett Wollman * procedure's code and a call to svc_sendreply. 217dba7a33eSGarrett Wollman * 218dba7a33eSGarrett Wollman * Also, if the service refuses to execute the procedure due to too- 219dba7a33eSGarrett Wollman * weak authentication parameters, svcerr_weakauth should be called. 220dba7a33eSGarrett Wollman * Note: do not confuse access-control failure with weak authentication! 221dba7a33eSGarrett Wollman * 222dba7a33eSGarrett Wollman * NB: In pure implementations of rpc, the caller always waits for a reply 223dba7a33eSGarrett Wollman * msg. This message is sent when svc_sendreply is called. 224dba7a33eSGarrett Wollman * Therefore pure service implementations should always call 225dba7a33eSGarrett Wollman * svc_sendreply even if the function logically returns void; use 226dba7a33eSGarrett Wollman * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows 227dba7a33eSGarrett Wollman * for the abuse of pure rpc via batched calling or pipelining. In the 228dba7a33eSGarrett Wollman * case of a batched call, svc_sendreply should NOT be called since 229dba7a33eSGarrett Wollman * this would send a return message, which is what batching tries to avoid. 230dba7a33eSGarrett Wollman * It is the service/protocol writer's responsibility to know which calls are 231dba7a33eSGarrett Wollman * batched and which are not. Warning: responding to batch calls may 232dba7a33eSGarrett Wollman * deadlock the caller and server processes! 233dba7a33eSGarrett Wollman */ 234dba7a33eSGarrett Wollman 23586b9a9ccSGarrett Wollman __BEGIN_DECLS 23686b9a9ccSGarrett Wollman extern bool_t svc_sendreply __P((SVCXPRT *, xdrproc_t, char *)); 23786b9a9ccSGarrett Wollman extern void svcerr_decode __P((SVCXPRT *)); 23886b9a9ccSGarrett Wollman extern void svcerr_weakauth __P((SVCXPRT *)); 23986b9a9ccSGarrett Wollman extern void svcerr_noproc __P((SVCXPRT *)); 24086b9a9ccSGarrett Wollman extern void svcerr_progvers __P((SVCXPRT *, u_long, u_long)); 24186b9a9ccSGarrett Wollman extern void svcerr_auth __P((SVCXPRT *, enum auth_stat)); 24286b9a9ccSGarrett Wollman extern void svcerr_noprog __P((SVCXPRT *)); 24386b9a9ccSGarrett Wollman extern void svcerr_systemerr __P((SVCXPRT *)); 24486b9a9ccSGarrett Wollman __END_DECLS 245dba7a33eSGarrett Wollman 246dba7a33eSGarrett Wollman /* 247dba7a33eSGarrett Wollman * Lowest level dispatching -OR- who owns this process anyway. 248dba7a33eSGarrett Wollman * Somebody has to wait for incoming requests and then call the correct 249dba7a33eSGarrett Wollman * service routine. The routine svc_run does infinite waiting; i.e., 250dba7a33eSGarrett Wollman * svc_run never returns. 251dba7a33eSGarrett Wollman * Since another (co-existant) package may wish to selectively wait for 252dba7a33eSGarrett Wollman * incoming calls or other events outside of the rpc architecture, the 253dba7a33eSGarrett Wollman * routine svc_getreq is provided. It must be passed readfds, the 254dba7a33eSGarrett Wollman * "in-place" results of a select system call (see select, section 2). 255dba7a33eSGarrett Wollman */ 256dba7a33eSGarrett Wollman 257dba7a33eSGarrett Wollman /* 258dba7a33eSGarrett Wollman * Global keeper of rpc service descriptors in use 259dba7a33eSGarrett Wollman * dynamic; must be inspected before each call to select 260dba7a33eSGarrett Wollman */ 26170de0abfSPeter Wemm extern int svc_maxfd; 262dba7a33eSGarrett Wollman extern fd_set svc_fdset; 263dba7a33eSGarrett Wollman #define svc_fds svc_fdset.fds_bits[0] /* compatibility */ 264dba7a33eSGarrett Wollman 265dba7a33eSGarrett Wollman /* 266dba7a33eSGarrett Wollman * a small program implemented by the svc_rpc implementation itself; 267dba7a33eSGarrett Wollman * also see clnt.h for protocol numbers. 268dba7a33eSGarrett Wollman */ 269dba7a33eSGarrett Wollman extern void rpctest_service(); 270dba7a33eSGarrett Wollman 27186b9a9ccSGarrett Wollman __BEGIN_DECLS 27286b9a9ccSGarrett Wollman extern void svc_getreq __P((int)); 27386b9a9ccSGarrett Wollman extern void svc_getreqset __P((fd_set *)); 27486b9a9ccSGarrett Wollman extern void svc_run __P((void)); 27586b9a9ccSGarrett Wollman __END_DECLS 276dba7a33eSGarrett Wollman 277dba7a33eSGarrett Wollman /* 278dba7a33eSGarrett Wollman * Socket to use on svcxxx_create call to get default socket 279dba7a33eSGarrett Wollman */ 280dba7a33eSGarrett Wollman #define RPC_ANYSOCK -1 281dba7a33eSGarrett Wollman 282dba7a33eSGarrett Wollman /* 283dba7a33eSGarrett Wollman * These are the existing service side transport implementations 284dba7a33eSGarrett Wollman */ 285dba7a33eSGarrett Wollman 286dba7a33eSGarrett Wollman /* 287dba7a33eSGarrett Wollman * Memory based rpc for testing and timing. 288dba7a33eSGarrett Wollman */ 28986b9a9ccSGarrett Wollman __BEGIN_DECLS 29086b9a9ccSGarrett Wollman extern SVCXPRT *svcraw_create __P((void)); 29186b9a9ccSGarrett Wollman __END_DECLS 29286b9a9ccSGarrett Wollman 293dba7a33eSGarrett Wollman 294dba7a33eSGarrett Wollman /* 295dba7a33eSGarrett Wollman * Udp based rpc. 296dba7a33eSGarrett Wollman */ 29786b9a9ccSGarrett Wollman __BEGIN_DECLS 29886b9a9ccSGarrett Wollman extern SVCXPRT *svcudp_create __P((int)); 29986b9a9ccSGarrett Wollman extern SVCXPRT *svcudp_bufcreate __P((int, u_int, u_int)); 30086b9a9ccSGarrett Wollman __END_DECLS 30186b9a9ccSGarrett Wollman 302dba7a33eSGarrett Wollman 303dba7a33eSGarrett Wollman /* 304dba7a33eSGarrett Wollman * Tcp based rpc. 305dba7a33eSGarrett Wollman */ 30686b9a9ccSGarrett Wollman __BEGIN_DECLS 30786b9a9ccSGarrett Wollman extern SVCXPRT *svctcp_create __P((int, u_int, u_int)); 30886b9a9ccSGarrett Wollman __END_DECLS 309dba7a33eSGarrett Wollman 31070de0abfSPeter Wemm /* 31170de0abfSPeter Wemm * Fd based rpc. 31270de0abfSPeter Wemm */ 31370de0abfSPeter Wemm __BEGIN_DECLS 31470de0abfSPeter Wemm extern SVCXPRT *svcfd_create __P((int, u_int, u_int)); 31570de0abfSPeter Wemm __END_DECLS 31670de0abfSPeter Wemm 31786b9a9ccSGarrett Wollman #endif /* !_RPC_SVC_H */ 318