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