fixup CNAME generated by scrubber.

git-svn-id: file:///svn/unbound/trunk@403 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-06-20 08:55:00 +00:00
parent 1c80108a5b
commit 9c33f8dcf4
5 changed files with 19 additions and 5 deletions

View file

@ -1,6 +1,7 @@
20 June 2007: Wouter 20 June 2007: Wouter
- new -C option to enable coredumps after forking away. - new -C option to enable coredumps after forking away.
- doc update. - doc update.
- fixup CNAME generation by scrubber, and memory allocation of it.
19 June 2007: Wouter 19 June 2007: Wouter
- nicer layout in stats.c, review 0.3 change. - nicer layout in stats.c, review 0.3 change.

View file

@ -248,6 +248,7 @@ synth_cname_rrset(uint8_t** sname, size_t* snamelen, uint8_t* alias,
cn->hash=pkt_hash_rrset(pkt, cn->dname, cn->type, cn->rrset_class, 0); cn->hash=pkt_hash_rrset(pkt, cn->dname, cn->type, cn->rrset_class, 0);
/* allocate TTL + rdatalen + uncompressed dname */ /* allocate TTL + rdatalen + uncompressed dname */
memset(cn->rr_first, 0, sizeof(struct rr_parse)); memset(cn->rr_first, 0, sizeof(struct rr_parse));
cn->rr_first->outside_packet = 1;
cn->rr_first->ttl_data = (uint8_t*)region_alloc(region, cn->rr_first->ttl_data = (uint8_t*)region_alloc(region,
sizeof(uint32_t)+sizeof(uint16_t)+aliaslen); sizeof(uint32_t)+sizeof(uint16_t)+aliaslen);
if(!cn->rr_first->ttl_data) if(!cn->rr_first->ttl_data)
@ -361,7 +362,7 @@ scrub_normalize(ldns_buffer* pkt, struct msg_parse* msg,
} }
/* synth a CNAME rrset */ /* synth a CNAME rrset */
prev = synth_cname_rrset(&sname, &snamelen, alias, prev = synth_cname_rrset(&sname, &snamelen, alias,
aliaslen, region, msg, rrset, prev, nx, pkt); aliaslen, region, msg, rrset, rrset, nx, pkt);
if(!prev) { if(!prev) {
log_err("out of memory synthesizing CNAME"); log_err("out of memory synthesizing CNAME");
return 0; return 0;

View file

@ -314,6 +314,7 @@ moveover_rrsigs(ldns_buffer* pkt, region_type* region,
/* new */ /* new */
insert = (struct rr_parse*)region_alloc(region, insert = (struct rr_parse*)region_alloc(region,
sizeof(struct rr_parse)); sizeof(struct rr_parse));
insert->outside_packet = 0;
insert->ttl_data = sig->ttl_data; insert->ttl_data = sig->ttl_data;
insert->size = sig->size; insert->size = sig->size;
} else { } else {
@ -718,6 +719,7 @@ add_rr_to_rrset(struct rrset_parse* rrset, ldns_buffer* pkt,
/* create rr */ /* create rr */
if(!(rr = (struct rr_parse*)region_alloc(region, sizeof(*rr)))) if(!(rr = (struct rr_parse*)region_alloc(region, sizeof(*rr))))
return LDNS_RCODE_SERVFAIL; return LDNS_RCODE_SERVFAIL;
rr->outside_packet = 0;
rr->ttl_data = ldns_buffer_current(pkt); rr->ttl_data = ldns_buffer_current(pkt);
rr->next = 0; rr->next = 0;
if(type == LDNS_RR_TYPE_RRSIG && rrset->type != LDNS_RR_TYPE_RRSIG) { if(type == LDNS_RR_TYPE_RRSIG && rrset->type != LDNS_RR_TYPE_RRSIG) {

View file

@ -171,6 +171,9 @@ struct rr_parse {
* its dname, type and class are the same and stored for the rrset. * its dname, type and class are the same and stored for the rrset.
*/ */
uint8_t* ttl_data; uint8_t* ttl_data;
/** true if ttl_data is not part of the packet, but elsewhere in mem.
* Set for generated CNAMEs for DNAMEs. */
int outside_packet;
/** the length of the rdata if allocated (with no dname compression)*/ /** the length of the rdata if allocated (with no dname compression)*/
size_t size; size_t size;
/** next in list of RRs. */ /** next in list of RRs. */

View file

@ -148,15 +148,22 @@ rdata_copy(ldns_buffer* pkt, struct packed_rrset_data* data, uint8_t* to,
{ {
uint16_t pkt_len; uint16_t pkt_len;
const ldns_rr_descriptor* desc; const ldns_rr_descriptor* desc;
ldns_buffer_set_position(pkt, (size_t)
(rr->ttl_data - ldns_buffer_begin(pkt))); *rr_ttl = ldns_read_uint32(rr->ttl_data);
log_assert(ldns_buffer_remaining(pkt) >= 6 /* ttl + rdatalen */);
*rr_ttl = ldns_buffer_read_u32(pkt);
/* RFC 2181 Section 8. if msb of ttl is set treat as if zero. */ /* RFC 2181 Section 8. if msb of ttl is set treat as if zero. */
if(*rr_ttl & 0x80000000U) if(*rr_ttl & 0x80000000U)
*rr_ttl = 0; *rr_ttl = 0;
if(*rr_ttl < data->ttl) if(*rr_ttl < data->ttl)
data->ttl = *rr_ttl; data->ttl = *rr_ttl;
if(rr->outside_packet) {
/* uncompressed already, only needs copy */
memmove(to, rr->ttl_data+sizeof(uint32_t), rr->size);
return 1;
}
ldns_buffer_set_position(pkt, (size_t)
(rr->ttl_data - ldns_buffer_begin(pkt) + sizeof(uint32_t)));
/* insert decompressed size into rdata len stored in memory */ /* insert decompressed size into rdata len stored in memory */
/* -2 because rdatalen bytes are not included. */ /* -2 because rdatalen bytes are not included. */
pkt_len = htons(rr->size - 2); pkt_len = htons(rr->size - 2);