clnt_raw.c revision 8870
1/* 2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 * unrestricted use provided that this legend is included on all tape 4 * media and as a part of the software program in whole or part. Users 5 * may copy or modify Sun RPC without charge, but are not authorized 6 * to license or distribute it to anyone else except as part of a product or 7 * program developed by the user. 8 * 9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 * 13 * Sun RPC is provided with no support and without any obligation on the 14 * part of Sun Microsystems, Inc. to assist in its use, correction, 15 * modification or enhancement. 16 * 17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 * OR ANY PART THEREOF. 20 * 21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 * or profits or other special, indirect and consequential damages, even if 23 * Sun has been advised of the possibility of such damages. 24 * 25 * Sun Microsystems, Inc. 26 * 2550 Garcia Avenue 27 * Mountain View, California 94043 28 */ 29 30#if defined(LIBC_SCCS) && !defined(lint) 31/*static char *sccsid = "from: @(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";*/ 32/*static char *sccsid = "from: @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC";*/ 33static char *rcsid = "$Id: clnt_raw.c,v 1.1 1994/08/07 18:35:45 wollman Exp $"; 34#endif 35 36/* 37 * clnt_raw.c 38 * 39 * Copyright (C) 1984, Sun Microsystems, Inc. 40 * 41 * Memory based rpc for simple testing and timing. 42 * Interface to create an rpc client and server in the same process. 43 * This lets us similate rpc and get round trip overhead, without 44 * any interference from the kernal. 45 */ 46 47#include <rpc/rpc.h> 48 49#define MCALL_MSG_SIZE 24 50 51/* 52 * This is the "network" we will be moving stuff over. 53 */ 54static struct clntraw_private { 55 CLIENT client_object; 56 XDR xdr_stream; 57 char _raw_buf[UDPMSGSIZE]; 58 char mashl_callmsg[MCALL_MSG_SIZE]; 59 u_int mcnt; 60} *clntraw_private; 61 62static enum clnt_stat clntraw_call(); 63static void clntraw_abort(); 64static void clntraw_geterr(); 65static bool_t clntraw_freeres(); 66static bool_t clntraw_control(); 67static void clntraw_destroy(); 68 69static struct clnt_ops client_ops = { 70 clntraw_call, 71 clntraw_abort, 72 clntraw_geterr, 73 clntraw_freeres, 74 clntraw_destroy, 75 clntraw_control 76}; 77 78void svc_getreq(); 79 80/* 81 * Create a client handle for memory based rpc. 82 */ 83CLIENT * 84clntraw_create(prog, vers) 85 u_long prog; 86 u_long vers; 87{ 88 register struct clntraw_private *clp = clntraw_private; 89 struct rpc_msg call_msg; 90 XDR *xdrs = &clp->xdr_stream; 91 CLIENT *client = &clp->client_object; 92 93 if (clp == 0) { 94 clp = (struct clntraw_private *)calloc(1, sizeof (*clp)); 95 if (clp == 0) 96 return (0); 97 clntraw_private = clp; 98 } 99 /* 100 * pre-serialize the staic part of the call msg and stash it away 101 */ 102 call_msg.rm_direction = CALL; 103 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; 104 call_msg.rm_call.cb_prog = prog; 105 call_msg.rm_call.cb_vers = vers; 106 xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE); 107 if (! xdr_callhdr(xdrs, &call_msg)) { 108 perror("clnt_raw.c - Fatal header serialization error."); 109 } 110 clp->mcnt = XDR_GETPOS(xdrs); 111 XDR_DESTROY(xdrs); 112 113 /* 114 * Set xdrmem for client/server shared buffer 115 */ 116 xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE); 117 118 /* 119 * create client handle 120 */ 121 client->cl_ops = &client_ops; 122 client->cl_auth = authnone_create(); 123 return (client); 124} 125 126static enum clnt_stat 127clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout) 128 CLIENT *h; 129 u_long proc; 130 xdrproc_t xargs; 131 caddr_t argsp; 132 xdrproc_t xresults; 133 caddr_t resultsp; 134 struct timeval timeout; 135{ 136 register struct clntraw_private *clp = clntraw_private; 137 register XDR *xdrs = &clp->xdr_stream; 138 struct rpc_msg msg; 139 enum clnt_stat status; 140 struct rpc_err error; 141 142 if (clp == 0) 143 return (RPC_FAILED); 144call_again: 145 /* 146 * send request 147 */ 148 xdrs->x_op = XDR_ENCODE; 149 XDR_SETPOS(xdrs, 0); 150 ((struct rpc_msg *)clp->mashl_callmsg)->rm_xid ++ ; 151 if ((! XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) || 152 (! XDR_PUTLONG(xdrs, (long *)&proc)) || 153 (! AUTH_MARSHALL(h->cl_auth, xdrs)) || 154 (! (*xargs)(xdrs, argsp))) { 155 return (RPC_CANTENCODEARGS); 156 } 157 (void)XDR_GETPOS(xdrs); /* called just to cause overhead */ 158 159 /* 160 * We have to call server input routine here because this is 161 * all going on in one process. Yuk. 162 */ 163 svc_getreq(1); 164 165 /* 166 * get results 167 */ 168 xdrs->x_op = XDR_DECODE; 169 XDR_SETPOS(xdrs, 0); 170 msg.acpted_rply.ar_verf = _null_auth; 171 msg.acpted_rply.ar_results.where = resultsp; 172 msg.acpted_rply.ar_results.proc = xresults; 173 if (! xdr_replymsg(xdrs, &msg)) 174 return (RPC_CANTDECODERES); 175 _seterr_reply(&msg, &error); 176 status = error.re_status; 177 178 if (status == RPC_SUCCESS) { 179 if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) { 180 status = RPC_AUTHERROR; 181 } 182 } /* end successful completion */ 183 else { 184 if (AUTH_REFRESH(h->cl_auth)) 185 goto call_again; 186 } /* end of unsuccessful completion */ 187 188 if (status == RPC_SUCCESS) { 189 if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) { 190 status = RPC_AUTHERROR; 191 } 192 if (msg.acpted_rply.ar_verf.oa_base != NULL) { 193 xdrs->x_op = XDR_FREE; 194 (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf)); 195 } 196 } 197 198 return (status); 199} 200 201static void 202clntraw_geterr() 203{ 204} 205 206 207static bool_t 208clntraw_freeres(cl, xdr_res, res_ptr) 209 CLIENT *cl; 210 xdrproc_t xdr_res; 211 caddr_t res_ptr; 212{ 213 register struct clntraw_private *clp = clntraw_private; 214 register XDR *xdrs = &clp->xdr_stream; 215 bool_t rval; 216 217 if (clp == 0) 218 { 219 rval = (bool_t) RPC_FAILED; 220 return (rval); 221 } 222 xdrs->x_op = XDR_FREE; 223 return ((*xdr_res)(xdrs, res_ptr)); 224} 225 226static void 227clntraw_abort() 228{ 229} 230 231static bool_t 232clntraw_control() 233{ 234 return (FALSE); 235} 236 237static void 238clntraw_destroy() 239{ 240} 241