mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
simpler ptr loop check.
git-svn-id: file:///svn/unbound/trunk@984 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
fb1bdb8ee0
commit
fa368eff78
2 changed files with 6 additions and 19 deletions
|
|
@ -5,6 +5,8 @@
|
||||||
profile reports.
|
profile reports.
|
||||||
- default is now minievent - not libevent. As its faster and
|
- default is now minievent - not libevent. As its faster and
|
||||||
not needed for regular installs, only for very large port ranges.
|
not needed for regular installs, only for very large port ranges.
|
||||||
|
- loop check different speedup pkt-dname-reading, 1% faster for
|
||||||
|
nocache-recursion check.
|
||||||
|
|
||||||
21 February 2008: Wouter
|
21 February 2008: Wouter
|
||||||
- speedup of root-delegation message encoding by 15%.
|
- speedup of root-delegation message encoding by 15%.
|
||||||
|
|
|
||||||
|
|
@ -145,34 +145,19 @@ query_dname_tolower(uint8_t* dname)
|
||||||
|
|
||||||
/** maximum compression pointer position pointed to */
|
/** maximum compression pointer position pointed to */
|
||||||
#define MAX_COMPRESS_POS 16384
|
#define MAX_COMPRESS_POS 16384
|
||||||
/** size of bitmap for loop detection */
|
/** max number of compression ptrs to follow */
|
||||||
#define LOOP_BITMAP_SIZE (MAX_COMPRESS_POS/8)
|
#define MAX_COMPRESS_PTRS 256
|
||||||
|
|
||||||
/** check bit in bitmap for loop detection, then set it for next check */
|
|
||||||
static uint8_t
|
|
||||||
loopcheck(uint8_t loop[], size_t pos)
|
|
||||||
{
|
|
||||||
const uint8_t bits[8] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80};
|
|
||||||
uint8_t ret;
|
|
||||||
log_assert(pos < MAX_COMPRESS_POS);
|
|
||||||
ret = loop[ pos / 8 ] & bits[ pos & 0x7 ];
|
|
||||||
loop[ pos / 8 ] |= bits[ pos & 0x7 ];
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
pkt_dname_len(ldns_buffer* pkt)
|
pkt_dname_len(ldns_buffer* pkt)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
uint8_t loop[LOOP_BITMAP_SIZE]; /* loopcheck array. */
|
int ptrcount = 0;
|
||||||
uint8_t labellen;
|
uint8_t labellen;
|
||||||
size_t endpos = 0;
|
size_t endpos = 0;
|
||||||
|
|
||||||
/* read dname and determine length */
|
/* read dname and determine length */
|
||||||
/* check compression pointers, loops, out of bounds */
|
/* check compression pointers, loops, out of bounds */
|
||||||
memset(loop, 0, sizeof(loop));
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
/* read next label */
|
/* read next label */
|
||||||
if(ldns_buffer_remaining(pkt) < 1)
|
if(ldns_buffer_remaining(pkt) < 1)
|
||||||
|
|
@ -184,7 +169,7 @@ pkt_dname_len(ldns_buffer* pkt)
|
||||||
if(ldns_buffer_remaining(pkt) < 1)
|
if(ldns_buffer_remaining(pkt) < 1)
|
||||||
return 0;
|
return 0;
|
||||||
ptr = PTR_OFFSET(labellen, ldns_buffer_read_u8(pkt));
|
ptr = PTR_OFFSET(labellen, ldns_buffer_read_u8(pkt));
|
||||||
if(loopcheck(loop, ptr))
|
if(ptrcount++ > MAX_COMPRESS_PTRS)
|
||||||
return 0; /* loop! */
|
return 0; /* loop! */
|
||||||
if(ldns_buffer_limit(pkt) <= ptr)
|
if(ldns_buffer_limit(pkt) <= ptr)
|
||||||
return 0; /* out of bounds! */
|
return 0; /* out of bounds! */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue