Add static nfs boot configuration, from the kernel config file or from trunk
authorcl <cl@NetBSD.org>
Thu, 11 Mar 2004 21:48:43 +0000
branchtrunk
changeset 124672 04292780867f
parent 124671 e975e3939a56
child 124673 74db40a8b4e6
Add static nfs boot configuration, from the kernel config file or from a driver selectable callback function. This is used in the Xen port to allow controlling the domain's network setup from the domain building environment at domain creation (vs. having to maintain/change this on a dhcp server). The Xen network driver parses a command line passed in from the domain builder.
sys/nfs/files.nfs
sys/nfs/nfs_boot.c
sys/nfs/nfs_bootstatic.c
sys/nfs/nfsdiskless.h
--- a/sys/nfs/files.nfs	Thu Mar 11 21:44:08 2004 +0000
+++ b/sys/nfs/files.nfs	Thu Mar 11 21:48:43 2004 +0000
@@ -1,12 +1,16 @@
-#	$NetBSD: files.nfs,v 1.2 2002/10/23 09:14:48 jdolecek Exp $
+#	$NetBSD: files.nfs,v 1.3 2004/03/11 21:48:43 cl Exp $
 
 deffs	fs_nfs.h		NFS
 
 defflag opt_nfs_boot.h		NFS_BOOT_BOOTP NFS_BOOT_BOOTPARAM NFS_BOOT_DHCP
 				NFS_BOOT_GATEWAY NFS_BOOT_TCP
+				NFS_BOOT_BOOTSTATIC
 
 defparam opt_nfs_boot.h		NFS_BOOT_BOOTP_REQFILE NFS_BOOT_OPTIONS
 				NFS_BOOT_RWSIZE
+				NFS_BOOTSTATIC_MYIP NFS_BOOTSTATIC_GWIP
+				NFS_BOOTSTATIC_MASK NFS_BOOTSTATIC_SADDR
+				NFS_BOOTSTATIC_SERVER
 
 defflag opt_nfs.h		NFS_V2_ONLY
 
@@ -17,6 +21,7 @@
 file	nfs/nfs_boot.c		nfs 
 file	nfs/nfs_bootdhcp.c	nfs & (nfs_boot_bootp | nfs_boot_dhcp)
 file	nfs/nfs_bootparam.c	nfs & nfs_boot_bootparam
+file	nfs/nfs_bootstatic.c	nfs & nfs_boot_bootstatic
 file	nfs/nfs_kq.c		nfs   
 file	nfs/nfs_node.c		nfs   
 file	nfs/nfs_nqlease.c	nfsserver | nfs
--- a/sys/nfs/nfs_boot.c	Thu Mar 11 21:44:08 2004 +0000
+++ b/sys/nfs/nfs_boot.c	Thu Mar 11 21:48:43 2004 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs_boot.c,v 1.59 2003/06/29 22:32:14 fvdl Exp $	*/
+/*	$NetBSD: nfs_boot.c,v 1.60 2004/03/11 21:48:43 cl Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_boot.c,v 1.59 2003/06/29 22:32:14 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_boot.c,v 1.60 2004/03/11 21:48:43 cl Exp $");
 
 #include "opt_nfs.h"
 #include "opt_nfs_boot.h"
@@ -89,6 +89,9 @@
 #ifdef NFS_BOOT_BOOTPARAM
 int nfs_boot_bootparam = 1; /* BOOTPARAM enabled (default) */
 #endif
+#ifdef NFS_BOOT_BOOTSTATIC
+int nfs_boot_bootstatic = 1; /* BOOTSTATIC enabled (default) */
+#endif
 
 /* mountd RPC */
 static int md_mount __P((struct sockaddr_in *mdsin, char *path,
@@ -123,6 +126,12 @@
 	nd->nd_ifp = ifp;
 
 	error = EADDRNOTAVAIL; /* ??? */
+#if defined(NFS_BOOT_BOOTSTATIC)
+	if (error && nfs_boot_bootstatic) {
+		printf("nfs_boot: trying static\n");
+		error = nfs_bootstatic(nd, procp);
+	}
+#endif
 #if defined(NFS_BOOT_BOOTP) || defined(NFS_BOOT_DHCP)
 	if (error && nfs_boot_rfc951) {
 #if defined(NFS_BOOT_DHCP)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/nfs/nfs_bootstatic.c	Thu Mar 11 21:48:43 2004 +0000
@@ -0,0 +1,148 @@
+/*	$NetBSD: nfs_bootstatic.c,v 1.1 2004/03/11 21:48:43 cl Exp $	*/
+
+/*
+ *
+ * Copyright (c) 2004 Christian Limpach.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Christian Limpach.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: nfs_bootstatic.c,v 1.1 2004/03/11 21:48:43 cl Exp $");
+
+#include "opt_nfs_boot.h"
+#include "opt_inet.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/ioctl.h>
+#include <sys/proc.h>
+#include <sys/mount.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+
+#include <net/if.h>
+#include <net/if_types.h>
+#include <net/if_media.h>
+#include <net/route.h>
+#include <net/if_ether.h>
+
+#include <netinet/in.h>
+#include <netinet/if_inarp.h>
+
+#include <nfs/rpcv2.h>
+
+#include <nfs/nfsproto.h>
+#include <nfs/nfs.h>
+#include <nfs/nfsmount.h>
+#include <nfs/nfsdiskless.h>
+
+int (*nfs_bootstatic_callback)(struct nfs_diskless *) = NULL;
+
+int
+nfs_bootstatic(struct nfs_diskless *nd, struct proc *procp)
+{
+	struct ifnet *ifp = nd->nd_ifp;
+	struct sockaddr_in *sin;
+	int error, flags;
+
+	if (nfs_bootstatic_callback)
+		flags = (*nfs_bootstatic_callback)(nd);
+	else
+		flags = 0;
+
+	if (flags == 0) {
+#ifdef NFS_BOOTSTATIC_MYIP
+		nd->nd_myip.s_addr = inet_addr(NFS_BOOTSTATIC_MYIP);
+		flags |= NFS_BOOTSTATIC_HAS_MYIP;
+#endif
+#ifdef NFS_BOOTSTATIC_GWIP
+		nd->nd_gwip.s_addr = inet_addr(NFS_BOOTSTATIC_GWIP);
+		flags |= NFS_BOOTSTATIC_HAS_GWIP;
+#endif
+#ifdef NFS_BOOTSTATIC_MASK
+		nd->nd_mask.s_addr = inet_addr(NFS_BOOTSTATIC_MASK);
+		flags |= NFS_BOOTSTATIC_HAS_MASK;
+#endif
+#ifdef NFS_BOOTSTATIC_SERVADDR
+		sin = (struct sockaddr_in *) &nd->nd_root.ndm_saddr;
+		memset((caddr_t)sin, 0, sizeof(*sin));
+		sin->sin_len = sizeof(*sin);
+		sin->sin_family = AF_INET;
+		sin->sin_addr.s_addr = inet_addr(NFS_BOOTSTATIC_SERVADDR);
+		flags |= NFS_BOOTSTATIC_HAS_SERVADDR;
+#endif
+#ifdef NFS_BOOTSTATIC_SERVER
+		strncpy(nd->nd_root.ndm_host, NFS_BOOTSTATIC_SERVER, MNAMELEN);
+		flags |= NFS_BOOTSTATIC_HAS_SERVER;
+#endif
+	}
+
+	if (flags & NFS_BOOTSTATIC_HAS_MYIP)
+		aprint_normal("nfs_boot: client_addr=%s\n",
+		    inet_ntoa(nd->nd_myip));
+	
+	if (flags & NFS_BOOTSTATIC_HAS_GWIP)
+		aprint_normal("nfs_boot: gateway=%s\n",
+		    inet_ntoa(nd->nd_gwip));
+
+	if (flags & NFS_BOOTSTATIC_HAS_MASK)
+		aprint_normal("nfs_boot: netmask=%s\n",
+		    inet_ntoa(nd->nd_mask));
+
+	if (flags & NFS_BOOTSTATIC_HAS_SERVADDR) {
+		sin = (struct sockaddr_in *) &nd->nd_root.ndm_saddr;
+		aprint_normal("nfs_boot: server=%s\n",
+		    inet_ntoa(sin->sin_addr));
+	}
+
+	if (flags & NFS_BOOTSTATIC_HAS_SERVER)
+		aprint_normal("nfs_boot: root=%.*s\n", MNAMELEN,
+		    nd->nd_root.ndm_host);
+
+	/*
+	 * Do enough of ifconfig(8) so that the chosen interface
+	 * can talk to the servers.
+	 */
+	error = nfs_boot_setaddress(ifp, procp,
+	    flags & NFS_BOOTSTATIC_HAS_MYIP ? nd->nd_myip.s_addr : INADDR_ANY,
+	    flags & NFS_BOOTSTATIC_HAS_MASK ? nd->nd_mask.s_addr : INADDR_ANY,
+	    INADDR_ANY);
+	if (error) {
+		aprint_error("nfs_boot: set ifaddr, error=%d\n", error);
+		goto out;
+	}
+
+	error = 0;
+
+ out:
+
+	return error;
+}
--- a/sys/nfs/nfsdiskless.h	Thu Mar 11 21:44:08 2004 +0000
+++ b/sys/nfs/nfsdiskless.h	Thu Mar 11 21:48:43 2004 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfsdiskless.h,v 1.20 2003/06/29 22:32:21 fvdl Exp $	*/
+/*	$NetBSD: nfsdiskless.h,v 1.21 2004/03/11 21:48:43 cl Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@@ -85,6 +85,15 @@
 
 int nfs_bootdhcp  __P((struct nfs_diskless *, struct proc *));
 int nfs_bootparam __P((struct nfs_diskless *, struct proc *));
+int nfs_bootstatic __P((struct nfs_diskless *, struct proc *));
+
+int (*nfs_bootstatic_callback)(struct nfs_diskless *);
+
+#define	NFS_BOOTSTATIC_HAS_MYIP		0x01
+#define	NFS_BOOTSTATIC_HAS_GWIP		0x02
+#define	NFS_BOOTSTATIC_HAS_MASK		0x04
+#define	NFS_BOOTSTATIC_HAS_SERVADDR	0x08
+#define	NFS_BOOTSTATIC_HAS_SERVER	0x10
 #endif /* _KERNEL */
 
 #endif /* _NFS_NFSDISKLESS_H_ */