Project

General

Profile

Feature #2204

Fallback to server.port in $SERVER["socket"]

Added by Olaf-van-der-Spek almost 7 years ago. Updated 11 months ago.

Status:
Fixed
Priority:
Normal
Assignee:
-
Category:
core
Target version:
Start date:
2010-05-20
Due date:
% Done:

100%

Missing in 1.5.x:
No

Description

Debian would like to see a way to (automatically) enable IPv6 without specifying a port number (or IP address) to listen on.

Associated revisions

Revision 3104 (diff)
Added by stbuehler about 1 year ago

[core] more careful parse of $SERVER["socket"] config str (prepare #2204)

detect unix domain socket path earlier
detect IPv6 addr without port (might contain ':' within addr, e.g. [::])

From: Glenn Strauss <>

Revision d85bdab4 (diff)
Added by gstrauss about 1 year ago

[core] more careful parse of $SERVER["socket"] config str (prepare #2204)

detect unix domain socket path earlier
detect IPv6 addr without port (might contain ':' within addr, e.g. [::])

From: Glenn Strauss <>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3104 152afb58-edef-0310-8abb-c4023f1b3aa9

Revision 3105 (diff)
Added by stbuehler about 1 year ago

[core] accept $SERVER["socket"] without port, use server.port as fallback (fixes #2204)

From: Stefan Bühler <>

Revision 70036ff5 (diff)
Added by stbuehler about 1 year ago

[core] accept $SERVER["socket"] without port, use server.port as fallback (fixes #2204)

From: Stefan Bühler <>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3105 152afb58-edef-0310-8abb-c4023f1b3aa9

Revision 598cdd0e (diff)
Added by gstrauss 11 months ago

[core] fix IPv6 address + port parsing (#2204)

History

#1 Updated by stbuehler almost 7 years ago

Ok, imagine we had an option "listen-on-ipv6-too":

server.bind = "127.0.0.1" 
listen-on-ipv6-too = "enable" 

Do we listen to "[::]" now or "[::1]" ?

I don't like any magic in that area (yes, i don't like $SERVER["socket"] either).

I don't see a good way to provide this option...

#2 Updated by Olaf-van-der-Spek almost 7 years ago

Well, there are three questions when binding: IP address, port and transport (IPv4, IPv6).
IMO the default should be: *, 80, * where the first * is from server.bind and 80 is from server.port.

If both IPv4 and v6 are available, is there a reason to only bind to one of the two?

#3 Updated by stbuehler almost 7 years ago

The reason is simple: I don't want to change it.

#4 Updated by Olaf-van-der-Spek almost 7 years ago

I understand. Do you have any idea why Debian uses $SERVER["socket"] == "[::]:80" instead of server.use-ipv6?

#5 Updated by andersman almost 7 years ago

Olaf-van-der-Spek wrote:

I understand. Do you have any idea why Debian uses $SERVER["socket"] == "[::]:80" instead of server.use-ipv6?

Probably so it doesn't use v4-mapped addresses (::ffff:1.2.3.4) in REMOTE_ADDR, logs etc.

#6 Updated by Olaf-van-der-Spek almost 7 years ago

andersman wrote:

Probably so it doesn't use v4-mapped addresses (::ffff:1.2.3.4) in REMOTE_ADDR, logs etc.

Hasn't that been solved already by Lighttpd itself?

#7 Updated by stbuehler almost 7 years ago

No, lighty still prints the address as it gets it from the socket (but debian disabled dual-stack, see below).

server.use-ipv6 = "enable" doesn't do much; it only uses
a) ipv6 [::] if you didn't specify server.bind
b) tries to use ipv6 for dns

If you use an ipv6 address in server.bind or $SERVER["socket"] lighty detects ipv6 itself, so no need for the option in these cases.

And i guess it fails if you try server.use-ipv6 with an ipv4 address.

Since debian changed the kernel default for bind-v6only to 1, server.use-ipv6 would lead to ipv6-only listening;
otoh, $SERVER["socket"] == "[::]:80" fails for people who either changed server.port or changed bind-v6only back to 0 (or tried backporting it).

#8 Updated by Olaf-van-der-Spek almost 7 years ago

So server.bind = [::] might be better. Or would that disable IPv4 (if v6only is enabled)?

#9 Updated by Olaf-van-der-Spek almost 7 years ago

What about BSD? It has v6only enabled too AFAIK.

#10 Updated by spaam almost 7 years ago

fbsd set this in their config if you enable ipv6 when you are going to compile:
server.use-ipv6 = "enable"
$SERVER["socket"] == "0.0.0.0:80" { }

#11 Updated by Olaf-van-der-Spek almost 7 years ago

stbuehler wrote:

Do we listen to "[::]" now or "[::1]" ?

Neither. 127.0.0.1 is a v4 address, so only v4 gets bound.
If server.bind = "localhost", both v4 and v6 would get bound.

#12 Updated by stbuehler over 6 years ago

  • Target version changed from 1.4.28 to 1.4.29

#13 Updated by Olaf-van-der-Spek over 6 years ago

Would it be possible to support $SERVER["socket"] == "[::]" (just IPA, no port) and take the port from server.port? It's backwards compatible and solves part of the problem.

#14 Updated by stbuehler almost 6 years ago

  • Target version changed from 1.4.29 to 1.4.x

Might be possible.

#15 Updated by gstrauss about 1 year ago

Submitted pull request https://github.com/lighttpd/lighttpd1.4/pull/42 to fix a couple things
  • detect unix domain socket path earlier
  • detect IPv6 addr without port (might contain ':' within addr, e.g. [::])

After the above, Olaf's request becomes a smaller change to consider to use the default port (srv->srvconf.port) when one is not provided. This specifically errors if string is empty (""), with no host and no port. We'd have to consider how it might affect condition matching in configfile-glue.c were it to be allowed.

diff --git a/src/network.c b/src/network.c
index b401787..12c515b 100644
--- a/src/network.c
+++ b/src/network.c
@@ -205,11 +205,14 @@ static int network_server_init(server *srv, buffer *host_token, specific_config
                size_t len = buffer_string_length(b);
                char *sp = NULL;
                if ((b->ptr[0] == '[' && b->ptr[len-1] == ']') || NULL == (sp = strrchr(b->ptr, ':'))) {
-                       if (NULL == sp) {
-                               log_error_write(srv, __FILE__, __LINE__, "sb", "value of $SERVER[\"socket\"] has to be \"ip:port\".", b);
+                       if (*b->ptr == '\0') {
+                               log_error_write(srv, __FILE__, __LINE__, "s", "value of $SERVER[\"socket\"] has to be \"ip:port\"; value may not be empty");

                                goto error_free_socket;
                        }
+                       /* use server.port if set in config, or else default from config_set_defaults() */
+                       port = srv->srvconf.port;
+                       sp = b->ptr + len; /* point to '\0' at end of string */
                }

                /* check for [ and ] */

#16 Updated by stbuehler about 1 year ago

  • Subject changed from Enable IPv6 conf to Fallback to server.port in $SERVER["socket"]

#17 Updated by stbuehler about 1 year ago

  • Target version changed from 1.4.x to 1.4.40

#18 Updated by stbuehler about 1 year ago

  • Status changed from New to Fixed
  • % Done changed from 0 to 100

Applied in changeset r3105.

#19 Updated by roytam1 11 months ago

seem this changeset breaks this type of config:

# listen to ipv6
$SERVER["socket"] == "[::]:80" {  }

I tried with latest git rev and I got "gethostbyname failed: 1" error.

#20 Updated by gstrauss 11 months ago

Thanks for the report. I have committed a patch to address the issue and it will push to master on Monday.

#21 Updated by gstrauss 11 months ago

roytam1: the issue you reported should be fixed with current tip of git master. Thanks.

#22 Updated by roytam1 11 months ago

gstrauss wrote:

roytam1: the issue you reported should be fixed with current tip of git master. Thanks.

Fix confirmed, Thanks!

Also available in: Atom