mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
dname isroot and dellabel
git-svn-id: file:///svn/unbound/trunk@492 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
44560e40ea
commit
4eaa855db9
6 changed files with 77 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
|||
6 August 2007: Wouter
|
||||
- key cache for validator.
|
||||
- moved isroot and dellabel to own dname routines, with unit test.
|
||||
|
||||
3 August 2007: Wouter
|
||||
- replanning.
|
||||
|
|
|
|||
|
|
@ -643,11 +643,9 @@ processInitRequest(struct module_qstate* qstate, struct iter_qstate* iq,
|
|||
delnamelen = iq->qchase.qname_len;
|
||||
}
|
||||
if((iq->qchase.qtype == LDNS_RR_TYPE_DS || iq->refetch_glue)
|
||||
&& delname[0] != 0) {
|
||||
&& !dname_is_root(delname)) {
|
||||
/* do not adjust root label, remove first label from delname */
|
||||
size_t lablen = delname[0] + 1;
|
||||
delname += lablen;
|
||||
delnamelen -= lablen;
|
||||
dname_remove_label(&delname, &delnamelen);
|
||||
}
|
||||
|
||||
/* Lookup the delegation in the cache. If null, then the cache needs
|
||||
|
|
|
|||
|
|
@ -433,6 +433,36 @@ dname_test_strict_subdomain()
|
|||
(uint8_t*)"\007example\003org", 3));
|
||||
}
|
||||
|
||||
/** test dname_is_root */
|
||||
static void
|
||||
dname_test_isroot()
|
||||
{
|
||||
unit_assert(dname_is_root((uint8_t*)"\000"));
|
||||
unit_assert(!dname_is_root((uint8_t*)"\001a\000"));
|
||||
unit_assert(!dname_is_root((uint8_t*)"\005abvcd\003com\000"));
|
||||
/* malformed dname in this test, but should work */
|
||||
unit_assert(!dname_is_root((uint8_t*)"\077a\000"));
|
||||
unit_assert(dname_is_root((uint8_t*)"\000"));
|
||||
}
|
||||
|
||||
/** test dname_remove_label */
|
||||
static void
|
||||
dname_test_removelabel()
|
||||
{
|
||||
uint8_t* orig = (uint8_t*)"\007example\003com\000";
|
||||
uint8_t* n = orig;
|
||||
size_t l = 13;
|
||||
dname_remove_label(&n, &l);
|
||||
unit_assert( n == orig+8 );
|
||||
unit_assert( l == 5 );
|
||||
dname_remove_label(&n, &l);
|
||||
unit_assert( n == orig+12 );
|
||||
unit_assert( l == 1 );
|
||||
dname_remove_label(&n, &l);
|
||||
unit_assert( n == orig+12 );
|
||||
unit_assert( l == 1 );
|
||||
}
|
||||
|
||||
void dname_test()
|
||||
{
|
||||
ldns_buffer* buff = ldns_buffer_new(65800);
|
||||
|
|
@ -446,5 +476,7 @@ void dname_test()
|
|||
dname_test_pkt_dname_len(buff);
|
||||
dname_test_strict_subdomain();
|
||||
dname_test_subdomain();
|
||||
dname_test_isroot();
|
||||
dname_test_removelabel();
|
||||
ldns_buffer_free(buff);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -571,3 +571,27 @@ dname_subdomain_c(uint8_t* d1, uint8_t* d2)
|
|||
}
|
||||
return (m == labs2);
|
||||
}
|
||||
|
||||
int
|
||||
dname_is_root(uint8_t* dname)
|
||||
{
|
||||
uint8_t len;
|
||||
log_assert(dname);
|
||||
len = dname[0];
|
||||
log_assert(!LABEL_IS_PTR(len));
|
||||
return (len == 0);
|
||||
}
|
||||
|
||||
void
|
||||
dname_remove_label(uint8_t** dname, size_t* len)
|
||||
{
|
||||
size_t lablen;
|
||||
log_assert(dname && *dname && len);
|
||||
lablen = (*dname)[0];
|
||||
log_assert(!LABEL_IS_PTR(lablen));
|
||||
log_assert(*len > lablen);
|
||||
if(lablen == 0)
|
||||
return; /* do not modify root label */
|
||||
*len -= lablen+1;
|
||||
*dname += lablen+1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,4 +207,19 @@ void dname_print(FILE* out, ldns_buffer* pkt, uint8_t* dname);
|
|||
*/
|
||||
void dname_str(uint8_t* dname, char* str);
|
||||
|
||||
/**
|
||||
* Returns true if the uncompressed wireformat dname is the root "."
|
||||
* @param dname: the dname to check
|
||||
* @return true if ".", false if not.
|
||||
*/
|
||||
int dname_is_root(uint8_t* dname);
|
||||
|
||||
/**
|
||||
* Snip off first label from a dname, returning the parent zone.
|
||||
* @param dname: from what to strip off. uncompressed wireformat.
|
||||
* @param len: length, adjusted to become less.
|
||||
* @return stripped off, or "." if input was ".".
|
||||
*/
|
||||
void dname_remove_label(uint8_t** dname, size_t* len);
|
||||
|
||||
#endif /* UTIL_DATA_DNAME_H */
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#include "validator/val_kentry.h"
|
||||
#include "util/log.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/data/dname.h"
|
||||
|
||||
struct key_cache*
|
||||
key_cache_create(struct config_file* cfg)
|
||||
|
|
@ -140,10 +141,9 @@ key_cache_obtain(struct key_cache* kcache, uint8_t* name, size_t namelen,
|
|||
lock_rw_unlock(&k->entry.lock);
|
||||
}
|
||||
/* snip off first label to continue */
|
||||
if(name[0] == 0 || namelen <= 1)
|
||||
if(dname_is_root(name))
|
||||
break;
|
||||
namelen -= (size_t)name[0] + 1;
|
||||
name += (size_t)name[0] + 1;
|
||||
dname_remove_label(&name, &namelen);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue