nfs_bootparam.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: nfs_bootparam.c,v 1.1.2.2 1997/09/01 21:02:56 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*-
4 1.1.2.2 thorpej * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
5 1.1.2.2 thorpej * All rights reserved.
6 1.1.2.2 thorpej *
7 1.1.2.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 thorpej * by Adam Glass and Gordon W. Ross.
9 1.1.2.2 thorpej *
10 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.1.2.2 thorpej * are met:
13 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 thorpej * must display the following acknowledgement:
20 1.1.2.2 thorpej * This product includes software developed by the NetBSD
21 1.1.2.2 thorpej * Foundation, Inc. and its contributors.
22 1.1.2.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 thorpej * contributors may be used to endorse or promote products derived
24 1.1.2.2 thorpej * from this software without specific prior written permission.
25 1.1.2.2 thorpej *
26 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 thorpej */
38 1.1.2.2 thorpej
39 1.1.2.2 thorpej /*
40 1.1.2.2 thorpej * Support for NFS diskless booting, Sun-style (RPC/bootparams)
41 1.1.2.2 thorpej */
42 1.1.2.2 thorpej
43 1.1.2.2 thorpej #include <sys/param.h>
44 1.1.2.2 thorpej #include <sys/systm.h>
45 1.1.2.2 thorpej #include <sys/kernel.h>
46 1.1.2.2 thorpej #include <sys/conf.h>
47 1.1.2.2 thorpej #include <sys/device.h>
48 1.1.2.2 thorpej #include <sys/ioctl.h>
49 1.1.2.2 thorpej #include <sys/proc.h>
50 1.1.2.2 thorpej #include <sys/mount.h>
51 1.1.2.2 thorpej #include <sys/mbuf.h>
52 1.1.2.2 thorpej #include <sys/reboot.h>
53 1.1.2.2 thorpej #include <sys/socket.h>
54 1.1.2.2 thorpej #include <sys/socketvar.h>
55 1.1.2.2 thorpej
56 1.1.2.2 thorpej #include <net/if.h>
57 1.1.2.2 thorpej #include <net/route.h>
58 1.1.2.2 thorpej #include <net/if_ether.h>
59 1.1.2.2 thorpej
60 1.1.2.2 thorpej #include <netinet/in.h>
61 1.1.2.2 thorpej #include <netinet/if_inarp.h>
62 1.1.2.2 thorpej
63 1.1.2.2 thorpej #include <nfs/rpcv2.h>
64 1.1.2.2 thorpej #include <nfs/krpc.h>
65 1.1.2.2 thorpej #include <nfs/xdr_subs.h>
66 1.1.2.2 thorpej
67 1.1.2.2 thorpej #include <nfs/nfsproto.h>
68 1.1.2.2 thorpej #include <nfs/nfsdiskless.h>
69 1.1.2.2 thorpej
70 1.1.2.2 thorpej /*
71 1.1.2.2 thorpej * There are two implementations of NFS diskless boot.
72 1.1.2.2 thorpej * This implementation uses Sun RPC/bootparams, and the
73 1.1.2.2 thorpej * the other uses BOOTP (RFC951 - see nfs_bootdhcp.c).
74 1.1.2.2 thorpej *
75 1.1.2.2 thorpej * The Sun-style boot sequence goes as follows:
76 1.1.2.2 thorpej * (1) Use RARP to get our interface address
77 1.1.2.2 thorpej * (2) Use RPC/bootparam/whoami to get our hostname,
78 1.1.2.2 thorpej * our IP address, and the server's IP address.
79 1.1.2.2 thorpej * (3) Use RPC/bootparam/getfile to get the root path
80 1.1.2.2 thorpej * (4) Use RPC/mountd to get the root file handle
81 1.1.2.2 thorpej * (5) Use RPC/bootparam/getfile to get the swap path
82 1.1.2.2 thorpej * (6) Use RPC/mountd to get the swap file handle
83 1.1.2.2 thorpej */
84 1.1.2.2 thorpej
85 1.1.2.2 thorpej /* bootparam RPC */
86 1.1.2.2 thorpej static int bp_whoami __P((struct sockaddr_in *bpsin,
87 1.1.2.2 thorpej struct in_addr *my_ip, struct in_addr *gw_ip));
88 1.1.2.2 thorpej static int bp_getfile __P((struct sockaddr_in *bpsin, char *key,
89 1.1.2.2 thorpej struct nfs_dlmount *ndm));
90 1.1.2.2 thorpej
91 1.1.2.2 thorpej
92 1.1.2.2 thorpej /*
93 1.1.2.2 thorpej * Get client name, gateway address, then
94 1.1.2.2 thorpej * get root and swap server:pathname info.
95 1.1.2.2 thorpej * RPCs: bootparam/whoami, bootparam/getfile
96 1.1.2.2 thorpej *
97 1.1.2.2 thorpej * Use the old broadcast address for the WHOAMI
98 1.1.2.2 thorpej * call because we do not yet know our netmask.
99 1.1.2.2 thorpej * The server address returned by the WHOAMI call
100 1.1.2.2 thorpej * is used for all subsequent booptaram RPCs.
101 1.1.2.2 thorpej */
102 1.1.2.2 thorpej int
103 1.1.2.2 thorpej nfs_bootparam(ifp, nd, procp)
104 1.1.2.2 thorpej struct ifnet *ifp;
105 1.1.2.2 thorpej struct nfs_diskless *nd;
106 1.1.2.2 thorpej struct proc *procp;
107 1.1.2.2 thorpej {
108 1.1.2.2 thorpej struct ifreq ireq;
109 1.1.2.2 thorpej struct sockaddr_in bp_sin;
110 1.1.2.2 thorpej struct sockaddr_in *sin;
111 1.1.2.2 thorpej struct socket *so;
112 1.1.2.2 thorpej struct in_addr my_ip;
113 1.1.2.2 thorpej int error;
114 1.1.2.2 thorpej
115 1.1.2.2 thorpej bzero(&ireq, sizeof(ireq));
116 1.1.2.2 thorpej bcopy(ifp->if_xname, ireq.ifr_name, IFNAMSIZ);
117 1.1.2.2 thorpej
118 1.1.2.2 thorpej /*
119 1.1.2.2 thorpej * Get a socket to use for various things in here.
120 1.1.2.2 thorpej * After this, use "goto out" to cleanup and return.
121 1.1.2.2 thorpej */
122 1.1.2.2 thorpej error = socreate(AF_INET, &so, SOCK_DGRAM, 0);
123 1.1.2.2 thorpej if (error) {
124 1.1.2.2 thorpej printf("nfs_boot: socreate, error=%d\n", error);
125 1.1.2.2 thorpej return (error);
126 1.1.2.2 thorpej }
127 1.1.2.2 thorpej
128 1.1.2.2 thorpej /*
129 1.1.2.2 thorpej * Bring up the interface. (just set the "up" flag)
130 1.1.2.2 thorpej * Get the old interface flags and or IFF_UP into them so
131 1.1.2.2 thorpej * things like media selection flags are not clobbered.
132 1.1.2.2 thorpej */
133 1.1.2.2 thorpej error = ifioctl(so, SIOCGIFFLAGS, (caddr_t)&ireq, procp);
134 1.1.2.2 thorpej if (error) {
135 1.1.2.2 thorpej printf("nfs_boot: GIFFLAGS, error=%d\n", error);
136 1.1.2.2 thorpej goto out;
137 1.1.2.2 thorpej }
138 1.1.2.2 thorpej ireq.ifr_flags |= IFF_UP;
139 1.1.2.2 thorpej error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)&ireq, procp);
140 1.1.2.2 thorpej if (error) {
141 1.1.2.2 thorpej printf("nfs_boot: SIFFLAGS, error=%d\n", error);
142 1.1.2.2 thorpej goto out;
143 1.1.2.2 thorpej }
144 1.1.2.2 thorpej
145 1.1.2.2 thorpej /*
146 1.1.2.2 thorpej * Do RARP for the interface address.
147 1.1.2.2 thorpej */
148 1.1.2.2 thorpej error = revarpwhoami(&my_ip, ifp);
149 1.1.2.2 thorpej if (error) {
150 1.1.2.2 thorpej printf("revarp failed, error=%d\n", error);
151 1.1.2.2 thorpej goto out;
152 1.1.2.2 thorpej }
153 1.1.2.2 thorpej nd->nd_myip.s_addr = my_ip.s_addr;
154 1.1.2.2 thorpej printf("nfs_boot: client_addr=0x%x\n",
155 1.1.2.2 thorpej (u_int32_t)ntohl(my_ip.s_addr));
156 1.1.2.2 thorpej
157 1.1.2.2 thorpej /*
158 1.1.2.2 thorpej * Do enough of ifconfig(8) so that the chosen interface
159 1.1.2.2 thorpej * can talk to the servers. (just set the address)
160 1.1.2.2 thorpej */
161 1.1.2.2 thorpej sin = (struct sockaddr_in *)&ireq.ifr_addr;
162 1.1.2.2 thorpej sin->sin_len = sizeof(*sin);
163 1.1.2.2 thorpej sin->sin_family = AF_INET;
164 1.1.2.2 thorpej sin->sin_addr.s_addr = my_ip.s_addr;
165 1.1.2.2 thorpej error = ifioctl(so, SIOCSIFADDR, (caddr_t)&ireq, procp);
166 1.1.2.2 thorpej if (error) {
167 1.1.2.2 thorpej printf("nfs_boot: set ifaddr, error=%d\n", error);
168 1.1.2.2 thorpej goto out;
169 1.1.2.2 thorpej }
170 1.1.2.2 thorpej
171 1.1.2.2 thorpej /*
172 1.1.2.2 thorpej * Get client name and gateway address.
173 1.1.2.2 thorpej * RPC: bootparam/whoami
174 1.1.2.2 thorpej * Use the old broadcast address for the WHOAMI
175 1.1.2.2 thorpej * call because we do not yet know our netmask.
176 1.1.2.2 thorpej * The server address returned by the WHOAMI call
177 1.1.2.2 thorpej * is used for all subsequent booptaram RPCs.
178 1.1.2.2 thorpej */
179 1.1.2.2 thorpej sin = &bp_sin;
180 1.1.2.2 thorpej bzero((caddr_t)sin, sizeof(*sin));
181 1.1.2.2 thorpej sin->sin_len = sizeof(*sin);
182 1.1.2.2 thorpej sin->sin_family = AF_INET;
183 1.1.2.2 thorpej sin->sin_addr.s_addr = INADDR_BROADCAST;
184 1.1.2.2 thorpej
185 1.1.2.2 thorpej /* Do the RPC/bootparam/whoami. */
186 1.1.2.2 thorpej error = bp_whoami(sin, &my_ip, &nd->nd_gwip);
187 1.1.2.2 thorpej if (error) {
188 1.1.2.2 thorpej printf("nfs_boot: bootparam whoami, error=%d\n", error);
189 1.1.2.2 thorpej goto out;
190 1.1.2.2 thorpej }
191 1.1.2.2 thorpej printf("nfs_boot: server_addr=0x%x\n",
192 1.1.2.2 thorpej (u_int32_t)ntohl(sin->sin_addr.s_addr));
193 1.1.2.2 thorpej printf("nfs_boot: hostname=%s\n", hostname);
194 1.1.2.2 thorpej
195 1.1.2.2 thorpej /*
196 1.1.2.2 thorpej * Now fetch the server:pathname strings and server IP
197 1.1.2.2 thorpej * for root and swap. Missing swap is not fatal.
198 1.1.2.2 thorpej */
199 1.1.2.2 thorpej error = bp_getfile(sin, "root", &nd->nd_root);
200 1.1.2.2 thorpej if (error) {
201 1.1.2.2 thorpej printf("nfs_boot: bootparam get root: %d\n", error);
202 1.1.2.2 thorpej goto out;
203 1.1.2.2 thorpej }
204 1.1.2.2 thorpej #if 0
205 1.1.2.2 thorpej error = bp_getfile(sin, "swap", &nd->nd_swap);
206 1.1.2.2 thorpej if (error) {
207 1.1.2.2 thorpej printf("nfs_boot: bootparam get swap: %d\n", error);
208 1.1.2.2 thorpej error = 0;
209 1.1.2.2 thorpej }
210 1.1.2.2 thorpej #endif
211 1.1.2.2 thorpej
212 1.1.2.2 thorpej /*
213 1.1.2.2 thorpej * XXX - Use bp_getfile(sin, "gate", &gw_ip)
214 1.1.2.2 thorpej * to get the [router:mask] information, maybe?
215 1.1.2.2 thorpej * Better still, just use BOOTP/DHCP instead.
216 1.1.2.2 thorpej */
217 1.1.2.2 thorpej
218 1.1.2.2 thorpej out:
219 1.1.2.2 thorpej soclose(so);
220 1.1.2.2 thorpej return (error);
221 1.1.2.2 thorpej }
222 1.1.2.2 thorpej
223 1.1.2.2 thorpej
224 1.1.2.2 thorpej /*
225 1.1.2.2 thorpej * RPC: bootparam/whoami
226 1.1.2.2 thorpej * Given client IP address, get:
227 1.1.2.2 thorpej * client name (hostname)
228 1.1.2.2 thorpej * domain name (domainname)
229 1.1.2.2 thorpej * gateway address
230 1.1.2.2 thorpej *
231 1.1.2.2 thorpej * The hostname and domainname are set here for convenience.
232 1.1.2.2 thorpej *
233 1.1.2.2 thorpej * Note - bpsin is initialized to the broadcast address,
234 1.1.2.2 thorpej * and will be replaced with the bootparam server address
235 1.1.2.2 thorpej * after this call is complete. Have to use PMAP_PROC_CALL
236 1.1.2.2 thorpej * to make sure we get responses only from a servers that
237 1.1.2.2 thorpej * know about us (don't want to broadcast a getport call).
238 1.1.2.2 thorpej */
239 1.1.2.2 thorpej static int
240 1.1.2.2 thorpej bp_whoami(bpsin, my_ip, gw_ip)
241 1.1.2.2 thorpej struct sockaddr_in *bpsin;
242 1.1.2.2 thorpej struct in_addr *my_ip;
243 1.1.2.2 thorpej struct in_addr *gw_ip;
244 1.1.2.2 thorpej {
245 1.1.2.2 thorpej /* RPC structures for PMAPPROC_CALLIT */
246 1.1.2.2 thorpej struct whoami_call {
247 1.1.2.2 thorpej u_int32_t call_prog;
248 1.1.2.2 thorpej u_int32_t call_vers;
249 1.1.2.2 thorpej u_int32_t call_proc;
250 1.1.2.2 thorpej u_int32_t call_arglen;
251 1.1.2.2 thorpej } *call;
252 1.1.2.2 thorpej struct callit_reply {
253 1.1.2.2 thorpej u_int32_t port;
254 1.1.2.2 thorpej u_int32_t encap_len;
255 1.1.2.2 thorpej /* encapsulated data here */
256 1.1.2.2 thorpej } *reply;
257 1.1.2.2 thorpej
258 1.1.2.2 thorpej struct mbuf *m, *from;
259 1.1.2.2 thorpej struct sockaddr_in *sin;
260 1.1.2.2 thorpej int error, msg_len;
261 1.1.2.2 thorpej int16_t port;
262 1.1.2.2 thorpej
263 1.1.2.2 thorpej /*
264 1.1.2.2 thorpej * Build request message for PMAPPROC_CALLIT.
265 1.1.2.2 thorpej */
266 1.1.2.2 thorpej m = m_get(M_WAIT, MT_DATA);
267 1.1.2.2 thorpej call = mtod(m, struct whoami_call *);
268 1.1.2.2 thorpej m->m_len = sizeof(*call);
269 1.1.2.2 thorpej call->call_prog = txdr_unsigned(BOOTPARAM_PROG);
270 1.1.2.2 thorpej call->call_vers = txdr_unsigned(BOOTPARAM_VERS);
271 1.1.2.2 thorpej call->call_proc = txdr_unsigned(BOOTPARAM_WHOAMI);
272 1.1.2.2 thorpej
273 1.1.2.2 thorpej /*
274 1.1.2.2 thorpej * append encapsulated data (client IP address)
275 1.1.2.2 thorpej */
276 1.1.2.2 thorpej m->m_next = xdr_inaddr_encode(my_ip);
277 1.1.2.2 thorpej call->call_arglen = txdr_unsigned(m->m_next->m_len);
278 1.1.2.2 thorpej
279 1.1.2.2 thorpej /* RPC: portmap/callit */
280 1.1.2.2 thorpej bpsin->sin_port = htons(PMAPPORT);
281 1.1.2.2 thorpej from = NULL;
282 1.1.2.2 thorpej error = krpc_call(bpsin, PMAPPROG, PMAPVERS,
283 1.1.2.2 thorpej PMAPPROC_CALLIT, &m, &from);
284 1.1.2.2 thorpej if (error)
285 1.1.2.2 thorpej return error;
286 1.1.2.2 thorpej
287 1.1.2.2 thorpej /*
288 1.1.2.2 thorpej * Parse result message.
289 1.1.2.2 thorpej */
290 1.1.2.2 thorpej if (m->m_len < sizeof(*reply)) {
291 1.1.2.2 thorpej m = m_pullup(m, sizeof(*reply));
292 1.1.2.2 thorpej if (m == NULL)
293 1.1.2.2 thorpej goto bad;
294 1.1.2.2 thorpej }
295 1.1.2.2 thorpej reply = mtod(m, struct callit_reply *);
296 1.1.2.2 thorpej port = fxdr_unsigned(u_int32_t, reply->port);
297 1.1.2.2 thorpej msg_len = fxdr_unsigned(u_int32_t, reply->encap_len);
298 1.1.2.2 thorpej m_adj(m, sizeof(*reply));
299 1.1.2.2 thorpej
300 1.1.2.2 thorpej /*
301 1.1.2.2 thorpej * Save bootparam server address
302 1.1.2.2 thorpej */
303 1.1.2.2 thorpej sin = mtod(from, struct sockaddr_in *);
304 1.1.2.2 thorpej bpsin->sin_port = htons(port);
305 1.1.2.2 thorpej bpsin->sin_addr.s_addr = sin->sin_addr.s_addr;
306 1.1.2.2 thorpej
307 1.1.2.2 thorpej /* client name */
308 1.1.2.2 thorpej hostnamelen = MAXHOSTNAMELEN-1;
309 1.1.2.2 thorpej m = xdr_string_decode(m, hostname, &hostnamelen);
310 1.1.2.2 thorpej if (m == NULL)
311 1.1.2.2 thorpej goto bad;
312 1.1.2.2 thorpej
313 1.1.2.2 thorpej /* domain name */
314 1.1.2.2 thorpej domainnamelen = MAXHOSTNAMELEN-1;
315 1.1.2.2 thorpej m = xdr_string_decode(m, domainname, &domainnamelen);
316 1.1.2.2 thorpej if (m == NULL)
317 1.1.2.2 thorpej goto bad;
318 1.1.2.2 thorpej
319 1.1.2.2 thorpej /* gateway address */
320 1.1.2.2 thorpej m = xdr_inaddr_decode(m, gw_ip);
321 1.1.2.2 thorpej if (m == NULL)
322 1.1.2.2 thorpej goto bad;
323 1.1.2.2 thorpej
324 1.1.2.2 thorpej /* success */
325 1.1.2.2 thorpej goto out;
326 1.1.2.2 thorpej
327 1.1.2.2 thorpej bad:
328 1.1.2.2 thorpej printf("nfs_boot: bootparam_whoami: bad reply\n");
329 1.1.2.2 thorpej error = EBADRPC;
330 1.1.2.2 thorpej
331 1.1.2.2 thorpej out:
332 1.1.2.2 thorpej if (from)
333 1.1.2.2 thorpej m_freem(from);
334 1.1.2.2 thorpej if (m)
335 1.1.2.2 thorpej m_freem(m);
336 1.1.2.2 thorpej return(error);
337 1.1.2.2 thorpej }
338 1.1.2.2 thorpej
339 1.1.2.2 thorpej
340 1.1.2.2 thorpej /*
341 1.1.2.2 thorpej * RPC: bootparam/getfile
342 1.1.2.2 thorpej * Given client name and file "key", get:
343 1.1.2.2 thorpej * server name
344 1.1.2.2 thorpej * server IP address
345 1.1.2.2 thorpej * server pathname
346 1.1.2.2 thorpej */
347 1.1.2.2 thorpej static int
348 1.1.2.2 thorpej bp_getfile(bpsin, key, ndm)
349 1.1.2.2 thorpej struct sockaddr_in *bpsin;
350 1.1.2.2 thorpej char *key;
351 1.1.2.2 thorpej struct nfs_dlmount *ndm;
352 1.1.2.2 thorpej {
353 1.1.2.2 thorpej char pathname[MNAMELEN];
354 1.1.2.2 thorpej struct in_addr inaddr;
355 1.1.2.2 thorpej struct sockaddr_in *sin;
356 1.1.2.2 thorpej struct mbuf *m;
357 1.1.2.2 thorpej char *serv_name;
358 1.1.2.2 thorpej int error, sn_len, path_len;
359 1.1.2.2 thorpej
360 1.1.2.2 thorpej /*
361 1.1.2.2 thorpej * Build request message.
362 1.1.2.2 thorpej */
363 1.1.2.2 thorpej
364 1.1.2.2 thorpej /* client name (hostname) */
365 1.1.2.2 thorpej m = xdr_string_encode(hostname, hostnamelen);
366 1.1.2.2 thorpej if (m == NULL)
367 1.1.2.2 thorpej return (ENOMEM);
368 1.1.2.2 thorpej
369 1.1.2.2 thorpej /* key name (root or swap) */
370 1.1.2.2 thorpej m->m_next = xdr_string_encode(key, strlen(key));
371 1.1.2.2 thorpej if (m->m_next == NULL)
372 1.1.2.2 thorpej return (ENOMEM);
373 1.1.2.2 thorpej
374 1.1.2.2 thorpej /* RPC: bootparam/getfile */
375 1.1.2.2 thorpej error = krpc_call(bpsin, BOOTPARAM_PROG, BOOTPARAM_VERS,
376 1.1.2.2 thorpej BOOTPARAM_GETFILE, &m, NULL);
377 1.1.2.2 thorpej if (error)
378 1.1.2.2 thorpej return error;
379 1.1.2.2 thorpej
380 1.1.2.2 thorpej /*
381 1.1.2.2 thorpej * Parse result message.
382 1.1.2.2 thorpej */
383 1.1.2.2 thorpej
384 1.1.2.2 thorpej /* server name */
385 1.1.2.2 thorpej serv_name = &ndm->ndm_host[0];
386 1.1.2.2 thorpej sn_len = sizeof(ndm->ndm_host) - 1;
387 1.1.2.2 thorpej m = xdr_string_decode(m, serv_name, &sn_len);
388 1.1.2.2 thorpej if (m == NULL)
389 1.1.2.2 thorpej goto bad;
390 1.1.2.2 thorpej
391 1.1.2.2 thorpej /* server IP address (mountd/NFS) */
392 1.1.2.2 thorpej m = xdr_inaddr_decode(m, &inaddr);
393 1.1.2.2 thorpej if (m == NULL)
394 1.1.2.2 thorpej goto bad;
395 1.1.2.2 thorpej
396 1.1.2.2 thorpej /* server pathname */
397 1.1.2.2 thorpej path_len = sizeof(pathname) - 1;
398 1.1.2.2 thorpej m = xdr_string_decode(m, pathname, &path_len);
399 1.1.2.2 thorpej if (m == NULL)
400 1.1.2.2 thorpej goto bad;
401 1.1.2.2 thorpej
402 1.1.2.2 thorpej /*
403 1.1.2.2 thorpej * Store the results in the nfs_dlmount.
404 1.1.2.2 thorpej * The strings become "server:pathname"
405 1.1.2.2 thorpej */
406 1.1.2.2 thorpej sin = (struct sockaddr_in *) &ndm->ndm_saddr;
407 1.1.2.2 thorpej bzero((caddr_t)sin, sizeof(*sin));
408 1.1.2.2 thorpej sin->sin_len = sizeof(*sin);
409 1.1.2.2 thorpej sin->sin_family = AF_INET;
410 1.1.2.2 thorpej sin->sin_addr = inaddr;
411 1.1.2.2 thorpej if ((sn_len + 1 + path_len + 1) > sizeof(ndm->ndm_host)) {
412 1.1.2.2 thorpej printf("nfs_boot: getfile name too long\n");
413 1.1.2.2 thorpej error = EIO;
414 1.1.2.2 thorpej goto out;
415 1.1.2.2 thorpej }
416 1.1.2.2 thorpej ndm->ndm_host[sn_len] = ':';
417 1.1.2.2 thorpej bcopy(pathname, ndm->ndm_host + sn_len + 1, path_len + 1);
418 1.1.2.2 thorpej
419 1.1.2.2 thorpej /* success */
420 1.1.2.2 thorpej goto out;
421 1.1.2.2 thorpej
422 1.1.2.2 thorpej bad:
423 1.1.2.2 thorpej printf("nfs_boot: bootparam_getfile: bad reply\n");
424 1.1.2.2 thorpej error = EBADRPC;
425 1.1.2.2 thorpej
426 1.1.2.2 thorpej out:
427 1.1.2.2 thorpej m_freem(m);
428 1.1.2.2 thorpej return(0);
429 1.1.2.2 thorpej }
430 1.1.2.2 thorpej
431 1.1.2.2 thorpej
432