Skip to content

mod_http3: Bind the QUIC socket to the address given to Listen - #1069

Open
arturobernalg wants to merge 2 commits into
apache:trunkfrom
arturobernalg:fix/httpd-h3-listen-address
Open

arturobernalg wants to merge 2 commits into
apache:trunkfrom
arturobernalg:fix/httpd-h3-listen-address

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

With Listen 127.0.0.1:443, TCP is served on 127.0.0.1 only, but mod_http3 binds its UDP socket to :: dual-stack and serves HTTP/3 on every address of the host: LAN, global IPv6, other loopback addresses. h3_socket_open() only ever took the port.

# Listen 127.0.0.1:18443
$ ss -ulnp | grep 18443
udp  UNCONN 0  0  *:18443  ...
$ curl --http3-only https://192.168.0.240:18443/   # 200
$ curl --http1.1    https://192.168.0.240:18443/   # connection refused

This takes the address from the Listen directives for the TCP port of the HTTP/3 host, or from every listener for a host without a port such as the main server. A wildcard keeps today's dual-stack socket; a single address is bound alone, in its own family (V6ONLY for IPv6). One QUIC socket cannot serve several addresses, so in that case HTTP/3 is not started, an error says why, and no Alt-Svc is sent; TCP is unaffected. A graceful restart that changes the address binds the parent's socket again.

Serving one socket per address would need the module's one-socket-per-port design to change, so I kept to this; an explicit IPv4 plus IPv6 pair on the port currently leaves HTTP/3 off.

Tests: test/modules/http3/test_017_listen_address.py, using 127.0.0.2 as the other address (Linux only). On trunk 6 of the 7 fail (the wildcard case passes, as it should); with this change all pass. Built like the CI mod_http3 job, 0 warnings. The rest of modules/http3: 148 passed; test_003_03 and test_106_01/02 fail at teardown on trunk as well, and test_016, 203, 204 and 205 need aioquic, which I don't have locally. test_202_01 (graceful restart) hung twice in 29 local runs with this change and not in 12 trunk runs; with a wildcard Listen the change takes the same path as trunk, so I think it is the existing graceful-restart race, but flagging it.

No CVE: mod_http3 is trunk-only and unreleased.

@jfclere this touches the socket setup in h3_server.c, would you take a look?

h3_socket_open() always bound the IPv6 dual-stack wildcard and took only
the port, so with "Listen 127.0.0.1:443" HTTP/3 was still served on every
address of the host, while TCP was not.

Take the address from the Listen directives for the TCP port of the
HTTP/3 host, or from every listener for a host without a port: a
wildcard keeps the dual-stack wildcard, a single address is bound alone,
in its own family. One QUIC socket cannot serve several addresses, so
then HTTP/3 is not started and no Alt-Svc is sent. A graceful restart
that changes the address binds the socket again.

* modules/http3/h3_server.c (choose_quic_addr, h3_server_enabled): New.
  (h3_server_post_config): Take the configuration pool. Choose the
  address, or leave HTTP/3 off. Keep the bound address and bind again
  when it changes.
  (acquire_port, h3_child_init): Bind the chosen address.
* modules/http3/h3_socket.c (h3_socket_open): Take the address to bind.
* modules/http3/h3_hooks.c: Send no Alt-Svc while HTTP/3 is off.
* modules/http3/h3_config.c: Pass the configuration pool.
* modules/http3/README.md: Say so.
* test/modules/http3/test_017_listen_address.py: New.
* test/modules/http3/env.py (rewrite_test_conf): New.
Comment thread modules/http3/h3_server.c Outdated

/* The address the QUIC socket binds, chosen in post_config; NULL while
* HTTP/3 is off. The children inherit it. */
static apr_sockaddr_t* quic_addr = NULL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add apr_sockaddr_t* quic_addr; next to h3_port in h3_config.h?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 24ccc22: quic_addr now lives in h3_server_conf, next to h3_port.

Comment thread modules/http3/h3_server.c Outdated
/* The address the QUIC socket binds, chosen in post_config; NULL while
* HTTP/3 is off. The children inherit it. */
static apr_sockaddr_t* quic_addr = NULL;
static int quic_refused = 0;

@jfclere jfclere Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need it, quic_addr=NULL has the same meaning no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, removed in 24ccc22. A NULL quic_addr now means HTTP/3 was not started, and the Alt-Svc check uses that.

Store the address chosen in post_config in each HTTP/3 host's
configuration instead of a file static, and drop quic_refused: a NULL
address already means HTTP/3 was not started.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants