Browse Source

Plan 9 from Bell Labs 2008-07-16

David du Colombier 12 years ago
parent
commit
bc1b3bf0f8
5 changed files with 86 additions and 58 deletions
  1. 10 10
      dist/replica/_plan9.db
  2. 10 10
      dist/replica/plan9.db
  3. 10 0
      dist/replica/plan9.log
  4. 54 37
      sys/src/9/ip/devip.c
  5. 2 1
      sys/src/9/ip/ip.h

+ 10 - 10
dist/replica/_plan9.db

@@ -3,14 +3,14 @@
 386/9loaddebug - 775 sys sys 1212010545 455911
 386/9loadlite - 775 sys sys 1212010543 164328
 386/9loadlitedebug - 775 sys sys 1212010546 240926
-386/9pc - 775 sys sys 1216062725 2130539
-386/9pc.gz - 664 sys sys 1216062745 912812
-386/9pccpu - 775 sys sys 1211924426 2245510
-386/9pccpu.gz - 664 sys sys 1211924426 921192
-386/9pcdisk - 775 sys sys 1216063090 2326466
-386/9pcdisk.gz - 664 sys sys 1216063109 990198
-386/9pcf - 775 sys sys 1216062998 2993768
-386/9pcf.gz - 664 sys sys 1216063026 1273054
+386/9pc - 775 sys sys 1216152518 2130687
+386/9pc.gz - 664 sys sys 1216152539 912822
+386/9pccpu - 775 sys sys 1216152687 2245388
+386/9pccpu.gz - 664 sys sys 1216152708 921103
+386/9pcdisk - 775 sys sys 1216152757 2326614
+386/9pcdisk.gz - 664 sys sys 1216152780 990292
+386/9pcf - 775 sys sys 1216152607 2993916
+386/9pcf.gz - 664 sys sys 1216152637 1273103
 386/9pxeload - 775 sys sys 1212010541 341556
 386/9pxeloaddebug - 775 sys sys 1212010542 455922
 386/bin - 20000000775 sys sys 1018897690 0
@@ -8036,7 +8036,7 @@ sys/src/9/boot/testboot.c - 664 sys sys 1039763734 496
 sys/src/9/ip - 20000000775 sys sys 1119710004 0
 sys/src/9/ip/arp.c - 664 sys sys 1204180133 11321
 sys/src/9/ip/chandial.c - 664 sys sys 1099020048 2295
-sys/src/9/ip/devip.c - 664 sys sys 1204180143 24398
+sys/src/9/ip/devip.c - 664 sys sys 1216152698 24934
 sys/src/9/ip/eipconvtest.c - 664 sys sys 1022588098 3135
 sys/src/9/ip/esp.c - 664 sys sys 1187064283 19158
 sys/src/9/ip/ethermedium.c - 664 sys sys 1187735942 15427
@@ -8046,7 +8046,7 @@ sys/src/9/ip/icmp6.c - 664 sys sys 1187036525 18131
 sys/src/9/ip/igmp.c - 664 sys sys 1055700768 5175
 sys/src/9/ip/inferno.c - 664 sys sys 1022588098 517
 sys/src/9/ip/ip.c - 664 sys sys 1187735970 14553
-sys/src/9/ip/ip.h - 664 sys sys 1204231127 16639
+sys/src/9/ip/ip.h - 664 sys sys 1216152694 16677
 sys/src/9/ip/ipaux.c - 664 sys sys 1204231128 6250
 sys/src/9/ip/ipifc.c - 664 sys sys 1204180081 34151
 sys/src/9/ip/ipmux.c - 664 sys sys 1187047550 14991

+ 10 - 10
dist/replica/plan9.db

@@ -3,14 +3,14 @@
 386/9loaddebug - 775 sys sys 1212010545 455911
 386/9loadlite - 775 sys sys 1212010543 164328
 386/9loadlitedebug - 775 sys sys 1212010546 240926
-386/9pc - 775 sys sys 1216062725 2130539
-386/9pc.gz - 664 sys sys 1216062745 912812
-386/9pccpu - 775 sys sys 1211924426 2245510
-386/9pccpu.gz - 664 sys sys 1211924426 921192
-386/9pcdisk - 775 sys sys 1216063090 2326466
-386/9pcdisk.gz - 664 sys sys 1216063109 990198
-386/9pcf - 775 sys sys 1216062998 2993768
-386/9pcf.gz - 664 sys sys 1216063026 1273054
+386/9pc - 775 sys sys 1216152518 2130687
+386/9pc.gz - 664 sys sys 1216152539 912822
+386/9pccpu - 775 sys sys 1216152687 2245388
+386/9pccpu.gz - 664 sys sys 1216152708 921103
+386/9pcdisk - 775 sys sys 1216152757 2326614
+386/9pcdisk.gz - 664 sys sys 1216152780 990292
+386/9pcf - 775 sys sys 1216152607 2993916
+386/9pcf.gz - 664 sys sys 1216152637 1273103
 386/9pxeload - 775 sys sys 1212010541 341556
 386/9pxeloaddebug - 775 sys sys 1212010542 455922
 386/bin - 20000000775 sys sys 1018897690 0
@@ -8036,7 +8036,7 @@ sys/src/9/boot/testboot.c - 664 sys sys 1039763734 496
 sys/src/9/ip - 20000000775 sys sys 1119710004 0
 sys/src/9/ip/arp.c - 664 sys sys 1204180133 11321
 sys/src/9/ip/chandial.c - 664 sys sys 1099020048 2295
-sys/src/9/ip/devip.c - 664 sys sys 1204180143 24398
+sys/src/9/ip/devip.c - 664 sys sys 1216152698 24934
 sys/src/9/ip/eipconvtest.c - 664 sys sys 1022588098 3135
 sys/src/9/ip/esp.c - 664 sys sys 1187064283 19158
 sys/src/9/ip/ethermedium.c - 664 sys sys 1187735942 15427
@@ -8046,7 +8046,7 @@ sys/src/9/ip/icmp6.c - 664 sys sys 1187036525 18131
 sys/src/9/ip/igmp.c - 664 sys sys 1055700768 5175
 sys/src/9/ip/inferno.c - 664 sys sys 1022588098 517
 sys/src/9/ip/ip.c - 664 sys sys 1187735970 14553
-sys/src/9/ip/ip.h - 664 sys sys 1204231127 16639
+sys/src/9/ip/ip.h - 664 sys sys 1216152694 16677
 sys/src/9/ip/ipaux.c - 664 sys sys 1204231128 6250
 sys/src/9/ip/ipifc.c - 664 sys sys 1204180081 34151
 sys/src/9/ip/ipmux.c - 664 sys sys 1187047550 14991

+ 10 - 0
dist/replica/plan9.log

@@ -20055,3 +20055,13 @@
 1216063804 3 c 386/9pcdisk.gz - 664 sys sys 1216063109 990198
 1216063804 4 c 386/9pcf - 775 sys sys 1216062998 2993768
 1216063804 5 c 386/9pcf.gz - 664 sys sys 1216063026 1273054
+1216153804 0 c 386/9pc - 775 sys sys 1216152518 2130687
+1216153804 1 c 386/9pc.gz - 664 sys sys 1216152539 912822
+1216153804 2 c 386/9pccpu - 775 sys sys 1216152687 2245388
+1216153804 3 c 386/9pccpu.gz - 664 sys sys 1216152708 921103
+1216153804 4 c 386/9pcdisk - 775 sys sys 1216152757 2326614
+1216153804 5 c 386/9pcdisk.gz - 664 sys sys 1216152780 990292
+1216153804 6 c 386/9pcf - 775 sys sys 1216152607 2993916
+1216153804 7 c 386/9pcf.gz - 664 sys sys 1216152637 1273103
+1216153804 8 c sys/src/9/ip/devip.c - 664 sys sys 1216152698 24934
+1216153804 9 c sys/src/9/ip/ip.h - 664 sys sys 1216152694 16677

+ 54 - 37
sys/src/9/ip/devip.c

@@ -766,53 +766,64 @@ setluniqueport(Conv* c, int lport)
 	return nil;
 }
 
+/*
+ * is lport in use by anyone?
+ */
+static int
+lportinuse(Proto *p, ushort lport)
+{
+	int x;
+
+	for(x = 0; x < p->nc && p->conv[x]; x++)
+		if(p->conv[x]->lport == lport)
+			return 1;
+	return 0;
+}
 
 /*
  *  pick a local port and set it
  */
-void
+char *
 setlport(Conv* c)
 {
 	Proto *p;
-	ushort *pp;
-	int x, found;
+	int i, port;
 
 	p = c->p;
-	if(c->restricted)
-		pp = &p->nextrport;
-	else
-		pp = &p->nextport;
 	qlock(p);
-	for(;;(*pp)++){
+	if(c->restricted){
+		/* Restricted ports cycle between 600 and 1024. */
+		for(i=0; i<1024-600; i++){
+			if(p->nextrport >= 1024 || p->nextrport < 600)
+				p->nextrport = 600;
+			port = p->nextrport++;
+			if(!lportinuse(p, port))
+				goto chosen;
+		}
+	}else{
 		/*
-		 * Fsproto initialises p->nextport to 0 and the restricted
-		 * ports (p->nextrport) to 600.
-		 * Restricted ports must lie between 600 and 1024.
-		 * For the initial condition or if the unrestricted port number
-		 * has wrapped round, select a random port between 5000 and 1<<15
-		 * to start at.
+		 * Unrestricted ports are chosen randomly
+		 * between 2^15 and 2^16.  There are at most
+		 * 4*Nchan = 4096 ports in use at any given time,
+		 * so even in the worst case, a random probe has a
+		 * 1 - 4096/2^15 = 87% chance of success.
+		 * If 64 successive probes fail, there is a bug somewhere
+		 * (or a once in 10^58 event has happened, but that's
+		 * less likely than a venti collision).
 		 */
-		if(c->restricted){
-			if(*pp >= 1024)
-				*pp = 600;
+		for(i=0; i<64; i++){
+			port = (1<<15) + nrand(1<<15);
+			if(!lportinuse(p, port))
+				goto chosen;
 		}
-		else while(*pp < 5000)
-			*pp = nrand(1<<15);
-
-		found = 0;
-		for(x = 0; x < p->nc; x++){
-			if(p->conv[x] == nil)
-				break;
-			if(p->conv[x]->lport == *pp){
-				found = 1;
-				break;
-			}
-		}
-		if(!found)
-			break;
 	}
-	c->lport = (*pp)++;
 	qunlock(p);
+	return "no ports available";
+
+chosen:
+	c->lport = port;
+	qunlock(p);
+	return nil;
 }
 
 /*
@@ -827,8 +838,6 @@ setladdrport(Conv* c, char* str, int announcing)
 	ushort lport;
 	uchar addr[IPaddrlen];
 
-	rv = nil;
-
 	/*
 	 *  ignore restricted part if it exists.  it's
 	 *  meaningless on local ports.
@@ -869,7 +878,7 @@ setladdrport(Conv* c, char* str, int announcing)
 
 	lport = atoi(p);
 	if(lport <= 0)
-		setlport(c);
+		rv = setlport(c);
 	else
 		rv = setluniqueport(c, lport);
 	return rv;
@@ -911,7 +920,9 @@ Fsstdconnect(Conv *c, char *argv[], int argc)
 		if(p != nil)
 			return p;
 		setladdr(c);
-		setlport(c);
+		p = setlport(c);
+		if (p != nil)
+			return p;
 		break;
 	case 3:
 		p = setraddrport(c, argv[1]);
@@ -1153,6 +1164,12 @@ ipwrite(Chan* ch, void *v, long n, vlong off)
 			if (parseip(ia, cb->f[1]) == -1)
 				error(Ebadip);
 			ipifcremmulti(c, c->raddr, ia);
+		} else if(strcmp(cb->f[0], "maxfragsize") == 0){
+			if(cb->nf < 2)
+				error("maxfragsize needs size");
+
+			c->maxfragsize = (int)strtol(cb->f[1], nil, 0);
+			
 		} else if(x->ctl != nil) {
 			p = x->ctl(c, cb->f, cb->nf);
 			if(p != nil)
@@ -1235,7 +1252,6 @@ Fsproto(Fs *f, Proto *p)
 		panic("Fsproto");
 
 	p->x = f->np;
-	p->nextport = 0;
 	p->nextrport = 600;
 	f->p[f->np++] = p;
 
@@ -1313,6 +1329,7 @@ retry:
 	c->lport = 0;
 	c->rport = 0;
 	c->restricted = 0;
+	c->maxfragsize = 0;
 	c->ttl = MAXTTL;
 	qreopen(c->rq);
 	qreopen(c->wq);

+ 2 - 1
sys/src/9/ip/ip.h

@@ -115,6 +115,8 @@ struct Conv
 	int	length;
 	int	state;
 
+	int	maxfragsize;		/* If set, used for fragmentation */
+
 	/* udp specific */
 	int	headers;		/* data src/dst headers in udp */
 	int	reliable;		/* true if reliable udp */
@@ -330,7 +332,6 @@ struct Proto
 	int		nc;		/* number of conversations */
 	int		ac;
 	Qid		qid;		/* qid for protocol directory */
-	ushort		nextport;
 	ushort		nextrport;
 
 	void		*priv;