2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Simplify and speed up DNS name compression

All we need for compression is a very small hash set of compression
offsets, because most of the information we need (the previously added
names) can be found in the message using the compression offsets.

This change combines dns_compress_find() and dns_compress_add() into
one function dns_compress_name() that both finds any existing suffix,
and adds any new prefix to the table. The old split led to performance
problems caused by duplicate names in the compression context.

Compression contexts are now either small or large, which the caller
chooses depending on the expected size of the message. There is no
dynamic resizing.

There is a behaviour change: compression now acts on all the labels in
each name, instead of just the last few.

A small benchmark suggests this is about 2x faster.
This commit is contained in:
Tony Finch
2022-06-23 21:53:46 +01:00
committed by Ondřej Surý
parent a00333d0d8
commit 45b2d8938b
24 changed files with 520 additions and 669 deletions

View File

@@ -464,6 +464,7 @@ ns_client_send(ns_client_t *client) {
isc_buffer_t buffer = { .magic = 0 };
isc_region_t r;
dns_compress_t cctx;
unsigned int compflags;
bool cleanup_cctx = false;
unsigned int render_opts;
unsigned int preferred_glue;
@@ -531,11 +532,7 @@ ns_client_send(ns_client_t *client) {
}
client_allocsendbuf(client, &buffer, &data);
result = dns_compress_init(&cctx, client->manager->mctx);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
compflags = 0;
if (client->peeraddr_valid && client->view != NULL) {
isc_netaddr_t netaddr;
dns_name_t *name = NULL;
@@ -549,13 +546,14 @@ ns_client_send(ns_client_t *client) {
!dns_acl_allowed(&netaddr, name,
client->view->nocasecompress, env))
{
dns_compress_setsensitive(&cctx, true);
compflags |= DNS_COMPRESS_CASE;
}
if (!client->view->msgcompression) {
dns_compress_disable(&cctx);
compflags = DNS_COMPRESS_DISABLED;
}
}
dns_compress_init(&cctx, client->manager->mctx, compflags);
cleanup_cctx = true;
result = dns_message_renderbegin(client->message, &cctx, &buffer);