ref: 137533bd69847030d716658e1772c6320f9282bb
parent: eed13a5c22662fe4c77b8587e7a53c9b1ae96acb
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Mar 31 16:35:02 EDT 2016
6in4: allow setting the local IPv4 address with -i flag (thanks k0ga)
--- a/sys/man/8/6in4
+++ b/sys/man/8/6in4
@@ -11,6 +11,9 @@
] [
.B -o
.I outnetmtpt
+] [
+.B -i
+.I local4
] [
.IB local6 [ /mask ]
[
@@ -91,6 +94,12 @@
.IR 6in4 ,
permit any remote IPv4 address as the far end of a tunnel.
This is likely to be useful for the server side of a tunnel.
+.TP
+.B -i
+for
+.IR 6in4 ,
+define what is the local IPv4 address, otherwise it takes the first
+non-loopback address of the outside IP stack.
.TP
.B -g
use the tunnel as the default route for global IPv6 addresses
--- a/sys/src/cmd/ip/6in4.c
+++ b/sys/src/cmd/ip/6in4.c
@@ -71,7 +71,7 @@
static void
usage(void)
{
- fprint(2, "usage: %s [-ag] [-x mtpt] [-o mtpt] [local6[/mask]] [remote4 [remote6]]\n",
+ fprint(2, "usage: %s [-ag] [-x mtpt] [-o mtpt] [-i local4] [local6[/mask]] [remote4 [remote6]]\n",
argv0);
exits("Usage");
}
@@ -261,11 +261,14 @@
case 'o':
outside = EARGF(usage());
break;
+ case 'i':
+ parseip(myip, EARGF(usage()));
+ break;
default:
usage();
} ARGEND
- if (myipaddr(myip, outside) < 0)
+ if (ipcmp(myip, IPnoaddr) == 0 && 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);