mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Cleanup interfaces no longer available
Clean addresses and interfaces not found after enumerate. Free unused records to speed up checking active interfaces and reduce used memory.
This commit is contained in:
committed by
Simon Kelley
parent
951a22165c
commit
60a3ae19c5
@@ -533,7 +533,30 @@ static int iface_allowed_v4(struct in_addr local, int if_index, char *label,
|
||||
|
||||
return iface_allowed((struct iface_param *)vparam, if_index, label, &addr, netmask, prefix, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Clean old interfaces no longer found.
|
||||
*/
|
||||
static void clean_interfaces()
|
||||
{
|
||||
struct irec *iface;
|
||||
struct irec **up = &daemon->interfaces;
|
||||
|
||||
for (iface = *up; iface; iface = *up)
|
||||
{
|
||||
if (!iface->found && !iface->done)
|
||||
{
|
||||
*up = iface->next;
|
||||
free(iface->name);
|
||||
free(iface);
|
||||
}
|
||||
else
|
||||
{
|
||||
up = &iface->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int enumerate_interfaces(int reset)
|
||||
{
|
||||
static struct addrlist *spare = NULL;
|
||||
@@ -631,6 +654,7 @@ int enumerate_interfaces(int reset)
|
||||
in OPT_CLEVERBIND mode, that at listener will just disappear after
|
||||
a call to enumerate_interfaces, this is checked OK on all calls. */
|
||||
struct listener *l, *tmp, **up;
|
||||
int freed = 0;
|
||||
|
||||
for (up = &daemon->listeners, l = daemon->listeners; l; l = tmp)
|
||||
{
|
||||
@@ -660,10 +684,14 @@ int enumerate_interfaces(int reset)
|
||||
close(l->tftpfd);
|
||||
|
||||
free(l);
|
||||
freed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (freed)
|
||||
clean_interfaces();
|
||||
}
|
||||
|
||||
|
||||
errno = errsave;
|
||||
spare = param.spare;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user