xref: /onnv-gate/usr/src/stand/lib/fs/nfs/clnt_budp.c (revision 1230:b5ac481933a3)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1230Sss146032  * Common Development and Distribution License (the "License").
6*1230Sss146032  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*1230Sss146032 
220Sstevel@tonic-gate /*
23*1230Sss146032  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
320Sstevel@tonic-gate  * under license from the Regents of the University of California.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate  * Boot subsystem client side rpc
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include <sys/errno.h>
420Sstevel@tonic-gate #include <rpc/types.h>
430Sstevel@tonic-gate #include <sys/socket.h>
440Sstevel@tonic-gate #include <netinet/in.h>
450Sstevel@tonic-gate #include "socket_inet.h"
460Sstevel@tonic-gate #include "ipv4.h"
470Sstevel@tonic-gate #include "clnt.h"
480Sstevel@tonic-gate #include <rpc/rpc.h>
490Sstevel@tonic-gate #include "brpc.h"
500Sstevel@tonic-gate #include "pmap.h"
510Sstevel@tonic-gate #include <sys/promif.h>
520Sstevel@tonic-gate #include <rpc/xdr.h>
530Sstevel@tonic-gate #include <rpc/auth.h>
540Sstevel@tonic-gate #include <rpc/auth_sys.h>
550Sstevel@tonic-gate #include "auth_inet.h"
560Sstevel@tonic-gate #include <rpc/rpc_msg.h>
570Sstevel@tonic-gate #include <sys/salib.h>
580Sstevel@tonic-gate #include <sys/bootdebug.h>
590Sstevel@tonic-gate 
600Sstevel@tonic-gate #define	dprintf if (boothowto & RB_DEBUG) printf
610Sstevel@tonic-gate 
62*1230Sss146032 /* retries to send RPC message when sendto fails */
63*1230Sss146032 #define	RPC_UDP_SEND_RETRIES	3
64*1230Sss146032 
650Sstevel@tonic-gate extern int errno;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate  * If we create another clnt type this should be
690Sstevel@tonic-gate  * moved to a common file
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate struct rpc_createerr rpc_createerr;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate static struct clnt_ops *clntbudp_ops();
740Sstevel@tonic-gate 
750Sstevel@tonic-gate /*
760Sstevel@tonic-gate  * Private data kept per client handle
770Sstevel@tonic-gate  */
780Sstevel@tonic-gate struct cu_data {
790Sstevel@tonic-gate 	int		   cu_sock;
800Sstevel@tonic-gate 	bool_t		   cu_closeit;
810Sstevel@tonic-gate 	struct sockaddr_in cu_raddr;
820Sstevel@tonic-gate 	int		   cu_rlen;
830Sstevel@tonic-gate 	struct timeval	   cu_wait;
840Sstevel@tonic-gate 	struct timeval	   cu_total;
850Sstevel@tonic-gate 	struct rpc_err	   cu_error;
860Sstevel@tonic-gate 	XDR		   cu_outxdrs;
870Sstevel@tonic-gate 	uint_t		   cu_xdrpos;
880Sstevel@tonic-gate 	uint_t		   cu_sendsz;
890Sstevel@tonic-gate 	char		   *cu_outbuf;
900Sstevel@tonic-gate 	uint_t		   cu_recvsz;
910Sstevel@tonic-gate 	char		   cu_inbuf[1];
920Sstevel@tonic-gate };
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /*
950Sstevel@tonic-gate  * Create a UDP based client handle.
960Sstevel@tonic-gate  * If *sockp<0, *sockp is set to a newly created UPD socket.
970Sstevel@tonic-gate  * If raddr->sin_port is 0 a binder on the remote machine
980Sstevel@tonic-gate  * is consulted for the correct port number.
990Sstevel@tonic-gate  * NB: It is the clients responsibility to close *sockp.
1000Sstevel@tonic-gate  * NB: The rpch->cl_auth is initialized to null authentication.
1010Sstevel@tonic-gate  *	Caller may wish to set this something more useful.
1020Sstevel@tonic-gate  *
1030Sstevel@tonic-gate  * wait is the amount of time used between retransmitting a call if
1040Sstevel@tonic-gate  * no response has been heard;  retransmition occurs until the actual
1050Sstevel@tonic-gate  * rpc call times out.
1060Sstevel@tonic-gate  *
1070Sstevel@tonic-gate  * sendsz and recvsz are the maximum allowable packet sizes that can be
1080Sstevel@tonic-gate  * sent and received.
1090Sstevel@tonic-gate  */
1100Sstevel@tonic-gate CLIENT *
clntbudp_bufcreate(raddr,program,version,wait,sockp,sendsz,recvsz)1110Sstevel@tonic-gate clntbudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
1120Sstevel@tonic-gate 	struct sockaddr_in *raddr;
1130Sstevel@tonic-gate 	rpcprog_t program;
1140Sstevel@tonic-gate 	rpcvers_t version;
1150Sstevel@tonic-gate 	struct timeval wait;
1160Sstevel@tonic-gate 	int *sockp;
1170Sstevel@tonic-gate 	uint_t sendsz;
1180Sstevel@tonic-gate 	uint_t recvsz;
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate 	CLIENT *cl;
1210Sstevel@tonic-gate 	struct cu_data *cu;
1220Sstevel@tonic-gate 	struct rpc_msg call_msg;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	cl = (CLIENT *)bkmem_alloc(sizeof (CLIENT));
1250Sstevel@tonic-gate 	if (cl == NULL) {
1260Sstevel@tonic-gate 		errno = ENOMEM;
1270Sstevel@tonic-gate 		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
1280Sstevel@tonic-gate 		rpc_createerr.cf_error.re_errno = errno;
1290Sstevel@tonic-gate 		return ((CLIENT *)NULL);
1300Sstevel@tonic-gate 	}
1310Sstevel@tonic-gate 	sendsz = ((sendsz + 3) / 4) * 4;
1320Sstevel@tonic-gate 	recvsz = ((recvsz + 3) / 4) * 4;
1330Sstevel@tonic-gate 	cu = (struct cu_data *)bkmem_alloc(sizeof (*cu) + sendsz + recvsz);
1340Sstevel@tonic-gate 	if (cu == NULL) {
1350Sstevel@tonic-gate 		errno = ENOMEM;
1360Sstevel@tonic-gate 		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
1370Sstevel@tonic-gate 		rpc_createerr.cf_error.re_errno = errno;
1380Sstevel@tonic-gate 		goto fooy;
1390Sstevel@tonic-gate 	}
1400Sstevel@tonic-gate 	cu->cu_outbuf = &cu->cu_inbuf[recvsz];
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	if (raddr->sin_port == 0) {
1430Sstevel@tonic-gate 		ushort_t port;
1440Sstevel@tonic-gate 		if ((port = bpmap_getport(program, version,
1450Sstevel@tonic-gate 				&(rpc_createerr.cf_stat), raddr, NULL)) == 0) {
1460Sstevel@tonic-gate 			goto fooy;
1470Sstevel@tonic-gate 		}
1480Sstevel@tonic-gate 		raddr->sin_port = htons(port);
1490Sstevel@tonic-gate 	}
1500Sstevel@tonic-gate 	cl->cl_ops = clntbudp_ops();
1510Sstevel@tonic-gate 	cl->cl_private = (caddr_t)cu;
1520Sstevel@tonic-gate 	cu->cu_raddr = *raddr;
1530Sstevel@tonic-gate 	cu->cu_rlen = sizeof (cu->cu_raddr);
1540Sstevel@tonic-gate 	cu->cu_wait = wait;
1550Sstevel@tonic-gate 	cu->cu_total.tv_sec = -1;
1560Sstevel@tonic-gate 	cu->cu_total.tv_usec = -1;
1570Sstevel@tonic-gate 	cu->cu_sendsz = sendsz;
1580Sstevel@tonic-gate 	cu->cu_recvsz = recvsz;
1590Sstevel@tonic-gate 	call_msg.rm_xid = (uint_t)prom_gettime() + 1;
1600Sstevel@tonic-gate 	call_msg.rm_direction = CALL;
1610Sstevel@tonic-gate 	call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
1620Sstevel@tonic-gate 	call_msg.rm_call.cb_prog = program;
1630Sstevel@tonic-gate 	call_msg.rm_call.cb_vers = version;
1640Sstevel@tonic-gate 	xdrmem_create(&(cu->cu_outxdrs), cu->cu_outbuf,
1650Sstevel@tonic-gate 	    sendsz, XDR_ENCODE);
1660Sstevel@tonic-gate 	if (! xdr_callhdr(&(cu->cu_outxdrs), &call_msg)) {
1670Sstevel@tonic-gate 		goto fooy;
1680Sstevel@tonic-gate 	}
1690Sstevel@tonic-gate 	cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
1700Sstevel@tonic-gate 	cu->cu_closeit = FALSE;
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	if (*sockp < 0) {
1730Sstevel@tonic-gate 		struct sockaddr_in from;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 		*sockp = socket(PF_INET, SOCK_DGRAM, 0);
1760Sstevel@tonic-gate 		if (*sockp < 0) {
1770Sstevel@tonic-gate 			rpc_createerr.cf_stat = RPC_SYSTEMERROR;
1780Sstevel@tonic-gate 			rpc_createerr.cf_error.re_errno = errno;
1790Sstevel@tonic-gate 			goto fooy;
1800Sstevel@tonic-gate 		}
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 		if (dontroute) {
1830Sstevel@tonic-gate 			(void) setsockopt(*sockp, SOL_SOCKET, SO_DONTROUTE,
1840Sstevel@tonic-gate 				(const void *)&dontroute, sizeof (dontroute));
1850Sstevel@tonic-gate 		}
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 		/* attempt to bind to priv port */
1880Sstevel@tonic-gate 		from.sin_family = AF_INET;
1890Sstevel@tonic-gate 		ipv4_getipaddr(&from.sin_addr);
1900Sstevel@tonic-gate 		from.sin_addr.s_addr = htonl(from.sin_addr.s_addr);
1910Sstevel@tonic-gate 		from.sin_port = get_source_port(TRUE);
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 		if (bind(*sockp, (struct sockaddr *)&from, sizeof (from)) < 0) {
1940Sstevel@tonic-gate 			rpc_createerr.cf_stat = RPC_SYSTEMERROR;
1950Sstevel@tonic-gate 			rpc_createerr.cf_error.re_errno = errno;
1960Sstevel@tonic-gate 			goto fooy;
1970Sstevel@tonic-gate 		}
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 		cu->cu_closeit = TRUE;
2000Sstevel@tonic-gate 	}
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 	cu->cu_sock = *sockp;
2030Sstevel@tonic-gate 	cl->cl_auth = authnone_create();
2040Sstevel@tonic-gate 	return (cl);
2050Sstevel@tonic-gate fooy:
2060Sstevel@tonic-gate 	if (cu)
2070Sstevel@tonic-gate 		bkmem_free((caddr_t)cu, sizeof (*cu) + sendsz + recvsz);
2080Sstevel@tonic-gate 	if (cl)
2090Sstevel@tonic-gate 		bkmem_free((caddr_t)cl, sizeof (CLIENT));
2100Sstevel@tonic-gate 	return ((CLIENT *)NULL);
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate CLIENT *
clntbudp_create(raddr,program,version,wait,sockp)2140Sstevel@tonic-gate clntbudp_create(raddr, program, version, wait, sockp)
2150Sstevel@tonic-gate 	struct sockaddr_in *raddr;
2160Sstevel@tonic-gate 	rpcprog_t program;
2170Sstevel@tonic-gate 	rpcvers_t version;
2180Sstevel@tonic-gate 	struct timeval wait;
2190Sstevel@tonic-gate 	int *sockp;
2200Sstevel@tonic-gate {
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	return (clntbudp_bufcreate(raddr, program, version, wait, sockp,
2230Sstevel@tonic-gate 	    UDPMSGSIZE, UDPMSGSIZE));
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate static enum clnt_stat
clntbudp_call(cl,proc,xargs,argsp,xresults,resultsp,utimeout)2270Sstevel@tonic-gate clntbudp_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
2280Sstevel@tonic-gate 	CLIENT		*cl;		/* client handle */
2290Sstevel@tonic-gate 	rpcproc_t	proc;		/* procedure number */
2300Sstevel@tonic-gate 	xdrproc_t	xargs;		/* xdr routine for args */
2310Sstevel@tonic-gate 	caddr_t		argsp;		/* pointer to args */
2320Sstevel@tonic-gate 	xdrproc_t	xresults;	/* xdr routine for results */
2330Sstevel@tonic-gate 	caddr_t		resultsp;	/* pointer to results */
2340Sstevel@tonic-gate 	struct timeval	utimeout;	/* seconds to wait before giving up */
2350Sstevel@tonic-gate {
2360Sstevel@tonic-gate 	struct cu_data *cu;
2370Sstevel@tonic-gate 	XDR *xdrs;
2380Sstevel@tonic-gate 	int outlen;
2390Sstevel@tonic-gate 	int inlen;
2400Sstevel@tonic-gate 	socklen_t fromlen;
2410Sstevel@tonic-gate 	struct sockaddr_in from;
2420Sstevel@tonic-gate 	struct rpc_msg reply_msg;
2430Sstevel@tonic-gate 	XDR reply_xdrs;
2440Sstevel@tonic-gate 	uint_t xdelay;
2450Sstevel@tonic-gate 	int wait_time;
2460Sstevel@tonic-gate 	bool_t ok;
2470Sstevel@tonic-gate 	int nrefreshes = 2;	/* number of times to refresh cred */
2480Sstevel@tonic-gate 	struct timeval timeout;
2490Sstevel@tonic-gate 	int errors;
250*1230Sss146032 	short send_retries = RPC_UDP_SEND_RETRIES;
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 	cu = (struct cu_data *)cl->cl_private;
2530Sstevel@tonic-gate 	if (cu->cu_total.tv_usec == -1)
2540Sstevel@tonic-gate 		timeout = utimeout;	/* use supplied timeout */
2550Sstevel@tonic-gate 	else
2560Sstevel@tonic-gate 		timeout = cu->cu_total; /* use default timeout */
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 	/*
2590Sstevel@tonic-gate 	 * set a media level timeout
2600Sstevel@tonic-gate 	 */
2610Sstevel@tonic-gate 	xdelay = cu->cu_wait.tv_sec + 1000 + cu->cu_wait.tv_usec / 1000;
2620Sstevel@tonic-gate 	(void) setsockopt(cu->cu_sock, SOL_SOCKET, SO_RCVTIMEO,
2630Sstevel@tonic-gate 				(void *)&xdelay, sizeof (xdelay));
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 	wait_time = (timeout.tv_sec * 1000) + (timeout.tv_usec / 1000);
2660Sstevel@tonic-gate 	if (wait_time == 0)
2670Sstevel@tonic-gate 		wait_time = RPC_RCVWAIT_MSEC;
2680Sstevel@tonic-gate 	wait_time += prom_gettime();
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	errors = 0;
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate call_again:
2730Sstevel@tonic-gate 	xdrs = &(cu->cu_outxdrs);
2740Sstevel@tonic-gate 	xdrs->x_op = XDR_ENCODE;
2750Sstevel@tonic-gate 	XDR_SETPOS(xdrs, cu->cu_xdrpos);
2760Sstevel@tonic-gate 	/*
2770Sstevel@tonic-gate 	 * the transaction is the first thing in the out buffer
2780Sstevel@tonic-gate 	 */
2790Sstevel@tonic-gate 	(*(ushort_t *)(cu->cu_outbuf))++;
2800Sstevel@tonic-gate 	if ((! XDR_PUTINT32(xdrs, (int32_t *)&proc)) ||
2810Sstevel@tonic-gate 	    (! AUTH_MARSHALL(cl->cl_auth, xdrs, NULL)) ||
2820Sstevel@tonic-gate 	    (! (*xargs)(xdrs, argsp)))
2830Sstevel@tonic-gate 		return (cu->cu_error.re_status = RPC_CANTENCODEARGS);
2840Sstevel@tonic-gate 	outlen = (int)XDR_GETPOS(xdrs);
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate send_again:
2870Sstevel@tonic-gate 	if (sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0,
2880Sstevel@tonic-gate 	    (struct sockaddr *)&(cu->cu_raddr), cu->cu_rlen)
2890Sstevel@tonic-gate 	    != outlen) {
290*1230Sss146032 		if (errno == ETIMEDOUT) {
291*1230Sss146032 			/*
292*1230Sss146032 			 * sendto() times out probably because
293*1230Sss146032 			 * ARP times out while waiting for reply.
294*1230Sss146032 			 * We retry sending RPC message again.
295*1230Sss146032 			 */
296*1230Sss146032 			if (send_retries-- > 0) {
297*1230Sss146032 				dprintf("clntbudp_call: timedout, try sending"
298*1230Sss146032 				    "RPC again\n");
299*1230Sss146032 				errno = 0;
300*1230Sss146032 				goto send_again;
301*1230Sss146032 			}
302*1230Sss146032 			cu->cu_error.re_status = RPC_TIMEDOUT;
303*1230Sss146032 		} else {
304*1230Sss146032 			cu->cu_error.re_status = RPC_CANTSEND;
305*1230Sss146032 		}
3060Sstevel@tonic-gate 		cu->cu_error.re_errno = errno;
307*1230Sss146032 		return (cu->cu_error.re_status);
3080Sstevel@tonic-gate 	}
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	/*
3110Sstevel@tonic-gate 	 * sub-optimal code appears here because we have
3120Sstevel@tonic-gate 	 * some clock time to spare while the packets are in flight.
3130Sstevel@tonic-gate 	 * (We assume that this is actually only executed once.)
3140Sstevel@tonic-gate 	 */
3150Sstevel@tonic-gate recv_again:
3160Sstevel@tonic-gate 	reply_msg.acpted_rply.ar_verf = _null_auth;
3170Sstevel@tonic-gate 	reply_msg.acpted_rply.ar_results.where = resultsp;
3180Sstevel@tonic-gate 	reply_msg.acpted_rply.ar_results.proc = xresults;
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 	for (;;) {
3210Sstevel@tonic-gate 		if (errors >= RPC_ALLOWABLE_ERRORS)
3220Sstevel@tonic-gate 			return (cu->cu_error.re_status);
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 		if (prom_gettime() >= wait_time) {
3250Sstevel@tonic-gate 			cu->cu_error.re_errno = ETIMEDOUT;
3260Sstevel@tonic-gate 			return (cu->cu_error.re_status = RPC_TIMEDOUT);
3270Sstevel@tonic-gate 		}
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 		/*
3300Sstevel@tonic-gate 		 * Use MSG_DONTWAIT because we have set
3310Sstevel@tonic-gate 		 * a media level timeout above.
3320Sstevel@tonic-gate 		 */
3330Sstevel@tonic-gate 		fromlen = sizeof (struct sockaddr);
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 		inlen = recvfrom(cu->cu_sock, cu->cu_inbuf,
3360Sstevel@tonic-gate 				(int)cu->cu_recvsz, MSG_DONTWAIT,
3370Sstevel@tonic-gate 				(struct sockaddr *)&from, &fromlen);
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 		if (inlen < 0) {
3400Sstevel@tonic-gate 			if (errno == EWOULDBLOCK) {
3410Sstevel@tonic-gate 				/*
3420Sstevel@tonic-gate 				 * Media level has timedout
3430Sstevel@tonic-gate 				 * and no more data in buffers.
3440Sstevel@tonic-gate 				 */
3450Sstevel@tonic-gate 				goto send_again;
3460Sstevel@tonic-gate 			}
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate 			cu->cu_error.re_status = RPC_CANTRECV;
3490Sstevel@tonic-gate 			if (errno == ETIMEDOUT) {
3500Sstevel@tonic-gate 				errno = ETIMEDOUT;
3510Sstevel@tonic-gate 				cu->cu_error.re_status = RPC_TIMEDOUT;
3520Sstevel@tonic-gate 			}
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate 			cu->cu_error.re_errno = errno;
3550Sstevel@tonic-gate 			return (cu->cu_error.re_status);
3560Sstevel@tonic-gate 		}
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 		if (inlen < sizeof (uint32_t))
3590Sstevel@tonic-gate 			continue;
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate 		/* see if reply transaction id matches sent id */
3620Sstevel@tonic-gate 		if (*((uint32_t *)(cu->cu_inbuf)) !=
3630Sstevel@tonic-gate 				*((uint32_t *)(cu->cu_outbuf))) {
3640Sstevel@tonic-gate 			dprintf("clntbudp_call: xid: 0x%x != 0x%x\n",
3650Sstevel@tonic-gate 				*(uint32_t *)(cu->cu_inbuf),
3660Sstevel@tonic-gate 				*(uint32_t *)(cu->cu_outbuf));
3670Sstevel@tonic-gate 			continue;
3680Sstevel@tonic-gate 		}
3690Sstevel@tonic-gate 		/* we now assume we have the proper reply */
3700Sstevel@tonic-gate 		break;
3710Sstevel@tonic-gate 	}
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 	/*
3740Sstevel@tonic-gate 	 * now decode and validate the response
3750Sstevel@tonic-gate 	 */
3760Sstevel@tonic-gate 	xdrmem_create(&reply_xdrs, cu->cu_inbuf, (uint_t)inlen, XDR_DECODE);
3770Sstevel@tonic-gate 	ok = xdr_replymsg(&reply_xdrs, &reply_msg);
3780Sstevel@tonic-gate 	/* XDR_DESTROY(&reply_xdrs);  save a few cycles on noop destroy */
3790Sstevel@tonic-gate 	if (!ok) {
3800Sstevel@tonic-gate 		cu->cu_error.re_status = RPC_CANTDECODERES;
3810Sstevel@tonic-gate 		return (cu->cu_error.re_status);
3820Sstevel@tonic-gate 	}
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate 	_seterr_reply(&reply_msg, &(cu->cu_error));
3850Sstevel@tonic-gate 	if (cu->cu_error.re_status == RPC_SUCCESS) {
3860Sstevel@tonic-gate 		if (! AUTH_VALIDATE(cl->cl_auth,
3870Sstevel@tonic-gate 			&reply_msg.acpted_rply.ar_verf)) {
3880Sstevel@tonic-gate 			cu->cu_error.re_status = RPC_AUTHERROR;
3890Sstevel@tonic-gate 			cu->cu_error.re_why = AUTH_INVALIDRESP;
3900Sstevel@tonic-gate 			errors++;
3910Sstevel@tonic-gate 			goto call_again;
3920Sstevel@tonic-gate 		}
3930Sstevel@tonic-gate 		if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
3940Sstevel@tonic-gate 			xdrs->x_op = XDR_FREE;
3950Sstevel@tonic-gate 			(void) xdr_opaque_auth(xdrs,
3960Sstevel@tonic-gate 			    &(reply_msg.acpted_rply.ar_verf));
3970Sstevel@tonic-gate 		}
3980Sstevel@tonic-gate 		return (cu->cu_error.re_status);
3990Sstevel@tonic-gate 	}  /* end successful completion */
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate 	if (cu->cu_error.re_status == RPC_AUTHERROR) {
4020Sstevel@tonic-gate 		/* maybe our credentials need to be refreshed ... */
4030Sstevel@tonic-gate 		if (nrefreshes > 0 &&
4040Sstevel@tonic-gate 			AUTH_REFRESH(cl->cl_auth, NULL, NULL)) {
4050Sstevel@tonic-gate 			nrefreshes--;
4060Sstevel@tonic-gate 		}
4070Sstevel@tonic-gate 		errors++;
4080Sstevel@tonic-gate 		goto call_again;
4090Sstevel@tonic-gate 	}
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate 	/* Just keep trying till there's no data... */
4120Sstevel@tonic-gate 	errors++;
4130Sstevel@tonic-gate 	dprintf("clntbudp_call: from: %s, error: ",
4140Sstevel@tonic-gate 		inet_ntoa(from.sin_addr));
4150Sstevel@tonic-gate 	rpc_disperr(&cu->cu_error);
4160Sstevel@tonic-gate 	goto recv_again;
4170Sstevel@tonic-gate }
4180Sstevel@tonic-gate 
4190Sstevel@tonic-gate static void
clntbudp_geterr(cl,errp)4200Sstevel@tonic-gate clntbudp_geterr(cl, errp)
4210Sstevel@tonic-gate 	CLIENT *cl;
4220Sstevel@tonic-gate 	struct rpc_err *errp;
4230Sstevel@tonic-gate {
4240Sstevel@tonic-gate 	struct cu_data *cu = (struct cu_data *)cl->cl_private;
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate 	*errp = cu->cu_error;
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate 
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate static bool_t
clntbudp_freeres(cl,xdr_res,res_ptr)4310Sstevel@tonic-gate clntbudp_freeres(cl, xdr_res, res_ptr)
4320Sstevel@tonic-gate 	CLIENT *cl;
4330Sstevel@tonic-gate 	xdrproc_t xdr_res;
4340Sstevel@tonic-gate 	caddr_t res_ptr;
4350Sstevel@tonic-gate {
4360Sstevel@tonic-gate 	struct cu_data *cu = (struct cu_data *)cl->cl_private;
4370Sstevel@tonic-gate 	XDR *xdrs = &(cu->cu_outxdrs);
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 	xdrs->x_op = XDR_FREE;
4400Sstevel@tonic-gate 	return ((*xdr_res)(xdrs, res_ptr));
4410Sstevel@tonic-gate }
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate static void
clntbudp_abort()4440Sstevel@tonic-gate clntbudp_abort()
4450Sstevel@tonic-gate 	/* CLIENT *h; */
4460Sstevel@tonic-gate {
4470Sstevel@tonic-gate }
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate /* ARGSUSED */
4500Sstevel@tonic-gate static bool_t
clntbudp_control(cl,request,info)4510Sstevel@tonic-gate clntbudp_control(cl, request, info)
4520Sstevel@tonic-gate 	CLIENT *cl;
4530Sstevel@tonic-gate 	int request;
4540Sstevel@tonic-gate 	char *info;
4550Sstevel@tonic-gate {
4560Sstevel@tonic-gate 	/* CLNT_CONTROL is not used in boot */
4570Sstevel@tonic-gate 	return (FALSE);
4580Sstevel@tonic-gate }
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate static void
clntbudp_destroy(cl)4610Sstevel@tonic-gate clntbudp_destroy(cl)
4620Sstevel@tonic-gate 	CLIENT *cl;
4630Sstevel@tonic-gate {
4640Sstevel@tonic-gate 	struct cu_data *cu = (struct cu_data *)cl->cl_private;
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	if (cu->cu_closeit) {
4670Sstevel@tonic-gate 		(void) socket_close(cu->cu_sock);
4680Sstevel@tonic-gate 	}
4690Sstevel@tonic-gate 	XDR_DESTROY(&(cu->cu_outxdrs));
4700Sstevel@tonic-gate 	bkmem_free((caddr_t)cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
4710Sstevel@tonic-gate 	bkmem_free((caddr_t)cl, sizeof (CLIENT));
4720Sstevel@tonic-gate }
4730Sstevel@tonic-gate 
4740Sstevel@tonic-gate static struct clnt_ops *
clntbudp_ops()4750Sstevel@tonic-gate clntbudp_ops()
4760Sstevel@tonic-gate {
4770Sstevel@tonic-gate 	static struct clnt_ops ops;
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate 	if (ops.cl_call == NULL) {
4800Sstevel@tonic-gate 		ops.cl_call = clntbudp_call;
4810Sstevel@tonic-gate 		ops.cl_abort = clntbudp_abort;
4820Sstevel@tonic-gate 		ops.cl_geterr = clntbudp_geterr;
4830Sstevel@tonic-gate 		ops.cl_freeres = clntbudp_freeres;
4840Sstevel@tonic-gate 		ops.cl_destroy = clntbudp_destroy;
4850Sstevel@tonic-gate 		ops.cl_control = clntbudp_control;
4860Sstevel@tonic-gate 	}
4870Sstevel@tonic-gate 	return (&ops);
4880Sstevel@tonic-gate }
489