Browse Source

Plan 9 from Bell Labs 2007-04-18

David du Colombier 14 years ago
parent
commit
5ddf7a5e84

+ 12 - 7
dist/replica/_plan9.db

@@ -1399,7 +1399,7 @@ lib/face/48x48x4/x/xigh.1 - 664 sys sys 1142019024 1204
 lib/face/48x48x4/y - 20000000775 sys sys 1020895714 0
 lib/face/48x48x4/z - 20000000775 sys sys 1020895714 0
 lib/face/48x48x8 - 20000000775 sys sys 1123100641 0
-lib/face/48x48x8/.dict - 664 sys sys 1176753287 3931
+lib/face/48x48x8/.dict - 664 sys sys 1176834010 4026
 lib/face/48x48x8/Z - 20000000775 sys sys 1020895714 0
 lib/face/48x48x8/a - 20000000775 sys sys 1056983599 0
 lib/face/48x48x8/a/alcortes.1 - 664 sys sys 1176753392 976
@@ -1421,6 +1421,7 @@ lib/face/48x48x8/c/comcast.1 - 664 sys sys 1057025679 6972
 lib/face/48x48x8/d - 20000000775 sys sys 1118196820 0
 lib/face/48x48x8/d/daiello.1 - 664 sys sys 1176753392 902
 lib/face/48x48x8/d/dancross.1 - 664 sys sys 1057029244 1580
+lib/face/48x48x8/d/devon.1 - 664 sys sys 1176834003 1487
 lib/face/48x48x8/d/dlewis.1 - 664 sys sys 1118196820 2364
 lib/face/48x48x8/e - 20000000775 sys sys 1155331573 0
 lib/face/48x48x8/e/ericvh.2 - 664 sys sys 1155331573 1049
@@ -5471,7 +5472,7 @@ rc/bin/broke - 775 sys sys 1143389260 142
 rc/bin/bundle - 775 sys sys 945617206 173
 rc/bin/c: - 775 sys sys 1015089511 86
 rc/bin/cpurc - 775 sys sys 1176444833 1884
-rc/bin/cpurc.local - 775 sys sys 1176502011 448
+rc/bin/cpurc.local - 775 sys sys 1176827268 367
 rc/bin/delkey - 775 sys sys 1109429137 643
 rc/bin/dial - 20000000775 sys sys 1059180057 0
 rc/bin/diffy - 775 sys sys 1140694870 277
@@ -5592,7 +5593,7 @@ rc/bin/start - 775 sys sys 945617209 120
 rc/bin/stock - 775 sys sys 1143126371 292
 rc/bin/stop - 775 sys sys 945617209 110
 rc/bin/tel - 775 sys sys 1161209756 128
-rc/bin/termrc - 775 sys sys 1176444113 1665
+rc/bin/termrc - 775 sys sys 1176830829 1692
 rc/bin/termrc.local - 775 sys sys 1176500067 425
 rc/bin/thesaurus - 775 sys sys 1068054167 246
 rc/bin/tlsclienttunnel - 775 sys sys 1024375633 153
@@ -7944,7 +7945,7 @@ 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 1134498903 18054
+sys/src/9/ip/icmp6.c - 664 sys sys 1176844023 17914
 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
@@ -7955,7 +7956,7 @@ sys/src/9/ip/ipifc.c - 664 sys sys 1168305861 34233
 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.h - 664 sys sys 1169493796 4314
+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
 sys/src/9/ip/netlog.c - 664 sys sys 1026847568 4003
@@ -12789,7 +12790,7 @@ sys/src/cmd/ndb/dblookup.c - 664 sys sys 1175901604 21010
 sys/src/cmd/ndb/dn.c - 664 sys sys 1175925585 32939
 sys/src/cmd/ndb/dnarea.c - 664 sys sys 1175664421 2519
 sys/src/cmd/ndb/dnnotify.c - 664 sys sys 1175901450 3147
-sys/src/cmd/ndb/dnresolve.c - 664 sys sys 1175927771 29811
+sys/src/cmd/ndb/dnresolve.c - 664 sys sys 1176837575 30062
 sys/src/cmd/ndb/dns.c - 664 sys sys 1175901186 16013
 sys/src/cmd/ndb/dns.h - 664 sys sys 1175901645 10640
 sys/src/cmd/ndb/dnsdebug.c - 664 sys sys 1176746985 8741
@@ -14203,7 +14204,7 @@ sys/src/cmd/upas/send/tryit - 664 sys sys 944961322 584
 sys/src/cmd/upas/smtp - 20000000775 sys sys 1067741333 0
 sys/src/cmd/upas/smtp/greylist.c - 664 sys sys 1161209057 6546
 sys/src/cmd/upas/smtp/mkfile - 664 sys sys 1108910002 801
-sys/src/cmd/upas/smtp/mxdial.c - 664 sys sys 1131293478 6420
+sys/src/cmd/upas/smtp/mxdial.c - 664 sys sys 1176837561 6567
 sys/src/cmd/upas/smtp/rfc822.y - 664 sys sys 1064589606 13417
 sys/src/cmd/upas/smtp/rmtdns.c - 664 sys sys 1015013150 1069
 sys/src/cmd/upas/smtp/smtp.c - 664 sys sys 1143759341 20123
@@ -15800,3 +15801,7 @@ 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

+ 12 - 11
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
@@ -1399,7 +1399,7 @@ lib/face/48x48x4/x/xigh.1 - 664 sys sys 1142019024 1204
 lib/face/48x48x4/y - 20000000775 sys sys 1020895714 0
 lib/face/48x48x4/z - 20000000775 sys sys 1020895714 0
 lib/face/48x48x8 - 20000000775 sys sys 1123100641 0
-lib/face/48x48x8/.dict - 664 sys sys 1176753287 3931
+lib/face/48x48x8/.dict - 664 sys sys 1176834010 4026
 lib/face/48x48x8/Z - 20000000775 sys sys 1020895714 0
 lib/face/48x48x8/a - 20000000775 sys sys 1056983599 0
 lib/face/48x48x8/a/alcortes.1 - 664 sys sys 1176753392 976
@@ -1421,6 +1421,7 @@ lib/face/48x48x8/c/comcast.1 - 664 sys sys 1057025679 6972
 lib/face/48x48x8/d - 20000000775 sys sys 1118196820 0
 lib/face/48x48x8/d/daiello.1 - 664 sys sys 1176753392 902
 lib/face/48x48x8/d/dancross.1 - 664 sys sys 1057029244 1580
+lib/face/48x48x8/d/devon.1 - 664 sys sys 1176834003 1487
 lib/face/48x48x8/d/dlewis.1 - 664 sys sys 1118196820 2364
 lib/face/48x48x8/e - 20000000775 sys sys 1155331573 0
 lib/face/48x48x8/e/ericvh.2 - 664 sys sys 1155331573 1049
@@ -5471,7 +5472,7 @@ rc/bin/broke - 775 sys sys 1143389260 142
 rc/bin/bundle - 775 sys sys 945617206 173
 rc/bin/c: - 775 sys sys 1015089511 86
 rc/bin/cpurc - 775 sys sys 1176444833 1884
-rc/bin/cpurc.local - 775 sys sys 1176502011 448
+rc/bin/cpurc.local - 775 sys sys 1176827268 367
 rc/bin/delkey - 775 sys sys 1109429137 643
 rc/bin/dial - 20000000775 sys sys 1059180057 0
 rc/bin/diffy - 775 sys sys 1140694870 277
@@ -5592,7 +5593,7 @@ rc/bin/start - 775 sys sys 945617209 120
 rc/bin/stock - 775 sys sys 1143126371 292
 rc/bin/stop - 775 sys sys 945617209 110
 rc/bin/tel - 775 sys sys 1161209756 128
-rc/bin/termrc - 775 sys sys 1176444113 1665
+rc/bin/termrc - 775 sys sys 1176830829 1692
 rc/bin/termrc.local - 775 sys sys 1176500067 425
 rc/bin/thesaurus - 775 sys sys 1068054167 246
 rc/bin/tlsclienttunnel - 775 sys sys 1024375633 153
@@ -7944,7 +7945,7 @@ 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 1134498903 18054
+sys/src/9/ip/icmp6.c - 664 sys sys 1176844023 17914
 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
@@ -7955,7 +7956,7 @@ sys/src/9/ip/ipifc.c - 664 sys sys 1168305861 34233
 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.h - 664 sys sys 1169493796 4314
+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
 sys/src/9/ip/netlog.c - 664 sys sys 1026847568 4003
@@ -12789,7 +12790,7 @@ sys/src/cmd/ndb/dblookup.c - 664 sys sys 1175901604 21010
 sys/src/cmd/ndb/dn.c - 664 sys sys 1175925585 32939
 sys/src/cmd/ndb/dnarea.c - 664 sys sys 1175664421 2519
 sys/src/cmd/ndb/dnnotify.c - 664 sys sys 1175901450 3147
-sys/src/cmd/ndb/dnresolve.c - 664 sys sys 1175927771 29811
+sys/src/cmd/ndb/dnresolve.c - 664 sys sys 1176837575 30062
 sys/src/cmd/ndb/dns.c - 664 sys sys 1175901186 16013
 sys/src/cmd/ndb/dns.h - 664 sys sys 1175901645 10640
 sys/src/cmd/ndb/dnsdebug.c - 664 sys sys 1176746985 8741
@@ -14203,7 +14204,7 @@ sys/src/cmd/upas/send/tryit - 664 sys sys 944961322 584
 sys/src/cmd/upas/smtp - 20000000775 sys sys 1067741333 0
 sys/src/cmd/upas/smtp/greylist.c - 664 sys sys 1161209057 6546
 sys/src/cmd/upas/smtp/mkfile - 664 sys sys 1108910002 801
-sys/src/cmd/upas/smtp/mxdial.c - 664 sys sys 1131293478 6420
+sys/src/cmd/upas/smtp/mxdial.c - 664 sys sys 1176837561 6567
 sys/src/cmd/upas/smtp/rfc822.y - 664 sys sys 1064589606 13417
 sys/src/cmd/upas/smtp/rmtdns.c - 664 sys sys 1015013150 1069
 sys/src/cmd/upas/smtp/smtp.c - 664 sys sys 1143759341 20123

+ 13 - 0
dist/replica/plan9.log

@@ -48401,3 +48401,16 @@
 1176753606 28 a lib/face/48x48x8/y/yoshihide.1 - 664 sys sys 1176753394 909
 1176755406 0 a arm/inflate - 664 sys sys 1176753895 20480
 1176755406 1 a sys/src/boot/bitsy/sinflate - 775 sys sys 1176753922 20696
+1176827406 0 c rc/bin/cpurc.local - 775 sys sys 1176827268 367
+1176831006 0 c rc/bin/termrc - 775 sys sys 1176830829 1692
+1176834611 0 c lib/face/48x48x8/.dict - 664 sys sys 1176834010 4026
+1176834611 1 a lib/face/48x48x8/d/devon.1 - 664 sys sys 1176834003 1487
+1176838212 0 c sys/src/9/ip/ipv6.h - 664 sys sys 1176837552 4280
+1176838212 1 c sys/src/cmd/ndb/dnresolve.c - 664 sys sys 1176837575 30062
+1176838212 2 c sys/src/cmd/upas/smtp/mxdial.c - 664 sys sys 1176837561 6567
+1176845406 0 c sys/src/9/ip/icmp6.c - 664 sys sys 1176844023 17914
+1176845406 1 c sys/src/9/ip/ipv6.h - 664 sys sys 1176844019 4087
+1176867006 0 c 386/bin/ndb/dns - 775 sys sys 1176866482 286892
+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

+ 3 - 0
lib/face/48x48x8/.dict

@@ -46,6 +46,7 @@ flowerbed.dyndns.org/zfolkerts z/zfolkerts.1
 fr/unknown u/unknown.fr
 france3.fr/boyd b/boyd.1
 gmail.com/andresdju a/andresdju.1
+gmail.com/devon.odell d/devon.1
 gmail.com/benavento f/fgb.1
 gmail.com/bruce.ellis b/brucee.1
 gmail.com/bruce.ellis b/brucee.2
@@ -56,6 +57,7 @@ gmail.com/joelcsalomon c/chesky.1
 gmail.com/pablohaya p/pablo.1
 gmail.com/saoret.one s/saoret.1
 gmail.com/unknown g/gmail.1
+gmail.com/uriel99 u/uriel.2
 google.com/unknown g/google.1
 gr/unknown u/unknown.gr
 gsyc.escet.urjc.es/nemo n/nemo.1
@@ -96,6 +98,7 @@ plan9.escet.urjc.es/nemo n/nemo.1
 plan9.jp/chesky c/chesky.1
 planete.net/boyd b/boyd.1
 proweb.co.uk/matt m/matt.h.1
+proweb.co.uk/mattmobile m/matt.h.1
 proxima.alt.za/lucio l/lucio.1
 pt/unknown u/unknown.pt
 quanstro.net/quanstro q/quanstro.1

BIN
lib/face/48x48x8/d/devon.1


+ 1 - 4
rc/bin/cpurc.local

@@ -3,12 +3,9 @@
 
 # used only by upas, as default return domain appended to all unqualified
 # return addresses, even local ones
-site=plan9
+site=EXAMPLE
 # replace FILESERVER with the name of your file server
 # here we start with kfs, your local disk file system
 fileserver=kfs
 # replace FACEDOM with the local domain to be used in the faces database
 facedom=FACEDOM
-
-# turn on cooperative scheduling (assuming it starts off)
-echo coop > /dev/reboot

+ 2 - 1
rc/bin/termrc

@@ -28,7 +28,8 @@ sysname=`{cat /dev/sysname}
 if(test -e /net/ipifc/0/ctl)
 	ndb/dns -rf $NDBFILE
 
-aux/timesync $TIMESYNCARGS
+if(! ps|grep -s timesync)
+	aux/timesync $TIMESYNCARGS
 
 # bind all likely devices (#S was bound in boot)
 for(i in f t m v L P U '$' Σ κ)

+ 237 - 257
sys/src/9/ip/icmp6.c

@@ -1,3 +1,6 @@
+/*
+ * Internet Control Message Protocol for IPv6
+ */
 #include "u.h"
 #include "../port/lib.h"
 #include "mem.h"
@@ -7,41 +10,36 @@
 #include "ip.h"
 #include "ipv6.h"
 
-typedef struct ICMPpkt ICMPpkt;
-typedef struct IPICMP IPICMP;
-typedef struct Ndpkt Ndpkt;
-typedef struct NdiscC NdiscC;
-
-struct ICMPpkt {
-	uchar	type;
-	uchar	code;
-	uchar	cksum[2];
-	uchar	icmpid[2];
-	uchar	seq[2];
-};
+enum
+{
+	InMsgs6,
+	InErrors6,
+	OutMsgs6,
+	CsumErrs6,
+	LenErrs6,
+	HlenErrs6,
+	HoplimErrs6,
+	IcmpCodeErrs6,
+	TargetErrs6,
+	OptlenErrs6,
+	AddrmxpErrs6,
+	RouterAddrErrs6,
 
-struct IPICMP {
-	Ip6hdr;
-	ICMPpkt;
+	Nstats6,
 };
 
-struct NdiscC
-{
-	IPICMP;
-	uchar target[IPaddrlen];
+enum {
+	ICMP_USEAD6	= 40,
 };
 
-struct Ndpkt
-{
-	NdiscC;
-	uchar otype;
-	uchar olen;	// length in units of 8 octets(incl type, code),
-				// 1 for IEEE 802 addresses
-	uchar lnaddr[6];	// link-layer address
+enum {
+	Oflag	= 1<<5,
+	Sflag	= 1<<6,
+	Rflag	= 1<<7,
 };
 
-enum {	
-	// ICMPv6 types
+enum {
+	/* ICMPv6 types */
 	EchoReply	= 0,
 	UnreachableV6	= 1,
 	PacketTooBigV6	= 2,
@@ -69,6 +67,54 @@ enum {
 	Maxtype6	= 137,
 };
 
+typedef struct ICMPpkt ICMPpkt;
+typedef struct IPICMP IPICMP;
+typedef struct Ndpkt Ndpkt;
+typedef struct NdiscC NdiscC;
+
+struct ICMPpkt {
+	uchar	type;
+	uchar	code;
+	uchar	cksum[2];
+	uchar	icmpid[2];
+	uchar	seq[2];
+};
+
+struct IPICMP {
+	Ip6hdr;
+	ICMPpkt;
+};
+
+struct NdiscC
+{
+	IPICMP;
+	uchar	target[IPaddrlen];
+};
+
+struct Ndpkt
+{
+	NdiscC;
+	uchar	otype;
+	uchar	olen;		/* length in units of 8 octets(incl type, code),
+				 * 1 for IEEE 802 addresses */
+	uchar	lnaddr[6];	/* link-layer address */
+};
+
+typedef struct Icmppriv6
+{
+	ulong	stats[Nstats6];
+
+	/* message counts */
+	ulong	in[Maxtype6+1];
+	ulong	out[Maxtype6+1];
+} Icmppriv6;
+
+typedef struct Icmpcb6
+{
+	QLock;
+	uchar	headers;
+} Icmpcb6;
+
 char *icmpnames6[Maxtype6+1] =
 {
 [EchoReply]		"EchoReply",
@@ -95,24 +141,6 @@ char *icmpnames6[Maxtype6+1] =
 [RedirectV6]		"RedirectV6",
 };
 
-enum
-{
-	InMsgs6,
-	InErrors6,
-	OutMsgs6,
-	CsumErrs6,
-	LenErrs6,
-	HlenErrs6,
-	HoplimErrs6,
-	IcmpCodeErrs6,
-	TargetErrs6,
-	OptlenErrs6,
-	AddrmxpErrs6,
-	RouterAddrErrs6,
-
-	Nstats6,
-};
-
 static char *statnames6[Nstats6] =
 {
 [InMsgs6]	"InMsgs",
@@ -129,21 +157,6 @@ static char *statnames6[Nstats6] =
 [RouterAddrErrs6]	"RouterAddrErrs",
 };
 
-typedef struct Icmppriv6
-{
-	ulong	stats[Nstats6];
-
-	/* message counts */
-	ulong	in[Maxtype6+1];
-	ulong	out[Maxtype6+1];
-} Icmppriv6;
-
-typedef struct Icmpcb6 
-{
-	QLock;
-	uchar headers;
-} Icmpcb6;
-
 static char *unreachcode[] =
 {
 [icmp6_no_route]	"no route to destination",
@@ -154,24 +167,6 @@ static char *unreachcode[] =
 [icmp6_unkn_code]	"icmp unreachable: unknown code",
 };
 
-enum {
-	ICMP_USEAD6	= 40,
-};
-
-enum {
-	Oflag	= 1<<5,
-	Sflag	= 1<<6,
-	Rflag	= 1<<7,
-};
-
-enum {
-	slladd	= 1,
-	tlladd	= 2,
-	prfinfo	= 3,
-	redhdr	= 4,
-	mtuopt	= 5,
-};
-
 static void icmpkick6(void *x, Block *bp);
 
 static void
@@ -186,10 +181,10 @@ set_cksum(Block *bp)
 {
 	IPICMP *p = (IPICMP *)(bp->rp);
 
-	hnputl(p->vcf, 0);  // borrow IP header as pseudoheader
+	hnputl(p->vcf, 0);  	/* borrow IP header as pseudoheader */
 	hnputs(p->ploadlen, blocklen(bp)-IPV6HDR_LEN);
 	p->proto = 0;
-	p->ttl = ICMPv6;	// ttl gets set later
+	p->ttl = ICMPv6;	/* ttl gets set later */
 	hnputs(p->cksum, 0);
 	hnputs(p->cksum, ptclcsum(bp, 0, blocklen(bp)));
 	p->proto = ICMPv6;
@@ -198,7 +193,8 @@ set_cksum(Block *bp)
 static Block *
 newIPICMP(int packetlen)
 {
-	Block	*nbp;
+	Block *nbp;
+
 	nbp = allocb(packetlen);
 	nbp->wp += packetlen;
 	memset(nbp->rp, 0, packetlen);
@@ -208,17 +204,16 @@ newIPICMP(int packetlen)
 void
 icmpadvise6(Proto *icmp, Block *bp, char *msg)
 {
-	Conv	**c, *s;
-	IPICMP	*p;
-	ushort	recid;
+	ushort recid;
+	Conv **c, *s;
+	IPICMP *p;
 
-	p = (IPICMP *) bp->rp;
+	p = (IPICMP *)bp->rp;
 	recid = nhgets(p->icmpid);
 
 	for(c = icmp->conv; *c; c++) {
 		s = *c;
-		if(s->lport == recid)
-		if(ipcmp(s->raddr, p->dst) == 0){
+		if(s->lport == recid && ipcmp(s->raddr, p->dst) == 0){
 			qhangup(s->rq, msg);
 			qhangup(s->wq, msg);
 			break;
@@ -230,9 +225,9 @@ icmpadvise6(Proto *icmp, Block *bp, char *msg)
 static void
 icmpkick6(void *x, Block *bp)
 {
+	uchar laddr[IPaddrlen], raddr[IPaddrlen];
 	Conv *c = x;
 	IPICMP *p;
-	uchar laddr[IPaddrlen], raddr[IPaddrlen];
 	Icmppriv6 *ipriv = c->p->priv;
 	Icmpcb6 *icb = (Icmpcb6*)c->ptcl;
 
@@ -268,7 +263,7 @@ icmpkick6(void *x, Block *bp)
 
 	set_cksum(bp);
 	p->vcf[0] = 0x06 << 4;
-	if(p->type <= Maxtype6)	
+	if(p->type <= Maxtype6)
 		ipriv->out[p->type]++;
 	ipoput6(c->p->f, bp, 0, c->ttl, c->tos, nil);
 }
@@ -279,12 +274,9 @@ icmpctl6(Conv *c, char **argv, int argc)
 	Icmpcb6 *icb;
 
 	icb = (Icmpcb6*) c->ptcl;
-
-	if(argc==1) {
-		if(strcmp(argv[0], "headers")==0) {
-			icb->headers = 6;
-			return nil;
-		}
+	if(argc==1 && strcmp(argv[0], "headers")==0) {
+		icb->headers = 6;
+		return nil;
 	}
 	return "unknown control request";
 }
@@ -292,16 +284,15 @@ 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;
 
 	if(muxkey == 0) {
 		recid = nhgets(p->icmpid);
 		addr = p->src;
-	}
-	else {
+	} else {
 		recid = muxkey;
 		addr = p->dst;
 	}
@@ -322,8 +313,8 @@ goticmpkt6(Proto *icmp, Block *bp, int muxkey)
 static Block *
 mkechoreply6(Block *bp)
 {
+	uchar addr[IPaddrlen];
 	IPICMP *p = (IPICMP *)(bp->rp);
-	uchar	addr[IPaddrlen];
 
 	ipmove(addr, p->src);
 	ipmove(p->src, p->dst);
@@ -335,27 +326,24 @@ mkechoreply6(Block *bp)
 
 /*
  * sends out an ICMPv6 neighbor solicitation
- * 	suni == SRC_UNSPEC or SRC_UNI, 
+ * 	suni == SRC_UNSPEC or SRC_UNI,
  *	tuni == TARG_MULTI => multicast for address resolution,
  * 	and tuni == TARG_UNI => neighbor reachability.
  */
-
 extern void
 icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac)
 {
-	Block	*nbp;
+	Block *nbp;
 	Ndpkt *np;
 	Proto *icmp = f->t2p[ICMPv6];
 	Icmppriv6 *ipriv = icmp->priv;
 
-
 	nbp = newIPICMP(sizeof(Ndpkt));
 	np = (Ndpkt*) nbp->rp;
 
-
-	if(suni == SRC_UNSPEC) 
+	if(suni == SRC_UNSPEC)
 		memmove(np->src, v6Unspecified, IPaddrlen);
-	else 
+	else
 		memmove(np->src, src, IPaddrlen);
 
 	if(tuni == TARG_UNI)
@@ -367,17 +355,14 @@ icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac)
 	np->code = 0;
 	memmove(np->target, targ, IPaddrlen);
 	if(suni != SRC_UNSPEC) {
-		np->otype = SRC_LLADDRESS;
-		np->olen = 1;	/* 1+1+6 = 8 = 1 8-octet */
+		np->otype = SRC_LLADDR;
+		np->olen = 1;		/* 1+1+6 = 8 = 1 8-octet */
 		memmove(np->lnaddr, mac, sizeof(np->lnaddr));
-	}
-	else {
-		int r = sizeof(Ndpkt)-sizeof(NdiscC);
-		nbp->wp -= r;
-	}
+	} else
+		nbp->wp -= sizeof(Ndpkt) - sizeof(NdiscC);
 
 	set_cksum(nbp);
-	np = (Ndpkt*) nbp->rp;
+	np = (Ndpkt*)nbp->rp;
 	np->ttl = HOP_LIMIT;
 	np->vcf[0] = 0x06 << 4;
 	ipriv->out[NbrSolicit]++;
@@ -391,13 +376,13 @@ icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac)
 extern void
 icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags)
 {
-	Block	*nbp;
+	Block *nbp;
 	Ndpkt *np;
 	Proto *icmp = f->t2p[ICMPv6];
 	Icmppriv6 *ipriv = icmp->priv;
 
 	nbp = newIPICMP(sizeof(Ndpkt));
-	np = (Ndpkt*) nbp->rp;
+	np = (Ndpkt*)nbp->rp;
 
 	memmove(np->src, src, IPaddrlen);
 	memmove(np->dst, dst, IPaddrlen);
@@ -407,8 +392,8 @@ icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags)
 	np->icmpid[0] = flags;
 	memmove(np->target, targ, IPaddrlen);
 
-	np->otype = TARGET_LLADDRESS;
-	np->olen = 1;	
+	np->otype = TARGET_LLADDR;
+	np->olen = 1;
 	memmove(np->lnaddr, mac, sizeof(np->lnaddr));
 
 	set_cksum(nbp);
@@ -423,30 +408,31 @@ icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags)
 extern void
 icmphostunr(Fs *f, Ipifc *ifc, Block *bp, int code, int free)
 {
-	Block *nbp;
-	IPICMP *np;
-	Ip6hdr	*p;
 	int osz = BLEN(bp);
 	int sz = MIN(sizeof(IPICMP) + osz, v6MINTU);
-	Proto	*icmp = f->t2p[ICMPv6];
+	Block *nbp;
+	IPICMP *np;
+	Ip6hdr *p;
+	Proto *icmp = f->t2p[ICMPv6];
 	Icmppriv6 *ipriv = icmp->priv;
 
-	p = (Ip6hdr *) bp->rp;
+	p = (Ip6hdr *)bp->rp;
 
-	if(isv6mcast(p->src)) 
+	if(isv6mcast(p->src))
 		goto clean;
 
 	nbp = newIPICMP(sz);
-	np = (IPICMP *) nbp->rp;
+	np = (IPICMP *)nbp->rp;
 
 	rlock(ifc);
-	if(ipv6anylocal(ifc, np->src)) {
-		netlog(f, Logicmp, "send icmphostunr -> s%I d%I\n", p->src, p->dst);
-	}
+	if(ipv6anylocal(ifc, np->src))
+		netlog(f, Logicmp, "send icmphostunr -> s%I d%I\n",
+			p->src, p->dst);
 	else {
-		netlog(f, Logicmp, "icmphostunr fail -> s%I d%I\n", p->src, p->dst);
+		netlog(f, Logicmp, "icmphostunr fail -> s%I d%I\n",
+			p->src, p->dst);
 		freeblist(nbp);
-		if(free) 
+		if(free)
 			goto clean;
 		else
 			return;
@@ -476,27 +462,28 @@ clean:
 extern void
 icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp)
 {
-	Block *nbp;
-	IPICMP *np;
-	Ip6hdr	*p;
 	int osz = BLEN(bp);
 	int sz = MIN(sizeof(IPICMP) + osz, v6MINTU);
-	Proto	*icmp = f->t2p[ICMPv6];
+	Block *nbp;
+	IPICMP *np;
+	Ip6hdr *p;
+	Proto *icmp = f->t2p[ICMPv6];
 	Icmppriv6 *ipriv = icmp->priv;
 
-	p = (Ip6hdr *) bp->rp;
+	p = (Ip6hdr *)bp->rp;
 
-	if(isv6mcast(p->src)) 
+	if(isv6mcast(p->src))
 		return;
 
 	nbp = newIPICMP(sz);
 	np = (IPICMP *) nbp->rp;
 
-	if(ipv6anylocal(ifc, np->src)) {
-		netlog(f, Logicmp, "send icmpttlexceeded6 -> s%I d%I\n", p->src, p->dst);
-	}
+	if(ipv6anylocal(ifc, np->src))
+		netlog(f, Logicmp, "send icmpttlexceeded6 -> s%I d%I\n",
+			p->src, p->dst);
 	else {
-		netlog(f, Logicmp, "icmpttlexceeded6 fail -> s%I d%I\n", p->src, p->dst);
+		netlog(f, Logicmp, "icmpttlexceeded6 fail -> s%I d%I\n",
+			p->src, p->dst);
 		return;
 	}
 
@@ -514,27 +501,28 @@ icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp)
 extern void
 icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp)
 {
-	Block *nbp;
-	IPICMP *np;
-	Ip6hdr	*p;
 	int osz = BLEN(bp);
 	int sz = MIN(sizeof(IPICMP) + osz, v6MINTU);
-	Proto	*icmp = f->t2p[ICMPv6];
+	Block *nbp;
+	IPICMP *np;
+	Ip6hdr *p;
+	Proto *icmp = f->t2p[ICMPv6];
 	Icmppriv6 *ipriv = icmp->priv;
 
-	p = (Ip6hdr *) bp->rp;
+	p = (Ip6hdr *)bp->rp;
 
-	if(isv6mcast(p->src)) 
+	if(isv6mcast(p->src))
 		return;
 
 	nbp = newIPICMP(sz);
-	np = (IPICMP *) nbp->rp;
+	np = (IPICMP *)nbp->rp;
 
-	if(ipv6anylocal(ifc, np->src)) {
-		netlog(f, Logicmp, "send icmppkttoobig6 -> s%I d%I\n", p->src, p->dst);
-	}
+	if(ipv6anylocal(ifc, np->src))
+		netlog(f, Logicmp, "send icmppkttoobig6 -> s%I d%I\n",
+			p->src, p->dst);
 	else {
-		netlog(f, Logicmp, "icmppkttoobig6 fail -> s%I d%I\n", p->src, p->dst);
+		netlog(f, Logicmp, "icmppkttoobig6 fail -> s%I d%I\n",
+			p->src, p->dst);
 		return;
 	}
 
@@ -554,12 +542,13 @@ icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp)
  * RFC 2461, pages 39-40, pages 57-58.
  */
 static int
-valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv) {
-	int 	sz, osz, unsp, n, ttl, iplen;
-	int 	pktsz = BLEN(bp);
-	uchar	*packet = bp->rp;
-	IPICMP	*p = (IPICMP *) packet;
-	Ndpkt	*np;
+valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv)
+{
+	int sz, osz, unsp, n, ttl, iplen;
+	int pktsz = BLEN(bp);
+	uchar *packet = bp->rp;
+	IPICMP *p = (IPICMP *) packet;
+	Ndpkt *np;
 
 	USED(ifc);
 	n = blocklen(bp);
@@ -576,9 +565,9 @@ valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv) {
 		goto err;
 	}
 
-	// Rather than construct explicit pseudoheader, overwrite IPv6 header
+	/* Rather than construct explicit pseudoheader, overwrite IPv6 header */
 	if(p->proto != ICMPv6) {
-		// This code assumes no extension headers!!!
+		/* This code assumes no extension headers!!! */
 		netlog(icmp->f, Logicmp, "icmp error: extension header\n");
 		goto err;
 	}
@@ -595,19 +584,16 @@ valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv) {
 	p->ttl = ttl;
 
 	/* additional tests for some pkt types */
-	if( (p->type == NbrSolicit) ||
-		(p->type == NbrAdvert) ||
-		(p->type == RouterAdvert) ||
-		(p->type == RouterSolicit) ||
-		(p->type == RedirectV6) ) {
-
+	if (p->type == NbrSolicit   || p->type == NbrAdvert ||
+	    p->type == RouterAdvert || p->type == RouterSolicit ||
+	    p->type == RedirectV6) {
 		if(p->ttl != HOP_LIMIT) {
-			ipriv->stats[HoplimErrs6]++; 
-			goto err; 
+			ipriv->stats[HoplimErrs6]++;
+			goto err;
 		}
 		if(p->code != 0) {
-			ipriv->stats[IcmpCodeErrs6]++; 
-			goto err; 
+			ipriv->stats[IcmpCodeErrs6]++;
+			goto err;
 		}
 
 		switch (p->type) {
@@ -615,73 +601,71 @@ valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv) {
 		case NbrAdvert:
 			np = (Ndpkt*) p;
 			if(isv6mcast(np->target)) {
-				ipriv->stats[TargetErrs6]++; 
-				goto err; 
+				ipriv->stats[TargetErrs6]++;
+				goto err;
 			}
-			if(optexsts(np) && (np->olen == 0)) {
-				ipriv->stats[OptlenErrs6]++; 
-				goto err; 
+			if(optexsts(np) && np->olen == 0) {
+				ipriv->stats[OptlenErrs6]++;
+				goto err;
 			}
-		
-			if(p->type == NbrSolicit) {
-				if(ipcmp(np->src, v6Unspecified) == 0) { 
-					if(!issmcast(np->dst) || optexsts(np))  {
-						ipriv->stats[AddrmxpErrs6]++; 
+
+			if(p->type == NbrSolicit)
+				if(ipcmp(np->src, v6Unspecified) == 0)
+					if(!issmcast(np->dst) || optexsts(np)) {
+						ipriv->stats[AddrmxpErrs6]++;
 						goto err;
 					}
+
+			if(p->type == NbrAdvert)
+				if(isv6mcast(np->dst) &&
+				    (nhgets(np->icmpid) & Sflag)){
+					ipriv->stats[AddrmxpErrs6]++;
+					goto err;
 				}
-			}
-		
-			if(p->type == NbrAdvert) {
-				if((isv6mcast(np->dst))&&(nhgets(np->icmpid) & Sflag)){
-					ipriv->stats[AddrmxpErrs6]++; 
-					goto err; 
-				}
-			}
 			break;
-	
+
 		case RouterAdvert:
 			if(pktsz - sizeof(Ip6hdr) < 16) {
-				ipriv->stats[HlenErrs6]++; 
-				goto err; 
+				ipriv->stats[HlenErrs6]++;
+				goto err;
 			}
 			if(!islinklocal(p->src)) {
-				ipriv->stats[RouterAddrErrs6]++; 
-				goto err; 
+				ipriv->stats[RouterAddrErrs6]++;
+				goto err;
 			}
 			sz = sizeof(IPICMP) + 8;
-			while ((sz+1) < pktsz) {
-				osz = *(packet+sz+1);
+			while (sz+1 < pktsz) {
+				osz = packet[sz+1];
 				if(osz <= 0) {
-					ipriv->stats[OptlenErrs6]++; 
-					goto err; 
-				}	
+					ipriv->stats[OptlenErrs6]++;
+					goto err;
+				}
 				sz += 8*osz;
 			}
 			break;
-	
+
 		case RouterSolicit:
 			if(pktsz - sizeof(Ip6hdr) < 8) {
-				ipriv->stats[HlenErrs6]++; 
-				goto err; 
+				ipriv->stats[HlenErrs6]++;
+				goto err;
 			}
 			unsp = (ipcmp(p->src, v6Unspecified) == 0);
 			sz = sizeof(IPICMP) + 8;
-			while ((sz+1) < pktsz) {
-				osz = *(packet+sz+1);
-				if((osz <= 0) ||
-					(unsp && (*(packet+sz) == slladd)) ) {
-					ipriv->stats[OptlenErrs6]++; 
-					goto err; 
+			while (sz+1 < pktsz) {
+				osz = packet[sz+1];
+				if(osz <= 0 ||
+				    (unsp && packet[sz] == SRC_LLADDR)) {
+					ipriv->stats[OptlenErrs6]++;
+					goto err;
 				}
 				sz += 8*osz;
 			}
 			break;
-	
+
 		case RedirectV6:
-			//to be filled in
+			/* to be filled in */
 			break;
-	
+
 		default:
 			goto err;
 		}
@@ -690,7 +674,7 @@ valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv) {
 	return 1;
 
 err:
-	ipriv->stats[InErrors6]++; 
+	ipriv->stats[InErrors6]++;
 	return 0;
 }
 
@@ -706,13 +690,12 @@ targettype(Fs *f, Ipifc *ifc, uchar *target)
 		return t_uniproxy;
 	}
 
-	for(lifc = ifc->lifc; lifc; lifc = lifc->next) {
+	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;
 		}
-	}
 
 	runlock(ifc);
 	return 0;
@@ -721,25 +704,22 @@ targettype(Fs *f, Ipifc *ifc, uchar *target)
 static void
 icmpiput6(Proto *icmp, Ipifc *ipifc, Block *bp)
 {
-	uchar	*packet = bp->rp;
-	IPICMP	*p = (IPICMP *)packet;
-	Icmppriv6 *ipriv = icmp->priv;
-	Block	*r;
-	Proto	*pr;
-	char	*msg, m2[128];
-	Ndpkt* np;
+	int refresh = 1;
+	char *msg, m2[128];
 	uchar pktflags;
+	uchar *packet = bp->rp;
 	uchar lsrc[IPaddrlen];
-	int refresh = 1;
+	Block *r;
+	IPICMP *p = (IPICMP *)packet;
+	Icmppriv6 *ipriv = icmp->priv;
 	Iplifc *lifc;
+	Ndpkt* np;
+	Proto *pr;
 
-	if(!valid(icmp, ipifc, bp, ipriv)) 
+	if(!valid(icmp, ipifc, bp, ipriv) || p->type > Maxtype6)
 		goto raise;
 
-	if(p->type <= Maxtype6)
-		ipriv->in[p->type]++;
-	else
-		goto raise;
+	ipriv->in[p->type]++;
 
 	switch(p->type) {
 	case EchoRequestV6:
@@ -793,11 +773,12 @@ icmpiput6(Proto *icmp, Ipifc *ipifc, Block *bp)
 
 	case RouterAdvert:
 	case RouterSolicit:
-		/* using lsrc as a temp, munge hdr for goticmp6 
-		memmove(lsrc, p->src, IPaddrlen);
-		memmove(p->src, p->dst, IPaddrlen);
-		memmove(p->dst, lsrc, IPaddrlen); */
-
+		/* using lsrc as a temp, munge hdr for goticmp6 */
+		if (0) {
+			memmove(lsrc, p->src, IPaddrlen);
+			memmove(p->src, p->dst, IPaddrlen);
+			memmove(p->dst, lsrc, IPaddrlen);
+		}
 		goticmpkt6(icmp, bp, p->type);
 		break;
 
@@ -809,16 +790,17 @@ icmpiput6(Proto *icmp, Ipifc *ipifc, Block *bp)
 			pktflags |= Oflag;
 			/* fall through */
 
-		case t_uniproxy: 
+		case t_uniproxy:
 			if(ipcmp(np->src, v6Unspecified) != 0) {
-				arpenter(icmp->f, V6, np->src, np->lnaddr, 8*np->olen-2, 0);
+				arpenter(icmp->f, V6, np->src, np->lnaddr,
+					8*np->olen-2, 0);
 				pktflags |= Sflag;
 			}
-			if(ipv6local(ipifc, lsrc)) {
-				icmpna(icmp->f, lsrc, 
-				   (ipcmp(np->src, v6Unspecified)==0)?v6allnodesL:np->src,
-				   np->target, ipifc->mac, pktflags); 
-			}
+			if(ipv6local(ipifc, lsrc))
+				icmpna(icmp->f, lsrc,
+					(ipcmp(np->src, v6Unspecified) == 0?
+						v6allnodesL: np->src),
+					np->target, ipifc->mac, pktflags);
 			else
 				freeblist(bp);
 			break;
@@ -826,31 +808,30 @@ icmpiput6(Proto *icmp, Ipifc *ipifc, Block *bp)
 		case t_unitent:
 			/* not clear what needs to be done. send up
 			 * an icmp mesg saying don't use this address? */
-
 		default:
 			freeblist(bp);
 		}
-
 		break;
 
 	case NbrAdvert:
 		np = (Ndpkt*) p;
 
-		/* if the target address matches one of the local interface 
-		 * address and the local interface address has tentative bit set, 
-		 * then insert into ARP table. this is so the duplication address 
-		 * detection part of ipconfig can discover duplication through 
-		 * the arp table
+		/*
+		 * if the target address matches one of the local interface
+		 * addresses and the local interface address has tentative bit
+		 * set, insert into ARP table. this is so the duplicate address
+		 * detection part of ipconfig can discover duplication through
+		 * the arp table.
 		 */
 		lifc = iplocalonifc(ipifc, np->target);
 		if(lifc && lifc->tentative)
 			refresh = 0;
-		arpenter(icmp->f, V6, np->target, np->lnaddr, 8*np->olen-2, refresh);
+		arpenter(icmp->f, V6, np->target, np->lnaddr, 8*np->olen-2,
+			refresh);
 		freeblist(bp);
 		break;
 
 	case PacketTooBigV6:
-
 	default:
 		goticmpkt6(icmp, bp, 0);
 		break;
@@ -859,7 +840,6 @@ icmpiput6(Proto *icmp, Ipifc *ipifc, Block *bp)
 
 raise:
 	freeblist(bp);
-
 }
 
 int
@@ -874,18 +854,19 @@ icmpstats6(Proto *icmp6, char *buf, int len)
 	e = p+len;
 	for(i = 0; i < Nstats6; i++)
 		p = seprint(p, e, "%s: %lud\n", statnames6[i], priv->stats[i]);
-	for(i = 0; i <= Maxtype6; i++){
+	for(i = 0; i <= Maxtype6; i++)
 		if(icmpnames6[i])
-			p = seprint(p, e, "%s: %lud %lud\n", icmpnames6[i], priv->in[i], priv->out[i]);
+			p = seprint(p, e, "%s: %lud %lud\n", icmpnames6[i],
+				priv->in[i], priv->out[i]);
 /*		else
-			p = seprint(p, e, "%d: %lud %lud\n", i, priv->in[i], priv->out[i]);
-*/
-	}
+			p = seprint(p, e, "%d: %lud %lud\n", i, priv->in[i],
+				priv->out[i]);
+ */
 	return p - buf;
 }
 
 
-// need to import from icmp.c
+/* import from icmp.c */
 extern int	icmpstate(Conv *c, char *state, int n);
 extern char*	icmpannounce(Conv *c, char **argv, int argc);
 extern char*	icmpconnect(Conv *c, char **argv, int argc);
@@ -914,4 +895,3 @@ icmp6init(Fs *fs)
 
 	Fsproto(fs, icmp6);
 }
-

+ 109 - 115
sys/src/9/ip/ipv6.h

@@ -1,4 +1,6 @@
-#define MIN(a, b) ((a) <= (b) ? (a) : (b))
+#ifndef MIN
+#define MIN(a, b) ((a) <= (b)? (a): (b))
+#endif
 
 /* rfc 3513 defines the address prefices */
 #define isv6mcast(addr)	  ((addr)[0] == 0xff)
@@ -6,47 +8,13 @@
 #define issitelocal(addr) ((addr)[0] == 0xfe && ((addr)[1] & 0xc0) == 0xc0)
 #define isv6global(addr) (((addr)[0] & 0xe0) == 0x20)
 
-#define optexsts(np) (nhgets((np)->ploadlen) > 24)
-#define issmcast(addr) (memcmp((addr), v6solicitednode, 13) == 0)
+#define optexsts(np)	(nhgets((np)->ploadlen) > 24)
+#define issmcast(addr)	(memcmp((addr), v6solicitednode, 13) == 0)
 
 /* from RFC 2460 */
 
-typedef struct Ip6hdr     Ip6hdr;
-typedef struct Opthdr     Opthdr;
-typedef struct Routinghdr Routinghdr;
-typedef struct Fraghdr6    Fraghdr6;
-
-struct Ip6hdr {
-	uchar vcf[4];       	// version:4, traffic class:8, flow label:20
-	uchar ploadlen[2];  	// payload length: packet length - 40
-	uchar proto;		// next header type
-	uchar ttl;          	// hop limit
-	uchar src[IPaddrlen];
-	uchar dst[IPaddrlen];
-};
-
-struct Opthdr {
-	uchar nexthdr;
-	uchar len;
-};
-
-struct Routinghdr {
-	uchar nexthdr;
-	uchar len;
-	uchar rtetype;
-	uchar segrem;
-};
-
-struct Fraghdr6 {
-	uchar nexthdr;
-	uchar res;
-	uchar offsetRM[2];	// Offset, Res, M flag
-	uchar id[4];
-};
-
-
-enum {			/* Header Types */
-	HBH		= 0,	//?
+enum {				/* Header Types */
+	HBH		= 0,	/* hop-by-hop multicast routing protocol */
 	ICMP		= 1,
 	IGMP		= 2,
 	GGP		= 3,
@@ -71,88 +39,107 @@ enum {			/* Header Types */
 	Maxhdrtype	= 256,
 };
 
-
 enum {
-	//	multicast flgs and scop
-
-	well_known_flg				= 0,
-	transient_flg				= 1,
-
-	node_local_scop 			= 1,
-	link_local_scop 			= 2,
-	site_local_scop 			= 5,
-	org_local_scop				= 8,
-	global_scop				= 14,
-
-	//	various prefix lengths
-
-	SOLN_PREF_LEN				= 13,
-
-	//	icmpv6 unreach codes
-	icmp6_no_route				= 0,
-	icmp6_ad_prohib				= 1,
-	icmp6_unassigned			= 2,
-	icmp6_adr_unreach			= 3,
-	icmp6_port_unreach			= 4,
-	icmp6_unkn_code				= 5,
-
-	// 	various flags & constants
-
-	v6MINTU      				= 1280,
-	HOP_LIMIT    				= 255,
-	ETHERHDR_LEN 				= 14,
-	IPV6HDR_LEN  				= 40,
-	IPV4HDR_LEN  				= 20,
-
-	// 	option types
-
-	SRC_LLADDRESS    			= 1,
-	TARGET_LLADDRESS 			= 2,
-	PREFIX_INFO      			= 3,
-	REDIR_HEADER     			= 4,
-	MTU_OPTION       			= 5,
-
-	SRC_UNSPEC  				= 0,
-	SRC_UNI     				= 1,
-	TARG_UNI    				= 2,
-	TARG_MULTI  				= 3,
-
-	t_unitent   				= 1,
-	t_uniproxy  				= 2,
-	t_unirany   				= 3,
-
-	//	Router constants (all times in milliseconds)
-
-	MAX_INITIAL_RTR_ADVERT_INTERVAL 	= 16000,
-	MAX_INITIAL_RTR_ADVERTISEMENTS  	= 3,
-	MAX_FINAL_RTR_ADVERTISEMENTS    	= 3,
-	MIN_DELAY_BETWEEN_RAS 			= 3000,
-	MAX_RA_DELAY_TIME     			= 500,
-
-	//	Host constants
-
-	MAX_RTR_SOLICITATION_DELAY 		= 1000,
-	RTR_SOLICITATION_INTERVAL  		= 4000,
-	MAX_RTR_SOLICITATIONS      		= 3,
+	/* multicast flags and scopes */
+
+	Well_known_flg	= 0,
+	Transient_flg	= 1,
+
+	Node_local_scop	= 1,
+	Link_local_scop	= 2,
+	Site_local_scop	= 5,
+	Org_local_scop	= 8,
+	Global_scop	= 14,
+
+	/* various prefix lengths */
+	SOLN_PREF_LEN	= 13,
+
+	/* icmpv6 unreach codes */
+	icmp6_no_route		= 0,
+	icmp6_ad_prohib		= 1,
+	icmp6_unassigned	= 2,
+	icmp6_adr_unreach	= 3,
+	icmp6_port_unreach	= 4,
+	icmp6_unkn_code		= 5,
+
+	/* various flags & constants */
+	v6MINTU		= 1280,
+	HOP_LIMIT	= 255,
+	ETHERHDR_LEN	= 14,
+	IPV6HDR_LEN	= 40,
+	IPV4HDR_LEN	= 20,
+
+	/* option types */
+
+	SRC_LLADDR	= 1,
+	TARGET_LLADDR	= 2,
+	PREFIX_INFO	= 3,
+	REDIR_HEADER	= 4,
+	MTU_OPTION	= 5,
+
+	SRC_UNSPEC	= 0,
+	SRC_UNI		= 1,
+	TARG_UNI	= 2,
+	TARG_MULTI	= 3,
+
+	t_unitent	= 1,
+	t_uniproxy	= 2,
+	t_unirany	= 3,
+
+	/* Router constants (all times in milliseconds) */
+	MAX_INIT_RTR_ADVERT_INTVL = 16000,
+	MAX_INIT_RTR_ADVERTS	= 3,
+	MAX_FINAL_RTR_ADVERTS	= 3,
+	MIN_DELAY_BETWEEN_RAS	= 3000,
+	MAX_RA_DELAY_TIME	= 500,
+
+	/* Host constants */
+	MAX_RTR_SOLICIT_DELAY	= 1000,
+	RTR_SOLICIT_INTVL	= 4000,
+	MAX_RTR_SOLICITS	= 3,
+
+	/* Node constants */
+	MAX_MULTICAST_SOLICIT	= 3,
+	MAX_UNICAST_SOLICIT	= 3,
+	MAX_ANYCAST_DELAY_TIME	= 1000,
+	MAX_NEIGHBOR_ADVERT	= 3,
+	REACHABLE_TIME		= 30000,
+	RETRANS_TIMER		= 1000,
+	DELAY_FIRST_PROBE_TIME	= 5000,
+};
 
-	//	Node constants
+typedef struct Ip6hdr	Ip6hdr;
+typedef struct Opthdr	Opthdr;
+typedef struct Routinghdr Routinghdr;
+typedef struct Fraghdr6	Fraghdr6;
+
+struct	Ip6hdr {
+	uchar	vcf[4];		/* version:4, traffic class:8, flow label:20 */
+	uchar	ploadlen[2];	/* payload length: packet length - 40 */
+	uchar	proto;		/* next header type */
+	uchar	ttl;		/* hop limit */
+	uchar	src[IPaddrlen];
+	uchar	dst[IPaddrlen];
+};
 
-	MAX_MULTICAST_SOLICIT   		= 3,
-	MAX_UNICAST_SOLICIT     		= 3,
-	MAX_ANYCAST_DELAY_TIME  		= 1000,
-	MAX_NEIGHBOR_ADVERTISEMENT 		= 3,
-	REACHABLE_TIME 				= 30000,
-	RETRANS_TIMER  				= 1000,
-	DELAY_FIRST_PROBE_TIME 			= 5000,
+struct	Opthdr {
+	uchar	nexthdr;
+	uchar	len;
+};
 
+struct	Routinghdr {
+	uchar	nexthdr;
+	uchar	len;
+	uchar	rtetype;
+	uchar	segrem;
 };
 
-extern void ipv62smcast(uchar *, uchar *);
-extern void icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac);
-extern void icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags);
-extern void icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp);
-extern void icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp);
-extern void icmphostunr(Fs *f, Ipifc *ifc, Block *bp, int code, int free);
+struct	Fraghdr6 {
+	uchar	nexthdr;
+	uchar	res;
+	uchar	offsetRM[2];	/* Offset, Res, M flag */
+	uchar	id[4];
+};
 
 extern uchar v6allnodesN[IPaddrlen];
 extern uchar v6allnodesL[IPaddrlen];
@@ -183,3 +170,10 @@ extern int v6aNpreflen;
 extern int v6aLpreflen;
 
 extern int ReTransTimer;
+
+void ipv62smcast(uchar *, uchar *);
+void icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac);
+void icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags);
+void icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp);
+void icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp);
+void icmphostunr(Fs *f, Ipifc *ifc, Block *bp, int code, int free);

+ 20 - 11
sys/src/cmd/ndb/dnresolve.c

@@ -540,7 +540,10 @@ readnet(Query *qp, int medium, uchar *ibuf, ulong endtime, uchar **replyp,
 		else if (readn(fd, lenbuf, 2) != 2) {
 			dnslog("readnet: short read of tcp size from %I",
 				qp->tcpip);
-			/* probably a time-out; demote the ns */
+			/*
+			 * probably a time-out; demote the ns.
+			 * actually, the problem may be the query, not the ns.
+			 */
 			addslug(qp->tcpip);
 		} else {
 			len = lenbuf[0]<<8 | lenbuf[1];
@@ -1028,13 +1031,13 @@ procansw(Query *qp, DNSmsg *mp, uchar *srcip, int depth, Dest *p)
 	}
 	procsetname("recursive query for %s %s", qp->dp->name,
 		rrname(qp->type, buf, sizeof buf));
-	qunlock(&qp->dp->querylck);
+//	qunlock(&qp->dp->querylck);
 
 	queryinit(&nquery, qp->dp, qp->type, qp->req);
 	nquery.nsrp = tp;
 	rv = netquery(&nquery, depth+1);
 
-	qlock(&qp->dp->querylck);
+//	qlock(&qp->dp->querylck);
 	rrfreelist(tp);
 	memset(&nquery, 0, sizeof nquery); /* prevent accidents */
 	return rv;
@@ -1246,8 +1249,8 @@ udpquery(Query *qp, char *mntpt, int depth, int patient, int inns)
 	}
 	if(fd >= 0) {
 		qp->req->aborttime = time(nil) + (patient? Maxreqtm: Maxreqtm/2);
-		/* tune; was (patient? 15: 10) */
 		qp->udpfd = fd;
+		/* tune; was (patient? 15: 10) */
 		rv = netquery1(qp, depth, ibuf, obuf, (patient? 10: 5), inns);
 		close(fd);
 	} else
@@ -1277,13 +1280,20 @@ netquery(Query *qp, int depth)
 	 */
 
 	/* don't lock before call to slave so only children can block */
-	lock = qp->req->isslave != 0;
-	if(lock) {
+	if (0)
+		lock = qp->req->isslave != 0;
+	if(0 && lock) {
 		procsetname("query lock wait for %s", qp->dp->name);
-		/* don't make concurrent queries for this name */
+		/*
+		 * don't make concurrent queries for this name.
+		 *
+		 * this seemed like a good idea, to avoid swamping
+		 * an overloaded ns, but in practice, dns processes
+		 * pile up quickly and dns becomes unresponsive for a while.
+		 */
 		qlock(&qp->dp->querylck);
-		procsetname("netquery: %s", qp->dp->name);
 	}
+	procsetname("netquery: %s", qp->dp->name);
 
 	/* prepare server RR's for incremental lookup */
 	for(rp = qp->nsrp; rp; rp = rp->next)
@@ -1323,9 +1333,8 @@ netquery(Query *qp, int depth)
 //	if (rv == 0)		/* could ask /net.alt/dns directly */
 //		askoutdns(qp->dp, qp->type);
 
-	if(lock) {
+	if(0 && lock)
 		qunlock(&qp->dp->querylck);
-	}
 	return rv;
 }
 
@@ -1339,7 +1348,7 @@ seerootns(void)
 
 	memset(&req, 0, sizeof req);
 	req.isslave = 1;
-	req.aborttime = now + Maxreqtm*2;	/* be patient */
+	req.aborttime = now + Maxreqtm;
 	queryinit(&query, dnlookup(root, Cin, 1), Tns, &req);
 	query.nsrp = dblookup(root, Cin, Tns, 0, 0);
 	rv = netquery(&query, 0);

+ 17 - 11
sys/src/cmd/upas/smtp/mxdial.c

@@ -79,14 +79,13 @@ callmx(DS *ds, char *dest, char *domain)
 	}
 
 	/* refuse to honor loopback addresses given by dns */
-	for(i = 0; i < nmx; i++){
+	for(i = 0; i < nmx; i++)
 		if(strcmp(mx[i].ip, "127.0.0.1") == 0){
 			if(debug)
 				fprint(2, "mxlookup returns loopback\n");
 			werrstr("illegal: domain lists 127.0.0.1 as mail server");
 			return -1;
 		}
-	}
 
 	/* sort by preference */
 	if(nmx > 1)
@@ -123,9 +122,9 @@ mxlookup(DS *ds, char *domain)
 	/* just in case we find no domain name */
 	strcpy(domain, ds->host);
 
-	if(ds->netdir){
+	if(ds->netdir)
 		n = mxlookup1(ds, domain);
-	} else {
+	else {
 		ds->netdir = "/net";
 		n = mxlookup1(ds, domain);
 		if(n == 0) {
@@ -140,10 +139,10 @@ mxlookup(DS *ds, char *domain)
 static int
 mxlookup1(DS *ds, char *domain)
 {
-	char buf[1024];
-	char dnsname[Maxstring];
-	char *fields[4];
 	int i, n, fd, nmx;
+	long oalarm;
+	char buf[1024], dnsname[Maxstring];
+	char *fields[4];
 
 	snprint(dnsname, sizeof dnsname, "%s/dns", ds->netdir);
 
@@ -152,10 +151,17 @@ mxlookup1(DS *ds, char *domain)
 		return 0;
 
 	nmx = 0;
-	snprint(buf, sizeof(buf), "%s mx", ds->host);
+	snprint(buf, sizeof buf, "%s mx", ds->host);
 	if(debug)
 		fprint(2, "sending %s '%s'\n", dnsname, buf);
+	/*
+	 * don't hang indefinitely in the write to /net/dns.
+	 */
+	atnotify(timeout, 1);
+	oalarm = alarm(60*1000);
 	n = write(fd, buf, strlen(buf));
+	alarm(oalarm);
+	atnotify(timeout, 0);
 	if(n < 0){
 		rerrstr(buf, sizeof buf);
 		if(debug)
@@ -170,7 +176,7 @@ mxlookup1(DS *ds, char *domain)
 		 *  get any mx entries
 		 */
 		seek(fd, 0, 0);
-		while(nmx < Nmx && (n = read(fd, buf, sizeof(buf)-1)) > 0){
+		while(nmx < Nmx && (n = read(fd, buf, sizeof buf-1)) > 0){
 			buf[n] = 0;
 			if(debug)
 				fprint(2, "dns mx: %s\n", buf);
@@ -227,7 +233,7 @@ mxlookup1(DS *ds, char *domain)
 		mx[i] = mx[nmx];
 		i--;
 	}
-	return nmx;		
+	return nmx;
 }
 
 static int
@@ -291,7 +297,7 @@ expand_meta(DS *ds)
 		return;
 	}
 
-	snprint(buf, sizeof(buf), "!ipinfo %s", ds->host+1);	// +1 to skip $
+	snprint(buf, sizeof buf, "!ipinfo %s", ds->host+1);	// +1 to skip $
 	if(write(fd, buf, strlen(buf)) <= 0){
 		if(debug)
 			fprint(2, "write %s: %r\n", cs);