Home | History | Annotate | Line # | Download | only in common
nfs_diskless.c revision 1.1.1.1.12.1
      1  1.1.1.1.12.1     skrll /*	$NetBSD: nfs_diskless.c,v 1.1.1.1.12.1 2016/12/05 10:55:25 skrll Exp $	*/
      2           1.1  dholland /*-
      3           1.1  dholland  * Copyright (c) 1990 The Regents of the University of California.
      4           1.1  dholland  * All rights reserved.
      5           1.1  dholland  *
      6           1.1  dholland  * This code is derived from software contributed to Berkeley by
      7           1.1  dholland  * William Jolitz.
      8           1.1  dholland  *
      9           1.1  dholland  * Redistribution and use in source and binary forms, with or without
     10           1.1  dholland  * modification, are permitted provided that the following conditions
     11           1.1  dholland  * are met:
     12           1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     13           1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     14           1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     15           1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     16           1.1  dholland  *    documentation and/or other materials provided with the distribution.
     17           1.1  dholland  * 4. Neither the name of the University nor the names of its contributors
     18           1.1  dholland  *    may be used to endorse or promote products derived from this software
     19           1.1  dholland  *    without specific prior written permission.
     20           1.1  dholland  *
     21           1.1  dholland  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22           1.1  dholland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23           1.1  dholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24           1.1  dholland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25           1.1  dholland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26           1.1  dholland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27           1.1  dholland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28           1.1  dholland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29           1.1  dholland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30           1.1  dholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31           1.1  dholland  * SUCH DAMAGE.
     32           1.1  dholland  *
     33           1.1  dholland  *	from: @(#)autoconf.c	7.1 (Berkeley) 5/9/91
     34           1.1  dholland  */
     35           1.1  dholland 
     36           1.1  dholland #include <sys/cdefs.h>
     37  1.1.1.1.12.1     skrll /* __FBSDID("FreeBSD: head/sys/nfs/nfs_diskless.c 297086 2016-03-20 21:48:26Z ian "); */
     38  1.1.1.1.12.1     skrll __RCSID("$NetBSD: nfs_diskless.c,v 1.1.1.1.12.1 2016/12/05 10:55:25 skrll Exp $");
     39           1.1  dholland 
     40           1.1  dholland #include "opt_bootp.h"
     41           1.1  dholland 
     42           1.1  dholland #include <sys/param.h>
     43           1.1  dholland #include <sys/systm.h>
     44           1.1  dholland #include <sys/jail.h>
     45           1.1  dholland #include <sys/kernel.h>
     46           1.1  dholland #include <sys/malloc.h>
     47           1.1  dholland #include <sys/mount.h>
     48           1.1  dholland #include <sys/socket.h>
     49           1.1  dholland 
     50           1.1  dholland #include <net/if.h>
     51           1.1  dholland #include <net/if_dl.h>
     52           1.1  dholland #include <net/if_types.h>
     53           1.1  dholland #include <net/if_var.h>
     54           1.1  dholland #include <net/ethernet.h>
     55           1.1  dholland #include <net/vnet.h>
     56           1.1  dholland 
     57           1.1  dholland #include <netinet/in.h>
     58           1.1  dholland #include <nfs/nfsproto.h>
     59           1.1  dholland #include <nfsclient/nfs.h>
     60           1.1  dholland #include <nfs/nfsdiskless.h>
     61           1.1  dholland 
     62  1.1.1.1.12.1     skrll #define	NFS_IFACE_TIMEOUT_SECS	10 /* Timeout for interface to appear. */
     63  1.1.1.1.12.1     skrll 
     64           1.1  dholland static int inaddr_to_sockaddr(char *ev, struct sockaddr_in *sa);
     65           1.1  dholland static int hwaddr_to_sockaddr(char *ev, struct sockaddr_dl *sa);
     66           1.1  dholland static int decode_nfshandle(char *ev, u_char *fh, int maxfh);
     67           1.1  dholland 
     68           1.1  dholland /*
     69           1.1  dholland  * This structure must be filled in by a primary bootstrap or bootstrap
     70           1.1  dholland  * server for a diskless/dataless machine. It is initialized below just
     71           1.1  dholland  * to ensure that it is allocated to initialized data (.data not .bss).
     72           1.1  dholland  */
     73           1.1  dholland struct nfs_diskless	nfs_diskless = { { { 0 } } };
     74           1.1  dholland struct nfsv3_diskless	nfsv3_diskless = { { { 0 } } };
     75           1.1  dholland int			nfs_diskless_valid = 0;
     76           1.1  dholland 
     77           1.1  dholland /*
     78           1.1  dholland  * Validate/sanity check a rsize/wsize parameter.
     79           1.1  dholland  */
     80           1.1  dholland static int
     81           1.1  dholland checkrwsize(unsigned long v, const char *name)
     82           1.1  dholland {
     83           1.1  dholland 	/*
     84           1.1  dholland 	 * 32K is used as an upper bound because most servers
     85           1.1  dholland 	 * limit block size to satisfy IPv4's limit of
     86           1.1  dholland 	 * 64K/reassembled packet.  The lower bound is pretty
     87           1.1  dholland 	 * much arbitrary.
     88           1.1  dholland 	 */
     89           1.1  dholland 	if (!(4 <= v && v <= 32*1024)) {
     90           1.1  dholland 		printf("nfs_parse_options: invalid %s %lu ignored\n", name, v);
     91           1.1  dholland 		return 0;
     92           1.1  dholland 	} else
     93           1.1  dholland 		return 1;
     94           1.1  dholland }
     95           1.1  dholland 
     96           1.1  dholland /*
     97           1.1  dholland  * Parse mount options and apply them to the supplied
     98           1.1  dholland  * nfs_diskless state.  Used also by bootp/dhcp support.
     99           1.1  dholland  */
    100           1.1  dholland void
    101           1.1  dholland nfs_parse_options(const char *envopts, struct nfs_args *nd)
    102           1.1  dholland {
    103           1.1  dholland 	char *opts, *o, *otmp;
    104           1.1  dholland 	unsigned long v;
    105           1.1  dholland 
    106           1.1  dholland 	opts = strdup(envopts, M_TEMP);
    107           1.1  dholland 	otmp = opts;
    108           1.1  dholland 	while ((o = strsep(&otmp, ":;, ")) != NULL) {
    109           1.1  dholland 		if (*o == '\0')
    110           1.1  dholland 			; /* Skip empty options. */
    111           1.1  dholland 		else if (strcmp(o, "soft") == 0)
    112           1.1  dholland 			nd->flags |= NFSMNT_SOFT;
    113           1.1  dholland 		else if (strcmp(o, "intr") == 0)
    114           1.1  dholland 			nd->flags |= NFSMNT_INT;
    115           1.1  dholland 		else if (strcmp(o, "conn") == 0)
    116           1.1  dholland 			nd->flags |= NFSMNT_NOCONN;
    117           1.1  dholland 		else if (strcmp(o, "nolockd") == 0)
    118           1.1  dholland 			nd->flags |= NFSMNT_NOLOCKD;
    119           1.1  dholland 		else if (strcmp(o, "nocto") == 0)
    120           1.1  dholland 			nd->flags |= NFSMNT_NOCTO;
    121           1.1  dholland 		else if (strcmp(o, "nfsv2") == 0)
    122           1.1  dholland 			nd->flags &= ~(NFSMNT_NFSV3 | NFSMNT_NFSV4);
    123           1.1  dholland 		else if (strcmp(o, "nfsv3") == 0) {
    124           1.1  dholland 			nd->flags &= ~NFSMNT_NFSV4;
    125           1.1  dholland 			nd->flags |= NFSMNT_NFSV3;
    126           1.1  dholland 		} else if (strcmp(o, "tcp") == 0)
    127           1.1  dholland 			nd->sotype = SOCK_STREAM;
    128           1.1  dholland 		else if (strcmp(o, "udp") == 0)
    129           1.1  dholland 			nd->sotype = SOCK_DGRAM;
    130           1.1  dholland 		else if (strncmp(o, "rsize=", 6) == 0) {
    131           1.1  dholland 			v = strtoul(o+6, NULL, 10);
    132           1.1  dholland 			if (checkrwsize(v, "rsize")) {
    133           1.1  dholland 				nd->rsize = (int) v;
    134           1.1  dholland 				nd->flags |= NFSMNT_RSIZE;
    135           1.1  dholland 			}
    136           1.1  dholland 		} else if (strncmp(o, "wsize=", 6) == 0) {
    137           1.1  dholland 			v = strtoul(o+6, NULL, 10);
    138           1.1  dholland 			if (checkrwsize(v, "wsize")) {
    139           1.1  dholland 				nd->wsize = (int) v;
    140           1.1  dholland 				nd->flags |= NFSMNT_WSIZE;
    141           1.1  dholland 			}
    142           1.1  dholland 		} else
    143           1.1  dholland 			printf("%s: skipping unknown option \"%s\"\n",
    144           1.1  dholland 			    __func__, o);
    145           1.1  dholland 	}
    146           1.1  dholland 	free(opts, M_TEMP);
    147           1.1  dholland }
    148           1.1  dholland 
    149           1.1  dholland /*
    150           1.1  dholland  * Populate the essential fields in the nfsv3_diskless structure.
    151           1.1  dholland  *
    152           1.1  dholland  * The loader is expected to export the following environment variables:
    153           1.1  dholland  *
    154           1.1  dholland  * boot.netif.name		name of boot interface
    155           1.1  dholland  * boot.netif.ip		IP address on boot interface
    156           1.1  dholland  * boot.netif.netmask		netmask on boot interface
    157           1.1  dholland  * boot.netif.gateway		default gateway (optional)
    158           1.1  dholland  * boot.netif.hwaddr		hardware address of boot interface
    159  1.1.1.1.12.1     skrll  * boot.netif.mtu		interface mtu from bootp/dhcp (optional)
    160           1.1  dholland  * boot.nfsroot.server		IP address of root filesystem server
    161           1.1  dholland  * boot.nfsroot.path		path of the root filesystem on server
    162           1.1  dholland  * boot.nfsroot.nfshandle	NFS handle for root filesystem on server
    163           1.1  dholland  * boot.nfsroot.nfshandlelen	and length of this handle (for NFSv3 only)
    164           1.1  dholland  * boot.nfsroot.options		NFS options for the root filesystem
    165           1.1  dholland  */
    166           1.1  dholland void
    167           1.1  dholland nfs_setup_diskless(void)
    168           1.1  dholland {
    169           1.1  dholland 	struct nfs_diskless *nd = &nfs_diskless;
    170           1.1  dholland 	struct nfsv3_diskless *nd3 = &nfsv3_diskless;
    171           1.1  dholland 	struct ifnet *ifp;
    172           1.1  dholland 	struct ifaddr *ifa;
    173           1.1  dholland 	struct sockaddr_dl *sdl, ourdl;
    174           1.1  dholland 	struct sockaddr_in myaddr, netmask;
    175           1.1  dholland 	char *cp;
    176           1.1  dholland 	int cnt, fhlen, is_nfsv3;
    177           1.1  dholland 	uint32_t len;
    178  1.1.1.1.12.1     skrll 	time_t timeout_at;
    179           1.1  dholland 
    180           1.1  dholland 	if (nfs_diskless_valid != 0)
    181           1.1  dholland 		return;
    182           1.1  dholland 
    183           1.1  dholland 	/* get handle size. If this succeeds, it's an NFSv3 setup. */
    184  1.1.1.1.12.1     skrll 	if ((cp = kern_getenv("boot.nfsroot.nfshandlelen")) != NULL) {
    185           1.1  dholland 		cnt = sscanf(cp, "%d", &len);
    186           1.1  dholland 		freeenv(cp);
    187           1.1  dholland 		if (cnt != 1 || len == 0 || len > NFSX_V3FHMAX) {
    188           1.1  dholland 			printf("nfs_diskless: bad NFS handle len\n");
    189           1.1  dholland 			return;
    190           1.1  dholland 		}
    191           1.1  dholland 		nd3->root_fhsize = len;
    192           1.1  dholland 		is_nfsv3 = 1;
    193           1.1  dholland 	} else
    194           1.1  dholland 		is_nfsv3 = 0;
    195           1.1  dholland 	/* set up interface */
    196           1.1  dholland 	if (inaddr_to_sockaddr("boot.netif.ip", &myaddr))
    197           1.1  dholland 		return;
    198           1.1  dholland 	if (inaddr_to_sockaddr("boot.netif.netmask", &netmask)) {
    199           1.1  dholland 		printf("nfs_diskless: no netmask\n");
    200           1.1  dholland 		return;
    201           1.1  dholland 	}
    202           1.1  dholland 	if (is_nfsv3 != 0) {
    203           1.1  dholland 		bcopy(&myaddr, &nd3->myif.ifra_addr, sizeof(myaddr));
    204           1.1  dholland 		bcopy(&myaddr, &nd3->myif.ifra_broadaddr, sizeof(myaddr));
    205           1.1  dholland 		((struct sockaddr_in *)
    206           1.1  dholland 		   &nd3->myif.ifra_broadaddr)->sin_addr.s_addr =
    207           1.1  dholland 		    myaddr.sin_addr.s_addr | ~ netmask.sin_addr.s_addr;
    208           1.1  dholland 		bcopy(&netmask, &nd3->myif.ifra_mask, sizeof(netmask));
    209           1.1  dholland 	} else {
    210           1.1  dholland 		bcopy(&myaddr, &nd->myif.ifra_addr, sizeof(myaddr));
    211           1.1  dholland 		bcopy(&myaddr, &nd->myif.ifra_broadaddr, sizeof(myaddr));
    212           1.1  dholland 		((struct sockaddr_in *)
    213           1.1  dholland 		   &nd->myif.ifra_broadaddr)->sin_addr.s_addr =
    214           1.1  dholland 		    myaddr.sin_addr.s_addr | ~ netmask.sin_addr.s_addr;
    215           1.1  dholland 		bcopy(&netmask, &nd->myif.ifra_mask, sizeof(netmask));
    216           1.1  dholland 	}
    217           1.1  dholland 
    218           1.1  dholland 	if (hwaddr_to_sockaddr("boot.netif.hwaddr", &ourdl)) {
    219           1.1  dholland 		printf("nfs_diskless: no hardware address\n");
    220           1.1  dholland 		return;
    221           1.1  dholland 	}
    222           1.1  dholland 	ifa = NULL;
    223  1.1.1.1.12.1     skrll 	timeout_at = time_uptime + NFS_IFACE_TIMEOUT_SECS;
    224  1.1.1.1.12.1     skrll retry:
    225           1.1  dholland 	CURVNET_SET(TD_TO_VNET(curthread));
    226           1.1  dholland 	IFNET_RLOCK();
    227           1.1  dholland 	TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
    228           1.1  dholland 		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
    229           1.1  dholland 			if (ifa->ifa_addr->sa_family == AF_LINK) {
    230           1.1  dholland 				sdl = (struct sockaddr_dl *)ifa->ifa_addr;
    231           1.1  dholland 				if ((sdl->sdl_type == ourdl.sdl_type) &&
    232           1.1  dholland 				    (sdl->sdl_alen == ourdl.sdl_alen) &&
    233           1.1  dholland 				    !bcmp(LLADDR(sdl),
    234           1.1  dholland 					  LLADDR(&ourdl),
    235           1.1  dholland 					  sdl->sdl_alen)) {
    236           1.1  dholland 				    IFNET_RUNLOCK();
    237           1.1  dholland 				    CURVNET_RESTORE();
    238           1.1  dholland 				    goto match_done;
    239           1.1  dholland 				}
    240           1.1  dholland 			}
    241           1.1  dholland 		}
    242           1.1  dholland 	}
    243           1.1  dholland 	IFNET_RUNLOCK();
    244           1.1  dholland 	CURVNET_RESTORE();
    245  1.1.1.1.12.1     skrll 	if (time_uptime < timeout_at) {
    246  1.1.1.1.12.1     skrll 		pause("nfssdl", hz / 5);
    247  1.1.1.1.12.1     skrll 		goto retry;
    248  1.1.1.1.12.1     skrll 	}
    249           1.1  dholland 	printf("nfs_diskless: no interface\n");
    250           1.1  dholland 	return;	/* no matching interface */
    251           1.1  dholland match_done:
    252  1.1.1.1.12.1     skrll 	kern_setenv("boot.netif.name", ifp->if_xname);
    253           1.1  dholland 	if (is_nfsv3 != 0) {
    254           1.1  dholland 		strlcpy(nd3->myif.ifra_name, ifp->if_xname,
    255           1.1  dholland 		    sizeof(nd3->myif.ifra_name));
    256           1.1  dholland 
    257           1.1  dholland 		/* set up gateway */
    258           1.1  dholland 		inaddr_to_sockaddr("boot.netif.gateway", &nd3->mygateway);
    259           1.1  dholland 
    260           1.1  dholland 		/* set up root mount */
    261           1.1  dholland 		nd3->root_args.rsize = 32768;		/* XXX tunable? */
    262           1.1  dholland 		nd3->root_args.wsize = 32768;
    263           1.1  dholland 		nd3->root_args.sotype = SOCK_STREAM;
    264           1.1  dholland 		nd3->root_args.flags = (NFSMNT_NFSV3 | NFSMNT_WSIZE |
    265           1.1  dholland 		    NFSMNT_RSIZE | NFSMNT_RESVPORT);
    266           1.1  dholland 		if (inaddr_to_sockaddr("boot.nfsroot.server",
    267           1.1  dholland 		    &nd3->root_saddr)) {
    268           1.1  dholland 			printf("nfs_diskless: no server\n");
    269           1.1  dholland 			return;
    270           1.1  dholland 		}
    271           1.1  dholland 		nd3->root_saddr.sin_port = htons(NFS_PORT);
    272           1.1  dholland 		fhlen = decode_nfshandle("boot.nfsroot.nfshandle",
    273           1.1  dholland 		    &nd3->root_fh[0], NFSX_V3FHMAX);
    274           1.1  dholland 		if (fhlen == 0) {
    275           1.1  dholland 			printf("nfs_diskless: no NFS handle\n");
    276           1.1  dholland 			return;
    277           1.1  dholland 		}
    278           1.1  dholland 		if (fhlen != nd3->root_fhsize) {
    279           1.1  dholland 			printf("nfs_diskless: bad NFS handle len=%d\n", fhlen);
    280           1.1  dholland 			return;
    281           1.1  dholland 		}
    282  1.1.1.1.12.1     skrll 		if ((cp = kern_getenv("boot.nfsroot.path")) != NULL) {
    283           1.1  dholland 			strncpy(nd3->root_hostnam, cp, MNAMELEN - 1);
    284           1.1  dholland 			freeenv(cp);
    285           1.1  dholland 		}
    286  1.1.1.1.12.1     skrll 		if ((cp = kern_getenv("boot.nfsroot.options")) != NULL) {
    287           1.1  dholland 			nfs_parse_options(cp, &nd3->root_args);
    288           1.1  dholland 			freeenv(cp);
    289           1.1  dholland 		}
    290           1.1  dholland 
    291           1.1  dholland 		nfs_diskless_valid = 3;
    292           1.1  dholland 	} else {
    293           1.1  dholland 		strlcpy(nd->myif.ifra_name, ifp->if_xname,
    294           1.1  dholland 		    sizeof(nd->myif.ifra_name));
    295           1.1  dholland 
    296           1.1  dholland 		/* set up gateway */
    297           1.1  dholland 		inaddr_to_sockaddr("boot.netif.gateway", &nd->mygateway);
    298           1.1  dholland 
    299           1.1  dholland 		/* set up root mount */
    300           1.1  dholland 		nd->root_args.rsize = 8192;		/* XXX tunable? */
    301           1.1  dholland 		nd->root_args.wsize = 8192;
    302           1.1  dholland 		nd->root_args.sotype = SOCK_STREAM;
    303           1.1  dholland 		nd->root_args.flags = (NFSMNT_WSIZE |
    304           1.1  dholland 		    NFSMNT_RSIZE | NFSMNT_RESVPORT);
    305           1.1  dholland 		if (inaddr_to_sockaddr("boot.nfsroot.server",
    306           1.1  dholland 		    &nd->root_saddr)) {
    307           1.1  dholland 			printf("nfs_diskless: no server\n");
    308           1.1  dholland 			return;
    309           1.1  dholland 		}
    310           1.1  dholland 		nd->root_saddr.sin_port = htons(NFS_PORT);
    311           1.1  dholland 		if (decode_nfshandle("boot.nfsroot.nfshandle",
    312           1.1  dholland 		    &nd->root_fh[0], NFSX_V2FH) == 0) {
    313           1.1  dholland 			printf("nfs_diskless: no NFS handle\n");
    314           1.1  dholland 			return;
    315           1.1  dholland 		}
    316  1.1.1.1.12.1     skrll 		if ((cp = kern_getenv("boot.nfsroot.path")) != NULL) {
    317           1.1  dholland 			strncpy(nd->root_hostnam, cp, MNAMELEN - 1);
    318           1.1  dholland 			freeenv(cp);
    319           1.1  dholland 		}
    320  1.1.1.1.12.1     skrll 		if ((cp = kern_getenv("boot.nfsroot.options")) != NULL) {
    321           1.1  dholland 			struct nfs_args args;
    322           1.1  dholland 
    323           1.1  dholland 			/*
    324           1.1  dholland 			 * XXX yech, convert between old and current
    325           1.1  dholland 			 * arg format
    326           1.1  dholland 			 */
    327           1.1  dholland 			args.flags = nd->root_args.flags;
    328           1.1  dholland 			args.sotype = nd->root_args.sotype;
    329           1.1  dholland 			args.rsize = nd->root_args.rsize;
    330           1.1  dholland 			args.wsize = nd->root_args.wsize;
    331           1.1  dholland 			nfs_parse_options(cp, &args);
    332           1.1  dholland 			nd->root_args.flags = args.flags;
    333           1.1  dholland 			nd->root_args.sotype = args.sotype;
    334           1.1  dholland 			nd->root_args.rsize = args.rsize;
    335           1.1  dholland 			nd->root_args.wsize = args.wsize;
    336           1.1  dholland 			freeenv(cp);
    337           1.1  dholland 		}
    338           1.1  dholland 
    339           1.1  dholland 		nfs_diskless_valid = 1;
    340           1.1  dholland 	}
    341           1.1  dholland }
    342           1.1  dholland 
    343           1.1  dholland static int
    344           1.1  dholland inaddr_to_sockaddr(char *ev, struct sockaddr_in *sa)
    345           1.1  dholland {
    346           1.1  dholland 	u_int32_t a[4];
    347           1.1  dholland 	char *cp;
    348           1.1  dholland 	int count;
    349           1.1  dholland 
    350           1.1  dholland 	bzero(sa, sizeof(*sa));
    351           1.1  dholland 	sa->sin_len = sizeof(*sa);
    352           1.1  dholland 	sa->sin_family = AF_INET;
    353           1.1  dholland 
    354  1.1.1.1.12.1     skrll 	if ((cp = kern_getenv(ev)) == NULL)
    355           1.1  dholland 		return (1);
    356           1.1  dholland 	count = sscanf(cp, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
    357           1.1  dholland 	freeenv(cp);
    358           1.1  dholland 	if (count != 4)
    359           1.1  dholland 		return (1);
    360           1.1  dholland 	sa->sin_addr.s_addr =
    361           1.1  dholland 	    htonl((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]);
    362           1.1  dholland 	return (0);
    363           1.1  dholland }
    364           1.1  dholland 
    365           1.1  dholland static int
    366           1.1  dholland hwaddr_to_sockaddr(char *ev, struct sockaddr_dl *sa)
    367           1.1  dholland {
    368           1.1  dholland 	char *cp;
    369           1.1  dholland 	u_int32_t a[6];
    370           1.1  dholland 	int count;
    371           1.1  dholland 
    372           1.1  dholland 	bzero(sa, sizeof(*sa));
    373           1.1  dholland 	sa->sdl_len = sizeof(*sa);
    374           1.1  dholland 	sa->sdl_family = AF_LINK;
    375           1.1  dholland 	sa->sdl_type = IFT_ETHER;
    376           1.1  dholland 	sa->sdl_alen = ETHER_ADDR_LEN;
    377  1.1.1.1.12.1     skrll 	if ((cp = kern_getenv(ev)) == NULL)
    378           1.1  dholland 		return (1);
    379           1.1  dholland 	count = sscanf(cp, "%x:%x:%x:%x:%x:%x",
    380           1.1  dholland 	    &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
    381           1.1  dholland 	freeenv(cp);
    382           1.1  dholland 	if (count != 6)
    383           1.1  dholland 		return (1);
    384           1.1  dholland 	sa->sdl_data[0] = a[0];
    385           1.1  dholland 	sa->sdl_data[1] = a[1];
    386           1.1  dholland 	sa->sdl_data[2] = a[2];
    387           1.1  dholland 	sa->sdl_data[3] = a[3];
    388           1.1  dholland 	sa->sdl_data[4] = a[4];
    389           1.1  dholland 	sa->sdl_data[5] = a[5];
    390           1.1  dholland 	return (0);
    391           1.1  dholland }
    392           1.1  dholland 
    393           1.1  dholland static int
    394           1.1  dholland decode_nfshandle(char *ev, u_char *fh, int maxfh)
    395           1.1  dholland {
    396           1.1  dholland 	u_char *cp, *ep;
    397           1.1  dholland 	int len, val;
    398           1.1  dholland 
    399  1.1.1.1.12.1     skrll 	ep = cp = kern_getenv(ev);
    400           1.1  dholland 	if (cp == NULL)
    401           1.1  dholland 		return (0);
    402           1.1  dholland 	if ((strlen(cp) < 2) || (*cp != 'X')) {
    403           1.1  dholland 		freeenv(ep);
    404           1.1  dholland 		return (0);
    405           1.1  dholland 	}
    406           1.1  dholland 	len = 0;
    407           1.1  dholland 	cp++;
    408           1.1  dholland 	for (;;) {
    409           1.1  dholland 		if (*cp == 'X') {
    410           1.1  dholland 			freeenv(ep);
    411           1.1  dholland 			return (len);
    412           1.1  dholland 		}
    413           1.1  dholland 		if ((sscanf(cp, "%2x", &val) != 1) || (val > 0xff)) {
    414           1.1  dholland 			freeenv(ep);
    415           1.1  dholland 			return (0);
    416           1.1  dholland 		}
    417           1.1  dholland 		*(fh++) = val;
    418           1.1  dholland 		len++;
    419           1.1  dholland 		cp += 2;
    420           1.1  dholland 		if (len > maxfh) {
    421           1.1  dholland 		    freeenv(ep);
    422           1.1  dholland 		    return (0);
    423           1.1  dholland 		}
    424           1.1  dholland 	}
    425           1.1  dholland }
    426           1.1  dholland 
    427           1.1  dholland #if !defined(BOOTP_NFSROOT)
    428           1.1  dholland static void
    429           1.1  dholland nfs_rootconf(void)
    430           1.1  dholland {
    431           1.1  dholland 
    432           1.1  dholland 	nfs_setup_diskless();
    433           1.1  dholland 	if (nfs_diskless_valid)
    434           1.1  dholland 		rootdevnames[0] = "nfs:";
    435           1.1  dholland }
    436           1.1  dholland 
    437           1.1  dholland SYSINIT(cpu_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, nfs_rootconf, NULL);
    438           1.1  dholland #endif
    439           1.1  dholland 
    440