|
|
fad460 |
diff -up dhcp-4.2.4b1/server/dhcpv6.c.UseMulticast dhcp-4.2.4b1/server/dhcpv6.c
|
|
|
fad460 |
--- dhcp-4.2.4b1/server/dhcpv6.c.UseMulticast 2012-04-11 00:14:04.000000000 +0200
|
|
|
fad460 |
+++ dhcp-4.2.4b1/server/dhcpv6.c 2012-04-16 19:21:43.575923732 +0200
|
|
|
fad460 |
@@ -346,6 +346,48 @@ generate_new_server_duid(void) {
|
|
|
fad460 |
}
|
|
|
fad460 |
|
|
|
fad460 |
/*
|
|
|
fad460 |
+ * Is the D6O_UNICAST option defined in dhcpd.conf ?
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+static isc_boolean_t unicast_option_defined;
|
|
|
fad460 |
+
|
|
|
fad460 |
+/*
|
|
|
fad460 |
+ * Did we already search dhcpd.conf for D6O_UNICAST option ?
|
|
|
fad460 |
+ * We need to store it here to not parse dhcpd.conf repeatedly.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+static isc_boolean_t unicast_option_parsed = ISC_FALSE;
|
|
|
fad460 |
+
|
|
|
fad460 |
+
|
|
|
fad460 |
+/*
|
|
|
fad460 |
+ * Is the D6O_UNICAST option defined in dhcpd.conf ?
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+isc_boolean_t
|
|
|
fad460 |
+is_unicast_option_defined(void) {
|
|
|
fad460 |
+ struct option_state *opt_state;
|
|
|
fad460 |
+ struct option_cache *oc;
|
|
|
fad460 |
+
|
|
|
fad460 |
+ /*
|
|
|
fad460 |
+ * If we are looking for the unicast option for the first time
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ if (unicast_option_parsed == ISC_FALSE) {
|
|
|
fad460 |
+ unicast_option_parsed = ISC_TRUE;
|
|
|
fad460 |
+ opt_state = NULL;
|
|
|
fad460 |
+ if (!option_state_allocate(&opt_state, MDL)) {
|
|
|
fad460 |
+ log_fatal("No memory for option state.");
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+
|
|
|
fad460 |
+ execute_statements_in_scope(NULL, NULL, NULL, NULL, NULL,
|
|
|
fad460 |
+ opt_state, &global_scope, root_group, NULL);
|
|
|
fad460 |
+
|
|
|
fad460 |
+ oc = lookup_option(&dhcpv6_universe, opt_state, D6O_UNICAST);
|
|
|
fad460 |
+ unicast_option_defined = (oc != NULL);
|
|
|
fad460 |
+
|
|
|
fad460 |
+ option_state_dereference(&opt_state, MDL);
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+
|
|
|
fad460 |
+ return (unicast_option_defined);
|
|
|
fad460 |
+}
|
|
|
fad460 |
+
|
|
|
fad460 |
+/*
|
|
|
fad460 |
* Get the client identifier from the packet.
|
|
|
fad460 |
*/
|
|
|
fad460 |
isc_result_t
|
|
|
fad460 |
@@ -1404,6 +1446,56 @@ lease_to_client(struct data_string *repl
|
|
|
fad460 |
reply.shared->group);
|
|
|
fad460 |
}
|
|
|
fad460 |
|
|
|
fad460 |
+ /* reject unicast message, unless we set unicast option */
|
|
|
fad460 |
+ if ((packet->unicast == ISC_TRUE) && !is_unicast_option_defined())
|
|
|
fad460 |
+ /*
|
|
|
fad460 |
+ * RFC3315 section 18.2.1 (Request):
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * When the server receives a Request message via unicast from a client
|
|
|
fad460 |
+ * to which the server has not sent a unicast option, the server
|
|
|
fad460 |
+ * discards the Request message and responds with a Reply message
|
|
|
fad460 |
+ * containing a Status Code option with the value UseMulticast, a Server
|
|
|
fad460 |
+ * Identifier option containing the server's DUID, the Client Identifier
|
|
|
fad460 |
+ * option from the client message, and no other options.
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * Section 18.2.3 (Renew):
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * When the server receives a Renew message via unicast from a client to
|
|
|
fad460 |
+ * which the server has not sent a unicast option, the server discards
|
|
|
fad460 |
+ * the Renew message and responds with a Reply message containing a
|
|
|
fad460 |
+ * Status Code option with the value UseMulticast, a Server Identifier
|
|
|
fad460 |
+ * option containing the server's DUID, the Client Identifier option
|
|
|
fad460 |
+ * from the client message, and no other options.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ {
|
|
|
fad460 |
+ /* Set the UseMulticast status code. */
|
|
|
fad460 |
+ if (!set_status_code(STATUS_UseMulticast,
|
|
|
fad460 |
+ "Unicast not allowed by server.",
|
|
|
fad460 |
+ reply.opt_state)) {
|
|
|
fad460 |
+ log_error("lease_to_client: Unable to set "
|
|
|
fad460 |
+ "UseMulticast status code.");
|
|
|
fad460 |
+ goto exit;
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+
|
|
|
fad460 |
+ /* Rewind the cursor to the start. */
|
|
|
fad460 |
+ reply.cursor = REPLY_OPTIONS_INDEX;
|
|
|
fad460 |
+
|
|
|
fad460 |
+ /*
|
|
|
fad460 |
+ * Produce an reply that includes only:
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * Status code.
|
|
|
fad460 |
+ * Server DUID.
|
|
|
fad460 |
+ * Client DUID.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ reply.cursor += store_options6((char *)reply.buf.data +
|
|
|
fad460 |
+ reply.cursor,
|
|
|
fad460 |
+ sizeof(reply.buf) -
|
|
|
fad460 |
+ reply.cursor,
|
|
|
fad460 |
+ reply.opt_state, reply.packet,
|
|
|
fad460 |
+ required_opts_NAA,
|
|
|
fad460 |
+ NULL);
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+
|
|
|
fad460 |
/*
|
|
|
fad460 |
* RFC3315 section 17.2.2 (Solicit):
|
|
|
fad460 |
*
|
|
|
fad460 |
@@ -1429,8 +1521,8 @@ lease_to_client(struct data_string *repl
|
|
|
fad460 |
* Sends a Renew/Rebind if the IA is not in the Reply message.
|
|
|
fad460 |
*/
|
|
|
fad460 |
#if defined (RFC3315_PRE_ERRATA_2010_08)
|
|
|
fad460 |
- if (no_resources_avail && (reply.ia_count != 0) &&
|
|
|
fad460 |
- (reply.packet->dhcpv6_msg_type == DHCPV6_SOLICIT))
|
|
|
fad460 |
+ else if (no_resources_avail && (reply.ia_count != 0) &&
|
|
|
fad460 |
+ (reply.packet->dhcpv6_msg_type == DHCPV6_SOLICIT))
|
|
|
fad460 |
{
|
|
|
fad460 |
/* Set the NoAddrsAvail status code. */
|
|
|
fad460 |
if (!set_status_code(STATUS_NoAddrsAvail,
|
|
|
fad460 |
@@ -1477,6 +1569,7 @@ lease_to_client(struct data_string *repl
|
|
|
fad460 |
* Having stored the client's IA's, store any options that
|
|
|
fad460 |
* will fit in the remaining space.
|
|
|
fad460 |
*/
|
|
|
fad460 |
+ else
|
|
|
fad460 |
reply.cursor += store_options6((char *)reply.buf.data + reply.cursor,
|
|
|
fad460 |
sizeof(reply.buf) - reply.cursor,
|
|
|
fad460 |
reply.opt_state, reply.packet,
|
|
|
fad460 |
@@ -4126,7 +4219,6 @@ dhcpv6_solicit(struct data_string *reply
|
|
|
fad460 |
* Very similar to Solicit handling, except the server DUID is required.
|
|
|
fad460 |
*/
|
|
|
fad460 |
|
|
|
fad460 |
-/* TODO: reject unicast messages, unless we set unicast option */
|
|
|
fad460 |
static void
|
|
|
fad460 |
dhcpv6_request(struct data_string *reply_ret, struct packet *packet) {
|
|
|
fad460 |
struct data_string client_id;
|
|
|
fad460 |
@@ -4456,7 +4548,6 @@ exit:
|
|
|
fad460 |
* except for the error code of when addresses don't match.
|
|
|
fad460 |
*/
|
|
|
fad460 |
|
|
|
fad460 |
-/* TODO: reject unicast messages, unless we set unicast option */
|
|
|
fad460 |
static void
|
|
|
fad460 |
dhcpv6_renew(struct data_string *reply, struct packet *packet) {
|
|
|
fad460 |
struct data_string client_id;
|
|
|
fad460 |
@@ -4700,18 +4791,60 @@ iterate_over_ia_na(struct data_string *r
|
|
|
fad460 |
goto exit;
|
|
|
fad460 |
}
|
|
|
fad460 |
|
|
|
fad460 |
- snprintf(status_msg, sizeof(status_msg), "%s received.", packet_type);
|
|
|
fad460 |
- if (!set_status_code(STATUS_Success, status_msg, opt_state)) {
|
|
|
fad460 |
- goto exit;
|
|
|
fad460 |
- }
|
|
|
fad460 |
+ /* reject unicast message, unless we set unicast option */
|
|
|
fad460 |
+ if ((packet->unicast == ISC_TRUE) && !is_unicast_option_defined()) {
|
|
|
fad460 |
+ /*
|
|
|
fad460 |
+ * RFC3315 section 18.2.6 (Release):
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * When the server receives a Release message via unicast from a client
|
|
|
fad460 |
+ * to which the server has not sent a unicast option, the server
|
|
|
fad460 |
+ * discards the Release message and responds with a Reply message
|
|
|
fad460 |
+ * containing a Status Code option with value UseMulticast, a Server
|
|
|
fad460 |
+ * Identifier option containing the server's DUID, the Client Identifier
|
|
|
fad460 |
+ * option from the client message, and no other options.
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * Section 18.2.7 (Decline):
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * When the server receives a Decline message via unicast from a client
|
|
|
fad460 |
+ * to which the server has not sent a unicast option, the server
|
|
|
fad460 |
+ * discards the Decline message and responds with a Reply message
|
|
|
fad460 |
+ * containing a Status Code option with the value UseMulticast, a Server
|
|
|
fad460 |
+ * Identifier option containing the server's DUID, the Client Identifier
|
|
|
fad460 |
+ * option from the client message, and no other options.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ snprintf(status_msg, sizeof(status_msg),
|
|
|
fad460 |
+ "%s received unicast.", packet_type);
|
|
|
fad460 |
+ if (!set_status_code(STATUS_UseMulticast, status_msg, opt_state)) {
|
|
|
fad460 |
+ goto exit;
|
|
|
fad460 |
+ }
|
|
|
fad460 |
|
|
|
fad460 |
- /*
|
|
|
fad460 |
- * Add our options that are not associated with any IA_NA or IA_TA.
|
|
|
fad460 |
- */
|
|
|
fad460 |
- reply_ofs += store_options6(reply_data+reply_ofs,
|
|
|
fad460 |
- sizeof(reply_data)-reply_ofs,
|
|
|
fad460 |
+ /*
|
|
|
fad460 |
+ * Produce an reply that includes only:
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * Status code.
|
|
|
fad460 |
+ * Server DUID.
|
|
|
fad460 |
+ * Client DUID.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ reply_ofs += store_options6(reply_data+reply_ofs,
|
|
|
fad460 |
+ sizeof(reply_data)-reply_ofs,
|
|
|
fad460 |
opt_state, packet,
|
|
|
fad460 |
- required_opts, NULL);
|
|
|
fad460 |
+ required_opts_NAA, NULL);
|
|
|
fad460 |
+
|
|
|
fad460 |
+ goto return_reply;
|
|
|
fad460 |
+ } else {
|
|
|
fad460 |
+ snprintf(status_msg, sizeof(status_msg), "%s received.", packet_type);
|
|
|
fad460 |
+ if (!set_status_code(STATUS_Success, status_msg, opt_state)) {
|
|
|
fad460 |
+ goto exit;
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+
|
|
|
fad460 |
+ /*
|
|
|
fad460 |
+ * Add our options that are not associated with any IA_NA or IA_TA.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ reply_ofs += store_options6(reply_data+reply_ofs,
|
|
|
fad460 |
+ sizeof(reply_data)-reply_ofs,
|
|
|
fad460 |
+ opt_state, packet,
|
|
|
fad460 |
+ required_opts, NULL);
|
|
|
fad460 |
+ }
|
|
|
fad460 |
|
|
|
fad460 |
/*
|
|
|
fad460 |
* Loop through the IA_NA reported by the client, and deal with
|
|
|
fad460 |
@@ -4849,6 +4982,7 @@ iterate_over_ia_na(struct data_string *r
|
|
|
fad460 |
/*
|
|
|
fad460 |
* Return our reply to the caller.
|
|
|
fad460 |
*/
|
|
|
fad460 |
+return_reply:
|
|
|
fad460 |
reply_ret->len = reply_ofs;
|
|
|
fad460 |
reply_ret->buffer = NULL;
|
|
|
fad460 |
if (!buffer_allocate(&reply_ret->buffer, reply_ofs, MDL)) {
|
|
|
fad460 |
@@ -4894,7 +5028,6 @@ exit:
|
|
|
fad460 |
* we still need to be aware of this possibility.
|
|
|
fad460 |
*/
|
|
|
fad460 |
|
|
|
fad460 |
-/* TODO: reject unicast messages, unless we set unicast option */
|
|
|
fad460 |
/* TODO: IA_TA */
|
|
|
fad460 |
static void
|
|
|
fad460 |
dhcpv6_decline(struct data_string *reply, struct packet *packet) {
|
|
|
fad460 |
@@ -5364,7 +5497,6 @@ exit:
|
|
|
fad460 |
* Release means a client is done with the leases.
|
|
|
fad460 |
*/
|
|
|
fad460 |
|
|
|
fad460 |
-/* TODO: reject unicast messages, unless we set unicast option */
|
|
|
fad460 |
static void
|
|
|
fad460 |
dhcpv6_release(struct data_string *reply, struct packet *packet) {
|
|
|
fad460 |
struct data_string client_id;
|