[PATCH 2/2] receive agent options with bind update

Sytse Wielinga s.wielinga at lijbrandt-telecom.nl
Fri Jul 10 09:59:55 UTC 2009


---
 includes/dhcp.h   |    2 +-
 server/failover.c |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletions(-)

diff --git a/includes/dhcp.h b/includes/dhcp.h
index daf9d6c..1f3fe1e 100644
--- a/includes/dhcp.h
+++ b/includes/dhcp.h
@@ -149,7 +149,7 @@ struct dhcp_packet {
 #define DHO_NWIP_SUBOPTIONS			63
 #define DHO_USER_CLASS				77
 #define DHO_FQDN				81
-#define DHO_DHCP_AGENT_OPTIONS			82
+#define DHO_DHCP_AGENT_OPTIONS			82  /* RFC3046 */
 #define DHO_CLIENT_LAST_TRANSACTION_TIME	91
 #define DHO_ASSOCIATED_IP			92
 #define DHO_SUBNET_SELECTION			118 /* RFC3011! */
diff --git a/server/failover.c b/server/failover.c
index e7d6ec6..fa68715 100644
--- a/server/failover.c
+++ b/server/failover.c
@@ -5136,6 +5136,78 @@ isc_result_t dhcp_failover_process_bind_update (dhcp_failover_state_t *state,
 		lt->uid_max = lt->uid_len = 0;
 	}
 
+	if (msg->options_present & FTB_REQUEST_OPTIONS) {
+		int i, j;
+		failover_option_t request_options;
+
+		if (msg->binding_status == FTS_ABANDONED) {
+			message = "BNDUPD to ABANDONED with request-options";
+			goto bad;
+		}
+
+		if (lt -> agent_options)
+			option_chain_head_dereference (
+				&lt -> agent_options, MDL);
+
+		request_options = msg -> request_options;
+
+		for (i = 4; i < request_options.count;
+		     i += 2 + request_options.data[i+1]) {
+			u_int8_t len = request_options.data[i+1];
+			pair *p;
+			if (len + i + 2 > request_options.count) {
+				message = "Invalid BNDUPD: bad length in option";
+				break;
+			}
+
+			option_chain_head_allocate(&lt -> agent_options, MDL);
+			if (!lt -> agent_options) {
+				message = "no memory";
+				goto bad;
+			}
+			p = &lt -> agent_options -> first;
+
+			/* Process RFC3046 relay agent options */
+			if (request_options.data[i] == DHO_DHCP_AGENT_OPTIONS) {
+				u_int8_t *subopt = &request_options.data[i+2];
+
+				for (j = 0; j < len; j += 2 + subopt[j+1]) {
+					struct option *option = NULL;
+					struct option_cache *oc = NULL;
+					unsigned code;
+
+					if (j + 2 + subopt[j+1] > len) {
+						message = "Invalid BNDUPD: "
+							"bad length in option";
+						goto bad;
+					}
+					code = subopt[j];
+					option_code_hash_lookup(
+						&option,
+						agent_universe.code_hash,
+						&code, 0, MDL);
+					if (!option)
+						continue;
+					make_const_option_cache(&oc, NULL,
+								&subopt[j+2],
+								subopt[j+1],
+								option, MDL);
+					*p = cons(0, 0);
+					option_cache_reference(
+						((struct option_cache **)
+						 &((*p) -> car)),
+						oc, MDL);
+					option_cache_dereference (&oc, MDL);
+					p = &((*p) -> cdr);
+				}
+			}
+		}
+	} else if (lt->agent_options && msg->binding_status != FTS_RESET &&
+		   msg->binding_status != FTS_FREE &&
+		   msg->binding_status != FTS_BACKUP) {
+		option_chain_head_dereference (&lt -> agent_options, MDL);
+	}
+
 	/* If the lease was expired, also remove the stale binding scope. */
 	if (lt->scope && lt->ends < cur_time)
 		binding_scope_dereference(&lt->scope, MDL);
-- 
1.6.3.3




More information about the dhcp-hackers mailing list