Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning INET_DIST_INTERFACE to an IPv6 address #4189

Open
GautaA opened this issue Apr 3, 2024 · 3 comments
Open

Assigning INET_DIST_INTERFACE to an IPv6 address #4189

GautaA opened this issue Apr 3, 2024 · 3 comments
Assignees

Comments

@GautaA
Copy link

GautaA commented Apr 3, 2024

Environment

  • ejabberd version: 23.04
  • Erlang version: Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 13.1.5
  • OS: Linux (Debian)
  • Installed from: official deb/rpm

Bug description

In an IPv6 only environment when trying to set INET_DIST_INTERFACE in ejabberdctl.cfg to "::" or :: the result is:

Protocol 'inet_tcp': register/listen error: badarg

Can this even be done?
When testing in ERL emulator:

4> inet_tcp:parse_address("::").
{error,einval}
5> inet6_tcp:parse_address("::").
{ok,{0,0,0,0,0,0,0,0}}
@badlop
Copy link
Member

badlop commented Apr 3, 2024

This comment is just to say that I can reproduce it, and found no clue.

This works:

erl -sname aaa

epmd -names
epmd: up and running on port 4369 with data:
name aaa at port 35133

netstat -nl |  grep 35133
tcp        0      0 0.0.0.0:35133           0.0.0.0:*               LISTEN     

And also specifying a IPv4 address (the commas ' seem important here):

erl -name aaa@localhost -kernel inet_dist_use_interface '{127,0,0,1}'

epmd -names
epmd: up and running on port 4369 with data:
name aaa at port 37827

netstat -nl | grep 37827
tcp        0      0 127.0.0.1:37827         0.0.0.0:*               LISTEN     

However, I found no way to specify an IPv6 address. I tried:

erl -name aaa@localhost -kernel inet_dist_use_interface '{0,0,0,0,0,0,0,0}'
Protocol 'inet_tcp': register/listen error: badarg

erl -sname aaa@localhost -kernel inet_dist_use_interface '{0,0,0,0,0,0,0,0}'
Protocol 'inet_tcp': register/listen error: badarg

erl
1> inet:parse_address("FFFF::127.0.0.1").   
{ok,{65535,0,0,0,0,0,32512,1}}

erl -name aaa@localhost -kernel inet_dist_use_interface '{65535,0,0,0,0,0,32512,1}'
Protocol 'inet_tcp': register/listen error: badarg

erl -sname aaa -kernel inet_dist_use_interface '{65535,0,0,0,0,0,32512,1}'
Protocol 'inet_tcp': register/listen error: badarg

I can reproduce this with Erlang 25.3, 26.2.3 and 27.0-rc2

I couldn't find documentation for the -kernel option in erl
https://erlang.org/documentation/doc-15.0-rc2/erts-14.3/doc/html/erl_cmd.html

The inet_dist_user_interface option is documented in the kernel application:
https://erlang.org/documentation/doc-15.0-rc2/lib/kernel-9.3/doc/html/kernel_app.html#configuration

@nosnilmot
Copy link
Contributor

it needs -proto_dist inet6_tcp (https://www.erlang.org/doc/man/erl.html#proto_dist):

erl -proto_dist inet6_tcp -sname hello -kernel inet_dist_use_interface "{0,0,0,0,0,0,0,0}"

@badlop
Copy link
Member

badlop commented Apr 3, 2024

Great finding!

Then I guess that ejabberdctl option was never used to setup a IPv6 address.

And to support it, a patch like this would be required:

diff --git a/ejabberdctl.template b/ejabberdctl.template
index f558e93b2..28c31c054 100755
--- a/ejabberdctl.template
+++ b/ejabberdctl.template
@@ -78,6 +78,9 @@ fi
 if [ -n "$INET_DIST_INTERFACE" ] ; then
     INET_DIST_INTERFACE2=$("$ERL" $ERLANG_OPTS -noshell -eval 'case inet:parse_address("'$INET_DIST_INTERFACE'") of {ok,IP} -> io:format("~p",[IP]); _ -> ok end.' -s erlang halt)
     if [ -n "$INET_DIST_INTERFACE2" ] ; then
+        if [ $(echo "$INET_DIST_INTERFACE2" | grep -o "," | wc -l) -eq 7 ] ; then
+            INET_DIST_INTERFACE2="$INET_DIST_INTERFACE2 -proto_dist inet6_tcp"
+        fi
         ERLANG_OPTS="$ERLANG_OPTS -kernel inet_dist_use_interface $INET_DIST_INTERFACE2"
     fi
 fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants