Created attachment 242082 [details] www/lighttpd: fix listening on IPv6 addresses getaddrinfo was changed recently to (re)introduce EAI_NODATA and EAI_ADDRFAMILY error cases. These are non-standard error cases with differing semantics across different libc implementations. BSD libc returns EAI_ADDRFAMILY as being synonymous with the nsdispatch error case of similar name NS_ADDRFAMILY. However, GNU libc uses EAI_ADDRFAMILY to report trying to resolve an IPv4 address with an IPv6 hint and vice-versa. lighttpd abuses this error case by assuming each listen address is first an IPv6 address, falling through to trying IPv4 on error. On systems that define EAI_ADDRFAMILY, the return code is tested to be EAI_ADDRFAMILY before attempting the IPv4 lookup. On platforms that don't define EAI_ADDRFAMILY, this additional test is skipped. This patch undefines EAI_ADDRFAMILY.
Can you report this to upstream?
Yep. I will do that as well
> This patch undefines EAI_ADDRFAMILY. Unconditionally undefining EAI_ADDRFAMILY is not something that would be accepted upstream. Might one of the following patches work better for FreeBSD? --- a/src/sock_addr.c +++ b/src/sock_addr.c @@ -496,7 +496,9 @@ int sock_addr_from_str_hints(sock_addr * const restrict saddr, socklen_t * const if (0 != (rc = getaddrinfo(str, NULL, &hints, &res))) { hints.ai_family = AF_INET; if ( - #ifdef EAI_ADDRFAMILY + #if defined(EAI_ADDRFAMILY) && defined(EAI_NODATA) + (EAI_ADDRFAMILY == rc || EAI_NODATA == rc) && + #elif (defined(EAI_ADDRFAMILY) EAI_ADDRFAMILY == rc && #endif 0 == getaddrinfo(str, NULL, &hints, &res)) { or this? --- a/src/sock_addr.c +++ b/src/sock_addr.c @@ -496,7 +496,7 @@ int sock_addr_from_str_hints(sock_addr * const restrict saddr, socklen_t * const if (0 != (rc = getaddrinfo(str, NULL, &hints, &res))) { hints.ai_family = AF_INET; if ( - #ifdef EAI_ADDRFAMILY + #if defined(__GLIBC__) && defined(EAI_ADDRFAMILY) EAI_ADDRFAMILY == rc && #endif 0 == getaddrinfo(str, NULL, &hints, &res)) { I am leaning towards the latter patch.
Sure, if the plan is to upstream to lighttpd that is reasonable.
This patch is now on lighttpd git master branch and will be part of lighttpd 1.4.71, though no release date is scheduled at the moment (i.e. not soon). - #ifdef EAI_ADDRFAMILY + #if defined(__GLIBC__) && defined(EAI_ADDRFAMILY) Please do report issues upstream on https://wiki.lighttpd.net/ (I happened to stumble across this issue via search engine.)
Will do, thanks. Since the next release is not scheduled, I will go ahead submit a revised patch that is aligned with the patch upstream.
Created attachment 242197 [details] www/lighttpd: fix listening on IPv6 addresses v2
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=f75fc16179629b51725274bb82aac362fe6e41e5 commit f75fc16179629b51725274bb82aac362fe6e41e5 Author: Piotr Kubaj <pkubaj@FreeBSD.org> AuthorDate: 2023-05-25 08:16:20 +0000 Commit: Piotr Kubaj <pkubaj@FreeBSD.org> CommitDate: 2023-05-25 08:18:44 +0000 www/lighttpd: fix listening on IPv6 addresses PR: 271335 www/lighttpd/Makefile | 1 + www/lighttpd/files/patch-src_sock__addr.c (new) | 11 +++++++++++ 2 files changed, 12 insertions(+)