svc_raw.c revision 181344
174462Salfred/* $NetBSD: svc_raw.c,v 1.14 2000/07/06 03:10:35 christos Exp $ */ 274462Salfred 31901Swollman/* 41901Swollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 51901Swollman * unrestricted use provided that this legend is included on all tape 61901Swollman * media and as a part of the software program in whole or part. Users 71901Swollman * may copy or modify Sun RPC without charge, but are not authorized 81901Swollman * to license or distribute it to anyone else except as part of a product or 91901Swollman * program developed by the user. 108870Srgrimes * 111901Swollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 121901Swollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 131901Swollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 148870Srgrimes * 151901Swollman * Sun RPC is provided with no support and without any obligation on the 161901Swollman * part of Sun Microsystems, Inc. to assist in its use, correction, 171901Swollman * modification or enhancement. 188870Srgrimes * 191901Swollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 201901Swollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 211901Swollman * OR ANY PART THEREOF. 228870Srgrimes * 231901Swollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 241901Swollman * or profits or other special, indirect and consequential damages, even if 251901Swollman * Sun has been advised of the possibility of such damages. 268870Srgrimes * 271901Swollman * Sun Microsystems, Inc. 281901Swollman * 2550 Garcia Avenue 291901Swollman * Mountain View, California 94043 301901Swollman */ 3174462Salfred/* 3274462Salfred * Copyright (c) 1986-1991 by Sun Microsystems Inc. 3374462Salfred */ 341901Swollman 3574462Salfred/* #ident "@(#)svc_raw.c 1.16 94/04/24 SMI" */ 3674462Salfred 37136581Sobrien#if defined(LIBC_SCCS) && !defined(lint) 3874462Salfredstatic char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro"; 391901Swollman#endif 4092990Sobrien#include <sys/cdefs.h> 4192990Sobrien__FBSDID("$FreeBSD: head/lib/libc/rpc/svc_raw.c 181344 2008-08-06 14:02:05Z dfr $"); 421901Swollman 431901Swollman/* 441901Swollman * svc_raw.c, This a toy for simple testing and timing. 451901Swollman * Interface to create an rpc client and server in the same UNIX process. 461901Swollman * This lets us similate rpc and get rpc (round trip) overhead, without 4785138Salfred * any interference from the kernel. 481901Swollman * 491901Swollman */ 501901Swollman 5175094Siedowse#include "namespace.h" 5274462Salfred#include "reentrant.h" 531901Swollman#include <rpc/rpc.h> 5474462Salfred#include <sys/types.h> 5574462Salfred#include <rpc/raw.h> 5611666Sphk#include <stdlib.h> 5774462Salfred#include "un-namespace.h" 58156090Sdeischen#include "mt_misc.h" 591901Swollman 6074462Salfred#ifndef UDPMSGSIZE 6174462Salfred#define UDPMSGSIZE 8800 6274462Salfred#endif 6374462Salfred 641901Swollman/* 651901Swollman * This is the "network" that we will be moving data over 661901Swollman */ 6774462Salfredstatic struct svc_raw_private { 6874462Salfred char *raw_buf; /* should be shared with the cl handle */ 69181344Sdfr SVCXPRT *server; 701901Swollman XDR xdr_stream; 711901Swollman char verf_body[MAX_AUTH_BYTES]; 7274462Salfred} *svc_raw_private; 731901Swollman 7492905Sobrienstatic enum xprt_stat svc_raw_stat(SVCXPRT *); 7592905Sobrienstatic bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *); 7692905Sobrienstatic bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *); 7795658Sdesstatic bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *); 7895658Sdesstatic bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *); 7992905Sobrienstatic void svc_raw_destroy(SVCXPRT *); 8092905Sobrienstatic void svc_raw_ops(SVCXPRT *); 8192905Sobrienstatic bool_t svc_raw_control(SVCXPRT *, const u_int, void *); 821901Swollman 8374462Salfredchar *__rpc_rawcombuf = NULL; 8474462Salfred 851901SwollmanSVCXPRT * 8674462Salfredsvc_raw_create() 871901Swollman{ 8874462Salfred struct svc_raw_private *srp; 8974462Salfred/* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */ 901901Swollman 9174462Salfred mutex_lock(&svcraw_lock); 9274462Salfred srp = svc_raw_private; 9374462Salfred if (srp == NULL) { 9474462Salfred srp = (struct svc_raw_private *)calloc(1, sizeof (*srp)); 9574462Salfred if (srp == NULL) { 9674462Salfred mutex_unlock(&svcraw_lock); 9774462Salfred return (NULL); 9874462Salfred } 9974462Salfred if (__rpc_rawcombuf == NULL) 10074462Salfred __rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char)); 10174462Salfred srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */ 102181344Sdfr srp->server = svc_xprt_alloc(); 10374462Salfred svc_raw_private = srp; 1041901Swollman } 105181344Sdfr srp->server->xp_fd = FD_SETSIZE; 106181344Sdfr srp->server->xp_port = 0; 107181344Sdfr svc_raw_ops(srp->server); 108181344Sdfr srp->server->xp_verf.oa_base = srp->verf_body; 10974462Salfred xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE); 110181344Sdfr xprt_register(srp->server); 11174462Salfred mutex_unlock(&svcraw_lock); 112181344Sdfr return (srp->server); 1131901Swollman} 1141901Swollman 11574462Salfred/*ARGSUSED*/ 1161901Swollmanstatic enum xprt_stat 11774462Salfredsvc_raw_stat(xprt) 11874462SalfredSVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */ 1191901Swollman{ 1201901Swollman return (XPRT_IDLE); 1211901Swollman} 1221901Swollman 12374462Salfred/*ARGSUSED*/ 1241901Swollmanstatic bool_t 12574462Salfredsvc_raw_recv(xprt, msg) 1261901Swollman SVCXPRT *xprt; 1271901Swollman struct rpc_msg *msg; 1281901Swollman{ 12974462Salfred struct svc_raw_private *srp; 13074462Salfred XDR *xdrs; 1311901Swollman 13274462Salfred mutex_lock(&svcraw_lock); 13374462Salfred srp = svc_raw_private; 13474462Salfred if (srp == NULL) { 13574462Salfred mutex_unlock(&svcraw_lock); 13674462Salfred return (FALSE); 13774462Salfred } 13874462Salfred mutex_unlock(&svcraw_lock); 13974462Salfred 1401901Swollman xdrs = &srp->xdr_stream; 1411901Swollman xdrs->x_op = XDR_DECODE; 14274462Salfred (void) XDR_SETPOS(xdrs, 0); 14374462Salfred if (! xdr_callmsg(xdrs, msg)) { 14474462Salfred return (FALSE); 14574462Salfred } 1461901Swollman return (TRUE); 1471901Swollman} 1481901Swollman 14974462Salfred/*ARGSUSED*/ 1501901Swollmanstatic bool_t 15174462Salfredsvc_raw_reply(xprt, msg) 1521901Swollman SVCXPRT *xprt; 1531901Swollman struct rpc_msg *msg; 1541901Swollman{ 15574462Salfred struct svc_raw_private *srp; 15674462Salfred XDR *xdrs; 157181344Sdfr bool_t stat; 158181344Sdfr xdrproc_t xdr_proc; 159181344Sdfr caddr_t xdr_where; 1601901Swollman 16174462Salfred mutex_lock(&svcraw_lock); 16274462Salfred srp = svc_raw_private; 16374462Salfred if (srp == NULL) { 16474462Salfred mutex_unlock(&svcraw_lock); 1651901Swollman return (FALSE); 16674462Salfred } 16774462Salfred mutex_unlock(&svcraw_lock); 16874462Salfred 1691901Swollman xdrs = &srp->xdr_stream; 1701901Swollman xdrs->x_op = XDR_ENCODE; 17174462Salfred (void) XDR_SETPOS(xdrs, 0); 172181344Sdfr if (msg->rm_reply.rp_stat == MSG_ACCEPTED && 173181344Sdfr msg->rm_reply.rp_acpt.ar_stat == SUCCESS) { 174181344Sdfr xdr_proc = msg->acpted_rply.ar_results.proc; 175181344Sdfr xdr_where = msg->acpted_rply.ar_results.where; 176181344Sdfr msg->acpted_rply.ar_results.proc = (xdrproc_t) xdr_void; 177181344Sdfr msg->acpted_rply.ar_results.where = NULL; 178181344Sdfr 179181344Sdfr if (!xdr_replymsg(xdrs, msg) || 180181344Sdfr !SVCAUTH_WRAP(&SVC_AUTH(xprt), xdrs, xdr_proc, xdr_where)) 181181344Sdfr stat = FALSE; 182181344Sdfr } else { 183181344Sdfr stat = xdr_replymsg(xdrs, msg); 184181344Sdfr } 185181344Sdfr if (!stat) { 18674462Salfred return (FALSE); 18774462Salfred } 18874462Salfred (void) XDR_GETPOS(xdrs); /* called just for overhead */ 1891901Swollman return (TRUE); 1901901Swollman} 1911901Swollman 19274462Salfred/*ARGSUSED*/ 1931901Swollmanstatic bool_t 19474462Salfredsvc_raw_getargs(xprt, xdr_args, args_ptr) 1951901Swollman SVCXPRT *xprt; 1961901Swollman xdrproc_t xdr_args; 19795658Sdes void *args_ptr; 1981901Swollman{ 19974462Salfred struct svc_raw_private *srp; 2001901Swollman 20174462Salfred mutex_lock(&svcraw_lock); 20274462Salfred srp = svc_raw_private; 20374462Salfred if (srp == NULL) { 20474462Salfred mutex_unlock(&svcraw_lock); 2051901Swollman return (FALSE); 20674462Salfred } 20774462Salfred mutex_unlock(&svcraw_lock); 208181344Sdfr 209181344Sdfr return (SVCAUTH_UNWRAP(&SVC_AUTH(xprt), &srp->xdr_stream, 210181344Sdfr xdr_args, args_ptr)); 2111901Swollman} 2121901Swollman 21374462Salfred/*ARGSUSED*/ 2141901Swollmanstatic bool_t 21574462Salfredsvc_raw_freeargs(xprt, xdr_args, args_ptr) 2161901Swollman SVCXPRT *xprt; 2171901Swollman xdrproc_t xdr_args; 21895658Sdes void *args_ptr; 2198870Srgrimes{ 22074462Salfred struct svc_raw_private *srp; 22174462Salfred XDR *xdrs; 2221901Swollman 22374462Salfred mutex_lock(&svcraw_lock); 22474462Salfred srp = svc_raw_private; 22574462Salfred if (srp == NULL) { 22674462Salfred mutex_unlock(&svcraw_lock); 2271901Swollman return (FALSE); 22874462Salfred } 22974462Salfred mutex_unlock(&svcraw_lock); 23074462Salfred 2311901Swollman xdrs = &srp->xdr_stream; 2321901Swollman xdrs->x_op = XDR_FREE; 23374462Salfred return (*xdr_args)(xdrs, args_ptr); 2348870Srgrimes} 2351901Swollman 23674462Salfred/*ARGSUSED*/ 2371901Swollmanstatic void 23874462Salfredsvc_raw_destroy(xprt) 23974462SalfredSVCXPRT *xprt; 2401901Swollman{ 2411901Swollman} 24274462Salfred 24374462Salfred/*ARGSUSED*/ 24474462Salfredstatic bool_t 24574462Salfredsvc_raw_control(xprt, rq, in) 24674462Salfred SVCXPRT *xprt; 24774462Salfred const u_int rq; 24874462Salfred void *in; 24974462Salfred{ 25074462Salfred return (FALSE); 25174462Salfred} 25274462Salfred 25374462Salfredstatic void 25474462Salfredsvc_raw_ops(xprt) 25574462Salfred SVCXPRT *xprt; 25674462Salfred{ 25774462Salfred static struct xp_ops ops; 25874462Salfred static struct xp_ops2 ops2; 25974462Salfred 26074462Salfred/* VARIABLES PROTECTED BY ops_lock: ops */ 26174462Salfred 26274462Salfred mutex_lock(&ops_lock); 26374462Salfred if (ops.xp_recv == NULL) { 26474462Salfred ops.xp_recv = svc_raw_recv; 26574462Salfred ops.xp_stat = svc_raw_stat; 26674462Salfred ops.xp_getargs = svc_raw_getargs; 26774462Salfred ops.xp_reply = svc_raw_reply; 26874462Salfred ops.xp_freeargs = svc_raw_freeargs; 26974462Salfred ops.xp_destroy = svc_raw_destroy; 27074462Salfred ops2.xp_control = svc_raw_control; 27174462Salfred } 27274462Salfred xprt->xp_ops = &ops; 27374462Salfred xprt->xp_ops2 = &ops2; 27474462Salfred mutex_unlock(&ops_lock); 27574462Salfred} 276