1 /* @(#)svc_raw.c 2.1 88/07/29 4.0 RPCSRC */ 2 /* 3 * Copyright (c) 2010, Oracle America, Inc. 4 * 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * * Neither the name of the "Oracle America, Inc." nor the names of 19 * its contributors may be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 #if !defined(lint) && defined(SCCSIDS) 35 static char sccsid[] = "@(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro"; 36 #endif 37 38 /* 39 * svc_raw.c, This a toy for simple testing and timing. 40 * Interface to create an rpc client and server in the same UNIX process. 41 * This lets us similate rpc and get rpc (round trip) overhead, without 42 * any interference from the kernel. 43 */ 44 45 #include <gssrpc/rpc.h> 46 47 48 /* 49 * This is the "network" that we will be moving data over 50 */ 51 static struct svcraw_private { 52 char _raw_buf[UDPMSGSIZE]; 53 SVCXPRT server; 54 XDR xdr_stream; 55 char verf_body[MAX_AUTH_BYTES]; 56 } *svcraw_private; 57 58 static bool_t svcraw_recv(SVCXPRT *, struct rpc_msg *); 59 static enum xprt_stat svcraw_stat(SVCXPRT *); 60 static bool_t svcraw_getargs(SVCXPRT *, xdrproc_t, void *); 61 static bool_t svcraw_reply(SVCXPRT *, struct rpc_msg *); 62 static bool_t svcraw_freeargs(SVCXPRT *, xdrproc_t, void *); 63 static void svcraw_destroy(SVCXPRT *); 64 65 static struct xp_ops server_ops = { 66 svcraw_recv, 67 svcraw_stat, 68 svcraw_getargs, 69 svcraw_reply, 70 svcraw_freeargs, 71 svcraw_destroy 72 }; 73 74 SVCXPRT * 75 svcraw_create(void) 76 { 77 struct svcraw_private *srp = svcraw_private; 78 79 if (srp == 0) { 80 srp = (struct svcraw_private *)calloc(1, sizeof (*srp)); 81 if (srp == 0) 82 return (0); 83 svcraw_private = srp; 84 } 85 srp->server.xp_sock = 0; 86 srp->server.xp_port = 0; 87 srp->server.xp_ops = &server_ops; 88 srp->server.xp_verf.oa_base = srp->verf_body; 89 xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE); 90 return (&srp->server); 91 } 92 93 static enum xprt_stat 94 svcraw_stat(SVCXPRT *xprt) 95 { 96 97 return (XPRT_IDLE); 98 } 99 100 static bool_t 101 svcraw_recv(SVCXPRT *xprt, struct rpc_msg *msg) 102 { 103 struct svcraw_private *srp = svcraw_private; 104 XDR *xdrs; 105 106 if (srp == 0) 107 return (0); 108 xdrs = &srp->xdr_stream; 109 xdrs->x_op = XDR_DECODE; 110 XDR_SETPOS(xdrs, 0); 111 if (! xdr_callmsg(xdrs, msg)) 112 return (FALSE); 113 return (TRUE); 114 } 115 116 static bool_t 117 svcraw_reply(SVCXPRT *xprt, struct rpc_msg *msg) 118 { 119 struct svcraw_private *srp = svcraw_private; 120 XDR *xdrs; 121 122 if (srp == 0) 123 return (FALSE); 124 xdrs = &srp->xdr_stream; 125 xdrs->x_op = XDR_ENCODE; 126 XDR_SETPOS(xdrs, 0); 127 if (! xdr_replymsg(xdrs, msg)) 128 return (FALSE); 129 (void)XDR_GETPOS(xdrs); /* called just for overhead */ 130 return (TRUE); 131 } 132 133 static bool_t 134 svcraw_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) 135 { 136 struct svcraw_private *srp = svcraw_private; 137 138 if (srp == 0) 139 return (FALSE); 140 if (! (*xdr_args)(&srp->xdr_stream, args_ptr)) { 141 (void)svcraw_freeargs(xprt, xdr_args, args_ptr); 142 return FALSE; 143 } 144 return TRUE; 145 } 146 147 static bool_t 148 svcraw_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) 149 { 150 struct svcraw_private *srp = svcraw_private; 151 XDR *xdrs; 152 153 if (srp == 0) 154 return (FALSE); 155 xdrs = &srp->xdr_stream; 156 xdrs->x_op = XDR_FREE; 157 return ((*xdr_args)(xdrs, args_ptr)); 158 } 159 160 static void 161 svcraw_destroy(SVCXPRT *xprt) 162 { 163 } 164