svc.h 8.6 KB

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