Skip to content

Conversation

@jagerman
Copy link
Member

@jagerman jagerman commented Nov 8, 2025

This implements DNS name compression (see the decription added in dns/encode.cpp encode_name() for details).

This reduces the sizes of nearly all query responses (because every response answer includes the question, and then uses the name again for the response), and in some cases significantly so.

This is rather important for Session Router all of our names are 52 byte pubkeys (plus the 4 or 5 byte tld), and so we are potentially running up against the DNS 512-byte max message size.

(We should also enable EDNS to allow longer messages, but that is left here as a FIXME and not yet implemented).

An example shows how the compression helps:

For example, an AAAA query for localhost.sesh responds with an answer of:

;; QUESTION SECTION:
;localhost.sesh.			IN	AAAA

;; ANSWER SECTION:
localhost.sesh.		10	IN	CNAME	sh6tnpf84s885m8ygsjw7g8qjuo1jk7ydufiog8sjdtgkhb3w8iy.sesh.
sh6tnpf84s885m8ygsjw7g8qjuo1jk7ydufiog8sjdtgkhb3w8iy.sesh. 10 IN AAAA fd2e:7365:7368::1

The repeated question doesn't compress anything, of course, but once you hit the answer, you start getting savings:

The repeated localhost.sesh in the first answer gets compressed from 16 bytes (without compression) to a 2 byte pointer (back to the same address in the question).

The first PUBKEY.sesh (in the CNAME target) gets slightly reduced by being able to encode the trailing sesh from 6 bytes uncompressed (4+"sesh"+\0) to a 2-byte pointer (again back
into the question, pointing just at the sesh tld rather than the entire lokinet.sesh value).

The pubkey.sesh. in the second answers gets hugely reduced: an uncompressed 59 bytes (52+"pubkey"+4+"sesh"+0) becomes a simple 2-byte pointer to the same name in the previous answer line.

For some queries like SRV records the savings are even potentially even larger, especially when there are multiple SRV entries for a .sesh address.

Edit: and EDNS support!

EDNS support (including DNS cookies) wasn't too difficult, so I added that here too.

This implements DNS name compression (see the decription added in
dns/encode.cpp `encode_name()` for details).

This reduces the sizes of nearly all query responses
(because every response answer includes the question, and then uses the
name again for the response), and in some cases significantly so.

This is rather important for Session Router all of our names are 52 byte
pubkeys (plus the 4 or 5 byte tld), and so we are potentially running up
against the DNS 512-byte max message size.

(We should also enable EDNS to allow longer messages, but that is left
here as a FIXME and not yet implemented).

An example shows how the compression helps:

For example, an AAAA query for `localhost.sesh` responds with an answer
of:

    ;; QUESTION SECTION:
    ;localhost.sesh.			IN	AAAA

    ;; ANSWER SECTION:
    localhost.sesh.		10	IN	CNAME	sh6tnpf84s885m8ygsjw7g8qjuo1jk7ydufiog8sjdtgkhb3w8iy.sesh.
    sh6tnpf84s885m8ygsjw7g8qjuo1jk7ydufiog8sjdtgkhb3w8iy.sesh. 10 IN AAAA fd2e:7365:7368::1

The repeated question doesn't compress anything, of course, but once you
hit the answer, you start getting savings:

The repeated `localhost.sesh` in the first answer gets compressed from
16 bytes (without compression) to a 2 byte pointer (back to the same
address in the question).

The first PUBKEY.sesh (in the CNAME target) gets slightly reduced by
being able to encode the trailing `sesh` from 6 bytes uncompressed
(4+"sesh"+\0) to a 2-byte pointer (again back
into the question, pointing just at the sesh tld rather than the entire
lokinet.sesh value).

The pubkey.sesh. in the second answers gets hugely reduced: an
uncompressed 59 bytes (52+"pubkey"+4+"sesh"+0) becomes a simple 2-byte
pointer to the same name in the previous answer line.

For some queries like SRV records the savings are even potentially even
larger, especially when there are multiple SRV entries for a .sesh
address.
An empty name was getting encoded as two \0's instead of just one.
This adds support for EDNS requests, allowing for larger responses.  As
part of that, it adds support for handling DNS cookies, which are a sort
of pseudo-mac over DNS requests to prevent out-of-path attackers from
being able to forge responses.
@jagerman jagerman changed the title Implement DNS name compression Implement DNS name compression & EDNS Nov 11, 2025
@jagerman
Copy link
Member Author

Closing (included in #20)

@jagerman jagerman closed this Nov 19, 2025
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.

1 participant