June 2025 | ||||||
Mo | Tu | We | Th | Fr | Sa | Su |
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 1 | 2 | 3 | 4 | 5 | 6 |
001: /* 002: * svc.h, Server-side remote procedure call interface. 003: * 004: * Copyright (c) 2010, Oracle America, Inc. 005: * 006: * Redistribution and use in source and binary forms, with or without 007: * modification, are permitted provided that the following conditions are 008: * met: 009: * 010: * * Redistributions of source code must retain the above copyright 011: * notice, this list of conditions and the following disclaimer. 012: * * Redistributions in binary form must reproduce the above 013: * copyright notice, this list of conditions and the following 014: * disclaimer in the documentation and/or other materials 015: * provided with the distribution. 016: * * Neither the name of the "Oracle America, Inc." nor the names of its 017: * contributors may be used to endorse or promote products derived 018: * from this software without specific prior written permission. 019: * 020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 023: * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 024: * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 025: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 026: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 027: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 029: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 030: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 031: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 032: */ 033: 034: #ifndef _RPC_SVC_H 035: #define _RPC_SVC_H 1 036: 037: #include <features.h> 038: #include <rpc/rpc_msg.h> 039: 040: __BEGIN_DECLS 041: 042: /* 043: * This interface must manage two items concerning remote procedure calling: 044: * 045: * 1) An arbitrary number of transport connections upon which rpc requests 046: * are received. The two most notable transports are TCP and UDP; they are 047: * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; 048: * they in turn call xprt_register and xprt_unregister. 049: * 050: * 2) An arbitrary number of locally registered services. Services are 051: * described by the following four data: program number, version number, 052: * "service dispatch" function, a transport handle, and a boolean that 053: * indicates whether or not the exported program should be registered with a 054: * local binder service; if true the program's number and version and the 055: * port number from the transport handle are registered with the binder. 056: * These data are registered with the rpc svc system via svc_register. 057: * 058: * A service's dispatch function is called whenever an rpc request comes in 059: * on a transport. The request's program and version numbers must match 060: * those of the registered service. The dispatch function is passed two 061: * parameters, struct svc_req * and SVCXPRT *, defined below. 062: */ 063: 064: enum xprt_stat { 065: XPRT_DIED, 066: XPRT_MOREREQS, 067: XPRT_IDLE 068: }; 069: 070: /* 071: * Server side transport handle 072: */ 073: typedef struct SVCXPRT SVCXPRT; 074: struct SVCXPRT { 075: int xp_sock; 076: u_short xp_port; /* associated port number */ 077: const struct xp_ops { 078: bool_t (*xp_recv) (SVCXPRT *__xprt, struct rpc_msg *__msg); 079: /* receive incoming requests */ 080: enum xprt_stat (*xp_stat) (SVCXPRT *__xprt); 081: /* get transport status */ 082: bool_t (*xp_getargs) (SVCXPRT *__xprt, xdrproc_t __xdr_args, 083: caddr_t __args_ptr); /* get arguments */ 084: bool_t (*xp_reply) (SVCXPRT *__xprt, struct rpc_msg *__msg); 085: /* send reply */ 086: bool_t (*xp_freeargs) (SVCXPRT *__xprt, xdrproc_t __xdr_args, 087: caddr_t __args_ptr); 088: /* free mem allocated for args */ 089: void (*xp_destroy) (SVCXPRT *__xprt); 090: /* destroy this struct */ 091: } *xp_ops; 092: int xp_addrlen; /* length of remote address */ 093: struct sockaddr_in xp_raddr; /* remote address */ 094: struct opaque_auth xp_verf; /* raw response verifier */ 095: caddr_t xp_p1; /* private */ 096: caddr_t xp_p2; /* private */ 097: char xp_pad [256]; /* padding, internal use */ 098: }; 099: 100: /* 101: * Approved way of getting address of caller 102: */ 103: #define svc_getcaller(x) (&(x)->xp_raddr) 104: 105: /* 106: * Operations defined on an SVCXPRT handle 107: * 108: * SVCXPRT *xprt; 109: * struct rpc_msg *msg; 110: * xdrproc_t xargs; 111: * caddr_t argsp; 112: */ 113: #define SVC_RECV(xprt, msg) \ 114: (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 115: #define svc_recv(xprt, msg) \ 116: (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 117: 118: #define SVC_STAT(xprt) \ 119: (*(xprt)->xp_ops->xp_stat)(xprt) 120: #define svc_stat(xprt) \ 121: (*(xprt)->xp_ops->xp_stat)(xprt) 122: 123: #define SVC_GETARGS(xprt, xargs, argsp) \ 124: (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 125: #define svc_getargs(xprt, xargs, argsp) \ 126: (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 127: 128: #define SVC_REPLY(xprt, msg) \ 129: (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 130: #define svc_reply(xprt, msg) \ 131: (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 132: 133: #define SVC_FREEARGS(xprt, xargs, argsp) \ 134: (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 135: #define svc_freeargs(xprt, xargs, argsp) \ 136: (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 137: 138: #define SVC_DESTROY(xprt) \ 139: (*(xprt)->xp_ops->xp_destroy)(xprt) 140: #define svc_destroy(xprt) \ 141: (*(xprt)->xp_ops->xp_destroy)(xprt) 142: 143: 144: /* 145: * Service request 146: */ 147: struct svc_req { 148: rpcprog_t rq_prog; /* service program number */ 149: rpcvers_t rq_vers; /* service protocol version */ 150: rpcproc_t rq_proc; /* the desired procedure */ 151: struct opaque_auth rq_cred; /* raw creds from the wire */ 152: caddr_t rq_clntcred; /* read only cooked cred */ 153: SVCXPRT *rq_xprt; /* associated transport */ 154: }; 155: 156: #ifndef __DISPATCH_FN_T 157: #define __DISPATCH_FN_T 158: typedef void (*__dispatch_fn_t) (struct svc_req*, SVCXPRT*); 159: #endif 160: 161: /* 162: * Service registration 163: * 164: * svc_register(xprt, prog, vers, dispatch, protocol) 165: * SVCXPRT *xprt; 166: * rpcprog_t prog; 167: * rpcvers_t vers; 168: * void (*dispatch)(struct svc_req*, SVCXPRT*); 169: * rpcprot_t protocol; like TCP or UDP, zero means do not register 170: */ 171: extern bool_t svc_register (SVCXPRT *__xprt, rpcprog_t __prog, 172: rpcvers_t __vers, __dispatch_fn_t __dispatch, 173: rpcprot_t __protocol) __THROW; 174: 175: /* 176: * Service un-registration 177: * 178: * svc_unregister(prog, vers) 179: * rpcprog_t prog; 180: * rpcvers_t vers; 181: */ 182: extern void svc_unregister (rpcprog_t __prog, rpcvers_t __vers) __THROW; 183: 184: /* 185: * Transport registration. 186: * 187: * xprt_register(xprt) 188: * SVCXPRT *xprt; 189: */ 190: extern void xprt_register (SVCXPRT *__xprt) __THROW; 191: 192: /* 193: * Transport un-register 194: * 195: * xprt_unregister(xprt) 196: * SVCXPRT *xprt; 197: */ 198: extern void xprt_unregister (SVCXPRT *__xprt) __THROW; 199: 200: 201: /* 202: * When the service routine is called, it must first check to see if it 203: * knows about the procedure; if not, it should call svcerr_noproc 204: * and return. If so, it should deserialize its arguments via 205: * SVC_GETARGS (defined above). If the deserialization does not work, 206: * svcerr_decode should be called followed by a return. Successful 207: * decoding of the arguments should be followed the execution of the 208: * procedure's code and a call to svc_sendreply. 209: * 210: * Also, if the service refuses to execute the procedure due to too- 211: * weak authentication parameters, svcerr_weakauth should be called. 212: * Note: do not confuse access-control failure with weak authentication! 213: * 214: * NB: In pure implementations of rpc, the caller always waits for a reply 215: * msg. This message is sent when svc_sendreply is called. 216: * Therefore pure service implementations should always call 217: * svc_sendreply even if the function logically returns void; use 218: * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows 219: * for the abuse of pure rpc via batched calling or pipelining. In the 220: * case of a batched call, svc_sendreply should NOT be called since 221: * this would send a return message, which is what batching tries to avoid. 222: * It is the service/protocol writer's responsibility to know which calls are 223: * batched and which are not. Warning: responding to batch calls may 224: * deadlock the caller and server processes! 225: */ 226: 227: extern bool_t svc_sendreply (SVCXPRT *__xprt, xdrproc_t __xdr_results, 228: caddr_t __xdr_location) __THROW; 229: 230: extern void svcerr_decode (SVCXPRT *__xprt) __THROW; 231: 232: extern void svcerr_weakauth (SVCXPRT *__xprt) __THROW; 233: 234: extern void svcerr_noproc (SVCXPRT *__xprt) __THROW; 235: 236: extern void svcerr_progvers (SVCXPRT *__xprt, rpcvers_t __low_vers, 237: rpcvers_t __high_vers) __THROW; 238: 239: extern void svcerr_auth (SVCXPRT *__xprt, enum auth_stat __why) __THROW; 240: 241: extern void svcerr_noprog (SVCXPRT *__xprt) __THROW; 242: 243: extern void svcerr_systemerr (SVCXPRT *__xprt) __THROW; 244: 245: /* 246: * Lowest level dispatching -OR- who owns this process anyway. 247: * Somebody has to wait for incoming requests and then call the correct 248: * service routine. The routine svc_run does infinite waiting; i.e., 249: * svc_run never returns. 250: * Since another (coexistent) package may wish to selectively wait for 251: * incoming calls or other events outside of the rpc architecture, the 252: * routine svc_getreq is provided. It must be passed readfds, the 253: * "in-place" results of a select system call (see select, section 2). 254: */ 255: 256: /* 257: * Global keeper of rpc service descriptors in use 258: * dynamic; must be inspected before each call to select 259: */ 260: 261: extern struct pollfd *svc_pollfd; 262: extern int svc_max_pollfd; 263: extern fd_set svc_fdset; 264: #define svc_fds svc_fdset.fds_bits[0] /* compatibility */ 265: 266: /* 267: * a small program implemented by the svc_rpc implementation itself; 268: * also see clnt.h for protocol numbers. 269: */ 270: extern void svc_getreq (int __rdfds) __THROW; 271: extern void svc_getreq_common (const int __fd) __THROW; 272: extern void svc_getreqset (fd_set *__readfds) __THROW; 273: extern void svc_getreq_poll (struct pollfd *, const int) __THROW; 274: extern void svc_exit (void) __THROW; 275: extern void svc_run (void) __THROW; 276: 277: /* 278: * Socket to use on svcxxx_create call to get default socket 279: */ 280: #define RPC_ANYSOCK -1 281: 282: /* 283: * These are the existing service side transport implementations 284: */ 285: 286: /* 287: * Memory based rpc for testing and timing. 288: */ 289: extern SVCXPRT *svcraw_create (void) __THROW; 290: 291: /* 292: * Udp based rpc. 293: */ 294: extern SVCXPRT *svcudp_create (int __sock) __THROW; 295: extern SVCXPRT *svcudp_bufcreate (int __sock, u_int __sendsz, u_int __recvsz) 296: __THROW; 297: 298: /* 299: * Tcp based rpc. 300: */ 301: extern SVCXPRT *svctcp_create (int __sock, u_int __sendsize, u_int __recvsize) 302: __THROW; 303: 304: /* 305: * FD based rpc. 306: */ 307: extern SVCXPRT *svcfd_create (int __sock, u_int __sendsize, u_int __recvsize) 308: __THROW; 309: 310: /* 311: * Unix based rpc. 312: */ 313: extern SVCXPRT *svcunix_create (int __sock, u_int __sendsize, u_int __recvsize, 314: char *__path) __THROW; 315: 316: 317: __END_DECLS 318: 319: #endif /* rpc/svc.h */ 320: