1 diff -up dhcp-4.3.1b1/server/dhcpv6.c.UseMulticast dhcp-4.3.1b1/server/dhcpv6.c
2 --- dhcp-4.3.1b1/server/dhcpv6.c.UseMulticast 2014-07-02 19:58:40.000000000 +0200
3 +++ dhcp-4.3.1b1/server/dhcpv6.c 2014-07-10 18:20:03.066256219 +0200
4 @@ -376,6 +376,48 @@ generate_new_server_duid(void) {
8 + * Is the D6O_UNICAST option defined in dhcpd.conf ?
10 +static isc_boolean_t unicast_option_defined;
13 + * Did we already search dhcpd.conf for D6O_UNICAST option ?
14 + * We need to store it here to not parse dhcpd.conf repeatedly.
16 +static isc_boolean_t unicast_option_parsed = ISC_FALSE;
20 + * Is the D6O_UNICAST option defined in dhcpd.conf ?
23 +is_unicast_option_defined(void) {
24 + struct option_state *opt_state;
25 + struct option_cache *oc;
28 + * If we are looking for the unicast option for the first time
30 + if (unicast_option_parsed == ISC_FALSE) {
31 + unicast_option_parsed = ISC_TRUE;
33 + if (!option_state_allocate(&opt_state, MDL)) {
34 + log_fatal("No memory for option state.");
37 + execute_statements_in_scope(NULL, NULL, NULL, NULL, NULL,
38 + opt_state, &global_scope, root_group, NULL, NULL);
40 + oc = lookup_option(&dhcpv6_universe, opt_state, D6O_UNICAST);
41 + unicast_option_defined = (oc != NULL);
43 + option_state_dereference(&opt_state, MDL);
46 + return (unicast_option_defined);
50 * Get the client identifier from the packet.
53 @@ -706,6 +748,12 @@ static const int required_opts[] = {
57 +static const int required_opts_NAA[] = {
63 static const int required_opts_solicit[] = {
66 @@ -1587,6 +1635,56 @@ lease_to_client(struct data_string *repl
67 reply.shared->group, NULL);
70 + /* reject unicast message, unless we set unicast option */
71 + if ((packet->unicast == ISC_TRUE) && !is_unicast_option_defined())
73 + * RFC3315 section 18.2.1 (Request):
75 + * When the server receives a Request message via unicast from a client
76 + * to which the server has not sent a unicast option, the server
77 + * discards the Request message and responds with a Reply message
78 + * containing a Status Code option with the value UseMulticast, a Server
79 + * Identifier option containing the server's DUID, the Client Identifier
80 + * option from the client message, and no other options.
82 + * Section 18.2.3 (Renew):
84 + * When the server receives a Renew message via unicast from a client to
85 + * which the server has not sent a unicast option, the server discards
86 + * the Renew message and responds with a Reply message containing a
87 + * Status Code option with the value UseMulticast, a Server Identifier
88 + * option containing the server's DUID, the Client Identifier option
89 + * from the client message, and no other options.
92 + /* Set the UseMulticast status code. */
93 + if (!set_status_code(STATUS_UseMulticast,
94 + "Unicast not allowed by server.",
96 + log_error("lease_to_client: Unable to set "
97 + "UseMulticast status code.");
101 + /* Rewind the cursor to the start. */
102 + reply.cursor = REPLY_OPTIONS_INDEX;
105 + * Produce an reply that includes only:
111 + reply.cursor += store_options6((char *)reply.buf.data +
113 + sizeof(reply.buf) -
115 + reply.opt_state, reply.packet,
121 * RFC3315 section 17.2.2 (Solicit):
123 @@ -1619,6 +1717,7 @@ lease_to_client(struct data_string *repl
124 * Having stored the client's IA's, store any options that
125 * will fit in the remaining space.
128 reply.cursor += store_options6((char *)reply.buf.data + reply.cursor,
129 sizeof(reply.buf) - reply.cursor,
130 reply.opt_state, reply.packet,
131 @@ -4748,7 +4847,6 @@ dhcpv6_solicit(struct data_string *reply
132 * Very similar to Solicit handling, except the server DUID is required.
135 -/* TODO: reject unicast messages, unless we set unicast option */
137 dhcpv6_request(struct data_string *reply_ret, struct packet *packet) {
138 struct data_string client_id;
139 @@ -5078,7 +5176,6 @@ exit:
140 * except for the error code of when addresses don't match.
143 -/* TODO: reject unicast messages, unless we set unicast option */
145 dhcpv6_renew(struct data_string *reply, struct packet *packet) {
146 struct data_string client_id;
147 @@ -5322,18 +5419,60 @@ iterate_over_ia_na(struct data_string *r
151 - snprintf(status_msg, sizeof(status_msg), "%s received.", packet_type);
152 - if (!set_status_code(STATUS_Success, status_msg, opt_state)) {
155 + /* reject unicast message, unless we set unicast option */
156 + if ((packet->unicast == ISC_TRUE) && !is_unicast_option_defined()) {
158 + * RFC3315 section 18.2.6 (Release):
160 + * When the server receives a Release message via unicast from a client
161 + * to which the server has not sent a unicast option, the server
162 + * discards the Release message and responds with a Reply message
163 + * containing a Status Code option with value UseMulticast, a Server
164 + * Identifier option containing the server's DUID, the Client Identifier
165 + * option from the client message, and no other options.
167 + * Section 18.2.7 (Decline):
169 + * When the server receives a Decline message via unicast from a client
170 + * to which the server has not sent a unicast option, the server
171 + * discards the Decline message and responds with a Reply message
172 + * containing a Status Code option with the value UseMulticast, a Server
173 + * Identifier option containing the server's DUID, the Client Identifier
174 + * option from the client message, and no other options.
176 + snprintf(status_msg, sizeof(status_msg),
177 + "%s received unicast.", packet_type);
178 + if (!set_status_code(STATUS_UseMulticast, status_msg, opt_state)) {
183 - * Add our options that are not associated with any IA_NA or IA_TA.
185 - reply_ofs += store_options6(reply_data+reply_ofs,
186 - sizeof(reply_data)-reply_ofs,
188 + * Produce an reply that includes only:
194 + reply_ofs += store_options6(reply_data+reply_ofs,
195 + sizeof(reply_data)-reply_ofs,
197 - required_opts, NULL);
198 + required_opts_NAA, NULL);
202 + snprintf(status_msg, sizeof(status_msg), "%s received.", packet_type);
203 + if (!set_status_code(STATUS_Success, status_msg, opt_state)) {
208 + * Add our options that are not associated with any IA_NA or IA_TA.
210 + reply_ofs += store_options6(reply_data+reply_ofs,
211 + sizeof(reply_data)-reply_ofs,
213 + required_opts, NULL);
217 * Loop through the IA_NA reported by the client, and deal with
218 @@ -5471,6 +5610,7 @@ iterate_over_ia_na(struct data_string *r
220 * Return our reply to the caller.
223 reply_ret->len = reply_ofs;
224 reply_ret->buffer = NULL;
225 if (!buffer_allocate(&reply_ret->buffer, reply_ofs, MDL)) {
226 @@ -5516,7 +5656,6 @@ exit:
227 * we still need to be aware of this possibility.
230 -/* TODO: reject unicast messages, unless we set unicast option */
233 dhcpv6_decline(struct data_string *reply, struct packet *packet) {
234 @@ -5986,7 +6125,6 @@ exit:
235 * Release means a client is done with the leases.
238 -/* TODO: reject unicast messages, unless we set unicast option */
240 dhcpv6_release(struct data_string *reply, struct packet *packet) {
241 struct data_string client_id;