2002-09-22 00:59:02 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2002-09-22 00:59:02 +00:00
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* William Jolitz.
|
|
|
|
*
|
|
|
|
* 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.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2002-09-22 00:59:02 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
* from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91
|
|
|
|
*/
|
|
|
|
|
2003-06-11 05:37:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2005-01-12 12:42:46 +00:00
|
|
|
#include "opt_bootp.h"
|
|
|
|
|
2002-09-22 00:59:02 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2011-02-16 21:29:13 +00:00
|
|
|
#include <sys/jail.h>
|
2002-09-22 00:59:02 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/socket.h>
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
|
2002-09-22 00:59:02 +00:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_var.h>
|
|
|
|
#include <net/ethernet.h>
|
2008-12-02 21:37:28 +00:00
|
|
|
#include <net/vnet.h>
|
|
|
|
|
2002-09-22 00:59:02 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <nfs/nfsproto.h>
|
|
|
|
#include <nfsclient/nfs.h>
|
2011-04-25 22:22:51 +00:00
|
|
|
#include <nfs/nfsdiskless.h>
|
2002-09-22 00:59:02 +00:00
|
|
|
|
2015-09-26 13:55:55 +00:00
|
|
|
#define NFS_IFACE_TIMEOUT_SECS 10 /* Timeout for interface to appear. */
|
|
|
|
|
2002-09-22 00:59:02 +00:00
|
|
|
static int inaddr_to_sockaddr(char *ev, struct sockaddr_in *sa);
|
|
|
|
static int hwaddr_to_sockaddr(char *ev, struct sockaddr_dl *sa);
|
2010-09-01 23:51:07 +00:00
|
|
|
static int decode_nfshandle(char *ev, u_char *fh, int maxfh);
|
2002-09-22 00:59:02 +00:00
|
|
|
|
2011-04-25 22:22:51 +00:00
|
|
|
/*
|
|
|
|
* This structure must be filled in by a primary bootstrap or bootstrap
|
|
|
|
* server for a diskless/dataless machine. It is initialized below just
|
|
|
|
* to ensure that it is allocated to initialized data (.data not .bss).
|
|
|
|
*/
|
|
|
|
struct nfs_diskless nfs_diskless = { { { 0 } } };
|
|
|
|
struct nfsv3_diskless nfsv3_diskless = { { { 0 } } };
|
|
|
|
int nfs_diskless_valid = 0;
|
|
|
|
|
2006-12-06 02:15:25 +00:00
|
|
|
/*
|
|
|
|
* Validate/sanity check a rsize/wsize parameter.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
checkrwsize(unsigned long v, const char *name)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 32K is used as an upper bound because most servers
|
|
|
|
* limit block size to satisfy IPv4's limit of
|
|
|
|
* 64K/reassembled packet. The lower bound is pretty
|
|
|
|
* much arbitrary.
|
|
|
|
*/
|
|
|
|
if (!(4 <= v && v <= 32*1024)) {
|
|
|
|
printf("nfs_parse_options: invalid %s %lu ignored\n", name, v);
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse mount options and apply them to the supplied
|
|
|
|
* nfs_diskless state. Used also by bootp/dhcp support.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfs_parse_options(const char *envopts, struct nfs_args *nd)
|
2005-10-06 11:18:34 +00:00
|
|
|
{
|
2005-10-06 19:04:08 +00:00
|
|
|
char *opts, *o, *otmp;
|
2006-12-06 02:15:25 +00:00
|
|
|
unsigned long v;
|
2005-10-06 11:18:34 +00:00
|
|
|
|
|
|
|
opts = strdup(envopts, M_TEMP);
|
2005-10-06 19:04:08 +00:00
|
|
|
otmp = opts;
|
|
|
|
while ((o = strsep(&otmp, ":;, ")) != NULL) {
|
|
|
|
if (*o == '\0')
|
|
|
|
; /* Skip empty options. */
|
|
|
|
else if (strcmp(o, "soft") == 0)
|
2006-12-06 02:15:25 +00:00
|
|
|
nd->flags |= NFSMNT_SOFT;
|
2005-10-06 11:18:34 +00:00
|
|
|
else if (strcmp(o, "intr") == 0)
|
2006-12-06 02:15:25 +00:00
|
|
|
nd->flags |= NFSMNT_INT;
|
2005-10-06 11:18:34 +00:00
|
|
|
else if (strcmp(o, "conn") == 0)
|
2006-12-06 02:15:25 +00:00
|
|
|
nd->flags |= NFSMNT_NOCONN;
|
2006-03-19 13:27:37 +00:00
|
|
|
else if (strcmp(o, "nolockd") == 0)
|
2006-12-06 02:15:25 +00:00
|
|
|
nd->flags |= NFSMNT_NOLOCKD;
|
2011-05-04 13:27:45 +00:00
|
|
|
else if (strcmp(o, "nocto") == 0)
|
|
|
|
nd->flags |= NFSMNT_NOCTO;
|
2006-12-06 02:15:25 +00:00
|
|
|
else if (strcmp(o, "nfsv2") == 0)
|
|
|
|
nd->flags &= ~(NFSMNT_NFSV3 | NFSMNT_NFSV4);
|
|
|
|
else if (strcmp(o, "nfsv3") == 0) {
|
|
|
|
nd->flags &= ~NFSMNT_NFSV4;
|
|
|
|
nd->flags |= NFSMNT_NFSV3;
|
|
|
|
} else if (strcmp(o, "tcp") == 0)
|
|
|
|
nd->sotype = SOCK_STREAM;
|
|
|
|
else if (strcmp(o, "udp") == 0)
|
|
|
|
nd->sotype = SOCK_DGRAM;
|
|
|
|
else if (strncmp(o, "rsize=", 6) == 0) {
|
|
|
|
v = strtoul(o+6, NULL, 10);
|
|
|
|
if (checkrwsize(v, "rsize")) {
|
|
|
|
nd->rsize = (int) v;
|
|
|
|
nd->flags |= NFSMNT_RSIZE;
|
|
|
|
}
|
|
|
|
} else if (strncmp(o, "wsize=", 6) == 0) {
|
|
|
|
v = strtoul(o+6, NULL, 10);
|
|
|
|
if (checkrwsize(v, "wsize")) {
|
|
|
|
nd->wsize = (int) v;
|
|
|
|
nd->flags |= NFSMNT_WSIZE;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
printf("%s: skipping unknown option \"%s\"\n",
|
|
|
|
__func__, o);
|
2005-10-06 11:18:34 +00:00
|
|
|
}
|
|
|
|
free(opts, M_TEMP);
|
|
|
|
}
|
|
|
|
|
2002-09-22 00:59:02 +00:00
|
|
|
/*
|
|
|
|
* Populate the essential fields in the nfsv3_diskless structure.
|
|
|
|
*
|
|
|
|
* The loader is expected to export the following environment variables:
|
|
|
|
*
|
2005-04-26 20:47:59 +00:00
|
|
|
* boot.netif.name name of boot interface
|
2002-09-22 00:59:02 +00:00
|
|
|
* boot.netif.ip IP address on boot interface
|
|
|
|
* boot.netif.netmask netmask on boot interface
|
|
|
|
* boot.netif.gateway default gateway (optional)
|
|
|
|
* boot.netif.hwaddr hardware address of boot interface
|
2016-03-20 21:48:26 +00:00
|
|
|
* boot.netif.mtu interface mtu from bootp/dhcp (optional)
|
2002-09-22 00:59:02 +00:00
|
|
|
* boot.nfsroot.server IP address of root filesystem server
|
|
|
|
* boot.nfsroot.path path of the root filesystem on server
|
|
|
|
* boot.nfsroot.nfshandle NFS handle for root filesystem on server
|
2010-09-01 23:51:07 +00:00
|
|
|
* boot.nfsroot.nfshandlelen and length of this handle (for NFSv3 only)
|
2005-10-06 11:18:34 +00:00
|
|
|
* boot.nfsroot.options NFS options for the root filesystem
|
2002-09-22 00:59:02 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfs_setup_diskless(void)
|
|
|
|
{
|
|
|
|
struct nfs_diskless *nd = &nfs_diskless;
|
2010-09-01 23:51:07 +00:00
|
|
|
struct nfsv3_diskless *nd3 = &nfsv3_diskless;
|
2002-09-22 00:59:02 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct sockaddr_dl *sdl, ourdl;
|
|
|
|
struct sockaddr_in myaddr, netmask;
|
|
|
|
char *cp;
|
2010-09-01 23:51:07 +00:00
|
|
|
int cnt, fhlen, is_nfsv3;
|
|
|
|
uint32_t len;
|
2015-09-26 13:55:55 +00:00
|
|
|
time_t timeout_at;
|
2002-09-22 00:59:02 +00:00
|
|
|
|
2010-09-01 23:51:07 +00:00
|
|
|
if (nfs_diskless_valid != 0)
|
2002-09-22 00:59:02 +00:00
|
|
|
return;
|
2010-09-01 23:51:07 +00:00
|
|
|
|
|
|
|
/* get handle size. If this succeeds, it's an NFSv3 setup. */
|
2014-10-16 18:04:43 +00:00
|
|
|
if ((cp = kern_getenv("boot.nfsroot.nfshandlelen")) != NULL) {
|
2010-09-01 23:51:07 +00:00
|
|
|
cnt = sscanf(cp, "%d", &len);
|
|
|
|
freeenv(cp);
|
|
|
|
if (cnt != 1 || len == 0 || len > NFSX_V3FHMAX) {
|
|
|
|
printf("nfs_diskless: bad NFS handle len\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nd3->root_fhsize = len;
|
|
|
|
is_nfsv3 = 1;
|
|
|
|
} else
|
|
|
|
is_nfsv3 = 0;
|
2002-09-22 00:59:02 +00:00
|
|
|
/* set up interface */
|
|
|
|
if (inaddr_to_sockaddr("boot.netif.ip", &myaddr))
|
|
|
|
return;
|
|
|
|
if (inaddr_to_sockaddr("boot.netif.netmask", &netmask)) {
|
|
|
|
printf("nfs_diskless: no netmask\n");
|
|
|
|
return;
|
|
|
|
}
|
2010-09-01 23:51:07 +00:00
|
|
|
if (is_nfsv3 != 0) {
|
|
|
|
bcopy(&myaddr, &nd3->myif.ifra_addr, sizeof(myaddr));
|
|
|
|
bcopy(&myaddr, &nd3->myif.ifra_broadaddr, sizeof(myaddr));
|
|
|
|
((struct sockaddr_in *)
|
|
|
|
&nd3->myif.ifra_broadaddr)->sin_addr.s_addr =
|
|
|
|
myaddr.sin_addr.s_addr | ~ netmask.sin_addr.s_addr;
|
|
|
|
bcopy(&netmask, &nd3->myif.ifra_mask, sizeof(netmask));
|
|
|
|
} else {
|
|
|
|
bcopy(&myaddr, &nd->myif.ifra_addr, sizeof(myaddr));
|
|
|
|
bcopy(&myaddr, &nd->myif.ifra_broadaddr, sizeof(myaddr));
|
|
|
|
((struct sockaddr_in *)
|
|
|
|
&nd->myif.ifra_broadaddr)->sin_addr.s_addr =
|
|
|
|
myaddr.sin_addr.s_addr | ~ netmask.sin_addr.s_addr;
|
|
|
|
bcopy(&netmask, &nd->myif.ifra_mask, sizeof(netmask));
|
|
|
|
}
|
2002-09-22 00:59:02 +00:00
|
|
|
|
|
|
|
if (hwaddr_to_sockaddr("boot.netif.hwaddr", &ourdl)) {
|
|
|
|
printf("nfs_diskless: no hardware address\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifa = NULL;
|
2015-09-26 13:55:55 +00:00
|
|
|
timeout_at = time_uptime + NFS_IFACE_TIMEOUT_SECS;
|
|
|
|
retry:
|
2011-02-16 21:29:13 +00:00
|
|
|
CURVNET_SET(TD_TO_VNET(curthread));
|
2002-12-22 05:35:03 +00:00
|
|
|
IFNET_RLOCK();
|
2018-05-23 21:02:14 +00:00
|
|
|
CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
|
2018-05-18 20:13:34 +00:00
|
|
|
CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
|
2006-06-29 19:22:05 +00:00
|
|
|
if (ifa->ifa_addr->sa_family == AF_LINK) {
|
|
|
|
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
2002-09-22 00:59:02 +00:00
|
|
|
if ((sdl->sdl_type == ourdl.sdl_type) &&
|
|
|
|
(sdl->sdl_alen == ourdl.sdl_alen) &&
|
2005-11-29 09:51:47 +00:00
|
|
|
!bcmp(LLADDR(sdl),
|
|
|
|
LLADDR(&ourdl),
|
2002-12-22 05:35:03 +00:00
|
|
|
sdl->sdl_alen)) {
|
|
|
|
IFNET_RUNLOCK();
|
2011-02-16 21:29:13 +00:00
|
|
|
CURVNET_RESTORE();
|
2002-09-22 00:59:02 +00:00
|
|
|
goto match_done;
|
2002-12-22 05:35:03 +00:00
|
|
|
}
|
2002-09-22 00:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-22 05:35:03 +00:00
|
|
|
IFNET_RUNLOCK();
|
2011-02-16 21:29:13 +00:00
|
|
|
CURVNET_RESTORE();
|
2015-09-26 13:55:55 +00:00
|
|
|
if (time_uptime < timeout_at) {
|
|
|
|
pause("nfssdl", hz / 5);
|
|
|
|
goto retry;
|
|
|
|
}
|
2002-09-22 00:59:02 +00:00
|
|
|
printf("nfs_diskless: no interface\n");
|
|
|
|
return; /* no matching interface */
|
|
|
|
match_done:
|
2014-10-16 18:04:43 +00:00
|
|
|
kern_setenv("boot.netif.name", ifp->if_xname);
|
2010-09-01 23:51:07 +00:00
|
|
|
if (is_nfsv3 != 0) {
|
|
|
|
strlcpy(nd3->myif.ifra_name, ifp->if_xname,
|
|
|
|
sizeof(nd3->myif.ifra_name));
|
2020-09-01 21:25:39 +00:00
|
|
|
|
2010-09-01 23:51:07 +00:00
|
|
|
/* set up gateway */
|
|
|
|
inaddr_to_sockaddr("boot.netif.gateway", &nd3->mygateway);
|
2002-09-22 00:59:02 +00:00
|
|
|
|
2010-09-01 23:51:07 +00:00
|
|
|
/* set up root mount */
|
|
|
|
nd3->root_args.rsize = 32768; /* XXX tunable? */
|
|
|
|
nd3->root_args.wsize = 32768;
|
|
|
|
nd3->root_args.sotype = SOCK_STREAM;
|
|
|
|
nd3->root_args.flags = (NFSMNT_NFSV3 | NFSMNT_WSIZE |
|
|
|
|
NFSMNT_RSIZE | NFSMNT_RESVPORT);
|
|
|
|
if (inaddr_to_sockaddr("boot.nfsroot.server",
|
|
|
|
&nd3->root_saddr)) {
|
|
|
|
printf("nfs_diskless: no server\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nd3->root_saddr.sin_port = htons(NFS_PORT);
|
|
|
|
fhlen = decode_nfshandle("boot.nfsroot.nfshandle",
|
|
|
|
&nd3->root_fh[0], NFSX_V3FHMAX);
|
|
|
|
if (fhlen == 0) {
|
|
|
|
printf("nfs_diskless: no NFS handle\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fhlen != nd3->root_fhsize) {
|
|
|
|
printf("nfs_diskless: bad NFS handle len=%d\n", fhlen);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-16 18:04:43 +00:00
|
|
|
if ((cp = kern_getenv("boot.nfsroot.path")) != NULL) {
|
2010-09-01 23:51:07 +00:00
|
|
|
strncpy(nd3->root_hostnam, cp, MNAMELEN - 1);
|
|
|
|
freeenv(cp);
|
|
|
|
}
|
2014-10-16 18:04:43 +00:00
|
|
|
if ((cp = kern_getenv("boot.nfsroot.options")) != NULL) {
|
2010-09-01 23:51:07 +00:00
|
|
|
nfs_parse_options(cp, &nd3->root_args);
|
|
|
|
freeenv(cp);
|
|
|
|
}
|
2020-09-01 21:25:39 +00:00
|
|
|
|
2010-09-01 23:51:07 +00:00
|
|
|
nfs_diskless_valid = 3;
|
|
|
|
} else {
|
|
|
|
strlcpy(nd->myif.ifra_name, ifp->if_xname,
|
|
|
|
sizeof(nd->myif.ifra_name));
|
2020-09-01 21:25:39 +00:00
|
|
|
|
2010-09-01 23:51:07 +00:00
|
|
|
/* set up gateway */
|
|
|
|
inaddr_to_sockaddr("boot.netif.gateway", &nd->mygateway);
|
2006-12-06 02:15:25 +00:00
|
|
|
|
2010-09-01 23:51:07 +00:00
|
|
|
/* set up root mount */
|
|
|
|
nd->root_args.rsize = 8192; /* XXX tunable? */
|
|
|
|
nd->root_args.wsize = 8192;
|
|
|
|
nd->root_args.sotype = SOCK_STREAM;
|
|
|
|
nd->root_args.flags = (NFSMNT_WSIZE |
|
|
|
|
NFSMNT_RSIZE | NFSMNT_RESVPORT);
|
|
|
|
if (inaddr_to_sockaddr("boot.nfsroot.server",
|
|
|
|
&nd->root_saddr)) {
|
|
|
|
printf("nfs_diskless: no server\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nd->root_saddr.sin_port = htons(NFS_PORT);
|
|
|
|
if (decode_nfshandle("boot.nfsroot.nfshandle",
|
|
|
|
&nd->root_fh[0], NFSX_V2FH) == 0) {
|
|
|
|
printf("nfs_diskless: no NFS handle\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-10-16 18:04:43 +00:00
|
|
|
if ((cp = kern_getenv("boot.nfsroot.path")) != NULL) {
|
2010-09-01 23:51:07 +00:00
|
|
|
strncpy(nd->root_hostnam, cp, MNAMELEN - 1);
|
|
|
|
freeenv(cp);
|
|
|
|
}
|
2014-10-16 18:04:43 +00:00
|
|
|
if ((cp = kern_getenv("boot.nfsroot.options")) != NULL) {
|
2010-09-01 23:51:07 +00:00
|
|
|
struct nfs_args args;
|
2020-09-01 21:25:39 +00:00
|
|
|
|
2010-09-01 23:51:07 +00:00
|
|
|
/*
|
|
|
|
* XXX yech, convert between old and current
|
|
|
|
* arg format
|
|
|
|
*/
|
|
|
|
args.flags = nd->root_args.flags;
|
|
|
|
args.sotype = nd->root_args.sotype;
|
|
|
|
args.rsize = nd->root_args.rsize;
|
|
|
|
args.wsize = nd->root_args.wsize;
|
|
|
|
nfs_parse_options(cp, &args);
|
|
|
|
nd->root_args.flags = args.flags;
|
|
|
|
nd->root_args.sotype = args.sotype;
|
|
|
|
nd->root_args.rsize = args.rsize;
|
|
|
|
nd->root_args.wsize = args.wsize;
|
|
|
|
freeenv(cp);
|
|
|
|
}
|
2020-09-01 21:25:39 +00:00
|
|
|
|
2010-09-01 23:51:07 +00:00
|
|
|
nfs_diskless_valid = 1;
|
2005-10-06 11:18:34 +00:00
|
|
|
}
|
2002-09-22 00:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
inaddr_to_sockaddr(char *ev, struct sockaddr_in *sa)
|
|
|
|
{
|
|
|
|
u_int32_t a[4];
|
|
|
|
char *cp;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
bzero(sa, sizeof(*sa));
|
|
|
|
sa->sin_len = sizeof(*sa);
|
|
|
|
sa->sin_family = AF_INET;
|
|
|
|
|
2014-10-16 18:04:43 +00:00
|
|
|
if ((cp = kern_getenv(ev)) == NULL)
|
2002-09-22 00:59:02 +00:00
|
|
|
return (1);
|
|
|
|
count = sscanf(cp, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
|
|
|
|
freeenv(cp);
|
|
|
|
if (count != 4)
|
|
|
|
return (1);
|
|
|
|
sa->sin_addr.s_addr =
|
|
|
|
htonl((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hwaddr_to_sockaddr(char *ev, struct sockaddr_dl *sa)
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
u_int32_t a[6];
|
|
|
|
int count;
|
|
|
|
|
|
|
|
bzero(sa, sizeof(*sa));
|
|
|
|
sa->sdl_len = sizeof(*sa);
|
|
|
|
sa->sdl_family = AF_LINK;
|
|
|
|
sa->sdl_type = IFT_ETHER;
|
|
|
|
sa->sdl_alen = ETHER_ADDR_LEN;
|
2014-10-16 18:04:43 +00:00
|
|
|
if ((cp = kern_getenv(ev)) == NULL)
|
2002-09-22 00:59:02 +00:00
|
|
|
return (1);
|
|
|
|
count = sscanf(cp, "%x:%x:%x:%x:%x:%x",
|
|
|
|
&a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
|
|
|
|
freeenv(cp);
|
|
|
|
if (count != 6)
|
|
|
|
return (1);
|
|
|
|
sa->sdl_data[0] = a[0];
|
|
|
|
sa->sdl_data[1] = a[1];
|
|
|
|
sa->sdl_data[2] = a[2];
|
|
|
|
sa->sdl_data[3] = a[3];
|
|
|
|
sa->sdl_data[4] = a[4];
|
|
|
|
sa->sdl_data[5] = a[5];
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-09-01 23:51:07 +00:00
|
|
|
decode_nfshandle(char *ev, u_char *fh, int maxfh)
|
2002-09-22 00:59:02 +00:00
|
|
|
{
|
|
|
|
u_char *cp, *ep;
|
|
|
|
int len, val;
|
|
|
|
|
2014-10-16 18:04:43 +00:00
|
|
|
ep = cp = kern_getenv(ev);
|
2002-09-22 00:59:02 +00:00
|
|
|
if (cp == NULL)
|
|
|
|
return (0);
|
|
|
|
if ((strlen(cp) < 2) || (*cp != 'X')) {
|
|
|
|
freeenv(ep);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
len = 0;
|
|
|
|
cp++;
|
|
|
|
for (;;) {
|
|
|
|
if (*cp == 'X') {
|
|
|
|
freeenv(ep);
|
|
|
|
return (len);
|
|
|
|
}
|
|
|
|
if ((sscanf(cp, "%2x", &val) != 1) || (val > 0xff)) {
|
|
|
|
freeenv(ep);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
*(fh++) = val;
|
|
|
|
len++;
|
|
|
|
cp += 2;
|
2010-09-01 23:51:07 +00:00
|
|
|
if (len > maxfh) {
|
2002-09-22 00:59:02 +00:00
|
|
|
freeenv(ep);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-28 21:54:57 +00:00
|
|
|
|
|
|
|
#if !defined(BOOTP_NFSROOT)
|
|
|
|
static void
|
|
|
|
nfs_rootconf(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
nfs_setup_diskless();
|
|
|
|
if (nfs_diskless_valid)
|
|
|
|
rootdevnames[0] = "nfs:";
|
|
|
|
}
|
|
|
|
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, nfs_rootconf, NULL);
|
2004-07-28 21:54:57 +00:00
|
|
|
#endif
|