Skip to content

Commit

Permalink
Add temporary verbose log output. To be removed (or send to DHCP debu…
Browse files Browse the repository at this point in the history
…g logging later on)

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Apr 30, 2024
1 parent db32e4d commit b469f11
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/database/database-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ void *DB_thread(void *val)
// Do this once per second
if(now > before)
{
lock_shm();
queries_to_database();
unlock_shm();
before = now;

// Check if we need to reload gravity
Expand Down
6 changes: 6 additions & 0 deletions src/database/query-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,9 @@ bool queries_to_database(void)
return false;
}

// Lock shared memory for reading
lock_shm();

// Loop over recent queries and store new or changed ones in the in-memory database
const unsigned int min_iter = counters->queries - 1;
unsigned int max_iter = min_iter > DB_QUERY_MAX_ITER ? min_iter - DB_QUERY_MAX_ITER : 0;
Expand Down Expand Up @@ -1599,6 +1602,9 @@ bool queries_to_database(void)
query->flags.database.changed = false;
}

// Unlock shared memory
unlock_shm();

// Finalize all statements
for(unsigned int i = 0; i < ArraySize(stmts); i++)
{
Expand Down
3 changes: 3 additions & 0 deletions src/dnsmasq/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "dnsmasq.h"
#include "dnsmasq_interface.h"
#include "webserver/webserver.h"
#include "log.h"

static struct crec *cache_head = NULL, *cache_tail = NULL, **hash_table = NULL;
#ifdef HAVE_DHCP
Expand Down Expand Up @@ -1577,6 +1578,8 @@ void cache_add_dhcp_entry(char *host_name, int prot,
break;
}
}

log_info("Adding DHCP->DNS entry for %s at %s", host_name, daemon->addrbuff);

/* if in hosts, don't need DHCP record */
if (in_hosts)
Expand Down
18 changes: 18 additions & 0 deletions src/dnsmasq/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "log.h"

#include "dnsmasq.h"
#ifdef HAVE_DHCP

Expand Down Expand Up @@ -559,6 +562,8 @@ void lease_prune(struct dhcp_lease *target, time_t now)
if (lease->hostname)
dns_dirty = 1;

log_info("DHCP lease %s expired (%s)", inet_ntoa(lease->addr), ctime(&now));

daemon->metrics[lease->addr.s_addr ? METRIC_LEASES_PRUNED_4 : METRIC_LEASES_PRUNED_6]++;

*up = lease->next; /* unlink */
Expand Down Expand Up @@ -925,18 +930,23 @@ static void kill_name(struct dhcp_lease *lease)

/* this shouldn't happen unless updates are very quick and the
script very slow, we just avoid a memory leak if it does. */
log_info("kill_name(): Freeing old hostname lease %s -> %s", inet_ntoa(lease->addr), lease->old_hostname);
free(lease->old_hostname);

/* If we know the fqdn, pass that. The helper will derive the
unqualified name from it, free the unqualified name here. */

if (lease->fqdn)
{
log_info("kill_name(): Freeing hostname lease %s -> %s", inet_ntoa(lease->addr), lease->hostname);
lease->old_hostname = lease->fqdn;
free(lease->hostname);
}
else
{
log_info("kill_name(): Replacing old by new hostname lease %s -> %s", inet_ntoa(lease->addr), lease->hostname);
lease->old_hostname = lease->hostname;
}

lease->hostname = lease->fqdn = NULL;
}
Expand Down Expand Up @@ -966,6 +976,8 @@ void lease_calc_fqdns(void)
strcpy(lease->fqdn, lease->hostname);
strcat(lease->fqdn, ".");
strcat(lease->fqdn, domain);

log_info("lease_calc_fqdns(): lease %s -> %s", inet_ntoa(lease->addr), lease->fqdn);
}
}
}
Expand Down Expand Up @@ -1059,6 +1071,8 @@ void lease_set_hostname(struct dhcp_lease *lease, const char *name, int auth, ch

if (auth)
lease->flags |= LEASE_AUTH_NAME;

log_info("lease_set_hostname(): lease %s -> %s / %s", inet_ntoa(lease->addr), lease->hostname, lease->fqdn);

file_dirty = 1;
dns_dirty = 1;
Expand Down Expand Up @@ -1116,6 +1130,7 @@ int do_script_run(time_t now)
#ifdef HAVE_SCRIPT
queue_script(ACTION_OLD_HOSTNAME, lease, lease->old_hostname, now);
#endif
log_info("do_script_run(): Freeing old hostname lease %s -> %s", inet_ntoa(lease->addr), lease->old_hostname);
free(lease->old_hostname);
lease->old_hostname = NULL;
return 1;
Expand All @@ -1138,6 +1153,7 @@ int do_script_run(time_t now)
emit_dbus_signal(ACTION_DEL, lease, lease->old_hostname);
#endif
old_leases = lease->next;
log_info("do_script_run(): Freeing lease %s -> %s", inet_ntoa(lease->addr), lease->old_hostname);

free(lease->old_hostname);
free(lease->clid);
Expand All @@ -1155,6 +1171,7 @@ int do_script_run(time_t now)
#ifdef HAVE_SCRIPT
queue_script(ACTION_OLD_HOSTNAME, lease, lease->old_hostname, now);
#endif
log_info("do_script_run(): Freeing old hostname lease %s -> %s", inet_ntoa(lease->addr), lease->old_hostname);
free(lease->old_hostname);
lease->old_hostname = NULL;
return 1;
Expand All @@ -1165,6 +1182,7 @@ int do_script_run(time_t now)
((lease->flags & LEASE_AUX_CHANGED) && option_bool(OPT_LEASE_RO)) ||
((lease->flags & LEASE_EXP_CHANGED) && option_bool(OPT_LEASE_RENEW)))
{
log_info("do_script_run(): Lease %s %s -> %s", (lease->flags & LEASE_NEW) ? "NEW" : "CHANGED", inet_ntoa(lease->addr), lease->old_hostname);
#ifdef HAVE_SCRIPT
queue_script((lease->flags & LEASE_NEW) ? ACTION_ADD : ACTION_OLD, lease,
lease->fqdn ? lease->fqdn : lease->hostname, now);
Expand Down

0 comments on commit b469f11

Please sign in to comment.