1995-04-25 01:54:56 +04:00
|
|
|
/* $NetBSD: nfs_boot.c,v 1.16 1995/04/24 21:55:08 gwr Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1994-04-18 10:18:05 +04:00
|
|
|
/*
|
1995-04-25 01:54:56 +04:00
|
|
|
* Copyright (c) 1995 Adam Glass, Gordon Ross
|
1994-04-18 10:18:05 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1994-06-13 19:28:55 +04:00
|
|
|
* 3. The name of the authors may not be used to endorse or promote products
|
1994-04-18 10:18:05 +04:00
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
1994-06-13 19:28:55 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1994-04-18 10:18:05 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1994-05-05 09:35:42 +04:00
|
|
|
#include <sys/systm.h>
|
1994-04-18 10:18:05 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/reboot.h>
|
1995-04-25 01:54:56 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1994-04-18 10:18:05 +04:00
|
|
|
|
|
|
|
#include <net/if.h>
|
1994-06-13 19:28:55 +04:00
|
|
|
#include <net/route.h>
|
|
|
|
|
1994-04-18 10:18:05 +04:00
|
|
|
#include <netinet/in.h>
|
1994-06-13 19:28:55 +04:00
|
|
|
#include <netinet/if_ether.h>
|
1994-04-18 10:18:05 +04:00
|
|
|
|
|
|
|
#include <nfs/rpcv2.h>
|
|
|
|
#include <nfs/nfsv2.h>
|
|
|
|
#include <nfs/nfs.h>
|
|
|
|
#include <nfs/nfsdiskless.h>
|
1994-09-26 19:42:29 +03:00
|
|
|
#include <nfs/krpc.h>
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-07-16 15:43:12 +04:00
|
|
|
#include "ether.h"
|
1994-09-26 19:42:29 +03:00
|
|
|
#if NETHER == 0
|
|
|
|
|
|
|
|
int nfs_boot_init(nd, procp)
|
|
|
|
struct nfs_diskless *nd;
|
|
|
|
struct proc *procp;
|
|
|
|
{
|
|
|
|
panic("nfs_boot_init: no ether");
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* NETHER */
|
1994-07-16 15:43:12 +04:00
|
|
|
|
1994-04-18 10:18:05 +04:00
|
|
|
/*
|
|
|
|
* Support for NFS diskless booting, specifically getting information
|
|
|
|
* about where to boot from, what pathnames, etc.
|
|
|
|
*
|
1994-06-13 19:28:55 +04:00
|
|
|
* This implememtation uses RARP and the bootparam RPC.
|
|
|
|
* We are forced to implement RPC anyway (to get file handles)
|
|
|
|
* so we might as well take advantage of it for bootparam too.
|
1994-04-18 10:18:05 +04:00
|
|
|
*
|
1994-06-13 19:28:55 +04:00
|
|
|
* The diskless boot sequence goes as follows:
|
1995-03-29 01:29:32 +04:00
|
|
|
* (1) Use RARP to get our interface address
|
|
|
|
* (2) Use RPC/bootparam/whoami to get our hostname,
|
|
|
|
* our IP address, and the server's IP address.
|
|
|
|
* (3) Use RPC/bootparam/getfile to get the root path
|
|
|
|
* (4) Use RPC/mountd to get the root file handle
|
|
|
|
* (5) Use RPC/bootparam/getfile to get the swap path
|
|
|
|
* (6) Use RPC/mountd to get the swap file handle
|
1994-04-18 10:18:05 +04:00
|
|
|
*
|
1994-06-13 19:28:55 +04:00
|
|
|
* (This happens to be the way Sun does it too.)
|
1994-04-18 10:18:05 +04:00
|
|
|
*/
|
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/* bootparam RPC */
|
1994-06-29 11:28:36 +04:00
|
|
|
static int bp_whoami __P((struct sockaddr_in *bpsin,
|
|
|
|
struct in_addr *my_ip, struct in_addr *gw_ip));
|
|
|
|
static int bp_getfile __P((struct sockaddr_in *bpsin, char *key,
|
|
|
|
struct sockaddr_in *mdsin, char *servname, char *path));
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
/* mountd RPC */
|
1994-06-29 11:28:36 +04:00
|
|
|
static int md_mount __P((struct sockaddr_in *mdsin, char *path,
|
|
|
|
u_char *fh));
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
/* other helpers */
|
1994-06-29 11:28:36 +04:00
|
|
|
static void get_path_and_handle __P((struct sockaddr_in *bpsin,
|
|
|
|
char *key, struct nfs_dlmount *ndmntp));
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1995-02-17 00:42:50 +03:00
|
|
|
char *nfsbootdevname;
|
|
|
|
|
1994-04-18 10:18:05 +04:00
|
|
|
/*
|
1994-06-13 19:28:55 +04:00
|
|
|
* Called with an empty nfs_diskless struct to be filled in.
|
1994-04-18 10:18:05 +04:00
|
|
|
*/
|
1994-06-29 11:28:36 +04:00
|
|
|
int
|
|
|
|
nfs_boot_init(nd, procp)
|
1994-06-13 19:28:55 +04:00
|
|
|
struct nfs_diskless *nd;
|
|
|
|
struct proc *procp;
|
1994-04-18 10:18:05 +04:00
|
|
|
{
|
1994-06-13 19:28:55 +04:00
|
|
|
struct ifreq ireq;
|
1994-09-26 19:42:29 +03:00
|
|
|
struct in_addr my_ip, gw_ip;
|
1994-06-13 19:28:55 +04:00
|
|
|
struct sockaddr_in bp_sin;
|
1994-04-18 10:18:05 +04:00
|
|
|
struct sockaddr_in *sin;
|
1994-06-13 19:28:55 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct socket *so;
|
1995-04-25 01:54:56 +04:00
|
|
|
int error;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/*
|
|
|
|
* Find an interface, rarp for its ip address, stuff it, the
|
|
|
|
* implied broadcast addr, and netmask into a nfs_diskless struct.
|
|
|
|
*
|
|
|
|
* This was moved here from nfs_vfsops.c because this procedure
|
|
|
|
* would be quite different if someone decides to write (i.e.) a
|
1995-03-29 01:29:32 +04:00
|
|
|
* BOOTP version of this file (might not use RARP, etc.)
|
1994-06-13 19:28:55 +04:00
|
|
|
*/
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/*
|
|
|
|
* Find a network interface.
|
|
|
|
*/
|
1995-02-17 00:42:50 +03:00
|
|
|
if (nfsbootdevname)
|
|
|
|
ifp = ifunit(nfsbootdevname);
|
|
|
|
else
|
|
|
|
for (ifp = ifnet; ifp; ifp = ifp->if_next)
|
|
|
|
if ((ifp->if_flags &
|
|
|
|
(IFF_LOOPBACK|IFF_POINTOPOINT)) == 0)
|
|
|
|
break;
|
1994-06-13 19:28:55 +04:00
|
|
|
if (ifp == NULL)
|
|
|
|
panic("nfs_boot: no suitable interface");
|
|
|
|
sprintf(ireq.ifr_name, "%s%d", ifp->if_name, ifp->if_unit);
|
|
|
|
printf("nfs_boot: using network interface '%s'\n",
|
1994-06-29 11:28:36 +04:00
|
|
|
ireq.ifr_name);
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/*
|
|
|
|
* Bring up the interface.
|
|
|
|
*/
|
|
|
|
if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0)) != 0)
|
|
|
|
panic("nfs_boot: socreate, error=%d", error);
|
|
|
|
ireq.ifr_flags = IFF_UP;
|
|
|
|
error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)&ireq, procp);
|
1994-06-29 11:28:36 +04:00
|
|
|
if (error)
|
|
|
|
panic("nfs_boot: SIFFLAGS, error=%d", error);
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/*
|
1995-03-29 01:29:32 +04:00
|
|
|
* Do RARP for the interface address.
|
1994-06-13 19:28:55 +04:00
|
|
|
*/
|
1994-09-26 19:42:29 +03:00
|
|
|
if ((error = revarpwhoami(&my_ip, ifp)) != 0)
|
1994-06-13 19:28:55 +04:00
|
|
|
panic("revarp failed, error=%d", error);
|
1994-09-26 19:42:29 +03:00
|
|
|
printf("nfs_boot: client_addr=0x%x\n", ntohl(my_ip.s_addr));
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
/*
|
1995-03-29 01:29:32 +04:00
|
|
|
* Do enough of ifconfig(8) so that the chosen interface
|
|
|
|
* can talk to the servers. (just set the address)
|
1994-06-13 19:28:55 +04:00
|
|
|
*/
|
|
|
|
sin = (struct sockaddr_in *)&ireq.ifr_addr;
|
1994-08-12 03:47:51 +04:00
|
|
|
bzero((caddr_t)sin, sizeof(*sin));
|
1994-06-13 19:28:55 +04:00
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_addr.s_addr = my_ip.s_addr;
|
|
|
|
error = ifioctl(so, SIOCSIFADDR, (caddr_t)&ireq, procp);
|
1994-06-29 11:28:36 +04:00
|
|
|
if (error)
|
|
|
|
panic("nfs_boot: set if addr, error=%d", error);
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
soclose(so);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get client name and gateway address.
|
|
|
|
* RPC: bootparam/whoami
|
1995-03-29 01:29:32 +04:00
|
|
|
* Use the old broadcast address for the WHOAMI
|
|
|
|
* call because we do not yet know our netmask.
|
|
|
|
* The server address returned by the WHOAMI call
|
|
|
|
* is used for all subsequent booptaram RPCs.
|
1994-06-13 19:28:55 +04:00
|
|
|
*/
|
1994-08-12 03:47:51 +04:00
|
|
|
bzero((caddr_t)&bp_sin, sizeof(bp_sin));
|
1994-06-13 19:28:55 +04:00
|
|
|
bp_sin.sin_len = sizeof(bp_sin);
|
|
|
|
bp_sin.sin_family = AF_INET;
|
1995-03-29 01:29:32 +04:00
|
|
|
bp_sin.sin_addr.s_addr = INADDR_BROADCAST;
|
1994-06-13 19:28:55 +04:00
|
|
|
hostnamelen = MAXHOSTNAMELEN;
|
1994-06-29 11:28:36 +04:00
|
|
|
|
|
|
|
/* this returns gateway IP address */
|
|
|
|
error = bp_whoami(&bp_sin, &my_ip, &gw_ip);
|
1994-06-13 19:28:55 +04:00
|
|
|
if (error)
|
|
|
|
panic("nfs_boot: bootparam whoami, error=%d", error);
|
1994-09-26 19:42:29 +03:00
|
|
|
printf("nfs_boot: server_addr=0x%x\n",
|
|
|
|
ntohl(bp_sin.sin_addr.s_addr));
|
1994-06-13 19:28:55 +04:00
|
|
|
printf("nfs_boot: hostname=%s\n", hostname);
|
|
|
|
|
|
|
|
#ifdef NFS_BOOT_GATEWAY
|
|
|
|
/*
|
1994-07-19 06:23:27 +04:00
|
|
|
* XXX - This code is conditionally compiled only because
|
|
|
|
* many bootparam servers (in particular, SunOS 4.1.3)
|
|
|
|
* always set the gateway address to their own address.
|
|
|
|
* The bootparam server is not necessarily the gateway.
|
|
|
|
* We could just believe the server, and at worst you would
|
|
|
|
* need to delete the incorrect default route before adding
|
|
|
|
* the correct one, but for simplicity, ignore the gateway.
|
1994-06-13 19:28:55 +04:00
|
|
|
* If your server is OK, you can turn on this option.
|
|
|
|
*
|
|
|
|
* If the gateway address is set, add a default route.
|
|
|
|
* (The mountd RPCs may go across a gateway.)
|
|
|
|
*/
|
|
|
|
if (gw_ip.s_addr) {
|
1994-07-19 06:23:27 +04:00
|
|
|
struct sockaddr dst, gw, mask;
|
1994-06-13 19:28:55 +04:00
|
|
|
/* Destination: (default) */
|
1994-08-12 03:47:51 +04:00
|
|
|
bzero((caddr_t)&dst, sizeof(dst));
|
1994-07-19 06:23:27 +04:00
|
|
|
dst.sa_len = sizeof(dst);
|
|
|
|
dst.sa_family = AF_INET;
|
1994-06-13 19:28:55 +04:00
|
|
|
/* Gateway: */
|
1994-08-12 03:47:51 +04:00
|
|
|
bzero((caddr_t)&gw, sizeof(gw));
|
1994-07-19 06:23:27 +04:00
|
|
|
sin = (struct sockaddr_in *)&gw;
|
|
|
|
sin->sin_len = sizeof(gw);
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_addr.s_addr = gw_ip.s_addr;
|
|
|
|
/* Mask: (zero length) */
|
|
|
|
bzero(&mask, sizeof(mask));
|
|
|
|
|
|
|
|
printf("nfs_boot: gateway=0x%x\n", ntohl(gw_ip.s_addr));
|
1994-06-13 19:28:55 +04:00
|
|
|
/* add, dest, gw, mask, flags, 0 */
|
1994-07-19 06:23:27 +04:00
|
|
|
error = rtrequest(RTM_ADD, &dst, (struct sockaddr *)&gw,
|
|
|
|
&mask, (RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL);
|
1994-06-13 19:28:55 +04:00
|
|
|
if (error)
|
|
|
|
printf("nfs_boot: add route, error=%d\n", error);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
get_path_and_handle(&bp_sin, "root", &nd->nd_root);
|
|
|
|
get_path_and_handle(&bp_sin, "swap", &nd->nd_swap);
|
|
|
|
|
|
|
|
return (0);
|
1994-04-18 10:18:05 +04:00
|
|
|
}
|
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
static void
|
|
|
|
get_path_and_handle(bpsin, key, ndmntp)
|
|
|
|
struct sockaddr_in *bpsin; /* bootparam server */
|
1994-06-29 11:28:36 +04:00
|
|
|
char *key; /* root or swap */
|
|
|
|
struct nfs_dlmount *ndmntp; /* output */
|
1994-04-18 10:18:05 +04:00
|
|
|
{
|
1994-06-13 19:28:55 +04:00
|
|
|
char pathname[MAXPATHLEN];
|
1994-06-21 12:30:20 +04:00
|
|
|
char *sp, *dp, *endp;
|
1994-06-13 19:28:55 +04:00
|
|
|
int error;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/*
|
|
|
|
* Get server:pathname for "key" (root or swap)
|
|
|
|
* using RPC to bootparam/getfile
|
|
|
|
*/
|
1994-06-29 11:28:36 +04:00
|
|
|
error = bp_getfile(bpsin, key, &ndmntp->ndm_saddr,
|
|
|
|
ndmntp->ndm_host, pathname);
|
1994-06-13 19:28:55 +04:00
|
|
|
if (error)
|
|
|
|
panic("nfs_boot: bootparam get %s: %d", key, error);
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/*
|
|
|
|
* Get file handle for "key" (root or swap)
|
|
|
|
* using RPC to mountd/mount
|
|
|
|
*/
|
1994-06-29 11:28:36 +04:00
|
|
|
error = md_mount(&ndmntp->ndm_saddr, pathname, ndmntp->ndm_fh);
|
1994-04-18 10:18:05 +04:00
|
|
|
if (error)
|
1994-06-13 19:28:55 +04:00
|
|
|
panic("nfs_boot: mountd %s, error=%d", key, error);
|
1994-06-21 12:30:20 +04:00
|
|
|
|
|
|
|
/* Construct remote path (for getmntinfo(3)) */
|
|
|
|
dp = ndmntp->ndm_host;
|
|
|
|
endp = dp + MNAMELEN - 1;
|
|
|
|
dp += strlen(dp);
|
|
|
|
*dp++ = ':';
|
|
|
|
for (sp = pathname; *sp && dp < endp;)
|
|
|
|
*dp++ = *sp++;
|
|
|
|
*dp = '\0';
|
1994-06-29 11:28:36 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RPC: bootparam/whoami
|
|
|
|
* Given client IP address, get:
|
|
|
|
* client name (hostname)
|
|
|
|
* domain name (domainname)
|
|
|
|
* gateway address
|
|
|
|
*
|
1995-03-29 01:29:32 +04:00
|
|
|
* The hostname and domainname are set here for convenience.
|
1994-09-26 19:42:29 +03:00
|
|
|
*
|
|
|
|
* Note - bpsin is initialized to the broadcast address,
|
|
|
|
* and will be replaced with the bootparam server address
|
|
|
|
* after this call is complete. Have to use PMAP_PROC_CALL
|
|
|
|
* to make sure we get responses only from a servers that
|
|
|
|
* know about us (don't want to broadcast a getport call).
|
1994-06-13 19:28:55 +04:00
|
|
|
*/
|
|
|
|
static int
|
1994-06-29 11:28:36 +04:00
|
|
|
bp_whoami(bpsin, my_ip, gw_ip)
|
|
|
|
struct sockaddr_in *bpsin;
|
|
|
|
struct in_addr *my_ip;
|
|
|
|
struct in_addr *gw_ip;
|
1994-04-18 10:18:05 +04:00
|
|
|
{
|
1994-09-26 19:42:29 +03:00
|
|
|
/* RPC structures for PMAPPROC_CALLIT */
|
|
|
|
struct whoami_call {
|
1995-04-25 01:54:56 +04:00
|
|
|
u_int32_t call_prog;
|
|
|
|
u_int32_t call_vers;
|
|
|
|
u_int32_t call_proc;
|
|
|
|
u_int32_t call_arglen;
|
1994-09-26 19:42:29 +03:00
|
|
|
} *call;
|
1995-04-25 01:54:56 +04:00
|
|
|
struct callit_reply {
|
|
|
|
u_int32_t port;
|
|
|
|
u_int32_t encap_len;
|
|
|
|
/* encapsulated data here */
|
|
|
|
} *reply;
|
1994-09-26 19:42:29 +03:00
|
|
|
|
|
|
|
struct mbuf *m, *from;
|
1994-06-13 19:28:55 +04:00
|
|
|
struct sockaddr_in *sin;
|
|
|
|
int error, msg_len;
|
1995-04-25 01:54:56 +04:00
|
|
|
int16_t port;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/*
|
1994-09-26 19:42:29 +03:00
|
|
|
* Build request message for PMAPPROC_CALLIT.
|
1994-06-13 19:28:55 +04:00
|
|
|
*/
|
1995-04-25 01:54:56 +04:00
|
|
|
m = m_get(M_WAIT, MT_DATA);
|
1994-09-26 19:42:29 +03:00
|
|
|
call = mtod(m, struct whoami_call *);
|
1995-04-25 01:54:56 +04:00
|
|
|
m->m_len = sizeof(*call);
|
1994-10-29 09:38:11 +03:00
|
|
|
call->call_prog = htonl(BOOTPARAM_PROG);
|
|
|
|
call->call_vers = htonl(BOOTPARAM_VERS);
|
|
|
|
call->call_proc = htonl(BOOTPARAM_WHOAMI);
|
1994-09-26 19:42:29 +03:00
|
|
|
|
1995-04-25 01:54:56 +04:00
|
|
|
/*
|
|
|
|
* append encapsulated data (client IP address)
|
|
|
|
*/
|
|
|
|
m->m_next = xdr_inaddr_encode(my_ip);
|
|
|
|
call->call_arglen = m->m_next->m_len;
|
1994-09-26 19:42:29 +03:00
|
|
|
|
|
|
|
/* RPC: portmap/callit */
|
|
|
|
bpsin->sin_port = htons(PMAPPORT);
|
|
|
|
from = NULL;
|
|
|
|
error = krpc_call(bpsin, PMAPPROG, PMAPVERS,
|
|
|
|
PMAPPROC_CALLIT, &m, &from);
|
1994-04-18 10:18:05 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse result message.
|
|
|
|
*/
|
1995-04-25 01:54:56 +04:00
|
|
|
if (m->m_len < sizeof(*reply)) {
|
|
|
|
m = m_pullup(m, sizeof(*reply));
|
|
|
|
if (m == NULL)
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
reply = mtod(m, struct callit_reply *);
|
|
|
|
port = ntohl(reply->port);
|
|
|
|
msg_len = ntohl(reply->encap_len);
|
|
|
|
m_adj(m, sizeof(*reply));
|
1994-09-26 19:42:29 +03:00
|
|
|
|
1995-04-25 01:54:56 +04:00
|
|
|
/*
|
|
|
|
* Save bootparam server address
|
|
|
|
*/
|
1994-09-26 19:42:29 +03:00
|
|
|
sin = mtod(from, struct sockaddr_in *);
|
1995-04-25 01:54:56 +04:00
|
|
|
bpsin->sin_port = htons(port);
|
1994-09-26 19:42:29 +03:00
|
|
|
bpsin->sin_addr.s_addr = sin->sin_addr.s_addr;
|
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/* client name */
|
1995-04-25 01:54:56 +04:00
|
|
|
hostnamelen = MAXHOSTNAMELEN-1;
|
|
|
|
m = xdr_string_decode(m, hostname, &hostnamelen);
|
|
|
|
if (m == NULL)
|
1994-06-13 19:28:55 +04:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/* domain name */
|
1995-04-25 01:54:56 +04:00
|
|
|
domainnamelen = MAXHOSTNAMELEN-1;
|
|
|
|
m = xdr_string_decode(m, domainname, &domainnamelen);
|
|
|
|
if (m == NULL)
|
1994-06-13 19:28:55 +04:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/* gateway address */
|
1995-04-25 01:54:56 +04:00
|
|
|
m = xdr_inaddr_decode(m, gw_ip);
|
|
|
|
if (m == NULL)
|
1994-06-13 19:28:55 +04:00
|
|
|
goto bad;
|
1995-04-25 01:54:56 +04:00
|
|
|
|
|
|
|
/* success */
|
1994-06-13 19:28:55 +04:00
|
|
|
goto out;
|
|
|
|
|
1994-06-29 11:28:36 +04:00
|
|
|
bad:
|
1994-06-13 19:28:55 +04:00
|
|
|
printf("nfs_boot: bootparam_whoami: bad reply\n");
|
|
|
|
error = EBADRPC;
|
|
|
|
|
1994-06-29 11:28:36 +04:00
|
|
|
out:
|
1994-09-26 19:42:29 +03:00
|
|
|
if (from)
|
|
|
|
m_freem(from);
|
1995-04-25 01:54:56 +04:00
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
1994-06-13 19:28:55 +04:00
|
|
|
return(error);
|
1994-04-18 10:18:05 +04:00
|
|
|
}
|
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
|
1994-04-18 10:18:05 +04:00
|
|
|
/*
|
1994-06-13 19:28:55 +04:00
|
|
|
* RPC: bootparam/getfile
|
|
|
|
* Given client name and file "key", get:
|
|
|
|
* server name
|
|
|
|
* server IP address
|
|
|
|
* server pathname
|
1994-04-18 10:18:05 +04:00
|
|
|
*/
|
1994-06-13 19:28:55 +04:00
|
|
|
static int
|
1994-06-29 11:28:36 +04:00
|
|
|
bp_getfile(bpsin, key, md_sin, serv_name, pathname)
|
|
|
|
struct sockaddr_in *bpsin;
|
|
|
|
char *key;
|
|
|
|
struct sockaddr_in *md_sin;
|
|
|
|
char *serv_name;
|
|
|
|
char *pathname;
|
1994-04-18 10:18:05 +04:00
|
|
|
{
|
1994-06-13 19:28:55 +04:00
|
|
|
struct mbuf *m;
|
1994-04-18 10:18:05 +04:00
|
|
|
struct sockaddr_in *sin;
|
1995-04-25 01:54:56 +04:00
|
|
|
struct in_addr inaddr;
|
|
|
|
int error, sn_len, path_len;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
|
|
|
/*
|
1994-06-13 19:28:55 +04:00
|
|
|
* Build request message.
|
1994-04-18 10:18:05 +04:00
|
|
|
*/
|
1995-04-25 01:54:56 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/* client name (hostname) */
|
1995-04-25 01:54:56 +04:00
|
|
|
m = xdr_string_encode(hostname, hostnamelen);
|
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/* key name (root or swap) */
|
1995-04-25 01:54:56 +04:00
|
|
|
m->m_next = xdr_string_encode(key, strlen(key));
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
/* RPC: bootparam/getfile */
|
1994-09-26 19:42:29 +03:00
|
|
|
error = krpc_call(bpsin, BOOTPARAM_PROG, BOOTPARAM_VERS,
|
|
|
|
BOOTPARAM_GETFILE, &m, NULL);
|
1994-06-13 19:28:55 +04:00
|
|
|
if (error)
|
1994-04-18 10:18:05 +04:00
|
|
|
return error;
|
|
|
|
|
|
|
|
/*
|
1994-06-13 19:28:55 +04:00
|
|
|
* Parse result message.
|
1994-04-18 10:18:05 +04:00
|
|
|
*/
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
/* server name */
|
1995-04-25 01:54:56 +04:00
|
|
|
sn_len = MNAMELEN-1;
|
|
|
|
m = xdr_string_decode(m, serv_name, &sn_len);
|
|
|
|
if (m == NULL)
|
1994-06-13 19:28:55 +04:00
|
|
|
goto bad;
|
|
|
|
|
1995-04-25 01:54:56 +04:00
|
|
|
/* server IP address (mountd/NFS) */
|
|
|
|
m = xdr_inaddr_decode(m, &inaddr);
|
|
|
|
if (m == NULL)
|
1994-06-13 19:28:55 +04:00
|
|
|
goto bad;
|
1995-04-25 01:54:56 +04:00
|
|
|
|
|
|
|
/* server pathname */
|
|
|
|
path_len = MAXPATHLEN-1;
|
|
|
|
m = xdr_string_decode(m, pathname, &path_len);
|
|
|
|
if (m == NULL)
|
1994-06-13 19:28:55 +04:00
|
|
|
goto bad;
|
1995-04-25 01:54:56 +04:00
|
|
|
|
|
|
|
/* setup server socket address */
|
1994-06-13 19:28:55 +04:00
|
|
|
sin = md_sin;
|
1994-08-12 03:47:51 +04:00
|
|
|
bzero((caddr_t)sin, sizeof(*sin));
|
1994-06-13 19:28:55 +04:00
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
sin->sin_family = AF_INET;
|
1995-04-25 01:54:56 +04:00
|
|
|
sin->sin_addr = inaddr;
|
1994-06-13 19:28:55 +04:00
|
|
|
|
1995-04-25 01:54:56 +04:00
|
|
|
/* success */
|
1994-06-13 19:28:55 +04:00
|
|
|
goto out;
|
|
|
|
|
1994-06-29 11:28:36 +04:00
|
|
|
bad:
|
1994-06-13 19:28:55 +04:00
|
|
|
printf("nfs_boot: bootparam_getfile: bad reply\n");
|
|
|
|
error = EBADRPC;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-29 11:28:36 +04:00
|
|
|
out:
|
1994-06-13 19:28:55 +04:00
|
|
|
m_freem(m);
|
|
|
|
return(0);
|
1994-04-18 10:18:05 +04:00
|
|
|
}
|
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
|
1994-04-18 10:18:05 +04:00
|
|
|
/*
|
1994-06-13 19:28:55 +04:00
|
|
|
* RPC: mountd/mount
|
|
|
|
* Given a server pathname, get an NFS file handle.
|
|
|
|
* Also, sets sin->sin_port to the NFS service port.
|
1994-04-18 10:18:05 +04:00
|
|
|
*/
|
1994-06-13 19:28:55 +04:00
|
|
|
static int
|
|
|
|
md_mount(mdsin, path, fhp)
|
|
|
|
struct sockaddr_in *mdsin; /* mountd server address */
|
|
|
|
char *path;
|
|
|
|
u_char *fhp;
|
1994-04-18 10:18:05 +04:00
|
|
|
{
|
1994-06-13 19:28:55 +04:00
|
|
|
/* The RPC structures */
|
|
|
|
struct rdata {
|
1995-04-25 01:54:56 +04:00
|
|
|
u_int32_t errno;
|
1994-06-13 19:28:55 +04:00
|
|
|
u_char fh[NFS_FHSIZE];
|
|
|
|
} *rdata;
|
|
|
|
struct mbuf *m;
|
1995-04-25 01:54:56 +04:00
|
|
|
int error;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-09-26 19:42:29 +03:00
|
|
|
/* Get port number for MOUNTD. */
|
|
|
|
error = krpc_portmap(mdsin, RPCPROG_MNT, RPCMNT_VER1,
|
|
|
|
&mdsin->sin_port);
|
|
|
|
if (error) return error;
|
|
|
|
|
1995-04-25 01:54:56 +04:00
|
|
|
m = xdr_string_encode(path, strlen(path));
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/* Do RPC to mountd. */
|
1994-09-26 19:42:29 +03:00
|
|
|
error = krpc_call(mdsin, RPCPROG_MNT, RPCMNT_VER1,
|
|
|
|
RPCMNT_MOUNT, &m, NULL);
|
1994-06-29 11:28:36 +04:00
|
|
|
if (error)
|
1994-06-13 19:28:55 +04:00
|
|
|
return error; /* message already freed */
|
|
|
|
|
1995-04-25 01:54:56 +04:00
|
|
|
if (m->m_len < sizeof(*rdata)) {
|
|
|
|
m = m_pullup(m, sizeof(*rdata));
|
|
|
|
if (m == NULL)
|
|
|
|
goto bad;
|
|
|
|
}
|
1994-06-13 19:28:55 +04:00
|
|
|
rdata = mtod(m, struct rdata *);
|
|
|
|
error = ntohl(rdata->errno);
|
1994-04-18 10:18:05 +04:00
|
|
|
if (error)
|
1994-06-13 19:28:55 +04:00
|
|
|
goto bad;
|
|
|
|
bcopy(rdata->fh, fhp, NFS_FHSIZE);
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/* Set port number for NFS use. */
|
1994-09-26 19:42:29 +03:00
|
|
|
error = krpc_portmap(mdsin, NFS_PROG, NFS_VER2,
|
|
|
|
&mdsin->sin_port);
|
1994-06-13 19:28:55 +04:00
|
|
|
goto out;
|
|
|
|
|
1994-06-29 11:28:36 +04:00
|
|
|
bad:
|
1994-06-13 19:28:55 +04:00
|
|
|
error = EBADRPC;
|
|
|
|
|
1994-06-29 11:28:36 +04:00
|
|
|
out:
|
1994-06-13 19:28:55 +04:00
|
|
|
m_freem(m);
|
|
|
|
return error;
|
1994-04-18 10:18:05 +04:00
|
|
|
}
|
1994-07-16 15:43:12 +04:00
|
|
|
|
|
|
|
#endif /* NETHER */
|