#include "util/config_file.h"
#include "util/module.h"
#include "util/net_help.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "iterator/iterator.h"
#include "validator/validator.h"
#include <pwd.h>
struct module_env env;
memset(&env, 0, sizeof(env));
env.cfg = cfg;
- env.scratch = region_create(malloc, free);
+ env.scratch = regional_create();
env.scratch_buffer = ldns_buffer_new(BUFSIZ);
+ if(!env.scratch || !env.scratch_buffer)
+ fatal_exit("out of memory");
if(!(*fb->init)(&env, 0)) {
fatal_exit("bad config for %s module", fb->name);
}
(*fb->deinit)(&env, 0);
ldns_buffer_free(env.scratch_buffer);
- region_destroy(env.scratch);
+ regional_destroy(env.scratch);
}
/** check configuration for errors */
#include "util/netevent.h"
#include "util/config_file.h"
#include "util/module.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/storage/slabhash.h"
#include "services/listen_dnsport.h"
#include "services/outside_network.h"
(&worker->env, i);
}
me = sizeof(*worker) + sizeof(*worker->base) + sizeof(*worker->comsig)
- + comm_point_get_mem(worker->cmd_com) +
- sizeof(worker->rndstate) + region_get_mem(worker->scratchpad)+
- sizeof(*worker->env.scratch_buffer) +
- ldns_buffer_capacity(worker->env.scratch_buffer);
+ + comm_point_get_mem(worker->cmd_com)
+ + sizeof(worker->rndstate)
+ + regional_get_mem(worker->scratchpad)
+ + sizeof(*worker->env.scratch_buffer)
+ + ldns_buffer_capacity(worker->env.scratch_buffer);
if(cur_serv) {
me += serviced_get_mem(cur_serv);
}
qinfo->qname_len, qinfo->qtype, qinfo->qclass,
worker->scratchpad, &msg, timenow);
if(!dp) { /* no delegation, need to reprime */
- region_free_all(worker->scratchpad);
+ regional_free_all(worker->scratchpad);
return 0;
}
if(must_validate) {
case sec_status_unchecked:
/* some rrsets have not been verified yet, go and
* let validator do that */
- region_free_all(worker->scratchpad);
+ regional_free_all(worker->scratchpad);
return 0;
case sec_status_bogus:
/* some rrsets are bogus, reply servfail */
edns->bits &= EDNS_DO;
error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
&msg->qinfo, id, flags, edns);
- region_free_all(worker->scratchpad);
+ regional_free_all(worker->scratchpad);
return 1;
case sec_status_secure:
/* all rrsets are secure */
error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
&msg->qinfo, id, flags, edns);
}
- region_free_all(worker->scratchpad);
+ regional_free_all(worker->scratchpad);
return 1;
}
bail_out:
rrset_array_unlock_touch(worker->env.rrset_cache,
worker->scratchpad, rep->ref, rep->rrset_count);
- region_free_all(worker->scratchpad);
+ regional_free_all(worker->scratchpad);
return 0;
}
}
&mrentry->key, id, flags, edns);
rrset_array_unlock_touch(worker->env.rrset_cache,
worker->scratchpad, rep->ref, rep->rrset_count);
- region_free_all(worker->scratchpad);
+ regional_free_all(worker->scratchpad);
return 1;
} else if( rep->security == sec_status_unchecked && must_validate) {
verbose(VERB_ALGO, "Cache reply: unchecked entry needs "
* is bad while holding locks. */
rrset_array_unlock_touch(worker->env.rrset_cache, worker->scratchpad,
rep->ref, rep->rrset_count);
- region_free_all(worker->scratchpad);
+ regional_free_all(worker->scratchpad);
/* go and return this buffer to the client */
return 1;
}
}
/* we use the msg_buffer_size as a good estimate for what the
* user wants for memory usage sizes */
- worker->scratchpad = region_create_custom(malloc, free,
- cfg->msg_buffer_size, cfg->msg_buffer_size/4, 32, 1);
+ worker->scratchpad = regional_create_custom(cfg->msg_buffer_size);
if(!worker->scratchpad) {
log_err("malloc failure");
worker_delete(worker);
close(worker->cmd_recv_fd);
worker->cmd_recv_fd = -1;
alloc_clear(&worker->alloc);
- region_destroy(worker->scratchpad);
+ regional_destroy(worker->scratchpad);
free(worker);
}
struct module_qstate* q)
{
struct worker* worker = q->env->worker;
- struct outbound_entry* e = (struct outbound_entry*)region_alloc(
+ struct outbound_entry* e = (struct outbound_entry*)regional_alloc(
q->region, sizeof(*e));
if(!e)
return NULL;
struct daemon;
struct listen_port;
struct ub_randstate;
-struct region;
+struct regional;
/** size of table used for random numbers. large to be more secure. */
#define RND_STATE_SIZE 256
struct alloc_cache alloc;
/** per thread statistics */
struct server_stats stats;
- /** thread scratch region */
- struct region* scratchpad;
+ /** thread scratch regional */
+ struct regional* scratchpad;
/** module environment passed to modules, changed for this thread */
struct module_env env;
- ldns-src.tar.gz is used if no ldns is found on the system, and
statically linked into unbound.
- start of regional allocator code.
+ - regional uses less memory and variables, simplified code.
+ - remove of region-allocator.
17 October 2007: Wouter
- fixup another cycle detect and ns-addr timeout resolution bug.
#include "config.h"
#include "iterator/iter_delegpt.h"
#include "services/cache/dns.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/data/dname.h"
#include "util/data/packed_rrset.h"
#include "util/data/msgreply.h"
#include "util/net_help.h"
struct delegpt*
-delegpt_create(struct region* region)
+delegpt_create(struct regional* region)
{
- struct delegpt* dp=(struct delegpt*)region_alloc(region, sizeof(*dp));
+ struct delegpt* dp=(struct delegpt*)regional_alloc(
+ region, sizeof(*dp));
if(!dp)
return NULL;
memset(dp, 0, sizeof(*dp));
return dp;
}
-struct delegpt* delegpt_copy(struct delegpt* dp, struct region* region)
+struct delegpt* delegpt_copy(struct delegpt* dp, struct regional* region)
{
struct delegpt* copy = delegpt_create(region);
struct delegpt_ns* ns;
}
int
-delegpt_set_name(struct delegpt* dp, struct region* region, uint8_t* name)
+delegpt_set_name(struct delegpt* dp, struct regional* region, uint8_t* name)
{
dp->namelabs = dname_count_size_labels(name, &dp->namelen);
- dp->name = region_alloc_init(region, name, dp->namelen);
+ dp->name = regional_alloc_init(region, name, dp->namelen);
return dp->name != 0;
}
int
-delegpt_add_ns(struct delegpt* dp, struct region* region, uint8_t* name)
+delegpt_add_ns(struct delegpt* dp, struct regional* region, uint8_t* name)
{
struct delegpt_ns* ns;
size_t len;
* adding the same server as a dependency twice */
if(delegpt_find_ns(dp, name, len))
return 1;
- ns = (struct delegpt_ns*)region_alloc(region,
+ ns = (struct delegpt_ns*)regional_alloc(region,
sizeof(struct delegpt_ns));
if(!ns)
return 0;
ns->next = dp->nslist;
ns->namelen = len;
dp->nslist = ns;
- ns->name = region_alloc_init(region, name, ns->namelen);
+ ns->name = regional_alloc_init(region, name, ns->namelen);
ns->resolved = 0;
return 1;
}
}
int
-delegpt_add_target(struct delegpt* dp, struct region* region,
+delegpt_add_target(struct delegpt* dp, struct regional* region,
uint8_t* name, size_t namelen, struct sockaddr_storage* addr,
socklen_t addrlen)
{
}
int
-delegpt_add_addr(struct delegpt* dp, struct region* region,
+delegpt_add_addr(struct delegpt* dp, struct regional* region,
struct sockaddr_storage* addr, socklen_t addrlen)
{
- struct delegpt_addr* a = (struct delegpt_addr*)region_alloc(region,
+ struct delegpt_addr* a = (struct delegpt_addr*)regional_alloc(region,
sizeof(struct delegpt_addr));
if(!a)
return 0;
}
struct delegpt*
-delegpt_from_message(struct dns_msg* msg, struct region* region)
+delegpt_from_message(struct dns_msg* msg, struct regional* region)
{
struct ub_packed_rrset_key* ns_rrset = NULL;
struct delegpt* dp;
}
int
-delegpt_rrset_add_ns(struct delegpt* dp, struct region* region,
+delegpt_rrset_add_ns(struct delegpt* dp, struct regional* region,
struct ub_packed_rrset_key* ns_rrset)
{
struct packed_rrset_data* nsdata = (struct packed_rrset_data*)
}
int
-delegpt_add_rrset_A(struct delegpt* dp, struct region* region,
+delegpt_add_rrset_A(struct delegpt* dp, struct regional* region,
struct ub_packed_rrset_key* ak)
{
struct packed_rrset_data* d=(struct packed_rrset_data*)ak->entry.data;
}
int
-delegpt_add_rrset_AAAA(struct delegpt* dp, struct region* region,
+delegpt_add_rrset_AAAA(struct delegpt* dp, struct regional* region,
struct ub_packed_rrset_key* ak)
{
struct packed_rrset_data* d=(struct packed_rrset_data*)ak->entry.data;
}
int
-delegpt_add_rrset(struct delegpt* dp, struct region* region,
+delegpt_add_rrset(struct delegpt* dp, struct regional* region,
struct ub_packed_rrset_key* rrset)
{
if(!rrset)
#ifndef ITERATOR_ITER_DELEGPT_H
#define ITERATOR_ITER_DELEGPT_H
#include "util/log.h"
-struct region;
+struct regional;
struct delegpt_ns;
struct delegpt_addr;
struct dns_msg;
/**
* Create new delegation point.
- * @param region: where to allocate it.
+ * @param regional: where to allocate it.
* @return new delegation point or NULL on error.
*/
-struct delegpt* delegpt_create(struct region* region);
+struct delegpt* delegpt_create(struct regional* regional);
/**
* Create a copy of a delegation point.
* @param dp: delegation point to copy.
- * @param region: where to allocate it.
+ * @param regional: where to allocate it.
* @return new delegation point or NULL on error.
*/
-struct delegpt* delegpt_copy(struct delegpt* dp, struct region* region);
+struct delegpt* delegpt_copy(struct delegpt* dp, struct regional* regional);
/**
* Set name of delegation point.
* @param dp: delegation point.
- * @param region: where to allocate the name copy.
+ * @param regional: where to allocate the name copy.
* @param name: name to use.
* @return false on error.
*/
-int delegpt_set_name(struct delegpt* dp, struct region* region, uint8_t* name);
+int delegpt_set_name(struct delegpt* dp, struct regional* regional,
+ uint8_t* name);
/**
* Add a name to the delegation point.
* @param dp: delegation point.
- * @param region: where to allocate the info.
+ * @param regional: where to allocate the info.
* @param name: domain name in wire format.
* @return false on error.
*/
-int delegpt_add_ns(struct delegpt* dp, struct region* region, uint8_t* name);
+int delegpt_add_ns(struct delegpt* dp, struct regional* regional,
+ uint8_t* name);
/**
* Add NS rrset; calls add_ns repeatedly.
* @param dp: delegation point.
- * @param region: where to allocate the info.
+ * @param regional: where to allocate the info.
* @param ns_rrset: NS rrset.
* return 0 on alloc error.
*/
-int delegpt_rrset_add_ns(struct delegpt* dp, struct region* region,
+int delegpt_rrset_add_ns(struct delegpt* dp, struct regional* regional,
struct ub_packed_rrset_key* ns_rrset);
/**
* Add target address to the delegation point.
* @param dp: delegation point.
- * @param region: where to allocate the info.
+ * @param regional: where to allocate the info.
* @param name: name for which target was found (must be in nslist).
* This name is marked resolved.
* @param namelen: length of name.
* @param addrlen: the length of addr.
* @return false on error.
*/
-int delegpt_add_target(struct delegpt* dp, struct region* region,
+int delegpt_add_target(struct delegpt* dp, struct regional* regional,
uint8_t* name, size_t namelen, struct sockaddr_storage* addr,
socklen_t addrlen);
/**
* Add A RRset to delegpt.
* @param dp: delegation point.
- * @param region: where to allocate the info.
+ * @param regional: where to allocate the info.
* @param rrset: RRset A to add.
* @return 0 on alloc error.
*/
-int delegpt_add_rrset_A(struct delegpt* dp, struct region* region,
+int delegpt_add_rrset_A(struct delegpt* dp, struct regional* regional,
struct ub_packed_rrset_key* rrset);
/**
* Add AAAA RRset to delegpt.
* @param dp: delegation point.
- * @param region: where to allocate the info.
+ * @param regional: where to allocate the info.
* @param rrset: RRset AAAA to add.
* @return 0 on alloc error.
*/
-int delegpt_add_rrset_AAAA(struct delegpt* dp, struct region* region,
+int delegpt_add_rrset_AAAA(struct delegpt* dp, struct regional* regional,
struct ub_packed_rrset_key* rrset);
/**
* Add any RRset to delegpt.
* @param dp: delegation point.
- * @param region: where to allocate the info.
+ * @param regional: where to allocate the info.
* @param rrset: RRset to add, NS, A, AAAA.
* @return 0 on alloc error.
*/
-int delegpt_add_rrset(struct delegpt* dp, struct region* region,
+int delegpt_add_rrset(struct delegpt* dp, struct regional* regional,
struct ub_packed_rrset_key* rrset);
/**
* Add address to the delegation point. No servername is associated or checked.
* @param dp: delegation point.
- * @param region: where to allocate the info.
+ * @param regional: where to allocate the info.
* @param addr: the address.
* @param addrlen: the length of addr.
* @return false on error.
*/
-int delegpt_add_addr(struct delegpt* dp, struct region* region,
+int delegpt_add_addr(struct delegpt* dp, struct regional* regional,
struct sockaddr_storage* addr, socklen_t addrlen);
/**
* find "glue" in either the ADDITIONAL section or the ANSWER section.
*
* @param msg: the dns message, referral.
- * @param region: where to allocate delegation point.
+ * @param regional: where to allocate delegation point.
* @return new delegation point or NULL on alloc error, or if the
* message was not appropriate.
*/
struct delegpt* delegpt_from_message(struct dns_msg* msg,
- struct region* region);
+ struct regional* regional);
#endif /* ITERATOR_ITER_DELEGPT_H */
*/
#include "config.h"
#include "iterator/iter_donotq.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/log.h"
#include "util/config_file.h"
#include "util/net_help.h"
sizeof(struct iter_donotq));
if(!dq)
return NULL;
- dq->region = region_create(malloc, free);
+ dq->region = regional_create();
if(!dq->region) {
donotq_delete(dq);
return NULL;
{
if(!dq)
return;
- region_destroy(dq->region);
+ regional_destroy(dq->region);
free(dq->tree);
free(dq);
}
donotq_insert(struct iter_donotq* dq, struct sockaddr_storage* addr,
socklen_t addrlen)
{
- struct iter_donotq_addr* node = region_alloc(dq->region,
+ struct iter_donotq_addr* node = regional_alloc(dq->region,
sizeof(struct iter_donotq_addr));
if(!node)
return 0;
donotq_get_mem(struct iter_donotq* donotq)
{
if(!donotq) return 0;
- return sizeof(*donotq) + region_get_mem(donotq->region);
+ return sizeof(*donotq) + regional_get_mem(donotq->region);
}
#include "util/rbtree.h"
struct iter_env;
struct config_file;
-struct region;
+struct regional;
/**
* Iterator donotqueryaddresses structure
*/
struct iter_donotq {
- /** region for allocation */
- struct region* region;
+ /** regional for allocation */
+ struct regional* region;
/**
* Tree of the single addresses that are blocked.
* contents of type iter_donotq_addr.
#include "config.h"
#include "iterator/iter_fwd.h"
#include "iterator/iter_delegpt.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/log.h"
#include "util/config_file.h"
#include "util/net_help.h"
sizeof(struct iter_forwards));
if(!fwd)
return NULL;
- fwd->region = region_create(malloc, free);
+ fwd->region = regional_create();
if(!fwd->region) {
forwards_delete(fwd);
return NULL;
{
if(!fwd)
return;
- region_destroy(fwd->region);
+ regional_destroy(fwd->region);
free(fwd->tree);
free(fwd);
}
static int
forwards_insert(struct iter_forwards* fwd, uint16_t c, struct delegpt* dp)
{
- struct iter_forward_zone* node = region_alloc(fwd->region,
+ struct iter_forward_zone* node = regional_alloc(fwd->region,
sizeof(struct iter_forward_zone));
if(!node)
return 0;
node->node.key = node;
node->dclass = c;
- node->name = region_alloc_init(fwd->region, dp->name, dp->namelen);
+ node->name = regional_alloc_init(fwd->region, dp->name, dp->namelen);
if(!node->name)
return 0;
node->namelen = dp->namelen;
{
if(!fwd)
return 0;
- return sizeof(*fwd) + region_get_mem(fwd->region);
+ return sizeof(*fwd) + regional_get_mem(fwd->region);
}
struct iter_env;
struct config_file;
struct delegpt;
-struct region;
+struct regional;
/**
* Iterator forward zones structure
*/
struct iter_forwards {
- /** region where forward zone server addresses are allocated */
- struct region* region;
+ /** regional where forward zone server addresses are allocated */
+ struct regional* region;
/**
* Zones are stored in this tree. Sort order is specially chosen.
* first sorted on qtype. Then on dname in nsec-like order, so that
#include "config.h"
#include "iterator/iter_hints.h"
#include "iterator/iter_delegpt.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/log.h"
#include "util/config_file.h"
#include "util/net_help.h"
sizeof(struct iter_hints));
if(!hints)
return NULL;
- hints->region = region_create(malloc, free);
+ hints->region = regional_create();
if(!hints->region) {
hints_delete(hints);
return NULL;
{
if(!hints)
return;
- region_destroy(hints->region);
+ regional_destroy(hints->region);
free(hints->tree);
free(hints);
}
/** add hint to delegation hints */
static int
-ah(struct delegpt* dp, struct region* r, const char* sv, const char* ip)
+ah(struct delegpt* dp, struct regional* r, const char* sv, const char* ip)
{
struct sockaddr_storage addr;
socklen_t addrlen;
/** obtain compiletime provided root hints */
static struct delegpt*
-compile_time_root_prime(struct region* r)
+compile_time_root_prime(struct regional* r)
{
/* from:
; This file is made available by InterNIC
static int
hints_insert(struct iter_hints* hints, uint16_t c, struct delegpt* dp)
{
- struct iter_hints_stub* node = region_alloc(hints->region,
+ struct iter_hints_stub* node = regional_alloc(hints->region,
sizeof(struct iter_hints_stub));
if(!node)
return 0;
node->node.key = node;
node->hint_class = c;
- node->name = region_alloc_init(hints->region, dp->name, dp->namelen);
+ node->name = regional_alloc_init(hints->region, dp->name, dp->namelen);
if(!node->name)
return 0;
node->namelen = dp->namelen;
hints_get_mem(struct iter_hints* hints)
{
if(!hints) return 0;
- return sizeof(*hints) + region_get_mem(hints->region);
+ return sizeof(*hints) + regional_get_mem(hints->region);
}
struct iter_env;
struct config_file;
struct delegpt;
-struct region;
+struct regional;
/**
* Iterator hints structure
*/
struct iter_hints {
- /** region where hints are allocated */
- struct region* region;
+ /** regional where hints are allocated */
+ struct regional* region;
/**
* Hints are stored in this tree. Sort order is specially chosen.
* first sorted on qtype. Then on dname in nsec-like order, so that
#include "services/cache/rrset.h"
#include "util/log.h"
#include "util/net_help.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/config_file.h"
#include "util/module.h"
#include "util/data/msgparse.h"
/** synthesize a CNAME rrset */
static struct rrset_parse*
synth_cname_rrset(uint8_t** sname, size_t* snamelen, uint8_t* alias,
- size_t aliaslen, struct region* region, struct msg_parse* msg,
+ size_t aliaslen, struct regional* region, struct msg_parse* msg,
struct rrset_parse* rrset, struct rrset_parse* prev,
struct rrset_parse* nx, ldns_buffer* pkt)
{
- struct rrset_parse* cn = (struct rrset_parse*)region_alloc(region,
+ struct rrset_parse* cn = (struct rrset_parse*)regional_alloc(region,
sizeof(struct rrset_parse));
if(!cn)
return NULL;
memset(cn, 0, sizeof(*cn));
- cn->rr_first = (struct rr_parse*)region_alloc(region,
+ cn->rr_first = (struct rr_parse*)regional_alloc(region,
sizeof(struct rr_parse));
if(!cn->rr_first)
return NULL;
cn->rr_last = cn->rr_first;
/* CNAME from sname to alias */
- cn->dname = (uint8_t*)region_alloc(region, *snamelen);
+ cn->dname = (uint8_t*)regional_alloc(region, *snamelen);
if(!cn->dname)
return NULL;
dname_pkt_copy(pkt, cn->dname, *sname);
/* allocate TTL + rdatalen + uncompressed dname */
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*)regional_alloc(region,
sizeof(uint32_t)+sizeof(uint16_t)+aliaslen);
if(!cn->rr_first->ttl_data)
return NULL;
*/
static int
scrub_normalize(ldns_buffer* pkt, struct msg_parse* msg,
- struct query_info* qinfo, struct region* region)
+ struct query_info* qinfo, struct regional* region)
{
uint8_t* sname = qinfo->qname;
size_t snamelen = qinfo->qname_len;
int
scrub_message(ldns_buffer* pkt, struct msg_parse* msg,
- struct query_info* qinfo, uint8_t* zonename, struct region* region,
+ struct query_info* qinfo, uint8_t* zonename, struct regional* region,
struct module_env* env)
{
/* basic sanity checks */
#define ITERATOR_ITER_SCRUB_H
struct msg_parse;
struct query_info;
-struct region;
+struct regional;
struct module_env;
/**
* @param qinfo: the query info that was sent to the server. Checked.
* @param zonename: the name of the last delegation point.
* Used to determine out of bailiwick information.
- * @param region: where to allocate (new) parts of the message.
+ * @param regional: where to allocate (new) parts of the message.
* @param env: module environment with config settings and cache.
* @return: false if the message is total waste. true if scrubbed with success.
*/
int scrub_message(ldns_buffer* pkt, struct msg_parse* msg,
- struct query_info* qinfo, uint8_t* zonename, struct region* region,
+ struct query_info* qinfo, uint8_t* zonename, struct regional* regional,
struct module_env* env);
#endif /* ITERATOR_ITER_SCRUB_H */
#include "util/module.h"
#include "util/log.h"
#include "util/config_file.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/data/msgparse.h"
#include "util/data/dname.h"
#include "util/random.h"
}
struct dns_msg*
-dns_alloc_msg(ldns_buffer* pkt, struct msg_parse* msg, struct region* region)
+dns_alloc_msg(ldns_buffer* pkt, struct msg_parse* msg,
+ struct regional* region)
{
- struct dns_msg* m = (struct dns_msg*)region_alloc(region,
+ struct dns_msg* m = (struct dns_msg*)regional_alloc(region,
sizeof(struct dns_msg));
if(!m)
return NULL;
}
struct dns_msg*
-dns_copy_msg(struct dns_msg* from, struct region* region)
+dns_copy_msg(struct dns_msg* from, struct regional* region)
{
- struct dns_msg* m = (struct dns_msg*)region_alloc(region,
+ struct dns_msg* m = (struct dns_msg*)regional_alloc(region,
sizeof(struct dns_msg));
if(!m)
return NULL;
m->qinfo = from->qinfo;
- if(!(m->qinfo.qname = region_alloc_init(region, from->qinfo.qname,
+ if(!(m->qinfo.qname = regional_alloc_init(region, from->qinfo.qname,
from->qinfo.qname_len)))
return NULL;
if(!(m->rep = reply_info_copy(from->rep, NULL, region)))
struct module_env;
struct delegpt_addr;
struct delegpt;
-struct region;
+struct regional;
struct msg_parse;
struct ub_randstate;
struct query_info;
size_t namelen);
/**
- * Allocate dns_msg from parsed msg, in region.
+ * Allocate dns_msg from parsed msg, in regional.
* @param pkt: packet.
- * @param msg: parsed message (cleaned and ready for region allocation).
- * @param region: region to use for allocation.
+ * @param msg: parsed message (cleaned and ready for regional allocation).
+ * @param regional: regional to use for allocation.
* @return newly allocated dns_msg, or NULL on memory error.
*/
struct dns_msg* dns_alloc_msg(ldns_buffer* pkt, struct msg_parse* msg,
- struct region* region);
+ struct regional* regional);
/**
- * Copy a dns_msg to this region.
- * @param from: dns message, also in region.
- * @param region: region to use for allocation.
+ * Copy a dns_msg to this regional.
+ * @param from: dns message, also in regional.
+ * @param regional: regional to use for allocation.
* @return newly allocated dns_msg, or NULL on memory error.
*/
-struct dns_msg* dns_copy_msg(struct dns_msg* from, struct region* region);
+struct dns_msg* dns_copy_msg(struct dns_msg* from, struct regional* regional);
/**
* Allocate a dns_msg with malloc/alloc structure and store in dns cache.
#include "util/module.h"
#include "util/netevent.h"
#include "util/net_help.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/data/dname.h"
#include "util/data/msgencode.h"
#include "util/fptr_wlist.h"
static int
iter_new(struct module_qstate* qstate, int id)
{
- struct iter_qstate* iq = (struct iter_qstate*)region_alloc(
+ struct iter_qstate* iq = (struct iter_qstate*)regional_alloc(
qstate->region, sizeof(struct iter_qstate));
qstate->minfo[id] = iq;
if(!iq)
/** prepend the prepend list in the answer and authority section of dns_msg */
static int
iter_prepend(struct iter_qstate* iq, struct dns_msg* msg,
- struct region* region)
+ struct regional* region)
{
struct iter_prep_list* p;
struct ub_packed_rrset_key** sets;
if(num_an + num_ns == 0)
return 1;
verbose(VERB_ALGO, "prepending %d rrsets", (int)num_an + (int)num_ns);
- sets = region_alloc(region, (num_an+num_ns+msg->rep->rrset_count) *
+ sets = regional_alloc(region, (num_an+num_ns+msg->rep->rrset_count) *
sizeof(struct ub_packed_rrset_key*));
if(!sets)
return 0;
iter_add_prepend_answer(struct module_qstate* qstate, struct iter_qstate* iq,
struct ub_packed_rrset_key* rrset)
{
- struct iter_prep_list* p = (struct iter_prep_list*)region_alloc(
+ struct iter_prep_list* p = (struct iter_prep_list*)regional_alloc(
qstate->region, sizeof(struct iter_prep_list));
if(!p)
return 0;
iter_add_prepend_auth(struct module_qstate* qstate, struct iter_qstate* iq,
struct ub_packed_rrset_key* rrset)
{
- struct iter_prep_list* p = (struct iter_prep_list*)region_alloc(
+ struct iter_prep_list* p = (struct iter_prep_list*)regional_alloc(
qstate->region, sizeof(struct iter_prep_list));
if(!p)
return 0;
/* initialise the new subquery */
subq->curmod = id;
subq->ext_state[id] = module_state_initial;
- subq->minfo[id] = region_alloc(subq->region,
+ subq->minfo[id] = regional_alloc(subq->region,
sizeof(struct iter_qstate));
if(!subq->minfo[id]) {
log_err("init subq: out of memory");
}
/* parse message */
- prs = (struct msg_parse*)region_alloc(qstate->env->scratch,
+ prs = (struct msg_parse*)regional_alloc(qstate->env->scratch,
sizeof(struct msg_parse));
if(!prs) {
log_err("out of memory on incoming message");
#include "util/data/dname.h"
#include "util/module.h"
#include "util/net_help.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
/** store rrsets in the rrset cache.
* @param env: module environment with caches.
/** allocate rrset in region - no more locks needed */
static struct ub_packed_rrset_key*
-copy_rrset(struct ub_packed_rrset_key* key, struct region* region,
+copy_rrset(struct ub_packed_rrset_key* key, struct regional* region,
uint32_t now)
{
- struct ub_packed_rrset_key* ck = region_alloc(region,
+ struct ub_packed_rrset_key* ck = regional_alloc(region,
sizeof(struct ub_packed_rrset_key));
struct packed_rrset_data* d;
struct packed_rrset_data* data = (struct packed_rrset_data*)
ck->entry.hash = key->entry.hash;
ck->entry.key = ck;
ck->rk = key->rk;
- ck->rk.dname = region_alloc_init(region, key->rk.dname,
+ ck->rk.dname = regional_alloc_init(region, key->rk.dname,
key->rk.dname_len);
if(!ck->rk.dname)
return NULL;
dsize = packed_rrset_sizeof(data);
- d = (struct packed_rrset_data*)region_alloc_init(region, data, dsize);
+ d = (struct packed_rrset_data*)regional_alloc_init(region, data, dsize);
if(!d)
return NULL;
ck->entry.data = d;
/** add addr to additional section */
static void
-addr_to_additional(struct ub_packed_rrset_key* rrset, struct region* region,
+addr_to_additional(struct ub_packed_rrset_key* rrset, struct regional* region,
struct dns_msg* msg, uint32_t now)
{
if((msg->rep->rrsets[msg->rep->rrset_count] =
/** find and add A and AAAA records for nameservers in delegpt */
static int
-find_add_addrs(struct module_env* env, uint16_t qclass, struct region* region,
- struct delegpt* dp, uint32_t now, struct dns_msg** msg)
+find_add_addrs(struct module_env* env, uint16_t qclass,
+ struct regional* region, struct delegpt* dp, uint32_t now,
+ struct dns_msg** msg)
{
struct delegpt_ns* ns;
struct ub_packed_rrset_key* akey;
/** find and add A and AAAA records for missing nameservers in delegpt */
int
cache_fill_missing(struct module_env* env, uint16_t qclass,
- struct region* region, struct delegpt* dp)
+ struct regional* region, struct delegpt* dp)
{
struct delegpt_ns* ns;
struct ub_packed_rrset_key* akey;
/** find and add DS or NSEC to delegation msg */
static void
-find_add_ds(struct module_env* env, struct region* region,
+find_add_ds(struct module_env* env, struct regional* region,
struct dns_msg* msg, struct delegpt* dp, uint32_t now)
{
/* Lookup the DS or NSEC at the delegation point. */
/** create referral message with NS and query */
static struct dns_msg*
create_msg(uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
- struct region* region, struct ub_packed_rrset_key* nskey,
+ struct regional* region, struct ub_packed_rrset_key* nskey,
struct packed_rrset_data* nsdata, uint32_t now)
{
- struct dns_msg* msg = (struct dns_msg*)region_alloc(region,
+ struct dns_msg* msg = (struct dns_msg*)regional_alloc(region,
sizeof(struct dns_msg));
if(!msg)
return NULL;
- msg->qinfo.qname = region_alloc_init(region, qname, qnamelen);
+ msg->qinfo.qname = regional_alloc_init(region, qname, qnamelen);
if(!msg->qinfo.qname)
return NULL;
msg->qinfo.qname_len = qnamelen;
msg->qinfo.qtype = qtype;
msg->qinfo.qclass = qclass;
/* non-packed reply_info, because it needs to grow the array */
- msg->rep = (struct reply_info*)region_alloc(region,
+ msg->rep = (struct reply_info*)regional_alloc(region,
sizeof(struct reply_info)-sizeof(struct rrset_ref));
if(!msg->rep)
return NULL;
* A rrset for every NS RR
* AAAA rrset for every NS RR
*/
- msg->rep->rrsets = (struct ub_packed_rrset_key**)region_alloc(region,
+ msg->rep->rrsets = (struct ub_packed_rrset_key**)
+ regional_alloc(region,
(2 + nsdata->count*2)*sizeof(struct ub_packed_rrset_key*));
if(!msg->rep->rrsets)
return NULL;
struct delegpt*
dns_cache_find_delegation(struct module_env* env, uint8_t* qname,
size_t qnamelen, uint16_t qtype, uint16_t qclass,
- struct region* region, struct dns_msg** msg, uint32_t now)
+ struct regional* region, struct dns_msg** msg, uint32_t now)
{
/* try to find closest NS rrset */
struct ub_packed_rrset_key* nskey;
/** allocate dns_msg from query_info and reply_info */
static struct dns_msg*
-gen_dns_msg(struct region* region, struct query_info* q, size_t num)
+gen_dns_msg(struct regional* region, struct query_info* q, size_t num)
{
- struct dns_msg* msg = (struct dns_msg*)region_alloc(region,
+ struct dns_msg* msg = (struct dns_msg*)regional_alloc(region,
sizeof(struct dns_msg));
if(!msg)
return NULL;
memcpy(&msg->qinfo, q, sizeof(struct query_info));
- msg->qinfo.qname = region_alloc_init(region, q->qname, q->qname_len);
+ msg->qinfo.qname = regional_alloc_init(region, q->qname, q->qname_len);
if(!msg->qinfo.qname)
return NULL;
/* allocate replyinfo struct and rrset key array separately */
- msg->rep = (struct reply_info*)region_alloc(region,
+ msg->rep = (struct reply_info*)regional_alloc(region,
sizeof(struct reply_info) - sizeof(struct rrset_ref));
if(!msg->rep)
return NULL;
- msg->rep->rrsets = (struct ub_packed_rrset_key**)region_alloc(region,
+ msg->rep->rrsets = (struct ub_packed_rrset_key**)
+ regional_alloc(region,
num * sizeof(struct ub_packed_rrset_key*));
if(!msg->rep->rrsets)
return NULL;
/** generate dns_msg from cached message */
static struct dns_msg*
tomsg(struct module_env* env, struct msgreply_entry* e, struct reply_info* r,
- struct region* region, uint32_t now, struct region* scratch)
+ struct regional* region, uint32_t now, struct regional* scratch)
{
struct dns_msg* msg;
size_t i;
/** synthesize RRset-only response from cached RRset item */
static struct dns_msg*
-rrset_msg(struct ub_packed_rrset_key* rrset, struct region* region,
+rrset_msg(struct ub_packed_rrset_key* rrset, struct regional* region,
uint32_t now, struct query_info* q)
{
struct dns_msg* msg;
/** synthesize DNAME+CNAME response from cached DNAME item */
static struct dns_msg*
-synth_dname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
+synth_dname_msg(struct ub_packed_rrset_key* rrset, struct regional* region,
uint32_t now, struct query_info* q)
{
struct dns_msg* msg;
msg->rep->flags |= LDNS_RCODE_YXDOMAIN;
return msg;
}
- newname = (uint8_t*)region_alloc(region, newlen);
+ newname = (uint8_t*)regional_alloc(region, newlen);
if(!newname)
return NULL;
/* new name is concatenation of qname front (without DNAME owner)
memcpy(newname, q->qname, q->qname_len-rrset->rk.dname_len);
memmove(newname+(q->qname_len-rrset->rk.dname_len), dtarg, dtarglen);
/* create rest of CNAME rrset */
- ck = (struct ub_packed_rrset_key*)region_alloc(region,
+ ck = (struct ub_packed_rrset_key*)regional_alloc(region,
sizeof(struct ub_packed_rrset_key));
if(!ck)
return NULL;
ck->rk.type = htons(LDNS_RR_TYPE_CNAME);
ck->rk.rrset_class = rrset->rk.rrset_class;
ck->rk.flags = 0;
- ck->rk.dname = region_alloc_init(region, q->qname, q->qname_len);
+ ck->rk.dname = regional_alloc_init(region, q->qname, q->qname_len);
if(!ck->rk.dname)
return NULL;
ck->rk.dname_len = q->qname_len;
ck->entry.hash = rrset_key_hash(&ck->rk);
- newd = (struct packed_rrset_data*)region_alloc(region,
+ newd = (struct packed_rrset_data*)regional_alloc(region,
sizeof(struct packed_rrset_data) + sizeof(size_t) +
sizeof(uint8_t*) + sizeof(uint32_t) + sizeof(uint16_t)
+ newlen);
struct dns_msg*
dns_cache_lookup(struct module_env* env,
uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
- struct region* region, struct region* scratch)
+ struct regional* region, struct regional* scratch)
{
struct lruhash_entry* e;
struct query_info k;
struct module_env;
struct query_info;
struct reply_info;
-struct region;
+struct regional;
struct delegpt;
/**
*/
struct delegpt* dns_cache_find_delegation(struct module_env* env,
uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
- struct region* region, struct dns_msg** msg, uint32_t timenow);
+ struct regional* region, struct dns_msg** msg, uint32_t timenow);
/**
* Find cached message
*/
struct dns_msg* dns_cache_lookup(struct module_env* env,
uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
- struct region* region, struct region* scratch);
+ struct regional* region, struct regional* scratch);
/**
* find and add A and AAAA records for missing nameservers in delegpt
* @return false on alloc failure.
*/
int cache_fill_missing(struct module_env* env, uint16_t qclass,
- struct region* region, struct delegpt* dp);
+ struct regional* region, struct delegpt* dp);
/** Find covering DNAME */
#include "util/config_file.h"
#include "util/data/packed_rrset.h"
#include "util/data/msgreply.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/alloc.h"
struct rrset_cache* rrset_cache_create(struct config_file* cfg,
}
void
-rrset_array_unlock_touch(struct rrset_cache* r, struct region* scratch,
+rrset_array_unlock_touch(struct rrset_cache* r, struct regional* scratch,
struct rrset_ref* ref, size_t count)
{
hashvalue_t* h;
size_t i;
- if(!(h = (hashvalue_t*)region_alloc(scratch,
+ if(!(h = (hashvalue_t*)regional_alloc(scratch,
sizeof(hashvalue_t)*count)))
log_warn("rrset LRU: memory allocation failed");
else /* store hash values */
struct config_file;
struct alloc_cache;
struct rrset_ref;
-struct region;
+struct regional;
/**
* The rrset cache
* duplicate references are allowed and handled.
* @param count: size of array.
*/
-void rrset_array_unlock_touch(struct rrset_cache* r, struct region* scratch,
+void rrset_array_unlock_touch(struct rrset_cache* r, struct regional* scratch,
struct rrset_ref* ref, size_t count);
/**
#include "util/log.h"
#include "util/net_help.h"
#include "util/module.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/data/msgencode.h"
#include "util/timehist.h"
#include "util/fptr_wlist.h"
mesh_state_create(struct module_env* env, struct query_info* qinfo,
uint16_t qflags, int prime)
{
- region_type* region = region_create(malloc, free);
+ struct regional* region = regional_create();
struct mesh_state* mstate;
int i;
if(!region)
return NULL;
- mstate = (struct mesh_state*)region_alloc(region,
+ mstate = (struct mesh_state*)regional_alloc(region,
sizeof(struct mesh_state));
if(!mstate) {
- region_destroy(region);
+ regional_destroy(region);
return NULL;
}
memset(mstate, 0, sizeof(*mstate));
mstate->s.qinfo.qtype = qinfo->qtype;
mstate->s.qinfo.qclass = qinfo->qclass;
mstate->s.qinfo.qname_len = qinfo->qname_len;
- mstate->s.qinfo.qname = region_alloc_init(region, qinfo->qname,
+ mstate->s.qinfo.qname = regional_alloc_init(region, qinfo->qname,
qinfo->qname_len);
if(!mstate->s.qinfo.qname) {
- region_destroy(region);
+ regional_destroy(region);
return NULL;
}
/* remove all weird bits from qflags */
mstate->s.minfo[i] = NULL;
mstate->s.ext_state[i] = module_finished;
}
- region_destroy(mstate->s.region);
+ regional_destroy(mstate->s.region);
}
void
struct rbnode_t* n;
struct mesh_state_ref* subref; /* points to sub, inserted in super */
struct mesh_state_ref* superref; /* points to super, inserted in sub */
- if( !(subref = region_alloc(super->s.region,
+ if( !(subref = regional_alloc(super->s.region,
sizeof(struct mesh_state_ref))) ||
- !(superref = region_alloc(sub->s.region,
+ !(superref = regional_alloc(sub->s.region,
sizeof(struct mesh_state_ref))) ) {
log_err("mesh_state_attachment: out of memory");
return 0;
int mesh_state_add_reply(struct mesh_state* s, struct edns_data* edns,
struct comm_reply* rep, uint16_t qid, uint16_t qflags)
{
- struct mesh_reply* r = region_alloc(s->s.region,
+ struct mesh_reply* r = regional_alloc(s->s.region,
sizeof(struct mesh_reply));
if(!r)
return 0;
/* examine results */
mstate->s.reply = NULL;
- region_free_all(mstate->s.env->scratch);
+ regional_free_all(mstate->s.env->scratch);
s = mstate->s.ext_state[mstate->s.curmod];
verbose(VERB_ALGO, "mesh_run: %s module exit state is %s",
mesh->modfunc[mstate->s.curmod]->name, strextstate(s));
sizeof(struct th_buck)*mesh->histogram->num;
RBTREE_FOR(m, struct mesh_state*, &mesh->all) {
/* all, including m itself allocated in qstate region */
- s += region_get_mem(m->s.region);
+ s += regional_get_mem(m->s.region);
}
return s;
}
#include "util/data/msgreply.h"
#include "util/data/msgencode.h"
#include "util/alloc.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/net_help.h"
#include "testcode/readhex.h"
uint16_t id;
uint16_t flags;
uint32_t timenow = 0;
- region_type *region = region_create(malloc, free);
+ struct regional* region = regional_create();
struct edns_data edns;
hex_to_buf(pkt, hex);
query_info_clear(&qi);
reply_info_parsedelete(rep, alloc);
- region_destroy(region);
+ regional_destroy(region);
}
/** simple test of parsing */
#include "util/data/msgreply.h"
#include "util/data/msgparse.h"
#include "util/data/dname.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/alloc.h"
#include "util/rbtree.h"
#include "util/net_help.h"
/** entry to reply info conversion */
static void
-entry_to_repinfo(struct entry* e, struct alloc_cache* alloc, struct region*
- region, ldns_buffer* pkt, struct query_info* qi,
+entry_to_repinfo(struct entry* e, struct alloc_cache* alloc,
+ struct regional* region, ldns_buffer* pkt, struct query_info* qi,
struct reply_info** rep)
{
int ret;
/** extract DNSKEY rrset from answer and convert it */
static struct ub_packed_rrset_key*
-extract_keys(struct entry* e, struct alloc_cache* alloc, struct region*
- region, ldns_buffer* pkt)
+extract_keys(struct entry* e, struct alloc_cache* alloc,
+ struct regional* region, ldns_buffer* pkt)
{
struct ub_packed_rrset_key* dnskey = NULL;
struct query_info qinfo;
/** verify and test an entry - every rr in the message */
static void
-verifytest_entry(struct entry* e, struct alloc_cache* alloc, struct region*
- region, ldns_buffer* pkt, struct ub_packed_rrset_key* dnskey,
- struct module_env* env, struct val_env* ve)
+verifytest_entry(struct entry* e, struct alloc_cache* alloc,
+ struct regional* region, ldns_buffer* pkt,
+ struct ub_packed_rrset_key* dnskey, struct module_env* env,
+ struct val_env* ve)
{
struct query_info qinfo;
struct reply_info* rep = NULL;
size_t i;
- region_free_all(region);
+ regional_free_all(region);
if(vsig) {
printf("verifying pkt:\n");
ldns_pkt_print(stdout, e->reply_list->reply);
/** DS sig test an entry - get DNSKEY and DS in entry and verify */
static void
-dstest_entry(struct entry* e, struct alloc_cache* alloc, struct region*
- region, ldns_buffer* pkt, struct module_env* env)
+dstest_entry(struct entry* e, struct alloc_cache* alloc,
+ struct regional* region, ldns_buffer* pkt, struct module_env* env)
{
struct query_info qinfo;
struct reply_info* rep = NULL;
struct ub_packed_rrset_key* ds, *dnskey;
int ret;
- region_free_all(region);
+ regional_free_all(region);
if(vsig) {
printf("verifying DS-DNSKEY match:\n");
ldns_pkt_print(stdout, e->reply_list->reply);
* The answer rrset is the keyset that will be used for verification
*/
struct ub_packed_rrset_key* dnskey;
- struct region* region = region_create(malloc, free);
+ struct regional* region = regional_create();
struct alloc_cache alloc;
ldns_buffer* buf = ldns_buffer_new(65535);
struct entry* e;
}
delete_entry(list);
- region_destroy(region);
+ regional_destroy(region);
alloc_clear(&alloc);
ldns_buffer_free(buf);
}
* The first entry must be a query for DNSKEY.
* The answer rrset is the keyset that will be used for verification
*/
- struct region* region = region_create(malloc, free);
+ struct regional* region = regional_create();
struct alloc_cache alloc;
ldns_buffer* buf = ldns_buffer_new(65535);
struct entry* e;
}
delete_entry(list);
- region_destroy(region);
+ regional_destroy(region);
alloc_clear(&alloc);
ldns_buffer_free(buf);
}
/** Test hash algo - NSEC3 hash it and compare result */
static void
nsec3_hash_test_entry(struct entry* e, rbtree_t* ct,
- struct alloc_cache* alloc, struct region* region,
+ struct alloc_cache* alloc, struct regional* region,
ldns_buffer* buf)
{
struct query_info qinfo;
entry_to_repinfo(e, alloc, region, buf, &qinfo, &rep);
nsec3 = find_rrset_type(rep, LDNS_RR_TYPE_NSEC3);
answer = find_rrset_type(rep, LDNS_RR_TYPE_AAAA);
- qname = region_alloc_init(region, qinfo.qname, qinfo.qname_len);
+ qname = regional_alloc_init(region, qinfo.qname, qinfo.qname_len);
/* check test is OK */
unit_assert(nsec3 && answer && qname);
* The test does not perform canonicalization during the compare.
*/
rbtree_t ct;
- struct region* region = region_create(malloc, free);
+ struct regional* region = regional_create();
struct alloc_cache alloc;
ldns_buffer* buf = ldns_buffer_new(65535);
struct entry* e;
}
delete_entry(list);
- region_destroy(region);
+ regional_destroy(region);
alloc_clear(&alloc);
ldns_buffer_free(buf);
}
return unbound_stat_realloc(ptr, size);
}
-/** special routine for region-allocator, print to log */
-void *unbound_stat_malloc_region(size_t size)
-{
- log_info("region malloc(%u)", (unsigned)size);
- return unbound_stat_malloc(size);
-}
-
-/** special routine for region-allocator, print to log */
-void unbound_stat_free_region(void *ptr)
-{
- if(ptr && memcmp(ptr-8, &mem_special, sizeof(mem_special)) == 0) {
- size_t s;
- memcpy(&s, ptr-16, sizeof(s));
- log_info("region free(%p) size %u", ptr, (unsigned)s);
- } else
- log_info("region unmatched free(%p)", ptr);
- unbound_stat_free(ptr);
-}
-
#endif /* UNBOUND_ALLOC_STATS */
#include "util/data/msgparse.h"
#include "util/data/dname.h"
#include "util/log.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/net_help.h"
/** return code that means the function ran out of memory. negative so it does
*/
static struct compress_tree_node*
compress_tree_insert(struct compress_tree_node** tree, uint8_t* dname,
- int labs, size_t offset, region_type* region)
+ int labs, size_t offset, struct regional* region)
{
int c, m;
struct compress_tree_node* p, **prev;
struct compress_tree_node* n = (struct compress_tree_node*)
- region_alloc(region, sizeof(struct compress_tree_node));
+ regional_alloc(region, sizeof(struct compress_tree_node));
if(!n) return 0;
n->left = 0;
n->right = 0;
*/
static int
compress_tree_store(struct compress_tree_node** tree, uint8_t* dname,
- int labs, size_t offset, region_type* region,
+ int labs, size_t offset, struct regional* region,
struct compress_tree_node* closest)
{
uint8_t lablen;
/** compress owner name of RR, return RETVAL_OUTMEM RETVAL_TRUNC */
static int
compress_owner(struct ub_packed_rrset_key* key, ldns_buffer* pkt,
- region_type* region, struct compress_tree_node** tree,
+ struct regional* region, struct compress_tree_node** tree,
size_t owner_pos, uint16_t* owner_ptr, int owner_labs)
{
struct compress_tree_node* p;
/** compress any domain name to the packet, return RETVAL_* */
static int
compress_any_dname(uint8_t* dname, ldns_buffer* pkt, int labs,
- region_type* region, struct compress_tree_node** tree)
+ struct regional* region, struct compress_tree_node** tree)
{
struct compress_tree_node* p;
size_t pos = ldns_buffer_position(pkt);
/** compress domain names in rdata, return RETVAL_* */
static int
compress_rdata(ldns_buffer* pkt, uint8_t* rdata, size_t todolen,
- region_type* region, struct compress_tree_node** tree,
+ struct regional* region, struct compress_tree_node** tree,
const ldns_rr_descriptor* desc)
{
int labs, r, rdf = 0;
/** store rrset in buffer in wireformat, return RETVAL_* */
static int
packed_rrset_encode(struct ub_packed_rrset_key* key, ldns_buffer* pkt,
- uint16_t* num_rrs, uint32_t timenow, region_type* region,
+ uint16_t* num_rrs, uint32_t timenow, struct regional* region,
int do_data, int do_sig, struct compress_tree_node** tree,
ldns_pkt_section s, uint16_t qtype, int dnssec)
{
static int
insert_section(struct reply_info* rep, size_t num_rrsets, uint16_t* num_rrs,
ldns_buffer* pkt, size_t rrsets_before, uint32_t timenow,
- region_type* region, struct compress_tree_node** tree,
+ struct regional* region, struct compress_tree_node** tree,
ldns_pkt_section s, uint16_t qtype, int dnssec)
{
int r;
/** store query section in wireformat buffer, return RETVAL */
static int
insert_query(struct query_info* qinfo, struct compress_tree_node** tree,
- ldns_buffer* buffer, struct region* region)
+ ldns_buffer* buffer, struct regional* region)
{
if(ldns_buffer_remaining(buffer) <
qinfo->qname_len+sizeof(uint16_t)*2)
int
reply_info_encode(struct query_info* qinfo, struct reply_info* rep,
uint16_t id, uint16_t flags, ldns_buffer* buffer, uint32_t timenow,
- region_type* region, uint16_t udpsize, int dnssec)
+ struct regional* region, uint16_t udpsize, int dnssec)
{
uint16_t ancount=0, nscount=0, arcount=0;
struct compress_tree_node* tree = 0;
int
reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep,
uint16_t id, uint16_t qflags, ldns_buffer* pkt, uint32_t timenow,
- int cached, struct region* region, uint16_t udpsize,
+ int cached, struct regional* region, uint16_t udpsize,
struct edns_data* edns, int dnssec, int secure)
{
uint16_t flags;
#define UTIL_DATA_MSGENCODE_H
struct query_info;
struct reply_info;
-struct region;
+struct regional;
struct edns_data;
/**
*/
int reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep,
uint16_t id, uint16_t qflags, ldns_buffer* dest, uint32_t timenow,
- int cached, struct region* region, uint16_t udpsize,
+ int cached, struct regional* region, uint16_t udpsize,
struct edns_data* edns, int dnssec, int secure);
/**
*/
int reply_info_encode(struct query_info* qinfo, struct reply_info* rep,
uint16_t id, uint16_t flags, ldns_buffer* buffer, uint32_t timenow,
- struct region* region, uint16_t udpsize, int dnssec);
+ struct regional* region, uint16_t udpsize, int dnssec);
/**
* Encode query packet. Assumes the buffer is large enough.
#include "util/data/dname.h"
#include "util/data/packed_rrset.h"
#include "util/storage/lookup3.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
/** smart comparison of (compressed, valid) dnames from packet */
static int
static struct rrset_parse*
new_rrset(struct msg_parse* msg, uint8_t* dname, size_t dnamelen,
uint16_t type, uint16_t dclass, hashvalue_t hash,
- uint32_t rrset_flags, ldns_pkt_section section, region_type* region)
+ uint32_t rrset_flags, ldns_pkt_section section,
+ struct regional* region)
{
- struct rrset_parse* p = region_alloc(region, sizeof(*p));
+ struct rrset_parse* p = regional_alloc(region, sizeof(*p));
if(!p) return NULL;
p->rrset_bucket_next = msg->hashtable[hash & (PARSE_TABLE_SIZE-1)];
msg->hashtable[hash & (PARSE_TABLE_SIZE-1)] = p;
/** move rrsigs from sigset to dataset */
static int
-moveover_rrsigs(ldns_buffer* pkt, region_type* region,
+moveover_rrsigs(ldns_buffer* pkt, struct regional* region,
struct rrset_parse* sigset, struct rrset_parse* dataset, int duplicate)
{
struct rr_parse* sig = sigset->rr_first;
dataset->type)) {
if(duplicate) {
/* new */
- insert = (struct rr_parse*)region_alloc(region,
- sizeof(struct rr_parse));
+ insert = (struct rr_parse*)regional_alloc(
+ region, sizeof(struct rr_parse));
insert->outside_packet = 0;
insert->ttl_data = sig->ttl_data;
insert->size = sig->size;
static struct rrset_parse*
change_rrsig_rrset(struct rrset_parse* sigset, struct msg_parse* msg,
ldns_buffer* pkt, uint16_t datatype, uint32_t rrset_flags,
- int hasother, ldns_pkt_section section, region_type* region)
+ int hasother, ldns_pkt_section section, struct regional* region)
{
struct rrset_parse* dataset = sigset;
hashvalue_t hash = pkt_hash_rrset(pkt, sigset->dname, datatype,
uint8_t** prev_dname_first, uint8_t** prev_dname_last,
size_t* prev_dnamelen, uint16_t* prev_type,
uint16_t* prev_dclass, struct rrset_parse** rrset_prev,
- ldns_pkt_section section, region_type* region)
+ ldns_pkt_section section, struct regional* region)
{
uint16_t covtype;
if(rrset_prev) {
/** Add rr (from packet here) to rrset, skips rr */
static int
add_rr_to_rrset(struct rrset_parse* rrset, ldns_buffer* pkt,
- struct msg_parse* msg, region_type* region,
+ struct msg_parse* msg, struct regional* region,
ldns_pkt_section section, uint16_t type)
{
struct rr_parse* rr;
}
/* create rr */
- if(!(rr = (struct rr_parse*)region_alloc(region, sizeof(*rr))))
+ if(!(rr = (struct rr_parse*)regional_alloc(region, sizeof(*rr))))
return LDNS_RCODE_SERVFAIL;
rr->outside_packet = 0;
rr->ttl_data = ldns_buffer_current(pkt);
* @return: 0 if OK, or rcode on error.
*/
static int
-parse_section(ldns_buffer* pkt, struct msg_parse* msg, region_type* region,
- ldns_pkt_section section, uint16_t num_rrs, size_t* num_rrsets)
+parse_section(ldns_buffer* pkt, struct msg_parse* msg,
+ struct regional* region, ldns_pkt_section section,
+ uint16_t num_rrs, size_t* num_rrsets)
{
uint16_t i;
uint8_t* dname, *prev_dname_f = NULL, *prev_dname_l = NULL;
}
int
-parse_packet(ldns_buffer* pkt, struct msg_parse* msg, region_type* region)
+parse_packet(ldns_buffer* pkt, struct msg_parse* msg, struct regional* region)
{
int ret;
if(ldns_buffer_remaining(pkt) < LDNS_HEADER_SIZE)
#include "util/storage/lruhash.h"
struct rrset_parse;
struct rr_parse;
-struct region;
+struct regional;
/** number of buckets in parse rrset hash table. Must be power of 2. */
#define PARSE_TABLE_SIZE 1024
* @return: 0 if OK, or rcode on error.
*/
int parse_packet(ldns_buffer* pkt, struct msg_parse* msg,
- struct region* region);
+ struct regional* region);
/**
* After parsing the packet, extract EDNS data from packet.
#include "util/netevent.h"
#include "util/net_help.h"
#include "util/data/dname.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/data/msgparse.h"
#include "util/data/msgencode.h"
/** allocate qinfo, return 0 on error */
static int
parse_create_qinfo(ldns_buffer* pkt, struct msg_parse* msg,
- struct query_info* qinf, struct region* region)
+ struct query_info* qinf, struct regional* region)
{
if(msg->qname) {
if(region)
- qinf->qname = (uint8_t*)region_alloc(region,
+ qinf->qname = (uint8_t*)regional_alloc(region,
msg->qname_len);
else qinf->qname = (uint8_t*)malloc(msg->qname_len);
if(!qinf->qname) return 0;
/** constructor for replyinfo */
static struct reply_info*
-construct_reply_info_base(struct region* region, uint16_t flags, size_t qd,
+construct_reply_info_base(struct regional* region, uint16_t flags, size_t qd,
uint32_t ttl, size_t an, size_t ns, size_t ar, size_t total,
enum sec_status sec)
{
size_t s = sizeof(struct reply_info) - sizeof(struct rrset_ref) +
sizeof(struct ub_packed_rrset_key*) * total;
if(region)
- rep = (struct reply_info*)region_alloc(region, s);
+ rep = (struct reply_info*)regional_alloc(region, s);
else rep = (struct reply_info*)malloc(s +
sizeof(struct rrset_ref) * (total));
if(!rep)
/** allocate replyinfo, return 0 on error */
static int
parse_create_repinfo(struct msg_parse* msg, struct reply_info** rep,
- struct region* region)
+ struct regional* region)
{
*rep = construct_reply_info_base(region, msg->flags, msg->qdcount, 0,
msg->an_rrsets, msg->ns_rrsets, msg->ar_rrsets,
/** allocate (special) rrset keys, return 0 on error */
static int
repinfo_alloc_rrset_keys(struct reply_info* rep, struct alloc_cache* alloc,
- struct region* region)
+ struct regional* region)
{
size_t i;
for(i=0; i<rep->rrset_count; i++) {
if(region) {
rep->rrsets[i] = (struct ub_packed_rrset_key*)
- region_alloc(region,
+ regional_alloc(region,
sizeof(struct ub_packed_rrset_key));
if(rep->rrsets[i]) {
memset(rep->rrsets[i], 0,
/** create rrset return 0 on failure */
static int
parse_create_rrset(ldns_buffer* pkt, struct rrset_parse* pset,
- struct packed_rrset_data** data, struct region* region)
+ struct packed_rrset_data** data, struct regional* region)
{
/* allocate */
size_t s = sizeof(struct packed_rrset_data) +
(sizeof(size_t)+sizeof(uint8_t*)+sizeof(uint32_t)) +
pset->size;
if(region)
- *data = region_alloc(region, s);
+ *data = regional_alloc(region, s);
else *data = malloc(s);
if(!*data)
return 0;
int
parse_copy_decompress_rrset(ldns_buffer* pkt, struct msg_parse* msg,
- struct rrset_parse *pset, struct region* region,
+ struct rrset_parse *pset, struct regional* region,
struct ub_packed_rrset_key* pk)
{
struct packed_rrset_data* data;
pk->rk.flags = pset->flags;
pk->rk.dname_len = pset->dname_len;
if(region)
- pk->rk.dname = (uint8_t*)region_alloc(
+ pk->rk.dname = (uint8_t*)regional_alloc(
region, pset->dname_len);
else pk->rk.dname =
(uint8_t*)malloc(pset->dname_len);
*/
static int
parse_copy_decompress(ldns_buffer* pkt, struct msg_parse* msg,
- struct reply_info* rep, struct region* region)
+ struct reply_info* rep, struct regional* region)
{
size_t i;
struct rrset_parse *pset = msg->rrset_first;
int
parse_create_msg(ldns_buffer* pkt, struct msg_parse* msg,
struct alloc_cache* alloc, struct query_info* qinf,
- struct reply_info** rep, struct region* region)
+ struct reply_info** rep, struct regional* region)
{
log_assert(pkt && msg);
if(!parse_create_qinfo(pkt, msg, qinf, region))
}
int reply_info_parse(ldns_buffer* pkt, struct alloc_cache* alloc,
- struct query_info* qinf, struct reply_info** rep, struct region* region,
- struct edns_data* edns)
+ struct query_info* qinf, struct reply_info** rep,
+ struct regional* region, struct edns_data* edns)
{
/* use scratch pad region-allocator during parsing. */
struct msg_parse* msg;
qinf->qname = NULL;
*rep = NULL;
- if(!(msg = region_alloc(region, sizeof(*msg)))) {
+ if(!(msg = regional_alloc(region, sizeof(*msg)))) {
return LDNS_RCODE_SERVFAIL;
}
memset(msg, 0, sizeof(*msg));
/** copy rrsets from replyinfo to dest replyinfo */
static int
repinfo_copy_rrsets(struct reply_info* dest, struct reply_info* from,
- struct region* region)
+ struct regional* region)
{
size_t i, s;
struct packed_rrset_data* fd, *dd;
dk->rk = fk->rk;
if(region) {
dk->id = fk->id;
- dk->rk.dname = (uint8_t*)region_alloc_init(region,
+ dk->rk.dname = (uint8_t*)regional_alloc_init(region,
fk->rk.dname, fk->rk.dname_len);
} else
dk->rk.dname = (uint8_t*)memdup(fk->rk.dname,
return 0;
s = packed_rrset_sizeof(fd);
if(region)
- dd = (struct packed_rrset_data*)region_alloc_init(
+ dd = (struct packed_rrset_data*)regional_alloc_init(
region, fd, s);
else dd = (struct packed_rrset_data*)memdup(fd, s);
if(!dd)
struct reply_info*
reply_info_copy(struct reply_info* rep, struct alloc_cache* alloc,
- struct region* region)
+ struct regional* region)
{
struct reply_info* cp;
cp = construct_reply_info_base(region, rep->flags, rep->qdcount,
{
/* not particularly fast but flexible, make wireformat and print */
ldns_buffer* buf = ldns_buffer_new(65535);
- struct region* region = region_create(malloc, free);
+ struct regional* region = regional_create();
if(!reply_info_encode(qinfo, rep, 0, rep->flags, buf, 0,
region, 65535, 1)) {
log_info("%s: log_dns_msg: out of memory", str);
ldns_pkt_free(pkt);
}
ldns_buffer_free(buf);
- region_destroy(region);
+ regional_destroy(region);
}
void
struct comm_reply;
struct alloc_cache;
struct iovec;
-struct region;
+struct regional;
struct edns_data;
struct msg_parse;
struct rrset_parse;
*/
int reply_info_parse(ldns_buffer* pkt, struct alloc_cache* alloc,
struct query_info* qinf, struct reply_info** rep,
- struct region* region, struct edns_data* edns);
+ struct regional* region, struct edns_data* edns);
/**
* Allocate and decompress parsed message and rrsets.
*/
int parse_create_msg(ldns_buffer* pkt, struct msg_parse* msg,
struct alloc_cache* alloc, struct query_info* qinf,
- struct reply_info** rep, struct region* region);
+ struct reply_info** rep, struct regional* region);
/**
* Sorts the ref array.
* @return new reply info or NULL on memory error.
*/
struct reply_info* reply_info_copy(struct reply_info* rep,
- struct alloc_cache* alloc, struct region* region);
+ struct alloc_cache* alloc, struct regional* region);
/**
* Copy a parsed rrset into given key, decompressing and allocating rdata.
* @return false on alloc failure.
*/
int parse_copy_decompress_rrset(ldns_buffer* pkt, struct msg_parse* msg,
- struct rrset_parse *pset, struct region* region,
+ struct rrset_parse *pset, struct regional* region,
struct ub_packed_rrset_key* pk);
/**
return 0;
}
-int
-fptr_whitelist_region_allocator(void *(*fptr)(size_t))
-{
- /* TODO: remove callbacks from new region type */
- return 1; /* DEBUG for different mem allocs */
- if(fptr == &malloc) return 1;
- return 0;
-}
-
-int
-fptr_whitelist_region_deallocator(void (*fptr)(void*))
-{
- return 1; /* DEBUG for different mem allocs */
- if(fptr == &free) return 1;
- return 0;
-}
-
int
fptr_whitelist_rbtree_cmp(int (*fptr) (const void *, const void *))
{
*/
int fptr_whitelist_serviced_query(comm_point_callback_t *fptr);
-/**
- * Check function pointer whitelist for region allocator callback values.
- *
- * @param fptr: function pointer to check.
- * @return false if not in whitelist.
- */
-int fptr_whitelist_region_allocator(void *(*fptr)(size_t));
-
-/**
- * Check function pointer whitelist for region deallocator callback values.
- *
- * @param fptr: function pointer to check.
- * @return false if not in whitelist.
- */
-int fptr_whitelist_region_deallocator(void (*fptr)(void*));
-
/**
* Check function pointer whitelist for rbtree cmp callback values.
*
struct slabhash;
struct query_info;
struct edns_data;
-struct region;
+struct regional;
struct worker;
struct module_qstate;
struct ub_randstate;
struct query_info* qinfo, uint16_t flags, int prime);
/** region for temporary usage. May be cleared after operate() call. */
- struct region* scratch;
+ struct regional* scratch;
/** buffer for temporary usage. May be cleared after operate() call. */
ldns_buffer* scratch_buffer;
/** internal data for daemon - worker thread. */
/** the rcode, in case of error, instead of a reply message */
int return_rcode;
/** region for this query. Cleared when query process finishes. */
- struct region* region;
+ struct regional* region;
/** which module is executing */
int curmod;
+++ /dev/null
-/*
- * region-allocator.c -- region based memory allocator.
- *
- * Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
- *
- * Copyright (c) 2007, NLnet Labs. All rights reserved.
- *
- * This software is open source.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the NLNET LABS nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * \file
- * Region allocator. Allocates small portions of of larger chunks.
- */
-
-#include "config.h"
-#include "util/log.h"
-#include "util/region-allocator.h"
-#include "util/fptr_wlist.h"
-
-#ifdef ALIGNMENT
-# undef ALIGNMENT
-#endif
-/** increase size until it fits alignment of s bytes */
-#define ALIGN_UP(x, s) (((x) + s - 1) & (~(s - 1)))
-/** what size to align on */
-#define ALIGNMENT (sizeof(uint64_t))
-/** set to 1 to perform expensive check for double recycle() */
-#define CHECK_DOUBLE_FREE 0
-
-/** typedef for cleanup structure */
-typedef struct cleanup cleanup_type;
-/** store chunks and user cleanup actions */
-struct cleanup
-{
- /** action to call (such as free) */
- void (*action)(void *);
- /** pointer to pass to action. */
- void *data;
-};
-
-/** linked list of recycle elements of a certain size. */
-struct recycle_elem {
- /** next in recycle list. First bytes of block is used for this ptr */
- struct recycle_elem* next;
-};
-
-/** hidden type of the region. */
-struct region
-{
- /** total bytes allocated */
- size_t total_allocated;
- /** number of small objects allocated */
- size_t small_objects;
- /** number of large objects allocated */
- size_t large_objects;
- /** number of chunks allocated */
- size_t chunk_count;
- /** Unused space due to alignment, etc. */
- size_t unused_space;
-
- /** number of bytes allocated in the current chunk. */
- size_t allocated;
- /** initial chunk */
- char *initial_data;
- /** current chunk */
- char *data;
-
- /** how to allocate memory (for chunks) */
- void *(*allocator)(size_t);
- /** how to deallocate memory (for chunks) */
- void (*deallocator)(void *);
-
- /** current max size of growing cleanup array */
- size_t maximum_cleanup_count;
- /** number used inside the cleanup array */
- size_t cleanup_count;
- /** cleanup array, chunks and user actions */
- cleanup_type *cleanups;
-
- /** size of chunks */
- size_t chunk_size;
- /** large object size */
- size_t large_object_size;
-
- /** if not NULL recycling is enabled.
- * It is an array of linked lists of parts held for recycle.
- * The parts are all pointers to within the allocated chunks.
- * Array [i] points to elements of size i. */
- struct recycle_elem** recycle_bin;
- /** amount of memory in recycle storage */
- size_t recycle_size;
-};
-
-
-/** common code to initialize a region */
-static region_type *
-alloc_region_base(void *(*allocator)(size_t size),
- void (*deallocator)(void *),
- size_t initial_cleanup_count)
-{
- region_type *result = (region_type *) allocator(sizeof(region_type));
- if (!result) return NULL;
-
- result->total_allocated = 0;
- result->small_objects = 0;
- result->large_objects = 0;
- result->chunk_count = 1;
- result->unused_space = 0;
- result->recycle_bin = NULL;
- result->recycle_size = 0;
-
- result->allocated = 0;
- result->data = NULL;
- result->initial_data = NULL;
-
- result->allocator = allocator;
- result->deallocator = deallocator;
-
- log_assert(initial_cleanup_count > 0);
- result->maximum_cleanup_count = initial_cleanup_count;
- result->cleanup_count = 0;
- log_assert(fptr_whitelist_region_allocator(allocator));
- result->cleanups = (cleanup_type *) allocator(
- result->maximum_cleanup_count * sizeof(cleanup_type));
- if (!result->cleanups) {
- log_assert(fptr_whitelist_region_deallocator(deallocator));
- deallocator(result);
- return NULL;
- }
-
- result->chunk_size = DEFAULT_CHUNK_SIZE;
- result->large_object_size = DEFAULT_LARGE_OBJECT_SIZE;
- return result;
-}
-
-region_type *
-region_create(void *(*allocator)(size_t), void (*deallocator)(void *))
-{
- region_type* result;
-#ifdef UNBOUND_ALLOC_STATS
- void *unbound_stat_malloc_region(size_t size);
- void unbound_stat_free_region(void *ptr);
- allocator = &unbound_stat_malloc_region;
- deallocator = &unbound_stat_free_region;
-#endif
- log_assert(fptr_whitelist_region_allocator(allocator));
- result = alloc_region_base(allocator, deallocator,
- DEFAULT_INITIAL_CLEANUP_SIZE);
- if(!result)
- return NULL;
- result->data = (char *) allocator(result->chunk_size);
- if (!result->data) {
- log_assert(fptr_whitelist_region_deallocator(deallocator));
- deallocator(result->cleanups);
- deallocator(result);
- return NULL;
- }
- result->initial_data = result->data;
-
- return result;
-}
-
-
-region_type *region_create_custom(void *(*allocator)(size_t),
- void (*deallocator)(void *),
- size_t chunk_size,
- size_t large_object_size,
- size_t initial_cleanup_size,
- int recycle)
-{
- region_type* result;
-#ifdef UNBOUND_ALLOC_STATS
- void *unbound_stat_malloc_region(size_t size);
- void unbound_stat_free_region(void *ptr);
- allocator = &unbound_stat_malloc_region;
- deallocator = &unbound_stat_free_region;
-#endif
- log_assert(fptr_whitelist_region_allocator(allocator));
- result = alloc_region_base(allocator, deallocator,
- initial_cleanup_size);
- if(!result)
- return NULL;
- log_assert(large_object_size <= chunk_size);
- result->chunk_size = chunk_size;
- result->large_object_size = large_object_size;
- if(result->chunk_size > 0) {
- result->data = (char *) allocator(result->chunk_size);
- if (!result->data) {
- log_assert(fptr_whitelist_region_deallocator(
- deallocator));
- deallocator(result->cleanups);
- deallocator(result);
- return NULL;
- }
- result->initial_data = result->data;
- }
- if(recycle) {
- result->recycle_bin = allocator(sizeof(struct recycle_elem*)
- * result->large_object_size);
- if(!result->recycle_bin) {
- region_destroy(result);
- return NULL;
- }
- memset(result->recycle_bin, 0, sizeof(struct recycle_elem*)
- * result->large_object_size);
- }
- return result;
-}
-
-
-void
-region_destroy(region_type *region)
-{
- void (*deallocator)(void *);
- if (!region)
- return;
-
- deallocator = region->deallocator;
- log_assert(fptr_whitelist_region_deallocator(deallocator));
-
- region_free_all(region);
- deallocator(region->cleanups);
- deallocator(region->initial_data);
- if(region->recycle_bin)
- deallocator(region->recycle_bin);
- deallocator(region);
-}
-
-
-size_t
-region_add_cleanup(region_type *region, void (*action)(void *), void *data)
-{
- log_assert(action);
-
- log_assert(fptr_whitelist_region_allocator(region->allocator));
- if (region->cleanup_count >= region->maximum_cleanup_count) {
- cleanup_type *cleanups = (cleanup_type *) region->allocator(
- 2 * region->maximum_cleanup_count * sizeof(cleanup_type));
- if (!cleanups) return 0;
-
- memcpy(cleanups, region->cleanups,
- region->cleanup_count * sizeof(cleanup_type));
- log_assert(fptr_whitelist_region_deallocator(
- region->deallocator));
- region->deallocator(region->cleanups);
-
- region->cleanups = cleanups;
- region->maximum_cleanup_count *= 2;
- }
-
- region->cleanups[region->cleanup_count].action = action;
- region->cleanups[region->cleanup_count].data = data;
-
- ++region->cleanup_count;
- return region->cleanup_count;
-}
-
-void *
-region_alloc(region_type *region, size_t size)
-{
- size_t aligned_size;
- void *result;
-
- if (size == 0) {
- size = 1;
- }
- aligned_size = ALIGN_UP(size, ALIGNMENT);
-
- if (aligned_size >= region->large_object_size) {
- log_assert(fptr_whitelist_region_allocator(region->allocator));
- result = region->allocator(size);
- if (!result) return NULL;
-
- log_assert(fptr_whitelist_region_deallocator(
- region->deallocator));
- if (!region_add_cleanup(region, region->deallocator, result)) {
- region->deallocator(result);
- return NULL;
- }
-
- region->total_allocated += size;
- ++region->large_objects;
-
- return result;
- }
-
- if (region->recycle_bin && region->recycle_bin[aligned_size]) {
- result = (void*)region->recycle_bin[aligned_size];
- region->recycle_bin[aligned_size] = region->recycle_bin[aligned_size]->next;
- region->recycle_size -= aligned_size;
- region->unused_space += aligned_size - size;
- return result;
- }
-
- log_assert(fptr_whitelist_region_allocator(region->allocator));
- if (region->allocated + aligned_size > region->chunk_size) {
- void *chunk = region->allocator(region->chunk_size);
- size_t wasted;
- if (!chunk) return NULL;
-
- wasted = (region->chunk_size - region->allocated) & (~(ALIGNMENT-1));
- if(wasted >= ALIGNMENT) {
- /* put wasted part in recycle bin for later use */
- region->total_allocated += wasted;
- ++region->small_objects;
- region_recycle(region, region->data+region->allocated, wasted);
- region->allocated += wasted;
- }
- ++region->chunk_count;
- region->unused_space += region->chunk_size - region->allocated;
-
- log_assert(fptr_whitelist_region_deallocator(
- region->deallocator));
- if(!region_add_cleanup(region, region->deallocator, chunk)) {
- region->deallocator(chunk);
- region->chunk_count--;
- region->unused_space -=
- region->chunk_size - region->allocated;
- return NULL;
- }
- region->allocated = 0;
- region->data = (char *) chunk;
- }
-
- result = region->data + region->allocated;
- region->allocated += aligned_size;
-
- region->total_allocated += aligned_size;
- region->unused_space += aligned_size - size;
- ++region->small_objects;
-
- return result;
-}
-
-void *
-region_alloc_init(region_type *region, const void *init, size_t size)
-{
- void *result = region_alloc(region, size);
- if (!result) return NULL;
- memcpy(result, init, size);
- return result;
-}
-
-void *
-region_alloc_zero(region_type *region, size_t size)
-{
- void *result = region_alloc(region, size);
- if (!result) return NULL;
- memset(result, 0, size);
- return result;
-}
-
-void
-region_free_all(region_type *region)
-{
- size_t i;
- log_assert(region);
- log_assert(region->cleanups);
-
- i = region->cleanup_count;
- while (i > 0) {
- --i;
- log_assert(region->cleanups[i].action);
- region->cleanups[i].action(region->cleanups[i].data);
- }
-
- if(region->recycle_bin) {
- memset(region->recycle_bin, 0, sizeof(struct recycle_elem*)
- * region->large_object_size);
- region->recycle_size = 0;
- }
-
- region->data = region->initial_data;
- region->cleanup_count = 0;
- region->allocated = 0;
-
- region->total_allocated = 0;
- region->small_objects = 0;
- region->large_objects = 0;
- region->chunk_count = 1;
- region->unused_space = 0;
-}
-
-
-char *
-region_strdup(region_type *region, const char *string)
-{
- return (char *) region_alloc_init(region, string, strlen(string) + 1);
-}
-
-void
-region_recycle(region_type *region, void *block, size_t size)
-{
- size_t aligned_size;
- size_t i;
-
- if(!block || !region->recycle_bin)
- return;
-
- if (size == 0) {
- size = 1;
- }
- aligned_size = ALIGN_UP(size, ALIGNMENT);
-
- if(aligned_size < region->large_object_size) {
- struct recycle_elem* elem = (struct recycle_elem*)block;
- /* we rely on the fact that ALIGNMENT is void* so the next will fit */
- log_assert(aligned_size >= sizeof(struct recycle_elem));
-
- if(CHECK_DOUBLE_FREE) {
- /* make sure the same ptr is not freed twice. */
- struct recycle_elem *p = region->recycle_bin[aligned_size];
- while(p) {
- log_assert(p != elem);
- p = p->next;
- }
- }
-
- elem->next = region->recycle_bin[aligned_size];
- region->recycle_bin[aligned_size] = elem;
- region->recycle_size += aligned_size;
- region->unused_space -= aligned_size - size;
- return;
- }
-
- /* a large allocation */
- region->total_allocated -= size;
- --region->large_objects;
- for(i=0; i<region->cleanup_count; i++) {
- while(region->cleanups[i].data == block) {
- /* perform action (deallocator) on block */
- region->cleanups[i].action(block);
- region->cleanups[i].data = NULL;
- /* remove cleanup - move last entry here, check this one again */
- --region->cleanup_count;
- region->cleanups[i].action =
- region->cleanups[region->cleanup_count].action;
- region->cleanups[i].data =
- region->cleanups[region->cleanup_count].data;
- }
- }
-}
-
-void
-region_dump_stats(region_type *region, FILE *out)
-{
- fprintf(out, "%lu objects (%lu small/%lu large), %lu bytes allocated (%lu wasted) in %lu chunks, %lu cleanups, %lu in recyclebin",
- (unsigned long) (region->small_objects + region->large_objects),
- (unsigned long) region->small_objects,
- (unsigned long) region->large_objects,
- (unsigned long) region->total_allocated,
- (unsigned long) region->unused_space,
- (unsigned long) region->chunk_count,
- (unsigned long) region->cleanup_count,
- (unsigned long) region->recycle_size);
- if(1 && region->recycle_bin) {
- /* print details of the recycle bin */
- size_t i;
- for(i=0; i<region->large_object_size; i++) {
- size_t count = 0;
- struct recycle_elem* el = region->recycle_bin[i];
- while(el) {
- count++;
- el = el->next;
- }
- if(i%ALIGNMENT == 0 && i!=0)
- fprintf(out, " %lu", (unsigned long)count);
- }
- }
-}
-
-size_t region_get_recycle_size(region_type* region)
-{
- return region->recycle_size;
-}
-
-/* debug routine, includes here to keep base region-allocator independent */
-#undef ALIGN_UP
-#include "util/log.h"
-void
-region_log_stats(region_type *region)
-{
- char buf[10240], *str=buf;
- int len=0;
- snprintf(str, sizeof(buf), "%lu objects (%lu small/%lu large), %lu bytes allocated (%lu wasted) in %lu chunks, %lu cleanups, %lu in recyclebin%n",
- (unsigned long) (region->small_objects + region->large_objects),
- (unsigned long) region->small_objects,
- (unsigned long) region->large_objects,
- (unsigned long) region->total_allocated,
- (unsigned long) region->unused_space,
- (unsigned long) region->chunk_count,
- (unsigned long) region->cleanup_count,
- (unsigned long) region->recycle_size,
- &len);
- str+=len;
- if(1 && region->recycle_bin) {
- /* print details of the recycle bin */
- size_t i;
- for(i=0; i<region->large_object_size; i++) {
- size_t count = 0;
- struct recycle_elem* el = region->recycle_bin[i];
- while(el) {
- count++;
- el = el->next;
- }
- if(i%ALIGNMENT == 0 && i!=0) {
- snprintf(str, sizeof(buf)-(str-buf), " %lu%n",
- (unsigned long)count, &len);
- str+=len;
- }
- }
- }
- log_info("memory: %s", buf);
-}
-
-size_t
-region_get_mem(region_type* region)
-{
- size_t s = sizeof(*region);
- s += region->total_allocated + region->chunk_size - region->allocated;
- s += region->maximum_cleanup_count * sizeof(cleanup_type);
- if(region->recycle_bin)
- s += sizeof(struct recycle_elem*)*region->large_object_size;
- log_assert(s >= region->chunk_size * region->chunk_count);
- return s;
-}
+++ /dev/null
-/*
- * region-allocator.h -- region based memory allocator.
- *
- * Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
- *
- * Copyright (c) 2007, NLnet Labs. All rights reserved.
- *
- * This software is open source.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the NLNET LABS nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * \file
- * Region allocator. Allocates small portions of of larger chunks.
- */
-
-#ifndef _REGION_ALLOCATOR_H_
-#define _REGION_ALLOCATOR_H_
-
-#include <stdio.h>
-
-/** The region type */
-typedef struct region region_type;
-
-/** Default reasonable size for chunks */
-#define DEFAULT_CHUNK_SIZE 4096
-/** Default size for large objects - allocated outside of chunks. */
-#define DEFAULT_LARGE_OBJECT_SIZE (DEFAULT_CHUNK_SIZE / 8)
-/** Default size for cleanup array initial size. */
-#define DEFAULT_INITIAL_CLEANUP_SIZE 16
-
-/**
- * Create a new region.
- * @param allocator: 'malloc' or another memory allocator.
- * @param deallocator: 'free' or another memory deallocator.
- */
-region_type *region_create(void *(*allocator)(size_t),
- void (*deallocator)(void *));
-
-
-/**
- * Create a new region, with chunk size and large object size.
- * @param allocator: 'malloc' or another memory allocator.
- * @param deallocator: 'free' or another memory deallocator.
- * @param chunk_size: size of chunks to allocate.
- * @param large_object_size:
- * Note that large_object_size must be <= chunk_size.
- * Anything larger than the large object size is individually alloced.
- * large_object_size = chunk_size/8 is reasonable;
- * @param initial_cleanup_size:
- * initial_cleanup_size is the number of prealloced ptrs for cleanups.
- * The cleanups are in a growing array, and it must start larger than zero.
- * @param recycle:
- * If recycle is true, environmentally friendly memory recycling is enabled.
- */
-region_type *region_create_custom(void *(*allocator)(size_t),
- void (*deallocator)(void *),
- size_t chunk_size,
- size_t large_object_size,
- size_t initial_cleanup_size,
- int recycle);
-
-
-/**
- * Destroy REGION. All memory associated with REGION is freed as if
- * region_free_all was called.
- * @param region: to delete.
- */
-void region_destroy(region_type *region);
-
-
-/**
- * Add a cleanup to REGION.
- * @param region: the region.
- * @param action: ACTION will be called with DATA as
- * parameter when the region is freed or destroyed.
- * @param data: argument to action.
- * @return: 0 on failure.
- */
-size_t region_add_cleanup(region_type *region,
- void (*action)(void *),
- void *data);
-
-
-/**
- * Allocate SIZE bytes of memory inside REGION. The memory is
- * deallocated when region_free_all is called for this region.
- * @param region: the region.
- * @param size: number of bytes.
- * @return: pointer to memory allocated.
- */
-void *region_alloc(region_type *region, size_t size);
-
-
-/**
- * Allocate SIZE bytes of memory inside REGION and copy INIT into it.
- * The memory is deallocated when region_free_all is called for this
- * region.
- * @param region: the region.
- * @param init: to copy.
- * @param size: number of bytes.
- * @return: pointer to memory allocated.
- */
-void *region_alloc_init(region_type *region, const void *init, size_t size);
-
-
-/**
- * Allocate SIZE bytes of memory inside REGION that are initialized to
- * 0. The memory is deallocated when region_free_all is called for
- * this region.
- * @param region: the region.
- * @param size: number of bytes.
- * @return: pointer to memory allocated.
- */
-void *region_alloc_zero(region_type *region, size_t size);
-
-
-/**
- * Run the cleanup actions and free all memory associated with REGION.
- * @param region: the region.
- */
-void region_free_all(region_type *region);
-
-
-/**
- * Duplicate STRING and allocate the result in REGION.
- */
-char *region_strdup(region_type *region, const char *string);
-
-/**
- * Recycle an allocated memory block. Pass size used to alloc it.
- * Does nothing if recycling is not enabled for the region.
- * @param region: the region.
- * @param block: pointer to memory from region_alloc call.
- * @param size: number of bytes, same as passed to region_alloc call.
- */
-void region_recycle(region_type *region, void *block, size_t size);
-
-/**
- * Print some REGION statistics to OUT
- */
-void region_dump_stats(region_type *region, FILE *out);
-
-/** get size of recyclebin */
-size_t region_get_recycle_size(region_type* region);
-
-/** Debug print REGION statistics to LOG */
-void region_log_stats(region_type *region);
-
-/** get total memory size in use by region */
-size_t region_get_mem(region_type* region);
-
-#endif /* _REGION_ALLOCATOR_H_ */
/**
* \file
- * Region allocator. Allocates small portions of of larger chunks.
+ * Regional allocator. Allocates small portions of of larger chunks.
*/
#include "config.h"
struct regional*
regional_create()
{
- void *block = malloc(REGIONAL_CHUNK_SIZE);
- if(!block) return NULL;
- return regional_create_custom(block, REGIONAL_CHUNK_SIZE);
+ return regional_create_custom(REGIONAL_CHUNK_SIZE);
}
/** init regional struct with first block */
static void
regional_init(struct regional* r)
{
+ size_t a = ALIGN_UP(sizeof(struct regional), ALIGNMENT);
+ r->data = (char*)r + a;
+ r->available = r->first_size - a;
r->next = NULL;
- r->size = r->first_size;
- r->allocated = ALIGN_UP(sizeof(struct regional), ALIGNMENT);
- r->data = (char*)r;
- r->total_large = 0;
r->large_list = NULL;
+ r->total_large = 0;
}
struct regional*
-regional_create_custom(void* block, size_t size)
+regional_create_custom(size_t size)
{
- struct regional* r = (struct regional*)block;
+ struct regional* r = (struct regional*)malloc(size);
log_assert(sizeof(struct regional) <= size);
+ if(!r) return NULL;
r->first_size = size;
regional_init(r);
return r;
void
regional_destroy(struct regional *r)
{
+ if(!r) return;
regional_free_all(r);
free(r);
}
return s+ALIGNMENT;
}
/* create a new chunk */
- if(r->allocated + a > r->size) {
+ if(a > r->available) {
s = malloc(REGIONAL_CHUNK_SIZE);
if(!s) return NULL;
- *(char**)s = r->data;
- r->data = s;
- r->allocated = ALIGNMENT;
- r->size = REGIONAL_CHUNK_SIZE;
+ *(char**)s = r->next;
+ r->next = (char*)s;
+ r->data = (char*)s + ALIGNMENT;
+ r->available = REGIONAL_CHUNK_SIZE - ALIGNMENT;
}
/* put in this chunk */
- s = r->data + r->allocated;
- r->allocated += a;
+ r->available -= a;
+ s = r->data;
+ r->data += a;
return s;
}
regional_alloc_init(struct regional* r, const void *init, size_t size)
{
void *s = regional_alloc(r, size);
- if(!s)
- return NULL;
+ if(!s) return NULL;
memcpy(s, init, size);
return s;
}
regional_alloc_zero(struct regional *r, size_t size)
{
void *s = regional_alloc(r, size);
- if(!s)
- return NULL;
+ if(!s) return NULL;
memset(s, 0, size);
return s;
}
char *
regional_strdup(struct regional *r, const char *string)
{
- return regional_alloc_init(r, string, strlen(string)+1);
+ return (char*)regional_alloc_init(r, string, strlen(string)+1);
}
/**
void
regional_log_stats(struct regional *r)
{
+ /* some basic assertions put here (non time critical code) */
+ log_assert(ALIGNMENT >= sizeof(char*));
+ log_assert(REGIONAL_CHUNK_SIZE > ALIGNMENT);
+ log_assert(REGIONAL_CHUNK_SIZE-ALIGNMENT > REGIONAL_LARGE_OBJECT_SIZE);
+ log_assert(REGIONAL_CHUNK_SIZE >= sizeof(struct regional));
+ /* debug print */
log_info("regional %u chunks, %u large",
(unsigned)count_chunks(r), (unsigned)count_large(r));
}
/**
* \file
- * Region allocator. Allocates small portions of of larger chunks.
+ * Regional allocator. Allocates small portions of of larger chunks.
+ * Based on region-allocator from NSD, but rewritten to be light.
*
* Different from (nsd) region-allocator.h
* o does not have recycle bin
- * o does not collect stats
+ * o does not collect stats; just enough to answer get_mem() in use.
* o does not keep cleanup list
* o does not have function pointers to setup
* o allocs the regional struct inside the first block.
* o can take a block to create regional from.
+ * o blocks and large allocations are kept on singly linked lists.
*/
#ifndef UTIL_REGIONAL_H_
*/
struct regional
{
- /** next chunk. NULL if first chunk is the only chunk. */
- char* next;
- /** number of bytes allocated in the current chunk. */
- size_t allocated;
- /** initial chunk size */
- size_t first_size;
- /** current chunk size */
- size_t size;
- /** total large size */
- size_t total_large;
/**
- * current chunk
- * can be cast to char** to obtain next chunk pointer.
+ * next chunk. NULL if first chunk is the only chunk.
+ * first inside that chunk is the char* next pointer.
+ * When regional_free_all() has been called this value is NULL.
*/
- char *data;
+ char* next;
/** first large object, cast to char** to obtain next ptr */
char* large_list;
+ /** total large size */
+ size_t total_large;
+ /** initial chunk size */
+ size_t first_size;
+ /** number of bytes available in the current chunk. */
+ size_t available;
+ /** current chunk data position. */
+ char* data;
};
/**
* Create a new regional.
+ * @return: newly allocated regional.
*/
struct regional* regional_create();
/**
* Create a new region, with custom settings.
- * @param block: initial data block
- * The regional returned is allocated in the block (start of it).
- * @param size: length of block.
+ * @param size: length of first block.
+ * @return: newly allocated regional.
*/
-struct regional* regional_create_custom(void* block, size_t size);
+struct regional* regional_create_custom(size_t size);
/**
- * Free all memory associated with REGION. Only keeps the first block with
+ * Free all memory associated with regional. Only keeps the first block with
* the regional inside it.
* @param r: the region.
*/
void regional_destroy(struct regional *r);
/**
- * Allocate SIZE bytes of memory inside REGION. The memory is
+ * Allocate size bytes of memory inside regional. The memory is
* deallocated when region_free_all is called for this region.
* @param r: the region.
* @param size: number of bytes.
void *regional_alloc(struct regional *r, size_t size);
/**
- * Allocate SIZE bytes of memory inside REGION and copy INIT into it.
+ * Allocate size bytes of memory inside regional and copy INIT into it.
* The memory is deallocated when region_free_all is called for this
* region.
* @param r: the region.
void *regional_alloc_init(struct regional* r, const void *init, size_t size);
/**
- * Allocate SIZE bytes of memory inside REGION that are initialized to
+ * Allocate size bytes of memory inside regional that are initialized to
* 0. The memory is deallocated when region_free_all is called for
* this region.
* @param r: the region.
void *regional_alloc_zero(struct regional *r, size_t size);
/**
- * Duplicate STRING and allocate the result in REGION.
+ * Duplicate string and allocate the result in regional.
* @param r: the region.
* @param string: null terminated string.
+ * @return: pointer to memory allocated.
*/
char *regional_strdup(struct regional *r, const char *string);
-/** Debug print REGION statistics to LOG */
+/** Debug print regional statistics to log */
void regional_log_stats(struct regional *r);
/** get total memory size in use by region */
#include "util/data/dname.h"
#include "util/log.h"
#include "util/net_help.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/config_file.h"
int
struct val_anchors* a = (struct val_anchors*)calloc(1, sizeof(*a));
if(!a)
return NULL;
- a->region = region_create(malloc, free);
+ a->region = regional_create();
if(!a->region) {
free(a);
return NULL;
if(!anchors)
return;
free(anchors->tree);
- region_destroy(anchors->region);
+ regional_destroy(anchors->region);
free(anchors);
}
size_t namelen, uint16_t dclass)
{
rbnode_t* r;
- struct trust_anchor* ta = (struct trust_anchor*)region_alloc(
+ struct trust_anchor* ta = (struct trust_anchor*)regional_alloc(
anchors->region, sizeof(struct trust_anchor));
if(!ta)
return NULL;
memset(ta, 0, sizeof(*ta));
ta->node.key = ta;
- ta->name = region_alloc_init(anchors->region, name, namelen);
+ ta->name = regional_alloc_init(anchors->region, name, namelen);
if(!ta->name)
return NULL;
ta->namelabs = namelabs;
anchor_new_ta_key(struct val_anchors* anchors, uint8_t* rdata, size_t rdata_len,
uint16_t type)
{
- struct ta_key* k = (struct ta_key*)region_alloc(anchors->region,
+ struct ta_key* k = (struct ta_key*)regional_alloc(anchors->region,
sizeof(*k));
if(!k)
return NULL;
memset(k, 0, sizeof(*k));
- k->data = region_alloc_init(anchors->region, rdata, rdata_len);
+ k->data = regional_alloc_init(anchors->region, rdata, rdata_len);
if(!k->data)
return NULL;
k->len = rdata_len;
* @return rrset or NULL on error.
*/
static struct ub_packed_rrset_key*
-assemble_it(struct region* region, struct trust_anchor* ta, size_t num,
+assemble_it(struct regional* region, struct trust_anchor* ta, size_t num,
uint16_t type)
{
struct ub_packed_rrset_key* pkey = (struct ub_packed_rrset_key*)
- region_alloc(region, sizeof(*pkey));
+ regional_alloc(region, sizeof(*pkey));
struct packed_rrset_data* pd;
struct ta_key* tk;
size_t i;
if(!pkey)
return NULL;
memset(pkey, 0, sizeof(*pkey));
- pkey->rk.dname = region_alloc_init(region, ta->name, ta->namelen);
+ pkey->rk.dname = regional_alloc_init(region, ta->name, ta->namelen);
if(!pkey->rk.dname)
return NULL;
pkey->rk.rrset_class = htons(ta->dclass);
/* The rrset is build in an uncompressed way. This means it
* cannot be copied in the normal way. */
- pd = (struct packed_rrset_data*)region_alloc(region, sizeof(*pd));
+ pd = (struct packed_rrset_data*)regional_alloc(region, sizeof(*pd));
if(!pd)
return NULL;
memset(pd, 0, sizeof(*pd));
pd->count = num;
pd->trust = rrset_trust_ultimate;
- pd->rr_len = (size_t*)region_alloc(region, num*sizeof(size_t));
+ pd->rr_len = (size_t*)regional_alloc(region, num*sizeof(size_t));
if(!pd->rr_len)
return NULL;
- pd->rr_ttl = (uint32_t*)region_alloc(region, num*sizeof(uint32_t));
+ pd->rr_ttl = (uint32_t*)regional_alloc(region, num*sizeof(uint32_t));
if(!pd->rr_ttl)
return NULL;
- pd->rr_data = (uint8_t**)region_alloc(region, num*sizeof(uint8_t*));
+ pd->rr_data = (uint8_t**)regional_alloc(region, num*sizeof(uint8_t*));
if(!pd->rr_data)
return NULL;
/* fill in rrs */
size_t
anchors_get_mem(struct val_anchors* anchors)
{
- return sizeof(*anchors) + region_get_mem(anchors->region);
+ return sizeof(*anchors) + regional_get_mem(anchors->region);
}
#ifndef VALIDATOR_VAL_ANCHOR_H
#define VALIDATOR_VAL_ANCHOR_H
#include "util/rbtree.h"
-struct region;
+struct regional;
struct trust_anchor;
struct config_file;
struct ub_packed_rrset_key;
*/
struct val_anchors {
/** region where trust anchors are allocated */
- struct region* region;
+ struct regional* region;
/**
* Anchors are store in this tree. Sort order is chosen, so that
* dnames are in nsec-like order. A lookup on class, name will return
struct key_entry_key*
key_cache_obtain(struct key_cache* kcache, uint8_t* name, size_t namelen,
- uint16_t key_class, struct region* region)
+ uint16_t key_class, struct regional* region)
{
uint32_t now = time(NULL);
/* keep looking until we find a nonexpired entry */
struct key_entry_key;
struct key_entry_data;
struct config_file;
-struct region;
+struct regional;
/**
* Key cache
*/
struct key_entry_key* key_cache_obtain(struct key_cache* kcache,
uint8_t* name, size_t namelen, uint16_t key_class,
- struct region* region);
+ struct regional* region);
/**
* Get memory in use by the key cache.
#include "util/data/packed_rrset.h"
#include "util/data/dname.h"
#include "util/storage/lookup3.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/net_help.h"
size_t
}
struct key_entry_key*
-key_entry_copy_toregion(struct key_entry_key* kkey, struct region* region)
+key_entry_copy_toregion(struct key_entry_key* kkey, struct regional* region)
{
struct key_entry_key* newk;
- newk = region_alloc_init(region, kkey, sizeof(*kkey));
+ newk = regional_alloc_init(region, kkey, sizeof(*kkey));
if(!newk)
return NULL;
- newk->name = region_alloc_init(region, kkey->name, kkey->namelen);
+ newk->name = regional_alloc_init(region, kkey->name, kkey->namelen);
if(!newk->name)
return NULL;
newk->entry.key = newk;
struct key_entry_data *d = (struct key_entry_data*)
kkey->entry.data;
struct key_entry_data *newd;
- newd = region_alloc_init(region, d, sizeof(*d));
+ newd = regional_alloc_init(region, d, sizeof(*d));
if(!newd)
return NULL;
/* copy rrset */
if(d->rrset_data) {
- newd->rrset_data = region_alloc_init(region,
+ newd->rrset_data = regional_alloc_init(region,
d->rrset_data,
packed_rrset_sizeof(d->rrset_data));
if(!newd->rrset_data)
/** setup key entry in region */
static int
-key_entry_setup(struct region* region,
+key_entry_setup(struct regional* region,
uint8_t* name, size_t namelen, uint16_t dclass,
struct key_entry_key** k, struct key_entry_data** d)
{
- *k = region_alloc(region, sizeof(**k));
+ *k = regional_alloc(region, sizeof(**k));
if(!*k)
return 0;
memset(*k, 0, sizeof(**k));
(*k)->entry.key = *k;
- (*k)->name = region_alloc_init(region, name, namelen);
+ (*k)->name = regional_alloc_init(region, name, namelen);
if(!(*k)->name)
return 0;
(*k)->namelen = namelen;
(*k)->key_class = dclass;
- *d = region_alloc(region, sizeof(**d));
+ *d = regional_alloc(region, sizeof(**d));
if(!*d)
return 0;
(*k)->entry.data = *d;
}
struct key_entry_key*
-key_entry_create_null(struct region* region,
+key_entry_create_null(struct regional* region,
uint8_t* name, size_t namelen, uint16_t dclass, uint32_t ttl)
{
struct key_entry_key* k;
}
struct key_entry_key*
-key_entry_create_rrset(struct region* region,
+key_entry_create_rrset(struct regional* region,
uint8_t* name, size_t namelen, uint16_t dclass,
struct ub_packed_rrset_key* rrset)
{
d->ttl = rd->ttl + time(NULL);
d->isbad = 0;
d->rrset_type = ntohs(rrset->rk.type);
- d->rrset_data = (struct packed_rrset_data*)region_alloc_init(region,
+ d->rrset_data = (struct packed_rrset_data*)regional_alloc_init(region,
rd, packed_rrset_sizeof(rd));
if(!d->rrset_data)
return NULL;
}
struct key_entry_key*
-key_entry_create_bad(struct region* region,
+key_entry_create_bad(struct regional* region,
uint8_t* name, size_t namelen, uint16_t dclass)
{
struct key_entry_key* k;
}
struct ub_packed_rrset_key*
-key_entry_get_rrset(struct key_entry_key* kkey, struct region* region)
+key_entry_get_rrset(struct key_entry_key* kkey, struct regional* region)
{
struct key_entry_data* d = (struct key_entry_data*)kkey->entry.data;
struct ub_packed_rrset_key* rrk;
struct packed_rrset_data* rrd;
if(!d || !d->rrset_data)
return NULL;
- rrk = region_alloc(region, sizeof(*rrk));
+ rrk = regional_alloc(region, sizeof(*rrk));
if(!rrk)
return NULL;
memset(rrk, 0, sizeof(*rrk));
- rrk->rk.dname = region_alloc_init(region, kkey->name, kkey->namelen);
+ rrk->rk.dname = regional_alloc_init(region, kkey->name, kkey->namelen);
if(!rrk->rk.dname)
return NULL;
rrk->rk.dname_len = kkey->namelen;
rrk->rk.type = htons(d->rrset_type);
rrk->rk.rrset_class = htons(kkey->key_class);
rrk->entry.key = rrk;
- rrd = region_alloc_init(region, d->rrset_data,
+ rrd = regional_alloc_init(region, d->rrset_data,
packed_rrset_sizeof(d->rrset_data));
if(!rrd)
return NULL;
#ifndef VALIDATOR_VAL_KENTRY_H
#define VALIDATOR_VAL_KENTRY_H
struct packed_rrset_data;
-struct region;
+struct regional;
struct ub_packed_rrset_key;
#include "util/storage/lruhash.h"
* @return newly region-allocated entry or NULL on a failure to allocate.
*/
struct key_entry_key* key_entry_copy_toregion(struct key_entry_key* kkey,
- struct region* region);
+ struct regional* region);
/**
* Copy a key entry, malloced.
* @param ttl: what ttl should the key have. relative.
* @return new key entry or NULL on alloc failure
*/
-struct key_entry_key* key_entry_create_null(struct region* region,
+struct key_entry_key* key_entry_create_null(struct regional* region,
uint8_t* name, size_t namelen, uint16_t dclass, uint32_t ttl);
/**
* @param rrset: data for key entry. This is copied to the region.
* @return new key entry or NULL on alloc failure
*/
-struct key_entry_key* key_entry_create_rrset(struct region* region,
+struct key_entry_key* key_entry_create_rrset(struct regional* region,
uint8_t* name, size_t namelen, uint16_t dclass,
struct ub_packed_rrset_key* rrset);
* @param dclass: class of key entry. (host order);
* @return new key entry or NULL on alloc failure
*/
-struct key_entry_key* key_entry_create_bad(struct region* region,
+struct key_entry_key* key_entry_create_bad(struct regional* region,
uint8_t* name, size_t namelen, uint16_t dclass);
/**
* @return rrset copy; if no rrset or alloc error returns NULL.
*/
struct ub_packed_rrset_key* key_entry_get_rrset(struct key_entry_key* kkey,
- struct region* region);
+ struct regional* region);
/**
* Get keysize of the keyentry.
#include "validator/val_nsec3.h"
#include "validator/validator.h"
#include "validator/val_kentry.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/rbtree.h"
#include "util/module.h"
#include "util/net_help.h"
/** perform hash of name */
static int
-nsec3_calc_hash(struct region* region, ldns_buffer* buf,
+nsec3_calc_hash(struct regional* region, ldns_buffer* buf,
struct nsec3_cached_hash* c)
{
int algo = nsec3_get_algo(c->nsec3, c->rr);
#ifdef SHA_DIGEST_LENGTH
case NSEC3_HASH_SHA1:
c->hash_len = SHA_DIGEST_LENGTH;
- c->hash = (uint8_t*)region_alloc(region, c->hash_len);
+ c->hash = (uint8_t*)regional_alloc(region,
+ c->hash_len);
if(!c->hash)
return 0;
(void)SHA1((unsigned char*)ldns_buffer_begin(buf),
/** perform b32 encoding of hash */
static int
-nsec3_calc_b32(struct region* region, ldns_buffer* buf,
+nsec3_calc_b32(struct regional* region, ldns_buffer* buf,
struct nsec3_cached_hash* c)
{
int r;
return 0;
}
c->b32_len = (size_t)r;
- c->b32 = region_alloc_init(region, ldns_buffer_begin(buf), c->b32_len);
+ c->b32 = regional_alloc_init(region, ldns_buffer_begin(buf),
+ c->b32_len);
if(!c->b32)
return 0;
return 1;
}
int
-nsec3_hash_name(rbtree_t* table, struct region* region, ldns_buffer* buf,
+nsec3_hash_name(rbtree_t* table, struct regional* region, ldns_buffer* buf,
struct ub_packed_rrset_key* nsec3, int rr, uint8_t* dname,
size_t dname_len, struct nsec3_cached_hash** hash)
{
return 1;
}
/* create a new entry */
- c = (struct nsec3_cached_hash*)region_alloc(region, sizeof(*c));
+ c = (struct nsec3_cached_hash*)regional_alloc(region, sizeof(*c));
if(!c) return 0;
c->node.key = c;
c->nsec3 = nsec3;
/** allocate a wildcard for the closest encloser */
static uint8_t*
-nsec3_ce_wildcard(struct region* region, uint8_t* ce, size_t celen,
+nsec3_ce_wildcard(struct regional* region, uint8_t* ce, size_t celen,
size_t* len)
{
uint8_t* nm;
if(celen > LDNS_MAX_DOMAINLEN - 2)
return 0; /* too long */
- nm = (uint8_t*)region_alloc(region, celen+2);
+ nm = (uint8_t*)regional_alloc(region, celen+2);
if(!nm) {
log_err("nsec3 wildcard: out of memory");
return 0; /* alloc failure */
#define VALIDATOR_VAL_NSEC3_H
#include "util/rbtree.h"
struct val_env;
-struct region;
+struct regional;
struct module_env;
struct ub_packed_rrset_key;
enum sec_status;
* 0 on a malloc failure.
* -1 if the NSEC3 rr was badly formatted (i.e. formerr).
*/
-int nsec3_hash_name(rbtree_t* table, struct region* region, ldns_buffer* buf,
+int nsec3_hash_name(rbtree_t* table, struct regional* region, ldns_buffer* buf,
struct ub_packed_rrset_key* nsec3, int rr, uint8_t* dname,
size_t dname_len, struct nsec3_cached_hash** hash);
#include "util/rbtree.h"
#include "util/module.h"
#include "util/net_help.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#ifndef HAVE_SSL
#error "Need SSL library to do digital signature cryptography"
return 0; /* DS algorithm and digest do not match */
}
- digest = region_alloc(env->scratch, digestlen);
+ digest = regional_alloc(env->scratch, digestlen);
if(!digest) {
verbose(VERB_DETAIL, "DS fail: out of memory");
return 0; /* mem error */
* @return false on alloc error.
*/
static int
-rrset_canonical(struct region* region, ldns_buffer* buf,
+rrset_canonical(struct regional* region, ldns_buffer* buf,
struct ub_packed_rrset_key* k, uint8_t* sig, size_t siglen,
struct rbtree_t** sortree)
{
struct canon_rr* rrs;
if(!*sortree) {
- *sortree = (struct rbtree_t*)region_alloc(region,
+ *sortree = (struct rbtree_t*)regional_alloc(region,
sizeof(rbtree_t));
if(!*sortree)
return 0;
- rrs = region_alloc(region, sizeof(struct canon_rr)*d->count);
+ rrs = regional_alloc(region, sizeof(struct canon_rr)*d->count);
if(!rrs) {
*sortree = NULL;
return 0;
}
enum sec_status
-dnskey_verify_rrset_sig(struct region* region, ldns_buffer* buf,
+dnskey_verify_rrset_sig(struct regional* region, ldns_buffer* buf,
struct val_env* ve,
struct ub_packed_rrset_key* rrset, struct ub_packed_rrset_key* dnskey,
size_t dnskey_idx, size_t sig_idx,
struct ub_packed_rrset_key;
enum sec_status;
struct rbtree_t;
-struct region;
+struct regional;
/**
* Check if dnskey matches a DS digest
* @return secure if this key signs this signature. unchecked on error or
* bogus if it did not validate.
*/
-enum sec_status dnskey_verify_rrset_sig(struct region* region,
+enum sec_status dnskey_verify_rrset_sig(struct regional* region,
ldns_buffer* buf, struct val_env* ve,
struct ub_packed_rrset_key* rrset, struct ub_packed_rrset_key* dnskey,
size_t dnskey_idx, size_t sig_idx,
#include "util/data/dname.h"
#include "util/net_help.h"
#include "util/module.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
enum val_classification
val_classify_response(uint16_t query_flags, struct query_info* qinf,
ntohs(rrset->rk.type), ntohs(rrset->rk.rrset_class));
sec = dnskeyset_verify_rrset(env, ve, rrset, keys);
verbose(VERB_ALGO, "verify result: %s", sec_status_to_string(sec));
- region_free_all(env->scratch);
+ regional_free_all(env->scratch);
/* update rrset security status
* only improves security status
}
struct key_entry_key*
-val_verify_new_DNSKEYs(struct region* region, struct module_env* env,
+val_verify_new_DNSKEYs(struct regional* region, struct module_env* env,
struct val_env* ve, struct ub_packed_rrset_key* dnskey_rrset,
struct ub_packed_rrset_key* ds_rrset)
{
struct module_env;
struct ub_packed_rrset_key;
struct key_entry_key;
-struct region;
+struct regional;
struct val_anchors;
struct rrset_cache;
enum sec_status;
* this sort of thing is checked before fetching the matching DNSKEY
* rrset.
*/
-struct key_entry_key* val_verify_new_DNSKEYs(struct region* region,
+struct key_entry_key* val_verify_new_DNSKEYs(struct regional* region,
struct module_env* env, struct val_env* ve,
struct ub_packed_rrset_key* dnskey_rrset,
struct ub_packed_rrset_key* ds_rrset);
#include "util/module.h"
#include "util/log.h"
#include "util/net_help.h"
-#include "util/region-allocator.h"
+#include "util/regional.h"
#include "util/config_file.h"
#include "util/fptr_wlist.h"
static struct val_qstate*
val_new(struct module_qstate* qstate, int id)
{
- struct val_qstate* vq = (struct val_qstate*)region_alloc(
+ struct val_qstate* vq = (struct val_qstate*)regional_alloc(
qstate->region, sizeof(*vq));
log_assert(!qstate->minfo[id]);
if(!vq)
if(!qstate->return_msg || qstate->return_rcode != LDNS_RCODE_NOERROR) {
/* create a message to verify */
verbose(VERB_ALGO, "constructing reply for validation");
- vq->orig_msg = (struct dns_msg*)region_alloc(qstate->region,
+ vq->orig_msg = (struct dns_msg*)regional_alloc(qstate->region,
sizeof(struct dns_msg));
if(!vq->orig_msg)
return NULL;
vq->orig_msg->qinfo = qstate->qinfo;
- vq->orig_msg->rep = (struct reply_info*)region_alloc(
+ vq->orig_msg->rep = (struct reply_info*)regional_alloc(
qstate->region, sizeof(struct reply_info));
if(!vq->orig_msg->rep)
return NULL;
}
vq->qchase = qstate->qinfo;
/* chase reply will be an edited (sub)set of the orig msg rrset ptrs */
- vq->chase_reply = region_alloc_init(qstate->region, vq->orig_msg->rep,
+ vq->chase_reply = regional_alloc_init(qstate->region,
+ vq->orig_msg->rep,
sizeof(struct reply_info) - sizeof(struct rrset_ref));
if(!vq->chase_reply)
return NULL;
- vq->chase_reply->rrsets = region_alloc_init(qstate->region,
+ vq->chase_reply->rrsets = regional_alloc_init(qstate->region,
vq->orig_msg->rep->rrsets, sizeof(struct ub_packed_rrset_key*)
* vq->orig_msg->rep->rrset_count);
if(!vq->chase_reply->rrsets)
return;
}
if(dske == NULL) {
- vq->empty_DS_name = region_alloc_init(qstate->region,
+ vq->empty_DS_name = regional_alloc_init(qstate->region,
qinfo->qname, qinfo->qname_len);
if(!vq->empty_DS_name) {
log_err("malloc failure in empty_DS_name");