freelan-developers / freelan

The main freelan repository.
http://www.freelan.org
Other
1.35k stars 200 forks source link

webserver listen_on=[::]:443 use a random IPv6 listen port #215

Closed HenryNe closed 4 years ago

HenryNe commented 4 years ago

If the buildin web server is configured for all IPv6 devices with the option listen_on=[::]:443, then the web server is listen on a random IPv4 port.

Used ports by Freelan:

# netstat -antup | grep freelan
tcp        0      0 0.0.0.0:27113           0.0.0.0:*               LISTEN      2007/./freelan
tcp        0      0 127.0.0.1:62109         127.0.0.1:46610         ESTABLISHED 2007/./freelan
tcp        0      0 127.0.0.1:46610         127.0.0.1:62109         ESTABLISHED 2007/./freelan
udp        0      0 0.0.0.0:11701           0.0.0.0:*                           765/freelan
udp6       0      0 :::12000                :::*                                2007/./freelan

The "0.0.0.0:27113" is wrong there. This should be ":::443".

Config:

# sed '/^[[:blank:]]*#/d;s/#.*//;/^$/d' $HOME/freelan.conf
[server]
enabled=yes
listen_on=[::]:443
[client]
[fscp]
listen_on=[::]:12000
upnp_enabled=no
[tap_adapter]
name=tap0
ipv4_address_prefix_length=9.0.0.1/24
[switch]
[router]
[security]

Runing:

# ./freelan -f -d -c $HOME/freelan.conf
...
[DEBUG] Web server's listen endpoint set to [::]:443.
[INFORMATION] Starting https web server on [::]:443...
[INFORMATION] Web server started.

Full debug log: freelan-debug.txt

Freelan was build from source release 2.2 with:

$ make USE_MONGOOSE=yes
$ ./freelan -v
freelan 2.2.0 (2.2) Sun 22 Mar 2020

Same issure with build from current master source "freelan 2.3.0 (2.3) Sun 22 Mar 2020".

s-vincent commented 4 years ago

Hi and thanks for report !

After a quick review in code, we do not compile libmongoose with IPv6 support. => I will fix it soon.

HenryNe commented 4 years ago

NS_ENABLE_IPV6 in mongooseplus not helps. It stops here now:

2020-03-23T19:52:19.328549 [DEBUG] Web server's listen endpoint set to [::]:443.
2020-03-23T19:52:19.343334 [ERROR] Cannot bind to port

Lets see more with strace:

write(1, "2020-03-23T19:58:31.893982 [\33[37"..., 902020-03-23T19:58:31.893982 [DEBUG] Web server's listen endpoint set to [::]:443.) = 90
socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP) = 15
setsockopt(15, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(15, {sa_family=AF_INET6, sa_data="\1\273\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = -1 EINVAL (Invalid argument)
close(15)                               = 0
s-vincent commented 4 years ago

I try to fix that in git revision c74d13b6ebc14d5673d1bcae5d0574b2dcbf7519.

HenryNe commented 4 years ago

I try to fix that in git revision c74d13b.

HTTPS is working now. Connection with web browser is OK. Thanks again.