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