Browse Source

Plan 9 from Bell Labs 2007-08-15

David du Colombier 13 years ago
parent
commit
2e33844d2c

+ 15 - 16
dist/replica/_plan9.db

@@ -285,7 +285,7 @@
 386/bin/import - 775 sys sys 1179777651 102499
 386/bin/iostats - 775 sys sys 1178568280 98906
 386/bin/ip - 20000000775 sys sys 1016920851 0
-386/bin/ip/6in4 - 775 sys sys 1186257752 90935
+386/bin/ip/6in4 - 775 sys sys 1187061208 91687
 386/bin/ip/dhcpclient - 775 sys sys 1178568281 92992
 386/bin/ip/dhcpd - 775 sys sys 1186112227 151324
 386/bin/ip/dhcpleases - 775 sys sys 1186112228 85106
@@ -562,19 +562,19 @@
 386/lib/libgeometry.a - 664 sys sys 1168402366 50470
 386/lib/libhtml.a - 664 sys sys 1186370975 229202
 386/lib/libhttpd.a - 664 sys sys 1181332906 99734
-386/lib/libip.a - 664 sys sys 1185420496 34710
+386/lib/libip.a - 664 sys sys 1187061208 34710
 386/lib/libl.a - 664 sys sys 1168402367 5372
 386/lib/libmach.a - 664 sys sys 1184380786 807390
 386/lib/libmemdraw.a - 664 sys sys 1168402369 284092
 386/lib/libmemlayer.a - 664 sys sys 1168402369 47360
 386/lib/libmp.a - 664 sys sys 1181332906 79978
-386/lib/libndb.a - 664 sys sys 1185420497 64470
+386/lib/libndb.a - 664 sys sys 1187061208 64470
 386/lib/libplumb.a - 664 sys sys 1168402370 19408
 386/lib/libregexp.a - 664 sys sys 1181507273 37290
 386/lib/libscribble.a - 664 sys sys 1175972562 107238
 386/lib/libsec.a - 664 sys sys 1181332908 646724
 386/lib/libstdio.a - 664 sys sys 1176432133 126062
-386/lib/libsunrpc.a - 664 sys sys 1185420498 353148
+386/lib/libsunrpc.a - 664 sys sys 1187061209 353148
 386/lib/libthread.a - 664 sys sys 1184731247 71918
 386/lib/libventi.a - 664 sys sys 1181332909 97858
 386/mbr - 775 sys sys 1131317338 407
@@ -1403,7 +1403,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 1179510586 4082
+lib/face/48x48x8/.dict - 664 sys sys 1187107503 4193
 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
@@ -1447,6 +1447,7 @@ lib/face/48x48x8/j - 20000000775 sys sys 1020895714 0
 lib/face/48x48x8/j/jmehat.1 - 664 sys sys 1176753392 837
 lib/face/48x48x8/k - 20000000775 sys sys 1123100691 0
 lib/face/48x48x8/k/karen.1 - 664 sys sys 1057005135 1608
+lib/face/48x48x8/k/kix.1 - 664 sys sys 1187107466 779
 lib/face/48x48x8/k/kris.1 - 664 sys sys 1060142993 2364
 lib/face/48x48x8/l - 20000000775 sys sys 1059678230 0
 lib/face/48x48x8/l/lionkov.1 - 664 sys sys 1176753392 924
@@ -7790,7 +7791,7 @@ sys/man/8/cron - 664 sys sys 1063858596 1867
 sys/man/8/dhcpd - 664 sys sys 1172959497 5572
 sys/man/8/disksim - 664 sys sys 1144150487 1476
 sys/man/8/drawterm - 664 sys sys 1181675938 1921
-sys/man/8/fossilcons - 664 sys sys 1181331315 18400
+sys/man/8/fossilcons - 664 sys sys 1187134504 18542
 sys/man/8/fs - 664 sys sys 1172956177 15086
 sys/man/8/fsconfig - 664 sys sys 1172956534 8878
 sys/man/8/fshalt - 664 sys sys 1173737264 862
@@ -7965,7 +7966,7 @@ sys/src/9/ip/arp.c - 664 sys sys 1184794688 11234
 sys/src/9/ip/chandial.c - 664 sys sys 1099020048 2295
 sys/src/9/ip/devip.c - 664 sys sys 1161061185 24242
 sys/src/9/ip/eipconvtest.c - 664 sys sys 1022588098 3135
-sys/src/9/ip/esp.c - 664 sys sys 1187037502 17754
+sys/src/9/ip/esp.c - 664 sys sys 1187064283 19158
 sys/src/9/ip/ethermedium.c - 664 sys sys 1184244252 15419
 sys/src/9/ip/gre.c - 664 sys sys 1187045851 5103
 sys/src/9/ip/icmp.c - 664 sys sys 1184946959 9498
@@ -8168,7 +8169,7 @@ sys/src/9/port/chan.c - 664 sys sys 1146151714 34773
 sys/src/9/port/cis.c - 664 sys sys 1099761153 9248
 sys/src/9/port/debugalloc.c - 664 sys sys 1014931171 10402
 sys/src/9/port/dev.c - 664 sys sys 1146151714 8177
-sys/src/9/port/devaoe.c - 664 sys sys 1187034234 41526
+sys/src/9/port/devaoe.c - 664 sys sys 1187061517 41444
 sys/src/9/port/devaudio.c - 664 sys sys 1170456648 21199
 sys/src/9/port/devbridge.c - 664 sys sys 1185994684 24171
 sys/src/9/port/devcap.c - 664 sys sys 1178886040 4141
@@ -10345,7 +10346,7 @@ sys/src/cmd/fossil/build - 664 sys sys 1042005505 449
 sys/src/cmd/fossil/buildsh - 775 sys sys 1042005505 561
 sys/src/cmd/fossil/bwatch.c - 664 sys sys 1042005505 6754
 sys/src/cmd/fossil/cache.c - 664 sys sys 1180158132 43913
-sys/src/cmd/fossil/check.c - 664 sys sys 1177432003 17448
+sys/src/cmd/fossil/check.c - 664 sys sys 1187136398 17470
 sys/src/cmd/fossil/conf.rc - 775 sys sys 1084333190 1416
 sys/src/cmd/fossil/dat.h - 664 sys sys 1177432005 7655
 sys/src/cmd/fossil/deadlock - 775 sys sys 1042005506 413
@@ -10370,9 +10371,9 @@ sys/src/cmd/fossil/invariants - 664 sys sys 1042005509 4073
 sys/src/cmd/fossil/last.c - 664 sys sys 1087005593 812
 sys/src/cmd/fossil/mkfile - 664 sys sys 1139667242 2640
 sys/src/cmd/fossil/nobwatch.c - 664 sys sys 1042005509 329
-sys/src/cmd/fossil/pack.c - 664 sys sys 1061530726 4682
+sys/src/cmd/fossil/pack.c - 664 sys sys 1187136436 4710
 sys/src/cmd/fossil/periodic.c - 664 sys sys 1061530726 1087
-sys/src/cmd/fossil/source.c - 664 sys sys 1177432004 20301
+sys/src/cmd/fossil/source.c - 664 sys sys 1187135867 20578
 sys/src/cmd/fossil/srcload.c - 664 sys sys 1042005510 4178
 sys/src/cmd/fossil/stdinc.h - 664 sys sys 1042005510 155
 sys/src/cmd/fossil/trunc.c - 664 sys sys 1042005511 280
@@ -15852,8 +15853,6 @@ 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/ip/6in4 - 775 sys sys 1187061208 91687
-386/lib/libip.a - 664 sys sys 1187061208 34710
-386/lib/libndb.a - 664 sys sys 1187061208 64470
-386/lib/libsunrpc.a - 664 sys sys 1187061209 353148
-sys/src/9/port/devaoe.c - 664 sys sys 1187061517 41444
+386/bin/fossil/flchk - 775 sys sys 1187147720 237381
+386/bin/fossil/flfmt - 775 sys sys 1187147721 245386
+386/bin/fossil/fossil - 775 sys sys 1187147721 364045

+ 10 - 9
dist/replica/plan9.db

@@ -236,9 +236,9 @@
 386/bin/fortune - 775 sys sys 1168402308 67356
 386/bin/fossil - 20000000775 sys sys 1042005470 0
 386/bin/fossil/conf - 775 sys sys 1085077052 1506
-386/bin/fossil/flchk - 775 sys sys 1180209225 237116
-386/bin/fossil/flfmt - 775 sys sys 1180209226 245137
-386/bin/fossil/fossil - 775 sys sys 1181851033 363780
+386/bin/fossil/flchk - 775 sys sys 1187147720 237381
+386/bin/fossil/flfmt - 775 sys sys 1187147721 245386
+386/bin/fossil/fossil - 775 sys sys 1187147721 364045
 386/bin/fossil/last - 775 sys sys 1168402310 63550
 386/bin/freq - 775 sys sys 1168402310 62040
 386/bin/fs - 20000000775 sys sys 954380769 0
@@ -1403,7 +1403,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 1179510586 4082
+lib/face/48x48x8/.dict - 664 sys sys 1187107503 4193
 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
@@ -1447,6 +1447,7 @@ lib/face/48x48x8/j - 20000000775 sys sys 1020895714 0
 lib/face/48x48x8/j/jmehat.1 - 664 sys sys 1176753392 837
 lib/face/48x48x8/k - 20000000775 sys sys 1123100691 0
 lib/face/48x48x8/k/karen.1 - 664 sys sys 1057005135 1608
+lib/face/48x48x8/k/kix.1 - 664 sys sys 1187107466 779
 lib/face/48x48x8/k/kris.1 - 664 sys sys 1060142993 2364
 lib/face/48x48x8/l - 20000000775 sys sys 1059678230 0
 lib/face/48x48x8/l/lionkov.1 - 664 sys sys 1176753392 924
@@ -7790,7 +7791,7 @@ sys/man/8/cron - 664 sys sys 1063858596 1867
 sys/man/8/dhcpd - 664 sys sys 1172959497 5572
 sys/man/8/disksim - 664 sys sys 1144150487 1476
 sys/man/8/drawterm - 664 sys sys 1181675938 1921
-sys/man/8/fossilcons - 664 sys sys 1181331315 18400
+sys/man/8/fossilcons - 664 sys sys 1187134504 18542
 sys/man/8/fs - 664 sys sys 1172956177 15086
 sys/man/8/fsconfig - 664 sys sys 1172956534 8878
 sys/man/8/fshalt - 664 sys sys 1173737264 862
@@ -7965,7 +7966,7 @@ sys/src/9/ip/arp.c - 664 sys sys 1184794688 11234
 sys/src/9/ip/chandial.c - 664 sys sys 1099020048 2295
 sys/src/9/ip/devip.c - 664 sys sys 1161061185 24242
 sys/src/9/ip/eipconvtest.c - 664 sys sys 1022588098 3135
-sys/src/9/ip/esp.c - 664 sys sys 1187037502 17754
+sys/src/9/ip/esp.c - 664 sys sys 1187064283 19158
 sys/src/9/ip/ethermedium.c - 664 sys sys 1184244252 15419
 sys/src/9/ip/gre.c - 664 sys sys 1187045851 5103
 sys/src/9/ip/icmp.c - 664 sys sys 1184946959 9498
@@ -10345,7 +10346,7 @@ sys/src/cmd/fossil/build - 664 sys sys 1042005505 449
 sys/src/cmd/fossil/buildsh - 775 sys sys 1042005505 561
 sys/src/cmd/fossil/bwatch.c - 664 sys sys 1042005505 6754
 sys/src/cmd/fossil/cache.c - 664 sys sys 1180158132 43913
-sys/src/cmd/fossil/check.c - 664 sys sys 1177432003 17448
+sys/src/cmd/fossil/check.c - 664 sys sys 1187136398 17470
 sys/src/cmd/fossil/conf.rc - 775 sys sys 1084333190 1416
 sys/src/cmd/fossil/dat.h - 664 sys sys 1177432005 7655
 sys/src/cmd/fossil/deadlock - 775 sys sys 1042005506 413
@@ -10370,9 +10371,9 @@ sys/src/cmd/fossil/invariants - 664 sys sys 1042005509 4073
 sys/src/cmd/fossil/last.c - 664 sys sys 1087005593 812
 sys/src/cmd/fossil/mkfile - 664 sys sys 1139667242 2640
 sys/src/cmd/fossil/nobwatch.c - 664 sys sys 1042005509 329
-sys/src/cmd/fossil/pack.c - 664 sys sys 1061530726 4682
+sys/src/cmd/fossil/pack.c - 664 sys sys 1187136436 4710
 sys/src/cmd/fossil/periodic.c - 664 sys sys 1061530726 1087
-sys/src/cmd/fossil/source.c - 664 sys sys 1177432004 20301
+sys/src/cmd/fossil/source.c - 664 sys sys 1187135867 20578
 sys/src/cmd/fossil/srcload.c - 664 sys sys 1042005510 4178
 sys/src/cmd/fossil/stdinc.h - 664 sys sys 1042005510 155
 sys/src/cmd/fossil/trunc.c - 664 sys sys 1042005511 280

+ 10 - 0
dist/replica/plan9.log

@@ -49972,3 +49972,13 @@
 1187062204 2 c 386/lib/libndb.a - 664 sys sys 1187061208 64470
 1187062204 3 c 386/lib/libsunrpc.a - 664 sys sys 1187061209 353148
 1187062204 4 c sys/src/9/port/devaoe.c - 664 sys sys 1187061517 41444
+1187065804 0 c sys/src/9/ip/esp.c - 664 sys sys 1187064283 19158
+1187109004 0 c lib/face/48x48x8/.dict - 664 sys sys 1187107503 4193
+1187109004 1 a lib/face/48x48x8/k/kix.1 - 664 sys sys 1187107466 779
+1187136004 0 c sys/man/8/fossilcons - 664 sys sys 1187134504 18542
+1187136004 1 c sys/src/cmd/fossil/source.c - 664 sys sys 1187135867 20578
+1187137803 0 c sys/src/cmd/fossil/check.c - 664 sys sys 1187136398 17470
+1187137803 1 c sys/src/cmd/fossil/pack.c - 664 sys sys 1187136436 4710
+1187148603 0 c 386/bin/fossil/flchk - 775 sys sys 1187147720 237381
+1187148603 1 c 386/bin/fossil/flfmt - 775 sys sys 1187147721 245386
+1187148603 2 c 386/bin/fossil/fossil - 775 sys sys 1187147721 364045

+ 5 - 1
lib/face/48x48x8/.dict

@@ -6,11 +6,14 @@ acsnet/boyd b/boyd.1
 alcatel-lucent.com/plus p/plus.1
 alcatel-lucent.com/unknown a/alu.1
 alcatel-lucent.fr/unknown a/alu.1
+alcatel-lucent.de/unknown a/alu.1
+alcatel-lucent.nl/unknown a/alu.1
 alchar.org/aedil k/kris.1
 aprote.ee/t.lankots t/tiit.1
 ar/unknown u/unknown.ar
 arm.com/unknown a/arm.1
 astro/boyd b/boyd.1
+astro/paurea p/paurea.1
 at/unknown u/unknown.at
 au/unknown u/unknown.au
 be/unknown u/unknown.be
@@ -47,10 +50,10 @@ 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
+gmail.com/devon.odell d/devon.1
 gmail.com/ericvh e/ericvh.2
 gmail.com/gabidiaz g/gabidiaz.1
 gmail.com/jmehat j/jmehat.1
@@ -78,6 +81,7 @@ is/unknown u/unknown.is
 it.usyd.edu.au/boyd b/boyd.1
 it/unknown u/unknown.it
 jp/unknown u/unknown.jp
+kix.es/kix k/kix.1
 kr/unknown u/unknown.kr
 lanl.gov/lionkov l/lionkov.1
 lsub.org/cespedes c/cespedes.1

BIN
lib/face/48x48x8/k/kix.1


+ 8 - 0
sys/man/8/fossilcons

@@ -894,6 +894,14 @@ and
 .B l
 mode prefixes
 set the append-only, directory, and lock bits.
+The
+.I perm
+is formatted as described in the
+.I stat
+command;
+creating files or directories with the
+.BR snapshot (s)
+bit set is not allowed.
 .PP
 .I Df
 prints the amount of used disk space in the write buffer.

+ 168 - 108
sys/src/9/ip/esp.c

@@ -1,6 +1,7 @@
 /*
  * Encapsulating Security Payload for IPsec for IPv4, rfc1827.
- * TODO: update to match rfc4303 and thus IPv6.
+ *	currently only implements tunnel mode.
+ * TODO: update to match rfc4303.
  */
 #include	"u.h"
 #include	"../port/lib.h"
@@ -10,28 +11,39 @@
 #include	"../port/error.h"
 
 #include	"ip.h"
+#include	"ipv6.h"
 #include	"libsec.h"
 
 typedef struct Esphdr Esphdr;
+typedef struct Esp4hdr Esp4hdr;
+typedef struct Esp6hdr Esp6hdr;
 typedef struct Esptail Esptail;
 typedef struct Userhdr Userhdr;
 typedef struct Esppriv Esppriv;
 typedef struct Espcb Espcb;
 typedef struct Algorithm Algorithm;
-// typedef struct Esprc4 Esprc4;
-
-#define DPRINT if(0)print
 
 enum
 {
 	IP_ESPPROTO	= 50,	/* IP v4 and v6 protocol number */
-	EsphdrSize	= IP4HDR + 8,
+	Esp4hdrlen	= IP4HDR + 8,
+	Esp6hdrlen	= IP6HDR + 8,
 
-	EsptailSize	= 2,	/* does not include pad or auth data */
-	UserhdrSize	= 4,	/* user-visible header size - if enabled */
+	Esptaillen	= 2,	/* does not include pad or auth data */
+	Userhdrlen	= 4,	/* user-visible header size - if enabled */
 };
 
 struct Esphdr
+{
+	uchar	espspi[4];	/* Security parameter index */
+	uchar	espseq[4];	/* Sequence number */
+};
+
+/*
+ * tunnel-mode layout:		IP | ESP | TCP/UDP | user data.
+ * transport-mode layout is:	ESP | IP | TCP/UDP | user data.
+ */
+struct Esp4hdr
 {
 	/* ipv4 header */
 	uchar	vihl;		/* Version and header length */
@@ -45,9 +57,14 @@ struct Esphdr
 	uchar	espsrc[4];	/* Ip source */
 	uchar	espdst[4];	/* Ip destination */
 
-	/* esp header */
-	uchar	espspi[4];	/* Security parameter index */
-	uchar	espseq[4];	/* Sequence number */
+	Esphdr;
+};
+
+/* tunnel-mode layout */
+struct Esp6hdr
+{
+	Ip6hdr;
+	Esphdr;
 };
 
 struct Esptail
@@ -98,32 +115,12 @@ struct Algorithm
 	void	(*init)(Espcb*, char* name, uchar *key, int keylen);
 };
 
-
-enum {
-	RC4forward= 10*1024*1024,	/* maximum skip forward */
-	RC4back = 100*1024,	/* maximum look back */
-};
-
-#ifdef notdef
-struct Esprc4
-{
-	ulong	cseq;		/* current byte sequence number */
-	RC4state current;
-
-	int	ovalid;		/* old is valid */
-	ulong	lgseq;		/* last good sequence */
-	ulong	oseq;		/* old byte sequence number */
-	RC4state old;
-};
-#endif
-
 static	Conv* convlookup(Proto *esp, ulong spi);
 static	char *setalg(Espcb *ecb, char **f, int n, Algorithm *alg);
 static	void espkick(void *x);
 
 static	void nullespinit(Espcb*, char*, uchar *key, int keylen);
 static	void desespinit(Espcb *ecb, char *name, uchar *k, int n);
-// static void rc4espinit(Espcb *ecb, char *name, uchar *k, int n);
 
 static	void nullahinit(Espcb*, char*, uchar *key, int keylen);
 static	void shaahinit(Espcb*, char*, uchar *key, int keylen);
@@ -231,18 +228,34 @@ espclose(Conv *c)
 	memset(ecb, 0, sizeof(Espcb));
 }
 
+static int
+ipvers(Conv *c)
+{
+	if((memcmp(c->raddr, v4prefix, IPv4off) == 0 &&
+	    memcmp(c->laddr, v4prefix, IPv4off) == 0) ||
+	    ipcmp(c->raddr, IPnoaddr) == 0)
+		return V4;
+	else
+		return V6;
+}
+
 static void
 espkick(void *x)
 {
 	Conv *c = x;
-	Esphdr *eh;
+	Esp4hdr *eh4;
+	Esp6hdr *eh6;
 	Esptail *et;
 	Userhdr *uh;
 	Espcb *ecb;
 	Block *bp;
-	int nexthdr, payload, pad, align;
+	int nexthdr, payload, pad, align, version, hdrlen, iphdrlen;
 	uchar *auth;
 
+	version = ipvers(c);
+	iphdrlen = version == V4? IP4HDR: IP6HDR;
+	hdrlen =   version == V4? Esp4hdrlen: Esp6hdrlen;
+
 	bp = qget(c->wq);
 	if(bp == nil)
 		return;
@@ -252,96 +265,124 @@ espkick(void *x)
 
 	if(ecb->header) {
 		/* make sure the message has a User header */
-		bp = pullupblock(bp, UserhdrSize);
+		bp = pullupblock(bp, Userhdrlen);
 		if(bp == nil) {
 			qunlock(c);
 			return;
 		}
 		uh = (Userhdr*)bp->rp;
 		nexthdr = uh->nexthdr;
-		bp->rp += UserhdrSize;
+		bp->rp += Userhdrlen;
 	} else {
 		nexthdr = 0;	/* what should this be? */
 	}
 
 	payload = BLEN(bp) + ecb->espivlen;
 
-/* adapt to v6 */
 	/* Make space to fit ip header */
-	bp = padblock(bp, EsphdrSize + ecb->espivlen);
+	bp = padblock(bp, hdrlen + ecb->espivlen);
 
 	align = 4;
 	if(ecb->espblklen > align)
 		align = ecb->espblklen;
 	if(align % ecb->ahblklen != 0)
 		panic("espkick: ahblklen is important after all");
-	pad = (align-1) - (payload + EsptailSize-1)%align;
+	pad = (align-1) - (payload + Esptaillen-1)%align;
 
 	/*
 	 * Make space for tail
 	 * this is done by calling padblock with a negative size
 	 * Padblock does not change bp->wp!
 	 */
-	bp = padblock(bp, -(pad+EsptailSize+ecb->ahlen));
-	bp->wp += pad+EsptailSize+ecb->ahlen;
+	bp = padblock(bp, -(pad+Esptaillen+ecb->ahlen));
+	bp->wp += pad+Esptaillen+ecb->ahlen;
 
-	eh = (Esphdr *)(bp->rp);
-	et = (Esptail*)(bp->rp + EsphdrSize + payload + pad);
+	eh4 = (Esp4hdr *)bp->rp;
+	eh6 = (Esp6hdr *)bp->rp;
+	et = (Esptail*)(bp->rp + hdrlen + payload + pad);
 
 	/* fill in tail */
 	et->pad = pad;
 	et->nexthdr = nexthdr;
 
-	ecb->cipher(ecb, bp->rp+EsphdrSize, payload+pad+EsptailSize);
-	auth = bp->rp + EsphdrSize + payload + pad + EsptailSize;
+	ecb->cipher(ecb, bp->rp + hdrlen, payload + pad + Esptaillen);
+	auth = bp->rp + hdrlen + payload + pad + Esptaillen;
 
 	/* fill in head */
-	eh->vihl = IP_VER4;
-	hnputl(eh->espspi, ecb->spi);
-	hnputl(eh->espseq, ++ecb->seq);
-	v6tov4(eh->espsrc, c->laddr);
-	v6tov4(eh->espdst, c->raddr);
-	eh->espproto = IP_ESPPROTO;
-	eh->frag[0] = 0;
-	eh->frag[1] = 0;
-
-	ecb->auth(ecb, bp->rp + IP4HDR, (EsphdrSize - IP4HDR) +
-		payload + pad + EsptailSize, auth);
+	if (version == V4) {
+		eh4->vihl = IP_VER4;
+		hnputl(eh4->espspi, ecb->spi);
+		hnputl(eh4->espseq, ++ecb->seq);
+		v6tov4(eh4->espsrc, c->laddr);
+		v6tov4(eh4->espdst, c->raddr);
+		eh4->espproto = IP_ESPPROTO;
+		eh4->frag[0] = 0;
+		eh4->frag[1] = 0;
+	} else {
+		eh6->vcf[0] = IP_VER6;
+		hnputl(eh6->espspi, ecb->spi);
+		hnputl(eh6->espseq, ++ecb->seq);
+		ipmove(eh6->src, c->laddr);
+		ipmove(eh6->dst, c->raddr);
+		eh6->proto = IP_ESPPROTO;
+	}
+
+	ecb->auth(ecb, bp->rp + iphdrlen, (hdrlen - iphdrlen) +
+		payload + pad + Esptaillen, auth);
 
 	qunlock(c);
 	/* print("esp: pass down: %uld\n", BLEN(bp)); */
-	ipoput4(c->p->f, bp, 0, c->ttl, c->tos, c);
-/* end adapt to v6 */
+	if (version == V4)
+		ipoput4(c->p->f, bp, 0, c->ttl, c->tos, c);
+	else
+		ipoput6(c->p->f, bp, 0, c->ttl, c->tos, c);
 }
 
 void
 espiput(Proto *esp, Ipifc*, Block *bp)
 {
-	Esphdr *eh;
+	Esp4hdr *eh4;
+	Esp6hdr *eh6;
 	Esptail *et;
 	Userhdr *uh;
 	Conv *c;
 	Espcb *ecb;
 	uchar raddr[IPaddrlen], laddr[IPaddrlen];
 	Fs *f;
-	uchar *auth;
+	uchar *auth, *espspi;
 	ulong spi;
-	int payload, nexthdr;
+	int payload, nexthdr, version, hdrlen;
 
 	f = esp->f;
+	if (bp == nil || BLEN(bp) == 0) {
+		/* get enough to identify the IP version */
+		bp = pullupblock(bp, IP4HDR);
+		if(bp == nil) {
+			netlog(f, Logesp, "esp: short packet\n");
+			return;
+		}
+	}
+	eh4 = (Esp4hdr*)bp->rp;
+	version = ((eh4->vihl & 0xf0) == IP_VER4? V4: V6);
+	hdrlen = version == V4? Esp4hdrlen: Esp6hdrlen;
 
-	bp = pullupblock(bp, EsphdrSize+EsptailSize);
+	bp = pullupblock(bp, hdrlen + Esptaillen);
 	if(bp == nil) {
 		netlog(f, Logesp, "esp: short packet\n");
 		return;
 	}
 
-/* adapt to v6 */
-	eh = (Esphdr*)(bp->rp);
-	spi = nhgetl(eh->espspi);
-	v4tov6(raddr, eh->espsrc);
-	v4tov6(laddr, eh->espdst);
-/* end adapt to v6 */
+	if (version == V4) {
+		eh4 = (Esp4hdr*)bp->rp;
+		spi = nhgetl(eh4->espspi);
+		v4tov6(raddr, eh4->espsrc);
+		v4tov6(laddr, eh4->espdst);
+	} else {
+		eh6 = (Esp6hdr*)bp->rp;
+		spi = nhgetl(eh6->espspi);
+		ipmove(raddr, eh6->src);
+		ipmove(laddr, eh6->dst);
+	}
 
 	qlock(esp);
 	/* Look for a conversation structure for this port */
@@ -363,8 +404,7 @@ espiput(Proto *esp, Ipifc*, Block *bp)
 	if(bp->next)
 		bp = concatblock(bp);
 
-/* adapt to v6 */
-	if(BLEN(bp) < EsphdrSize + ecb->espivlen + EsptailSize + ecb->ahlen) {
+	if(BLEN(bp) < hdrlen + ecb->espivlen + Esptaillen + ecb->ahlen) {
 		qunlock(c);
 		netlog(f, Logesp, "esp: short block %I -> %I!%d\n", raddr,
 			laddr, spi);
@@ -372,9 +412,10 @@ espiput(Proto *esp, Ipifc*, Block *bp)
 		return;
 	}
 
-	eh = (Esphdr*)(bp->rp);
 	auth = bp->wp - ecb->ahlen;
-	if(!ecb->auth(ecb, eh->espspi, auth-eh->espspi, auth)) {
+	espspi = version == V4? ((Esp4hdr*)bp->rp)->espspi:
+				((Esp6hdr*)bp->rp)->espspi;
+	if(!ecb->auth(ecb, espspi, auth - espspi, auth)) {
 		qunlock(c);
 print("esp: bad auth %I -> %I!%ld\n", raddr, laddr, spi);
 		netlog(f, Logesp, "esp: bad auth %I -> %I!%d\n", raddr,
@@ -383,15 +424,15 @@ print("esp: bad auth %I -> %I!%ld\n", raddr, laddr, spi);
 		return;
 	}
 
-	payload = BLEN(bp)-EsphdrSize-ecb->ahlen;
-	if(payload<=0 || payload%4 != 0 || payload%ecb->espblklen!=0) {
+	payload = BLEN(bp) - hdrlen - ecb->ahlen;
+	if(payload <= 0 || payload % 4 != 0 || payload % ecb->espblklen != 0) {
 		qunlock(c);
 		netlog(f, Logesp, "esp: bad length %I -> %I!%d payload=%d BLEN=%d\n",
 			raddr, laddr, spi, payload, BLEN(bp));
 		freeb(bp);
 		return;
 	}
-	if(!ecb->cipher(ecb, bp->rp+EsphdrSize, payload)) {
+	if(!ecb->cipher(ecb, bp->rp + hdrlen, payload)) {
 		qunlock(c);
 print("esp: cipher failed %I -> %I!%ld: %s\n", raddr, laddr, spi, up->errstr);
 		netlog(f, Logesp, "esp: cipher failed %I -> %I!%d: %s\n", raddr,
@@ -400,8 +441,8 @@ print("esp: cipher failed %I -> %I!%ld: %s\n", raddr, laddr, spi, up->errstr);
 		return;
 	}
 
-	payload -= EsptailSize;
-	et = (Esptail*)(bp->rp + EsphdrSize + payload);
+	payload -= Esptaillen;
+	et = (Esptail*)(bp->rp + hdrlen + payload);
 	payload -= et->pad + ecb->espivlen;
 	nexthdr = et->nexthdr;
 	if(payload <= 0) {
@@ -413,16 +454,15 @@ print("esp: cipher failed %I -> %I!%ld: %s\n", raddr, laddr, spi, up->errstr);
 	}
 
 	/* trim packet */
-	bp->rp += EsphdrSize + ecb->espivlen;
+	bp->rp += hdrlen + ecb->espivlen;
 	bp->wp = bp->rp + payload;
 	if(ecb->header) {
-		/* assume UserhdrSize < EsphdrSize */
-		bp->rp -= UserhdrSize;
+		/* assume Userhdrlen < Esp4hdrlen < Esp6hdrlen */
+		bp->rp -= Userhdrlen;
 		uh = (Userhdr*)bp->rp;
-		memset(uh, 0, UserhdrSize);
+		memset(uh, 0, Userhdrlen);
 		uh->nexthdr = nexthdr;
 	}
-/* end adapt to v6 */
 
 	if(qfull(c->rq)){
 		netlog(f, Logesp, "esp: qfull %I -> %I.%uld\n", raddr,
@@ -458,11 +498,11 @@ espctl(Conv *c, char **f, int n)
 void
 espadvise(Proto *esp, Block *bp, char *msg)
 {
-	Esphdr *h;
+	Esp4hdr *h;
 	Conv *c;
 	ulong spi;
 
-	h = (Esphdr*)(bp->rp);
+	h = (Esp4hdr*)(bp->rp);
 
 	spi = nhgets(h->espspi);
 	qlock(esp);
@@ -762,7 +802,53 @@ desespinit(Espcb *ecb, char *name, uchar *k, int n)
 	setupDESstate(ecb->espstate, key, ivec);
 }
 
+void
+espinit(Fs *fs)
+{
+	Proto *esp;
+
+	esp = smalloc(sizeof(Proto));
+	esp->priv = smalloc(sizeof(Esppriv));
+	esp->name = "esp";
+	esp->connect = espconnect;
+	esp->announce = nil;
+	esp->ctl = espctl;
+	esp->state = espstate;
+	esp->create = espcreate;
+	esp->close = espclose;
+	esp->rcv = espiput;
+	esp->advise = espadvise;
+	esp->stats = espstats;
+	esp->local = esplocal;
+	esp->remote = espremote;
+	esp->ipproto = IP_ESPPROTO;
+	esp->nc = Nchans;
+	esp->ptclsize = sizeof(Espcb);
+
+	Fsproto(fs, esp);
+}
+
+
 #ifdef notdef
+enum {
+	RC4forward= 10*1024*1024,	/* maximum skip forward */
+	RC4back = 100*1024,	/* maximum look back */
+};
+
+typedef struct Esprc4 Esprc4;
+struct Esprc4
+{
+	ulong	cseq;		/* current byte sequence number */
+	RC4state current;
+
+	int	ovalid;		/* old is valid */
+	ulong	lgseq;		/* last good sequence */
+	ulong	oseq;		/* old byte sequence number */
+	RC4state old;
+};
+
+static void rc4espinit(Espcb *ecb, char *name, uchar *k, int n);
+
 static int
 rc4cipher(Espcb *ecb, uchar *p, int n)
 {
@@ -852,29 +938,3 @@ rc4espinit(Espcb *ecb, char *name, uchar *k, int n)
 	ecb->espstate = esprc4;
 }
 #endif
-
-void
-espinit(Fs *fs)
-{
-	Proto *esp;
-
-	esp = smalloc(sizeof(Proto));
-	esp->priv = smalloc(sizeof(Esppriv));
-	esp->name = "esp";
-	esp->connect = espconnect;
-	esp->announce = nil;
-	esp->ctl = espctl;
-	esp->state = espstate;
-	esp->create = espcreate;
-	esp->close = espclose;
-	esp->rcv = espiput;
-	esp->advise = espadvise;
-	esp->stats = espstats;
-	esp->local = esplocal;
-	esp->remote = espremote;
-	esp->ipproto = IP_ESPPROTO;
-	esp->nc = Nchans;
-	esp->ptclsize = sizeof(Espcb);
-
-	Fsproto(fs, esp);
-}

+ 9 - 8
sys/src/cmd/fossil/check.c

@@ -115,7 +115,7 @@ checkEpoch(Fsck *chk, u32int epoch)
 
 	for(a=0; a<chk->nblocks; a++){
 		if(!readLabel(chk->cache, &l, (a+chk->hint)%chk->nblocks)){
-			error(chk, "could not read label for addr %.8#ux", a);
+			error(chk, "could not read label for addr 0x%.8#ux", a);
 			continue;
 		}
 		if(l.tag == RootTag && l.epoch == epoch)
@@ -130,7 +130,7 @@ checkEpoch(Fsck *chk, u32int epoch)
 	a = (a+chk->hint)%chk->nblocks;
 	b = cacheLocalData(chk->cache, a, BtDir, RootTag, OReadOnly, 0);
 	if(b == nil){
-		error(chk, "could not read root block %.8#ux: %R", a);
+		error(chk, "could not read root block 0x%.8#ux: %R", a);
 		return;
 	}
 
@@ -145,7 +145,7 @@ checkEpoch(Fsck *chk, u32int epoch)
 	 * just a convenience to help the search.
 	 */
 	if(!entryUnpack(&e, b->data, 0)){
-		error(chk, "could not unpack root block %.8#ux: %R", a);
+		error(chk, "could not unpack root block 0x%.8#ux: %R", a);
 		blockPut(b);
 		return;
 	}
@@ -359,7 +359,7 @@ checkLeak(Fsck *chk)
 
 	for(a = 0; a < chk->nblocks; a++){
 		if(!readLabel(chk->cache, &l, a)){
-			error(chk, "could not read label: addr %ux %d %d: %R",
+			error(chk, "could not read label: addr 0x%ux %d %d: %R",
 				a, l.type, l.state);
 			continue;
 		}
@@ -374,11 +374,12 @@ checkLeak(Fsck *chk)
 		if(l.state&BsClosed)
 			continue;
 		nlost++;
-		// warn(chk, "unreachable block: addr %ux type %d tag %ux state %s epoch %ud close %ud",
-		// 	a, l.type, l.tag, bsStr(l.state), l.epoch, l.epochClose);
+//		warn(chk, "unreachable block: addr 0x%ux type %d tag 0x%ux "
+//			"state %s epoch %ud close %ud", a, l.type, l.tag,
+//			bsStr(l.state), l.epoch, l.epochClose);
 		b = cacheLocal(chk->cache, PartData, a, OReadOnly);
 		if(b == nil){
-			error(chk, "could not read block %#.8ux", a);
+			error(chk, "could not read block 0x%#.8ux", a);
 			continue;
 		}
 		chk->close(chk, b, 0);
@@ -388,7 +389,7 @@ checkLeak(Fsck *chk)
 	}
 	chk->print("fsys blocks: total=%ud used=%ud(%.1f%%) free=%ud(%.1f%%) lost=%ud(%.1f%%)\n",
 		chk->nblocks,
-		chk->nblocks-nfree-nlost,
+		chk->nblocks - nfree-nlost,
 		100.*(chk->nblocks - nfree - nlost)/chk->nblocks,
 		nfree, 100.*nfree/chk->nblocks,
 		nlost, 100.*nlost/chk->nblocks);

+ 5 - 6
sys/src/cmd/fossil/pack.c

@@ -73,16 +73,15 @@ labelUnpack(Label *l, uchar *p, int i)
 	l->tag = U32GET(p+10);
 
 	if(l->type > BtMax){
-	Bad:
+Bad:
 		vtSetError(EBadLabel);
-fprint(2, "labelUnpack %.2ux %.2ux %.8ux %.8ux %.8ux\n",
-	l->state, l->type, l->epoch, l->epochClose, l->tag);
+		fprint(2, "%s: labelUnpack: bad label: 0x%.2ux 0x%.2ux 0x%.8ux "
+			"0x%.8ux 0x%.8ux\n", argv0, l->state, l->type, l->epoch,
+			l->epochClose, l->tag);
 		return 0;
 	}
 	if(l->state != BsBad && l->state != BsFree){
-		if(!(l->state&BsAlloc))
-			goto Bad;
-		if(l->state&~BsMask)
+		if(!(l->state&BsAlloc) || l->state & ~BsMask)
 			goto Bad;
 		if(l->state&BsClosed){
 			if(l->epochClose == ~(u32int)0)

+ 17 - 10
sys/src/cmd/fossil/source.c

@@ -38,30 +38,36 @@ sourceAlloc(Fs *fs, Block *b, Source *p, u32int offset, int mode, int issnapshot
 	 * get prints.
 	 */
 	if(!entryUnpack(&e, b->data, offset % epb)){
-		fprint(2, "entryUnpack failed\n");
+		fprint(2, "%s: %V: sourceAlloc: entryUnpack failed\n", argv0,
+			b->score);
 		goto Bad;
 	}
 	if(!(e.flags & VtEntryActive)){
-		if(0)fprint(2, "not active\n");
+		if(0) fprint(2, "%s: %V: sourceAlloc: not active\n",
+			argv0, e.score);
 		goto Bad;
 	}
 	if(e.psize < 256 || e.dsize < 256){
-		fprint(2, "psize %ud dsize %ud\n", e.psize, e.dsize);
+		fprint(2, "%s: %V: sourceAlloc: psize %ud dsize %ud\n",
+			argv0, e.score, e.psize, e.dsize);
 		goto Bad;
 	}
 
 	if(e.depth < sizeToDepth(e.size, e.psize, e.dsize)){
-		fprint(2, "depth %ud size %llud psize %ud dsize %ud\n", e.depth, e.size, e.psize, e.dsize);
+		fprint(2, "%s: %V: sourceAlloc: depth %ud size %llud psize %ud dsize %ud\n",
+			argv0, e.score, e.depth, e.size, e.psize, e.dsize);
 		goto Bad;
 	}
 
 	if((e.flags & VtEntryLocal) && e.tag == 0){
-		fprint(2, "flags %#ux tag %#ux\n", e.flags, e.tag);
+		fprint(2, "%s: %V: sourceAlloc: flags %#ux tag %#ux\n",
+			argv0, e.score, e.flags, e.tag);
 		goto Bad;
 	}
 
 	if(e.dsize > fs->blockSize || e.psize > fs->blockSize){
-		fprint(2, "psize %ud dsize %ud blocksize %ud\n", e.psize, e.dsize, fs->blockSize);
+		fprint(2, "%s: %V: sourceAlloc: psize %ud dsize %ud blocksize %ud\n",
+			argv0, e.score, e.psize, e.dsize, fs->blockSize);
 		goto Bad;
 	}
 
@@ -98,20 +104,20 @@ sourceAlloc(Fs *fs, Block *b, Source *p, u32int offset, int mode, int issnapshot
 		vtUnlock(p->lk);
 	}
 	r->epoch = epoch;
-//fprint(2, "sourceAlloc have %V be.%d fse.%d %s\n", b->score, b->l.epoch, r->fs->ehi, mode==OReadWrite ? "rw" : "ro");
+//	fprint(2, "%s: sourceAlloc: have %V be.%d fse.%d %s\n", argv0, b->score,
+//		b->l.epoch, r->fs->ehi, mode == OReadWrite? "rw": "ro");
 	memmove(r->score, b->score, VtScoreSize);
 	r->scoreEpoch = b->l.epoch;
 	r->offset = offset;
 	r->epb = epb;
 	r->tag = b->l.tag;
 
-//fprint(2, "sourceAlloc: %p -> %V %d\n", r, r->score, r->offset);
+//	fprint(2, "%s: sourceAlloc: %p -> %V %d\n", r, r->score, r->offset);
 
 	return r;
 Bad:
 	vtSetError(EBadEntry);
 	return nil;
-
 }
 
 Source *
@@ -125,7 +131,8 @@ sourceRoot(Fs *fs, u32int addr, int mode)
 		return nil;
 
 	if(mode == OReadWrite && b->l.epoch != fs->ehi){
-		fprint(2, "sourceRoot: fs->ehi = %ud, b->l = %L\n", fs->ehi, &b->l);
+		fprint(2, "%s: sourceRoot: fs->ehi = %ud, b->l = %L\n",
+			argv0, fs->ehi, &b->l);
 		blockPut(b);
 		vtSetError(EBadRoot);
 		return nil;