"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/blockdata.c" between
dnsmasq-2.80.tar.gz and dnsmasq-2.81.tar.xz

About: Dnsmasq is a lightweight caching DNS forwarder and DHCP server.

blockdata.c  (dnsmasq-2.80):blockdata.c  (dnsmasq-2.81.tar.xz)
/* dnsmasq is Copyright (c) 2000-2018 Simon Kelley /* dnsmasq is Copyright (c) 2000-2020 Simon Kelley
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991, or the Free Software Foundation; version 2 dated June, 1991, or
(at your option) version 3 dated 29 June, 2007. (at your option) version 3 dated 29 June, 2007.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dnsmasq.h" #include "dnsmasq.h"
#ifdef HAVE_DNSSEC
static struct blockdata *keyblock_free; static struct blockdata *keyblock_free;
static unsigned int blockdata_count, blockdata_hwm, blockdata_alloced; static unsigned int blockdata_count, blockdata_hwm, blockdata_alloced;
static void blockdata_expand(int n) static void blockdata_expand(int n)
{ {
struct blockdata *new = whine_malloc(n * sizeof(struct blockdata)); struct blockdata *new = whine_malloc(n * sizeof(struct blockdata));
if (new) if (new)
{ {
int i; int i;
skipping to change at line 57 skipping to change at line 55
blockdata_count = 0; blockdata_count = 0;
blockdata_hwm = 0; blockdata_hwm = 0;
/* Note that daemon->cachesize is enforced to have non-zero size if OPT_DNSSEC _VALID is set */ /* Note that daemon->cachesize is enforced to have non-zero size if OPT_DNSSEC _VALID is set */
if (option_bool(OPT_DNSSEC_VALID)) if (option_bool(OPT_DNSSEC_VALID))
blockdata_expand(daemon->cachesize); blockdata_expand(daemon->cachesize);
} }
void blockdata_report(void) void blockdata_report(void)
{ {
if (option_bool(OPT_DNSSEC_VALID)) my_syslog(LOG_INFO, _("pool memory in use %u, max %u, allocated %u"),
my_syslog(LOG_INFO, _("DNSSEC memory in use %u, max %u, allocated %u"), blockdata_count * sizeof(struct blockdata),
blockdata_count * sizeof(struct blockdata), blockdata_hwm * sizeof(struct blockdata),
blockdata_hwm * sizeof(struct blockdata), blockdata_alloced * sizeof(struct blockdata));
blockdata_alloced * sizeof(struct blockdata));
} }
struct blockdata *blockdata_alloc(char *data, size_t len) static struct blockdata *blockdata_alloc_real(int fd, char *data, size_t len)
{ {
struct blockdata *block, *ret = NULL; struct blockdata *block, *ret = NULL;
struct blockdata **prev = &ret; struct blockdata **prev = &ret;
size_t blen; size_t blen;
while (len > 0) while (len > 0)
{ {
if (!keyblock_free) if (!keyblock_free)
blockdata_expand(50); blockdata_expand(50);
skipping to change at line 92 skipping to change at line 89
{ {
/* failed to alloc, free partial chain */ /* failed to alloc, free partial chain */
blockdata_free(ret); blockdata_free(ret);
return NULL; return NULL;
} }
if (blockdata_hwm < blockdata_count) if (blockdata_hwm < blockdata_count)
blockdata_hwm = blockdata_count; blockdata_hwm = blockdata_count;
blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len; blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len;
memcpy(block->key, data, blen); if (data)
data += blen; {
memcpy(block->key, data, blen);
data += blen;
}
else if (!read_write(fd, block->key, blen, 1))
{
/* failed read free partial chain */
blockdata_free(ret);
return NULL;
}
len -= blen; len -= blen;
*prev = block; *prev = block;
prev = &block->next; prev = &block->next;
block->next = NULL; block->next = NULL;
} }
return ret; return ret;
} }
struct blockdata *blockdata_alloc(char *data, size_t len)
{
return blockdata_alloc_real(0, data, len);
}
void blockdata_free(struct blockdata *blocks) void blockdata_free(struct blockdata *blocks)
{ {
struct blockdata *tmp; struct blockdata *tmp;
if (blocks) if (blocks)
{ {
for (tmp = blocks; tmp->next; tmp = tmp->next) for (tmp = blocks; tmp->next; tmp = tmp->next)
blockdata_count--; blockdata_count--;
tmp->next = keyblock_free; tmp->next = keyblock_free;
keyblock_free = blocks; keyblock_free = blocks;
skipping to change at line 151 skipping to change at line 162
{ {
blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len; blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len;
memcpy(d, b->key, blen); memcpy(d, b->key, blen);
d += blen; d += blen;
len -= blen; len -= blen;
} }
return data; return data;
} }
#endif void blockdata_write(struct blockdata *block, size_t len, int fd)
{
for (; len > 0 && block; block = block->next)
{
size_t blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len;
read_write(fd, block->key, blen, 0);
len -= blen;
}
}
struct blockdata *blockdata_read(int fd, size_t len)
{
return blockdata_alloc_real(fd, NULL, len);
}
 End of changes. 7 change blocks. 
11 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)