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

This commit is contained in:
cinap_lenrek 2013-01-14 07:09:25 +01:00
parent 33768d90bf
commit f2f2c8687a
2 changed files with 30 additions and 10 deletions

View file

@ -9,6 +9,9 @@
.B -x .B -x
.I netmtpt .I netmtpt
] [ ] [
.B -o
.I outnetmtpt
] [
.IB local6[ / mask] .IB local6[ / mask]
[ [
.I remote4 .I remote4
@ -78,7 +81,20 @@ use the tunnel as the default route for global IPv6 addresses
use the network mounted at use the network mounted at
.I netmtpt .I netmtpt
instead of 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 .PD
.SH EXAMPLES .SH EXAMPLES
If your primary IPv4 address is public, If your primary IPv4 address is public,

View file

@ -60,7 +60,8 @@ uchar myip[IPaddrlen];
/* magic anycast address from rfc3068 */ /* magic anycast address from rfc3068 */
uchar anycast6to4[IPv4addrlen] = { 192, 88, 99, 1 }; 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 badipv4(uchar*);
static int badipv6(uchar*); static int badipv6(uchar*);
@ -70,7 +71,7 @@ static void tunnel2ip(int, int);
static void static void
usage(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); argv0);
exits("Usage"); exits("Usage");
} }
@ -163,7 +164,7 @@ setup(int *v6net, int *tunp)
* gain access to IPv6-in-IPv4 packets via ipmux * gain access to IPv6-in-IPv4 packets via ipmux
*/ */
p = seprint(buf, buf + sizeof buf, "%s/ipmux!proto=%2.2x|%2.2x;dst=%V", 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) if (!anysender)
seprint(p, buf + sizeof buf, ";src=%V", remote4 + IPv4off); seprint(p, buf + sizeof buf, ";src=%V", remote4 + IPv4off);
*tunp = dial(buf, 0, 0, 0); *tunp = dial(buf, 0, 0, 0);
@ -176,7 +177,7 @@ setup(int *v6net, int *tunp)
* open local IPv6 interface (as a packet interface) * 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 */ cfd = open(cl, ORDWR); /* allocate a conversation */
n = 0; n = 0;
if (cfd < 0 || (n = read(cfd, buf, sizeof buf - 1)) <= 0) if (cfd < 0 || (n = read(cfd, buf, sizeof buf - 1)) <= 0)
@ -186,7 +187,7 @@ setup(int *v6net, int *tunp)
free(cl); free(cl);
buf[n] = 0; 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); *v6net = open(path, ORDWR);
if (*v6net < 0 || fprint(cfd, "bind pkt") < 0) if (*v6net < 0 || fprint(cfd, "bind pkt") < 0)
sysfatal("can't bind packet interface: %r"); sysfatal("can't bind packet interface: %r");
@ -199,7 +200,7 @@ setup(int *v6net, int *tunp)
if (gateway) { if (gateway) {
/* route global addresses through the tunnel to remote6 */ /* route global addresses through the tunnel to remote6 */
ir = smprint("%s/iproute", net); ir = smprint("%s/iproute", inside);
cfd = open(ir, OWRITE); cfd = open(ir, OWRITE);
if (cfd >= 0 && debug) if (cfd >= 0 && debug)
fprint(2, "injected 2000::/3 %I into %s\n", remote6, ir); fprint(2, "injected 2000::/3 %I into %s\n", remote6, ir);
@ -255,14 +256,17 @@ main(int argc, char **argv)
gateway++; gateway++;
break; break;
case 'x': case 'x':
net = EARGF(usage()); outside = inside = EARGF(usage());
break;
case 'o':
outside = EARGF(usage());
break; break;
default: default:
usage(); usage();
} ARGEND } ARGEND
if (myipaddr(myip, net) < 0) if (myipaddr(myip, outside) < 0)
sysfatal("can't find my ipv4 address on %s", net); sysfatal("can't find my ipv4 address on %s", outside);
if (!isv4(myip)) if (!isv4(myip))
sysfatal("my ip, %I, is not a v4 address", myip); sysfatal("my ip, %I, is not a v4 address", myip);