Esempio n. 1
0
int
net_mountroot(void)
{

#ifdef DEBUG
	printf("net_mountroot\n");
#endif

	/*
	 * Get info for NFS boot: our IP address, our hostname,
	 * server IP address, and our root path on the server.
	 * There are two ways to do this:  The old, Sun way,
	 * and the more modern, BOOTP way. (RFC951, RFC1048)
	 */

#ifdef	SUN_BOOTPARAMS
	/* Get boot info using RARP and Sun bootparams. */

	/* Get our IP address.  (rarp.c) */
	if (rarp_getipaddress(netdev_sock) == -1)
		return errno;

	printf("boot: client IP address: %s\n", inet_ntoa(myip));

	/* Get our hostname, server IP address. */
	if (bp_whoami(netdev_sock))
		return (errno);

	printf("boot: client name: %s\n", hostname);

	/* Get the root pathname. */
	if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
		return (errno);

#else

	/* Get boot info using BOOTP way. (RFC951, RFC1048) */
	bootp(netdev_sock);

	printf("Using IP address: %s\n", inet_ntoa(myip));

	printf("myip: %s (%s)", hostname, inet_ntoa(myip));
	if (gateip)
		printf(", gateip: %s", inet_ntoa(gateip));
	if (netmask)
		printf(", netmask: %s", intoa(netmask));
	printf("\n");

#endif

	printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);

	/* Get the NFS file handle (mount). */
	if (nfs_mount(netdev_sock, rootip, rootpath) != 0)
		return (errno);
	return 0;
}
Esempio n. 2
0
File: main.c Progetto: yeonsh/Amoeba
/*
 * RARP/TFTP bootstrap loader consists of two phases. During the
 * first phase the loader tries to determine its IP address by
 * using the RARP protocol. The seconds phase consist of using
 * TFTP to download the program to be booted. First a TFTP read
 * file is tried with the first host that answered the RARP
 * request, if this fails a TFTP read file is broadcasted in the
 * hope that someone out there knows the file.
 */
main()
{
    ipaddr_t server = IP_BCASTADDR;
    int loaded = 0;

    /* initialize ethernet board, and random generator */
    printf("RARP/TFTP bootstrap loader\n\n");

    pkt_init();
    if (!eth_init()) {
	printf("No ethernet board found\n");
	halt();
    }
    srand(timer() ^ eth_myaddr[5]);

#ifdef MONITOR
    /*
     * When ever the user types CRTL BREAK we jump into
     * a special kind of monitor program.
     */
    printf("** Press <CTRL>-break to go to monitor **\n\n");
    if (brkhandler())
	monitor(server);
#endif

    /* actual RARP/TFTP bootstrap loader */
    if (rarp_getipaddress(&server)) {
	bootfile(file);
	if (!(loaded = tftp(server, ip_gateway, file)))
	    loaded = tftp(IP_BCASTADDR, ip_gateway, file);
    }

#ifdef MONITOR
    brkreset();
#endif
    eth_stop();

    if (loaded)
	execute();
    reboot();
}
Esempio n. 3
0
int
net_mountroot_bootparams(void)
{
	/* Get our IP address.  (rarp.c) */
	if (rarp_getipaddress(netdev_sock) == -1)
		return (errno);

	printf("Using BOOTPARAMS protocol: ");
	printf("ip address: %s", inet_ntoa(myip));

	/* Get our hostname, server IP address. */
	if (bp_whoami(netdev_sock))
		return (errno);

	printf(", hostname: %s\n", hostname);

	/* Get the root pathname. */
	if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
		return (errno);

	return (0);
}
Esempio n. 4
0
static int
net_getparams(int sock)
{
	char buf[MAXHOSTNAMELEN];
	n_long rootaddr, smask;

#ifdef	SUPPORT_BOOTP
	/*
	 * Try to get boot info using BOOTP.  If we succeed, then
	 * the server IP address, gateway, and root path will all
	 * be initialized.  If any remain uninitialized, we will
	 * use RARP and RPC/bootparam (the Sun way) to get them.
	 */
	if (try_bootp)
		bootp(sock, BOOTP_NONE);
	if (myip.s_addr != 0)
		goto exit;
#ifdef	NETIF_DEBUG
	if (debug)
		printf("net_open: BOOTP failed, trying RARP/RPC...\n");
#endif
#endif

	/*
	 * Use RARP to get our IP address.  This also sets our
	 * netmask to the "natural" default for our address.
	 */
	if (rarp_getipaddress(sock)) {
		printf("net_open: RARP failed\n");
		return (EIO);
	}
	printf("net_open: client addr: %s\n", inet_ntoa(myip));

	/* Get our hostname, server IP address, gateway. */
	if (bp_whoami(sock)) {
		printf("net_open: bootparam/whoami RPC failed\n");
		return (EIO);
	}
#ifdef	NETIF_DEBUG
	if (debug)
		printf("net_open: client name: %s\n", hostname);
#endif

	/*
	 * Ignore the gateway from whoami (unreliable).
	 * Use the "gateway" parameter instead.
	 */
	smask = 0;
	gateip.s_addr = 0;
	if (bp_getfile(sock, "gateway", &gateip, buf) == 0) {
		/* Got it!  Parse the netmask. */
		smask = ip_convertaddr(buf);
	}
	if (smask) {
		netmask = smask;
#ifdef	NETIF_DEBUG
		if (debug)
			printf("net_open: subnet mask: %s\n", intoa(netmask));
#endif
	}
#ifdef	NETIF_DEBUG
	if (gateip.s_addr && debug)
		printf("net_open: net gateway: %s\n", inet_ntoa(gateip));
#endif

	/* Get the root server and pathname. */
	if (bp_getfile(sock, "root", &rootip, rootpath)) {
		printf("net_open: bootparam/getfile RPC failed\n");
		return (EIO);
	}
exit:
	if ((rootaddr = net_parse_rootpath()) != INADDR_NONE)
		rootip.s_addr = rootaddr;

#ifdef	NETIF_DEBUG
	if (debug) {
		printf("net_open: server addr: %s\n", inet_ntoa(rootip));
		printf("net_open: server path: %s\n", rootpath);
	}
#endif

	return (0);
}
Esempio n. 5
0
int
netmountroot(struct open_file *f, char *devname)
{
	int error;
	struct iodesc *d;

#ifdef DEBUG
	printf("netmountroot: %s\n", devname);
#endif

	if (netio_ask) {
 get_my_ip:
		printf("My IP address? ");
		bzero(input_line, sizeof(input_line));
		gets(input_line);
		if ((myip.s_addr = inet_addr(input_line)) ==
		    htonl(INADDR_NONE)) {
			printf("invalid IP address: %s\n", input_line);
			goto get_my_ip;
		}

 get_my_netmask:
		printf("My netmask? ");
		bzero(input_line, sizeof(input_line));
		gets(input_line);
		if ((netmask = inet_addr(input_line)) ==
		    htonl(INADDR_NONE)) {
			printf("invalid netmask: %s\n", input_line);
			goto get_my_netmask;
		}

 get_my_gateway:
		printf("My gateway? ");
		bzero(input_line, sizeof(input_line));
		gets(input_line);
		if ((gateip.s_addr = inet_addr(input_line)) ==
		    htonl(INADDR_NONE)) {
			printf("invalid IP address: %s\n", input_line);
			goto get_my_gateway;
		}

 get_server_ip:
		printf("Server IP address? ");
		bzero(input_line, sizeof(input_line));
		gets(input_line);
		if ((rootip.s_addr = inet_addr(input_line)) ==
		    htonl(INADDR_NONE)) {
			printf("invalid IP address: %s\n", input_line);
			goto get_server_ip;
		}

 get_server_path:
		printf("Server path? ");
		bzero(rootpath, sizeof(rootpath));
		gets(rootpath);
		if (rootpath[0] == '\0' || rootpath[0] == '\n')
			goto get_server_path;

		if ((d = socktodesc(netdev_sock)) == NULL)
			return (EMFILE);

		d->myip = myip;

		goto do_nfs_mount;
	}

	/*
	 * Get info for NFS boot: our IP address, our hostname,
	 * server IP address, and our root path on the server.
	 * There are two ways to do this:  The old, Sun way,
	 * and the more modern, BOOTP way. (RFC951, RFC1048)
	 */

#ifdef	SUN_BOOTPARAMS
	/* Get boot info using RARP and Sun bootparams. */

	/* Get our IP address.  (rarp.c) */
	if (rarp_getipaddress(netdev_sock) == -1)
		return (errno);

	printf("boot: client IP address: %s\n", inet_ntoa(myip));

	/* Get our hostname, server IP address. */
	if (bp_whoami(netdev_sock))
		return (errno);

	printf("boot: client name: %s\n", hostname);

	/* Get the root pathname. */
	if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
		return (errno);

#else

	/* Get boot info using BOOTP way. (RFC951, RFC1048) */
	bootp(netdev_sock);

	printf("Using IP address: %s\n", inet_ntoa(myip));

	printf("myip: %s (%s)", hostname, inet_ntoa(myip));
	if (gateip)
		printf(", gateip: %s", inet_ntoa(gateip));
	if (mask)
		printf(", mask: %s", intoa(netmask));
	printf("\n");

#endif /* SUN_BOOTPARAMS */

	printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);

 do_nfs_mount:
	/* Get the NFS file handle (mount). */
	error = nfs_mount(netdev_sock, rootip, rootpath);

	return (error);
}
Esempio n. 6
0
static int
net_getparams(int sock)
{
    char buf[MAXHOSTNAMELEN];
    char temp[FNAME_SIZE];
    struct iodesc *d;
    int i;
    n_long smask;

#ifdef	SUPPORT_BOOTP
    /*
     * Try to get boot info using BOOTP.  If we succeed, then
     * the server IP address, gateway, and root path will all
     * be initialized.  If any remain uninitialized, we will
     * use RARP and RPC/bootparam (the Sun way) to get them.
     */
    if (try_bootp)
	bootp(sock, BOOTP_NONE);
    if (myip.s_addr != 0)
	goto exit;
    if (debug)
	printf("net_open: BOOTP failed, trying RARP/RPC...\n");
#endif

    /*
     * Use RARP to get our IP address.  This also sets our
     * netmask to the "natural" default for our address.
     */
    if (rarp_getipaddress(sock)) {
	printf("net_open: RARP failed\n");
	return (EIO);
    }
    printf("net_open: client addr: %s\n", inet_ntoa(myip));

    /* Get our hostname, server IP address, gateway. */
    if (bp_whoami(sock)) {
	printf("net_open: bootparam/whoami RPC failed\n");
	return (EIO);
    }
    printf("net_open: client name: %s\n", hostname);

    /*
     * Ignore the gateway from whoami (unreliable).
     * Use the "gateway" parameter instead.
     */
    smask = 0;
    gateip.s_addr = 0;
    if (bp_getfile(sock, "gateway", &gateip, buf) == 0) {
	/* Got it!  Parse the netmask. */
	smask = ip_convertaddr(buf);
    }
    if (smask) {
	netmask = smask;
	printf("net_open: subnet mask: %s\n", intoa(netmask));
    }
    if (gateip.s_addr)
	printf("net_open: net gateway: %s\n", inet_ntoa(gateip));

    /* Get the root server and pathname. */
    if (bp_getfile(sock, "root", &rootip, rootpath)) {
	printf("net_open: bootparam/getfile RPC failed\n");
	return (EIO);
    }
 exit:
    /*  
     * If present, strip the server's address off of the rootpath
     * before passing it along.  This allows us to be compatible with
     * the kernel's diskless (BOOTP_NFSROOT) booting conventions
     */
    for (i = 0; i < FNAME_SIZE && rootpath[i] != '\0'; i++)
	    if (rootpath[i] == ':')
		    break;
    if (i && i != FNAME_SIZE && rootpath[i] == ':') {
	    rootpath[i++] = '\0';
	    if (inet_addr(&rootpath[0]) != INADDR_NONE)
		    rootip.s_addr = inet_addr(&rootpath[0]);
	    memcpy(&temp[0], &rootpath[i], strlen(&rootpath[i])+1);
	    memcpy(&rootpath[0], &temp[0], strlen(&rootpath[i])+1);	    
    }
    printf("net_open: server addr: %s\n", inet_ntoa(rootip));
    printf("net_open: server path: %s\n", rootpath);	    

    d = socktodesc(sock);
    snprintf(temp, sizeof(temp), "%6D", d->myea, ":");
    setenv("boot.netif.ip", inet_ntoa(myip), 1);
    setenv("boot.netif.netmask", intoa(netmask), 1);
    setenv("boot.netif.gateway", inet_ntoa(gateip), 1);
    setenv("boot.netif.hwaddr", temp, 1);
    setenv("boot.nfsroot.server", inet_ntoa(rootip), 1);
    setenv("boot.nfsroot.path", rootpath, 1);

    return (0);
}
Esempio n. 7
0
int
net_devinit(struct open_file *f, struct netif_driver *drv, u_char *eaddr) {
	static struct netif best_if;
	struct iodesc *s;
	int r;

	if (inited)
		return 0;
	/* find a free socket */
	s = &desc;

	memset(s, 0, sizeof(*s));
	best_if.nif_driver = drv;
	s->io_netif = &best_if;
	memcpy(s->myea, eaddr, 6);

	/*
	 * Get info for NFS boot: our IP address, our hostname,
	 * server IP address, and our root path on the server.
	 * There are two ways to do this:  The old, Sun way,
	 * and the more modern, BOOTP way. (RFC951, RFC1048)
	 */

#ifdef SUPPORT_BOOTP

	/* Get boot info using BOOTP way. (RFC951, RFC1048) */
	printf("Trying BOOTP\n");
	bootp(0);

	if (myip.s_addr) {
		printf("Using IP address: %s\n", inet_ntoa(myip));

		printf("myip: %s (%s)\n", hostname, inet_ntoa(myip));
	} else

#endif /* SUPPORT_BOOTP */
	{
#ifdef	SUPPORT_BOOTPARAMS
		/* Get boot info using RARP and Sun bootparams. */

		printf("Trying BOOTPARAMS\n");
		/* Get our IP address.	(rarp.c) */
		if (rarp_getipaddress(0) == -1)
			return (errno);

		printf("boot: client IP address: %s\n", inet_ntoa(myip));

		/* Get our hostname, server IP address. */
		if (bp_whoami(0))
			return (errno);

		printf("boot: client name: %s\n", hostname);

		/* Get the root pathname. */
		if (bp_getfile(0, "root", &rootip, rootpath))
			return (errno);
#endif
	}
	printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
	f->f_devdata = s;

	/* Get the NFS file handle (mount). */
	r = nfs_mount(0, rootip, rootpath);
	if (r)
		return r;

	inited = 1;
	return 0;
}
Esempio n. 8
0
/*
 * Called by devopen after it sets f->f_dev to our devsw entry.
 * This opens the low-level device and sets f->f_devdata.
 */
int
net_open(struct open_file *f, ...)
{
	int error = 0;

#ifdef NET_DEBUG
	if (netdev_sock != -1)
	    panic("net_open");
#endif

	/* Find network interface. */
	if ((netdev_sock = netif_open()) < 0)
		return (ENXIO);

#ifdef SUPPORT_BOOTP
	printf("configure network...trying bootp\n");
	/* Get boot info using BOOTP way. (RFC951, RFC1048) */
	bootp(netdev_sock);
#endif

	if (myip.s_addr != INADDR_ANY) {	/* got bootp reply or
							 * manually set */

#ifdef TFTP_HACK
	    int             num, i;
	    /* XXX (some) tftp servers don't like leading "/" */
	    for (num = 0; bootfile[num] == '/'; num++);
	    for (i = 0; (bootfile[i] = bootfile[i + num]) != 0; i++);
#endif

	    printf("boot: client IP address: %s\n",
		   inet_ntoa(myip));
	    printf("boot: client name: %s\n", hostname);
	} else {

#ifdef SUPPORT_RARP
	    /*
	     * no answer, Get boot info using RARP and Sun
	     * bootparams.
	     */
	    printf("configure network...trying rarp\n");

	    /* Get our IP address.  (rarp.c) */
	    if (rarp_getipaddress(netdev_sock)) {
		error = EIO;
		goto bad;
	    }
	    printf("boot: client IP address: %s\n",
		   inet_ntoa(myip));

#ifdef SUPPORT_BOOTPARAM
	    /* Get our hostname, server IP address. */
	    if (!bp_whoami(netdev_sock)) {
		printf("boot: client name: %s\n", hostname);

		/* Get the root pathname. */
		bp_getfile(netdev_sock, "root", &rootip,
			   rootpath);
	    }
#else
	    /*
	     * else fallback: use rarp server address
	     */
#endif

#else				/* no SUPPORT_RARP */
	    error = EIO;
	    goto bad;
#endif

	}
	printf("boot: server: %s, rootpath: %s, bootfile: %s\n",
	       inet_ntoa(rootip), rootpath, bootfile);

	f->f_devdata = &netdev_sock;
	return (error);

bad:
	printf("net_open failed\n");
	netif_close(netdev_sock);
	return (error);
}