From: Thomas Markwalder Date: Mon, 13 Jun 2016 14:26:24 +0000 (-0400) Subject: [master] Scrub leases when they are re-balanced X-Git-Tag: v4_1_esv_r14b1~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=48603a236927a6fa1c82348aa8ef84a456c4e26e;p=thirdparty%2Fdhcp.git [master] Scrub leases when they are re-balanced Merges in 42008. --- diff --git a/RELNOTES b/RELNOTES index 720994d93..111060631 100644 --- a/RELNOTES +++ b/RELNOTES @@ -69,6 +69,12 @@ by Eric Young (eay@cryptsoft.com). returned in responses. [ISC-Bugs #29246] +- 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.1-ESV-R13b1 - None diff --git a/server/failover.c b/server/failover.c index d7ac4cd37..778c2a3ef 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 () @@ -2565,6 +2566,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 " @@ -6358,3 +6360,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; + } +}