/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains routines responsible for getting the system's
* name and boot params. Most of it comes from the SVR4 diskless boot
* code (dlboot_inet), modified to work in a non socket environment.
*/
#include "clnt.h"
#include <netinet/if_ether.h>
#include <rpcsvc/bootparam.h>
#include "pmap.h"
#include "brpc.h"
#include "socket_inet.h"
#include "ipv4.h"
#include <sys/bootdebug.h>
extern int errno;
static const char *noserver =
"No bootparam (%s) server responding; still trying...\n";
/*
* Returns TRUE if it has set the global structure 'bp' to our boot
* parameters, FALSE if some failure occurred.
*/
whoami(void)
{
int namelen;
int printed_waiting_msg;
/*
* Set our destination IP address to the limited broadcast address
* (INADDR_BROADCAST).
*/
/*
* Set up the arguments expected by bootparamd.
*/
sizeof (ipaddr));
/*
* Retransmit/wait for up to resp_wait secs.
*/
rexmit = 0; /* start at default retransmission interval. */
resp_wait = 16;
/*
* Do a broadcast call to find a bootparam daemon that
* will tell us our hostname, domainname and any
* router that we have to use to talk to our NFS server.
*/
printed_waiting_msg = 0;
do {
/*
* First try the SunOS portmapper and if no reply is
* received will then try the SVR4 rpcbind.
* Either way, `bootpaddr' will be set to the
* correct address for the bootparamd that responds.
*/
printed_waiting_msg = 1;
}
/*
* Retransmission interval for second and subsequent tries.
* We expect first bpmap_rmtcall to retransmit and backoff to
* at least this value.
*/
resp_wait = 0; /* go to default wait now. */
} while (stat == RPC_TIMEDOUT);
if (stat != RPC_SUCCESS) {
goto done;
} else {
printf("Bootparam response received\n");
/* Cache responder... We'll send our getfile here... */
}
dprintf("whoami: hostname too long");
goto done;
}
if (namelen > 0) {
if (boothowto & RB_VERBOSE)
} else {
dprintf("whoami: no host name\n");
goto done;
}
dprintf("whoami: domainname too long");
goto done;
}
if (namelen > 0)
if (boothowto & RB_VERBOSE)
else
dprintf("whoami: no domain name\n");
dprintf("whoami: Router ip is: %s\n",
/* ipv4_route expects IP addresses in network order */
&ipaddr);
}
} else
dprintf("whoami: unknown gateway addr family %d\n",
done:
return (retval);
}
/*
* Returns:
* 1) The ascii form of our root servers name in `server_name'.
* 2) Pathname of our root on the server in `server_path'.
*
* NOTE: it's ok for getfile() to do dynamic allocation - it's only
* used locally, then freed. If the server address returned from the
* getfile call is different from our current destination address,
* reset destination IP address to the new value.
*/
char *server_path)
{
int rexmit;
int wait;
int def_rexmit = 0;
int printed_waiting_msg;
/*
* For non-root requests, set a smaller timeout
*/
/*
* Only send one request per call
*/
}
dprintf("getfile: rpc_call failed: No memory\n");
return (FALSE);
}
/*
* Our addressing information was filled in by the call to
* whoami(), so now send an rpc message to the
* bootparam daemon requesting our server information.
*
* Wait only 32 secs for rpc_call to succeed.
*/
rexmit = def_rexmit;
if (stat == RPC_TIMEDOUT) {
/*
* The server that answered the whoami doesn't
* answer our getfile. Broadcast the call to all. Keep
* trying forever. Set up for limited broadcast.
*/
printed_waiting_msg = 0;
do {
/*
* Limit the number of retries
*/
if (max_retries-- == 0)
break;
if (stat == RPC_SUCCESS) {
/*
* set our destination addresses to
* those of the server that responded.
* It's probably our server, and we
* can thus save arping for no reason later.
*/
if (printed_waiting_msg &&
(boothowto & RB_VERBOSE)) {
"Bootparam response received.\n");
}
break;
}
printed_waiting_msg = 1;
}
/*
* Retransmission interval for second and
* subsequent tries. We expect first bpmap_rmtcall
* to retransmit and backoff to at least this
* value.
*/
} while (stat == RPC_TIMEDOUT);
}
if (stat == RPC_SUCCESS) {
/* got the goods */
case IP_ADDR_TYPE:
/*
* server_address is where we will get our root
* from. Replace destination entries in address if
* necessary.
*/
break;
default:
dprintf("getfile: unknown address type %d\n",
return (FALSE);
}
} else {
dprintf("getfile: rpc_call failed.\n");
return (FALSE);
}
return (TRUE);
}