]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/clnt_raw.c
Typo fix in x86_64/dl-machine.h
[thirdparty/glibc.git] / sunrpc / clnt_raw.c
CommitLineData
28f540f4 1/*
a7ab6ec8 2 * clnt_raw.c
cbd3dceb 3 *
a7ab6ec8 4 * Copyright (c) 2010, Oracle America, Inc.
cbd3dceb 5 *
a7ab6ec8
UD
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
cb636bb2 9 *
a7ab6ec8
UD
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.
cb636bb2 19 *
a7ab6ec8
UD
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.
28f540f4
RM
32 *
33 * Memory based rpc for simple testing and timing.
34 * Interface to create an rpc client and server in the same process.
6d52618b
UD
35 * This lets us simulate rpc and get round trip overhead, without
36 * any interference from the kernel.
28f540f4
RM
37 */
38
39#include <rpc/rpc.h>
e7fd8a39
UD
40#include <rpc/svc.h>
41#include <rpc/xdr.h>
4360eafd 42#include <libintl.h>
e7fd8a39 43
28f540f4
RM
44#define MCALL_MSG_SIZE 24
45
46/*
47 * This is the "network" we will be moving stuff over.
48 */
f1e4a4a4 49struct clntraw_private_s
e7fd8a39
UD
50 {
51 CLIENT client_object;
52 XDR xdr_stream;
53 char _raw_buf[UDPMSGSIZE];
6cc8844f
UD
54 union
55 {
56 char msg[MCALL_MSG_SIZE];
57 u_long rm_xid;
58 } mashl_callmsg;
e7fd8a39 59 u_int mcnt;
f1e4a4a4
UD
60 };
61#ifdef _RPC_THREAD_SAFE_
1bc1a2b9 62#define clntraw_private RPC_THREAD_VARIABLE(clntraw_private_s)
f1e4a4a4
UD
63#else
64static struct clntraw_private_s *clntraw_private;
65#endif
e7fd8a39
UD
66
67static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
68 xdrproc_t, caddr_t, struct timeval);
69static void clntraw_abort (void);
70static void clntraw_geterr (CLIENT *, struct rpc_err *);
71static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
72static bool_t clntraw_control (CLIENT *, int, char *);
73static void clntraw_destroy (CLIENT *);
74
a5abbd33 75static const struct clnt_ops client_ops =
e7fd8a39
UD
76{
77 clntraw_call,
78 clntraw_abort,
79 clntraw_geterr,
80 clntraw_freeres,
81 clntraw_destroy,
82 clntraw_control
28f540f4
RM
83};
84
28f540f4
RM
85/*
86 * Create a client handle for memory based rpc.
87 */
88CLIENT *
e7fd8a39 89clntraw_create (u_long prog, u_long vers)
28f540f4 90{
f1e4a4a4 91 struct clntraw_private_s *clp = clntraw_private;
e7fd8a39 92 struct rpc_msg call_msg;
f89bd0e5
UD
93 XDR *xdrs;
94 CLIENT *client;
e7fd8a39
UD
95
96 if (clp == 0)
97 {
f1e4a4a4 98 clp = (struct clntraw_private_s *) calloc (1, sizeof (*clp));
e7fd8a39
UD
99 if (clp == 0)
100 return (0);
101 clntraw_private = clp;
102 }
f89bd0e5
UD
103 xdrs = &clp->xdr_stream;
104 client = &clp->client_object;
e7fd8a39
UD
105 /*
106 * pre-serialize the static part of the call msg and stash it away
107 */
108 call_msg.rm_direction = CALL;
109 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
110 call_msg.rm_call.cb_prog = prog;
111 call_msg.rm_call.cb_vers = vers;
7b57bfe5
UD
112 xdrmem_create (xdrs, clp->mashl_callmsg.msg, MCALL_MSG_SIZE, XDR_ENCODE);
113 if (!xdr_callhdr (xdrs, &call_msg))
e7fd8a39 114 {
11bf311e 115 perror (_ ("clnt_raw.c: fatal header serialization error"));
e7fd8a39
UD
116 }
117 clp->mcnt = XDR_GETPOS (xdrs);
118 XDR_DESTROY (xdrs);
119
120 /*
121 * Set xdrmem for client/server shared buffer
122 */
7b57bfe5 123 xdrmem_create (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
e7fd8a39
UD
124
125 /*
126 * create client handle
127 */
a5abbd33 128 client->cl_ops = (struct clnt_ops *) &client_ops;
7b57bfe5 129 client->cl_auth = authnone_create ();
e7fd8a39 130 return client;
28f540f4 131}
7b57bfe5 132libc_hidden_nolink (clntraw_create, GLIBC_2_0)
28f540f4 133
cbd3dceb 134static enum clnt_stat
e7fd8a39
UD
135clntraw_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;
28f540f4 143{
f1e4a4a4 144 struct clntraw_private_s *clp = clntraw_private;
e7fd8a39
UD
145 XDR *xdrs = &clp->xdr_stream;
146 struct rpc_msg msg;
147 enum clnt_stat status;
148 struct rpc_err error;
149
150 if (clp == NULL)
151 return RPC_FAILED;
28f540f4 152call_again:
e7fd8a39
UD
153 /*
154 * send request
155 */
156 xdrs->x_op = XDR_ENCODE;
157 XDR_SETPOS (xdrs, 0);
6cc8844f
UD
158 /* Just checking the union definition to access rm_xid is correct. */
159 if (offsetof (struct rpc_msg, rm_xid) != 0)
160 abort ();
161 clp->mashl_callmsg.rm_xid++;
162 if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg.msg, clp->mcnt)) ||
e7fd8a39
UD
163 (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
164 (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
165 (!(*xargs) (xdrs, argsp)))
166 {
167 return (RPC_CANTENCODEARGS);
168 }
169 (void) XDR_GETPOS (xdrs); /* called just to cause overhead */
170
171 /*
172 * We have to call server input routine here because this is
173 * all going on in one process. Yuk.
174 */
7b57bfe5 175 svc_getreq (1);
e7fd8a39
UD
176
177 /*
178 * get results
179 */
180 xdrs->x_op = XDR_DECODE;
181 XDR_SETPOS (xdrs, 0);
182 msg.acpted_rply.ar_verf = _null_auth;
183 msg.acpted_rply.ar_results.where = resultsp;
184 msg.acpted_rply.ar_results.proc = xresults;
7b57bfe5 185 if (!xdr_replymsg (xdrs, &msg))
e7fd8a39
UD
186 return RPC_CANTDECODERES;
187 _seterr_reply (&msg, &error);
188 status = error.re_status;
189
190 if (status == RPC_SUCCESS)
191 {
192 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
193 {
194 status = RPC_AUTHERROR;
28f540f4 195 }
e7fd8a39
UD
196 } /* end successful completion */
197 else
198 {
199 if (AUTH_REFRESH (h->cl_auth))
200 goto call_again;
201 } /* end of unsuccessful completion */
202
203 if (status == RPC_SUCCESS)
204 {
205 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
206 {
207 status = RPC_AUTHERROR;
208 }
209 if (msg.acpted_rply.ar_verf.oa_base != NULL)
210 {
211 xdrs->x_op = XDR_FREE;
7b57bfe5 212 (void) xdr_opaque_auth (xdrs, &(msg.acpted_rply.ar_verf));
28f540f4 213 }
e7fd8a39 214 }
28f540f4 215
e7fd8a39 216 return status;
28f540f4
RM
217}
218
219static void
e7fd8a39 220clntraw_geterr (CLIENT *cl, struct rpc_err *err)
28f540f4
RM
221{
222}
223
224
225static bool_t
e7fd8a39
UD
226clntraw_freeres (cl, xdr_res, res_ptr)
227 CLIENT *cl;
228 xdrproc_t xdr_res;
229 caddr_t res_ptr;
28f540f4 230{
f1e4a4a4 231 struct clntraw_private_s *clp = clntraw_private;
e7fd8a39
UD
232 XDR *xdrs = &clp->xdr_stream;
233 bool_t rval;
234
235 if (clp == NULL)
236 {
237 rval = (bool_t) RPC_FAILED;
238 return rval;
239 }
240 xdrs->x_op = XDR_FREE;
241 return (*xdr_res) (xdrs, res_ptr);
28f540f4
RM
242}
243
244static void
e7fd8a39 245clntraw_abort (void)
28f540f4
RM
246{
247}
248
249static bool_t
e7fd8a39 250clntraw_control (CLIENT *cl, int i, char *c)
28f540f4 251{
e7fd8a39 252 return FALSE;
28f540f4
RM
253}
254
255static void
e7fd8a39 256clntraw_destroy (CLIENT *cl)
28f540f4
RM
257{
258}