Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/boot/bootip.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname boot/bootip.c 2000/0405
## diff -e /dev/null /n/emeliedump/2000/0405/sys/src/9/boot/bootip.c
0a
#include <u.h>
#include <libc.h>
#include <ip.h>

#include "boot.h"

static uchar	fsip[IPaddrlen];
static uchar	auip[IPaddrlen];
static char	mpoint[32];

static int isvalidip(uchar*);
static void netndb(char*, uchar*);

void
configip(void)
{
	int argc, pid, wpid;
	char **argv, *p;
	Waitmsg w;
	char **arg;
	char buf[32];
	
	fmtinstall('I', eipconv);
	fmtinstall('M', eipconv);
	fmtinstall('E', eipconv);

	arg = malloc((bargc+1) * sizeof(char*));
	if(arg == nil)
		fatal("%r");
	memmove(arg, bargv, (bargc+1) * sizeof(char*));

	argc = bargc;
	argv = arg;
	strcpy(mpoint, "/net");
	ARGBEGIN {
	case 'x':
		p = ARGF();
		if(p != nil)
			snprint(mpoint, sizeof(mpoint), "/net%s", p);
		break;
	case 'g':
	case 'b':
	case 'h':
	case 'm':
		ARGF();
		break;
	} ARGEND;

	/* bind in an ip interface */
	bind("#I", mpoint, MAFTER);
	bind("#l0", mpoint, MAFTER);
	bind("#l1", mpoint, MAFTER);

	/* let ipconfig configure the ip interface */
	switch(pid = fork()){
	case -1:
		fatal("configuring ip: %r");
	case 0:
		exec("/ipconfig", arg);
		fatal("execing /ipconfig");
	default:
		break;
	}

	/* wait for ipconfig to finish */
	for(;;){
		wpid = wait(&w);
		if(wpid == pid){
			if(w.msg[0] != 0)
				fatal(w.msg);
			break;
		} else if(wpid < 0)
			fatal("configuring ip");
	}

	/* if we didn't get a file and auth server, query user */
	netndb("fs", fsip);
	netndb("auth", auip);
	if(!isvalidip(fsip)){
		buf[0] = 0;
		outin("filesystem IP address", buf, sizeof(buf));
		parseip(fsip, buf);
	}
	if(!isvalidip(auip)){
		buf[0] = 0;
		outin("authentication server IP address", buf, sizeof(buf));
		parseip(auip, buf);
	}
}

void
configtcp(Method*)
{
	sleep(100);
	print("t");
	sleep(100);
	configip();
	sleep(100);
	print(".");
	sleep(100);
}

int
authtcp(void)
{
	return -1;
}

int
connecttcp(void)
{
	char buf[2*NAMELEN];

	sprint(buf, "tcp!%I!564", fsip);
	return dial(buf, 0, 0, 0);
}

void
configil(Method*)
{
	configip();
}

int
authil(void)
{
	char buf[2*NAMELEN];

	sprint(buf, "il!%I!566", auip);
	return dial(buf, 0, 0, 0);
}

int
connectil(void)
{
	char buf[2*NAMELEN];

	sprint(buf, "il!%I!17008", fsip);
	return dial(buf, 0, 0, 0);
}

static int
isvalidip(uchar *ip)
{
	if(ipcmp(ip, IPnoaddr) == 0)
		return 0;
	if(ipcmp(ip, v4prefix) == 0)
		return 0;
	return 1;
}

static void
netndb(char *attr, uchar *ip)
{
	int fd, n, c;
	char buf[1024];
	char *p;

	ipmove(ip, IPnoaddr);
	snprint(buf, sizeof(buf), "%s/ndb", mpoint);
	fd = open(buf, OREAD);
	if(fd < 0)
		return;
	n = read(fd, buf, sizeof(buf)-1);
	close(fd);
	if(n <= 0)
		return;
	buf[n] = 0;
	n = strlen(attr);
	for(p = buf;;){
		p = strstr(p, attr);
		if(p == nil)
			break;
		c = *(p-1);
		if(*(p + n) == '=' && (p == buf || c == '\n' || c == ' ' || c == '\t')){
			p += n+1;
			parseip(ip, p);
			break;
		}
		p++;
	}
}
.
## diffname boot/bootip.c 2000/0407
## diff -e /n/emeliedump/2000/0405/sys/src/9/boot/bootip.c /n/emeliedump/2000/0407/sys/src/9/boot/bootip.c
45c
		p = ARGF();
		USED(p);
.
## diffname boot/bootip.c 2000/0702
## diff -e /n/emeliedump/2000/0407/sys/src/9/boot/bootip.c /n/emeliedump/2000/0702/sys/src/9/boot/bootip.c
182a
	return;
.
179c
			return;
.
153a
netenv(char *attr, uchar *ip)
{
	int fd, n;
	char buf[128];

	ipmove(ip, IPnoaddr);
	snprint(buf, sizeof(buf), "#e/%s", attr);
	fd = open(buf, OREAD);
	if(fd < 0)
		return;

	n = read(fd, buf, sizeof(buf)-1);
	if(n <= 0)
		return;
	buf[n] = 0;
	parseip(ip, buf);
}

static void
.
85c

	netndb("auth", auip);
	if(!isvalidip(auip))
		netenv("auth", auip);
	while(!isvalidip(auip)){
.
79,80c
	if(!isvalidip(fsip))
		netenv("fs", fsip);
	while(!isvalidip(fsip)){
.
12a
static void netenv(char*, uchar*);
.
## diffname boot/bootip.c 2000/1021
## diff -e /n/emeliedump/2000/0702/sys/src/9/boot/bootip.c /n/emeliedump/2000/1021/sys/src/9/boot/bootip.c
59c
		fatal("configuring ip");
.
30c
		fatal("malloc");
.
## diffname boot/bootip.c 2000/1107
## diff -e /n/emeliedump/2000/1021/sys/src/9/boot/bootip.c /n/emeliedump/2000/1107/sys/src/9/boot/bootip.c
45a
	case 'c':
.
## diffname boot/bootip.c 2001/0214
## diff -e /n/emeliedump/2000/1107/sys/src/9/boot/bootip.c /n/emeliedump/2001/0214/sys/src/9/boot/bootip.c
146,147c
	sprint(buf, "tcp!%I!564", fsip);
	fd = dial(buf, 0, 0, 0);
	if(fd < 0)
		return -1;
	return pushfcall(fd);
.
144a
	int fd;
.
142c
connecttcp(void)
.
137c
	sprint(buf, "tcp!%I!567", auip);
.
133c
authtcp(void)
.
127c
configtcp(Method*)
.
122c
	sprint(buf, "il!%I!17008", fsip);
.
118c
connectil(void)
.
114c
	char buf[2*NAMELEN];

	sprint(buf, "il!%I!566", auip);
	return dial(buf, 0, 0, 0);
.
112c
authil(void)
.
106,108d
102,104d
100c
configil(Method*)
.
## diffname boot/bootip.c 2001/0527
## diff -e /n/emeliedump/2001/0214/sys/src/9/boot/bootip.c /n/emeliedump/2001/0527/sys/src/9/boot/bootip.c
144,148c
	snprint(buf, sizeof buf, "il!%I!17008", fsip);
	return dial(buf, 0, 0, 0);
.
141,142c
	char buf[64];
.
139c
connectil(void)
.
134c
	snprint(buf, sizeof buf, "il!%I!566", auip);
.
132c
	char buf[64];
.
130c
authil(void)
.
124c
configil(Method*)
.
119c
	snprint(buf, sizeof buf, "tcp!%I!564", fsip);
.
117c
	char buf[64];
.
115c
connecttcp(void)
.
108,111c
	return -1;
.
106c
authtcp(void)
.
102a
	sleep(100);
	print(".");
	sleep(100);
.
101a
	sleep(100);
	print("t");
	sleep(100);
.
100c
configtcp(Method*)
.
60c
		fatal("configuring ip: %r");
.
46d
30c
		fatal("%r");
.
## diffname boot/bootip.c 2001/0819
## diff -e /n/emeliedump/2001/0527/sys/src/9/boot/bootip.c /n/emeliedump/2001/0819/sys/src/9/boot/bootip.c
129,137c
	setauthaddr("il", 566);
.
111,116d
107a
	setauthaddr("tcp", 567);
.
97a
static void
setauthaddr(char *proto, int port)
{
	char buf[128];

	snprint(buf, sizeof buf, "%s!%I!%d", proto, auip, port);
	authaddr = strdup(buf);
}

.
75a
		free(w);
.
74c
		} else if(w == nil)
.
69,72c
		w = wait();
		if(w != nil && w->pid == pid){
			if(w->msg[0] != 0)
				fatal(w->msg);
			free(w);
.
20c
	Waitmsg *w;
.
18c
	int argc, pid;
.
7,9c
static	uchar	fsip[IPaddrlen];
	uchar	auip[IPaddrlen];
static	char	mpoint[32];
.
## diffname boot/bootip.c 2002/0217
## diff -e /n/emeliedump/2001/0819/sys/src/9/boot/bootip.c /n/emeliedump/2002/0217/sys/src/9/boot/bootip.c
24,26c
	fmtinstall('I', eipfmt);
	fmtinstall('M', eipfmt);
	fmtinstall('E', eipfmt);
.
## diffname boot/bootip.c 2002/0409
## diff -e /n/emeliedump/2002/0217/sys/src/9/boot/bootip.c /n/emeliedump/2002/0409/sys/src/9/boot/bootip.c
54a
	bind("#l2", mpoint, MAFTER);
	bind("#l3", mpoint, MAFTER);
.
## diffname boot/bootip.c 2002/0514
## diff -e /n/emeliedump/2002/0409/sys/src/9/boot/bootip.c /n/emeliedump/2002/0514/sys/src/9/boot/bootip.c
137c
	setauthaddr("tcp", 567);
.
## diffname boot/bootip.c 2002/0816
## diff -e /n/emeliedump/2002/0514/sys/src/9/boot/bootip.c /n/emeliedump/2002/0816/sys/src/9/boot/bootip.c
23c

.
## diffname boot/bootip.c 2002/1130
## diff -e /n/emeliedump/2002/0816/sys/src/9/boot/bootip.c /n/emeliedump/2002/1130/sys/src/9/boot/bootip.c
63c
		exec("/boot/ipconfig", arg);
.
## diffname boot/bootip.c 2002/1214
## diff -e /n/emeliedump/2002/1130/sys/src/9/boot/bootip.c /n/emeliedump/2002/1214/sys/src/9/boot/bootip.c
56a
	werrstr("");
.
## diffname boot/bootip.c 2003/0402
## diff -e /n/emeliedump/2002/1214/sys/src/9/boot/bootip.c /n/emeliedump/2003/0402/sys/src/9/boot/bootip.c
136a
	print("i");
.
116c
	print("t");	
.
## diffname boot/bootip.c 2003/0403
## diff -e /n/emeliedump/2003/0402/sys/src/9/boot/bootip.c /n/emeliedump/2003/0403/sys/src/9/boot/bootip.c
115d
## diffname boot/bootip.c 2003/0404
## diff -e /n/emeliedump/2003/0403/sys/src/9/boot/bootip.c /n/emeliedump/2003/0404/sys/src/9/boot/bootip.c
63a
		print("exec-ing ipconfig\n");
.
## diffname boot/bootip.c 2003/0405
## diff -e /n/emeliedump/2003/0404/sys/src/9/boot/bootip.c /n/emeliedump/2003/0405/sys/src/9/boot/bootip.c
64d
## diffname boot/bootip.c 2003/0409
## diff -e /n/emeliedump/2003/0405/sys/src/9/boot/bootip.c /n/emeliedump/2003/0409/sys/src/9/boot/bootip.c
136d
115d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].