Browse Source

Plan 9 from Bell Labs 2007-04-19

David du Colombier 14 years ago
parent
commit
e74a8ae07a
11 changed files with 241 additions and 336 deletions
  1. 13 16
      dist/replica/_plan9.db
  2. 9 8
      dist/replica/plan9.db
  3. 9 0
      dist/replica/plan9.log
  4. 9 0
      sys/man/2/ndb
  5. 0 3
      sys/man/6/ndb
  6. 1 1
      sys/man/8/ndb
  7. 12 15
      sys/src/9/ip/icmp6.c
  8. 112 187
      sys/src/9/ip/ipifc.c
  9. 72 102
      sys/src/9/ip/ipv6.c
  10. 2 2
      sys/src/cmd/ndb/cs.c
  11. 2 2
      sys/src/libndb/ndbipinfo.c

+ 13 - 16
dist/replica/_plan9.db

@@ -341,10 +341,10 @@
 386/bin/ndb - 20000000775 sys sys 985743147 0
 386/bin/ndb/cs - 775 sys sys 1176488417 150835
 386/bin/ndb/csquery - 775 sys sys 1176488418 61652
-386/bin/ndb/dns - 775 sys sys 1175972560 287154
-386/bin/ndb/dnsdebug - 775 sys sys 1176752973 261943
+386/bin/ndb/dns - 775 sys sys 1176866482 286892
+386/bin/ndb/dnsdebug - 775 sys sys 1176866483 261751
 386/bin/ndb/dnsquery - 775 sys sys 1174704818 64417
-386/bin/ndb/dnstcp - 775 sys sys 1175972561 260477
+386/bin/ndb/dnstcp - 775 sys sys 1176866483 260215
 386/bin/ndb/ipquery - 775 sys sys 1176488418 96918
 386/bin/ndb/mkdb - 775 sys sys 1168402340 64211
 386/bin/ndb/mkhash - 775 sys sys 1176488418 84704
@@ -471,7 +471,7 @@
 386/bin/upas/runq - 775 sys sys 1176520509 114236
 386/bin/upas/scanmail - 775 sys sys 1176520510 129604
 386/bin/upas/send - 775 sys sys 1176520510 193434
-386/bin/upas/smtp - 775 sys sys 1176520511 275966
+386/bin/upas/smtp - 775 sys sys 1176866484 276173
 386/bin/upas/smtpd - 775 sys sys 1176520511 332397
 386/bin/upas/spam - 775 sys sys 1064598366 36
 386/bin/upas/testscan - 775 sys sys 1176520512 83863
@@ -7555,7 +7555,7 @@ sys/man/2/mouse - 664 sys sys 1140900146 4952
 sys/man/2/mp - 664 sys sys 1140106703 10762
 sys/man/2/muldiv - 664 sys sys 984709633 639
 sys/man/2/nan - 664 sys sys 975084242 937
-sys/man/2/ndb - 664 sys sys 1173401633 9573
+sys/man/2/ndb - 664 sys sys 1176932123 9743
 sys/man/2/notify - 664 sys sys 1032058674 6376
 sys/man/2/object - 664 sys sys 944959695 3864
 sys/man/2/open - 664 sys sys 1015091524 3404
@@ -7726,7 +7726,7 @@ sys/man/6/mnihongo - 664 sys sys 1158064572 716
 sys/man/6/mpictures - 664 sys sys 944959678 2899
 sys/man/6/ms - 664 sys sys 958249504 6815
 sys/man/6/namespace - 664 sys sys 1048637182 1576
-sys/man/6/ndb - 664 sys sys 1174770884 6755
+sys/man/6/ndb - 664 sys sys 1176932139 6671
 sys/man/6/plot - 664 sys sys 944959679 6739
 sys/man/6/plumb - 664 sys sys 969499892 10918
 sys/man/6/regexp - 664 sys sys 954089523 2050
@@ -7784,7 +7784,7 @@ sys/man/8/mkpaqfs - 664 sys sys 1018386778 892
 sys/man/8/mksacfs - 664 sys sys 964886843 710
 sys/man/8/mouse - 664 sys sys 971455511 2476
 sys/man/8/na - 664 sys sys 958527089 859
-sys/man/8/ndb - 664 sys sys 1175725007 13255
+sys/man/8/ndb - 664 sys sys 1176932150 13254
 sys/man/8/newuser - 664 sys sys 1116954242 2418
 sys/man/8/nfsserver - 664 sys sys 1163208425 3587
 sys/man/8/pcmcia - 664 sys sys 944959679 408
@@ -7945,17 +7945,17 @@ sys/src/9/ip/esp.c - 664 sys sys 1047260561 17084
 sys/src/9/ip/ethermedium.c - 664 sys sys 1115565973 15592
 sys/src/9/ip/gre.c - 664 sys sys 1115566178 5069
 sys/src/9/ip/icmp.c - 664 sys sys 1134390100 9496
-sys/src/9/ip/icmp6.c - 664 sys sys 1176844023 17914
+sys/src/9/ip/icmp6.c - 664 sys sys 1176937812 17893
 sys/src/9/ip/igmp.c - 664 sys sys 1055700768 5175
 sys/src/9/ip/il.c - 664 sys sys 1134498903 27226
 sys/src/9/ip/inferno.c - 664 sys sys 1022588098 517
 sys/src/9/ip/ip.c - 664 sys sys 1101906449 15285
 sys/src/9/ip/ip.h - 664 sys sys 1162907930 15760
 sys/src/9/ip/ipaux.c - 664 sys sys 1079538100 12862
-sys/src/9/ip/ipifc.c - 664 sys sys 1168305861 34233
+sys/src/9/ip/ipifc.c - 664 sys sys 1176937940 33863
 sys/src/9/ip/ipmux.c - 664 sys sys 1047260566 15362
 sys/src/9/ip/iproute.c - 664 sys sys 1168305878 14778
-sys/src/9/ip/ipv6.c - 664 sys sys 1047951328 14433
+sys/src/9/ip/ipv6.c - 664 sys sys 1176938017 14297
 sys/src/9/ip/ipv6.h - 664 sys sys 1176844019 4087
 sys/src/9/ip/loopbackmedium.c - 664 sys sys 1055701769 1671
 sys/src/9/ip/netdevmedium.c - 664 sys sys 1045063517 2675
@@ -12508,6 +12508,7 @@ sys/src/cmd/ip/imap4d/nodes.c - 664 sys sys 1015013077 3173
 sys/src/cmd/ip/imap4d/search.c - 664 sys sys 1015013077 4520
 sys/src/cmd/ip/imap4d/store.c - 664 sys sys 1066317059 1910
 sys/src/cmd/ip/imap4d/utils.c - 664 sys sys 1168894057 2587
+sys/src/cmd/ip/ipconfig - 20000000775 sys sys 1176933436 0
 sys/src/cmd/ip/ipconfig.c - 664 sys sys 1176502464 35429
 sys/src/cmd/ip/measure.c - 664 sys sys 944961011 3733
 sys/src/cmd/ip/mkfile - 664 sys sys 1169163575 1250
@@ -12784,7 +12785,7 @@ sys/src/cmd/mv.c - 664 sys sys 1163029439 4682
 sys/src/cmd/ndb - 20000000775 sys sys 1080135004 0
 sys/src/cmd/ndb/convDNS2M.c - 664 sys sys 1175901489 6927
 sys/src/cmd/ndb/convM2DNS.c - 664 sys sys 1175901582 11659
-sys/src/cmd/ndb/cs.c - 664 sys sys 1163208159 33080
+sys/src/cmd/ndb/cs.c - 664 sys sys 1176931848 33123
 sys/src/cmd/ndb/csquery.c - 664 sys sys 1174626119 1073
 sys/src/cmd/ndb/dblookup.c - 664 sys sys 1175901604 21010
 sys/src/cmd/ndb/dn.c - 664 sys sys 1175925585 32939
@@ -15540,7 +15541,7 @@ sys/src/libndb/ndbgetipaddr.c - 664 sys sys 1144174489 876
 sys/src/libndb/ndbgetval.c - 664 sys sys 1144174490 1348
 sys/src/libndb/ndbhash.c - 664 sys sys 1144174490 5276
 sys/src/libndb/ndbhf.h - 664 sys sys 1015013485 746
-sys/src/libndb/ndbipinfo.c - 664 sys sys 1157899101 5127
+sys/src/libndb/ndbipinfo.c - 664 sys sys 1176931776 5181
 sys/src/libndb/ndblookval.c - 664 sys sys 1078839929 791
 sys/src/libndb/ndbopen.c - 664 sys sys 1173737251 2717
 sys/src/libndb/ndbparse.c - 664 sys sys 1144174490 1207
@@ -15801,7 +15802,3 @@ usr/glenda/lib/profile - 664 glenda glenda 1105128663 890
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
-386/bin/ndb/dns - 775 sys sys 1176866482 286892
-386/bin/ndb/dnsdebug - 775 sys sys 1176866483 261751
-386/bin/ndb/dnstcp - 775 sys sys 1176866483 260215
-386/bin/upas/smtp - 775 sys sys 1176866484 276173

+ 9 - 8
dist/replica/plan9.db

@@ -7555,7 +7555,7 @@ sys/man/2/mouse - 664 sys sys 1140900146 4952
 sys/man/2/mp - 664 sys sys 1140106703 10762
 sys/man/2/muldiv - 664 sys sys 984709633 639
 sys/man/2/nan - 664 sys sys 975084242 937
-sys/man/2/ndb - 664 sys sys 1173401633 9573
+sys/man/2/ndb - 664 sys sys 1176932123 9743
 sys/man/2/notify - 664 sys sys 1032058674 6376
 sys/man/2/object - 664 sys sys 944959695 3864
 sys/man/2/open - 664 sys sys 1015091524 3404
@@ -7726,7 +7726,7 @@ sys/man/6/mnihongo - 664 sys sys 1158064572 716
 sys/man/6/mpictures - 664 sys sys 944959678 2899
 sys/man/6/ms - 664 sys sys 958249504 6815
 sys/man/6/namespace - 664 sys sys 1048637182 1576
-sys/man/6/ndb - 664 sys sys 1174770884 6755
+sys/man/6/ndb - 664 sys sys 1176932139 6671
 sys/man/6/plot - 664 sys sys 944959679 6739
 sys/man/6/plumb - 664 sys sys 969499892 10918
 sys/man/6/regexp - 664 sys sys 954089523 2050
@@ -7784,7 +7784,7 @@ sys/man/8/mkpaqfs - 664 sys sys 1018386778 892
 sys/man/8/mksacfs - 664 sys sys 964886843 710
 sys/man/8/mouse - 664 sys sys 971455511 2476
 sys/man/8/na - 664 sys sys 958527089 859
-sys/man/8/ndb - 664 sys sys 1175725007 13255
+sys/man/8/ndb - 664 sys sys 1176932150 13254
 sys/man/8/newuser - 664 sys sys 1116954242 2418
 sys/man/8/nfsserver - 664 sys sys 1163208425 3587
 sys/man/8/pcmcia - 664 sys sys 944959679 408
@@ -7945,17 +7945,17 @@ sys/src/9/ip/esp.c - 664 sys sys 1047260561 17084
 sys/src/9/ip/ethermedium.c - 664 sys sys 1115565973 15592
 sys/src/9/ip/gre.c - 664 sys sys 1115566178 5069
 sys/src/9/ip/icmp.c - 664 sys sys 1134390100 9496
-sys/src/9/ip/icmp6.c - 664 sys sys 1176844023 17914
+sys/src/9/ip/icmp6.c - 664 sys sys 1176937812 17893
 sys/src/9/ip/igmp.c - 664 sys sys 1055700768 5175
 sys/src/9/ip/il.c - 664 sys sys 1134498903 27226
 sys/src/9/ip/inferno.c - 664 sys sys 1022588098 517
 sys/src/9/ip/ip.c - 664 sys sys 1101906449 15285
 sys/src/9/ip/ip.h - 664 sys sys 1162907930 15760
 sys/src/9/ip/ipaux.c - 664 sys sys 1079538100 12862
-sys/src/9/ip/ipifc.c - 664 sys sys 1168305861 34233
+sys/src/9/ip/ipifc.c - 664 sys sys 1176937940 33863
 sys/src/9/ip/ipmux.c - 664 sys sys 1047260566 15362
 sys/src/9/ip/iproute.c - 664 sys sys 1168305878 14778
-sys/src/9/ip/ipv6.c - 664 sys sys 1047951328 14433
+sys/src/9/ip/ipv6.c - 664 sys sys 1176938017 14297
 sys/src/9/ip/ipv6.h - 664 sys sys 1176844019 4087
 sys/src/9/ip/loopbackmedium.c - 664 sys sys 1055701769 1671
 sys/src/9/ip/netdevmedium.c - 664 sys sys 1045063517 2675
@@ -12508,6 +12508,7 @@ sys/src/cmd/ip/imap4d/nodes.c - 664 sys sys 1015013077 3173
 sys/src/cmd/ip/imap4d/search.c - 664 sys sys 1015013077 4520
 sys/src/cmd/ip/imap4d/store.c - 664 sys sys 1066317059 1910
 sys/src/cmd/ip/imap4d/utils.c - 664 sys sys 1168894057 2587
+sys/src/cmd/ip/ipconfig - 20000000775 sys sys 1176933436 0
 sys/src/cmd/ip/ipconfig.c - 664 sys sys 1176502464 35429
 sys/src/cmd/ip/measure.c - 664 sys sys 944961011 3733
 sys/src/cmd/ip/mkfile - 664 sys sys 1169163575 1250
@@ -12784,7 +12785,7 @@ sys/src/cmd/mv.c - 664 sys sys 1163029439 4682
 sys/src/cmd/ndb - 20000000775 sys sys 1080135004 0
 sys/src/cmd/ndb/convDNS2M.c - 664 sys sys 1175901489 6927
 sys/src/cmd/ndb/convM2DNS.c - 664 sys sys 1175901582 11659
-sys/src/cmd/ndb/cs.c - 664 sys sys 1163208159 33080
+sys/src/cmd/ndb/cs.c - 664 sys sys 1176931848 33123
 sys/src/cmd/ndb/csquery.c - 664 sys sys 1174626119 1073
 sys/src/cmd/ndb/dblookup.c - 664 sys sys 1175901604 21010
 sys/src/cmd/ndb/dn.c - 664 sys sys 1175925585 32939
@@ -15540,7 +15541,7 @@ sys/src/libndb/ndbgetipaddr.c - 664 sys sys 1144174489 876
 sys/src/libndb/ndbgetval.c - 664 sys sys 1144174490 1348
 sys/src/libndb/ndbhash.c - 664 sys sys 1144174490 5276
 sys/src/libndb/ndbhf.h - 664 sys sys 1015013485 746
-sys/src/libndb/ndbipinfo.c - 664 sys sys 1157899101 5127
+sys/src/libndb/ndbipinfo.c - 664 sys sys 1176931776 5181
 sys/src/libndb/ndblookval.c - 664 sys sys 1078839929 791
 sys/src/libndb/ndbopen.c - 664 sys sys 1173737251 2717
 sys/src/libndb/ndbparse.c - 664 sys sys 1144174490 1207

+ 9 - 0
dist/replica/plan9.log

@@ -48414,3 +48414,12 @@
 1176867006 1 c 386/bin/ndb/dnsdebug - 775 sys sys 1176866483 261751
 1176867006 2 c 386/bin/ndb/dnstcp - 775 sys sys 1176866483 260215
 1176867006 3 c 386/bin/upas/smtp - 775 sys sys 1176866484 276173
+1176931805 0 c sys/src/cmd/ndb/cs.c - 664 sys sys 1176931848 33123
+1176931805 1 c sys/src/libndb/ndbipinfo.c - 664 sys sys 1176931776 5181
+1176933607 0 c sys/man/2/ndb - 664 sys sys 1176932123 9743
+1176933607 1 c sys/man/6/ndb - 664 sys sys 1176932139 6671
+1176933607 2 c sys/man/8/ndb - 664 sys sys 1176932150 13254
+1176933607 3 a sys/src/cmd/ip/ipconfig - 20000000775 sys sys 1176933436 0
+1176939006 0 c sys/src/9/ip/icmp6.c - 664 sys sys 1176937812 17893
+1176939006 1 c sys/src/9/ip/ipifc.c - 664 sys sys 1176937940 33863
+1176939006 2 c sys/src/9/ip/ipv6.c - 664 sys sys 1176938017 14297

+ 9 - 0
sys/man/2/ndb

@@ -262,6 +262,15 @@ attributes in the
 .I n
 element array
 .IR attrs .
+If any
+.I attrs
+begin with
+.LR @ ,
+the
+.L @
+is excluded from the attribute name,
+but causes any corresponding value returned
+to be a resolved IP address(es), not a name.
 For example, consider the following database entries describing a network,
 a subnetwork, and a system.
 .IP

+ 0 - 3
sys/man/6/ndb

@@ -241,9 +241,6 @@ pairs.
 .B dns
 a DNS server to use (for DNS and DHCP)
 .TP
-.B @dns
-a DNS server to forward queries to when running as a resolver (for DNS)
-.TP
 .B ntp
 an NTP server to use (for DHCP)
 .TP

+ 1 - 1
sys/man/8/ndb

@@ -297,7 +297,7 @@ If present,
 must be a space-separated list of such DNS servers' IP addresses,
 otherwise optional
 .IR ndb (6)
-.B @dns
+.B dns
 attributes name DNS servers to forward queries to.
 .TP
 .B -R

+ 12 - 15
sys/src/9/ip/icmp6.c

@@ -284,10 +284,10 @@ icmpctl6(Conv *c, char **argv, int argc)
 static void
 goticmpkt6(Proto *icmp, Block *bp, int muxkey)
 {
-	ushort	recid;
-	uchar 	*addr;
-	Conv	**c, *s;
-	IPICMP	*p = (IPICMP *)bp->rp;
+	ushort recid;
+	uchar *addr;
+	Conv **c, *s;
+	IPICMP *p = (IPICMP *)bp->rp;
 
 	if(muxkey == 0) {
 		recid = nhgets(p->icmpid);
@@ -609,12 +609,12 @@ valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv)
 				goto err;
 			}
 
-			if(p->type == NbrSolicit)
-				if(ipcmp(np->src, v6Unspecified) == 0)
-					if(!issmcast(np->dst) || optexsts(np)) {
-						ipriv->stats[AddrmxpErrs6]++;
-						goto err;
-					}
+			if (p->type == NbrSolicit &&
+			    ipcmp(np->src, v6Unspecified) == 0)
+				if(!issmcast(np->dst) || optexsts(np)) {
+					ipriv->stats[AddrmxpErrs6]++;
+					goto err;
+				}
 
 			if(p->type == NbrAdvert)
 				if(isv6mcast(np->dst) &&
@@ -670,9 +670,7 @@ valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv)
 			goto err;
 		}
 	}
-
 	return 1;
-
 err:
 	ipriv->stats[InErrors6]++;
 	return 0;
@@ -692,7 +690,7 @@ targettype(Fs *f, Ipifc *ifc, uchar *target)
 
 	for(lifc = ifc->lifc; lifc; lifc = lifc->next)
 		if(ipcmp(lifc->local, target) == 0) {
-			t = (lifc->tentative) ? t_unitent : t_unirany;
+			t = (lifc->tentative)? t_unitent: t_unirany;
 			runlock(ifc);
 			return t;
 		}
@@ -761,7 +759,7 @@ icmpiput6(Proto *icmp, Ipifc *ipifc, Block *bp)
 			}
 			p = (IPICMP *)bp->rp;
 			pr = Fsrcvpcolx(icmp->f, p->proto);
-			if(pr != nil && pr->advise != nil) {
+			if(pr && pr->advise) {
 				(*pr->advise)(pr, bp, m2);
 				return;
 			}
@@ -837,7 +835,6 @@ icmpiput6(Proto *icmp, Ipifc *ipifc, Block *bp)
 		break;
 	}
 	return;
-
 raise:
 	freeblist(bp);
 }

+ 112 - 187
sys/src/9/ip/ipifc.c

@@ -13,15 +13,12 @@
 enum {
 	Maxmedia	= 32,
 	Nself		= Maxmedia*5,
-	NHASH		= (1<<6),
+	NHASH		= 1<<6,
 	NCACHE		= 256,
 	QMAX		= 64*1024-1,
 };
 
-Medium *media[Maxmedia] =
-{
-	0
-};
+Medium *media[Maxmedia] = { 0 };
 
 /*
  *  cache of local addresses (addresses we answer to)
@@ -144,15 +141,15 @@ ipifcbind(Conv *c, char **argv, int argc)
 	ifc->maxtu = ifc->m->maxtu;
 	if(ifc->m->unbindonclose == 0)
 		ifc->conv->inuse++;
-	ifc->rp.mflag = 0;		// default not managed
+	ifc->rp.mflag = 0;		/* default not managed */
 	ifc->rp.oflag = 0;
-	ifc->rp.maxraint = 600000;	// millisecs
+	ifc->rp.maxraint = 600000;	/* millisecs */
 	ifc->rp.minraint = 200000;
-	ifc->rp.linkmtu = 0;		// no mtu sent
+	ifc->rp.linkmtu = 0;		/* no mtu sent */
 	ifc->rp.reachtime = 0;
 	ifc->rp.rxmitra = 0;
 	ifc->rp.ttl = MAXTTL;
-	ifc->rp.routerlt = 3*(ifc->rp.maxraint);
+	ifc->rp.routerlt = 3 * ifc->rp.maxraint;
 
 	/* any ancillary structures (like routes) no longer pertain */
 	ifc->ifcid++;
@@ -189,7 +186,7 @@ ipifcunbind(Ipifc *ifc)
 	ifc->ifcid++;
 
 	/* disassociate device */
-	if(ifc->m != nil && ifc->m->unbind)
+	if(ifc->m && ifc->m->unbind)
 		(*ifc->m->unbind)(ifc);
 	memset(ifc->dev, 0, sizeof(ifc->dev));
 	ifc->arg = nil;
@@ -213,7 +210,9 @@ ipifcunbind(Ipifc *ifc)
 	return nil;
 }
 
-char sfixedformat[] = "device %s maxtu %d sendra %d recvra %d mflag %d oflag %d maxraint %d minraint %d linkmtu %d reachtime %d rxmitra %d ttl %d routerlt %d pktin %lud pktout %lud errin %lud errout %lud\n";
+char sfixedformat[] = "device %s maxtu %d sendra %d recvra %d mflag %d oflag"
+" %d maxraint %d minraint %d linkmtu %d reachtime %d rxmitra %d ttl %d routerlt"
+" %d pktin %lud pktout %lud errin %lud errout %lud\n";
 
 char slineformat[] = "	%-40I %-10M %-40I %-12lud %-12lud\n";
 
@@ -225,7 +224,6 @@ ipifcstate(Conv *c, char *state, int n)
 	int m;
 
 	ifc = (Ipifc*)c->ptcl;
-
 	m = snprint(state, n, sfixedformat,
 		ifc->dev, ifc->maxtu, ifc->sendra6, ifc->recvra6,
 		ifc->rp.mflag, ifc->rp.oflag, ifc->rp.maxraint,
@@ -235,9 +233,8 @@ ipifcstate(Conv *c, char *state, int n)
 
 	rlock(ifc);
 	for(lifc = ifc->lifc; lifc && n > m; lifc = lifc->next)
-		m += snprint(state+m, n - m, slineformat,
-			lifc->local, lifc->mask, lifc->remote,
-			lifc->validlt, lifc->preflt);
+		m += snprint(state+m, n - m, slineformat, lifc->local,
+			lifc->mask, lifc->remote, lifc->validlt, lifc->preflt);
 	if(ifc->lifc == nil)
 		m += snprint(state+m, n - m, "\n");
 	runlock(ifc);
@@ -253,7 +250,6 @@ ipifclocal(Conv *c, char *state, int n)
 	int m;
 
 	ifc = (Ipifc*)c->ptcl;
-
 	m = 0;
 
 	rlock(ifc);
@@ -337,7 +333,7 @@ ipifcclose(Conv *c)
 
 	ifc = (Ipifc*)c->ptcl;
 	m = ifc->m;
-	if(m != nil && m->unbindonclose)
+	if(m && m->unbindonclose)
 		ipifcunbind(ifc);
 }
 
@@ -349,9 +345,7 @@ ipifcsetmtu(Ipifc *ifc, char **argv, int argc)
 {
 	int mtu;
 
-	if(argc < 2)
-		return Ebadarg;
-	if(ifc->m == nil)
+	if(argc < 2 || ifc->m == nil)
 		return Ebadarg;
 	mtu = strtoul(argv[1], 0, 0);
 	if(mtu < ifc->m->mintu || mtu > ifc->m->maxtu)
@@ -366,12 +360,11 @@ ipifcsetmtu(Ipifc *ifc, char **argv, int argc)
 char*
 ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
 {
+	int i, type, mtu, sendnbrdisc = 0;
 	uchar ip[IPaddrlen], mask[IPaddrlen], rem[IPaddrlen];
 	uchar bcast[IPaddrlen], net[IPaddrlen];
 	Iplifc *lifc, **l;
-	int i, type, mtu;
 	Fs *f;
-	int sendnbrdisc = 0;
 
 	if(ifc->m == nil)
 		return "ipifc not yet bound to device";
@@ -412,14 +405,13 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
 		break;
 	default:
 		return Ebadarg;
-		break;
 	}
 	if(isv4(ip))
 		tentative = 0;
 	wlock(ifc);
 
 	/* ignore if this is already a local address for this ifc */
-	for(lifc = ifc->lifc; lifc; lifc = lifc->next) {
+	for(lifc = ifc->lifc; lifc; lifc = lifc->next)
 		if(ipcmp(lifc->local, ip) == 0) {
 			if(lifc->tentative != tentative)
 				lifc->tentative = tentative;
@@ -432,7 +424,6 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
 			}
 			goto out;
 		}
-	}
 
 	/* add the address to the list of logical ifc's for this ifc */
 	lifc = smalloc(sizeof(Iplifc));
@@ -447,13 +438,12 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
 		lifc->validlt = lifcp->validlt;
 		lifc->preflt = lifcp->preflt;
 		lifc->origint = lifcp->origint;
-	}
-	else {		// default values
+	} else {		/* default values */
 		lifc->onlink = 1;
 		lifc->autoflag = 1;
-		lifc->validlt = 0xffffffff;
-		lifc->preflt = 0xffffffff;
-		lifc->origint = NOW / 10^3;
+		lifc->validlt = ~0L;
+		lifc->preflt = ~0L;
+		lifc->origint = NOW / 1000;
 	}
 	lifc->next = nil;
 
@@ -462,7 +452,7 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
 	*l = lifc;
 
 	/* check for point-to-point interface */
-	if(ipcmp(ip, v6loopback))	/* skip v6 loopback, it's a special address */
+	if(ipcmp(ip, v6loopback)) /* skip v6 loopback, it's a special address */
 	if(ipcmp(mask, IPallbits) == 0)
 		type |= Rptpt;
 
@@ -503,21 +493,22 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
 		addselfcache(f, ifc, lifc, bcast, Rbcast);
 
 		addselfcache(f, ifc, lifc, IPv4bcast, Rbcast);
-	}
-	else {
+	} else {
 		if(ipcmp(ip, v6loopback) == 0) {
 			/* add node-local mcast address */
 			addselfcache(f, ifc, lifc, v6allnodesN, Rmulti);
 
 			/* add route for all node multicast */
-			v6addroute(f, tifc, v6allnodesN, v6allnodesNmask, v6allnodesN, Rmulti);
+			v6addroute(f, tifc, v6allnodesN, v6allnodesNmask,
+				v6allnodesN, Rmulti);
 		}
 
 		/* add all nodes multicast address */
 		addselfcache(f, ifc, lifc, v6allnodesL, Rmulti);
 
 		/* add route for all nodes multicast */
-		v6addroute(f, tifc, v6allnodesL, v6allnodesLmask, v6allnodesL, Rmulti);
+		v6addroute(f, tifc, v6allnodesL, v6allnodesLmask, v6allnodesL,
+			Rmulti);
 
 		/* add solicited-node multicast address */
 		ipv62smcast(bcast, ip);
@@ -579,7 +570,6 @@ ipifcremlifc(Ipifc *ifc, Iplifc *lifc)
 
 	free(lifc);
 	return nil;
-
 }
 
 /*
@@ -589,11 +579,9 @@ ipifcremlifc(Ipifc *ifc, Iplifc *lifc)
 char*
 ipifcrem(Ipifc *ifc, char **argv, int argc)
 {
-	uchar ip[IPaddrlen];
-	uchar mask[IPaddrlen];
-	uchar rem[IPaddrlen];
-	Iplifc *lifc;
 	char *rv;
+	uchar ip[IPaddrlen], mask[IPaddrlen], rem[IPaddrlen];
+	Iplifc *lifc;
 
 	if(argc < 3)
 		return Ebadarg;
@@ -612,12 +600,11 @@ ipifcrem(Ipifc *ifc, char **argv, int argc)
 	 *  for pt to pt we actually specify the remote address as the
 	 *  addresss to remove.
 	 */
-	for(lifc = ifc->lifc; lifc != nil; lifc = lifc->next) {
+	for(lifc = ifc->lifc; lifc != nil; lifc = lifc->next)
 		if (memcmp(ip, lifc->local, IPaddrlen) == 0
 		&& memcmp(mask, lifc->mask, IPaddrlen) == 0
 		&& memcmp(rem, lifc->remote, IPaddrlen) == 0)
 			break;
-	}
 
 	rv = ipifcremlifc(ifc, lifc);
 	wunlock(ifc);
@@ -636,16 +623,13 @@ ipifcaddroute(Fs *f, int vers, uchar *addr, uchar *mask, uchar *gate, int type)
 	Ipifc *ifc;
 
 	e = &f->ipifc->conv[f->ipifc->nc];
-	for(cp = f->ipifc->conv; cp < e; cp++){
+	for(cp = f->ipifc->conv; cp < e; cp++)
 		if(*cp != nil) {
 			ifc = (Ipifc*)(*cp)->ptcl;
 			m = ifc->m;
-			if(m == nil)
-				continue;
-			if(m->addroute != nil)
+			if(m && m->addroute)
 				m->addroute(ifc, vers, addr, mask, gate, type);
 		}
-	}
 }
 
 void
@@ -656,16 +640,13 @@ ipifcremroute(Fs *f, int vers, uchar *addr, uchar *mask)
 	Ipifc *ifc;
 
 	e = &f->ipifc->conv[f->ipifc->nc];
-	for(cp = f->ipifc->conv; cp < e; cp++){
+	for(cp = f->ipifc->conv; cp < e; cp++)
 		if(*cp != nil) {
 			ifc = (Ipifc*)(*cp)->ptcl;
 			m = ifc->m;
-			if(m == nil)
-				continue;
-			if(m->remroute != nil)
+			if(m && m->remroute)
 				m->remroute(ifc, vers, addr, mask);
 		}
-	}
 }
 
 /*
@@ -702,7 +683,6 @@ ipifcconnect(Conv* c, char **argv, int argc)
 		return err;
 
 	Fsconnected(c, nil);
-
 	return nil;
 }
 
@@ -718,27 +698,27 @@ ipifcsetpar6(Ipifc *ifc, char **argv, int argc)
 		return Ebadarg;
 
 	while (argsleft > 1) {
-		if(strcmp(argv[i],"recvra")==0)
+		if(strcmp(argv[i], "recvra") == 0)
 			ifc->recvra6 = (atoi(argv[i+1]) != 0);
-		else if(strcmp(argv[i],"sendra")==0)
+		else if(strcmp(argv[i], "sendra") == 0)
 			ifc->sendra6 = (atoi(argv[i+1]) != 0);
-		else if(strcmp(argv[i],"mflag")==0)
+		else if(strcmp(argv[i], "mflag") == 0)
 			ifc->rp.mflag = (atoi(argv[i+1]) != 0);
-		else if(strcmp(argv[i],"oflag")==0)
+		else if(strcmp(argv[i], "oflag") == 0)
 			ifc->rp.oflag = (atoi(argv[i+1]) != 0);
-		else if(strcmp(argv[i],"maxraint")==0)
+		else if(strcmp(argv[i], "maxraint") == 0)
 			ifc->rp.maxraint = atoi(argv[i+1]);
-		else if(strcmp(argv[i],"minraint")==0)
+		else if(strcmp(argv[i], "minraint") == 0)
 			ifc->rp.minraint = atoi(argv[i+1]);
-		else if(strcmp(argv[i],"linkmtu")==0)
+		else if(strcmp(argv[i], "linkmtu") == 0)
 			ifc->rp.linkmtu = atoi(argv[i+1]);
-		else if(strcmp(argv[i],"reachtime")==0)
+		else if(strcmp(argv[i], "reachtime") == 0)
 			ifc->rp.reachtime = atoi(argv[i+1]);
-		else if(strcmp(argv[i],"rxmitra")==0)
+		else if(strcmp(argv[i], "rxmitra") == 0)
 			ifc->rp.rxmitra = atoi(argv[i+1]);
-		else if(strcmp(argv[i],"ttl")==0)
+		else if(strcmp(argv[i], "ttl") == 0)
 			ifc->rp.ttl = atoi(argv[i+1]);
-		else if(strcmp(argv[i],"routerlt")==0)
+		else if(strcmp(argv[i], "routerlt") == 0)
 			ifc->rp.routerlt = atoi(argv[i+1]);
 		else
 			return Ebadarg;
@@ -747,37 +727,26 @@ ipifcsetpar6(Ipifc *ifc, char **argv, int argc)
 		i += 2;
 	}
 
-	// consistency check
+	/* consistency check */
 	if(ifc->rp.maxraint < ifc->rp.minraint) {
 		ifc->rp.maxraint = vmax;
 		ifc->rp.minraint = vmin;
 		return Ebadarg;
 	}
-
 	return nil;
 }
 
 char*
 ipifcsendra6(Ipifc *ifc, char **argv, int argc)
 {
-	int i;
-
-	i = 0;
-	if(argc > 1)
-		i = atoi(argv[1]);
-	ifc->sendra6 = (i!=0);
+	ifc->sendra6 = ((argc > 1? atoi(argv[1]): 0) != 0);
 	return nil;
 }
 
 char*
 ipifcrecvra6(Ipifc *ifc, char **argv, int argc)
 {
-	int i;
-
-	i = 0;
-	if(argc > 1)
-		i = atoi(argv[1]);
-	ifc->recvra6 = (i!=0);
+	ifc->recvra6 = ((argc > 1? atoi(argv[1]): 0) != 0);
 	return nil;
 }
 
@@ -789,7 +758,6 @@ static char*
 ipifcctl(Conv* c, char**argv, int argc)
 {
 	Ipifc *ifc;
-	int i;
 
 	ifc = (Ipifc*)c->ptcl;
 	if(strcmp(argv[0], "add") == 0)
@@ -809,15 +777,10 @@ ipifcctl(Conv* c, char**argv, int argc)
 	else if(strcmp(argv[0], "reassemble") == 0){
 		ifc->reassemble = 1;
 		return nil;
-	}
-	else if(strcmp(argv[0], "iprouting") == 0){
-		i = 1;
-		if(argc > 1)
-			i = atoi(argv[1]);
-		iprouting(c->p->f, i);
+	} else if(strcmp(argv[0], "iprouting") == 0){
+		iprouting(c->p->f, (argc > 1? atoi(argv[1]): 1));
 		return nil;
-	}
-	else if(strcmp(argv[0], "addpref6") == 0)
+	} else if(strcmp(argv[0], "addpref6") == 0)
 		return ipifcaddpref6(ifc, argv, argc);
 	else if(strcmp(argv[0], "setpar6") == 0)
 		return ipifcsetpar6(ifc, argv, argc);
@@ -857,7 +820,7 @@ ipifcinit(Fs *f)
 	ipifc->nc = Maxmedia;
 	ipifc->ptclsize = sizeof(Ipifc);
 
-	f->ipifc = ipifc;			/* hack for ipifcremroute, findipifc, ... */
+	f->ipifc = ipifc;	/* hack for ipifcremroute, findipifc, ... */
 	f->self = smalloc(sizeof(Ipselftab));	/* hack for ipforme */
 
 	Fsproto(f, ipifc);
@@ -913,15 +876,15 @@ addselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a, int type)
 
 		/* add to routing table */
 		if(isv4(a))
-			v4addroute(f, tifc, a+IPv4off, IPallbits+IPv4off, a+IPv4off, type);
+			v4addroute(f, tifc, a+IPv4off, IPallbits+IPv4off,
+				a+IPv4off, type);
 		else
 			v6addroute(f, tifc, a, IPallbits, a, type);
 
 		if((type & Rmulti) && ifc->m->addmulti != nil)
 			(*ifc->m->addmulti)(ifc, a, lifc->local);
-	} else {
+	} else
 		lp->ref++;
-	}
 
 	qunlock(f->self);
 }
@@ -950,7 +913,7 @@ iplinkfree(Iplink *p)
 		}
 		l = &np->next;
 	}
-	p->expire = now + 5000;		/* give other threads 5 secs to get out */
+	p->expire = now + 5000;	/* give other threads 5 secs to get out */
 	p->next = nil;
 	*l = p;
 }
@@ -969,7 +932,7 @@ ipselffree(Ipself *p)
 		}
 		l = &np->next;
 	}
-	p->expire = now + 5000;		/* give other threads 5 secs to get out */
+	p->expire = now + 5000;	/* give other threads 5 secs to get out */
 	p->next = nil;
 	*l = p;
 }
@@ -1018,7 +981,7 @@ remselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a)
 	 */
 	l_self = &p->link;
 	for(link = *l_self; link; link = *l_self){
-		if(link == *(l_lifc))
+		if(link == *l_lifc)
 			break;
 		l_self = &link->selflink;
 	}
@@ -1075,7 +1038,7 @@ ipselftabread(Fs *f, char *cp, ulong offset, int n)
 	m = 0;
 	off = offset;
 	qlock(f->self);
-	for(i = 0; i < NHASH && m < n; i++){
+	for(i = 0; i < NHASH && m < n; i++)
 		for(p = f->self->hash[i]; p != nil && m < n; p = p->next){
 			nifc = 0;
 			for(link = p->link; link; link = link->selflink)
@@ -1087,7 +1050,6 @@ ipselftabread(Fs *f, char *cp, ulong offset, int n)
 				m = 0;
 			}
 		}
-	}
 	qunlock(f->self);
 	return m;
 }
@@ -1098,11 +1060,9 @@ iptentative(Fs *f, uchar *addr)
  	Ipself *p;
 
 	p = f->self->hash[hashipa(addr)];
-	for(; p; p = p->next){
-		if(ipcmp(addr, p->a) == 0) {
+	for(; p; p = p->next)
+		if(ipcmp(addr, p->a) == 0)
 			return p->link->lifc->tentative;
-		}
-	}
 	return 0;
 }
 
@@ -1119,15 +1079,13 @@ ipforme(Fs *f, uchar *addr)
 	Ipself *p;
 
 	p = f->self->hash[hashipa(addr)];
-	for(; p; p = p->next){
+	for(; p; p = p->next)
 		if(ipcmp(addr, p->a) == 0)
 			return p->type;
-	}
 
 	/* hack to say accept anything */
 	if(f->self->acceptall)
 		return Runi;
-
 	return 0;
 }
 
@@ -1141,34 +1099,31 @@ findipifc(Fs *f, uchar *remote, int type)
 	Ipifc *ifc, *x;
 	Iplifc *lifc;
 	Conv **cp, **e;
-	uchar gnet[IPaddrlen];
-	uchar xmask[IPaddrlen];
+	uchar gnet[IPaddrlen], xmask[IPaddrlen];
 
-	x = nil; memset(xmask, 0, IPaddrlen);
+	x = nil;
+	memset(xmask, 0, IPaddrlen);
 
 	/* find most specific match */
 	e = &f->ipifc->conv[f->ipifc->nc];
 	for(cp = f->ipifc->conv; cp < e; cp++){
 		if(*cp == 0)
 			continue;
-
 		ifc = (Ipifc*)(*cp)->ptcl;
-
 		for(lifc = ifc->lifc; lifc; lifc = lifc->next){
 			maskip(remote, lifc->mask, gnet);
-			if(ipcmp(gnet, lifc->net) == 0){
+			if(ipcmp(gnet, lifc->net) == 0)
 				if(x == nil || ipcmp(lifc->mask, xmask) > 0){
 					x = ifc;
 					ipmove(xmask, lifc->mask);
 				}
-			}
 		}
 	}
 	if(x != nil)
 		return x;
 
 	/* for now for broadcast and multicast, just use first interface */
-	if(type & (Rbcast|Rmulti)){
+	if(type & (Rbcast|Rmulti))
 		for(cp = f->ipifc->conv; cp < e; cp++){
 			if(*cp == 0)
 				continue;
@@ -1176,13 +1131,11 @@ findipifc(Fs *f, uchar *remote, int type)
 			if(ifc->lifc != nil)
 				return ifc;
 		}
-	}
-
 	return nil;
 }
 
 enum {
-	unknownv6,
+	unknownv6,		/* UGH */
 	multicastv6,
 	unspecifiedv6,
 	linklocalv6,
@@ -1204,15 +1157,16 @@ v6addrtype(uchar *addr)
 	return unknownv6;
 }
 
-#define v6addrcurr(lifc) (( (lifc)->origint + (lifc)->preflt >= (NOW/10^3) ) || ( (lifc)->preflt == 0xffffffff ))
+#define v6addrcurr(lifc) ((lifc)->origint + (lifc)->preflt >= NOW/1000 || \
+				(lifc)->preflt == ~0L)
 
 static void
 findprimaryipv6(Fs *f, uchar *local)
 {
+	int atype, atypel;
 	Conv **cp, **e;
 	Ipifc *ifc;
 	Iplifc *lifc;
-	int atype, atypel;
 
 	ipmove(local, v6Unspecified);
 	atype = unspecifiedv6;
@@ -1227,8 +1181,7 @@ findprimaryipv6(Fs *f, uchar *local)
 		ifc = (Ipifc*)(*cp)->ptcl;
 		for(lifc = ifc->lifc; lifc; lifc = lifc->next){
 			atypel = v6addrtype(lifc->local);
-			if(atypel > atype)
-			if(v6addrcurr(lifc)) {
+			if(atypel > atype && v6addrcurr(lifc)) {
 				ipmove(local, lifc->local);
 				atype = atypel;
 				if(atype == globalv6)
@@ -1268,19 +1221,17 @@ findprimaryipv4(Fs *f, uchar *local)
 void
 findlocalip(Fs *f, uchar *local, uchar *remote)
 {
+	int version, atype = unspecifiedv6, atypel = unknownv6;
+	uchar gate[IPaddrlen], gnet[IPaddrlen];
 	Ipifc *ifc;
 	Iplifc *lifc;
 	Route *r;
-	uchar gate[IPaddrlen];
-	uchar gnet[IPaddrlen];
-	int version;
-	int atype = unspecifiedv6, atypel = unknownv6;
 
 	USED(atype);
 	USED(atypel);
 	qlock(f->ipifc);
 	r = v6lookup(f, remote, nil);
- 	version = (memcmp(remote, v4prefix, IPv4off) == 0) ? V4 : V6;
+ 	version = (memcmp(remote, v4prefix, IPv4off) == 0)? V4: V6;
 
 	if(r != nil){
 		ifc = r->ifc;
@@ -1306,9 +1257,8 @@ findlocalip(Fs *f, uchar *local, uchar *remote)
 			for(lifc = ifc->lifc; lifc; lifc = lifc->next){
 				atypel = v6addrtype(lifc->local);
 				maskip(gate, lifc->mask, gnet);
-				if(ipcmp(gnet, lifc->net) == 0)
-				if(atypel > atype)
-				if(v6addrcurr(lifc)) {
+				if (ipcmp(gnet, lifc->net) == 0 &&
+				    atypel > atype && v6addrcurr(lifc)) {
 					ipmove(local, lifc->local);
 					atype = atypel;
 					if(atype == globalv6)
@@ -1346,12 +1296,11 @@ ipv4local(Ipifc *ifc, uchar *addr)
 {
 	Iplifc *lifc;
 
-	for(lifc = ifc->lifc; lifc; lifc = lifc->next){
+	for(lifc = ifc->lifc; lifc; lifc = lifc->next)
 		if(isv4(lifc->local)){
 			memmove(addr, lifc->local+IPv4off, IPv4addrlen);
 			return 1;
 		}
-	}
 	return 0;
 }
 
@@ -1363,12 +1312,11 @@ ipv6local(Ipifc *ifc, uchar *addr)
 {
 	Iplifc *lifc;
 
-	for(lifc = ifc->lifc; lifc; lifc = lifc->next){
+	for(lifc = ifc->lifc; lifc; lifc = lifc->next)
 		if(!isv4(lifc->local) && !(lifc->tentative)){
 			ipmove(addr, lifc->local);
 			return 1;
 		}
-	}
 	return 0;
 }
 
@@ -1377,12 +1325,11 @@ ipv6anylocal(Ipifc *ifc, uchar *addr)
 {
 	Iplifc *lifc;
 
-	for(lifc = ifc->lifc; lifc; lifc = lifc->next){
+	for(lifc = ifc->lifc; lifc; lifc = lifc->next)
 		if(!isv4(lifc->local)){
 			ipmove(addr, lifc->local);
 			return SRC_UNI;
 		}
-	}
 	return SRC_UNSPEC;
 }
 
@@ -1413,9 +1360,7 @@ ipproxyifc(Fs *f, Ipifc *ifc, uchar *ip)
 
 	/* see if this is a direct connected pt to pt address */
 	r = v6lookup(f, ip, nil);
-	if(r == nil)
-		return 0;
-	if((r->type & (Rifc|Rproxy)) != (Rifc|Rproxy))
+	if(r == nil || (r->type & (Rifc|Rproxy)) != (Rifc|Rproxy))
 		return 0;
 
 	/* see if this is on the right interface */
@@ -1424,7 +1369,6 @@ ipproxyifc(Fs *f, Ipifc *ifc, uchar *ip)
 		if(ipcmp(net, lifc->remote) == 0)
 			return 1;
 	}
-
 	return 0;
 }
 
@@ -1437,24 +1381,22 @@ ipismulticast(uchar *ip)
 	if(isv4(ip)){
 		if(ip[IPv4off] >= 0xe0 && ip[IPv4off] < 0xf0)
 			return V4;
-	} else {
+	} else
 		if(ip[0] == 0xff)
 			return V6;
-	}
 	return 0;
 }
 int
 ipisbm(uchar *ip)
 {
-	if(isv4(ip)){
+	if(isv4(ip))
 		if(ip[IPv4off] >= 0xe0 && ip[IPv4off] < 0xf0)
 			return V4;
-		if(ipcmp(ip, IPv4bcast) == 0)
+		else if(ipcmp(ip, IPv4bcast) == 0)
 			return V4;
-	} else {
+	else
 		if(ip[0] == 0xff)
 			return V6;
-	}
 	return 0;
 }
 
@@ -1474,8 +1416,7 @@ ipifcaddmulti(Conv *c, uchar *ma, uchar *ia)
 	f = c->p->f;
 
 	for(l = &c->multi; *l; l = &(*l)->next)
-		if(ipcmp(ma, (*l)->ma) == 0)
-		if(ipcmp(ia, (*l)->ia) == 0)
+		if(ipcmp(ma, (*l)->ma) == 0 && ipcmp(ia, (*l)->ia) == 0)
 			return;		/* it's already there */
 
 	multi = *l = smalloc(sizeof(*multi));
@@ -1516,8 +1457,7 @@ ipifcremmulti(Conv *c, uchar *ma, uchar *ia)
 	f = c->p->f;
 
 	for(l = &c->multi; *l; l = &(*l)->next)
-		if(ipcmp(ma, (*l)->ma) == 0)
-		if(ipcmp(ia, (*l)->ia) == 0)
+		if(ipcmp(ma, (*l)->ma) == 0 && ipcmp(ia, (*l)->ia) == 0)
 			break;
 
 	multi = *l;
@@ -1575,14 +1515,10 @@ ipifcregisterproxy(Fs *f, Ipifc *ifc, uchar *ip)
 	/* register the address on any network that will proxy for us */
 	e = &f->ipifc->conv[f->ipifc->nc];
 
-	if(!isv4(ip)) { // V6
+	if(!isv4(ip))				/* V6 */
 		for(cp = f->ipifc->conv; cp < e; cp++){
-			if(*cp == nil)
-				continue;
-			nifc = (Ipifc*)(*cp)->ptcl;
-			if(nifc == ifc)
+			if(*cp == nil || (nifc = (Ipifc*)(*cp)->ptcl) == ifc)
 				continue;
-
 			rlock(nifc);
 			m = nifc->m;
 			if(m == nil || m->addmulti == nil) {
@@ -1591,26 +1527,21 @@ ipifcregisterproxy(Fs *f, Ipifc *ifc, uchar *ip)
 			}
 			for(lifc = nifc->lifc; lifc; lifc = lifc->next){
 				maskip(ip, lifc->mask, net);
-				if(ipcmp(net, lifc->remote) == 0) { /* add solicited-node multicast address */
+				if(ipcmp(net, lifc->remote) == 0) {
+					/* add solicited-node multicast addr */
 					ipv62smcast(net, ip);
 					addselfcache(f, nifc, lifc, net, Rmulti);
 					arpenter(f, V6, ip, nifc->mac, 6, 0);
-					//(*m->addmulti)(nifc, net, ip);
+					// (*m->addmulti)(nifc, net, ip);
 					break;
 				}
 			}
 			runlock(nifc);
 		}
-		return;
-	}
-	else { // V4
+	else					/* V4 */
 		for(cp = f->ipifc->conv; cp < e; cp++){
-			if(*cp == nil)
+			if(*cp == nil || (nifc = (Ipifc*)(*cp)->ptcl) == ifc)
 				continue;
-			nifc = (Ipifc*)(*cp)->ptcl;
-			if(nifc == ifc)
-				continue;
-
 			rlock(nifc);
 			m = nifc->m;
 			if(m == nil || m->areg == nil){
@@ -1626,44 +1557,41 @@ ipifcregisterproxy(Fs *f, Ipifc *ifc, uchar *ip)
 			}
 			runlock(nifc);
 		}
-	}
 }
 
 
-// added for new v6 mesg types
+/* added for new v6 mesg types */
 static void
 adddefroute6(Fs *f, uchar *gate, int force)
 {
 	Route *r;
 
 	r = v6lookup(f, v6Unspecified, nil);
-	if(r!=nil)
-	if(!(force) && (strcmp(r->tag,"ra")!=0))	// route entries generated
-		return;			// by all other means take
-					// precedence over router annc
+	/*
+	 * route entries generated by all other means take precedence
+	 * over router announcements.
+	 */
+	if (r && !force && strcmp(r->tag, "ra") != 0)
+		return;
 
 	v6delroute(f, v6Unspecified, v6Unspecified, 1);
 	v6addroute(f, "ra", v6Unspecified, v6Unspecified, gate, 0);
 }
 
-enum
-{
+enum {
 	Ngates = 3,
 };
 
 char*
 ipifcaddpref6(Ipifc *ifc, char**argv, int argc)
 {
-	uchar	onlink = 1;
-	uchar	autoflag = 1;
-	long 	validlt = 0xffffffff;
-	long 	preflt = 0xffffffff;
-	long	origint = NOW / 10^3;
-	uchar	prefix[IPaddrlen];
-	int	plen = 64;
-	Iplifc	*lifc;
-	char	addr[40], preflen[6];
-	char	*params[3];
+	int plen = 64;
+	long origint = NOW / 1000, preflt = ~0L, validlt = ~0L;
+	char addr[40], preflen[6];
+	char *params[3];
+	uchar autoflag = 1, onlink = 1;
+	uchar prefix[IPaddrlen];
+	Iplifc *lifc;
 
 	switch(argc) {
 	case 7:
@@ -1680,17 +1608,15 @@ ipifcaddpref6(Ipifc *ifc, char**argv, int argc)
 		/* fall through */
 	case 3:
 		plen = atoi(argv[2]);
+		/* fall through */
 	case 2:
 		break;
 	default:
 		return Ebadarg;
 	}
 
-	if((parseip(prefix, argv[1])!=6) ||
-	 	(validlt < preflt) ||
-		(plen < 0) || (plen > 64) ||
-		(islinklocal(prefix))
-	)
+	if (parseip(prefix, argv[1]) != 6 || validlt < preflt || plen < 0 ||
+	    plen > 64 || islinklocal(prefix))
 		return Ebadarg;
 
 	lifc = smalloc(sizeof(Iplifc));
@@ -1700,7 +1626,7 @@ ipifcaddpref6(Ipifc *ifc, char**argv, int argc)
 	lifc->preflt = preflt;
 	lifc->origint = origint;
 
-	if(ifc->m->pref2addr!=nil)
+	if(ifc->m->pref2addr)
 		ifc->m->pref2addr(prefix, ifc->mac);
 	else
 		return Ebadarg;
@@ -1713,4 +1639,3 @@ ipifcaddpref6(Ipifc *ifc, char**argv, int argc)
 
 	return ipifcadd(ifc, params, 3, 0, lifc);
 }
-

+ 72 - 102
sys/src/9/ip/ipv6.c

@@ -16,11 +16,11 @@ enum
 	IP_DF		= 0x4000,	/* Don't fragment */
 	IP_MF		= 0x2000,	/* More fragments */
 	IP6FHDR		= 8, 		/* sizeof(Fraghdr6) */
-	IP_MAX		= (32*1024),	/* Maximum Internet packet size */
+	IP_MAX		= 32*1024,	/* Maximum Internet packet size */
 };
 
-#define IPV6CLASS(hdr) ((hdr->vcf[0]&0x0F)<<2 | (hdr->vcf[1]&0xF0)>>2)
-#define BLKIPVER(xp)	(((Ip6hdr*)((xp)->rp))->vcf[0]&0xF0)
+#define IPV6CLASS(hdr)	(((hdr)->vcf[0]&0x0F)<<2 | ((hdr)->vcf[1]&0xF0)>>2)
+#define BLKIPVER(xp)	(((Ip6hdr*)((xp)->rp))->vcf[0] & 0xF0)
 /*
  * This sleazy macro is stolen shamelessly from ip.c, see comment there.
  */
@@ -32,11 +32,11 @@ typedef struct	Fragment6	Fragment6;
 typedef struct	Ipfrag	Ipfrag;
 
 Block*		ip6reassemble(IP*, int, Block*, Ip6hdr*);
-void		ipfragfree6(IP*, Fragment6*);
 Fragment6*	ipfragallo6(IP*);
-static Block*		procxtns(IP *ip, Block *bp, int doreasm);
-int		unfraglen(Block *bp, uchar *nexthdr, int setfh);
+void		ipfragfree6(IP*, Fragment6*);
 Block*		procopts(Block *bp);
+static Block*	procxtns(IP *ip, Block *bp, int doreasm);
+int		unfraglen(Block *bp, uchar *nexthdr, int setfh);
 
 /* MIB II counters */
 enum
@@ -134,16 +134,15 @@ struct IP
 int
 ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 {
-	int tentative;
-	Ipifc *ifc;
+	int medialen, len, chunk, uflen, flen, seglen, lid, offset, fragoff;
+	int morefrags, blklen, rv = 0, tentative;
 	uchar *gate, nexthdr;
-	Ip6hdr *eh;
-	int medialen, len, chunk, uflen, flen, seglen, lid, offset, fragoff, morefrags, blklen;
-	Route *r, *sr;
-	Fraghdr6 fraghdr;
 	Block *xp, *nb;
+	Fraghdr6 fraghdr;
 	IP *ip;
-	int rv = 0;
+	Ip6hdr *eh;
+	Ipifc *ifc;
+	Route *r, *sr;
 
 	ip = f->ip;
 
@@ -154,7 +153,7 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 
 	/* Number of uchars in data and ip header to write */
 	len = blocklen(bp);
-	
+
 	tentative = iptentative(f, eh->src);
 	if(tentative){
 		netlog(f, Logip, "reject tx of packet with tentative src address\n");
@@ -191,36 +190,32 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 	ifc = r->ifc;
 	if(r->type & (Rifc|Runi))
 		gate = eh->dst;
-	else
-	if(r->type & (Rbcast|Rmulti)) {
+	else if(r->type & (Rbcast|Rmulti)) {
 		gate = eh->dst;
 		sr = v6lookup(f, eh->src, nil);
-		if(sr != nil && (sr->type & Runi))
+		if(sr && (sr->type & Runi))
 			ifc = sr->ifc;
-	}
-	else
+	} else
 		gate = r->v6.gate;
 
 	if(!gating)
 		eh->vcf[0] = IP_VER6;
 	eh->ttl = ttl;
 	if(!gating) {
-		eh->vcf[0] |= (tos >> 4);
-		eh->vcf[1] = (tos << 4);
+		eh->vcf[0] |= tos >> 4;
+		eh->vcf[1]  = tos << 4;
 	}
 
-	if(!canrlock(ifc)) {
+	if(!canrlock(ifc))
 		goto free;
-	}
 
 	if(waserror()){
 		runlock(ifc);
 		nexterror();
 	}
 
-	if(ifc->m == nil) {
+	if(ifc->m == nil)
 		goto raise;
-	}
 
 	/* If we dont need to fragment just send it */
 	medialen = ifc->maxtu - ifc->m->hsize;
@@ -232,20 +227,18 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 		return 0;
 	}
 
-	if(gating) 
-	if(ifc->reassemble <= 0) {
-
-		/* v6 intermediate nodes are not supposed to fragment pkts;
-		   we fragment if ifc->reassemble is turned on; an exception
-		   needed for nat.
+	if(gating && ifc->reassemble <= 0) {
+		/*
+		 * v6 intermediate nodes are not supposed to fragment pkts;
+		 * we fragment if ifc->reassemble is turned on; an exception
+		 * needed for nat.
 		 */
-
 		ip->stats[OutDiscards]++;
 		icmppkttoobig6(f, ifc, bp);
 		netlog(f, Logip, "%I: gated pkts not fragmented\n", eh->dst);
 		goto raise;
 	}
-		
+
 	/* start v6 fragmentation */
 	uflen = unfraglen(bp, &nexthdr, 1);
 	if(uflen > medialen) {
@@ -271,13 +264,13 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 
 	xp = bp;
 	offset = uflen;
-	while (xp != nil && offset && offset >= BLEN(xp)) {
+	while (xp && offset && offset >= BLEN(xp)) {
 		offset -= BLEN(xp);
 		xp = xp->next;
 	}
 	xp->rp += offset;
 
-	fragoff = 0; 
+	fragoff = 0;
 	morefrags = 1;
 
 	for(; fragoff < flen; fragoff += seglen) {
@@ -292,7 +285,7 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 		memmove(nb->wp, eh, uflen);
 		nb->wp += uflen;
 
-		hnputs(fraghdr.offsetRM, fragoff); // last 3 bits must be 0
+		hnputs(fraghdr.offsetRM, fragoff); /* last 3 bits must be 0 */
 		fraghdr.offsetRM[1] |= morefrags;
 		memmove(nb->wp, &fraghdr, IP6FHDR);
 		nb->wp += IP6FHDR;
@@ -316,7 +309,7 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 			xp->rp += blklen;
 			chunk -= blklen;
 			if(xp->rp == xp->wp)
-				xp = xp->next; 
+				xp = xp->next;
 		}
 
 		ifc->m->bwrite(ifc, nb, V6, gate);
@@ -328,22 +321,19 @@ raise:
 	runlock(ifc);
 	poperror();
 free:
-	freeblist(bp);	
+	freeblist(bp);
 	return rv;
 }
 
 void
 ipiput6(Fs *f, Ipifc *ifc, Block *bp)
 {
-	int hl;
-	int hop, tos;
+	int hl, hop, tos, notforme, tentative;
 	uchar proto;
-	Ip6hdr *h;
-	Proto *p;
-	int notforme;
-	int tentative;
 	uchar v6dst[IPaddrlen];
 	IP *ip;
+	Ip6hdr *h;
+	Proto *p;
 	Route *r, *sr;
 
 	ip = f->ip;
@@ -365,13 +355,13 @@ ipiput6(Fs *f, Ipifc *ifc, Block *bp)
 			return;
 	}
 
-	h = (Ip6hdr *)(bp->rp);
+	h = (Ip6hdr *)bp->rp;
 
-	memmove(&v6dst[0], &(h->dst)[0], IPaddrlen);
+	memmove(&v6dst[0], &h->dst[0], IPaddrlen);
 	notforme = ipforme(f, v6dst) == 0;
 	tentative = iptentative(f, v6dst);
-  
-	if(tentative && (h->proto != ICMPv6)) {
+
+	if(tentative && h->proto != ICMPv6) {
 		print("tentative addr, drop\n");
 		freeblist(bp);
 		return;
@@ -393,7 +383,7 @@ ipiput6(Fs *f, Ipifc *ifc, Block *bp)
 		}
 		/* don't forward to source's network */
 		sr = v6lookup(f, h->src, nil);
-		r = v6lookup(f, h->dst, nil);
+		r  = v6lookup(f, h->dst, nil);
 
 		if(r == nil || sr == r){
 			ip->stats[OutDiscards]++;
@@ -412,12 +402,11 @@ ipiput6(Fs *f, Ipifc *ifc, Block *bp)
 
 		/* process headers & reassemble if the interface expects it */
 		bp = procxtns(ip, bp, r->ifc->reassemble);
-
 		if(bp == nil)
 			return;
 
 		ip->stats[ForwDatagrams]++;
-		h = (Ip6hdr *) (bp->rp);
+		h = (Ip6hdr *)bp->rp;
 		tos = IPV6CLASS(h);
 		hop = h->ttl;
 		ipoput6(f, bp, 1, hop-1, tos, nil);
@@ -426,14 +415,13 @@ ipiput6(Fs *f, Ipifc *ifc, Block *bp)
 
 	/* reassemble & process headers if needed */
 	bp = procxtns(ip, bp, 1);
-
 	if(bp == nil)
 		return;
 
 	h = (Ip6hdr *) (bp->rp);
 	proto = h->proto;
 	p = Fsrcvpcol(f, proto);
-	if(p != nil && p->rcv != nil) {
+	if(p && p->rcv) {
 		ip->stats[InDelivers]++;
 		(*p->rcv)(p, ifc, bp);
 		return;
@@ -470,7 +458,6 @@ ipfragfree6(IP *ip, Fragment6 *frag)
 
 	frag->next = ip->fragfree6;
 	ip->fragfree6 = frag;
-
 }
 
 /*
@@ -497,33 +484,32 @@ ipfragallo6(IP *ip)
 }
 
 static Block*
-procxtns(IP *ip, Block *bp, int doreasm) {
-
+procxtns(IP *ip, Block *bp, int doreasm)
+{
 	int offset;
 	uchar proto;
 	Ip6hdr *h;
 
-	h = (Ip6hdr *) (bp->rp);
+	h = (Ip6hdr *)bp->rp;
 	offset = unfraglen(bp, &proto, 0);
 
-	if((proto == FH) && (doreasm != 0)) {
+	if(proto == FH && doreasm != 0) {
 		bp = ip6reassemble(ip, offset, bp, h);
-		if(bp == nil) 
-			return nil; 
+		if(bp == nil)
+			return nil;
 		offset = unfraglen(bp, &proto, 0);
 	}
 
-	if(proto == DOH || offset > IP6HDR) 
+	if(proto == DOH || offset > IP6HDR)
 		bp = procopts(bp);
-
 	return bp;
 }
 
-
-/*	returns length of "Unfragmentable part", i.e., sum of lengths of ipv6 hdr,
- *	hop-by-hop & routing headers if present; *nexthdr is set to nexthdr value
- *	of the last header in the "Unfragmentable part"; if setfh != 0, nexthdr
- *	field of the last header in the "Unfragmentable part" is set to FH.
+/*
+ * returns length of "Unfragmentable part", i.e., sum of lengths of ipv6 hdr,
+ * hop-by-hop & routing headers if present; *nexthdr is set to nexthdr value
+ * of the last header in the "Unfragmentable part"; if setfh != 0, nexthdr
+ * field of the last header in the "Unfragmentable part" is set to FH.
  */
 int
 unfraglen(Block *bp, uchar *nexthdr, int setfh)
@@ -532,29 +518,25 @@ unfraglen(Block *bp, uchar *nexthdr, int setfh)
 	int ufl, hs;
 
 	p = bp->rp;
-	q = p+6;	/* proto, = p+sizeof(Ip6hdr.vcf)+sizeof(Ip6hdr.ploadlen) */
+	q = p+6;   /* proto, = p+sizeof(Ip6hdr.vcf)+sizeof(Ip6hdr.ploadlen) */
 	*nexthdr = *q;
 	ufl = IP6HDR;
 	p += ufl;
 
-	for(;;) {
+	for(;;)
 		if(*nexthdr == HBH || *nexthdr == RH) {
 			*nexthdr = *p;
 			hs = ((int)*(p+1) + 1) * 8;
 			ufl += hs;
 			q = p;
 			p += hs;
-		}
-		else
+		} else
 			break;
-	}
 
 	if(*nexthdr == FH)
 		*q = *p;
-
 	if(setfh)
 		*q = FH;
-
 	return ufl;
 }
 
@@ -567,16 +549,14 @@ procopts(Block *bp)
 Block*
 ip6reassemble(IP* ip, int uflen, Block* bp, Ip6hdr* ih)
 {
-
-	int fend, offset;
+	int fend, offset, ovlap, len, fragsize, pktposn;
 	uint id;
-	Fragment6 *f, *fnext;
-	Fraghdr6 *fraghdr;
 	uchar src[IPaddrlen], dst[IPaddrlen];
 	Block *bl, **l, *last, *prev;
-	int ovlap, len, fragsize, pktposn;
+	Fraghdr6 *fraghdr;
+	Fragment6 *f, *fnext;
 
-	fraghdr = (Fraghdr6 *) (bp->rp + uflen);
+	fraghdr = (Fraghdr6 *)(bp->rp + uflen);
 	memmove(src, ih->src, IPaddrlen);
 	memmove(dst, ih->dst, IPaddrlen);
 	id = nhgetl(fraghdr->id);
@@ -587,10 +567,9 @@ ip6reassemble(IP* ip, int uflen, Block* bp, Ip6hdr* ih)
 	 */
 	if(bp->next){
 		bp = pullupblock(bp, blocklen(bp));
-		ih = (Ip6hdr *)(bp->rp);
+		ih = (Ip6hdr *)bp->rp;
 	}
 
-
 	qlock(&ip->fraglock6);
 
 	/*
@@ -606,14 +585,13 @@ ip6reassemble(IP* ip, int uflen, Block* bp, Ip6hdr* ih)
 		}
 	}
 
-
 	/*
 	 *  if this isn't a fragmented packet, accept it
 	 *  and get rid of any fragments that might go
 	 *  with it.
 	 */
-	if(nhgets(fraghdr->offsetRM)==0) {	// first frag is also the last
-		if(f != nil) {
+	if(nhgets(fraghdr->offsetRM) == 0) {	/* 1st frag is also last */
+		if(f) {
 			ipfragfree6(ip, f);
 			ip->stats[ReasmFails]++;
 		}
@@ -678,12 +656,10 @@ ip6reassemble(IP* ip, int uflen, Block* bp, Ip6hdr* ih)
 		fend = BKFG(bp)->foff + BKFG(bp)->flen;
 
 		/* Take completely covered segments out */
-
 		while(*l) {
 			ovlap = fend - BKFG(*l)->foff;
-
-			if(ovlap <= 0) 
-				break; 
+			if(ovlap <= 0)
+				break;
 			if(ovlap < BKFG(*l)->flen) {
 				BKFG(*l)->flen -= ovlap;
 				BKFG(*l)->foff += ovlap;
@@ -704,23 +680,18 @@ ip6reassemble(IP* ip, int uflen, Block* bp, Ip6hdr* ih)
 	 *  with the trailing bit of fraghdr->offsetRM[1] set, we're done.
 	 */
 	pktposn = 0;
-	for(bl = f->blist; bl; bl = bl->next) {
-		if(BKFG(bl)->foff != pktposn)
-			break;
-	
-		fraghdr = (Fraghdr6 *) (bl->rp + uflen);
+	for(bl = f->blist; bl && BKFG(bl)->foff == pktposn; bl = bl->next) {
+		fraghdr = (Fraghdr6 *)(bl->rp + uflen);
 		if((fraghdr->offsetRM[1] & 1) == 0) {
-
 			bl = f->blist;
 
 			/* get rid of frag header in first fragment */
-
 			memmove(bl->rp + IP6FHDR, bl->rp, uflen);
 			bl->rp += IP6FHDR;
-			len = nhgets(((Ip6hdr*)(bl->rp))->ploadlen) - IP6FHDR;
+			len = nhgets(((Ip6hdr*)bl->rp)->ploadlen) - IP6FHDR;
 			bl->wp = bl->rp + len + IP6HDR;
-
-			/* Pullup all the fragment headers and
+			/*
+			 * Pullup all the fragment headers and
 			 * return a complete packet
 			 */
 			for(bl = bl->next; bl; bl = bl->next) {
@@ -733,15 +704,14 @@ ip6reassemble(IP* ip, int uflen, Block* bp, Ip6hdr* ih)
 			bl = f->blist;
 			f->blist = nil;
 			ipfragfree6(ip, f);
-			ih = (Ip6hdr*)(bl->rp);
+			ih = (Ip6hdr*)bl->rp;
 			hnputs(ih->ploadlen, len);
 			qunlock(&ip->fraglock6);
 			ip->stats[ReasmOKs]++;
-			return bl;		
+			return bl;
 		}
 		pktposn += BKFG(bl)->flen;
 	}
 	qunlock(&ip->fraglock6);
 	return nil;
 }
-

+ 2 - 2
sys/src/cmd/ndb/cs.c

@@ -1770,9 +1770,9 @@ ipinfoquery(Mfile *mf, char **list, int n)
 	 */
 	nresolve = 0;
 	for(i = 0; i < n; i++)
-		if(*list[i] == '@'){
+		if(*list[i] == '@'){		/* @attr=val ? */
 			list[i]++;
-			resolve[i] = 1;
+			resolve[i] = 1;		/* we'll resolve it */
 			nresolve++;
 		} else
 			resolve[i] = 0;

+ 2 - 2
sys/src/libndb/ndbipinfo.c

@@ -34,8 +34,8 @@ mkfilter(int argc, char **argv)
 			first = t;
 		last = t;
 		p = *argv++;
-		if(*p == '@'){
-			t->ptr |= Faddr;
+		if(*p == '@'){			/* @attr=val ? */
+			t->ptr |= Faddr;	/* return resolved address(es) */
 			p++;
 		}
 		strncpy(t->attr, p, sizeof(t->attr)-1);