Project

General

Profile

Actions

Feature #2204

closed

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

Added by Olaf-van-der-Spek almost 14 years ago. Updated almost 8 years ago.

Status:
Fixed
Priority:
Normal
Category:
core
Target version:
ASK QUESTIONS IN Forums:

Description

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

Actions #1

Updated by stbuehler almost 14 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...

Actions #2

Updated by Olaf-van-der-Spek almost 14 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?

Actions #3

Updated by stbuehler almost 14 years ago

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

Actions #4

Updated by Olaf-van-der-Spek almost 14 years ago

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

Actions #5

Updated by andersman almost 14 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.

Actions #6

Updated by Olaf-van-der-Spek almost 14 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?

Actions #7

Updated by stbuehler almost 14 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).

Actions #8

Updated by Olaf-van-der-Spek almost 14 years ago

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

Actions #9

Updated by Olaf-van-der-Spek almost 14 years ago

What about BSD? It has v6only enabled too AFAIK.

Actions #10

Updated by spaam almost 14 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" { }

Actions #11

Updated by Olaf-van-der-Spek almost 14 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.

Actions #12

Updated by stbuehler over 13 years ago

  • Target version changed from 1.4.28 to 1.4.29
Actions #13

Updated by Olaf-van-der-Spek over 13 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.

Actions #14

Updated by stbuehler almost 13 years ago

  • Target version changed from 1.4.29 to 1.4.x

Might be possible.

Actions #15

Updated by gstrauss about 8 years 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 ] */

Actions #16

Updated by stbuehler about 8 years ago

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

Updated by stbuehler about 8 years ago

  • Target version changed from 1.4.x to 1.4.40
Actions #18

Updated by stbuehler about 8 years ago

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

Applied in changeset r3105.

Actions #19

Updated by roytam1 almost 8 years 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.

Actions #20

Updated by gstrauss almost 8 years ago

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

Actions #21

Updated by gstrauss almost 8 years ago

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

Actions #22

Updated by roytam1 almost 8 years ago

gstrauss wrote:

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

Fix confirmed, Thanks!

Actions

Also available in: Atom