Skip to content

Commit

Permalink
Merge pull request #1888 from pi-hole/development
Browse files Browse the repository at this point in the history
Pi-hole FTL v5.25
  • Loading branch information
DL6ER authored Feb 14, 2024
2 parents 0122731 + bda4bd5 commit 4f92b48
Show file tree
Hide file tree
Showing 58 changed files with 2,915 additions and 1,942 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
cmake_minimum_required(VERSION 2.8.12)
project(PIHOLE_FTL C)

set(DNSMASQ_VERSION pi-hole-v2.89-9461807)
set(DNSMASQ_VERSION pi-hole-v2.90)

add_subdirectory(src)
2 changes: 1 addition & 1 deletion src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void parse_args(int argc, char* argv[])
const char *arg[2];
arg[0] = "";
arg[1] = "--test";
exit(main_dnsmasq(2, arg));
exit(main_dnsmasq(2, (char**)arg));
}

// If we find "--" we collect everything behind that for dnsmasq
Expand Down
10 changes: 10 additions & 0 deletions src/dnsmasq/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Pi-hole: A black hole for Internet advertisements
# (c) 2020 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
# FTL Engine
# /src/dnsmasq/CMakeList.txt
#
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.

set(sources
arp.c
auth.c
Expand Down
2 changes: 1 addition & 1 deletion src/dnsmasq/arp.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* dnsmasq is Copyright (c) 2000-2022 Simon Kelley
/* dnsmasq is Copyright (c) 2000-2024 Simon Kelley
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
Expand Down
2 changes: 1 addition & 1 deletion src/dnsmasq/auth.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* dnsmasq is Copyright (c) 2000-2022 Simon Kelley
/* dnsmasq is Copyright (c) 2000-2024 Simon Kelley
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
Expand Down
123 changes: 93 additions & 30 deletions src/dnsmasq/blockdata.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* dnsmasq is Copyright (c) 2000-2022 Simon Kelley
/* dnsmasq is Copyright (c) 2000-2024 Simon Kelley
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
Expand All @@ -19,7 +19,7 @@
static struct blockdata *keyblock_free;
static unsigned int blockdata_count, blockdata_hwm, blockdata_alloced;

static void blockdata_expand(int n)
static void add_blocks(int n)
{
struct blockdata *new = whine_malloc(n * sizeof(struct blockdata));

Expand Down Expand Up @@ -47,7 +47,7 @@ void blockdata_init(void)

/* Note that daemon->cachesize is enforced to have non-zero size if OPT_DNSSEC_VALID is set */
if (option_bool(OPT_DNSSEC_VALID))
blockdata_expand(daemon->cachesize);
add_blocks(daemon->cachesize);
}

void blockdata_report(void)
Expand All @@ -58,50 +58,61 @@ void blockdata_report(void)
blockdata_alloced * sizeof(struct blockdata));
}

static struct blockdata *new_block(void)
{
struct blockdata *block;

if (!keyblock_free)
add_blocks(50);

if (keyblock_free)
{
block = keyblock_free;
keyblock_free = block->next;
blockdata_count++;
if (blockdata_hwm < blockdata_count)
blockdata_hwm = blockdata_count;
block->next = NULL;
return block;
}

return NULL;
}

static struct blockdata *blockdata_alloc_real(int fd, char *data, size_t len)
{
struct blockdata *block, *ret = NULL;
struct blockdata **prev = &ret;
size_t blen;

while (len > 0)
do
{
if (!keyblock_free)
blockdata_expand(50);

if (keyblock_free)
{
block = keyblock_free;
keyblock_free = block->next;
blockdata_count++;
}
else
if (!(block = new_block()))
{
/* failed to alloc, free partial chain */
blockdata_free(ret);
return NULL;
}

if (blockdata_hwm < blockdata_count)
blockdata_hwm = blockdata_count;

blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len;
if (data)
{
memcpy(block->key, data, blen);
data += blen;
}
else if (!read_write(fd, block->key, blen, 1))

if ((blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len) > 0)
{
/* failed read free partial chain */
blockdata_free(ret);
return NULL;
if (data)
{
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;
*prev = block;
prev = &block->next;
block->next = NULL;
}
} while (len != 0);

return ret;
}
Expand All @@ -111,6 +122,58 @@ struct blockdata *blockdata_alloc(char *data, size_t len)
return blockdata_alloc_real(0, data, len);
}

/* Add data to the end of the block.
newlen is length of new data, NOT total new length.
Use blockdata_alloc(NULL, 0) to make empty block to add to. */
int blockdata_expand(struct blockdata *block, size_t oldlen, char *data, size_t newlen)
{
struct blockdata *b;

/* find size of current final block */
for (b = block; oldlen > KEYBLOCK_LEN && b; b = b->next, oldlen -= KEYBLOCK_LEN);

/* chain to short for length, something is broken */
if (oldlen > KEYBLOCK_LEN)
{
blockdata_free(block);
return 0;
}

while (1)
{
struct blockdata *new;
size_t blocksize = KEYBLOCK_LEN - oldlen;
size_t size = (newlen <= blocksize) ? newlen : blocksize;

if (size != 0)
{
memcpy(&b->key[oldlen], data, size);
data += size;
newlen -= size;
}

/* full blocks from now on. */
oldlen = 0;

if (newlen == 0)
break;

if ((new = new_block()))
{
b->next = new;
b = new;
}
else
{
/* failed to alloc, free partial chain */
blockdata_free(block);
return 0;
}
}

return 1;
}

void blockdata_free(struct blockdata *blocks)
{
struct blockdata *tmp;
Expand Down
2 changes: 1 addition & 1 deletion src/dnsmasq/bpf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* dnsmasq is Copyright (c) 2000-2022 Simon Kelley
/* dnsmasq is Copyright (c) 2000-2024 Simon Kelley
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
Expand Down
Loading

0 comments on commit 4f92b48

Please sign in to comment.