svc_raw.c revision 199785
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 199785 2009-11-25 04:49:41Z wollman $"); 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 179199785Swollman stat = xdr_replymsg(xdrs, msg) && 180199785Swollman SVCAUTH_WRAP(&SVC_AUTH(xprt), xdrs, xdr_proc, xdr_where); 181181344Sdfr } else { 182181344Sdfr stat = xdr_replymsg(xdrs, msg); 183181344Sdfr } 184181344Sdfr if (!stat) { 18574462Salfred return (FALSE); 18674462Salfred } 18774462Salfred (void) XDR_GETPOS(xdrs); /* called just for overhead */ 1881901Swollman return (TRUE); 1891901Swollman} 1901901Swollman 19174462Salfred/*ARGSUSED*/ 1921901Swollmanstatic bool_t 19374462Salfredsvc_raw_getargs(xprt, xdr_args, args_ptr) 1941901Swollman SVCXPRT *xprt; 1951901Swollman xdrproc_t xdr_args; 19695658Sdes void *args_ptr; 1971901Swollman{ 19874462Salfred struct svc_raw_private *srp; 1991901Swollman 20074462Salfred mutex_lock(&svcraw_lock); 20174462Salfred srp = svc_raw_private; 20274462Salfred if (srp == NULL) { 20374462Salfred mutex_unlock(&svcraw_lock); 2041901Swollman return (FALSE); 20574462Salfred } 20674462Salfred mutex_unlock(&svcraw_lock); 207181344Sdfr 208181344Sdfr return (SVCAUTH_UNWRAP(&SVC_AUTH(xprt), &srp->xdr_stream, 209181344Sdfr xdr_args, args_ptr)); 2101901Swollman} 2111901Swollman 21274462Salfred/*ARGSUSED*/ 2131901Swollmanstatic bool_t 21474462Salfredsvc_raw_freeargs(xprt, xdr_args, args_ptr) 2151901Swollman SVCXPRT *xprt; 2161901Swollman xdrproc_t xdr_args; 21795658Sdes void *args_ptr; 2188870Srgrimes{ 21974462Salfred struct svc_raw_private *srp; 22074462Salfred XDR *xdrs; 2211901Swollman 22274462Salfred mutex_lock(&svcraw_lock); 22374462Salfred srp = svc_raw_private; 22474462Salfred if (srp == NULL) { 22574462Salfred mutex_unlock(&svcraw_lock); 2261901Swollman return (FALSE); 22774462Salfred } 22874462Salfred mutex_unlock(&svcraw_lock); 22974462Salfred 2301901Swollman xdrs = &srp->xdr_stream; 2311901Swollman xdrs->x_op = XDR_FREE; 23274462Salfred return (*xdr_args)(xdrs, args_ptr); 2338870Srgrimes} 2341901Swollman 23574462Salfred/*ARGSUSED*/ 2361901Swollmanstatic void 23774462Salfredsvc_raw_destroy(xprt) 23874462SalfredSVCXPRT *xprt; 2391901Swollman{ 2401901Swollman} 24174462Salfred 24274462Salfred/*ARGSUSED*/ 24374462Salfredstatic bool_t 24474462Salfredsvc_raw_control(xprt, rq, in) 24574462Salfred SVCXPRT *xprt; 24674462Salfred const u_int rq; 24774462Salfred void *in; 24874462Salfred{ 24974462Salfred return (FALSE); 25074462Salfred} 25174462Salfred 25274462Salfredstatic void 25374462Salfredsvc_raw_ops(xprt) 25474462Salfred SVCXPRT *xprt; 25574462Salfred{ 25674462Salfred static struct xp_ops ops; 25774462Salfred static struct xp_ops2 ops2; 25874462Salfred 25974462Salfred/* VARIABLES PROTECTED BY ops_lock: ops */ 26074462Salfred 26174462Salfred mutex_lock(&ops_lock); 26274462Salfred if (ops.xp_recv == NULL) { 26374462Salfred ops.xp_recv = svc_raw_recv; 26474462Salfred ops.xp_stat = svc_raw_stat; 26574462Salfred ops.xp_getargs = svc_raw_getargs; 26674462Salfred ops.xp_reply = svc_raw_reply; 26774462Salfred ops.xp_freeargs = svc_raw_freeargs; 26874462Salfred ops.xp_destroy = svc_raw_destroy; 26974462Salfred ops2.xp_control = svc_raw_control; 27074462Salfred } 27174462Salfred xprt->xp_ops = &ops; 27274462Salfred xprt->xp_ops2 = &ops2; 27374462Salfred mutex_unlock(&ops_lock); 27474462Salfred} 275