From perhov@math.ntnu.no  Sun Sep 28 14:09:36 2003
Return-Path: <perhov@math.ntnu.no>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 40E7116A4B3
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 28 Sep 2003 14:09:36 -0700 (PDT)
Received: from abel.math.ntnu.no (abel.math.ntnu.no [129.241.15.50])
	by mx1.FreeBSD.org (Postfix) with SMTP id E0A2544011
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 28 Sep 2003 14:09:33 -0700 (PDT)
	(envelope-from perhov@math.ntnu.no)
Received: (qmail 17226 invoked from network); 28 Sep 2003 21:09:32 -0000
Received: from torx.math.ntnu.no (129.241.15.52)
  by abel.math.ntnu.no with QMQP; 28 Sep 2003 21:09:32 -0000
Message-Id: <20030928210932.74023.qmail@torx.math.ntnu.no>
Date: 28 Sep 2003 21:09:32 -0000
From: Per Kristian Hove <Per.Hove@math.ntnu.no>
Reply-To: Per Kristian Hove <Per.Hove@math.ntnu.no>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Per Kristian Hove <Per.Hove@math.ntnu.no>
Subject: [patch] -current loader uses wrong IP address for kernel and NFSROOT
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         57328
>Category:       kern
>Synopsis:       [patch] -current loader uses wrong IP address for kernel and NFSROOT
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 28 14:10:12 PDT 2003
>Closed-Date:    Mon Nov 03 11:46:48 PST 2003
>Last-Modified:  Mon Nov 03 11:46:48 PST 2003
>Originator:     Per Kristian Hove
>Release:        FreeBSD 5.1-CURRENT sparc64
>Organization:
>Environment:
System: FreeBSD 5.1-CURRENT sparc64


	
>Description:
When netbooting FreeBSD 5.1-CURRENT on sparc64, the loader tries to
download the kernel and mount the NFS root file system from the wrong
server address. This isn't noticeable unless you have separate DHCP,
TFTP and NFS servers, but if you do, the loader tries to load the
kernel and mount the root file system from the TFTP server.

The problem doesn't seem to be sparc64-specific, it probably affects
all non-PXE netbooting.
>How-To-Repeat:
Use a separate DHCP server (10.0.0.10), TFTP server (10.0.0.20) and
NFS server (10.0.0.30). Put the following in dhcpd.conf:
        host hostname.example.com {
                [...]
                next-server 10.0.0.20;
                filename "loader";
                option root-path "10.0.0.30:/export/install";
        }
Then netboot the sparc64 computer with "boot net:dhcp". The loader says:
   net_open: server addr: 10.0.0.20
   net_open: server path: /export/install
The first line should read
   net_open: server addr: 10.0.0.30
>Fix:
Apply the following patch.
Tested on: sparc64 buildworld (on i386 with TARGET_ARCH=sparc64).

--- dev_net.c.diff begins here ---
--- /sys/boot/common/dev_net.c.orig	Tue Aug 26 01:30:41 2003
+++ /sys/boot/common/dev_net.c	Sun Sep 28 22:41:47 2003
@@ -270,22 +270,21 @@
 	return (EIO);
     }
  exit:
-    printf("net_open: server addr: %s\n", inet_ntoa(rootip));
-
-    /*  
-     * 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
+    /*
+     * Now that the loader loads the kernel via NFS, we should
+     * honor the IP address given in the rootpath.
      */
-
-    for(i=0; i<FNAME_SIZE; i++)
-	    if(rootpath[i] == ':')
+    for (i = 0; rootpath[i] != '\0' && i < FNAME_SIZE; i++)
+	    if (rootpath[i] == ':')
 		    break;
-    if(i && i != FNAME_SIZE) {
-	    i++;
+    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);	    
     }
+    printf("net_open: server addr: %s\n", inet_ntoa(rootip));
     printf("net_open: server path: %s\n", rootpath);	    
 
     d = socktodesc(sock);
@@ -294,6 +293,8 @@
     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);
 }
--- dev_net.c.diff ends here ---


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: iedowse 
State-Changed-When: Mon Nov 3 11:45:34 PST 2003 
State-Changed-Why:  

Committed as revision 1.13 of dev_net.c. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=57328 
>Unformatted:
