shithub: riscv

Download patch

ref: 4a684fc627175ee27833d5fcc9569510fa04dfcd
parent: 435a9a150ea5d3eae891503be0224ea9c9d29bab
author: cinap_lenrek <[email protected]>
date: Sat Nov 18 11:03:44 EST 2017

6in4: add -m mtu option to specify outer MTU

instead of hardcoding the tunnel interface MTU to 1280,
we calculate the tunnel MTU from the outside MTU, which
can now be specified with the -m mtu option. The deault
outside MTU is 1500 - 8 (PPPoE).

--- a/sys/man/8/6in4
+++ b/sys/man/8/6in4
@@ -6,6 +6,9 @@
 [
 .B -ag
 ] [
+.B -m
+.I mtu
+] [
 .B -x
 .I netmtpt
 ] [
@@ -26,6 +29,9 @@
 [
 .B -g
 ] [
+.B -m
+.I mtu
+] [
 .B -x
 .I netmtpt
 ] [
@@ -103,6 +109,11 @@
 .TP
 .B -g
 use the tunnel as the default route for global IPv6 addresses
+.TP
+.B -m
+.I mtu
+specifies the outside MTU in bytes from which the inside
+tunnel MTU is derived. Deaults to 1500 - 8 (Ethernet - PPPoE).
 .TP
 .B -x
 use the network mounted at
--- a/sys/src/cmd/ip/6in4.c
+++ b/sys/src/cmd/ip/6in4.c
@@ -46,6 +46,8 @@
 
 #define STFHDR offsetof(Iphdr, payload[0])
 
+int mtu = 1500-8;
+
 int anysender;
 int gateway;
 int debug;
@@ -71,7 +73,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-ag] [-x mtpt] [-o mtpt] [-i local4] [local6[/mask]] [remote4 [remote6]]\n",
+	fprint(2, "usage: %s [-ag] [-m mtu] [-x mtpt] [-o mtpt] [-i local4] [local6[/mask]] [remote4 [remote6]]\n",
 		argv0);
 	exits("Usage");
 }
@@ -191,8 +193,8 @@
 	*v6net = open(path, ORDWR);
 	if (*v6net < 0 || fprint(cfd, "bind pkt") < 0)
 		sysfatal("can't bind packet interface: %r");
-	/* 1280 is MTU, apparently from rfc2460 */
-	if (fprint(cfd, "add %I %M %I 1280", local6, localmask, remote6) <= 0)
+	if (fprint(cfd, "add %I %M %I %d", local6, localmask, remote6,
+		mtu - IPV4HDR_LEN) <= 0)
 		sysfatal("can't set local ipv6 address: %r");
 	close(cfd);
 	if (debug)
@@ -254,6 +256,9 @@
 		break;
 	case 'g':
 		gateway++;
+		break;
+	case 'm':
+		mtu = atoi(EARGF(usage()));
 		break;
 	case 'x':
 		outside = inside = EARGF(usage());
--- a/sys/src/cmd/ip/ayiya.c
+++ b/sys/src/cmd/ip/ayiya.c
@@ -76,6 +76,8 @@
 
 AYIYA	conf;
 
+int mtu = 1500-8;
+
 int gateway;
 int debug;
 
@@ -283,7 +285,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-g] [-x mtpt] [-k secret] local6[/mask] remote4 remote6\n",
+	fprint(2, "usage: %s [-g] [-m mtu] [-x mtpt] [-k secret] local6[/mask] remote4 remote6\n",
 		argv0);
 	exits("Usage");
 }
@@ -363,8 +365,8 @@
 	*v6net = open(path, ORDWR);
 	if (*v6net < 0 || fprint(cfd, "bind pkt") < 0)
 		sysfatal("can't bind packet interface: %r");
-	/* 1280 is MTU, apparently from rfc2460 */
-	if (fprint(cfd, "add %I %M %I 1280", local6, localmask, remote6) <= 0)
+	if (fprint(cfd, "add %I %M %I %d", local6, localmask, remote6,
+		mtu - (IPV4HDR_LEN+8) - (8+conf.idlen+conf.siglen)) <= 0)
 		sysfatal("can't set local ipv6 address: %r");
 	close(cfd);
 	if (debug)
@@ -423,6 +425,9 @@
 		break;
 	case 'g':
 		gateway++;
+		break;
+	case 'm':
+		mtu = atoi(EARGF(usage()));
 		break;
 	case 'x':
 		inside = EARGF(usage());