clnt_budp.c revision 9f1fc992b281e57216b036e784b762829b875b4b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Boot subsystem client side rpc
*/
#include "socket_inet.h"
#include "ipv4.h"
#include "clnt.h"
#include "brpc.h"
#include "pmap.h"
#include <rpc/auth_sys.h>
#include "auth_inet.h"
#include <sys/bootdebug.h>
/* retries to send RPC message when sendto fails */
#define RPC_UDP_SEND_RETRIES 3
extern int errno;
/*
* If we create another clnt type this should be
* moved to a common file
*/
struct rpc_createerr rpc_createerr;
static struct clnt_ops *clntbudp_ops();
/*
* Private data kept per client handle
*/
struct cu_data {
int cu_sock;
struct sockaddr_in cu_raddr;
int cu_rlen;
char *cu_outbuf;
char cu_inbuf[1];
};
/*
* Create a UDP based client handle.
* If *sockp<0, *sockp is set to a newly created UPD socket.
* If raddr->sin_port is 0 a binder on the remote machine
* is consulted for the correct port number.
* NB: It is the clients responsibility to close *sockp.
* NB: The rpch->cl_auth is initialized to null authentication.
* Caller may wish to set this something more useful.
*
* wait is the amount of time used between retransmitting a call if
* no response has been heard; retransmition occurs until the actual
* rpc call times out.
*
* sendsz and recvsz are the maximum allowable packet sizes that can be
* sent and received.
*/
CLIENT *
struct sockaddr_in *raddr;
int *sockp;
{
}
goto fooy;
}
goto fooy;
}
}
sendsz, XDR_ENCODE);
goto fooy;
}
if (*sockp < 0) {
struct sockaddr_in from;
if (*sockp < 0) {
goto fooy;
}
if (dontroute) {
}
/* attempt to bind to priv port */
goto fooy;
}
}
return (cl);
fooy:
if (cu)
if (cl)
}
CLIENT *
struct sockaddr_in *raddr;
int *sockp;
{
UDPMSGSIZE, UDPMSGSIZE));
}
static enum clnt_stat
{
int outlen;
int inlen;
struct sockaddr_in from;
int wait_time;
int errors;
short send_retries = RPC_UDP_SEND_RETRIES;
else
/*
* set a media level timeout
*/
if (wait_time == 0)
wait_time += prom_gettime();
errors = 0;
/*
* the transaction is the first thing in the out buffer
*/
!= outlen) {
/*
* sendto() times out probably because
* ARP times out while waiting for reply.
* We retry sending RPC message again.
*/
if (send_retries-- > 0) {
dprintf("clntbudp_call: timedout, try sending"
"RPC again\n");
errno = 0;
goto send_again;
}
} else {
}
}
/*
* sub-optimal code appears here because we have
* some clock time to spare while the packets are in flight.
* (We assume that this is actually only executed once.)
*/
for (;;) {
if (errors >= RPC_ALLOWABLE_ERRORS)
if (prom_gettime() >= wait_time) {
}
/*
* Use MSG_DONTWAIT because we have set
* a media level timeout above.
*/
if (inlen < 0) {
if (errno == EWOULDBLOCK) {
/*
* Media level has timedout
* and no more data in buffers.
*/
goto send_again;
}
}
}
continue;
/* see if reply transaction id matches sent id */
dprintf("clntbudp_call: xid: 0x%x != 0x%x\n",
continue;
}
/* we now assume we have the proper reply */
break;
}
/*
* now decode and validate the response
*/
/* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
if (!ok) {
}
errors++;
goto call_again;
}
(void) xdr_opaque_auth(xdrs,
}
} /* end successful completion */
/* maybe our credentials need to be refreshed ... */
if (nrefreshes > 0 &&
nrefreshes--;
}
errors++;
goto call_again;
}
/* Just keep trying till there's no data... */
errors++;
dprintf("clntbudp_call: from: %s, error: ",
goto recv_again;
}
static void
{
}
static bool_t
{
}
static void
/* CLIENT *h; */
{
}
/* ARGSUSED */
static bool_t
int request;
char *info;
{
/* CLNT_CONTROL is not used in boot */
return (FALSE);
}
static void
{
if (cu->cu_closeit) {
}
}
static struct clnt_ops *
{
}
return (&ops);
}