From owner-svn-src-all@FreeBSD.ORG Mon May 18 15:46:44 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EAB4811F; Mon, 18 May 2015 15:46:44 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CB9D81A8A; Mon, 18 May 2015 15:46:44 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t4IFkij4068565; Mon, 18 May 2015 15:46:44 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t4IFkiDo068563; Mon, 18 May 2015 15:46:44 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201505181546.t4IFkiDo068563@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 18 May 2015 15:46:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r283062 - head/sys/boot/common X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 May 2015 15:46:45 -0000 Author: ian Date: Mon May 18 15:46:43 2015 New Revision: 283062 URL: https://svnweb.freebsd.org/changeset/base/283062 Log: Refactor net_getparams() to make it easier to get params from sources other than bootp and rarp. The code which splits a serverip:/rootpath string into rootip and a plain pathname is now a separate net_parse_rootpath() function that can be called by others. The code that sets the kernel env vars needed for nfs_diskless is moved into net_open() so that the variables get set no matter where the params came from. There was already code in net_open() that allowed for the possibility that some other entity has set up the network-related global variables. It uses the rootip variable as the key, assuming that if it is set all the other required variables are set too. These changes don't alter the existing behavior, they just make it easier to actually write some new code to get the params from another source (such as the U-Boot environment). Modified: head/sys/boot/common/dev_net.c head/sys/boot/common/dev_net.h Modified: head/sys/boot/common/dev_net.c ============================================================================== --- head/sys/boot/common/dev_net.c Mon May 18 15:05:12 2015 (r283061) +++ head/sys/boot/common/dev_net.c Mon May 18 15:46:43 2015 (r283062) @@ -111,6 +111,8 @@ net_init(void) static int net_open(struct open_file *f, ...) { + char temp[FNAME_SIZE]; + struct iodesc *d; va_list args; char *devname; /* Device part of file name (or NULL). */ int error = 0; @@ -140,6 +142,10 @@ net_open(struct open_file *f, ...) printf("net_open: netif_open() succeeded\n"); #endif } + /* + * If network params were not set by netif_open(), try to get + * them via bootp, rarp, etc. + */ if (rootip.s_addr == 0) { /* Get root IP address, and path, etc. */ error = net_getparams(netdev_sock); @@ -151,6 +157,20 @@ net_open(struct open_file *f, ...) return (error); } } + /* + * Set the variables required by the kernel's nfs_diskless + * mechanism. This is the minimum set of variables required to + * mount a root filesystem without needing to obtain additional + * info from bootp or other sources. + */ + d = socktodesc(netdev_sock); + sprintf(temp, "%6D", d->myea, ":"); + setenv("boot.netif.hwaddr", temp, 1); + setenv("boot.netif.ip", inet_ntoa(myip), 1); + setenv("boot.netif.netmask", intoa(netmask), 1); + setenv("boot.netif.gateway", inet_ntoa(gateip), 1); + setenv("boot.nfsroot.server", inet_ntoa(rootip), 1); + setenv("boot.nfsroot.path", rootpath, 1); } netdev_opens++; f->f_devdata = &netdev_sock; @@ -232,10 +252,7 @@ static int net_getparams(int sock) { char buf[MAXHOSTNAMELEN]; - char temp[FNAME_SIZE]; - struct iodesc *d; - int i; - n_long smask; + n_long rootaddr, smask; #ifdef SUPPORT_BOOTP /* @@ -302,21 +319,9 @@ net_getparams(int sock) return (EIO); } exit: - /* - * If present, strip the server's address off of the rootpath - * before passing it along. This allows us to be compatible with - * the kernel's diskless (BOOTP_NFSROOT) booting conventions - */ - for (i = 0; rootpath[i] != '\0' && i < FNAME_SIZE; i++) - if (rootpath[i] == ':') - break; - if (i && i != FNAME_SIZE && rootpath[i] == ':') { - rootpath[i++] = '\0'; - if (inet_addr(&rootpath[0]) != INADDR_NONE) - rootip.s_addr = inet_addr(&rootpath[0]); - bcopy(&rootpath[i], &temp[0], strlen(&rootpath[i])+1); - bcopy(&temp[0], &rootpath[0], strlen(&rootpath[i])+1); - } + if ((rootaddr = net_parse_rootpath()) != INADDR_NONE) + rootip.s_addr = rootaddr; + #ifdef NETIF_DEBUG if (debug) { printf("net_open: server addr: %s\n", inet_ntoa(rootip)); @@ -324,15 +329,6 @@ exit: } #endif - d = socktodesc(sock); - sprintf(temp, "%6D", d->myea, ":"); - setenv("boot.netif.ip", inet_ntoa(myip), 1); - setenv("boot.netif.netmask", intoa(netmask), 1); - setenv("boot.netif.gateway", inet_ntoa(gateip), 1); - setenv("boot.netif.hwaddr", temp, 1); - setenv("boot.nfsroot.server", inet_ntoa(rootip), 1); - setenv("boot.nfsroot.path", rootpath, 1); - return (0); } @@ -354,3 +350,24 @@ net_print(int verbose) } printf("\n"); } + +/* + * Strip the server's address off of the rootpath if present and return it in + * network byte order, leaving just the pathname part in the global rootpath. + */ +uint32_t +net_parse_rootpath() +{ + int i; + n_long addr = INADDR_NONE; + + for (i = 0; rootpath[i] != '\0' && i < FNAME_SIZE; i++) + if (rootpath[i] == ':') + break; + if (i && i != FNAME_SIZE && rootpath[i] == ':') { + rootpath[i++] = '\0'; + addr = inet_addr(&rootpath[0]); + bcopy(&rootpath[i], rootpath, strlen(&rootpath[i])+1); + } + return (addr); +} Modified: head/sys/boot/common/dev_net.h ============================================================================== --- head/sys/boot/common/dev_net.h Mon May 18 15:05:12 2015 (r283061) +++ head/sys/boot/common/dev_net.h Mon May 18 15:46:43 2015 (r283062) @@ -26,5 +26,11 @@ * $FreeBSD$ */ +#ifndef _BOOT_DEV_NET_H_ +#define _BOOT_DEV_NET_H_ + extern struct devsw netdev; +uint32_t net_parse_rootpath(void); + +#endif