Deleted Added
full compact
dev_net.c (256281) dev_net.c (283510)
1/* $NetBSD: dev_net.c,v 1.23 2008/04/28 20:24:06 martin Exp $ */
2
3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.

--- 16 unchanged lines hidden (view full) ---

25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
1/* $NetBSD: dev_net.c,v 1.23 2008/04/28 20:24:06 martin Exp $ */
2
3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.

--- 16 unchanged lines hidden (view full) ---

25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: stable/10/sys/boot/common/dev_net.c 201932 2010-01-09 21:23:39Z marius $");
33__FBSDID("$FreeBSD: stable/10/sys/boot/common/dev_net.c 283510 2015-05-25 01:29:45Z ian $");
34
35/*-
36 * This module implements a "raw device" interface suitable for
37 * use by the stand-alone I/O library NFS code. This interface
38 * does not support any "block" access, and exists only for the
39 * purpose of initializing the network interface, getting boot
40 * parameters, and performing the NFS mount.
41 *

--- 64 unchanged lines hidden (view full) ---

106/*
107 * Called by devopen after it sets f->f_dev to our devsw entry.
108 * This opens the low-level device and sets f->f_devdata.
109 * This is declared with variable arguments...
110 */
111static int
112net_open(struct open_file *f, ...)
113{
34
35/*-
36 * This module implements a "raw device" interface suitable for
37 * use by the stand-alone I/O library NFS code. This interface
38 * does not support any "block" access, and exists only for the
39 * purpose of initializing the network interface, getting boot
40 * parameters, and performing the NFS mount.
41 *

--- 64 unchanged lines hidden (view full) ---

106/*
107 * Called by devopen after it sets f->f_dev to our devsw entry.
108 * This opens the low-level device and sets f->f_devdata.
109 * This is declared with variable arguments...
110 */
111static int
112net_open(struct open_file *f, ...)
113{
114 char temp[FNAME_SIZE];
115 struct iodesc *d;
114 va_list args;
115 char *devname; /* Device part of file name (or NULL). */
116 int error = 0;
117
118 va_start(args, f);
119 devname = va_arg(args, char*);
120 va_end(args);
121

--- 13 unchanged lines hidden (view full) ---

135 return (ENXIO);
136 }
137 netdev_name = strdup(devname);
138#ifdef NETIF_DEBUG
139 if (debug)
140 printf("net_open: netif_open() succeeded\n");
141#endif
142 }
116 va_list args;
117 char *devname; /* Device part of file name (or NULL). */
118 int error = 0;
119
120 va_start(args, f);
121 devname = va_arg(args, char*);
122 va_end(args);
123

--- 13 unchanged lines hidden (view full) ---

137 return (ENXIO);
138 }
139 netdev_name = strdup(devname);
140#ifdef NETIF_DEBUG
141 if (debug)
142 printf("net_open: netif_open() succeeded\n");
143#endif
144 }
145 /*
146 * If network params were not set by netif_open(), try to get
147 * them via bootp, rarp, etc.
148 */
143 if (rootip.s_addr == 0) {
144 /* Get root IP address, and path, etc. */
145 error = net_getparams(netdev_sock);
146 if (error) {
147 /* getparams makes its own noise */
148 free(netdev_name);
149 netif_close(netdev_sock);
150 netdev_sock = -1;
151 return (error);
152 }
153 }
149 if (rootip.s_addr == 0) {
150 /* Get root IP address, and path, etc. */
151 error = net_getparams(netdev_sock);
152 if (error) {
153 /* getparams makes its own noise */
154 free(netdev_name);
155 netif_close(netdev_sock);
156 netdev_sock = -1;
157 return (error);
158 }
159 }
160 /*
161 * Set the variables required by the kernel's nfs_diskless
162 * mechanism. This is the minimum set of variables required to
163 * mount a root filesystem without needing to obtain additional
164 * info from bootp or other sources.
165 */
166 d = socktodesc(netdev_sock);
167 sprintf(temp, "%6D", d->myea, ":");
168 setenv("boot.netif.hwaddr", temp, 1);
169 setenv("boot.netif.ip", inet_ntoa(myip), 1);
170 setenv("boot.netif.netmask", intoa(netmask), 1);
171 setenv("boot.netif.gateway", inet_ntoa(gateip), 1);
172 setenv("boot.nfsroot.server", inet_ntoa(rootip), 1);
173 setenv("boot.nfsroot.path", rootpath, 1);
154 }
155 netdev_opens++;
156 f->f_devdata = &netdev_sock;
157 return (error);
158}
159
160static int
161net_close(struct open_file *f)

--- 65 unchanged lines hidden (view full) ---

227#endif
228
229extern n_long ip_convertaddr(char *p);
230
231static int
232net_getparams(int sock)
233{
234 char buf[MAXHOSTNAMELEN];
174 }
175 netdev_opens++;
176 f->f_devdata = &netdev_sock;
177 return (error);
178}
179
180static int
181net_close(struct open_file *f)

--- 65 unchanged lines hidden (view full) ---

247#endif
248
249extern n_long ip_convertaddr(char *p);
250
251static int
252net_getparams(int sock)
253{
254 char buf[MAXHOSTNAMELEN];
235 char temp[FNAME_SIZE];
236 struct iodesc *d;
237 int i;
238 n_long smask;
255 n_long rootaddr, smask;
239
240#ifdef SUPPORT_BOOTP
241 /*
242 * Try to get boot info using BOOTP. If we succeed, then
243 * the server IP address, gateway, and root path will all
244 * be initialized. If any remain uninitialized, we will
245 * use RARP and RPC/bootparam (the Sun way) to get them.
246 */

--- 50 unchanged lines hidden (view full) ---

297#endif
298
299 /* Get the root server and pathname. */
300 if (bp_getfile(sock, "root", &rootip, rootpath)) {
301 printf("net_open: bootparam/getfile RPC failed\n");
302 return (EIO);
303 }
304exit:
256
257#ifdef SUPPORT_BOOTP
258 /*
259 * Try to get boot info using BOOTP. If we succeed, then
260 * the server IP address, gateway, and root path will all
261 * be initialized. If any remain uninitialized, we will
262 * use RARP and RPC/bootparam (the Sun way) to get them.
263 */

--- 50 unchanged lines hidden (view full) ---

314#endif
315
316 /* Get the root server and pathname. */
317 if (bp_getfile(sock, "root", &rootip, rootpath)) {
318 printf("net_open: bootparam/getfile RPC failed\n");
319 return (EIO);
320 }
321exit:
305 /*
306 * If present, strip the server's address off of the rootpath
307 * before passing it along. This allows us to be compatible with
308 * the kernel's diskless (BOOTP_NFSROOT) booting conventions
309 */
310 for (i = 0; rootpath[i] != '\0' && i < FNAME_SIZE; i++)
311 if (rootpath[i] == ':')
312 break;
313 if (i && i != FNAME_SIZE && rootpath[i] == ':') {
314 rootpath[i++] = '\0';
315 if (inet_addr(&rootpath[0]) != INADDR_NONE)
316 rootip.s_addr = inet_addr(&rootpath[0]);
317 bcopy(&rootpath[i], &temp[0], strlen(&rootpath[i])+1);
318 bcopy(&temp[0], &rootpath[0], strlen(&rootpath[i])+1);
319 }
322 if ((rootaddr = net_parse_rootpath()) != INADDR_NONE)
323 rootip.s_addr = rootaddr;
324
320#ifdef NETIF_DEBUG
321 if (debug) {
322 printf("net_open: server addr: %s\n", inet_ntoa(rootip));
323 printf("net_open: server path: %s\n", rootpath);
324 }
325#endif
326
325#ifdef NETIF_DEBUG
326 if (debug) {
327 printf("net_open: server addr: %s\n", inet_ntoa(rootip));
328 printf("net_open: server path: %s\n", rootpath);
329 }
330#endif
331
327 d = socktodesc(sock);
328 sprintf(temp, "%6D", d->myea, ":");
329 setenv("boot.netif.ip", inet_ntoa(myip), 1);
330 setenv("boot.netif.netmask", intoa(netmask), 1);
331 setenv("boot.netif.gateway", inet_ntoa(gateip), 1);
332 setenv("boot.netif.hwaddr", temp, 1);
333 setenv("boot.nfsroot.server", inet_ntoa(rootip), 1);
334 setenv("boot.nfsroot.path", rootpath, 1);
335
336 return (0);
337}
338
339static void
340net_print(int verbose)
341{
342 struct netif_driver *drv;
343 int i, d, cnt;

--- 5 unchanged lines hidden (view full) ---

349 printf("\t%s%d:", "net", cnt++);
350 if (verbose)
351 printf(" (%s%d)", drv->netif_bname,
352 drv->netif_ifs[i].dif_unit);
353 }
354 }
355 printf("\n");
356}
332 return (0);
333}
334
335static void
336net_print(int verbose)
337{
338 struct netif_driver *drv;
339 int i, d, cnt;

--- 5 unchanged lines hidden (view full) ---

345 printf("\t%s%d:", "net", cnt++);
346 if (verbose)
347 printf(" (%s%d)", drv->netif_bname,
348 drv->netif_ifs[i].dif_unit);
349 }
350 }
351 printf("\n");
352}
353
354/*
355 * Strip the server's address off of the rootpath if present and return it in
356 * network byte order, leaving just the pathname part in the global rootpath.
357 */
358uint32_t
359net_parse_rootpath()
360{
361 int i;
362 n_long addr = INADDR_NONE;
363
364 for (i = 0; rootpath[i] != '\0' && i < FNAME_SIZE; i++)
365 if (rootpath[i] == ':')
366 break;
367 if (i && i != FNAME_SIZE && rootpath[i] == ':') {
368 rootpath[i++] = '\0';
369 addr = inet_addr(&rootpath[0]);
370 bcopy(&rootpath[i], rootpath, strlen(&rootpath[i])+1);
371 }
372 return (addr);
373}