clnt_raw.c 6.6 KB

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