#865520 calypso: does not listen on IPv6 address

Package:
calypso
Source:
calypso
Submitter:
Roland Hieber
Date:
2024-11-25 00:10:37 UTC
Severity:
normal
Tags:
#865520#5
Date:
2017-06-22 10:33:01 UTC
From:
To:
Dear Maintainer,

I tried to find an option to let calypso listen on IPv6, but I found none.
I'm starting calypso over a minimal systemd unit file:

#865520#10
Date:
2018-03-26 12:40:05 UTC
From:
To:
For the record, an obvious workaround is to put calypso behind a reverse
proxy, for example with nginx:

server {
	listen 80 default_server;
	listen [::]:80 default_server ipv6only=on;
	listen 443 default_server ssl;
	listen [::]:443 default_server ipv6only=on ssl;
# [...]
	location /calendar {
		proxy_set_header Host $host;
		proxy_buffering off;
		proxy_pass https://localhost:5233/calendar;
	}
}

 - Roland

#865520#15
Date:
2024-10-22 22:49:37 UTC
From:
To:
control: tags -1 patch

I have a fix for this issue that allows calypso to listen on addresses
from addressing families other than AF_INET. This means that by default,
not specifying anything, the server will typically listen on :: and
service IPv4 addresses too.

I could not clone the specified upstream repo but did add a merge
request to the maintainer repo so please use that or the following patch
at your convenience!

Thank you,

Andrew


From 8c161af0febb99bfb956ff5793ac378581230129 Mon Sep 17 00:00:00 2001
From: Andrew Bower <andrew@bower.uk>
Date: Tue, 22 Oct 2024 23:15:43 +0100
Subject: [PATCH] Listen on appropriate addressing family

Rather than only listening on AF_INET, regardless of the addressing
family needed to support the supplied hostname, listen on the addressing
family of the first result from getaddrinfo() after re-ordering to make
sure AF_INET6 addresses come first.

This enables dual-stack listening by default with no hostname specified.
---
 calypso/__init__.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/calypso/__init__.py b/calypso/__init__.py
index 7c9a81b..d3285c9 100644
--- a/calypso/__init__.py
+++ b/calypso/__init__.py
@@ -99,6 +99,22 @@ def _check(request, function):
     # pylint: enable=W0212


+def resolve_server_address(address):
+    """Get server address details from string."""
+    (host, port) = address
+    addrs = socket.getaddrinfo(None if host == '' else host, port,
+                               type=socket.SOCK_STREAM,
+                               flags=socket.AI_PASSIVE)
+
+    # Put IPv6 addresses first, resulting in dual stack listener by default,
+    # otherwise preserving ordering.
+    inorder      = [a for a in addrs if a[0] == socket.AF_INET6]
+    inorder.extend([a for a in addrs if a[0] != socket.AF_INET6])
+
+    # Ideally we would listen on each returned address separately.
+    return inorder[0] if inorder else None
+
+
 class HTTPServer(server.HTTPServer):
     """HTTP server."""
     PROTOCOL = "http"
@@ -107,6 +123,9 @@ class HTTPServer(server.HTTPServer):
     # pylint: disable=W0231
     def __init__(self, address, handler):
         """Create server."""
+        addrinfo = resolve_server_address(address)
+        self.address_family = addrinfo[0]
+        self.socket_type = addrinfo[1]
         http_server.__init__(self, address, handler)
         self.acl = acl.load()
     # pylint: enable=W0231

#865520#22
Date:
2024-11-24 23:50:55 UTC
From:
To:
On Tue, Oct 22, 2024 at 11:49:37PM +0100, Andrew Bower wrote:

[..]
[..]
[..]

I have replaced my patch on salsa, which was formulated as an upstream
patch, with a downstream Debian patch that could be applied
independently of upstream:

https://salsa.debian.org/debian/calypso/-/merge_requests/3

It would be nice to squash another IPv6 miss in Debian!

#865520#25
Date:
2024-11-24 23:50:55 UTC
From:
To:
On Tue, Oct 22, 2024 at 11:49:37PM +0100, Andrew Bower wrote:

[..]
[..]
[..]

I have replaced my patch on salsa, which was formulated as an upstream
patch, with a downstream Debian patch that could be applied
independently of upstream:

https://salsa.debian.org/debian/calypso/-/merge_requests/3

It would be nice to squash another IPv6 miss in Debian!