Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2007/0413/11

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


/sys/man/8/ipconfig /sys/src/cmd/ip/ipconfig.c
% cat >/sys/lib/dist/changes/1176503406.2.txt << EOF
•	Alphabetize options
•	Fix section formatting
•	More massive // to /* */! Yay.
•	Apparently, we're still too lazy to mail presotto a corrected array.
•	Fix usage()
•	Make ARGF usage consistent
•	Whitespace changes
•	Do extra argument checking and display usage() if it fails (mostly IP
parsing)

EOF
 [geoff] --rw-rw-r-- M 121 glenda sys 6209 Apr 13 18:13 sys/man/8/ipconfig
	/n/sourcesdump/2007/0413/plan9/sys/man/8/ipconfig:3,9 - 
	/n/sources/plan9/sys/man/8/ipconfig:3,9
	  ipconfig, rip \- Internet configuration and routing
	  .SH SYNOPSIS
	  .B ip/ipconfig
	- .RB [ -NDGPOdnpr ]
	+ .RB [ -DGNOPdnpr ]
	  .RB [ -b
	  .IR baud ]
	  .RB [ -c
	/n/sourcesdump/2007/0413/plan9/sys/man/8/ipconfig:20,25 - 
	/n/sources/plan9/sys/man/8/ipconfig:20,27
	  .IR dhcpoption ]
	  .I type
	  .I device
	+ .br
	+ .ti +0.5i
	  .RI [ verb ]
	  .RI [ local-addr ]
	  .RI [ mask ]
	/n/sourcesdump/2007/0413/plan9/sys/man/8/ipconfig:69,74 - 
	/n/sources/plan9/sys/man/8/ipconfig:71,77
	  The verb (default
	  .IR add )
	  determines the action performed.  The verbs are:
	+ .TF remove
	  .TP
	  .B add
	  if the device is not bound to the IP stack, bind it.
	/n/sourcesdump/2007/0413/plan9/sys/man/8/ipconfig:81,97 - 
	/n/sources/plan9/sys/man/8/ipconfig:84,98
	  .B unbind
	  unbind the device interface and all its addresses from the
	  IP stack.
	+ .PD
	  .PP
	  The options are:
	+ .TF M
	+ .PD
	  .TP
	  .B D
	  turn on debugging.
	  .TP
	- .B N
	- look in /lib/ndb for the IP parameters.  This only works if the
	- interface is an ethernet.  It uses the ethernet address to find
	- a matching entry.
	- .TP
	  .B G
	  use only generic DHCP options.  Without this option,
	  .I ipconfig
	/n/sourcesdump/2007/0413/plan9/sys/man/8/ipconfig:102,107 - 
	/n/sources/plan9/sys/man/8/ipconfig:103,115
	  Replies to these options contain a list of IP addresses for possible
	  file servers and auth servers.
	  .TP
	+ .B N
	+ look in
	+ .B /lib/ndb
	+ for the IP parameters.  This only works if the
	+ interface is an ethernet.  It uses the ethernet address to find
	+ a matching entry.
	+ .TP
	  .B p
	  write configuration information to
	  .BR /net/ndb ,
	/n/sourcesdump/2007/0413/plan9/sys/man/8/ipconfig:163,184 - 
	/n/sources/plan9/sys/man/8/ipconfig:171,195
	  result will appear in
	  .B /net/ndb
	  should this be the first interface.  The known options are:
	- .EX
	-   ipmask, timeoff, ipgw, time, name, dns, log, cookie,
	-   lpr, impress, rl, sys, bflen, dumpfile, dom, swap,
	-   rootpath, extpath, ipforward, nonlocal, policyfilter,
	-   maxdatagram, ttl, pathtimeout, pathplateau, mtu,
	-   subnetslocal, baddr, discovermask, supplymask,
	-   discoverrouter, rs, staticroutes, trailerencap,
	-   arptimeout, etherencap, tcpttl, tcpka, tcpkag,
	-   nisdomain, ni, ntp, netbiosns, netbiosdds,
	-   netbiostype, netbiosscope, xfont, xdispmanager,
	-   nisplusdomain, nisplus, homeagent, smtp, pop3, nntp,
	-   www, finger, irc, st, stdar, ipaddr, lease,
	-   overload, type, serverid, params, message, maxmsg,
	-   renewaltime, rebindingtime, vendorclass, clientid,
	-   tftp, bootfile
	- .EE
	+ .TP 0.5i
	+ \&
	+ .ft CW
	+ ipmask, timeoff, ipgw, time, name, dns, log, cookie,
	+ lpr, impress, rl, sys, bflen, dumpfile, dom, swap,
	+ rootpath, extpath, ipforward, nonlocal, policyfilter,
	+ maxdatagram, ttl, pathtimeout, pathplateau, mtu,
	+ subnetslocal, baddr, discovermask, supplymask,
	+ discoverrouter, rs, staticroutes, trailerencap,
	+ arptimeout, etherencap, tcpttl, tcpka, tcpkag,
	+ nisdomain, ni, ntp, netbiosns, netbiosdds,
	+ netbiostype, netbiosscope, xfont, xdispmanager,
	+ nisplusdomain, nisplus, homeagent, smtp, pop3, nntp,
	+ www, finger, irc, st, stdar, ipaddr, lease,
	+ overload, type, serverid, params, message, maxmsg,
	+ renewaltime, rebindingtime, vendorclass, clientid,
	+ tftp, bootfile
	+ .PD
	+ .LP
	  The options
	  .BR ipmask ,
	  .BR ipgw ,
	/n/sourcesdump/2007/0413/plan9/sys/man/8/ipconfig:187,198 - 
	/n/sources/plan9/sys/man/8/ipconfig:198,210
	  and
	  .B ntp
	  are always requested.
	+ .TF M
	+ .PD
	  .TP
	  .B O
	  addresses specified on the command line override those obtained
	  via DHCP.
	  A command line address of 0 implies no override.
	- .PD
	  .PP
	  If DHCP is requested, a process is forked
	  off to renew the lease before it
 [geoff] --rw-rw-r-- M 121 glenda sys 35429 Apr 13 18:14 sys/src/cmd/ip/ipconfig.c
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:21,27 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:21,27
	  
	  Ipifc	*ifc;
	  
	- // possible verbs
	+ /* possible verbs */
	  enum
	  {
	  	Vadd,
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:33,45 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:33,45
	  };
	  
	  struct {
	- 	// locally generated
	+ 	/* locally generated */
	  	char	*type;
	  	char	*dev;
	  	char	mpoint[32];
	- 	int	cfd;			// ifc control channel
	+ 	int	cfd;			/* ifc control channel */
	  	char	*cputype;
	- 	uchar	hwa[32];		// hardware address
	+ 	uchar	hwa[32];		/* hardware address */
	  	int	hwatype;
	  	int	hwalen;
	  	uchar	cid[32];
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:46,52 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:46,52
	  	int	cidlen;
	  	char	*baud;
	  
	- 	// learned info
	+ 	/* learned info */
	  	uchar	gaddr[IPaddrlen];
	  	uchar	laddr[IPaddrlen];
	  	uchar	mask[IPaddrlen];
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:57,63 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:57,63
	  	uchar	ntp[IPaddrlen];
	  	int	mtu;
	  
	- 	// dhcp specific
	+ 	/* dhcp specific */
	  	int	state;
	  	int	fd;
	  	ulong	xid;
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:89,97 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:89,99
	  	int	type;
	  };
	  
	- // I was too lazy to look up the types for each of these
	- // options.  If someone feels like it, please mail me a
	- // corrected array -- presotto
	+ /*
	+  * I was too lazy to look up the types for each of these
	+  * options.  If someone feels like it, please mail me a
	+  * corrected array -- presotto
	+  */
	  Option option[256] =
	  {
	  [OBmask]		{ "ipmask",		Taddr },
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:236,242 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:238,246
	  void
	  usage(void)
	  {
	- 	fprint(2, "usage: %s [-ndDrGX] [-x netmtpt] [-m mtu] [-b baud] [-g gateway] [-h hostname] [-c control-string]* type device [verb] [localaddr [mask [remoteaddr [fsaddr [authaddr]]]]]\n", argv0);
	+ 	fprint(2,
	+ "usage: %s [-ndDrGX] [-x netmtpt] [-m mtu] [-b baud] [-g gateway] [-h hostname] [-c ctlmsg]* type device [verb] [localaddr [mask [remoteaddr [fsaddr [authaddr]]]]]\n",
	+ 		argv0);
	  	exits("usage");
	  }
	  
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:261,267 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:265,271
	  	retry = 0;
	  	ctll = &firstctl;
	  
	- 	// init set of requested parameters with the default
	+ 	/* init set of requested parameters with the default */
	  	nrequested = sizeof(defrequested);
	  	memcpy(requested, defrequested, nrequested);
	  
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:284,298 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:288,296
	  	case 'P':
	  		beprimary = 0;
	  	case 'b':
	- 		p = ARGF();
	- 		if(p == nil)
	- 			usage();
	- 		conf.baud = p;
	+ 		conf.baud = EARGF(usage());
	  		break;
	  	case 'c':
	- 		p = ARGF();
	- 		if(p == nil)
	- 			usage();
	  		cp = malloc(sizeof(*cp));
	  		if(cp == nil)
	  			sysfatal("%r");
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:299,320 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:297,314
	  		*ctll = cp;
	  		ctll = &cp->next;
	  		cp->next = nil;
	- 		cp->ctl = p;
	+ 		cp->ctl = EARGF(usage());
	  		break;
	  	case 'd':
	  		dodhcp = 1;
	  		break;
	  	case 'g':
	- 		p = ARGF();
	- 		if(p == nil)
	+ 		if (parseip(conf.gaddr, EARGF(usage())) == -1)
	  			usage();
	- 		parseip(conf.gaddr, p);
	  		break;
	  	case 'h':
	- 		p = ARGF();
	- 		if(p == nil)
	- 			usage();
	- 		snprint(conf.hostname, sizeof(conf.hostname), "%s", p);
	+ 		snprint(conf.hostname, sizeof conf.hostname, "%s",
	+ 			EARGF(usage()));
	  		sendhostname = 1;
	  		break;
	  	case 'n':
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:321,350 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:315,341
	  		noconfig = 1;
	  		break;
	  	case 'm':
	- 		p = ARGF();
	- 		if(p == nil)
	- 			usage();
	- 		conf.mtu = atoi(p);
	+ 		conf.mtu = atoi(EARGF(usage()));
	  		break;
	  	case 'r':
	  		retry = 1;
	  		break;
	  	case 'x':
	- 		p = ARGF();
	- 		if(p == nil)
	- 			usage();
	- 		setnetmtpt(conf.mpoint, sizeof(conf.mpoint), p);
	+ 		setnetmtpt(conf.mpoint, sizeof conf.mpoint, EARGF(usage()));
	  		break;
	  	case 'X':
	  		nodhcpwatch = 1;
	  		break;
	  	case 'o':
	- 		if(addoption(ARGF()) < 0)
	+ 		if(addoption(EARGF(usage())) < 0)
	  			usage();
	  		break;
	+ 	default:
	+ 		usage();
	+ 		break;
	  	} ARGEND;
	  
	- 	// default to any host name we already have
	+ 	/* default to any host name we already have */
	  	if(*conf.hostname == 0){
	  		p = getenv("sysname");
	  		if(p == nil || *p == 0)
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:351,364 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:342,355
	  			p = sysname();
	  		if(p != nil)
	  			strncpy(conf.hostname, p, sizeof(conf.hostname)-1);
	- 	}		
	+ 	}
	  
	- 	// default
	+ 	/* default */
	  	conf.type = "ether";
	  	conf.dev = "/net/ether0";
	  	action = Vadd;
	  
	- 	// get verb, default is "add"
	+ 	/* get verb, default is "add" */
	  	while(argc > 0){
	  		verb = parseverb(argv[0]);
	  		switch(verb){
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:382,405 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:373,406
	  		argc--, argv++;
	  	}
	  
	- 	// get addresses
	+ 	/* get addresses */
	  	switch(argc){
	  	case 5:
	- 		parseip(conf.auth, argv[4]);
	+ 		if (parseip(conf.auth, argv[4]) == -1)
	+ 			usage();
	  		/* fall through */
	  	case 4:
	- 		parseip(conf.fs, argv[3]);
	+ 		if (parseip(conf.fs, argv[3]) == -1)
	+ 			usage();
	  		/* fall through */
	  	case 3:
	- 		parseip(conf.raddr, argv[2]);
	+ 		if (parseip(conf.raddr, argv[2]) == -1)
	+ 			usage();
	  		/* fall through */
	  	case 2:
	  		if(strcmp(argv[1], "0") != 0)
	- 			parseipmask(conf.mask, argv[1]);
	+ 			if (parseipmask(conf.mask, argv[1]) == -1)
	+ 				usage();
	  		/* fall through */
	  	case 1:
	- 		parseip(conf.laddr, argv[0]);
	+ 		if (parseip(conf.laddr, argv[0]) == -1)
	+ 			usage();
	  		break;
	+ 	case 0:
	+ 		break;
	+ 	default:
	+ 		usage();
	+ 		break;
	  	}
	  
	  	switch(action){
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:439,450 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:440,451
	  {
	  	int tries;
	  
	- 	// get number of preexisting interfaces
	+ 	/* get number of preexisting interfaces */
	  	nip = nipifcs(conf.mpoint);
	  	if(beprimary == -1 && (nip == 0 || !havendb(conf.mpoint)))
	  		beprimary = 1;
	  
	- 	// get ipifc into name space and condition device for ip
	+ 	/* get ipifc into name space and condition device for ip */
	  	if(!noconfig){
	  		lookforip(conf.mpoint);
	  		controldevice();
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:458,464 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:459,465
	  			dodhcp = 1;
	  	}
	  
	- 	// run dhcp if we need something
	+ 	/* run dhcp if we need something */
	  	if(dodhcp){
	  		mkclientid();
	  		for(tries = 0; tries < 6; tries++){
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:487,493 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:488,494
	  			dhcpwatch(0);
	  	}
	  
	- 	// leave everything we've learned somewhere other procs can find it
	+ 	/* leave everything we've learned somewhere other procs can find it */
	  	if(beprimary == 1){
	  		putndb();
	  		tweakservers();
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:555,561 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:556,562
	  	}
	  }
	  
	- // set the default route
	+ /* set the default route */
	  void
	  adddefroute(char *mpoint, uchar *gaddr)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:573,579 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:574,580
	  	close(cfd);
	  }
	  
	- // create a client id
	+ /* create a client id */
	  void
	  mkclientid(void)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:591,597 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:592,598
	  	}
	  }
	  
	- // bind ip into the namespace
	+ /* bind ip into the namespace */
	  void
	  lookforip(char *net)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:603,609 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:604,610
	  	sysfatal("no ip stack bound onto %s", net);
	  }
	  
	- // send some ctls to a device
	+ /* send some ctls to a device */
	  void
	  controldevice(void)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:628,636 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:629,638
	  			sysfatal("ctl message %s: %r", cp->ctl);
	  		seek(fd, 0, 0);
	  	}
	+ //	close(fd);		/* or does it need to be left hanging? */
	  }
	  
	- // bind an ip stack to a device, leave the control channel open
	+ /* bind an ip stack to a device, leave the control channel open */
	  void
	  binddevice(void)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:637,653 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:639,655
	  	char buf[256];
	  
	  	if(myifc < 0){
	- 		// get a new ip interface
	+ 		/* get a new ip interface */
	  		snprint(buf, sizeof(buf), "%s/ipifc/clone", conf.mpoint);
	  		conf.cfd = open(buf, ORDWR);
	  		if(conf.cfd < 0)
	  			sysfatal("opening %s/ipifc/clone: %r", conf.mpoint);
	  
	- 		// specify the medium as an ethernet, and bind the interface to it
	+ 		/* specify the medium as an ethernet, and bind the interface to it */
	  		if(fprint(conf.cfd, "bind %s %s", conf.type, conf.dev) < 0)
	  			sysfatal("binding device: %r");
	  	} else {
	- 		// open the old interface
	+ 		/* open the old interface */
	  		snprint(buf, sizeof(buf), "%s/ipifc/%d/ctl", conf.mpoint, myifc);
	  		conf.cfd = open(buf, ORDWR);
	  		if(conf.cfd < 0)
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:656,662 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:658,664
	  
	  }
	  
	- // add a logical interface to the ip stack
	+ /* add a logical interface to the ip stack */
	  int
	  ipconfig(void)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:690,696 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:692,698
	  	return 0;
	  }
	  
	- // remove a logical interface to the ip stack
	+ /* remove a logical interface to the ip stack */
	  void
	  ipunconfig(void)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:713,719 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:715,721
	  	ipmove(conf.raddr, IPnoaddr);
	  	ipmove(conf.mask, IPnoaddr);
	  
	- 	// forget configuration info
	+ 	/* forget configuration info */
	  	if(beprimary==1)
	  		writendb("", 0, 0);
	  }
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:739,745 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:741,747
	  	}
	  	notify(ding);
	  
	- 	// try dhcp for 10 seconds
	+ 	/* try dhcp for 10 seconds */
	  	conf.xid = lrand();
	  	conf.starttime = time(0);
	  	conf.state = startstate;
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:789,795 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:791,797
	  		break;
	  	}
	  
	- 	// keep trying to renew the lease
	+ 	/* keep trying to renew the lease */
	  	for(;;){
	  		if(conf.lease == 0)
	  			secs = 5;
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:796,802 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:798,804
	  		else
	  			secs = conf.lease>>1;
	  
	- 		// avoid overflows
	+ 		/* avoid overflows */
	  		for(s = secs; s > 0; s -= t){
	  			if(s > MAXSLEEP)
	  				t = MAXSLEEP;
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:806,813 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:808,817
	  		}
	  
	  		if(conf.lease > 0){
	- 			// during boot, the starttime can be bogus so avoid
	- 			// spurious ipinconfig's
	+ 			/*
	+ 			 * during boot, the starttime can be bogus so avoid
	+ 			 * spurious ipinconfig's
	+ 			 */
	  			t = time(0) - conf.starttime;
	  			if(t > (3*secs)/2)
	  				t = secs;
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:827,833 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:831,837
	  				sysfatal("can't start ip: %r");
	  			needconfig = 0;
	  
	- 			// leave everything we've learned somewhere other procs can find it
	+ 			/* leave everything we've learned somewhere other procs can find it */
	  			if(beprimary==1){
	  				putndb();
	  				tweakservers();
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:919,925 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:923,929
	  	default:
	  		sysfatal("dhcpsend: unknown message type: %d", type);
	  	case Discover:
	- 		ipmove(up->raddr, IPv4bcast);	// broadcast
	+ 		ipmove(up->raddr, IPv4bcast);	/* broadcast */
	  		if(*conf.hostname && sendhostname)
	  			p = optaddstr(p, OBhostname, conf.hostname);
	  		if(plan9){
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:937,947 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:941,951
	  			v6tov4(bp.ciaddr, conf.laddr);
	  			break;
	  		case Srebinding:
	- 			ipmove(up->raddr, IPv4bcast);	// broadcast
	+ 			ipmove(up->raddr, IPv4bcast);	/* broadcast */
	  			v6tov4(bp.ciaddr, conf.laddr);
	  			break;
	  		case Srequesting:
	- 			ipmove(up->raddr, IPv4bcast);	// broadcast
	+ 			ipmove(up->raddr, IPv4bcast);	/* broadcast */
	  			p = optaddaddr(p, ODipaddr, conf.laddr);
	  			p = optaddaddr(p, ODserverid, conf.server);
	  			break;
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:954,960 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:958,964
	  		p = optaddvec(p, ODparams, requested, nrequested);
	  		if(*conf.hostname && sendhostname)
	  			p = optaddstr(p, OBhostname, conf.hostname);
	- 		break;	
	+ 		break;
	  	case Release:
	  		ipmove(up->raddr, conf.server);
	  		v6tov4(bp.ciaddr, conf.laddr);
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1051,1057 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1055,1061
	  		if(conf.state != Srebinding)
	  			break;
	  
	- 		// ignore a bad lease
	+ 		/* ignore a bad lease */
	  		lease = optgetulong(bp->optdata, ODlease);
	  		if(lease == 0){
	  			/*
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1063,1069 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1067,1073
	  		}
	  		DEBUG("lease=%lud ", lease);
	  
	- 		// address and mask
	+ 		/* address and mask */
	  		if(!validip(conf.laddr) || !Oflag)
	  			v4tov6(conf.laddr, bp->yiaddr);
	  		if(!validip(conf.mask) || !Oflag){
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1072,1079 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1076,1085
	  		}
	  		DEBUG("ipaddr=%I ipmask=%M ", conf.laddr, conf.mask);
	  
	- 		// get a router address either from the router option
	- 		// or from the router that forwarded the dhcp packet
	+ 		/*
	+ 		 * get a router address either from the router option
	+ 		 * or from the router that forwarded the dhcp packet
	+ 		 */
	  		if(!validip(conf.gaddr) || !Oflag){
	  			if(optgetaddr(bp->optdata, OBrouter, conf.gaddr)){
	  				DEBUG("ipgw=%I ", conf.gaddr);
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1087,1093 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1093,1099
	  		else
	  			DEBUG("ipgw=%I ", conf.gaddr);
	  
	- 		// get dns servers
	+ 		/* get dns servers */
	  		memset(conf.dns, 0, sizeof(conf.dns));
	  		n = optgetaddrs(bp->optdata, OBdnserver, conf.dns,
	  				sizeof(conf.dns)/IPaddrlen);
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1094,1100 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1100,1106
	  		for(i = 0; i < n; i++)
	  			DEBUG("dns=%I ", conf.dns+i*IPaddrlen);
	  
	- 		// get ntp servers
	+ 		/* get ntp servers */
	  		memset(conf.ntp, 0, sizeof(conf.ntp));
	  		n = optgetaddrs(bp->optdata, OBntpserver, conf.ntp,
	  				sizeof(conf.ntp)/IPaddrlen);
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1101,1114 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1107,1120
	  		for(i = 0; i < n; i++)
	  			DEBUG("ntp=%I ", conf.ntp+i*IPaddrlen);
	  
	- 		// get names
	+ 		/* get names */
	  		optgetstr(bp->optdata, OBhostname, conf.hostname, sizeof(conf.hostname));
	  		optgetstr(bp->optdata, OBdomainname, conf.domainname, sizeof(conf.domainname));
	  
	- 		// get anything else we asked for
	+ 		/* get anything else we asked for */
	  		getoptions(bp->optdata);
	  
	- 		// get plan9 specific options
	+ 		/* get plan9 specific options */
	  		n = optgetvec(bp->optdata, OBvendorinfo, vopts, sizeof(vopts)-1);
	  		if(n > 0 && parseoptions(vopts, n) == 0){
	  			if(validip(conf.fs) && Oflag)
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1157,1163 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1163,1169
	  		if(!noconfig)
	  			sysfatal("can't announce for dhcp: %r");
	  
	- 		// might be another client - wait and try again
	+ 		/* might be another client - wait and try again */
	  		fprint(2, "%s: can't announce: %r\n", argv0);
	  		sleep((nrand(10)+1)*1000);
	  		if(n > 10)
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1228,1234 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1234,1240
	  {
	  	int n;
	  
	- 	n = strlen(v)+1;	// microsoft leaves on the null, so we do too
	+ 	n = strlen(v)+1;	/* microsoft leaves on the null, so we do too */
	  	p[0] = op;
	  	p[1] = n;
	  	memmove(p+2, v, n);
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1348,1356 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1354,1364
	  	return len;
	  }
	  
	- // sanity check options area
	- //	- options don't overflow packet
	- //	- options end with an OBend
	+ /*
	+  * sanity check options area
	+  * 	- options don't overflow packet
	+  * 	- options end with an OBend
	+  */
	  int
	  parseoptions(uchar *p, int n)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1377,1393 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1385,1403
	  			return -1;
	  		}
	  		p += len;
	- 		n -= len;		
	+ 		n -= len;
	  	}
	  
	- 	// make sure packet ends with an OBend all the optget code
	+ 	/* make sure packet ends with an OBend all the optget code */
	  	*p = OBend;
	  	return 0;
	  }
	  
	- //  sanity check received packet:
	- //	- magic is dhcp magic
	- //	- options don't overflow packet
	+ /*
	+  * sanity check received packet:
	+  * 	- magic is dhcp magic
	+  * 	- options don't overflow packet
	+  */
	  Bootp *
	  parsebootp(uchar *p, int n)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1427,1433 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1437,1443
	  	return bp;
	  }
	  
	- // write out an ndb entry
	+ /* write out an ndb entry */
	  void
	  writendb(char *s, int n, int append)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1444,1450 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1454,1460
	  	close(fd);
	  }
	  
	- // put server addresses into the ndb entry
	+ /* put server addresses into the ndb entry */
	  char*
	  putaddrs(char *p, char *e, char *attr, uchar *a, int len)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1458,1464 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1468,1474
	  	return p;
	  }
	  
	- // make an ndb entry and put it into /net/ndb for the servers to see
	+ /* make an ndb entry and put it into /net/ndb for the servers to see */
	  void
	  putndb(void)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1498,1510 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1508,1519
	  		writendb(buf, p-buf, append);
	  }
	  
	- // get an ndb entry someone else wrote
	+ /* get an ndb entry someone else wrote */
	  int
	  getndb(void)
	  {
	  	char buf[1024];
	- 	int fd;
	- 	int n;
	+ 	int fd, n;
	  	char *p;
	  
	  	snprint(buf, sizeof buf, "%s/ndb", conf.mpoint);
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1522,1528 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1531,1537
	  	return 0;
	  }
	  
	- // tell a server to refresh
	+ /* tell a server to refresh */
	  void
	  tweakserver(char *server)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1537,1543 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1546,1552
	  	close(fd);
	  }
	  
	- // tell all servers to refresh their information
	+ /* tell all servers to refresh their information */
	  void
	  tweakservers(void)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1545,1551 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1554,1560
	  	tweakserver("cs");
	  }
	  
	- // return number of networks
	+ /* return number of networks */
	  int
	  nipifcs(char *net)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1572,1578 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1581,1587
	  	return n;
	  }
	  
	- // return true if this is a valid v4 address
	+ /* return true if this is a valid v4 address */
	  int
	  validip(uchar *addr)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1584,1609 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1593,1615
	  [Vremove]	"remove",
	  [Vunbind]	"unbind",
	  [Vether]	"ether",
	- [Vgbe]	"gbe",
	+ [Vgbe]		"gbe",
	  [Vloopback]	"loopback",
	  };
	  
	- // look for an action
	+ /* look for an action */
	  int
	  parseverb(char *name)
	  {
	  	int i;
	  
	- 	for(i = 0; i < nelem(verbs); i++){
	- 		if(verbs[i] == 0)
	- 			continue;
	- 		if(strcmp(name, verbs[i]) == 0)
	+ 	for(i = 0; i < nelem(verbs); i++)
	+ 		if(verbs[i] != nil && strcmp(name, verbs[i]) == 0)
	  			return i;
	- 	}
	  	return -1;
	  }
	  
	- // get everything out of ndb
	+ /* get everything out of ndb */
	  void
	  ndbconfig(void)
	  {
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1619,1625 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1625,1632
	  	db = ndbopen(0);
	  	if(db == nil)
	  		sysfatal("can't open ndb: %r");
	- 	if((strcmp(conf.type, "ether") != 0 && strcmp(conf.type, "gbe") != 0) || myetheraddr(conf.hwa, conf.dev) != 0)
	+ 	if((strcmp(conf.type, "ether") != 0 && strcmp(conf.type, "gbe") != 0) ||
	+ 	    myetheraddr(conf.hwa, conf.dev) != 0)
	  		sysfatal("can't read hardware address");
	  	sprint(etheraddr, "%E", conf.hwa);
	  	nattr = 0;
	/n/sourcesdump/2007/0413/plan9/sys/src/cmd/ip/ipconfig.c:1632,1654 - 
	/n/sources/plan9/sys/src/cmd/ip/ipconfig.c:1639,1659
	  	attrs[nattr++] = "@auth";
	  	attrs[nattr] = nil;
	  	t = ndbipinfo(db, "ether", etheraddr, attrs, nattr);
	- 	for(nt = t; nt != nil; nt = nt->entry){
	- 		if(strcmp(nt->attr, "ip") == 0){
	+ 	for(nt = t; nt != nil; nt = nt->entry)
	+ 		if(strcmp(nt->attr, "ip") == 0)
	  			parseip(conf.laddr, nt->val);
	- 		} else if(strcmp(nt->attr, "ipmask") == 0){
	+ 		else if(strcmp(nt->attr, "ipmask") == 0)
	  			parseipmask(conf.mask, nt->val);
	- 		} else if(strcmp(nt->attr, "ipgw") == 0){
	+ 		else if(strcmp(nt->attr, "ipgw") == 0)
	  			parseip(conf.gaddr, nt->val);
	- 		} else if(ndns < 2 && strcmp(nt->attr, "dns") == 0){
	+ 		else if(ndns < 2 && strcmp(nt->attr, "dns") == 0)
	  			parseip(conf.dns+IPaddrlen*ndns, nt->val);
	- 		} else if(strcmp(nt->attr, "ntp") == 0){
	+ 		else if(strcmp(nt->attr, "ntp") == 0)
	  			parseip(conf.ntp, nt->val);
	- 		} else if(nfs < 2 && strcmp(nt->attr, "fs") == 0){
	+ 		else if(nfs < 2 && strcmp(nt->attr, "fs") == 0)
	  			parseip(conf.fs+IPaddrlen*nfs, nt->val);
	- 		} else if(nauth < 2 && strcmp(nt->attr, "auth") == 0){
	+ 		else if(nauth < 2 && strcmp(nt->attr, "auth") == 0)
	  			parseip(conf.auth+IPaddrlen*nauth, nt->val);
	- 		}
	- 	}
	  	ndbfree(t);
	  	if(!validip(conf.laddr))
	  		sysfatal("address not found in ndb");


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.