shithub: riscv

Download patch

ref: f2f2c8687afbe0af3fa98376bab3ed27d1d82801
parent: 33768d90bf4c72051d1483d3dea11bff41dbd698
author: cinap_lenrek <[email protected]>
date: Mon Jan 14 02:09:25 EST 2013

6in4: add -o option to make it possible to use different nets for ipv6 and ipv4 interface

--- a/sys/man/8/6in4
+++ b/sys/man/8/6in4
@@ -9,6 +9,9 @@
 .B -x
 .I netmtpt
 ] [
+.B -o
+.I outnetmtpt
+] [
 .IB local6[ / mask]
 [
 .I remote4
@@ -78,7 +81,20 @@
 use the network mounted at
 .I netmtpt
 instead of
-.LR /net .
+.LR /net
+for binding the tunnel interface and sending/receiving IPv4
+packets.
+.TP
+.B -o
+use
+.I outnetmtpt
+for the IPv4 packets but bind the IPv6 interface on
+.LR /net
+or
+.I netmtpt
+when specified by a previous
+.B -x
+option.
 .PD
 .SH EXAMPLES
 If your primary IPv4 address is public,
--- a/sys/src/cmd/ip/6in4.c
+++ b/sys/src/cmd/ip/6in4.c
@@ -60,7 +60,8 @@
 /* magic anycast address from rfc3068 */
 uchar anycast6to4[IPv4addrlen] = { 192, 88, 99, 1 };
 
-static char *net = "/net";
+static char *inside = "/net";
+static char *outside = "/net";
 
 static int	badipv4(uchar*);
 static int	badipv6(uchar*);
@@ -70,7 +71,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-ag] [-x mtpt] [local6[/mask]] [remote4 [remote6]]\n",
+	fprint(2, "usage: %s [-ag] [-x mtpt] [-o mtpt] [local6[/mask]] [remote4 [remote6]]\n",
 		argv0);
 	exits("Usage");
 }
@@ -163,7 +164,7 @@
 	 * gain access to IPv6-in-IPv4 packets via ipmux
 	 */
 	p = seprint(buf, buf + sizeof buf, "%s/ipmux!proto=%2.2x|%2.2x;dst=%V",
-		net, IP_IPV6PROTO, IP_ICMPV6PROTO, myip + IPv4off);
+		outside, IP_IPV6PROTO, IP_ICMPV6PROTO, myip + IPv4off);
 	if (!anysender)
 		seprint(p, buf + sizeof buf, ";src=%V", remote4 + IPv4off);
 	*tunp = dial(buf, 0, 0, 0);
@@ -176,7 +177,7 @@
 	 * open local IPv6 interface (as a packet interface)
 	 */
 
-	cl = smprint("%s/ipifc/clone", net);
+	cl = smprint("%s/ipifc/clone", inside);
 	cfd = open(cl, ORDWR);			/* allocate a conversation */
 	n = 0;
 	if (cfd < 0 || (n = read(cfd, buf, sizeof buf - 1)) <= 0)
@@ -186,7 +187,7 @@
 	free(cl);
 	buf[n] = 0;
 
-	snprint(path, sizeof path, "%s/ipifc/%s/data", net, buf);
+	snprint(path, sizeof path, "%s/ipifc/%s/data", inside, buf);
 	*v6net = open(path, ORDWR);
 	if (*v6net < 0 || fprint(cfd, "bind pkt") < 0)
 		sysfatal("can't bind packet interface: %r");
@@ -199,7 +200,7 @@
 
 	if (gateway) {
 		/* route global addresses through the tunnel to remote6 */
-		ir = smprint("%s/iproute", net);
+		ir = smprint("%s/iproute", inside);
 		cfd = open(ir, OWRITE);
 		if (cfd >= 0 && debug)
 			fprint(2, "injected 2000::/3 %I into %s\n", remote6, ir);
@@ -255,14 +256,17 @@
 		gateway++;
 		break;
 	case 'x':
-		net = EARGF(usage());
+		outside = inside = EARGF(usage());
 		break;
+	case 'o':
+		outside = EARGF(usage());
+		break;
 	default:
 		usage();
 	} ARGEND
 
-	if (myipaddr(myip, net) < 0)
-		sysfatal("can't find my ipv4 address on %s", net);
+	if (myipaddr(myip, outside) < 0)
+		sysfatal("can't find my ipv4 address on %s", outside);
 	if (!isv4(myip))
 		sysfatal("my ip, %I, is not a v4 address", myip);