OpenWrt Forum Archive

Topic: uHTTPd listening on one interface with IPv4 and IPv6 on the same port

The content of this topic has been archived on 23 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I currently try to configure my Trunk x86 Router with uHTTPd to listen only on the lan port on both IPv4 and IPv6.
Documentation say
"80" -> then listen on ALL interfaces on port 80
0.0.0.0:80 -> Only IPv4 on ALL Interfaces
[::]:80 -> Only IPv6 an ALL interfaces
192.168.1.1:80 -> Only IPv4 on Interface with given address
[fe80:....:1] -> Only IPv6 on Interface with given address

If I configure both 192.168.1.1:80 and a second entry [fe80:....:1]80 in /etc/config/uhttpd, only the first parameter
is recognised and uHTTPd started listening on this IPv4 or IPv6. Never both protocols.
For security reasons I only want access to on interface.

Thanks for your support

Christian

Show the exact config you tried, it works just fine here.

I can connect via browser (mozilla firefox on ubuntu 13.04 and firefox and ie on win7) only to the IPv4.

config uhttpd 'main'
    option home '/www'
    option rfc1918_filter '1'
    option max_requests '3'
    option max_connections '100'
    option cgi_prefix '/cgi-bin'
    option script_timeout '60'
    option network_timeout '30'
    option http_keepalive '20'
    option index_page 'blank.gif'
    option error_page '/blank.gif'
    option cert '/etc/certs/server.crt'
    option key '/etc/certs/server.key'
    option tcp_keepalive '5'
    option realm 'VBox-OWRouter'
    option no_dirlists '1'
    option no_symlinks '0'
    list listen_http '192.168.238.190:80'
    list listen_http '[fe80::a00:27ff:fea4:36e0]:80'

You're binding to a link local ip, this will not work with most normal programs. You should bind it to a non-link-local address, e.g. an ULA or public one.

why not link local ?
it's simply an ipv6 address, no routing needed
ping works fine
the web interface of my HP printer is also availible via link local
the default router is set to the link local address via dhcp/6relayd

looks like that uhttpd did not allow to use link local

Sorry to bring up this old topic, but has there been some solutions to this?

My /etc/config/uhttpd is default setting and is shown below, yet I can ONLY access it through my google chrome with IPv4. When trying to put the IPv6 address and/or IPv6 FQDN using my google chrome, I get This webpage is not available error messages. I can ping my device through either IPv6 and/or IPv6 FQDN without a problem.

config uhttpd 'main'
        list    listen_http     '0.0.0.0:80'
        list    listen_http     '[::]:80'
        list    listen_https    '0.0.0.0:443'
        list    listen_https    '[::]:443'
        option  home            '/www'
        option  rfc1918_filter  '1'
        option  max_requests    '3'
        option  cert            '/etc/uhttpd.crt'
        option  key             '/etc/uhttpd.key'
        option  cgi_prefix      '/cgi-bin'
        option  script_timeout  '60'
        option  network_timeout '30'
        option  tcp_keepalive   '1'
        option  ubus_prefix     '/ubus'

Why don't you listen on *:80 and use the firewall/iptables to control traffic?

It would be ideal if the uhttpd daemon allowed for this kind of config, but it doesn't, and there is already a tool that allows both the OP and yourself to do what you want.

The original issue is just a configuration mistake. When using IPv6 link local IPs you *must* include the scope identifier, here's some strace log:

root@OpenWrt:~# strace -e bind uhttpd -h /tmp -p [fe80::20d:b9ff:fe35:8849]:80
bind(3, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "fe80::20d:b9ff:fe35:8849", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 EINVAL (Invalid argument)
bind(): Invalid argument
Error: No sockets bound, unable to continue
+++ exited with 1 +++
root@OpenWrt:~#

With scope identifier:

root@OpenWrt:~# strace -e bind uhttpd -h /tmp -p [fe80::20d:b9ff:fe35:8849%br-lan]:80
bind(3, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "fe80::20d:b9ff:fe35:8849", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=if_nametoindex("br-lan")}, 28) = 0
+++ exited with 0 +++
root@OpenWrt:~#

So short answer, when you want to use link local IPs, use the % scope notation:

list listen_http '[fe80::a00:27ff:fea4:36e0%br-lan]:80'

The discussion might have continued from here.