Diff for /embedaddon/dnsmasq/src/blockdata.c between versions 1.1.1.1 and 1.1.1.3

version 1.1.1.1, 2014/06/15 16:31:38 version 1.1.1.3, 2021/03/17 00:56:46
Line 1 Line 1
/* dnsmasq is Copyright (c) 2000-2014 Simon Kelley/* dnsmasq is Copyright (c) 2000-2021 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
Line 16 Line 16
   
 #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;
   
Line 25  static void blockdata_expand(int n) Line 23  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 (n > 0 && new)  if (new)
     {      {
       int i;        int i;
               
Line 49  void blockdata_init(void) Line 47  void blockdata_init(void)
   
   /* 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 * 100) / sizeof(struct blockdata));    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;
Line 89  struct blockdata *blockdata_alloc(char *data, size_t l Line 86  struct blockdata *blockdata_alloc(char *data, size_t l
         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;
Line 100  struct blockdata *blockdata_alloc(char *data, size_t l Line 106  struct blockdata *blockdata_alloc(char *data, size_t l
   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;
Line 147  void *blockdata_retrieve(struct blockdata *block, size Line 158  void *blockdata_retrieve(struct blockdata *block, size
   
   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);
 }
 

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>