[erlang-bugs] Connection to IPv6 link local address fails due to missing scope identifier
Raimo Niskanen
raimo+erlang-bugs@REDACTED
Wed Oct 13 09:04:30 CEST 2010
On Tue, Oct 12, 2010 at 10:41:19PM +0200, Michael Stapelberg wrote:
> Hi,
>
> the following proof of concept fails:
> -module(poc).
> -export([start/0]).
>
> start() ->
> {ok, Sock} = gen_tcp:connect("fe80::21f:16ff:fe1a:f5b8%eth0", 80, [inet6]),
> io:fwrite("connect said: ~p~n", [ok]).
>
> If you strace it using strace -fF -etrace=network erl -s poc, you???ll see the
> following:
>
> socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP) = 7
> bind(7, {sa_family=AF_INET6, sin6_port=htons(0), inet_pton(AF_INET6, "::",
> &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0
> getsockname(7, {sa_family=AF_INET6, sin6_port=htons(36404),
> inet_pton(AF_INET6, "::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0},
> [28]) = 0
> connect(7, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6,
> "fe80::21f:16ff:fe1a:f5b8", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0},
> 28) = -1 EINVAL (Invalid argument)
>
> The problem is the missing scope identifier (sin6_scope_id), which should be 2
> for eth0 in my case (see /proc/net/igmp6 for easily getting the scope id for
> your interfaces).
Scope identifiers are currently not implemented. They are also not quite
portable, especially how you find them out and translate them into the 32-bit
scope ID needed in sockaddr_in6{}.
We need to support as many as possible of Linux, Solaris 8/9/10/..,
Windows XP/Vista/7, MacOS X, FreeBSD, OpenBSD and NetBSD, plus some other
Unix-like OS:es. Most do not have Linux /proc.
We also need to solve our own backwards compatibility problem of representing
IPv6 addresses as 8-tuples of 0..65535 and having _lots_ of code testing
for a term being an IPv6-address simply by checking if it is an 8-tuple.
Somehow we need to squeeze in a scope ID in our representation of IPv6 addresses.
There are also issues to consider regarding how and to what extent the
name resolving functions can/should return scope IDs with accompaning
OS compatibility quirks.
But it _is_ on our todo list...
>
> To reproduce this test:
> ??? to test the client side, use nc -6 fe80::21f:16ff:fe1a:f5b8%eth0 80
> ??? to test the server side, use for example OpenSSH (listens on all
> interfaces/addresses per default) or Apache.
> ??? to get your link local address, use ifconfig(1) or "ip a|grep fe80"
>
> Best regards,
> Michael
>
> ________________________________________________________________
> erlang-bugs (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-bugs-unsubscribe@REDACTED
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-bugs
mailing list