Repository navigation
Send a CONNECTION_CLOSE when conn_new() refuses a DoQ connection - #3373
Merged
Merged
Conversation
OpenSSL hands a connection to `SSL_accept_connection()` on the client's first validated Initial, after it has sent the server's first flight, so the client completes its handshake and believes the connection is up. When `conn_new()` then refused it, at the connection caps or for a source that is not allowed, it only called `SSL_free()`, which discards the connection without a CONNECTION_CLOSE. The client sent its queries into it until its idle timer ran out, 30 s later, instead of failing over. Sending the close right away is not enough either. Until the handshake is complete OpenSSL can send it only in an Initial packet, and a client that has already sent its Handshake packet has dropped its Initial keys (RFC 9001 Sec. 4.9.1) and cannot read it. Freeing the connection also drops its connection IDs, so the client's next Initial, which still carries the Retry token, makes OpenSSL accept a second connection that is refused the same way. Under load 4 of 160 refused clients at the per-source cap and 12 of 100 at the global cap never learned about the refusal, and most of the others got a transport APPLICATION_ERROR instead of the DoQ code. `conn_refuse()` therefore keeps a refused connection until its handshake is complete and then closes it with `DOQ_EXCESSIVE_LOAD` at the caps, `DOQ_INTERNAL_ERROR` otherwise, which goes out in a 1-RTT packet with that code. `refused_drive()` advances these connections from the event loop. At most `DOQ_MAX_REFUSED` (16) connections are kept, each for at most about 2 s (`DOQ_REFUSE_TIMEOUT_MS` for the handshake, then `DOQ_CLOSE_TIMEOUT_MS` for the close). A refusal beyond them closes the connection at once, where the close can be lost as before; a client opening connections beyond the caps can fill the table to get there. `doq_shutdown()` takes the connection object and the code for this. Signed-off-by: 010011110 <duckenheim@posteo.de>
DL6ER
approved these changes
Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
when conn_new() refused a DoQ connection (connection caps, source not allowed) it only called SSL_free(). OpenSSL hands the connection out after the server's first flight, so the client finished its handshake, got no CONNECTION_CLOSE and sent its queries into nothing until its own idle timeout instead of failing over
sending the close right away is not enough: before the handshake completes OpenSSL can only send it in an Initial packet, which a client that already sent its Handshake packet cannot decrypt any more (RFC 9001 4.9.1), and freeing the connection lets the client's next Initial create a second connection that gets refused again. under load that lost 4 of 160 refusals at the per-source cap and 12 of 100 at the global cap. a refused connection is now kept until its handshake is complete and then closed with the DoQ code in a 1-RTT packet. at most 16 are kept, each for about 2 s at most, beyond that it falls back to the immediate close
independent of #3372, both touch doq_server.c but merge cleanly. #3234 adds a line at the same place in the thread teardown, whichever lands second keeps both
How to test the change during review
run the two refused-connection tests in dotdoh_server.bats (17th connection from one address, 65th overall), both expect the kept connections open and close code 4
Additional information
Related issue or feature (if applicable): N/A
Pull request in docs with documentation (if applicable): N/A
By submitting this pull request, I confirm the following:
git rebase)src/dnsmasq/. That tree is a verbatim copy of upstream dnsmasq and we do not carry anything in it that deviates from upstream. Fixes have to go through thednsmasq-discussmailing list first, we merge them once they are in dnsmasq master.Checklist:
developmentbranch.