1 /* $NetBSD: nfs_bootstatic.c,v 1.4 2007/03/04 06:03:36 christos Exp $ */
5 * Copyright (c) 2004 Christian Limpach.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Christian Limpach.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: nfs_bootstatic.c,v 1.4 2007/03/04 06:03:36 christos Exp $");
38 #include "opt_nfs_boot.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/ioctl.h>
46 #include <sys/mount.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
52 #include <net/if_types.h>
53 #include <net/if_media.h>
54 #include <net/route.h>
55 #include <net/if_ether.h>
57 #include <netinet/in.h>
58 #include <netinet/if_inarp.h>
60 #include <nfs/rpcv2.h>
62 #include <nfs/nfsproto.h>
64 #include <nfs/nfsmount.h>
65 #include <nfs/nfsdiskless.h>
67 int (*nfs_bootstatic_callback
)(struct nfs_diskless
*) = NULL
;
70 nfs_bootstatic(struct nfs_diskless
*nd
, struct lwp
*lwp
)
72 struct ifnet
*ifp
= nd
->nd_ifp
;
73 struct sockaddr_in
*sin
;
76 if (nfs_bootstatic_callback
)
77 flags
= (*nfs_bootstatic_callback
)(nd
);
81 if (flags
& NFS_BOOTSTATIC_NOSTATIC
)
85 #ifdef NFS_BOOTSTATIC_MYIP
86 nd
->nd_myip
.s_addr
= inet_addr(NFS_BOOTSTATIC_MYIP
);
87 flags
|= NFS_BOOTSTATIC_HAS_MYIP
;
89 #ifdef NFS_BOOTSTATIC_GWIP
90 nd
->nd_gwip
.s_addr
= inet_addr(NFS_BOOTSTATIC_GWIP
);
91 flags
|= NFS_BOOTSTATIC_HAS_GWIP
;
93 #ifdef NFS_BOOTSTATIC_MASK
94 nd
->nd_mask
.s_addr
= inet_addr(NFS_BOOTSTATIC_MASK
);
95 flags
|= NFS_BOOTSTATIC_HAS_MASK
;
97 #ifdef NFS_BOOTSTATIC_SERVADDR
98 sin
= (struct sockaddr_in
*) &nd
->nd_root
.ndm_saddr
;
99 memset((void *)sin
, 0, sizeof(*sin
));
100 sin
->sin_len
= sizeof(*sin
);
101 sin
->sin_family
= AF_INET
;
102 sin
->sin_addr
.s_addr
= inet_addr(NFS_BOOTSTATIC_SERVADDR
);
103 flags
|= NFS_BOOTSTATIC_HAS_SERVADDR
;
105 #ifdef NFS_BOOTSTATIC_SERVER
106 strncpy(nd
->nd_root
.ndm_host
, NFS_BOOTSTATIC_SERVER
, MNAMELEN
);
107 flags
|= NFS_BOOTSTATIC_HAS_SERVER
;
111 if (flags
& NFS_BOOTSTATIC_HAS_MYIP
)
112 aprint_normal("nfs_boot: client_addr=%s\n",
113 inet_ntoa(nd
->nd_myip
));
115 if (flags
& NFS_BOOTSTATIC_HAS_GWIP
)
116 aprint_normal("nfs_boot: gateway=%s\n",
117 inet_ntoa(nd
->nd_gwip
));
119 if (flags
& NFS_BOOTSTATIC_HAS_MASK
)
120 aprint_normal("nfs_boot: netmask=%s\n",
121 inet_ntoa(nd
->nd_mask
));
123 if (flags
& NFS_BOOTSTATIC_HAS_SERVADDR
) {
124 sin
= (struct sockaddr_in
*) &nd
->nd_root
.ndm_saddr
;
125 aprint_normal("nfs_boot: server=%s\n",
126 inet_ntoa(sin
->sin_addr
));
129 if (flags
& NFS_BOOTSTATIC_HAS_SERVER
)
130 aprint_normal("nfs_boot: root=%.*s\n", MNAMELEN
,
131 nd
->nd_root
.ndm_host
);
134 * Do enough of ifconfig(8) so that the chosen interface
135 * can talk to the servers.
137 error
= nfs_boot_setaddress(ifp
, lwp
,
138 flags
& NFS_BOOTSTATIC_HAS_MYIP
? nd
->nd_myip
.s_addr
: INADDR_ANY
,
139 flags
& NFS_BOOTSTATIC_HAS_MASK
? nd
->nd_mask
.s_addr
: INADDR_ANY
,
142 aprint_error("nfs_boot: set ifaddr, error=%d\n", error
);