svc.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 _RPC_SVC_H
  36. #define _RPC_SVC_H 1
  37. #include <features.h>
  38. #include <rpc/rpc_msg.h>
  39. __BEGIN_DECLS
  40. /*
  41. * This interface must manage two items concerning remote procedure calling:
  42. *
  43. * 1) An arbitrary number of transport connections upon which rpc requests
  44. * are received. The two most notable transports are TCP and UDP; they are
  45. * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  46. * they in turn call xprt_register and xprt_unregister.
  47. *
  48. * 2) An arbitrary number of locally registered services. Services are
  49. * described by the following four data: program number, version number,
  50. * "service dispatch" function, a transport handle, and a boolean that
  51. * indicates whether or not the exported program should be registered with a
  52. * local binder service; if true the program's number and version and the
  53. * port number from the transport handle are registered with the binder.
  54. * These data are registered with the rpc svc system via svc_register.
  55. *
  56. * A service's dispatch function is called whenever an rpc request comes in
  57. * on a transport. The request's program and version numbers must match
  58. * those of the registered service. The dispatch function is passed two
  59. * parameters, struct svc_req * and SVCXPRT *, defined below.
  60. */
  61. enum xprt_stat {
  62. XPRT_DIED,
  63. XPRT_MOREREQS,
  64. XPRT_IDLE
  65. };
  66. /*
  67. * Server side transport handle
  68. */
  69. typedef struct SVCXPRT SVCXPRT;
  70. struct SVCXPRT {
  71. int xp_sock;
  72. u_short xp_port; /* associated port number */
  73. const struct xp_ops {
  74. bool_t (*xp_recv) __P ((SVCXPRT *__xprt, struct rpc_msg *__msg));
  75. /* receive incoming requests */
  76. enum xprt_stat (*xp_stat) __P ((SVCXPRT *__xprt));
  77. /* get transport status */
  78. bool_t (*xp_getargs) __P ((SVCXPRT *__xprt, xdrproc_t __xdr_args,
  79. caddr_t args_ptr)); /* get arguments */
  80. bool_t (*xp_reply) __P ((SVCXPRT *__xprt, struct rpc_msg *__msg));
  81. /* send reply */
  82. bool_t (*xp_freeargs) __P ((SVCXPRT *__xprt, xdrproc_t __xdr_args,
  83. caddr_t args_ptr));
  84. /* free mem allocated for args */
  85. void (*xp_destroy) __P ((SVCXPRT *__xprt));
  86. /* destroy this struct */
  87. } *xp_ops;
  88. int xp_addrlen; /* length of remote address */
  89. struct sockaddr_in xp_raddr; /* remote address */
  90. struct opaque_auth xp_verf; /* raw response verifier */
  91. caddr_t xp_p1; /* private */
  92. caddr_t xp_p2; /* private */
  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. u_long rq_prog; /* service program number */
  135. u_long rq_vers; /* service protocol version */
  136. u_long 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) __P ((struct svc_req*, SVCXPRT*));
  144. #endif
  145. /*
  146. * Service registration
  147. *
  148. * svc_register(xprt, prog, vers, dispatch, protocol)
  149. * SVCXPRT *xprt;
  150. * u_long prog;
  151. * u_long vers;
  152. * void (*dispatch)();
  153. * u_long protocol; like TCP or UDP, zero means do not register
  154. */
  155. extern bool_t svc_register __P ((SVCXPRT *__xprt, u_long __prog,
  156. u_long __vers, __dispatch_fn_t __dispatch,
  157. u_long __protocol));
  158. /*
  159. * Service un-registration
  160. *
  161. * svc_unregister(prog, vers)
  162. * u_long prog;
  163. * u_long vers;
  164. */
  165. extern void svc_unregister __P ((u_long __prog, u_long __vers));
  166. /*
  167. * Transport registration.
  168. *
  169. * xprt_register(xprt)
  170. * SVCXPRT *xprt;
  171. */
  172. extern void xprt_register __P ((SVCXPRT *__xprt));
  173. /*
  174. * Transport un-register
  175. *
  176. * xprt_unregister(xprt)
  177. * SVCXPRT *xprt;
  178. */
  179. extern void xprt_unregister __P ((SVCXPRT *__xprt));
  180. /*
  181. * When the service routine is called, it must first check to see if it
  182. * knows about the procedure; if not, it should call svcerr_noproc
  183. * and return. If so, it should deserialize its arguments via
  184. * SVC_GETARGS (defined above). If the deserialization does not work,
  185. * svcerr_decode should be called followed by a return. Successful
  186. * decoding of the arguments should be followed the execution of the
  187. * procedure's code and a call to svc_sendreply.
  188. *
  189. * Also, if the service refuses to execute the procedure due to too-
  190. * weak authentication parameters, svcerr_weakauth should be called.
  191. * Note: do not confuse access-control failure with weak authentication!
  192. *
  193. * NB: In pure implementations of rpc, the caller always waits for a reply
  194. * msg. This message is sent when svc_sendreply is called.
  195. * Therefore pure service implementations should always call
  196. * svc_sendreply even if the function logically returns void; use
  197. * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
  198. * for the abuse of pure rpc via batched calling or pipelining. In the
  199. * case of a batched call, svc_sendreply should NOT be called since
  200. * this would send a return message, which is what batching tries to avoid.
  201. * It is the service/protocol writer's responsibility to know which calls are
  202. * batched and which are not. Warning: responding to batch calls may
  203. * deadlock the caller and server processes!
  204. */
  205. extern bool_t svc_sendreply __P ((SVCXPRT *xprt, xdrproc_t __xdr_results,
  206. caddr_t __xdr_location));
  207. extern void svcerr_decode __P ((SVCXPRT *__xprt));
  208. extern void svcerr_weakauth __P ((SVCXPRT *__xprt));
  209. extern void svcerr_noproc __P ((SVCXPRT *__xprt));
  210. extern void svcerr_progvers __P ((SVCXPRT *__xprt, u_long __low_vers,
  211. u_long __high_vers));
  212. extern void svcerr_auth __P ((SVCXPRT *__xprt, enum auth_stat __why));
  213. extern void svcerr_noprog __P ((SVCXPRT *__xprt));
  214. extern void svcerr_systemerr __P ((SVCXPRT *__xprt));
  215. /*
  216. * Lowest level dispatching -OR- who owns this process anyway.
  217. * Somebody has to wait for incoming requests and then call the correct
  218. * service routine. The routine svc_run does infinite waiting; i.e.,
  219. * svc_run never returns.
  220. * Since another (coexistent) package may wish to selectively wait for
  221. * incoming calls or other events outside of the rpc architecture, the
  222. * routine svc_getreq is provided. It must be passed readfds, the
  223. * "in-place" results of a select system call (see select, section 2).
  224. */
  225. /*
  226. * Global keeper of rpc service descriptors in use
  227. * dynamic; must be inspected before each call to select
  228. */
  229. #ifdef FD_SETSIZE
  230. extern fd_set svc_fdset;
  231. #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
  232. #else
  233. extern int svc_fds;
  234. #endif /* def FD_SETSIZE */
  235. /*
  236. * a small program implemented by the svc_rpc implementation itself;
  237. * also see clnt.h for protocol numbers.
  238. */
  239. extern void svc_getreq __P ((int __rdfds));
  240. extern void svc_getreqset __P ((fd_set *__readfds));
  241. extern void svc_exit __P ((void));
  242. extern void svc_run __P ((void));
  243. /*
  244. * Socket to use on svcxxx_create call to get default socket
  245. */
  246. #define RPC_ANYSOCK -1
  247. /*
  248. * These are the existing service side transport implementations
  249. */
  250. /*
  251. * Memory based rpc for testing and timing.
  252. */
  253. extern SVCXPRT *svcraw_create __P ((void));
  254. /*
  255. * Udp based rpc.
  256. */
  257. extern SVCXPRT *svcudp_create __P ((int __sock));
  258. extern SVCXPRT *svcudp_bufcreate __P ((int __sock, u_int __sendsz,
  259. u_int __recvsz));
  260. /*
  261. * Tcp based rpc.
  262. */
  263. extern SVCXPRT *svctcp_create __P ((int __sock, u_int __sendsize,
  264. u_int __recvsize));
  265. /*
  266. * Unix based rpc.
  267. */
  268. extern SVCXPRT *svcunix_create __P ((int __sock, u_int __sendsize,
  269. u_int __recvsize, char *__path));
  270. __END_DECLS
  271. #endif /* rpc/svc.h */