mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Martin Schwenke" <martin@meltin.net>
To: trond.myklebust@fys.uio.no
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Patch to pull NFS server address off root_server_path
Date: Fri, 15 Mar 2002 15:37:17 +1100	[thread overview]
Message-ID: <200203150437.PAA30106@thucydides.inspired.net.au> (raw)

This is a new version of a patch that I originally submitted to Rusty
Russell as trivial patch dude...

The following patch pulls an NFS server IP address off
root_server_path (handed out via the DHCP root-path option), if it is
present.  For example, you can do this sort of thing in dhcpd.conf:

  root-path = 192.168.1.33:/tftpboot/yip.zImage

The patch appears to be backwards compatible.

RFC2132 says this about the root-path option:

   This option specifies the path-name that contains the client's root
   disk.  The path is formatted as a character string consisting of
   characters from the NVT ASCII character set.

This is sufficiently vague to allow the path-name to include an
IP-address.  Also, I found some documentation for FreeBSD saying it
does this too, so it must be right, because those FreeBSD guys are
really smart...  :-)

The only downside of the patch is that the summary that ipconfig
prints can be a little odd when the kernel command line overrides
whatever ipconfig gets from (say) DHCP.  The address from the kernel
command line seems to get stripped off early, so ipconfig reports it,
but it doesn't report the kernel command line NFS path, since that's
handled a bit later...

peace & happiness,
martin

diff -r -u linux-2.4.19-pre2/fs/nfs/nfsroot.c linux-2.4.19-pre2-working/fs/nfs/nfsroot.c
--- linux-2.4.19-pre2/fs/nfs/nfsroot.c	Thu Oct 25 11:29:22 2001
+++ linux-2.4.19-pre2-working/fs/nfs/nfsroot.c	Tue Mar 12 14:25:14 2002
@@ -163,37 +163,6 @@
 
 
 /*
- *  Extract IP address from the parameter string if needed. Note that we
- *  need to have root_server_addr set _before_ IPConfig gets called as it
- *  can override it.
- */
-static void __init root_nfs_parse_addr(char *name)
-{
-	int octets = 0;
-	char *cp, *cq;
-
-	cp = cq = name;
-	while (octets < 4) {
-		while (*cp >= '0' && *cp <= '9')
-			cp++;
-		if (cp == cq || cp - cq > 3)
-			break;
-		if (*cp == '.' || octets == 3)
-			octets++;
-		if (octets < 4)
-			cp++;
-		cq = cp;
-	}
-	if (octets == 4 && (*cp == ':' || *cp == '\0')) {
-		if (*cp == ':')
-			*cp++ = '\0';
-		root_server_addr = in_aton(name);
-		strcpy(name, cp);
-	}
-}
-
-
-/*
  *  Parse option string.
  */
 static void __init root_nfs_parse(char *name, char *buf)
@@ -344,7 +313,7 @@
 			line[sizeof(nfs_root_name) - strlen(NFS_ROOT) - 1] = '\0';
 		sprintf(nfs_root_name, NFS_ROOT, line);
 	}
-	root_nfs_parse_addr(nfs_root_name);
+	root_server_addr = root_nfs_parse_addr(nfs_root_name);
 	return 1;
 }
 
diff -r -u linux-2.4.19-pre2/include/linux/nfs_fs.h linux-2.4.19-pre2-working/include/linux/nfs_fs.h
--- linux-2.4.19-pre2/include/linux/nfs_fs.h	Tue Feb 26 11:39:37 2002
+++ linux-2.4.19-pre2-working/include/linux/nfs_fs.h	Tue Mar 12 14:25:14 2002
@@ -273,6 +273,9 @@
 extern int  nfs_mount(struct sockaddr_in *, char *, struct nfs_fh *);
 extern int  nfs3_mount(struct sockaddr_in *, char *, struct nfs_fh *);
 
+/* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
+extern u32 root_nfs_parse_addr(char *name); /*__init*/
+
 /*
  * inline functions
  */
Only in linux-2.4.19-pre2-working/include/linux: nfs_fs.h.orig
diff -r -u linux-2.4.19-pre2/net/ipv4/ipconfig.c linux-2.4.19-pre2-working/net/ipv4/ipconfig.c
--- linux-2.4.19-pre2/net/ipv4/ipconfig.c	Tue Feb 26 07:14:51 2002
+++ linux-2.4.19-pre2-working/net/ipv4/ipconfig.c	Tue Mar 12 14:42:15 2002
@@ -1105,6 +1105,40 @@
 #endif /* CONFIG_PROC_FS */
 
 /*
+ *  Extract IP address from the parameter string if needed. Note that we
+ *  need to have root_server_addr set _before_ IPConfig gets called as it
+ *  can override it.
+ */
+u32 __init root_nfs_parse_addr(char *name)
+{
+	u32 addr;
+	int octets = 0;
+	char *cp, *cq;
+
+	cp = cq = name;
+	while (octets < 4) {
+		while (*cp >= '0' && *cp <= '9')
+			cp++;
+		if (cp == cq || cp - cq > 3)
+			break;
+		if (*cp == '.' || octets == 3)
+			octets++;
+		if (octets < 4)
+			cp++;
+		cq = cp;
+	}
+	if (octets == 4 && (*cp == ':' || *cp == '\0')) {
+		if (*cp == ':')
+			*cp++ = '\0';
+		addr = in_aton(name);
+		strcpy(name, cp);
+	} else
+		addr = INADDR_NONE;
+
+	return addr;
+}
+
+/*
  *	IP Autoconfig dispatcher.
  */
 
@@ -1112,6 +1146,7 @@
 {
 	int retries = CONF_OPEN_RETRIES;
 	unsigned long jiff;
+	u32 addr;
 
 #ifdef CONFIG_PROC_FS
 	proc_net_create("pnp", 0, pnp_get_info);
@@ -1196,6 +1231,10 @@
 		/* Device selected manually or only one device -> use it */
 		ic_dev = ic_first_dev->dev;
 	}
+
+	addr = root_nfs_parse_addr(root_server_path);
+	if (root_server_addr == INADDR_NONE)
+		root_server_addr = addr;
 
 	/*
 	 * Use defaults whereever applicable.

             reply	other threads:[~2002-03-15  4:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-15  4:37 Martin Schwenke [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-03-06  4:04 Rusty Russell
2002-03-06 20:26 ` Trond Myklebust

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200203150437.PAA30106@thucydides.inspired.net.au \
    --to=martin@meltin.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=trond.myklebust@fys.uio.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®