From 09dccd0331452b078a9bb970423cc915be3b9a28 Mon Sep 17 00:00:00 2001 From: Thomas Markwalder Date: Mon, 13 Jun 2016 10:01:48 -0400 Subject: [PATCH] [master] Scrub leases when they are re-balanced Merges in 42008. --- RELNOTES | 6 ++++++ server/failover.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/RELNOTES b/RELNOTES index 06d420bb5..188b46d90 100644 --- a/RELNOTES +++ b/RELNOTES @@ -71,6 +71,12 @@ by Eric Young (eay@cryptsoft.com). otherwise harmless error message when running "make check". [ISC-Bugs #41883] +- Leases are now scrubbed of certain prior use information when pool + re-balancing reassigns them from one FO peer to the other. This + corrects an issue where leases that were offered but ignored retained + the client hostname from the original client. + [ISC-Bugs #42008] + Changes since 4.3.4b1 - None diff --git a/server/failover.c b/server/failover.c index b2cfa5c21..12ba123d8 100644 --- a/server/failover.c +++ b/server/failover.c @@ -48,6 +48,7 @@ static int dhcp_failover_pool_dobalance(dhcp_failover_state_t *state, isc_boolean_t *sendreq); static inline int secondary_not_hoarding(dhcp_failover_state_t *state, struct pool *p); +static void scrub_lease(struct lease* lease, const char *file, int line); void dhcp_failover_startup () @@ -2618,6 +2619,7 @@ dhcp_failover_pool_dobalance(dhcp_failover_state_t *state, lp->tstp = cur_time; lp->starts = cur_time; + scrub_lease(lp, MDL); if (!supersede_lease(lp, NULL, 0, 1, 0, 0) || !write_lease(lp)) log_error("can't commit lease %s on " @@ -6502,3 +6504,48 @@ const char *binding_state_print (enum failover_state state) break; } } + + +/*! + * \brief Given a char pointer, return always return a printable value + * + * This function is intended to be used in within log statements, such that + * its invocation only occurs if the logging level is enabled. + * + * \param value pointer the character to print + * + * \return If value is null, returns the string "", if it contains + * non-printable bytes, returns the string "", + * otherwise it returns a const pointer to value + */ +const char *printable(const char* value) { + const char *print_value = ""; + if (value) { + if ((strlen (value) <= 64) && + db_printable((unsigned char*)value)) { + print_value = value; + } + else { + print_value = ""; + } + } + + return (print_value); +} + +/*! + * \brief Remove information from a prior use of a lease + * + * Remove information from a lease that is not germain to lease affinity + * + * \param lease the lease to scrub + */ +void scrub_lease(struct lease* lease, const char *file, int line) { + log_debug ("%s(%d):scrubbing lease for %s, hostname: %s", file, line, + piaddr(lease->ip_addr), printable(lease->client_hostname)); + + if (lease->client_hostname) { + dfree (lease->client_hostname, MDL); + lease->client_hostname = (char *)0; + } +} -- 2.47.3