clnt_raw.c 6.3 KB

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