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