[support] How do the tunnel work?
tony chen
aoc90058 at gmail.com
Sun Nov 15 13:01:22 JST 2009
Hi!everyone.
I'm doing about creating ipv6 tunnel and encountering a problem.
I wrote a program that was similar to "tunnalctl.c" in nepl.
As i run the NEPL and build up the tunnel ,the information is
Sun Nov 15 11:29:22 __tunnel_add: created tunnel ip6tnl3 (18) from
2001:a:b:0:0:0:0:1 to 2001:a:b:0:0:0:0:1000 user count 1
Sun Nov 15 11:29:22 tnl_dump: name: ip6tnl3
link: 3
proto: 41
encap_limit: 0
hop_limit: 64
flowinfo: 0
flags: 30009
laddr: 2001:a:b:0:0:0:0:1
raddr: 2001:a:b:0:0:0:0:1000
ifindex: 18
users: 1
Sun Nov 15 11:29:22 conf_home_addr_info: Home address 2001:a:b:0:0:0:0:1
Sun Nov 15 11:29:22 flag_hoa: set HoA 2001:a:b:0:0:0:0:1/128 iif 18 flags 12
preferred_time 4294967295 valid_time 4294967295
Sun Nov 15 11:29:22 conf_home_addr_info: Added new home_addr_info
successfully
I look at the ifconfig infomation about ip6tnl3:
ip6tnl3 Link encap:UNSPEC HWaddr
20-01-00-0A-00-0B-00-00-00-00-00-00-00-00-00-00
inet6 addr: fe80::212:f0ff:fe08:72ce/64 Scope:Link
inet6 addr: 2001:a:b::1/128 Scope:Global
UP POINTOPOINT RUNNING NOARP MTU:1460 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
but I wrote my program following above information,and I use the tnl_dump to
get the tunnel information:
name: ip6tnl6
link: 0
proto: 41
encap_limit: 0
hop_limit: 64
flowinfo: 0
flags: 30009
laddr: 2001:a:b:0:0:0:0:1
raddr: 2001:0:0:0:0:0:0:1000
ifindex: 20
users: 1
It's right,
but I look at information of ifconfig of the ip6tnl6.
ip6tnl6 Link encap:UNSPEC HWaddr
20-01-00-0A-00-0B-00-00-00-00-00-00-00-00-00-00
inet6 addr: fe80::212:f0ff:fe08:72ce/64 Scope:Link
UP POINTOPOINT RUNNING NOARP MTU:1460 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
the inet6 addr: 2001:a:b::1/128 Scope:Global is gone!! Orz..
why?
This is my code below:
int main()
{
const char basedev[] = "ip6tnl0";
struct mip6_tnl *tnl = NULL;
struct ifreq ifr;
struct in6_addr *local, *remote;
int link=0;
if ((tnl_fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
return -1;
local=malloc( sizeof(struct in6_addr) );
remote=malloc( sizeof(struct in6_addr) );
if ((tnl = malloc(sizeof(struct mip6_tnl))) == NULL)
return NULL;
memset(local,0,sizeof(struct in6_addr));
memset(remote,0,sizeof(struct in6_addr));
inet_pton(AF_INET6, "2001:a:b::1", &(local->in6_u.u6_addr16));
inet_pton(AF_INET6, "2001::1", &(remote->in6_u.u6_addr16));
memset(tnl, 0, sizeof(struct mip6_tnl));
tnl->users = 1;
tnl->parm.proto = IPPROTO_IPV6;
tnl->parm.flags = IP6_TNL_F_MIP6_DEV|IP6_TNL_F_IGN_ENCAP_LIMIT;
tnl->parm.hop_limit = 64;
tnl->parm.laddr = *local;
tnl->parm.raddr = *remote;
tnl->parm.link = link;
strcpy(ifr.ifr_name, basedev);
ifr.ifr_ifru.ifru_data = (void *)&tnl->parm;
if (ioctl(tnl_fd, SIOCADDTUNNEL, &ifr) < 0) {
printf("SIOCADDTUNNEL failed status %d %s\n",
errno, strerror(errno));
goto err;
}
if (!(tnl->parm.flags & IP6_TNL_F_MIP6_DEV)) {
printf("tunnel exists,but isn't used for MIPv6\n");
goto err;
}
strcpy(ifr.ifr_name, tnl->parm.name);
if (ioctl(tnl_fd, SIOCGIFFLAGS, &ifr) < 0) {
printf("SIOCGIFFLAGS failed status %d %s\n",
errno, strerror(errno));
goto err;
}
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (ioctl(tnl_fd, SIOCSIFFLAGS, &ifr) < 0) {
printf("SIOCSIFFLAGS failed status %d %s\n",
errno, strerror(errno));
goto err;
}
if (!(tnl->ifindex = if_nametoindex(tnl->parm.name))) {
printf("no device called %s\n", tnl->parm.name);
goto err;
}
tnl_dump(tnl);
return tnl;
err:
free(tnl);
return NULL;
}
Thank to everybody viewing and replying.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ml.nautilus6.org/pipermail/support/attachments/20091115/951c2fb0/attachment.html
More information about the Support
mailing list