NetBSD/external/bsd/nsd/dist/region-allocator.c

564 lines
14 KiB
C
Raw Permalink Normal View History

2017-01-07 22:41:59 +03:00
/*
* region-allocator.c -- region based memory allocator.
*
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
*
* See LICENSE for the license.
*
*/
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "region-allocator.h"
#include "util.h"
/** This value is enough so that x*y does not overflow if both < than this */
#define REGION_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
#ifdef ALIGNMENT
#undef ALIGNMENT
#endif
NSD 4.1.19 Dec 11, 2017 Bugfixes ignore fallthrough compiler warning in flex EOF rule. Fix warnings emitted by clang for --enable-packed. Alignment is not a problem for x86_64, don't enable packed when the platform requires aligned access. Fix spelling error in xfr-inspect. Fix 3392: Fix regression in 4.1.18 for notify lists with ip4 and ip6 targets. Add test for support of -Wno-address-of-packed-member for --enable-packed. NSD 4.1.18 Nov 30, 2017 Features xfr-inspect, it is not installed, it prints xfr files from /tmp made with 'make xfr-inspect' in the source dir. retry timeout between sending notifies dropped from 15 to 3 sec. NSD sends 16 notifies simultaneously. configure --enable-packed reduces memory usage, at expense of unaligned reads. Saves about 17%. Save memory by selectively allocate precompiled nsec3 hashes, saves about 16% memory. make ip-transparent option work on OpenBSD. Save about 2% memory by changing usage count size in name tree. Fix #2871: Increase number of sockets for xfrd transfers. Bugfixes Fix gcc 7.1.1 warnings. Fix writev compile warning on FreeBSD. Fix #1446: A corrupted zone file "propagates" to good ones. nsd-control zonestatus prints wait time between attempts, for zones that are in that waiting time. Fix collision printout of nsec3 to print name, hash and reverse. Fix #1567: Change crit to err log level for gettimeofday failure. Add defines for compile without syslog. Fix crash for DS query when parent and child zones both configured in nsd.conf and parent zone has not loaded properly. NSD 4.1.17 Jul 21, 2017 Features zone parser parses type AVC (it has TXT format). Fix #1272: use writev to put tcp length field with data for outgoing zone transfer requests. Bugfixes Fix potential null pointer in nsec3 adjustment tree. Fix text format of deletes for CDS and CDNSKEY, single 0 to represent empty base64 or hex string. NSD 4.1.16 Apr 25, 2017 Features zone parser can parse acronyms for algorithms ED25519 and ED448. Fix 1243: Option to make NSD emit really minimal responses, minimal-responses: yes in nsd.conf. Bugfixes Calculate new udb index after growing the array, fix from Chaofeng Liu. Fix missing _t to _type conversion for disable-radix-tree option. Printout serial error with hint it may be too big. Fix 1228: OpenSSL include is not guarded with HAVE_SSL Patch for expire state in multi-master when masters includes broken master, from Manabu Sonoda. minor manpage fix. NSD 4.1.15 Feb 16, 2017 Bugfixes Fix nsd-control and ipv6 only. Squelch zone transfer error address family not supported by protocol at low verbosity levels. Fix #1195: Fix so that NSD fails on non-compliant values for Serial. Fix to rename _t typedefs because POSIX reserves them. Fix that nsec3 hash collisions only reported on verbosity level 3.
2018-02-09 19:52:53 +03:00
#ifndef PACKED_STRUCTS
2017-01-07 22:41:59 +03:00
#define REGION_ALIGN_UP(x, s) (((x) + s - 1) & (~(s - 1)))
#if SIZEOF_OFF_T > SIZEOF_VOIDP
#define ALIGNMENT (sizeof(off_t))
#else
#define ALIGNMENT (sizeof(void *))
#endif
NSD 4.1.19 Dec 11, 2017 Bugfixes ignore fallthrough compiler warning in flex EOF rule. Fix warnings emitted by clang for --enable-packed. Alignment is not a problem for x86_64, don't enable packed when the platform requires aligned access. Fix spelling error in xfr-inspect. Fix 3392: Fix regression in 4.1.18 for notify lists with ip4 and ip6 targets. Add test for support of -Wno-address-of-packed-member for --enable-packed. NSD 4.1.18 Nov 30, 2017 Features xfr-inspect, it is not installed, it prints xfr files from /tmp made with 'make xfr-inspect' in the source dir. retry timeout between sending notifies dropped from 15 to 3 sec. NSD sends 16 notifies simultaneously. configure --enable-packed reduces memory usage, at expense of unaligned reads. Saves about 17%. Save memory by selectively allocate precompiled nsec3 hashes, saves about 16% memory. make ip-transparent option work on OpenBSD. Save about 2% memory by changing usage count size in name tree. Fix #2871: Increase number of sockets for xfrd transfers. Bugfixes Fix gcc 7.1.1 warnings. Fix writev compile warning on FreeBSD. Fix #1446: A corrupted zone file "propagates" to good ones. nsd-control zonestatus prints wait time between attempts, for zones that are in that waiting time. Fix collision printout of nsec3 to print name, hash and reverse. Fix #1567: Change crit to err log level for gettimeofday failure. Add defines for compile without syslog. Fix crash for DS query when parent and child zones both configured in nsd.conf and parent zone has not loaded properly. NSD 4.1.17 Jul 21, 2017 Features zone parser parses type AVC (it has TXT format). Fix #1272: use writev to put tcp length field with data for outgoing zone transfer requests. Bugfixes Fix potential null pointer in nsec3 adjustment tree. Fix text format of deletes for CDS and CDNSKEY, single 0 to represent empty base64 or hex string. NSD 4.1.16 Apr 25, 2017 Features zone parser can parse acronyms for algorithms ED25519 and ED448. Fix 1243: Option to make NSD emit really minimal responses, minimal-responses: yes in nsd.conf. Bugfixes Calculate new udb index after growing the array, fix from Chaofeng Liu. Fix missing _t to _type conversion for disable-radix-tree option. Printout serial error with hint it may be too big. Fix 1228: OpenSSL include is not guarded with HAVE_SSL Patch for expire state in multi-master when masters includes broken master, from Manabu Sonoda. minor manpage fix. NSD 4.1.15 Feb 16, 2017 Bugfixes Fix nsd-control and ipv6 only. Squelch zone transfer error address family not supported by protocol at low verbosity levels. Fix #1195: Fix so that NSD fails on non-compliant values for Serial. Fix to rename _t typedefs because POSIX reserves them. Fix that nsec3 hash collisions only reported on verbosity level 3.
2018-02-09 19:52:53 +03:00
#else
#define REGION_ALIGN_UP(x, s) ((x)<SIZEOF_VOIDP?SIZEOF_VOIDP:(x))
#define ALIGNMENT 1
#endif /* PACKED_STRUCTS */
2017-01-07 22:41:59 +03:00
/* #define CHECK_DOUBLE_FREE 0 */ /* set to 1 to perform expensive check for double recycle() */
typedef struct cleanup cleanup_type;
struct cleanup
{
void (*action)(void *);
void *data;
};
struct recycle_elem {
struct recycle_elem* next;
};
struct large_elem {
struct large_elem* next;
struct large_elem* prev;
};
struct region
{
size_t total_allocated;
size_t small_objects;
size_t large_objects;
size_t chunk_count;
size_t unused_space; /* Unused space due to alignment, etc. */
size_t allocated;
char *initial_data;
char *data;
void *(*allocator)(size_t);
void (*deallocator)(void *);
size_t maximum_cleanup_count;
size_t cleanup_count;
cleanup_type *cleanups;
struct large_elem* large_list;
size_t chunk_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;
};
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->large_list = NULL;
result->allocated = 0;
result->data = NULL;
result->initial_data = NULL;
result->allocator = allocator;
result->deallocator = deallocator;
assert(initial_cleanup_count > 0);
result->maximum_cleanup_count = initial_cleanup_count;
result->cleanup_count = 0;
result->cleanups = (cleanup_type *) allocator(
result->maximum_cleanup_count * sizeof(cleanup_type));
if (!result->cleanups) {
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 size),
void (*deallocator)(void *))
{
region_type* result = alloc_region_base(allocator, deallocator,
DEFAULT_INITIAL_CLEANUP_SIZE);
if(!result)
return NULL;
result->data = (char *) allocator(result->chunk_size);
if (!result->data) {
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 = alloc_region_base(allocator, deallocator,
initial_cleanup_size);
if(!result)
return NULL;
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) {
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;
region_free_all(region);
deallocator(region->cleanups);
deallocator(region->initial_data);
if(region->recycle_bin)
deallocator(region->recycle_bin);
if(region->large_list) {
struct large_elem* p = region->large_list, *np;
while(p) {
np = p->next;
deallocator(p);
p = np;
}
}
deallocator(region);
}
size_t
region_add_cleanup(region_type *region, void (*action)(void *), void *data)
{
assert(action);
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));
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_remove_cleanup(region_type *region, void (*action)(void *), void *data)
{
size_t i;
for(i=0; i<region->cleanup_count; i++) {
if(region->cleanups[i].action == action &&
region->cleanups[i].data == data) {
region->cleanup_count--;
region->cleanups[i] =
region->cleanups[region->cleanup_count];
return;
}
}
}
void *
region_alloc(region_type *region, size_t size)
{
size_t aligned_size;
void *result;
if (size == 0) {
size = 1;
}
aligned_size = REGION_ALIGN_UP(size, ALIGNMENT);
if (aligned_size >= region->large_object_size) {
result = region->allocator(size + sizeof(struct large_elem));
if (!result)
return NULL;
((struct large_elem*)result)->prev = NULL;
((struct large_elem*)result)->next = region->large_list;
if(region->large_list)
region->large_list->prev = (struct large_elem*)result;
region->large_list = (struct large_elem*)result;
region->total_allocated += size;
++region->large_objects;
Import 4.3.5: 19 January 2021: Wouter - Set branch ready for 4.3.5 release. Tag for 4.3.5rc1. Became the 4.3.5 release on 26 january 2021. This branch continues with 4.3.6 in development. 15 January 2021: Wouter - Fix #152: '*' in Rdata causes the return code to be NOERROR instead of NX. - Add config.guess and config.sub to .gitignore for autoconf 2.70. - Fix #150: TXT record validation difference with BIND. - Fixup TXT record validation fix for escaped quotes. - Fixup TXT record validation fix for escaped backslashes. - Fixup escape character parse for quoted strings. 11 January 2021: Wouter - Fix #151: DNAME not applied more than once to resolve the query. - Fix dname test for #148. - For #151: fix to not produce loops in output. 5 January 2021: Wouter - Fix configure.ac for autoconf 2.70. 4 January 2021: Wouter - Fix #148: CNAME need not be followed after a synthesized CNAME for a CNAME query. 11 December 2020: Wouter - Fix that nsd-control has timeout when connection is down. - remove windows socket ifdefs from nsd-control. 3 December 2020: Wouter - For #145: Fix that service of remaining TCP and TLS connections does not allow new queries to be made, the connection is closed. Only existing queries and zone transfers are answered, new ones are rejected by a close of the channel. 30 November 2020: Wouter - Fix #144: fix better. 27 November 2020: Wouter - Fix #144: Typo fix in nsd.conf.5.in. 26 November 2020: Wouter - Fix #143: xfrd no hysteresis with NOT IMPLEMENTED rcode. 24 November 2020: Wouter - Merge PR #141: ZONEMD RR type. - tag for 4.3.4rc1. This became 4.3.4 release on 1 dec 2020. The code repo continues for 4.3.5 in development. 23 November 2020: Wouter - Fix #142: NODATA answers missin SOA in authority section after CNAME chain. - Fix for CVE-2020-28935 : Fix that symlink does not interfere with chown of pidfile. - fix writepid for retvalue 0. 9 November 2020: Wouter - Fix #138: NSD returns non-EDNS answer when QUESTION is empty. - Fix to check nscount in previous fix for EDNS in formerr response when there is no question. 28 October 2020: Wouter - Remove unused init_cfg_parse routine from configlexer. 20 October 2020: Wouter - Fix to add missing closest encloser NSEC3 for wildcard nodata type DS answer. 14 October 2020: Wouter - Fix #134: IPV4_MINIMAL_RESPONSE_SIZE vs EDNS_MAX_MESSAGE_LEN. 13 October 2020: Wouter - Fix missing parenthesis on size of fix to init buffer. 12 October 2020: Wouter - Fix #127: two minor `-Wcast-qual` cleanups - Fix #126: minor header hygiene - Fix #125: include config.h in compat/setproctitle.c and fix prototype of `setproctitle` - Fix #133: fix 0-init of local ( stack ) buffer. 8 October 2020: Wouter - tag for 4.3.3 release - current repository contains 4.3.4 in development. - Fix #129: ambiguous use of errno, in log message if sendmmsg fails. - Fix #128: Fix that the invalid port number is logged for sendmmsg failed: Invalid argument. 1 October 2020: Wouter - tag for 4.3.3rc1 release. 30 September 2020: Wouter - Updated date in nsd -v output. - Fixup bug013_truncate, checkconf and cutest_qroot tests for new default EDNS size. 29 September 2020: Willem - Follow DNS flag day 2020 advice and set default EDNS message size to 1232. 4 September 2020: Wouter - Remove unused space from LIBS on link line. 3 September 2020: Wouter - Merge PR #121: Increase log level of recreated database from WARNING to ERR. 1 September 2020: Wouter - Fix #119: fix compile warnings from new gcc. - Fix #119: warn when trying to parse a directory. 27 August 2020: Wouter - Merged PR #113 with fixes. Instead of listing an IP-address to listen on, an interface name can be specified in nsd.conf, with ip-address: eth0. The IP-addresses for that interface are then used. 26 August 2020: Wouter - Add xstrdup for PR #113. - Tidy up code like in PR #113. - Import code from PR #113. - Fix for unknown EVP_MAC_CTX_free function in openssl 3.0.0 tsig code. 24 August 2020: Wouter - Fix that configure checks for EVP_sha256 to detect openssl, because HMAC_CTX_new is deprecated in 3.0.0. - Port TSIG code for openssl 3.0.0-alpha6. - Sync acx_nlnetlabs.m4 with the unbound repo. - Review fixes for tsig, defensive free and zero. 4 August 2020: Wouter - Merge #117: mini_event.h (4.3.2 and 4.3.1) on OpenBSD cannot find fd_set - patch. 23 July 2020: Wouter - Merge #115 from millert: Fix strlcpy() usage. From OpenBSD. 15 July 2020: Wouter - Fix make install with --with-pidfile="". 14 July 2020: Wouter - Tag for 4.3.2 release. Master branch contains the next version in development, 4.3.3. 7 July 2020: Wouter - Tag for 4.3.2rc1. 6 July 2020: Wouter - Fix compile includes for xfr-inspect tool on FreeBSD. - Add tpkg/run_vm.sh that runs test when in a virtual machine. - Merge #112 from jaredmauch: log old and new serials when NSD rejects an IXFR due to an old serial number. - Fix bug034 test for vm test changes. 22 June 2020: Wouter - Remove errno reset behaviour from sendmmsg and recvmmsg replacement functions. - Fix unit test for different nsd-control-setup -h exit code. 19 June 2020: Wouter - Merge #108 from Nomis: Make the max-retry-time description clearer. - Retry when udp send buffer is full to wait until buffer space is available. 18 June 2020: Wouter - Do not log EAGAIN errors for sendmmsg, to stop log spam on OpenBSD. 17 June 2020: Wouter - Fix #107: nsd -v shows configure line, openssl version and libevent version. 27 May 2020: Wouter - Fix unlink of pidfile warning if not possible due to permissions, nsd can display the message at high verbosity levels. - Update contrib/nsd.service for chown of nsd.log and /var/log in ReadWritePaths. - Removed contrib/nsd.service, example is too complicated and not useful. 15 May 2020: Wouter - Merge PR#102 from and0x000: add missing default in documentation for drop-updates. - Fix checkconf test for log-only-syslog option. 14 May 2020: Wouter - Document default value for tcp-timeout. 13 May 2020: Jeroen - Fix #99: Fix copying of socket properties with reuseport enabled. 24 April 2020: Wouter - Fix #97: EDNS unknown version: query not in response. 21 April 2020: Wouter - Fix #96: log-only-syslog: yes sets to only use syslog, fixes that the default configuration and systemd results in duplicate log messages. 20 April 2020: Wouter - Fix #95: Removed make test check because tpkg not included in release tarballs. - Fix unused parameter compile warnings. 16 April 2020: Wouter - Tag for 4.3.1 release and track 4.3.2 release in code repository. - note sha256 digest algo use in makedist.sh. - Fix for posix shell syntax for trap in nsd-control-setup. - Fix to omit the listen-on lines from log at startup, unless verbose. - Fix uninitialised values for bindtodevice option at startup with reuseport and multiple interfaces. 8 April 2020: Wouter - Tag for 4.3.1rc2. 7 April 2020: Wouter - Merge PR #91 by gearnode: nsd-control-setup recreate certificates. The '-r' option recreates certificates. Without it it creates them if they do not exist, and does not modify them otherwise. 6 April 2020: Wouter - Merge PR #90 by phicoh: O_CLOEXEC should be FD_CLOEXEC. - Merge PR #92 by tonysgi: Fix typo. 2 April 2020: Wouter - Tag for 4.3.1rc1. 1 April 2020: Wouter - Fix for whitespace in minimal responses test for FreeBSD. 25 March 2020: Wouter - Merge PR #86 from noloader: Use precious variables for GREP, EGREP, SED, AWK, LEX and YACC. - For PR #86: Fix that programs loaded after CFLAGS and stuff is set, specifically the compiler, so that it can work if it needs special flags from that. Fix that lex only needs to support -i if actually defined, otherwise the output included in the source tarball can be used. - Merge PR #72 from noloader: Increase Travis testing coverage 23 March 2020: Wouter - Fix unterminated ifdef in nsd.h. - Fix unknown u_long in util.c for Issue #80 . 20 March 2020: Wouter - Merge PR #83 from noloader: Fix GNU HURD sched_setaffinity compile. - Fix #82: print error when system does not have setaffinity. - Fix #80: NetBSD and implicit declaration of reallocarray. - Fix for #80: Fix reallocarray test to define before include. - Fix for #80: Define alternatives for IFNAMSIZ if it does not exist. 19 March 2020: Wouter - Fix #76: cpuid typedef for Hurd, DragonflyBSD compile. - Fix #75: configure test for sched_setaffinity, and use cpuset_setaffinity otherwise. Also test for presence of sysconf. - Fix #74: GNU Hurd fix cast from pointer to integer of different size. - Fix for #74, #75: cpuset test for header contents and provide code. - Fix #78: Fix SO_SETFIB error on FreeBSD. 18 March 2020: Wouter - Fix #70: error: 'fd_set' undeclared. - Fix #71: error: 'for' loop initial declaration used outside C99 mode. - Fix to move declarations out of for loops in event test too. - Fix to move declarations out of for loops in popen3 test too. - Another fix to move declaration out of for loop for event test. - Fix to move declarations out of for loops in cutest regex display. 17 March 2020: Wouter - tag for 4.3.0 release and master branch has version 4.3.1. 10 March 2020: Wouter - repository has version number 4.3.0. Tag for 4.3.0rc1. 3 March 2020: Wouter - Fix that the retry wait does not exceed one day for zone transfers. 27 February 2020: Wouter - Fix warning on FreeBSD about pointer size cast. 26 February 2020: Wouter - Fixup fix of reuseport TCP for server close of sockets not used by it. And the unit test skips when the necessary debug output is not enabled. 25 February 2020: Wouter - Fix event unit test, signal has to be registered with signal_add, event_add not for every backend for signals. The event_initialized is not possible for every backend, so event_added variable. The agent write event fires after a timeout, instead of on event write so that it does not trigger a sigpipe event when the handlers stop. Timeout shorted to 0.1 second. event_get_fd was not implemented, so used ev_fd. Debug output printfs added to see what happens. - Fix checkconf test for new drop-updates config option. - Fix errors with reuseport and TCP file descriptors, it was closing them for server-1 in server-2 and server-3.. 7 February 2020: Jeroen - Add feature to drop queries with opcode UPDATE. 6 February 2020: Jeroen - Support SO_BINDTODEVICE on Linux. Specify bindtodevice: yes to bind sockets directly to the network interface. - Support SO_SETFIB on FreeBSD. Add setfib=<FIB> after an ip-address option to use the specified FIB for that socket. - Require user to add servers=<range> after an ip-address option to specify the servers that must listen on that socket. 6 February 2020: Wouter - Merge PR#60: Minor portability fixes from michaelforney, with avoid pointer arithmetic on void* and avoid unnecessary VLA. 4 February 2020: Wouter - Merge PR#22: minimise-any: prefer polular and not large RRset, from Daisuke Higashi. - Fix responses for IXFR so that the authority section is not echoed in the response. 21 January 2020: Wouter - Fix leak in server bitset setup. 16 January 2020: Jeroen - Add zone resource record iterator for future zone-verification port. - Set FD_CLOEXEC on opened sockets. - Add popen3 implementation for future zone-verification port. - Add -r option to cutest so that a subset of tests can be run. 15 January 2020: Jeroen - Add feature to pin server proccesses to specific cpus. - Add feature to pin IP addresses to selected server processes. - Set process title to identify individual processes. 13 January 2020: Wouter - Merge pull request #59 from buddyns: add FreeBSD support for conf key ip-transparent. 10 January 2020: Wouter - Fix unreachable code in ssl set options code. - Fix bad shift in assertion code analyzer complaint. 6 January 2020: Wouter - Fix #56: Drop sparse TSIG signing support in NSD. Sign every axfr packet with TSIG, according to the latest draft-ietf-dnsop-rfc2845bis-06, Section 5.3.1. 12 December 2019: Wouter - Note that use-systemd is not necessary and ignored in man page. 11 December 2019: Wouter - Fix whitespace in nsd.conf.sample.in, patch from Paul Wouters. - use-systemd is ignored in nsd.conf, when NSD is compiled with libsystemd it always signals readiness, if possible. 9 December 2019: Wouter - Fix to define upper bounds on rr counts read from untrusted packet data. - Try different annotation for radix_find_prefix_node not reachable. - Separate acl_addr_match_range functions for ip4 and ip6, to please checkers. - Avoid unused variable warning in new match_range_v4 function. 6 December 2019: Wouter - Fix to define max number of EDNS records we are willing to spend time on. - Fix size of string len and capacity type cast in udbradtree. - Fix to protect rrcount in tsig_find_rr from overflow. - Annotate radix_find_prefix_node not reachable trail code. - Fix to protect rrcount in packet_find_notify_serial from overflow. - Fix to close socket on error in create_tcp_accept_sock. - Fix to log on failure to chmod for socket for remote control. - Fix to remove unneeded if in open of socket for remote control. - Fix to restore input parameter on call failure in create_dirs. - Please checker by terminating and initialising string read by remote control. - Fixup of random_generate negative modulo, from previous commit, and return srandom when random is used if no getrandom. 5 December 2019: Wouter - Fix fname null check of fname in namedb_read_zonefile. - Fix implicit cast of size in udb_radnode_array_grow. - Fix ignore of return value of ssl_printf in remote.c. - Fix unused check of fd in parent_handle_reload_command. - Fix to use getrandom() for randomness, if available. - Attempt to fix signedness of nscount lookup in ixfr query_process. - Fix identical branches for ssl_print of errors in remote.c. - Fix type cast bounds, signedness of opt_rdlen in edns_parse_record. - Fix to separate header and data lines in parse_zone_list_file.
2021-03-15 21:38:56 +03:00
return (char *)result + sizeof(struct large_elem);
2017-01-07 22:41:59 +03:00
}
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;
}
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));
NSD 4.1.19 Dec 11, 2017 Bugfixes ignore fallthrough compiler warning in flex EOF rule. Fix warnings emitted by clang for --enable-packed. Alignment is not a problem for x86_64, don't enable packed when the platform requires aligned access. Fix spelling error in xfr-inspect. Fix 3392: Fix regression in 4.1.18 for notify lists with ip4 and ip6 targets. Add test for support of -Wno-address-of-packed-member for --enable-packed. NSD 4.1.18 Nov 30, 2017 Features xfr-inspect, it is not installed, it prints xfr files from /tmp made with 'make xfr-inspect' in the source dir. retry timeout between sending notifies dropped from 15 to 3 sec. NSD sends 16 notifies simultaneously. configure --enable-packed reduces memory usage, at expense of unaligned reads. Saves about 17%. Save memory by selectively allocate precompiled nsec3 hashes, saves about 16% memory. make ip-transparent option work on OpenBSD. Save about 2% memory by changing usage count size in name tree. Fix #2871: Increase number of sockets for xfrd transfers. Bugfixes Fix gcc 7.1.1 warnings. Fix writev compile warning on FreeBSD. Fix #1446: A corrupted zone file "propagates" to good ones. nsd-control zonestatus prints wait time between attempts, for zones that are in that waiting time. Fix collision printout of nsec3 to print name, hash and reverse. Fix #1567: Change crit to err log level for gettimeofday failure. Add defines for compile without syslog. Fix crash for DS query when parent and child zones both configured in nsd.conf and parent zone has not loaded properly. NSD 4.1.17 Jul 21, 2017 Features zone parser parses type AVC (it has TXT format). Fix #1272: use writev to put tcp length field with data for outgoing zone transfer requests. Bugfixes Fix potential null pointer in nsec3 adjustment tree. Fix text format of deletes for CDS and CDNSKEY, single 0 to represent empty base64 or hex string. NSD 4.1.16 Apr 25, 2017 Features zone parser can parse acronyms for algorithms ED25519 and ED448. Fix 1243: Option to make NSD emit really minimal responses, minimal-responses: yes in nsd.conf. Bugfixes Calculate new udb index after growing the array, fix from Chaofeng Liu. Fix missing _t to _type conversion for disable-radix-tree option. Printout serial error with hint it may be too big. Fix 1228: OpenSSL include is not guarded with HAVE_SSL Patch for expire state in multi-master when masters includes broken master, from Manabu Sonoda. minor manpage fix. NSD 4.1.15 Feb 16, 2017 Bugfixes Fix nsd-control and ipv6 only. Squelch zone transfer error address family not supported by protocol at low verbosity levels. Fix #1195: Fix so that NSD fails on non-compliant values for Serial. Fix to rename _t typedefs because POSIX reserves them. Fix that nsec3 hash collisions only reported on verbosity level 3.
2018-02-09 19:52:53 +03:00
if(
#ifndef PACKED_STRUCTS
wasted >= ALIGNMENT
#else
wasted >= SIZEOF_VOIDP
#endif
) {
2017-01-07 22:41:59 +03:00
/* 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;
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_alloc_array_init(region_type *region, const void *init, size_t num,
size_t size)
{
if((num >= REGION_NO_OVERFLOW || size >= REGION_NO_OVERFLOW) &&
num > 0 && SIZE_MAX / num < size) {
log_msg(LOG_ERR, "region_alloc_array_init failed because of integer overflow");
exit(1);
}
return region_alloc_init(region, init, num*size);
}
void *
region_alloc_array_zero(region_type *region, size_t num, size_t size)
{
if((num >= REGION_NO_OVERFLOW || size >= REGION_NO_OVERFLOW) &&
num > 0 && SIZE_MAX / num < size) {
log_msg(LOG_ERR, "region_alloc_array_zero failed because of integer overflow");
exit(1);
}
return region_alloc_zero(region, num*size);
}
void *
region_alloc_array(region_type *region, size_t num, size_t size)
{
if((num >= REGION_NO_OVERFLOW || size >= REGION_NO_OVERFLOW) &&
num > 0 && SIZE_MAX / num < size) {
log_msg(LOG_ERR, "region_alloc_array failed because of integer overflow");
exit(1);
}
return region_alloc(region, num*size);
}
void
region_free_all(region_type *region)
{
size_t i;
assert(region);
assert(region->cleanups);
i = region->cleanup_count;
while (i > 0) {
--i;
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;
}
if(region->large_list) {
struct large_elem* p = region->large_list, *np;
void (*deallocator)(void *) = region->deallocator;
while(p) {
np = p->next;
deallocator(p);
p = np;
}
region->large_list = NULL;
}
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;
if(!block || !region->recycle_bin)
return;
if (size == 0) {
size = 1;
}
aligned_size = REGION_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 */
assert(aligned_size >= sizeof(struct recycle_elem));
#ifdef CHECK_DOUBLE_FREE
if(CHECK_DOUBLE_FREE) {
/* make sure the same ptr is not freed twice. */
struct recycle_elem *p = region->recycle_bin[aligned_size];
while(p) {
assert(p != elem);
p = p->next;
}
}
#endif
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;
} else {
struct large_elem* l;
/* a large allocation */
region->total_allocated -= size;
--region->large_objects;
Import 4.3.5: 19 January 2021: Wouter - Set branch ready for 4.3.5 release. Tag for 4.3.5rc1. Became the 4.3.5 release on 26 january 2021. This branch continues with 4.3.6 in development. 15 January 2021: Wouter - Fix #152: '*' in Rdata causes the return code to be NOERROR instead of NX. - Add config.guess and config.sub to .gitignore for autoconf 2.70. - Fix #150: TXT record validation difference with BIND. - Fixup TXT record validation fix for escaped quotes. - Fixup TXT record validation fix for escaped backslashes. - Fixup escape character parse for quoted strings. 11 January 2021: Wouter - Fix #151: DNAME not applied more than once to resolve the query. - Fix dname test for #148. - For #151: fix to not produce loops in output. 5 January 2021: Wouter - Fix configure.ac for autoconf 2.70. 4 January 2021: Wouter - Fix #148: CNAME need not be followed after a synthesized CNAME for a CNAME query. 11 December 2020: Wouter - Fix that nsd-control has timeout when connection is down. - remove windows socket ifdefs from nsd-control. 3 December 2020: Wouter - For #145: Fix that service of remaining TCP and TLS connections does not allow new queries to be made, the connection is closed. Only existing queries and zone transfers are answered, new ones are rejected by a close of the channel. 30 November 2020: Wouter - Fix #144: fix better. 27 November 2020: Wouter - Fix #144: Typo fix in nsd.conf.5.in. 26 November 2020: Wouter - Fix #143: xfrd no hysteresis with NOT IMPLEMENTED rcode. 24 November 2020: Wouter - Merge PR #141: ZONEMD RR type. - tag for 4.3.4rc1. This became 4.3.4 release on 1 dec 2020. The code repo continues for 4.3.5 in development. 23 November 2020: Wouter - Fix #142: NODATA answers missin SOA in authority section after CNAME chain. - Fix for CVE-2020-28935 : Fix that symlink does not interfere with chown of pidfile. - fix writepid for retvalue 0. 9 November 2020: Wouter - Fix #138: NSD returns non-EDNS answer when QUESTION is empty. - Fix to check nscount in previous fix for EDNS in formerr response when there is no question. 28 October 2020: Wouter - Remove unused init_cfg_parse routine from configlexer. 20 October 2020: Wouter - Fix to add missing closest encloser NSEC3 for wildcard nodata type DS answer. 14 October 2020: Wouter - Fix #134: IPV4_MINIMAL_RESPONSE_SIZE vs EDNS_MAX_MESSAGE_LEN. 13 October 2020: Wouter - Fix missing parenthesis on size of fix to init buffer. 12 October 2020: Wouter - Fix #127: two minor `-Wcast-qual` cleanups - Fix #126: minor header hygiene - Fix #125: include config.h in compat/setproctitle.c and fix prototype of `setproctitle` - Fix #133: fix 0-init of local ( stack ) buffer. 8 October 2020: Wouter - tag for 4.3.3 release - current repository contains 4.3.4 in development. - Fix #129: ambiguous use of errno, in log message if sendmmsg fails. - Fix #128: Fix that the invalid port number is logged for sendmmsg failed: Invalid argument. 1 October 2020: Wouter - tag for 4.3.3rc1 release. 30 September 2020: Wouter - Updated date in nsd -v output. - Fixup bug013_truncate, checkconf and cutest_qroot tests for new default EDNS size. 29 September 2020: Willem - Follow DNS flag day 2020 advice and set default EDNS message size to 1232. 4 September 2020: Wouter - Remove unused space from LIBS on link line. 3 September 2020: Wouter - Merge PR #121: Increase log level of recreated database from WARNING to ERR. 1 September 2020: Wouter - Fix #119: fix compile warnings from new gcc. - Fix #119: warn when trying to parse a directory. 27 August 2020: Wouter - Merged PR #113 with fixes. Instead of listing an IP-address to listen on, an interface name can be specified in nsd.conf, with ip-address: eth0. The IP-addresses for that interface are then used. 26 August 2020: Wouter - Add xstrdup for PR #113. - Tidy up code like in PR #113. - Import code from PR #113. - Fix for unknown EVP_MAC_CTX_free function in openssl 3.0.0 tsig code. 24 August 2020: Wouter - Fix that configure checks for EVP_sha256 to detect openssl, because HMAC_CTX_new is deprecated in 3.0.0. - Port TSIG code for openssl 3.0.0-alpha6. - Sync acx_nlnetlabs.m4 with the unbound repo. - Review fixes for tsig, defensive free and zero. 4 August 2020: Wouter - Merge #117: mini_event.h (4.3.2 and 4.3.1) on OpenBSD cannot find fd_set - patch. 23 July 2020: Wouter - Merge #115 from millert: Fix strlcpy() usage. From OpenBSD. 15 July 2020: Wouter - Fix make install with --with-pidfile="". 14 July 2020: Wouter - Tag for 4.3.2 release. Master branch contains the next version in development, 4.3.3. 7 July 2020: Wouter - Tag for 4.3.2rc1. 6 July 2020: Wouter - Fix compile includes for xfr-inspect tool on FreeBSD. - Add tpkg/run_vm.sh that runs test when in a virtual machine. - Merge #112 from jaredmauch: log old and new serials when NSD rejects an IXFR due to an old serial number. - Fix bug034 test for vm test changes. 22 June 2020: Wouter - Remove errno reset behaviour from sendmmsg and recvmmsg replacement functions. - Fix unit test for different nsd-control-setup -h exit code. 19 June 2020: Wouter - Merge #108 from Nomis: Make the max-retry-time description clearer. - Retry when udp send buffer is full to wait until buffer space is available. 18 June 2020: Wouter - Do not log EAGAIN errors for sendmmsg, to stop log spam on OpenBSD. 17 June 2020: Wouter - Fix #107: nsd -v shows configure line, openssl version and libevent version. 27 May 2020: Wouter - Fix unlink of pidfile warning if not possible due to permissions, nsd can display the message at high verbosity levels. - Update contrib/nsd.service for chown of nsd.log and /var/log in ReadWritePaths. - Removed contrib/nsd.service, example is too complicated and not useful. 15 May 2020: Wouter - Merge PR#102 from and0x000: add missing default in documentation for drop-updates. - Fix checkconf test for log-only-syslog option. 14 May 2020: Wouter - Document default value for tcp-timeout. 13 May 2020: Jeroen - Fix #99: Fix copying of socket properties with reuseport enabled. 24 April 2020: Wouter - Fix #97: EDNS unknown version: query not in response. 21 April 2020: Wouter - Fix #96: log-only-syslog: yes sets to only use syslog, fixes that the default configuration and systemd results in duplicate log messages. 20 April 2020: Wouter - Fix #95: Removed make test check because tpkg not included in release tarballs. - Fix unused parameter compile warnings. 16 April 2020: Wouter - Tag for 4.3.1 release and track 4.3.2 release in code repository. - note sha256 digest algo use in makedist.sh. - Fix for posix shell syntax for trap in nsd-control-setup. - Fix to omit the listen-on lines from log at startup, unless verbose. - Fix uninitialised values for bindtodevice option at startup with reuseport and multiple interfaces. 8 April 2020: Wouter - Tag for 4.3.1rc2. 7 April 2020: Wouter - Merge PR #91 by gearnode: nsd-control-setup recreate certificates. The '-r' option recreates certificates. Without it it creates them if they do not exist, and does not modify them otherwise. 6 April 2020: Wouter - Merge PR #90 by phicoh: O_CLOEXEC should be FD_CLOEXEC. - Merge PR #92 by tonysgi: Fix typo. 2 April 2020: Wouter - Tag for 4.3.1rc1. 1 April 2020: Wouter - Fix for whitespace in minimal responses test for FreeBSD. 25 March 2020: Wouter - Merge PR #86 from noloader: Use precious variables for GREP, EGREP, SED, AWK, LEX and YACC. - For PR #86: Fix that programs loaded after CFLAGS and stuff is set, specifically the compiler, so that it can work if it needs special flags from that. Fix that lex only needs to support -i if actually defined, otherwise the output included in the source tarball can be used. - Merge PR #72 from noloader: Increase Travis testing coverage 23 March 2020: Wouter - Fix unterminated ifdef in nsd.h. - Fix unknown u_long in util.c for Issue #80 . 20 March 2020: Wouter - Merge PR #83 from noloader: Fix GNU HURD sched_setaffinity compile. - Fix #82: print error when system does not have setaffinity. - Fix #80: NetBSD and implicit declaration of reallocarray. - Fix for #80: Fix reallocarray test to define before include. - Fix for #80: Define alternatives for IFNAMSIZ if it does not exist. 19 March 2020: Wouter - Fix #76: cpuid typedef for Hurd, DragonflyBSD compile. - Fix #75: configure test for sched_setaffinity, and use cpuset_setaffinity otherwise. Also test for presence of sysconf. - Fix #74: GNU Hurd fix cast from pointer to integer of different size. - Fix for #74, #75: cpuset test for header contents and provide code. - Fix #78: Fix SO_SETFIB error on FreeBSD. 18 March 2020: Wouter - Fix #70: error: 'fd_set' undeclared. - Fix #71: error: 'for' loop initial declaration used outside C99 mode. - Fix to move declarations out of for loops in event test too. - Fix to move declarations out of for loops in popen3 test too. - Another fix to move declaration out of for loop for event test. - Fix to move declarations out of for loops in cutest regex display. 17 March 2020: Wouter - tag for 4.3.0 release and master branch has version 4.3.1. 10 March 2020: Wouter - repository has version number 4.3.0. Tag for 4.3.0rc1. 3 March 2020: Wouter - Fix that the retry wait does not exceed one day for zone transfers. 27 February 2020: Wouter - Fix warning on FreeBSD about pointer size cast. 26 February 2020: Wouter - Fixup fix of reuseport TCP for server close of sockets not used by it. And the unit test skips when the necessary debug output is not enabled. 25 February 2020: Wouter - Fix event unit test, signal has to be registered with signal_add, event_add not for every backend for signals. The event_initialized is not possible for every backend, so event_added variable. The agent write event fires after a timeout, instead of on event write so that it does not trigger a sigpipe event when the handlers stop. Timeout shorted to 0.1 second. event_get_fd was not implemented, so used ev_fd. Debug output printfs added to see what happens. - Fix checkconf test for new drop-updates config option. - Fix errors with reuseport and TCP file descriptors, it was closing them for server-1 in server-2 and server-3.. 7 February 2020: Jeroen - Add feature to drop queries with opcode UPDATE. 6 February 2020: Jeroen - Support SO_BINDTODEVICE on Linux. Specify bindtodevice: yes to bind sockets directly to the network interface. - Support SO_SETFIB on FreeBSD. Add setfib=<FIB> after an ip-address option to use the specified FIB for that socket. - Require user to add servers=<range> after an ip-address option to specify the servers that must listen on that socket. 6 February 2020: Wouter - Merge PR#60: Minor portability fixes from michaelforney, with avoid pointer arithmetic on void* and avoid unnecessary VLA. 4 February 2020: Wouter - Merge PR#22: minimise-any: prefer polular and not large RRset, from Daisuke Higashi. - Fix responses for IXFR so that the authority section is not echoed in the response. 21 January 2020: Wouter - Fix leak in server bitset setup. 16 January 2020: Jeroen - Add zone resource record iterator for future zone-verification port. - Set FD_CLOEXEC on opened sockets. - Add popen3 implementation for future zone-verification port. - Add -r option to cutest so that a subset of tests can be run. 15 January 2020: Jeroen - Add feature to pin server proccesses to specific cpus. - Add feature to pin IP addresses to selected server processes. - Set process title to identify individual processes. 13 January 2020: Wouter - Merge pull request #59 from buddyns: add FreeBSD support for conf key ip-transparent. 10 January 2020: Wouter - Fix unreachable code in ssl set options code. - Fix bad shift in assertion code analyzer complaint. 6 January 2020: Wouter - Fix #56: Drop sparse TSIG signing support in NSD. Sign every axfr packet with TSIG, according to the latest draft-ietf-dnsop-rfc2845bis-06, Section 5.3.1. 12 December 2019: Wouter - Note that use-systemd is not necessary and ignored in man page. 11 December 2019: Wouter - Fix whitespace in nsd.conf.sample.in, patch from Paul Wouters. - use-systemd is ignored in nsd.conf, when NSD is compiled with libsystemd it always signals readiness, if possible. 9 December 2019: Wouter - Fix to define upper bounds on rr counts read from untrusted packet data. - Try different annotation for radix_find_prefix_node not reachable. - Separate acl_addr_match_range functions for ip4 and ip6, to please checkers. - Avoid unused variable warning in new match_range_v4 function. 6 December 2019: Wouter - Fix to define max number of EDNS records we are willing to spend time on. - Fix size of string len and capacity type cast in udbradtree. - Fix to protect rrcount in tsig_find_rr from overflow. - Annotate radix_find_prefix_node not reachable trail code. - Fix to protect rrcount in packet_find_notify_serial from overflow. - Fix to close socket on error in create_tcp_accept_sock. - Fix to log on failure to chmod for socket for remote control. - Fix to remove unneeded if in open of socket for remote control. - Fix to restore input parameter on call failure in create_dirs. - Please checker by terminating and initialising string read by remote control. - Fixup of random_generate negative modulo, from previous commit, and return srandom when random is used if no getrandom. 5 December 2019: Wouter - Fix fname null check of fname in namedb_read_zonefile. - Fix implicit cast of size in udb_radnode_array_grow. - Fix ignore of return value of ssl_printf in remote.c. - Fix unused check of fd in parent_handle_reload_command. - Fix to use getrandom() for randomness, if available. - Attempt to fix signedness of nscount lookup in ixfr query_process. - Fix identical branches for ssl_print of errors in remote.c. - Fix type cast bounds, signedness of opt_rdlen in edns_parse_record. - Fix to separate header and data lines in parse_zone_list_file.
2021-03-15 21:38:56 +03:00
l = (struct large_elem*)((char*)block-sizeof(struct large_elem));
2017-01-07 22:41:59 +03:00
if(l->prev)
l->prev->next = l->next;
else region->large_list = l->next;
if(l->next)
l->next->prev = l->prev;
region->deallocator(l);
}
}
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);
19 March 2019: Wouter - tag 4.1.27rc1 18 March 2019: Wouter - Fix unit test bug013_truncate for new truncation with EDNS size, it is one RR smaller for the truncated response in the test. 14 March 2019: Wouter - Fixed radtree_insert memory leak. - Fixed access recycled variable. 11 March 2019: Wouter - Fix #6: nsd-control-setup: Change validity time to a shorter period (<2038). - Fix unused definition in header remote.h. - Fix #4236: IPV4_MINIMAL_RESPONSE_SIZE=1480 is slightly too big. - Fix #4235: IP_PMTUDISC_OMIT on IPv4/UDP sockets. 18 February 2019: Wouter - Fix to remove unused code. 15 February 2019: Wouter - tentative robustness, delete stats items from list twice if needed. 14 February 2019: Wouter - Fix #4: setusercontext() is in libutil on NetBSD, and also include login_cap.h only if it exists. - Fix #4215: fixup for state update for TSIG information in server processes, nicer printout for tsig_print, tsig_print without arguments and no leaks. - nicer logging for update_tsig. 1 February 2019: Wouter - Fix for tsig assoc_tsig command on acl with nokey elements. 29 January 2019: Wouter - Fix #4215: on-the-fly change of TSIG keys with patch from Igor, adds nsd-control print_tsig, update_tsig, add_tsig, assoc_tsig and del_tsig. These changes are gone after reload, edit the config file (or a file included from it) to make changes that last after restart. - documentation for tsig nsd-control options. 24 January 2019: Wouter - Deny ANY with only one RR in response, by default. Patch from Daisuke Higashi. The deny-any statement in nsd.conf sets ANY queries over UDP to be further moved to TCP as well. Also no additional section processig for type ANY, reducing the response size. - assertions for clang analysis. 10 December 2018: Wouter - Fix for FreeBSD port with dnstap enabled. 6 December 2018: Wouter - Fix to reduce region_log_stats if condition, this removes a debug statement. 5 December 2018: Wouter - Fix #4213: disable-ipv6 and dnstap compile error. 3 December 2018: Wouter - Note that the content_list member is unused; and could be removed if the database format is modified or updated. - Fix that dnstap logs CQ and CR like BIND does. - Revert that, it looks wrong, AQ and AR are for the authoritative.
2019-05-25 22:44:43 +03:00
if(region->recycle_bin) {
2017-01-07 22:41:59 +03:00
/* 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;
}
size_t region_get_mem(region_type* region)
{
return region->total_allocated;
}
size_t region_get_mem_unused(region_type* region)
{
return region->unused_space;
}
/* debug routine */
void
region_log_stats(region_type *region)
{
char buf[10240], *str=buf;
int strl = sizeof(buf);
int len;
snprintf(str, strl, "%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);
len = strlen(str);
str+=len;
strl-=len;
19 March 2019: Wouter - tag 4.1.27rc1 18 March 2019: Wouter - Fix unit test bug013_truncate for new truncation with EDNS size, it is one RR smaller for the truncated response in the test. 14 March 2019: Wouter - Fixed radtree_insert memory leak. - Fixed access recycled variable. 11 March 2019: Wouter - Fix #6: nsd-control-setup: Change validity time to a shorter period (<2038). - Fix unused definition in header remote.h. - Fix #4236: IPV4_MINIMAL_RESPONSE_SIZE=1480 is slightly too big. - Fix #4235: IP_PMTUDISC_OMIT on IPv4/UDP sockets. 18 February 2019: Wouter - Fix to remove unused code. 15 February 2019: Wouter - tentative robustness, delete stats items from list twice if needed. 14 February 2019: Wouter - Fix #4: setusercontext() is in libutil on NetBSD, and also include login_cap.h only if it exists. - Fix #4215: fixup for state update for TSIG information in server processes, nicer printout for tsig_print, tsig_print without arguments and no leaks. - nicer logging for update_tsig. 1 February 2019: Wouter - Fix for tsig assoc_tsig command on acl with nokey elements. 29 January 2019: Wouter - Fix #4215: on-the-fly change of TSIG keys with patch from Igor, adds nsd-control print_tsig, update_tsig, add_tsig, assoc_tsig and del_tsig. These changes are gone after reload, edit the config file (or a file included from it) to make changes that last after restart. - documentation for tsig nsd-control options. 24 January 2019: Wouter - Deny ANY with only one RR in response, by default. Patch from Daisuke Higashi. The deny-any statement in nsd.conf sets ANY queries over UDP to be further moved to TCP as well. Also no additional section processig for type ANY, reducing the response size. - assertions for clang analysis. 10 December 2018: Wouter - Fix for FreeBSD port with dnstap enabled. 6 December 2018: Wouter - Fix to reduce region_log_stats if condition, this removes a debug statement. 5 December 2018: Wouter - Fix #4213: disable-ipv6 and dnstap compile error. 3 December 2018: Wouter - Note that the content_list member is unused; and could be removed if the database format is modified or updated. - Fix that dnstap logs CQ and CR like BIND does. - Revert that, it looks wrong, AQ and AR are for the authoritative.
2019-05-25 22:44:43 +03:00
if(region->recycle_bin) {
2017-01-07 22:41:59 +03:00
/* 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, strl, " %lu", (unsigned long)count);
len = strlen(str);
str+=len;
strl-=len;
}
}
}
log_msg(LOG_INFO, "memory: %s", buf);
}