[erlang-questions] Inets and IPv6 (noob)

Michael Talyansky mtalyans@REDACTED
Fri May 1 06:27:15 CEST 2009


Kenji,

Thanks, I found this, and also another bit of code (in "any" handling code
path) that favors IPv6 over IPv4.

Do you know, by any chance, how to disable IPv6 on Ubuntu 9.04? I tried the
recommended games with /etc/modprobe.d/blacklist, pf-10 aliases, and so on,
all to no avail. I have finally solved my problem by manually modifying
http_server code to always use IPv4.

It would be very nice to have a parameter in inets or http_server, to
specify which binding is required; after all, gen_tcp does have such
parameter, and handles everything correctly...

Thanks for your help,
Michael Talyansky


On 4/30/09 9:07 PM, "Kenji Rikitake" <kenji.rikitake@REDACTED> wrote:

> In the message <C61D2E52.10FB0%mtalyans@REDACTED>
> dated Tue, Apr 28, 2009 at 10:05:46PM -0700,
> Michael Talyansky <mtalyans@REDACTED> writes:
>> On BSD, server was binding to (and listening on) IPv4 address. On Linux, it
>> binds to IPv6 only (verified with netstat), unless I explicitly specify IPv4
>> interface address in the bind_address tuple.
> 
> On Ubuntu 8.10 and 9.04, IPv6 is enabled as default.
> 
> See the following code from R13B; IPv6 takes precedence higher than
> IPv4, if enabled.
> 
> %%% quoted from R13B lib/inets/src/http_server/httpd_util.erl
> ip_address(Host) ->
>     Inet = case gen_tcp:listen(0, [inet6]) of
>                {ok, Dummyport} ->
>                    gen_tcp:close(Dummyport),
>                    inet6;
>                _ ->
>                    inet
>            end,
>     inet:getaddr(Host, Inet).
> %%% unquote
> 
>> What should I set and where in order for the server to bind to both IPv4 and
>> IPv6 addresses?
> 
> You should not do this, at least on FreeBSD (and other *BSDs), because
> IPV6_V6ONLY is effective as default (see sysctl net.inet6.ip6.v6only).
> (See also RFC3493 Section 5.3) In such an environment, you have to bind
> separately to each of IPv4 and IPv6 addresses.
> 
>> I am using R13B, on BSD it was R13A. Could this be a factor?
> 
> I haven't checked out the R13A code, but on R12B5 the code was
> 
> %%% quoted from R12B5 lib/inets/src/http_server/httpd_util.erl
> ip_address(Host) ->
>     case (catch inet:getaddr(Host,inet6)) of
>         {ok, {0, 0, 0, 0, 0, 16#ffff, _, _}} ->
>             inet:getaddr(Host, inet);
>         {ok, IPAddr} ->
>             {ok, IPAddr};
>         _ ->
>             inet:getaddr(Host, inet)
>     end.
> %%% unquote
> 
> so the implementation might be changed.
> 
> (Note that {0, 0, 0, 0, 0, 16#ffff, _, _} represents the set of
> IPv4-mapped address, which does not work on BSD and should be
> deprecated.)
> 
> Kenji Rikitake




More information about the erlang-questions mailing list