1996-10-20 17:13:22 +04:00
|
|
|
/* $NetBSD: nfs_boot.c,v 1.29 1996/10/20 13:13:25 fvdl 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>
|
1996-02-18 14:53:36 +03:00
|
|
|
#include <nfs/nfsproto.h>
|
1994-04-18 10:18:05 +04:00
|
|
|
#include <nfs/nfs.h>
|
|
|
|
#include <nfs/nfsdiskless.h>
|
1994-09-26 19:42:29 +03:00
|
|
|
#include <nfs/krpc.h>
|
1995-05-20 05:52:49 +04:00
|
|
|
#include <nfs/xdr_subs.h>
|
1996-02-10 00:48:19 +03:00
|
|
|
#include <nfs/nfs_var.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");
|
|
|
|
}
|
|
|
|
|
1996-02-16 18:18:19 +03:00
|
|
|
void
|
|
|
|
nfs_boot_getfh(bpsin, key, ndmntp)
|
|
|
|
struct sockaddr_in *bpsin;
|
|
|
|
char *key;
|
|
|
|
struct nfs_dlmount *ndmntp;
|
|
|
|
{
|
|
|
|
/* can not get here */
|
|
|
|
}
|
|
|
|
|
1994-09-26 19:42:29 +03:00
|
|
|
#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,
|
1996-10-20 17:13:22 +04:00
|
|
|
struct nfs_args *argp));
|
1994-06-13 19:28:55 +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
|
1995-06-12 04:46:47 +04:00
|
|
|
for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next)
|
1995-02-17 00:42:50 +03:00
|
|
|
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");
|
1996-05-07 06:51:25 +04:00
|
|
|
bcopy(ifp->if_xname, ireq.ifr_name, IFNAMSIZ);
|
1996-10-13 05:39:03 +04:00
|
|
|
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.
|
1995-05-23 04:14:06 +04:00
|
|
|
*
|
|
|
|
* Get the old interface flags and or IFF_UP into them; if
|
|
|
|
* IFF_UP set blindly, interface selection can be clobbered.
|
1994-06-13 19:28:55 +04:00
|
|
|
*/
|
|
|
|
if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0)) != 0)
|
|
|
|
panic("nfs_boot: socreate, error=%d", error);
|
1995-05-23 04:14:06 +04:00
|
|
|
error = ifioctl(so, SIOCGIFFLAGS, (caddr_t)&ireq, procp);
|
|
|
|
if (error)
|
|
|
|
panic("nfs_boot: GIFFLAGS, error=%d", error);
|
|
|
|
ireq.ifr_flags |= IFF_UP;
|
1994-06-13 19:28:55 +04:00
|
|
|
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);
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("nfs_boot: client_addr=0x%x\n", (u_int32_t)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);
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("nfs_boot: server_addr=0x%x\n",
|
1996-02-18 14:53:36 +03:00
|
|
|
(u_int32_t)ntohl(bp_sin.sin_addr.s_addr));
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("nfs_boot: hostname=%s\n", hostname);
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
#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));
|
|
|
|
|
1996-10-13 05:39:03 +04:00
|
|
|
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)
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("nfs_boot: add route, error=%d\n", error);
|
1994-06-13 19:28:55 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1996-02-13 20:53:32 +03:00
|
|
|
bcopy(&bp_sin, &nd->nd_boot, sizeof(bp_sin));
|
1994-06-13 19:28:55 +04:00
|
|
|
|
|
|
|
return (0);
|
1994-04-18 10:18:05 +04:00
|
|
|
}
|
|
|
|
|
1996-02-13 20:53:32 +03:00
|
|
|
void
|
|
|
|
nfs_boot_getfh(bpsin, key, ndmntp)
|
1994-06-13 19:28:55 +04:00
|
|
|
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
|
|
|
{
|
1996-10-20 17:13:22 +04:00
|
|
|
struct nfs_args *args;
|
1994-06-13 19:28:55 +04:00
|
|
|
char pathname[MAXPATHLEN];
|
1994-06-21 12:30:20 +04:00
|
|
|
char *sp, *dp, *endp;
|
1996-02-13 20:53:32 +03:00
|
|
|
struct sockaddr_in *sin;
|
1994-06-13 19:28:55 +04:00
|
|
|
int error;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1996-10-20 17:13:22 +04:00
|
|
|
args = &ndmntp->ndm_args;
|
|
|
|
|
|
|
|
/* Initialize mount args. */
|
|
|
|
bzero((caddr_t) args, sizeof(*args));
|
|
|
|
args->addr = &ndmntp->ndm_saddr;
|
|
|
|
args->addrlen = args->addr->sa_len;
|
|
|
|
#ifdef NFS_BOOT_TCP
|
|
|
|
args->sotype = SOCK_STREAM;
|
|
|
|
#else
|
|
|
|
args->sotype = SOCK_DGRAM;
|
|
|
|
#endif
|
|
|
|
args->fh = ndmntp->ndm_fh;
|
|
|
|
args->hostname = ndmntp->ndm_host;
|
|
|
|
args->flags = NFSMNT_RESVPORT | NFSMNT_NFSV3;
|
|
|
|
|
|
|
|
#ifdef NFS_BOOT_OPTIONS
|
|
|
|
args->flags |= NFS_BOOT_OPTIONS;
|
|
|
|
#endif
|
|
|
|
#ifdef NFS_BOOT_RWSIZE
|
|
|
|
/*
|
|
|
|
* Reduce rsize,wsize for interfaces that consistently
|
|
|
|
* drop fragments of long UDP messages. (i.e. wd8003).
|
|
|
|
* You can always change these later via remount.
|
|
|
|
*/
|
|
|
|
args->flags |= NFSMNT_WSIZE | NFSMNT_RSIZE;
|
|
|
|
args->wsize = NFS_BOOT_RWSIZE;
|
|
|
|
args->rsize = NFS_BOOT_RWSIZE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sin = (void*)&ndmntp->ndm_saddr;
|
1996-02-13 20:53:32 +03:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/*
|
|
|
|
* Get server:pathname for "key" (root or swap)
|
|
|
|
* using RPC to bootparam/getfile
|
|
|
|
*/
|
1996-02-18 14:53:36 +03:00
|
|
|
error = bp_getfile(bpsin, key, sin, 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
|
|
|
|
*/
|
1996-10-20 17:13:22 +04:00
|
|
|
error = md_mount(sin, pathname, args);
|
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
|
|
|
|
1996-02-13 20:53:32 +03:00
|
|
|
/* Set port number for NFS use. */
|
|
|
|
/* XXX: NFS port is always 2049, right? */
|
1996-10-20 17:13:22 +04:00
|
|
|
#ifdef NFS_BOOT_TCP
|
|
|
|
retry:
|
|
|
|
#endif
|
|
|
|
error = krpc_portmap(sin, NFS_PROG,
|
|
|
|
(args->flags & NFSMNT_NFSV3) ? NFS_VER3 : NFS_VER2,
|
|
|
|
(args->sotype == SOCK_STREAM) ? IPPROTO_TCP : IPPROTO_UDP,
|
|
|
|
&sin->sin_port);
|
|
|
|
|
|
|
|
if (error || (sin->sin_port == htons(0))) {
|
|
|
|
#ifdef NFS_BOOT_TCP
|
|
|
|
if (args->sotype == SOCK_STREAM) {
|
|
|
|
args->sotype = SOCK_DGRAM;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
panic("nfs_boot: portmap NFS, error=%d", error);
|
|
|
|
}
|
1996-02-13 20:53:32 +03:00
|
|
|
|
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);
|
1995-05-20 05:52:49 +04:00
|
|
|
call->call_prog = txdr_unsigned(BOOTPARAM_PROG);
|
|
|
|
call->call_vers = txdr_unsigned(BOOTPARAM_VERS);
|
|
|
|
call->call_proc = txdr_unsigned(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);
|
1995-05-20 05:52:49 +04:00
|
|
|
call->call_arglen = txdr_unsigned(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 *);
|
1995-05-20 05:52:49 +04:00
|
|
|
port = fxdr_unsigned(u_int32_t, reply->port);
|
|
|
|
msg_len = fxdr_unsigned(u_int32_t, reply->encap_len);
|
1995-04-25 01:54:56 +04:00
|
|
|
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:
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("nfs_boot: bootparam_whoami: bad reply\n");
|
1994-06-13 19:28:55 +04:00
|
|
|
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);
|
1996-02-11 01:55:16 +03:00
|
|
|
if (m == NULL)
|
|
|
|
return (ENOMEM);
|
1995-04-25 01:54:56 +04:00
|
|
|
|
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));
|
1996-02-11 01:55:16 +03:00
|
|
|
if (m->m_next == NULL)
|
|
|
|
return (ENOMEM);
|
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:
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("nfs_boot: bootparam_getfile: bad reply\n");
|
1994-06-13 19:28:55 +04:00
|
|
|
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
|
1996-10-20 17:13:22 +04:00
|
|
|
md_mount(mdsin, path, argp)
|
1994-06-13 19:28:55 +04:00
|
|
|
struct sockaddr_in *mdsin; /* mountd server address */
|
|
|
|
char *path;
|
1996-10-20 17:13:22 +04:00
|
|
|
struct nfs_args *argp;
|
1994-04-18 10:18:05 +04:00
|
|
|
{
|
1994-06-13 19:28:55 +04:00
|
|
|
/* The RPC structures */
|
|
|
|
struct rdata {
|
1995-12-20 02:07:11 +03:00
|
|
|
u_int32_t errno;
|
1996-10-20 17:13:22 +04:00
|
|
|
union {
|
|
|
|
u_int8_t v2fh[NFSX_V2FH];
|
|
|
|
struct {
|
|
|
|
u_int32_t fhlen;
|
|
|
|
u_int8_t fh[1];
|
|
|
|
} v3fh;
|
|
|
|
} fh;
|
1994-06-13 19:28:55 +04:00
|
|
|
} *rdata;
|
|
|
|
struct mbuf *m;
|
1996-10-20 17:13:22 +04:00
|
|
|
u_int8_t *fh;
|
|
|
|
int minlen, error;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1996-10-20 17:13:22 +04:00
|
|
|
retry:
|
1994-09-26 19:42:29 +03:00
|
|
|
/* Get port number for MOUNTD. */
|
1996-10-20 17:13:22 +04:00
|
|
|
error = krpc_portmap(mdsin, RPCPROG_MNT,
|
|
|
|
(argp->flags & NFSMNT_NFSV3) ? RPCMNT_VER3 : RPCMNT_VER1,
|
|
|
|
IPPROTO_UDP, &mdsin->sin_port);
|
|
|
|
if (error)
|
|
|
|
return error;
|
1994-09-26 19:42:29 +03:00
|
|
|
|
1995-04-25 01:54:56 +04:00
|
|
|
m = xdr_string_encode(path, strlen(path));
|
1996-02-11 01:55:16 +03:00
|
|
|
if (m == NULL)
|
1996-02-18 14:53:36 +03:00
|
|
|
return ENOMEM;
|
1994-04-18 10:18:05 +04:00
|
|
|
|
1994-06-13 19:28:55 +04:00
|
|
|
/* Do RPC to mountd. */
|
1996-10-20 17:13:22 +04:00
|
|
|
error = krpc_call(mdsin, RPCPROG_MNT, (argp->flags & NFSMNT_NFSV3) ?
|
|
|
|
RPCMNT_VER3 : RPCMNT_VER1, RPCMNT_MOUNT, &m, NULL);
|
|
|
|
if (error) {
|
|
|
|
if ((error==RPC_PROGMISMATCH) && (argp->flags & NFSMNT_NFSV3)) {
|
|
|
|
argp->flags &= ~NFSMNT_NFSV3;
|
|
|
|
goto retry;
|
|
|
|
}
|
1994-06-13 19:28:55 +04:00
|
|
|
return error; /* message already freed */
|
1996-10-20 17:13:22 +04:00
|
|
|
}
|
1994-06-13 19:28:55 +04:00
|
|
|
|
1996-02-13 20:53:32 +03:00
|
|
|
/* The reply might have only the errno. */
|
|
|
|
if (m->m_len < 4)
|
|
|
|
goto bad;
|
|
|
|
/* Have at least errno, so check that. */
|
|
|
|
rdata = mtod(m, struct rdata *);
|
|
|
|
error = fxdr_unsigned(u_int32_t, rdata->errno);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
/* Have errno==0, so the fh must be there. */
|
1996-10-20 17:13:22 +04:00
|
|
|
if (argp->flags & NFSMNT_NFSV3){
|
|
|
|
argp->fhsize = fxdr_unsigned(u_int32_t, rdata->fh.v3fh.fhlen);
|
|
|
|
if (argp->fhsize > NFSX_V3FHMAX)
|
1995-04-25 01:54:56 +04:00
|
|
|
goto bad;
|
1996-10-20 17:13:22 +04:00
|
|
|
minlen = 2 * sizeof(u_int32_t) + argp->fhsize;
|
|
|
|
} else {
|
|
|
|
argp->fhsize = NFSX_V2FH;
|
|
|
|
minlen = sizeof(u_int32_t) + argp->fhsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m->m_len < minlen) {
|
|
|
|
m = m_pullup(m, minlen);
|
|
|
|
if (m == NULL)
|
|
|
|
return(EBADRPC);
|
1996-02-13 20:53:32 +03:00
|
|
|
rdata = mtod(m, struct rdata *);
|
1995-04-25 01:54:56 +04:00
|
|
|
}
|
1996-10-20 17:13:22 +04:00
|
|
|
|
|
|
|
fh = (argp->flags & NFSMNT_NFSV3) ? rdata->fh.v3fh.fh : rdata->fh.v2fh;
|
|
|
|
bcopy(fh, argp->fh, argp->fhsize);
|
|
|
|
|
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 */
|