clnt_raw.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */
  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. #if 0
  31. static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
  32. #endif
  33. /*
  34. * clnt_raw.c
  35. *
  36. * Copyright (C) 1984, Sun Microsystems, Inc.
  37. *
  38. * Memory based rpc for simple testing and timing.
  39. * Interface to create an rpc client and server in the same process.
  40. * This lets us simulate rpc and get round trip overhead, without
  41. * any interference from the kernel.
  42. */
  43. #define authnone_create __authnone_create
  44. #define xdrmem_create __xdrmem_create
  45. #define __FORCE_GLIBC
  46. #include <features.h>
  47. #include "rpc_private.h"
  48. #include <rpc/svc.h>
  49. #include <rpc/xdr.h>
  50. #define MCALL_MSG_SIZE 24
  51. /*
  52. * This is the "network" we will be moving stuff over.
  53. */
  54. struct clntraw_private_s
  55. {
  56. CLIENT client_object;
  57. XDR xdr_stream;
  58. char _raw_buf[UDPMSGSIZE];
  59. char mashl_callmsg[MCALL_MSG_SIZE];
  60. u_int mcnt;
  61. };
  62. #ifdef __UCLIBC_HAS_THREADS__
  63. #define clntraw_private (*(struct clntraw_private_s **)&RPC_THREAD_VARIABLE(clntraw_private_s))
  64. #else
  65. static struct clntraw_private_s *clntraw_private;
  66. #endif
  67. static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
  68. xdrproc_t, caddr_t, struct timeval);
  69. static void clntraw_abort (void);
  70. static void clntraw_geterr (CLIENT *, struct rpc_err *);
  71. static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
  72. static bool_t clntraw_control (CLIENT *, int, char *);
  73. static void clntraw_destroy (CLIENT *);
  74. static struct clnt_ops client_ops =
  75. {
  76. clntraw_call,
  77. clntraw_abort,
  78. clntraw_geterr,
  79. clntraw_freeres,
  80. clntraw_destroy,
  81. clntraw_control
  82. };
  83. /*
  84. * Create a client handle for memory based rpc.
  85. */
  86. CLIENT *
  87. clntraw_create (u_long prog, u_long vers)
  88. {
  89. struct clntraw_private_s *clp = clntraw_private;
  90. struct rpc_msg call_msg;
  91. XDR *xdrs = &clp->xdr_stream;
  92. CLIENT *client = &clp->client_object;
  93. if (clp == 0)
  94. {
  95. clp = (struct clntraw_private_s *) calloc (1, sizeof (*clp));
  96. if (clp == 0)
  97. return (0);
  98. clntraw_private = clp;
  99. }
  100. /*
  101. * pre-serialize the static part of the call msg and stash it away
  102. */
  103. call_msg.rm_direction = CALL;
  104. call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  105. call_msg.rm_call.cb_prog = prog;
  106. call_msg.rm_call.cb_vers = vers;
  107. xdrmem_create (xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
  108. if (!xdr_callhdr (xdrs, &call_msg))
  109. {
  110. perror (_ ("clnt_raw.c - Fatal header serialization error."));
  111. }
  112. clp->mcnt = XDR_GETPOS (xdrs);
  113. XDR_DESTROY (xdrs);
  114. /*
  115. * Set xdrmem for client/server shared buffer
  116. */
  117. xdrmem_create (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
  118. /*
  119. * create client handle
  120. */
  121. client->cl_ops = &client_ops;
  122. client->cl_auth = authnone_create ();
  123. return client;
  124. }
  125. static enum clnt_stat
  126. clntraw_call (h, proc, xargs, argsp, xresults, resultsp, timeout)
  127. CLIENT *h;
  128. u_long proc;
  129. xdrproc_t xargs;
  130. caddr_t argsp;
  131. xdrproc_t xresults;
  132. caddr_t resultsp;
  133. struct timeval timeout;
  134. {
  135. struct clntraw_private_s *clp = clntraw_private;
  136. XDR *xdrs = &clp->xdr_stream;
  137. struct rpc_msg msg;
  138. enum clnt_stat status;
  139. struct rpc_err error;
  140. if (clp == NULL)
  141. return RPC_FAILED;
  142. call_again:
  143. /*
  144. * send request
  145. */
  146. xdrs->x_op = XDR_ENCODE;
  147. XDR_SETPOS (xdrs, 0);
  148. ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
  149. if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg, clp->mcnt)) ||
  150. (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
  151. (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
  152. (!(*xargs) (xdrs, argsp)))
  153. {
  154. return (RPC_CANTENCODEARGS);
  155. }
  156. (void) XDR_GETPOS (xdrs); /* called just to cause overhead */
  157. /*
  158. * We have to call server input routine here because this is
  159. * all going on in one process. Yuk.
  160. */
  161. svc_getreq (1);
  162. /*
  163. * get results
  164. */
  165. xdrs->x_op = XDR_DECODE;
  166. XDR_SETPOS (xdrs, 0);
  167. msg.acpted_rply.ar_verf = _null_auth;
  168. msg.acpted_rply.ar_results.where = resultsp;
  169. msg.acpted_rply.ar_results.proc = xresults;
  170. if (!xdr_replymsg (xdrs, &msg))
  171. return RPC_CANTDECODERES;
  172. _seterr_reply (&msg, &error);
  173. status = error.re_status;
  174. if (status == RPC_SUCCESS)
  175. {
  176. if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
  177. {
  178. status = RPC_AUTHERROR;
  179. }
  180. } /* end successful completion */
  181. else
  182. {
  183. if (AUTH_REFRESH (h->cl_auth))
  184. goto call_again;
  185. } /* end of unsuccessful completion */
  186. if (status == RPC_SUCCESS)
  187. {
  188. if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
  189. {
  190. status = RPC_AUTHERROR;
  191. }
  192. if (msg.acpted_rply.ar_verf.oa_base != NULL)
  193. {
  194. xdrs->x_op = XDR_FREE;
  195. (void) xdr_opaque_auth (xdrs, &(msg.acpted_rply.ar_verf));
  196. }
  197. }
  198. return status;
  199. }
  200. static void
  201. clntraw_geterr (CLIENT *cl, struct rpc_err *err)
  202. {
  203. }
  204. static bool_t
  205. clntraw_freeres (cl, xdr_res, res_ptr)
  206. CLIENT *cl;
  207. xdrproc_t xdr_res;
  208. caddr_t res_ptr;
  209. {
  210. struct clntraw_private_s *clp = clntraw_private;
  211. XDR *xdrs = &clp->xdr_stream;
  212. bool_t rval;
  213. if (clp == NULL)
  214. {
  215. rval = (bool_t) RPC_FAILED;
  216. return rval;
  217. }
  218. xdrs->x_op = XDR_FREE;
  219. return (*xdr_res) (xdrs, res_ptr);
  220. }
  221. static void
  222. clntraw_abort (void)
  223. {
  224. }
  225. static bool_t
  226. clntraw_control (CLIENT *cl, int i, char *c)
  227. {
  228. return FALSE;
  229. }
  230. static void
  231. clntraw_destroy (CLIENT *cl)
  232. {
  233. }