svc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  3. * unrestricted use provided that this legend is included on all tape
  4. * media and as a part of the software program in whole or part. Users
  5. * may copy or modify Sun RPC without charge, but are not authorized
  6. * to license or distribute it to anyone else except as part of a product or
  7. * program developed by the user.
  8. *
  9. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12. *
  13. * Sun RPC is provided with no support and without any obligation on the
  14. * part of Sun Microsystems, Inc. to assist in its use, correction,
  15. * modification or enhancement.
  16. *
  17. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19. * OR ANY PART THEREOF.
  20. *
  21. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22. * or profits or other special, indirect and consequential damages, even if
  23. * Sun has been advised of the possibility of such damages.
  24. *
  25. * Sun Microsystems, Inc.
  26. * 2550 Garcia Avenue
  27. * Mountain View, California 94043
  28. */
  29. /*
  30. * svc.h, Server-side remote procedure call interface.
  31. *
  32. * Copyright (C) 1984, Sun Microsystems, Inc.
  33. */
  34. #ifndef _RPC_SVC_H
  35. #define _RPC_SVC_H 1
  36. #include <features.h>
  37. #include <rpc/rpc_msg.h>
  38. __BEGIN_DECLS
  39. /*
  40. * This interface must manage two items concerning remote procedure calling:
  41. *
  42. * 1) An arbitrary number of transport connections upon which rpc requests
  43. * are received. The two most notable transports are TCP and UDP; they are
  44. * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  45. * they in turn call xprt_register and xprt_unregister.
  46. *
  47. * 2) An arbitrary number of locally registered services. Services are
  48. * described by the following four data: program number, version number,
  49. * "service dispatch" function, a transport handle, and a boolean that
  50. * indicates whether or not the exported program should be registered with a
  51. * local binder service; if true the program's number and version and the
  52. * port number from the transport handle are registered with the binder.
  53. * These data are registered with the rpc svc system via svc_register.
  54. *
  55. * A service's dispatch function is called whenever an rpc request comes in
  56. * on a transport. The request's program and version numbers must match
  57. * those of the registered service. The dispatch function is passed two
  58. * parameters, struct svc_req * and SVCXPRT *, defined below.
  59. */
  60. enum xprt_stat {
  61. XPRT_DIED,
  62. XPRT_MOREREQS,
  63. XPRT_IDLE
  64. };
  65. /*
  66. * Server side transport handle
  67. */
  68. typedef struct SVCXPRT SVCXPRT;
  69. struct SVCXPRT {
  70. int xp_sock;
  71. u_short xp_port; /* associated port number */
  72. const struct xp_ops {
  73. bool_t (*xp_recv) (SVCXPRT *__xprt, struct rpc_msg *__msg);
  74. /* receive incoming requests */
  75. enum xprt_stat (*xp_stat) (SVCXPRT *__xprt);
  76. /* get transport status */
  77. bool_t (*xp_getargs) (SVCXPRT *__xprt, xdrproc_t __xdr_args,
  78. caddr_t args_ptr); /* get arguments */
  79. bool_t (*xp_reply) (SVCXPRT *__xprt, struct rpc_msg *__msg);
  80. /* send reply */
  81. bool_t (*xp_freeargs) (SVCXPRT *__xprt, xdrproc_t __xdr_args,
  82. caddr_t args_ptr);
  83. /* free mem allocated for args */
  84. void (*xp_destroy) (SVCXPRT *__xprt);
  85. /* destroy this struct */
  86. } *xp_ops;
  87. int xp_addrlen; /* length of remote address */
  88. struct sockaddr_in xp_raddr; /* remote address */
  89. struct opaque_auth xp_verf; /* raw response verifier */
  90. caddr_t xp_p1; /* private */
  91. caddr_t xp_p2; /* private */
  92. char xp_pad [256]; /* padding, internal use */
  93. };
  94. /*
  95. * Approved way of getting address of caller
  96. */
  97. #define svc_getcaller(x) (&(x)->xp_raddr)
  98. /*
  99. * Operations defined on an SVCXPRT handle
  100. *
  101. * SVCXPRT *xprt;
  102. * struct rpc_msg *msg;
  103. * xdrproc_t xargs;
  104. * caddr_t argsp;
  105. */
  106. #define SVC_RECV(xprt, msg) \
  107. (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  108. #define svc_recv(xprt, msg) \
  109. (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  110. #define SVC_STAT(xprt) \
  111. (*(xprt)->xp_ops->xp_stat)(xprt)
  112. #define svc_stat(xprt) \
  113. (*(xprt)->xp_ops->xp_stat)(xprt)
  114. #define SVC_GETARGS(xprt, xargs, argsp) \
  115. (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  116. #define svc_getargs(xprt, xargs, argsp) \
  117. (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  118. #define SVC_REPLY(xprt, msg) \
  119. (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  120. #define svc_reply(xprt, msg) \
  121. (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  122. #define SVC_FREEARGS(xprt, xargs, argsp) \
  123. (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  124. #define svc_freeargs(xprt, xargs, argsp) \
  125. (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  126. #define SVC_DESTROY(xprt) \
  127. (*(xprt)->xp_ops->xp_destroy)(xprt)
  128. #define svc_destroy(xprt) \
  129. (*(xprt)->xp_ops->xp_destroy)(xprt)
  130. /*
  131. * Service request
  132. */
  133. struct svc_req {
  134. rpcprog_t rq_prog; /* service program number */
  135. rpcvers_t rq_vers; /* service protocol version */
  136. rpcproc_t rq_proc; /* the desired procedure */
  137. struct opaque_auth rq_cred; /* raw creds from the wire */
  138. caddr_t rq_clntcred; /* read only cooked cred */
  139. SVCXPRT *rq_xprt; /* associated transport */
  140. };
  141. #ifndef __DISPATCH_FN_T
  142. #define __DISPATCH_FN_T
  143. typedef void (*__dispatch_fn_t) (struct svc_req*, SVCXPRT*);
  144. #endif
  145. /*
  146. * Service registration
  147. *
  148. * svc_register(xprt, prog, vers, dispatch, protocol)
  149. * SVCXPRT *xprt;
  150. * rpcprog_t prog;
  151. * rpcvers_t vers;
  152. * void (*dispatch)(struct svc_req*, SVCXPRT*);
  153. * rpcprot_t protocol; like TCP or UDP, zero means do not register
  154. */
  155. extern bool_t svc_register (SVCXPRT *__xprt, rpcprog_t __prog,
  156. rpcvers_t __vers, __dispatch_fn_t __dispatch,
  157. rpcprot_t __protocol) __THROW;
  158. libc_hidden_proto(svc_register)
  159. /*
  160. * Service un-registration
  161. *
  162. * svc_unregister(prog, vers)
  163. * rpcprog_t prog;
  164. * rpcvers_t vers;
  165. */
  166. extern void svc_unregister (rpcprog_t __prog, rpcvers_t __vers) __THROW;
  167. libc_hidden_proto(svc_unregister)
  168. /*
  169. * Transport registration.
  170. *
  171. * xprt_register(xprt)
  172. * SVCXPRT *xprt;
  173. */
  174. extern void xprt_register (SVCXPRT *__xprt) __THROW;
  175. libc_hidden_proto(xprt_register)
  176. /*
  177. * Transport un-register
  178. *
  179. * xprt_unregister(xprt)
  180. * SVCXPRT *xprt;
  181. */
  182. extern void xprt_unregister (SVCXPRT *__xprt) __THROW;
  183. libc_hidden_proto(xprt_unregister)
  184. /*
  185. * When the service routine is called, it must first check to see if it
  186. * knows about the procedure; if not, it should call svcerr_noproc
  187. * and return. If so, it should deserialize its arguments via
  188. * SVC_GETARGS (defined above). If the deserialization does not work,
  189. * svcerr_decode should be called followed by a return. Successful
  190. * decoding of the arguments should be followed the execution of the
  191. * procedure's code and a call to svc_sendreply.
  192. *
  193. * Also, if the service refuses to execute the procedure due to too-
  194. * weak authentication parameters, svcerr_weakauth should be called.
  195. * Note: do not confuse access-control failure with weak authentication!
  196. *
  197. * NB: In pure implementations of rpc, the caller always waits for a reply
  198. * msg. This message is sent when svc_sendreply is called.
  199. * Therefore pure service implementations should always call
  200. * svc_sendreply even if the function logically returns void; use
  201. * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
  202. * for the abuse of pure rpc via batched calling or pipelining. In the
  203. * case of a batched call, svc_sendreply should NOT be called since
  204. * this would send a return message, which is what batching tries to avoid.
  205. * It is the service/protocol writer's responsibility to know which calls are
  206. * batched and which are not. Warning: responding to batch calls may
  207. * deadlock the caller and server processes!
  208. */
  209. extern bool_t svc_sendreply (SVCXPRT *xprt, xdrproc_t __xdr_results,
  210. caddr_t __xdr_location) __THROW;
  211. libc_hidden_proto(svc_sendreply)
  212. extern void svcerr_decode (SVCXPRT *__xprt) __THROW;
  213. libc_hidden_proto(svcerr_decode)
  214. extern void svcerr_weakauth (SVCXPRT *__xprt) __THROW;
  215. extern void svcerr_noproc (SVCXPRT *__xprt) __THROW;
  216. extern void svcerr_progvers (SVCXPRT *__xprt, rpcvers_t __low_vers,
  217. rpcvers_t __high_vers) __THROW;
  218. libc_hidden_proto(svcerr_progvers)
  219. extern void svcerr_auth (SVCXPRT *__xprt, enum auth_stat __why) __THROW;
  220. libc_hidden_proto(svcerr_auth)
  221. extern void svcerr_noprog (SVCXPRT *__xprt) __THROW;
  222. libc_hidden_proto(svcerr_noprog)
  223. extern void svcerr_systemerr (SVCXPRT *__xprt) __THROW;
  224. /*
  225. * Lowest level dispatching -OR- who owns this process anyway.
  226. * Somebody has to wait for incoming requests and then call the correct
  227. * service routine. The routine svc_run does infinite waiting; i.e.,
  228. * svc_run never returns.
  229. * Since another (coexistent) package may wish to selectively wait for
  230. * incoming calls or other events outside of the rpc architecture, the
  231. * routine svc_getreq is provided. It must be passed readfds, the
  232. * "in-place" results of a select system call (see select, section 2).
  233. */
  234. /*
  235. * Global keeper of rpc service descriptors in use
  236. * dynamic; must be inspected before each call to select
  237. */
  238. extern struct pollfd *svc_pollfd;
  239. extern int svc_max_pollfd;
  240. extern fd_set svc_fdset;
  241. #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
  242. /*
  243. * a small program implemented by the svc_rpc implementation itself;
  244. * also see clnt.h for protocol numbers.
  245. */
  246. extern void svc_getreq (int __rdfds) __THROW;
  247. libc_hidden_proto(svc_getreq)
  248. extern void svc_getreq_common (const int __fd) __THROW;
  249. libc_hidden_proto(svc_getreq_common)
  250. extern void svc_getreqset (fd_set *__readfds) __THROW;
  251. libc_hidden_proto(svc_getreqset)
  252. extern void svc_getreq_poll (struct pollfd *, const int) __THROW;
  253. libc_hidden_proto(svc_getreq_poll)
  254. extern void svc_exit (void) __THROW;
  255. extern void svc_run (void) __THROW;
  256. /*
  257. * Socket to use on svcxxx_create call to get default socket
  258. */
  259. #define RPC_ANYSOCK -1
  260. /*
  261. * These are the existing service side transport implementations
  262. */
  263. /*
  264. * Memory based rpc for testing and timing.
  265. */
  266. extern SVCXPRT *svcraw_create (void) __THROW;
  267. /*
  268. * Udp based rpc.
  269. */
  270. extern SVCXPRT *svcudp_create (int __sock) __THROW;
  271. libc_hidden_proto(svcudp_create)
  272. extern SVCXPRT *svcudp_bufcreate (int __sock, u_int __sendsz, u_int __recvsz)
  273. __THROW;
  274. libc_hidden_proto(svcudp_bufcreate)
  275. /*
  276. * Tcp based rpc.
  277. */
  278. extern SVCXPRT *svctcp_create (int __sock, u_int __sendsize, u_int __recvsize)
  279. __THROW;
  280. /*
  281. * Unix based rpc.
  282. */
  283. extern SVCXPRT *svcunix_create (int __sock, u_int __sendsize, u_int __recvsize,
  284. char *__path) __THROW;
  285. __END_DECLS
  286. #endif /* rpc/svc.h */