Remove building with NOCRYPTO option
[minix3.git] / lib / libc / rpc / svc_raw.c
blobf1b2640ee4d5498071aed2f1f7c99d6d987b93e2
1 /* $NetBSD: svc_raw.c,v 1.24 2013/03/11 20:19:29 tron Exp $ */
3 /*
4 * Copyright (c) 2010, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
37 /* #ident "@(#)svc_raw.c 1.16 94/04/24 SMI" */
39 #include <sys/cdefs.h>
40 #if defined(LIBC_SCCS) && !defined(lint)
41 #if 0
42 static char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro";
43 #else
44 __RCSID("$NetBSD: svc_raw.c,v 1.24 2013/03/11 20:19:29 tron Exp $");
45 #endif
46 #endif
49 * svc_raw.c, This a toy for simple testing and timing.
50 * Interface to create an rpc client and server in the same UNIX process.
51 * This lets us similate rpc and get rpc (round trip) overhead, without
52 * any interference from the kernel.
56 #include "namespace.h"
57 #include "reentrant.h"
58 #include <rpc/rpc.h>
59 #include <sys/types.h>
60 #include <rpc/raw.h>
61 #include <assert.h>
62 #include <stdlib.h>
64 #ifdef __weak_alias
65 __weak_alias(svc_raw_create,_svc_raw_create)
66 #endif
68 #ifndef UDPMSGSIZE
69 #define UDPMSGSIZE 8800
70 #endif
73 * This is the "network" that we will be moving data over
75 static struct svc_raw_private {
76 char *raw_buf; /* should be shared with the cl handle */
77 SVCXPRT server;
78 XDR xdr_stream;
79 char verf_body[MAX_AUTH_BYTES];
80 } *svc_raw_private;
82 #ifdef _REENTRANT
83 extern mutex_t svcraw_lock;
84 #endif
86 static enum xprt_stat svc_raw_stat(SVCXPRT *);
87 static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *);
88 static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *);
89 static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, caddr_t);
90 static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, caddr_t);
91 static void svc_raw_destroy(SVCXPRT *);
92 static void svc_raw_ops(SVCXPRT *);
93 static bool_t svc_raw_control(SVCXPRT *, const u_int, void *);
95 char *__rpc_rawcombuf = NULL;
97 SVCXPRT *
98 svc_raw_create(void)
100 struct svc_raw_private *srp;
101 /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */
103 mutex_lock(&svcraw_lock);
104 srp = svc_raw_private;
105 if (srp == NULL) {
106 srp = calloc(1, sizeof(*srp));
107 if (srp == NULL)
108 goto out;
109 if (__rpc_rawcombuf == NULL)
110 __rpc_rawcombuf = malloc(UDPMSGSIZE);
111 if (__rpc_rawcombuf == NULL)
112 goto out;
113 srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
114 svc_raw_private = srp;
116 srp->server.xp_fd = FD_SETSIZE;
117 srp->server.xp_port = 0;
118 srp->server.xp_p3 = NULL;
119 svc_raw_ops(&srp->server);
120 srp->server.xp_verf.oa_base = srp->verf_body;
121 xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE);
122 if (!xprt_register(&srp->server))
123 goto out;
124 mutex_unlock(&svcraw_lock);
125 return (&srp->server);
126 out:
127 if (srp != NULL)
128 free(srp);
129 mutex_unlock(&svcraw_lock);
130 return (NULL);
133 /*ARGSUSED*/
134 static enum xprt_stat
135 svc_raw_stat(SVCXPRT *xprt) /* args needed to satisfy ANSI-C typechecking */
137 return (XPRT_IDLE);
140 /*ARGSUSED*/
141 static bool_t
142 svc_raw_recv(SVCXPRT *xprt, struct rpc_msg *msg)
144 struct svc_raw_private *srp;
145 XDR *xdrs;
147 mutex_lock(&svcraw_lock);
148 srp = svc_raw_private;
149 if (srp == NULL) {
150 mutex_unlock(&svcraw_lock);
151 return (FALSE);
153 mutex_unlock(&svcraw_lock);
155 xdrs = &srp->xdr_stream;
156 xdrs->x_op = XDR_DECODE;
157 (void) XDR_SETPOS(xdrs, 0);
158 if (! xdr_callmsg(xdrs, msg)) {
159 return (FALSE);
161 return (TRUE);
164 /*ARGSUSED*/
165 static bool_t
166 svc_raw_reply(SVCXPRT *xprt, struct rpc_msg *msg)
168 struct svc_raw_private *srp;
169 XDR *xdrs;
171 mutex_lock(&svcraw_lock);
172 srp = svc_raw_private;
173 if (srp == NULL) {
174 mutex_unlock(&svcraw_lock);
175 return (FALSE);
177 mutex_unlock(&svcraw_lock);
179 xdrs = &srp->xdr_stream;
180 xdrs->x_op = XDR_ENCODE;
181 (void) XDR_SETPOS(xdrs, 0);
182 if (! xdr_replymsg(xdrs, msg)) {
183 return (FALSE);
185 (void) XDR_GETPOS(xdrs); /* called just for overhead */
186 return (TRUE);
189 /*ARGSUSED*/
190 static bool_t
191 svc_raw_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
193 struct svc_raw_private *srp;
195 mutex_lock(&svcraw_lock);
196 srp = svc_raw_private;
197 if (srp == NULL) {
198 mutex_unlock(&svcraw_lock);
199 return (FALSE);
201 mutex_unlock(&svcraw_lock);
202 return (*xdr_args)(&srp->xdr_stream, args_ptr);
205 /*ARGSUSED*/
206 static bool_t
207 svc_raw_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
209 struct svc_raw_private *srp;
210 XDR *xdrs;
212 mutex_lock(&svcraw_lock);
213 srp = svc_raw_private;
214 if (srp == NULL) {
215 mutex_unlock(&svcraw_lock);
216 return (FALSE);
218 mutex_unlock(&svcraw_lock);
220 xdrs = &srp->xdr_stream;
221 xdrs->x_op = XDR_FREE;
222 return (*xdr_args)(xdrs, args_ptr);
225 /*ARGSUSED*/
226 static void
227 svc_raw_destroy(SVCXPRT *xprt)
231 /*ARGSUSED*/
232 static bool_t
233 svc_raw_control(SVCXPRT *xprt, const u_int rq, void *in)
235 return (FALSE);
238 static void
239 svc_raw_ops(SVCXPRT *xprt)
241 static struct xp_ops ops;
242 static struct xp_ops2 ops2;
243 #ifdef _REENTRANT
244 extern mutex_t ops_lock;
245 #endif
247 _DIAGASSERT(xprt != NULL);
249 /* VARIABLES PROTECTED BY ops_lock: ops */
251 mutex_lock(&ops_lock);
252 if (ops.xp_recv == NULL) {
253 ops.xp_recv = svc_raw_recv;
254 ops.xp_stat = svc_raw_stat;
255 ops.xp_getargs = svc_raw_getargs;
256 ops.xp_reply = svc_raw_reply;
257 ops.xp_freeargs = svc_raw_freeargs;
258 ops.xp_destroy = svc_raw_destroy;
259 ops2.xp_control = svc_raw_control;
261 xprt->xp_ops = &ops;
262 xprt->xp_ops2 = &ops2;
263 mutex_unlock(&ops_lock);