]> git.ipfire.org Git - thirdparty/bind9.git/commit
Simplify and speed up DNS name decompression
authorTony Finch <fanf@isc.org>
Mon, 7 Nov 2022 14:00:45 +0000 (14:00 +0000)
committerTony Finch <dot@dotat.at>
Thu, 17 Nov 2022 08:45:15 +0000 (08:45 +0000)
commit1c0f6078116607075a375e9c75304551ebd2fd44
tree2c66dd266caaeae57002e6e6d826464afa1f9f62
parente0c969234174e3c3d93016ea4a12a1c467df0698
Simplify and speed up DNS name decompression

The aim is to do less work per byte:

  * Check the bounds for each label, instead of checking the
    bounds for each character.

  * Instead of copying one character at a time from the wire to
    the name, copy entire runs of sequential labels using memmove()
    to make the most of its fast loop.

  * To remember where the name ends, we only need to set the end
    marker when we see a compression pointer or when we reach the
    root label. There is no need to check if we jumped back and
    conditionally update the counter for every character.

  * To parse a compression pointer, we no longer take a diversion
    around the outer loop in between reading the upper byte of the
    pointer and the lower byte.

  * The parser state machine is now implicit in the instruction
    pointer, instead of being an explicit variable. Similarly,
    when we reach the root label we break directly out of the loop
    instead of setting a second state machine variable.

  * DNS_NAME_DOWNCASE is never used with dns_name_fromwire() so
    that option is no longer supported.

I have removed this comment which dated from January 1999 when
dns_name_fromwire() was first introduced:

   /*
    * Note:  The following code is not optimized for speed, but
    * rather for correctness.  Speed will be addressed in the future.
    */

No functional change, apart from removing support for the unused
DNS_NAME_DOWNCASE option. The new code is about 2x faster than the
old code: best case 11x faster, worst case 1.4x faster.
CHANGES
lib/dns/include/dns/name.h
lib/dns/name.c