]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
1 | /* @(#)clnt_udp.c 2.2 88/08/01 4.0 RPCSRC */ |
2 | /* | |
3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | |
4 | * unrestricted use provided that this legend is included on all tape | |
5 | * media and as a part of the software program in whole or part. Users | |
6 | * may copy or modify Sun RPC without charge, but are not authorized | |
7 | * to license or distribute it to anyone else except as part of a product or | |
8 | * program developed by the user. | |
c4029823 | 9 | * |
28f540f4 RM |
10 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE |
11 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | |
12 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | |
c4029823 | 13 | * |
28f540f4 RM |
14 | * Sun RPC is provided with no support and without any obligation on the |
15 | * part of Sun Microsystems, Inc. to assist in its use, correction, | |
16 | * modification or enhancement. | |
c4029823 | 17 | * |
28f540f4 RM |
18 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE |
19 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | |
20 | * OR ANY PART THEREOF. | |
c4029823 | 21 | * |
28f540f4 RM |
22 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue |
23 | * or profits or other special, indirect and consequential damages, even if | |
24 | * Sun has been advised of the possibility of such damages. | |
c4029823 | 25 | * |
28f540f4 RM |
26 | * Sun Microsystems, Inc. |
27 | * 2550 Garcia Avenue | |
28 | * Mountain View, California 94043 | |
29 | */ | |
30 | #if !defined(lint) && defined(SCCSIDS) | |
31 | static char sccsid[] = "@(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro"; | |
32 | #endif | |
33 | ||
34 | /* | |
35 | * clnt_udp.c, Implements a UDP/IP based, client side RPC. | |
36 | * | |
37 | * Copyright (C) 1984, Sun Microsystems, Inc. | |
38 | */ | |
39 | ||
40 | #include <stdio.h> | |
e7fd8a39 | 41 | #include <unistd.h> |
4360eafd | 42 | #include <libintl.h> |
28f540f4 | 43 | #include <rpc/rpc.h> |
e7fd8a39 UD |
44 | #include <rpc/xdr.h> |
45 | #include <rpc/clnt.h> | |
099a6fbd | 46 | #include <sys/poll.h> |
28f540f4 RM |
47 | #include <sys/socket.h> |
48 | #include <sys/ioctl.h> | |
49 | #include <netdb.h> | |
50 | #include <errno.h> | |
51 | #include <rpc/pmap_clnt.h> | |
ea48e2c4 | 52 | #include <net/if.h> |
412c954a | 53 | #include <ifaddrs.h> |
51028f34 UD |
54 | #ifdef USE_IN_LIBIO |
55 | # include <wchar.h> | |
56 | #endif | |
28f540f4 | 57 | |
b1eab230 UD |
58 | #ifdef IP_RECVERR |
59 | #include <errqueue.h> | |
60 | #include <sys/uio.h> | |
61 | #endif | |
62 | ||
e7fd8a39 | 63 | extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *); |
090ca000 | 64 | extern u_long _create_xid (void); |
28f540f4 RM |
65 | |
66 | /* | |
67 | * UDP bases client side rpc operations | |
68 | */ | |
e7fd8a39 UD |
69 | static enum clnt_stat clntudp_call (CLIENT *, u_long, xdrproc_t, caddr_t, |
70 | xdrproc_t, caddr_t, struct timeval); | |
71 | static void clntudp_abort (void); | |
72 | static void clntudp_geterr (CLIENT *, struct rpc_err *); | |
73 | static bool_t clntudp_freeres (CLIENT *, xdrproc_t, caddr_t); | |
74 | static bool_t clntudp_control (CLIENT *, int, char *); | |
75 | static void clntudp_destroy (CLIENT *); | |
28f540f4 | 76 | |
31d7b14c | 77 | static const struct clnt_ops udp_ops = |
e7fd8a39 UD |
78 | { |
79 | clntudp_call, | |
80 | clntudp_abort, | |
81 | clntudp_geterr, | |
82 | clntudp_freeres, | |
83 | clntudp_destroy, | |
84 | clntudp_control | |
28f540f4 RM |
85 | }; |
86 | ||
c4029823 | 87 | /* |
28f540f4 RM |
88 | * Private data kept per client handle |
89 | */ | |
e7fd8a39 UD |
90 | struct cu_data |
91 | { | |
92 | int cu_sock; | |
93 | bool_t cu_closeit; | |
94 | struct sockaddr_in cu_raddr; | |
95 | int cu_rlen; | |
96 | struct timeval cu_wait; | |
97 | struct timeval cu_total; | |
98 | struct rpc_err cu_error; | |
99 | XDR cu_outxdrs; | |
100 | u_int cu_xdrpos; | |
101 | u_int cu_sendsz; | |
102 | char *cu_outbuf; | |
103 | u_int cu_recvsz; | |
104 | char cu_inbuf[1]; | |
105 | }; | |
28f540f4 RM |
106 | |
107 | /* | |
108 | * Create a UDP based client handle. | |
109 | * If *sockp<0, *sockp is set to a newly created UPD socket. | |
110 | * If raddr->sin_port is 0 a binder on the remote machine | |
111 | * is consulted for the correct port number. | |
112 | * NB: It is the clients responsibility to close *sockp. | |
113 | * NB: The rpch->cl_auth is initialized to null authentication. | |
114 | * Caller may wish to set this something more useful. | |
115 | * | |
116 | * wait is the amount of time used between retransmitting a call if | |
6d52618b | 117 | * no response has been heard; retransmission occurs until the actual |
28f540f4 RM |
118 | * rpc call times out. |
119 | * | |
120 | * sendsz and recvsz are the maximum allowable packet sizes that can be | |
121 | * sent and received. | |
122 | */ | |
123 | CLIENT * | |
090ca000 UD |
124 | clntudp_bufcreate (struct sockaddr_in *raddr, u_long program, u_long version, |
125 | struct timeval wait, int *sockp, u_int sendsz, | |
126 | u_int recvsz) | |
28f540f4 | 127 | { |
e7fd8a39 UD |
128 | CLIENT *cl; |
129 | struct cu_data *cu = NULL; | |
e7fd8a39 | 130 | struct rpc_msg call_msg; |
28f540f4 | 131 | |
e7fd8a39 | 132 | cl = (CLIENT *) mem_alloc (sizeof (CLIENT)); |
e7fd8a39 UD |
133 | sendsz = ((sendsz + 3) / 4) * 4; |
134 | recvsz = ((recvsz + 3) / 4) * 4; | |
135 | cu = (struct cu_data *) mem_alloc (sizeof (*cu) + sendsz + recvsz); | |
51028f34 | 136 | if (cl == NULL || cu == NULL) |
e7fd8a39 | 137 | { |
543cf8a9 | 138 | struct rpc_createerr *ce = &get_rpc_createerr (); |
8a259a23 | 139 | (void) __fxprintf (NULL, "%s", _("clntudp_create: out of memory\n")); |
543cf8a9 | 140 | ce->cf_stat = RPC_SYSTEMERROR; |
51028f34 | 141 | ce->cf_error.re_errno = ENOMEM; |
e7fd8a39 UD |
142 | goto fooy; |
143 | } | |
144 | cu->cu_outbuf = &cu->cu_inbuf[recvsz]; | |
28f540f4 | 145 | |
e7fd8a39 UD |
146 | if (raddr->sin_port == 0) |
147 | { | |
148 | u_short port; | |
149 | if ((port = | |
150 | pmap_getport (raddr, program, version, IPPROTO_UDP)) == 0) | |
151 | { | |
152 | goto fooy; | |
28f540f4 | 153 | } |
e7fd8a39 UD |
154 | raddr->sin_port = htons (port); |
155 | } | |
31d7b14c | 156 | cl->cl_ops = (struct clnt_ops *) &udp_ops; |
e7fd8a39 UD |
157 | cl->cl_private = (caddr_t) cu; |
158 | cu->cu_raddr = *raddr; | |
159 | cu->cu_rlen = sizeof (cu->cu_raddr); | |
160 | cu->cu_wait = wait; | |
161 | cu->cu_total.tv_sec = -1; | |
162 | cu->cu_total.tv_usec = -1; | |
163 | cu->cu_sendsz = sendsz; | |
164 | cu->cu_recvsz = recvsz; | |
090ca000 | 165 | call_msg.rm_xid = _create_xid (); |
e7fd8a39 UD |
166 | call_msg.rm_direction = CALL; |
167 | call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; | |
168 | call_msg.rm_call.cb_prog = program; | |
169 | call_msg.rm_call.cb_vers = version; | |
77fe0b9c UD |
170 | INTUSE(xdrmem_create) (&(cu->cu_outxdrs), cu->cu_outbuf, sendsz, XDR_ENCODE); |
171 | if (!INTUSE(xdr_callhdr) (&(cu->cu_outxdrs), &call_msg)) | |
e7fd8a39 UD |
172 | { |
173 | goto fooy; | |
174 | } | |
175 | cu->cu_xdrpos = XDR_GETPOS (&(cu->cu_outxdrs)); | |
176 | if (*sockp < 0) | |
177 | { | |
178 | int dontblock = 1; | |
28f540f4 | 179 | |
50304ef0 | 180 | *sockp = __socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
e7fd8a39 UD |
181 | if (*sockp < 0) |
182 | { | |
543cf8a9 UD |
183 | struct rpc_createerr *ce = &get_rpc_createerr (); |
184 | ce->cf_stat = RPC_SYSTEMERROR; | |
185 | ce->cf_error.re_errno = errno; | |
e7fd8a39 | 186 | goto fooy; |
28f540f4 | 187 | } |
e7fd8a39 | 188 | /* attempt to bind to prov port */ |
a585ba22 | 189 | (void) bindresvport (*sockp, (struct sockaddr_in *) 0); |
e7fd8a39 | 190 | /* the sockets rpc controls are non-blocking */ |
50304ef0 | 191 | (void) __ioctl (*sockp, FIONBIO, (char *) &dontblock); |
b1eab230 UD |
192 | #ifdef IP_RECVERR |
193 | { | |
194 | int on = 1; | |
b2bffca2 | 195 | __setsockopt (*sockp, SOL_IP, IP_RECVERR, &on, sizeof(on)); |
b1eab230 UD |
196 | } |
197 | #endif | |
e7fd8a39 UD |
198 | cu->cu_closeit = TRUE; |
199 | } | |
200 | else | |
201 | { | |
202 | cu->cu_closeit = FALSE; | |
203 | } | |
204 | cu->cu_sock = *sockp; | |
b2bffca2 | 205 | cl->cl_auth = INTUSE(authnone_create) (); |
e7fd8a39 | 206 | return cl; |
28f540f4 | 207 | fooy: |
e7fd8a39 UD |
208 | if (cu) |
209 | mem_free ((caddr_t) cu, sizeof (*cu) + sendsz + recvsz); | |
210 | if (cl) | |
211 | mem_free ((caddr_t) cl, sizeof (CLIENT)); | |
212 | return (CLIENT *) NULL; | |
28f540f4 | 213 | } |
b2bffca2 | 214 | INTDEF (clntudp_bufcreate) |
28f540f4 RM |
215 | |
216 | CLIENT * | |
e7fd8a39 UD |
217 | clntudp_create (raddr, program, version, wait, sockp) |
218 | struct sockaddr_in *raddr; | |
219 | u_long program; | |
220 | u_long version; | |
221 | struct timeval wait; | |
222 | int *sockp; | |
28f540f4 | 223 | { |
b2bffca2 UD |
224 | return INTUSE(clntudp_bufcreate) (raddr, program, version, wait, sockp, |
225 | UDPMSGSIZE, UDPMSGSIZE); | |
28f540f4 | 226 | } |
b2bffca2 | 227 | INTDEF (clntudp_create) |
28f540f4 | 228 | |
ea48e2c4 UD |
229 | static int |
230 | is_network_up (int sock) | |
231 | { | |
412c954a | 232 | struct ifaddrs *ifa; |
ea48e2c4 | 233 | |
412c954a UD |
234 | if (getifaddrs (&ifa) != 0) |
235 | return 0; | |
236 | ||
237 | struct ifaddrs *run = ifa; | |
238 | while (run != NULL) | |
ea48e2c4 | 239 | { |
412c954a | 240 | if ((run->ifa_flags & IFF_UP) != 0 |
f7e7a396 | 241 | && run->ifa_addr != NULL |
412c954a UD |
242 | && run->ifa_addr->sa_family == AF_INET) |
243 | break; | |
ea48e2c4 | 244 | |
412c954a | 245 | run = run->ifa_next; |
ea48e2c4 | 246 | } |
412c954a UD |
247 | |
248 | freeifaddrs (ifa); | |
249 | ||
250 | return run != NULL; | |
ea48e2c4 UD |
251 | } |
252 | ||
c4029823 | 253 | static enum clnt_stat |
e7fd8a39 UD |
254 | clntudp_call (cl, proc, xargs, argsp, xresults, resultsp, utimeout) |
255 | CLIENT *cl; /* client handle */ | |
256 | u_long proc; /* procedure number */ | |
257 | xdrproc_t xargs; /* xdr routine for args */ | |
258 | caddr_t argsp; /* pointer to args */ | |
259 | xdrproc_t xresults; /* xdr routine for results */ | |
260 | caddr_t resultsp; /* pointer to results */ | |
261 | struct timeval utimeout; /* seconds to wait before giving up */ | |
28f540f4 | 262 | { |
e7fd8a39 UD |
263 | struct cu_data *cu = (struct cu_data *) cl->cl_private; |
264 | XDR *xdrs; | |
1522c368 | 265 | int outlen = 0; |
e7fd8a39 | 266 | int inlen; |
41df5ed4 | 267 | socklen_t fromlen; |
099a6fbd UD |
268 | struct pollfd fd; |
269 | int milliseconds = (cu->cu_wait.tv_sec * 1000) + | |
270 | (cu->cu_wait.tv_usec / 1000); | |
e7fd8a39 UD |
271 | struct sockaddr_in from; |
272 | struct rpc_msg reply_msg; | |
273 | XDR reply_xdrs; | |
274 | struct timeval time_waited; | |
275 | bool_t ok; | |
276 | int nrefreshes = 2; /* number of times to refresh cred */ | |
277 | struct timeval timeout; | |
ea48e2c4 | 278 | int anyup; /* any network interface up */ |
28f540f4 | 279 | |
e7fd8a39 UD |
280 | if (cu->cu_total.tv_usec == -1) |
281 | { | |
282 | timeout = utimeout; /* use supplied timeout */ | |
283 | } | |
284 | else | |
285 | { | |
286 | timeout = cu->cu_total; /* use default timeout */ | |
287 | } | |
28f540f4 | 288 | |
e7fd8a39 UD |
289 | time_waited.tv_sec = 0; |
290 | time_waited.tv_usec = 0; | |
28f540f4 | 291 | call_again: |
e7fd8a39 | 292 | xdrs = &(cu->cu_outxdrs); |
60c96635 UD |
293 | if (xargs == NULL) |
294 | goto get_reply; | |
e7fd8a39 UD |
295 | xdrs->x_op = XDR_ENCODE; |
296 | XDR_SETPOS (xdrs, cu->cu_xdrpos); | |
297 | /* | |
298 | * the transaction is the first thing in the out buffer | |
299 | */ | |
d6f6ffa1 | 300 | (*(uint32_t *) (cu->cu_outbuf))++; |
e7fd8a39 UD |
301 | if ((!XDR_PUTLONG (xdrs, (long *) &proc)) || |
302 | (!AUTH_MARSHALL (cl->cl_auth, xdrs)) || | |
303 | (!(*xargs) (xdrs, argsp))) | |
304 | return (cu->cu_error.re_status = RPC_CANTENCODEARGS); | |
305 | outlen = (int) XDR_GETPOS (xdrs); | |
28f540f4 RM |
306 | |
307 | send_again: | |
b2bffca2 UD |
308 | if (__sendto (cu->cu_sock, cu->cu_outbuf, outlen, 0, |
309 | (struct sockaddr *) &(cu->cu_raddr), cu->cu_rlen) | |
e7fd8a39 UD |
310 | != outlen) |
311 | { | |
312 | cu->cu_error.re_errno = errno; | |
313 | return (cu->cu_error.re_status = RPC_CANTSEND); | |
314 | } | |
28f540f4 | 315 | |
e7fd8a39 UD |
316 | /* |
317 | * Hack to provide rpc-based message passing | |
318 | */ | |
319 | if (timeout.tv_sec == 0 && timeout.tv_usec == 0) | |
320 | { | |
321 | return (cu->cu_error.re_status = RPC_TIMEDOUT); | |
322 | } | |
60c96635 | 323 | get_reply: |
e7fd8a39 UD |
324 | /* |
325 | * sub-optimal code appears here because we have | |
326 | * some clock time to spare while the packets are in flight. | |
327 | * (We assume that this is actually only executed once.) | |
328 | */ | |
329 | reply_msg.acpted_rply.ar_verf = _null_auth; | |
330 | reply_msg.acpted_rply.ar_results.where = resultsp; | |
331 | reply_msg.acpted_rply.ar_results.proc = xresults; | |
099a6fbd UD |
332 | fd.fd = cu->cu_sock; |
333 | fd.events = POLLIN; | |
c556351f | 334 | anyup = 0; |
e7fd8a39 UD |
335 | for (;;) |
336 | { | |
ea48e2c4 | 337 | switch (__poll (&fd, 1, milliseconds)) |
e7fd8a39 | 338 | { |
28f540f4 | 339 | |
e7fd8a39 | 340 | case 0: |
ea48e2c4 UD |
341 | if (anyup == 0) |
342 | { | |
343 | anyup = is_network_up (cu->cu_sock); | |
344 | if (!anyup) | |
345 | return (cu->cu_error.re_status = RPC_CANTRECV); | |
346 | } | |
347 | ||
e7fd8a39 UD |
348 | time_waited.tv_sec += cu->cu_wait.tv_sec; |
349 | time_waited.tv_usec += cu->cu_wait.tv_usec; | |
350 | while (time_waited.tv_usec >= 1000000) | |
351 | { | |
352 | time_waited.tv_sec++; | |
353 | time_waited.tv_usec -= 1000000; | |
354 | } | |
355 | if ((time_waited.tv_sec < timeout.tv_sec) || | |
356 | ((time_waited.tv_sec == timeout.tv_sec) && | |
357 | (time_waited.tv_usec < timeout.tv_usec))) | |
358 | goto send_again; | |
359 | return (cu->cu_error.re_status = RPC_TIMEDOUT); | |
28f540f4 | 360 | |
e7fd8a39 UD |
361 | /* |
362 | * buggy in other cases because time_waited is not being | |
363 | * updated. | |
364 | */ | |
365 | case -1: | |
366 | if (errno == EINTR) | |
367 | continue; | |
368 | cu->cu_error.re_errno = errno; | |
369 | return (cu->cu_error.re_status = RPC_CANTRECV); | |
28f540f4 | 370 | } |
b1eab230 UD |
371 | #ifdef IP_RECVERR |
372 | if (fd.revents & POLLERR) | |
373 | { | |
374 | struct msghdr msg; | |
375 | struct cmsghdr *cmsg; | |
376 | struct sock_extended_err *e; | |
377 | struct sockaddr_in err_addr; | |
378 | struct iovec iov; | |
379 | char *cbuf = (char *) alloca (outlen + 256); | |
380 | int ret; | |
381 | ||
382 | iov.iov_base = cbuf + 256; | |
383 | iov.iov_len = outlen; | |
384 | msg.msg_name = (void *) &err_addr; | |
385 | msg.msg_namelen = sizeof (err_addr); | |
386 | msg.msg_iov = &iov; | |
387 | msg.msg_iovlen = 1; | |
388 | msg.msg_flags = 0; | |
389 | msg.msg_control = cbuf; | |
390 | msg.msg_controllen = 256; | |
b2bffca2 | 391 | ret = __recvmsg (cu->cu_sock, &msg, MSG_ERRQUEUE); |
b1eab230 UD |
392 | if (ret >= 0 |
393 | && memcmp (cbuf + 256, cu->cu_outbuf, ret) == 0 | |
394 | && (msg.msg_flags & MSG_ERRQUEUE) | |
395 | && ((msg.msg_namelen == 0 | |
396 | && ret >= 12) | |
397 | || (msg.msg_namelen == sizeof (err_addr) | |
398 | && err_addr.sin_family == AF_INET | |
399 | && memcmp (&err_addr.sin_addr, &cu->cu_raddr.sin_addr, | |
400 | sizeof (err_addr.sin_addr)) == 0 | |
401 | && err_addr.sin_port == cu->cu_raddr.sin_port))) | |
402 | for (cmsg = CMSG_FIRSTHDR (&msg); cmsg; | |
403 | cmsg = CMSG_NXTHDR (&msg, cmsg)) | |
404 | if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR) | |
405 | { | |
406 | e = (struct sock_extended_err *) CMSG_DATA(cmsg); | |
407 | cu->cu_error.re_errno = e->ee_errno; | |
408 | return (cu->cu_error.re_status = RPC_CANTRECV); | |
409 | } | |
410 | } | |
411 | #endif | |
e7fd8a39 UD |
412 | do |
413 | { | |
414 | fromlen = sizeof (struct sockaddr); | |
b2bffca2 UD |
415 | inlen = __recvfrom (cu->cu_sock, cu->cu_inbuf, |
416 | (int) cu->cu_recvsz, 0, | |
417 | (struct sockaddr *) &from, &fromlen); | |
e7fd8a39 UD |
418 | } |
419 | while (inlen < 0 && errno == EINTR); | |
420 | if (inlen < 0) | |
421 | { | |
422 | if (errno == EWOULDBLOCK) | |
423 | continue; | |
424 | cu->cu_error.re_errno = errno; | |
425 | return (cu->cu_error.re_status = RPC_CANTRECV); | |
28f540f4 | 426 | } |
e7fd8a39 UD |
427 | if (inlen < 4) |
428 | continue; | |
4c66860c UD |
429 | |
430 | /* see if reply transaction id matches sent id. | |
431 | Don't do this if we only wait for a replay */ | |
432 | if (xargs != NULL | |
433 | && (*((u_int32_t *) (cu->cu_inbuf)) | |
434 | != *((u_int32_t *) (cu->cu_outbuf)))) | |
e7fd8a39 UD |
435 | continue; |
436 | /* we now assume we have the proper reply */ | |
437 | break; | |
438 | } | |
439 | ||
440 | /* | |
441 | * now decode and validate the response | |
442 | */ | |
77fe0b9c UD |
443 | INTUSE(xdrmem_create) (&reply_xdrs, cu->cu_inbuf, (u_int) inlen, XDR_DECODE); |
444 | ok = INTUSE(xdr_replymsg) (&reply_xdrs, &reply_msg); | |
e7fd8a39 UD |
445 | /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */ |
446 | if (ok) | |
447 | { | |
448 | _seterr_reply (&reply_msg, &(cu->cu_error)); | |
449 | if (cu->cu_error.re_status == RPC_SUCCESS) | |
450 | { | |
451 | if (!AUTH_VALIDATE (cl->cl_auth, | |
452 | &reply_msg.acpted_rply.ar_verf)) | |
453 | { | |
454 | cu->cu_error.re_status = RPC_AUTHERROR; | |
455 | cu->cu_error.re_why = AUTH_INVALIDRESP; | |
456 | } | |
457 | if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) | |
458 | { | |
459 | xdrs->x_op = XDR_FREE; | |
77fe0b9c UD |
460 | (void) INTUSE(xdr_opaque_auth) (xdrs, |
461 | &(reply_msg.acpted_rply.ar_verf)); | |
e7fd8a39 UD |
462 | } |
463 | } /* end successful completion */ | |
464 | else | |
465 | { | |
466 | /* maybe our credentials need to be refreshed ... */ | |
467 | if (nrefreshes > 0 && AUTH_REFRESH (cl->cl_auth)) | |
468 | { | |
469 | nrefreshes--; | |
470 | goto call_again; | |
471 | } | |
472 | } /* end of unsuccessful completion */ | |
473 | } /* end of valid reply message */ | |
474 | else | |
475 | { | |
476 | cu->cu_error.re_status = RPC_CANTDECODERES; | |
477 | } | |
478 | return cu->cu_error.re_status; | |
28f540f4 RM |
479 | } |
480 | ||
481 | static void | |
e7fd8a39 | 482 | clntudp_geterr (CLIENT *cl, struct rpc_err *errp) |
28f540f4 | 483 | { |
e7fd8a39 | 484 | struct cu_data *cu = (struct cu_data *) cl->cl_private; |
28f540f4 | 485 | |
e7fd8a39 | 486 | *errp = cu->cu_error; |
28f540f4 RM |
487 | } |
488 | ||
489 | ||
490 | static bool_t | |
e7fd8a39 | 491 | clntudp_freeres (CLIENT *cl, xdrproc_t xdr_res, caddr_t res_ptr) |
28f540f4 | 492 | { |
e7fd8a39 UD |
493 | struct cu_data *cu = (struct cu_data *) cl->cl_private; |
494 | XDR *xdrs = &(cu->cu_outxdrs); | |
28f540f4 | 495 | |
e7fd8a39 UD |
496 | xdrs->x_op = XDR_FREE; |
497 | return (*xdr_res) (xdrs, res_ptr); | |
28f540f4 RM |
498 | } |
499 | ||
c4029823 | 500 | static void |
e7fd8a39 | 501 | clntudp_abort (void) |
28f540f4 RM |
502 | { |
503 | } | |
504 | ||
505 | static bool_t | |
e7fd8a39 | 506 | clntudp_control (CLIENT *cl, int request, char *info) |
28f540f4 | 507 | { |
e7fd8a39 | 508 | struct cu_data *cu = (struct cu_data *) cl->cl_private; |
28f540f4 | 509 | |
e7fd8a39 UD |
510 | switch (request) |
511 | { | |
26a60f90 UD |
512 | case CLSET_FD_CLOSE: |
513 | cu->cu_closeit = TRUE; | |
514 | break; | |
515 | case CLSET_FD_NCLOSE: | |
516 | cu->cu_closeit = FALSE; | |
517 | break; | |
e7fd8a39 UD |
518 | case CLSET_TIMEOUT: |
519 | cu->cu_total = *(struct timeval *) info; | |
520 | break; | |
521 | case CLGET_TIMEOUT: | |
522 | *(struct timeval *) info = cu->cu_total; | |
523 | break; | |
524 | case CLSET_RETRY_TIMEOUT: | |
525 | cu->cu_wait = *(struct timeval *) info; | |
526 | break; | |
527 | case CLGET_RETRY_TIMEOUT: | |
528 | *(struct timeval *) info = cu->cu_wait; | |
529 | break; | |
530 | case CLGET_SERVER_ADDR: | |
531 | *(struct sockaddr_in *) info = cu->cu_raddr; | |
532 | break; | |
26a60f90 UD |
533 | case CLGET_FD: |
534 | *(int *)info = cu->cu_sock; | |
535 | break; | |
536 | case CLGET_XID: | |
537 | /* | |
538 | * use the knowledge that xid is the | |
539 | * first element in the call structure *. | |
540 | * This will get the xid of the PREVIOUS call | |
541 | */ | |
542 | *(u_long *)info = ntohl(*(u_long *)cu->cu_outbuf); | |
543 | break; | |
544 | case CLSET_XID: | |
545 | /* This will set the xid of the NEXT call */ | |
546 | *(u_long *)cu->cu_outbuf = htonl(*(u_long *)info - 1); | |
547 | /* decrement by 1 as clntudp_call() increments once */ | |
548 | case CLGET_VERS: | |
549 | /* | |
550 | * This RELIES on the information that, in the call body, | |
551 | * the version number field is the fifth field from the | |
552 | * begining of the RPC header. MUST be changed if the | |
553 | * call_struct is changed | |
554 | */ | |
555 | *(u_long *)info = ntohl(*(u_long *)(cu->cu_outbuf + | |
556 | 4 * BYTES_PER_XDR_UNIT)); | |
557 | break; | |
558 | case CLSET_VERS: | |
559 | *(u_long *)(cu->cu_outbuf + 4 * BYTES_PER_XDR_UNIT) | |
560 | = htonl(*(u_long *)info); | |
561 | break; | |
562 | case CLGET_PROG: | |
563 | /* | |
564 | * This RELIES on the information that, in the call body, | |
565 | * the program number field is the field from the | |
566 | * begining of the RPC header. MUST be changed if the | |
567 | * call_struct is changed | |
568 | */ | |
569 | *(u_long *)info = ntohl(*(u_long *)(cu->cu_outbuf + | |
570 | 3 * BYTES_PER_XDR_UNIT)); | |
571 | break; | |
572 | case CLSET_PROG: | |
573 | *(u_long *)(cu->cu_outbuf + 3 * BYTES_PER_XDR_UNIT) | |
574 | = htonl(*(u_long *)info); | |
575 | break; | |
576 | /* The following are only possible with TI-RPC */ | |
577 | case CLGET_SVC_ADDR: | |
578 | case CLSET_SVC_ADDR: | |
579 | case CLSET_PUSH_TIMOD: | |
580 | case CLSET_POP_TIMOD: | |
e7fd8a39 UD |
581 | default: |
582 | return FALSE; | |
583 | } | |
584 | return TRUE; | |
28f540f4 | 585 | } |
c4029823 | 586 | |
28f540f4 | 587 | static void |
e7fd8a39 | 588 | clntudp_destroy (CLIENT *cl) |
28f540f4 | 589 | { |
e7fd8a39 | 590 | struct cu_data *cu = (struct cu_data *) cl->cl_private; |
28f540f4 | 591 | |
e7fd8a39 UD |
592 | if (cu->cu_closeit) |
593 | { | |
50304ef0 | 594 | (void) __close (cu->cu_sock); |
e7fd8a39 UD |
595 | } |
596 | XDR_DESTROY (&(cu->cu_outxdrs)); | |
597 | mem_free ((caddr_t) cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz)); | |
598 | mem_free ((caddr_t) cl, sizeof (CLIENT)); | |
28f540f4 | 599 | } |