Browse Source

Plan 9 from Bell Labs 2007-05-21

David du Colombier 17 years ago
parent
commit
48c48adaa7
6 changed files with 60 additions and 24 deletions
  1. 3 3
      dist/replica/_plan9.db
  2. 3 3
      dist/replica/plan9.db
  3. 3 0
      dist/replica/plan9.log
  4. 15 3
      sys/man/3/ip
  5. 35 14
      sys/src/9/ip/ipifc.c
  6. 1 1
      sys/src/9/ip/ipmux.c

+ 3 - 3
dist/replica/_plan9.db

@@ -7638,7 +7638,7 @@ sys/man/3/ether - 664 sys sys 1178597986 2890
 sys/man/3/floppy - 664 sys sys 954378905 881
 sys/man/3/fs - 664 sys sys 1175145095 3147
 sys/man/3/i82365 - 664 sys sys 954378906 884
-sys/man/3/ip - 664 sys sys 1178768702 24744
+sys/man/3/ip - 664 sys sys 1179708346 24886
 sys/man/3/kbmap - 664 sys sys 1131110122 1732
 sys/man/3/kprof - 664 sys sys 1018029972 1377
 sys/man/3/loopback - 664 sys sys 964662153 1995
@@ -7966,8 +7966,8 @@ sys/src/9/ip/inferno.c - 664 sys sys 1022588098 517
 sys/src/9/ip/ip.c - 664 sys sys 1176957040 15288
 sys/src/9/ip/ip.h - 664 sys sys 1176957139 15982
 sys/src/9/ip/ipaux.c - 664 sys sys 1079538100 12862
-sys/src/9/ip/ipifc.c - 664 sys sys 1178172609 33638
-sys/src/9/ip/ipmux.c - 664 sys sys 1047260566 15362
+sys/src/9/ip/ipifc.c - 664 sys sys 1179700017 34199
+sys/src/9/ip/ipmux.c - 664 sys sys 1179708314 15363
 sys/src/9/ip/iproute.c - 664 sys sys 1168305878 14778
 sys/src/9/ip/ipv6.c - 664 sys sys 1179511010 14506
 sys/src/9/ip/ipv6.h - 664 sys sys 1176844019 4087

+ 3 - 3
dist/replica/plan9.db

@@ -7638,7 +7638,7 @@ sys/man/3/ether - 664 sys sys 1178597986 2890
 sys/man/3/floppy - 664 sys sys 954378905 881
 sys/man/3/fs - 664 sys sys 1175145095 3147
 sys/man/3/i82365 - 664 sys sys 954378906 884
-sys/man/3/ip - 664 sys sys 1178768702 24744
+sys/man/3/ip - 664 sys sys 1179708346 24886
 sys/man/3/kbmap - 664 sys sys 1131110122 1732
 sys/man/3/kprof - 664 sys sys 1018029972 1377
 sys/man/3/loopback - 664 sys sys 964662153 1995
@@ -7966,8 +7966,8 @@ sys/src/9/ip/inferno.c - 664 sys sys 1022588098 517
 sys/src/9/ip/ip.c - 664 sys sys 1176957040 15288
 sys/src/9/ip/ip.h - 664 sys sys 1176957139 15982
 sys/src/9/ip/ipaux.c - 664 sys sys 1079538100 12862
-sys/src/9/ip/ipifc.c - 664 sys sys 1178172609 33638
-sys/src/9/ip/ipmux.c - 664 sys sys 1047260566 15362
+sys/src/9/ip/ipifc.c - 664 sys sys 1179700017 34199
+sys/src/9/ip/ipmux.c - 664 sys sys 1179708314 15363
 sys/src/9/ip/iproute.c - 664 sys sys 1168305878 14778
 sys/src/9/ip/ipv6.c - 664 sys sys 1179511010 14506
 sys/src/9/ip/ipv6.h - 664 sys sys 1176844019 4087

+ 3 - 0
dist/replica/plan9.log

@@ -49075,3 +49075,6 @@
 1179549023 56 c acme/bin/386/win - 775 sys sys 1179548040 183770
 1179592222 0 c sys/src/cmd/rio/wind.c - 664 sys sys 1179591640 33382
 1179604822 0 c 386/bin/rio - 775 sys sys 1179604582 312202
+1179700222 0 c sys/src/9/ip/ipifc.c - 664 sys sys 1179700017 34199
+1179709223 0 c sys/man/3/ip - 664 sys sys 1179708346 24886
+1179709223 1 c sys/src/9/ip/ipmux.c - 664 sys sys 1179708314 15363

+ 15 - 3
sys/man/3/ip

@@ -889,7 +889,7 @@ of a packet to match.  The possible relations are:
 the IP protocol number must be
 .IR n .
 .TP
-.BI dat[ n : m ]= expr
+.BI data[ n : m ]= expr
 bytes
 .I n
 through
@@ -897,6 +897,14 @@ through
 following the IP packet must match
 .IR expr .
 .TP
+.BI iph[ n : m ]= expr
+bytes
+.I n
+through
+.I m
+of the IP packet header must match
+.IR expr .
+.TP
 .BI ifc= expr
 the packet must have been received on an interface whose address
 matches
@@ -930,7 +938,10 @@ and
 .B src
 the value is a dot-formatted IP address and the mask is a dot-formatted
 IP mask.  In the case of
-.BR dat ,
+.BR data ,
+.B iph
+and
+.BR proto ,
 both value and mask are strings of 2 character hexadecimal digits representing
 8 bit values.
 .PP
@@ -948,7 +959,8 @@ longer matches > shorter matches
 older > younger
 .PP
 So far this has just been used to implement a version of
-OSPF in Inferno.
+OSPF in Inferno
+and 6to4 tunnelling.
 .SS Statistics
 .PP
 The

+ 35 - 14
sys/src/9/ip/ipifc.c

@@ -1131,19 +1131,28 @@ enum {
 int
 v6addrtype(uchar *addr)
 {
+	int scope;
+
 	if(isv6global(addr))
 		return globalv6;
-	if(islinklocal(addr))
+	else if(islinklocal(addr))
 		return linklocalv6;
-	if(isv6mcast(addr))
-		return multicastv6;
-	if(issitelocal(addr))
+	else if(isv6mcast(addr)){
+		scope = addr[1] & 0xF;
+		if (scope <= Link_local_scop)
+			return linklocalv6;
+		else if (scope <= Site_local_scop)
+			return sitelocalv6;
+		else
+			return globalv6;
+	} else if(issitelocal(addr))
 		return sitelocalv6;
-	return unknownv6;
+	else
+		return unknownv6;
 }
 
-#define v6addrcurr(lifc) ((lifc)->origint + (lifc)->preflt >= NOW/1000 || \
-				(lifc)->preflt == ~0L)
+#define v6addrcurr(lifc) ((lifc)->preflt == ~0L || \
+			(lifc)->origint + (lifc)->preflt >= NOW/1000)
 
 static void
 findprimaryipv6(Fs *f, uchar *local)
@@ -1207,6 +1216,7 @@ void
 findlocalip(Fs *f, uchar *local, uchar *remote)
 {
 	int version, atype = unspecifiedv6, atypel = unknownv6;
+	int atyper, deprecated;
 	uchar gate[IPaddrlen], gnet[IPaddrlen];
 	Ipifc *ifc;
 	Iplifc *lifc;
@@ -1227,9 +1237,9 @@ findlocalip(Fs *f, uchar *local, uchar *remote)
 			ipmove(local, v6Unspecified);
 		}
 
-		/* find ifc address closest to the gateway to use */
 		switch(version) {
 		case V4:
+			/* find ifc address closest to the gateway to use */
 			for(lifc = ifc->lifc; lifc; lifc = lifc->next){
 				maskip(gate, lifc->mask, gnet);
 				if(ipcmp(gnet, lifc->net) == 0){
@@ -1239,18 +1249,29 @@ findlocalip(Fs *f, uchar *local, uchar *remote)
 			}
 			break;
 		case V6:
+			/* find ifc address with scope matching the destination */
+			atyper = v6addrtype(remote);
+			deprecated = 0;
 			for(lifc = ifc->lifc; lifc; lifc = lifc->next){
 				atypel = v6addrtype(lifc->local);
-				maskip(gate, lifc->mask, gnet);
-				if (ipcmp(gnet, lifc->net) == 0 &&
-				    atypel > atype && v6addrcurr(lifc)) {
+				/* prefer appropriate scope */
+				if(atypel > atype && atype < atyper ||
+				   atypel < atype && atype > atyper){
 					ipmove(local, lifc->local);
+					deprecated = !v6addrcurr(lifc);
 					atype = atypel;
-					if(atype == globalv6)
-						break;
+				} else if(atypel == atype){
+					/* avoid deprecated addresses */
+					if(deprecated && v6addrcurr(lifc)){
+						ipmove(local, lifc->local);
+						atype = atypel;
+						deprecated = 0;
+					}
 				}
+				if(atype == atyper && !deprecated)
+					goto out;
 			}
-			if(atype > unspecifiedv6)
+			if(atype >= atyper)
 				goto out;
 			break;
 		default:

+ 1 - 1
sys/src/9/ip/ipmux.c

@@ -549,7 +549,7 @@ ipmuxremove(Ipmux **l, Ipmux *f)
 
 /*
  *  connection request is a semi separated list of filters
- *  e.g. proto=17;dat[0:4]=11aa22bb;ifc=135.104.9.2&255.255.255.0
+ *  e.g. proto=17;data[0:4]=11aa22bb;ifc=135.104.9.2&255.255.255.0
  *
  *  there's no protection against overlapping specs.
  */