blob: 9331121094416dd7fa60b20c81640d46739587f6 [file] [log] [blame]
Juraj Sloboda81119e82018-05-25 14:02:20 +02001/*
2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <vlib/vlib.h>
17#include <vnet/dhcp/dhcp6_packet.h>
18#include <vnet/dhcp/dhcp_proxy.h>
19#include <vnet/mfib/mfib_table.h>
20#include <vnet/mfib/ip6_mfib.h>
21#include <vnet/fib/fib.h>
22#include <vnet/adj/adj_mcast.h>
23#include <vnet/ip/ip6_neighbor.h>
24#include <vlibapi/api_common.h>
25#include <vlibmemory/api.h>
26#include <vnet/dhcp/dhcp6_pd_client_dp.h>
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020027#include <vnet/dhcp/dhcp6_client_common_dp.h>
Juraj Sloboda81119e82018-05-25 14:02:20 +020028
29#include <vnet/vnet_msg_enum.h>
30
31#define vl_typedefs /* define message structures */
32#include <vnet/vnet_all_api_h.h>
33#undef vl_typedefs
34
35#define vl_endianfun /* define message structures */
36#include <vnet/vnet_all_api_h.h>
37#undef vl_endianfun
38
39/* instantiate all the print functions we know about */
40#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
41#define vl_printfun
42#include <vnet/vnet_all_api_h.h>
43#undef vl_printfun
44
45#include <vlibapi/api_helper_macros.h>
46
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020047dhcp6_pd_client_main_t dhcp6_pd_client_main;
Juraj Sloboda81119e82018-05-25 14:02:20 +020048dhcp6_pd_client_public_main_t dhcp6_pd_client_public_main;
49
Juraj Sloboda81119e82018-05-25 14:02:20 +020050static void
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020051signal_report (prefix_report_t * r)
Juraj Sloboda81119e82018-05-25 14:02:20 +020052{
53 vlib_main_t *vm = vlib_get_main ();
54 dhcp6_pd_client_main_t *cm = &dhcp6_pd_client_main;
55 uword ni = cm->publisher_node;
56 uword et = cm->publisher_et;
57
58 if (ni == (uword) ~ 0)
59 return;
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020060 prefix_report_t *q =
61 vlib_process_signal_event_data (vm, ni, et, 1, sizeof *q);
Juraj Sloboda81119e82018-05-25 14:02:20 +020062
63 *q = *r;
64}
65
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020066int
67dhcp6_pd_publish_report (prefix_report_t * r)
Juraj Sloboda81119e82018-05-25 14:02:20 +020068{
69 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
70 vl_api_rpc_call_main_thread (signal_report, (u8 *) r, sizeof *r);
71 return 0;
72}
73
74void
75dhcp6_pd_set_publisher_node (uword node_index, uword event_type)
76{
77 dhcp6_pd_client_main_t *cm = &dhcp6_pd_client_main;
78 cm->publisher_node = node_index;
79 cm->publisher_et = event_type;
80}
81
Juraj Sloboda81119e82018-05-25 14:02:20 +020082static void
83stop_sending_client_message (vlib_main_t * vm,
84 dhcp6_pd_client_state_t * client_state)
85{
86 u32 bi0;
87
88 client_state->keep_sending_client_message = 0;
89 vec_free (client_state->params.prefixes);
90 if (client_state->buffer)
91 {
92 bi0 = vlib_get_buffer_index (vm, client_state->buffer);
93 vlib_buffer_free (vm, &bi0, 1);
94 client_state->buffer = 0;
95 adj_unlock (client_state->adj_index);
96 client_state->adj_index = ~0;
97 }
98}
99
Juraj Sloboda81119e82018-05-25 14:02:20 +0200100static vlib_buffer_t *
101create_buffer_for_client_message (vlib_main_t * vm,
102 u32 sw_if_index,
103 dhcp6_pd_client_state_t
104 * client_state, u32 type)
105{
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200106 dhcp6_client_common_main_t *ccm = &dhcp6_client_common_main;
Juraj Sloboda81119e82018-05-25 14:02:20 +0200107 vnet_main_t *vnm = vnet_get_main ();
108
109 vlib_buffer_t *b;
110 u32 bi;
111 ip6_header_t *ip;
112 udp_header_t *udp;
113 dhcpv6_header_t *dhcp;
114 ip6_address_t src_addr;
115 u32 dhcp_opt_len = 0;
116 client_state->transaction_start = vlib_time_now (vm);
117 u32 n_prefixes;
118 u32 i;
119
120 vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
121 vnet_sw_interface_t *sup_sw = vnet_get_sup_sw_interface (vnm, sw_if_index);
122 vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, sw_if_index);
123
124 /* Interface(s) down? */
125 if ((hw->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) == 0)
126 return NULL;
127 if ((sup_sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0)
128 return NULL;
129 if ((sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0)
130 return NULL;
131
132 /* Get a link-local address */
133 src_addr = ip6_neighbor_get_link_local_address (sw_if_index);
134
135 if (src_addr.as_u8[0] != 0xfe)
136 {
137 clib_warning ("Could not find source address to send DHCPv6 packet");
138 return NULL;
139 }
140
141 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
142 {
143 clib_warning ("Buffer allocation failed");
144 return NULL;
145 }
146
147 b = vlib_get_buffer (vm, bi);
148 vnet_buffer (b)->sw_if_index[VLIB_RX] = sw_if_index;
149 vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
150 client_state->adj_index = adj_mcast_add_or_lock (FIB_PROTOCOL_IP6,
151 VNET_LINK_IP6,
152 sw_if_index);
153 vnet_buffer (b)->ip.adj_index[VLIB_TX] = client_state->adj_index;
154 b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
155
156 ip = (ip6_header_t *) vlib_buffer_get_current (b);
157 udp = (udp_header_t *) (ip + 1);
158 dhcp = (dhcpv6_header_t *) (udp + 1);
159
160 ip->src_address = src_addr;
161 ip->hop_limit = 255;
162 ip->ip_version_traffic_class_and_flow_label =
163 clib_host_to_net_u32 (0x6 << 28);
164 ip->payload_length = 0;
165 ip->protocol = IP_PROTOCOL_UDP;
166
167 udp->src_port = clib_host_to_net_u16 (DHCPV6_CLIENT_PORT);
168 udp->dst_port = clib_host_to_net_u16 (DHCPV6_SERVER_PORT);
169 udp->checksum = 0;
170 udp->length = 0;
171
172 dhcp->msg_type = type;
173 dhcp->xid[0] = (client_state->transaction_id & 0x00ff0000) >> 16;
174 dhcp->xid[1] = (client_state->transaction_id & 0x0000ff00) >> 8;
175 dhcp->xid[2] = (client_state->transaction_id & 0x000000ff) >> 0;
176
177 void *d = (void *) dhcp->data;
178 dhcpv6_option_t *duid;
179 dhcpv6_elapsed_t *elapsed;
180 dhcpv6_ia_header_t *ia_hdr;
181 dhcpv6_ia_opt_pd_t *opt_pd;
182 if (type == DHCPV6_MSG_SOLICIT || type == DHCPV6_MSG_REQUEST ||
183 type == DHCPV6_MSG_RENEW || type == DHCPV6_MSG_REBIND ||
184 type == DHCPV6_MSG_RELEASE)
185 {
186 duid = (dhcpv6_option_t *) d;
187 duid->option = clib_host_to_net_u16 (DHCPV6_OPTION_CLIENTID);
188 duid->length = clib_host_to_net_u16 (CLIENT_DUID_LENGTH);
189 clib_memcpy (duid + 1, client_duid.bin_string, CLIENT_DUID_LENGTH);
190 d += sizeof (*duid) + CLIENT_DUID_LENGTH;
191
192 if (client_state->params.server_index != ~0)
193 {
194 server_id_t *se =
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200195 &ccm->server_ids[client_state->params.server_index];
Juraj Sloboda81119e82018-05-25 14:02:20 +0200196
197 duid = (dhcpv6_option_t *) d;
198 duid->option = clib_host_to_net_u16 (DHCPV6_OPTION_SERVERID);
199 duid->length = clib_host_to_net_u16 (se->len);
200 clib_memcpy (duid + 1, se->data, se->len);
201 d += sizeof (*duid) + se->len;
202 }
203
204 elapsed = (dhcpv6_elapsed_t *) d;
205 elapsed->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_ELAPSED_TIME);
206 elapsed->opt.length =
207 clib_host_to_net_u16 (sizeof (*elapsed) - sizeof (elapsed->opt));
208 elapsed->elapsed_10ms = 0;
209 client_state->elapsed_pos =
210 (char *) &elapsed->elapsed_10ms -
211 (char *) vlib_buffer_get_current (b);
212 d += sizeof (*elapsed);
213
214 ia_hdr = (dhcpv6_ia_header_t *) d;
215 ia_hdr->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_IA_PD);
216 ia_hdr->iaid = clib_host_to_net_u32 (DHCPV6_CLIENT_IAID);
217 ia_hdr->t1 = clib_host_to_net_u32 (client_state->params.T1);
218 ia_hdr->t2 = clib_host_to_net_u32 (client_state->params.T2);
219 d += sizeof (*ia_hdr);
220
221 n_prefixes = vec_len (client_state->params.prefixes);
222
223 ia_hdr->opt.length =
224 clib_host_to_net_u16 (sizeof (*ia_hdr) +
225 n_prefixes * sizeof (*opt_pd) -
226 sizeof (ia_hdr->opt));
227
228 for (i = 0; i < n_prefixes; i++)
229 {
230 dhcp6_pd_send_client_message_params_prefix_t *pref =
231 &client_state->params.prefixes[i];
232 opt_pd = (dhcpv6_ia_opt_pd_t *) d;
233 opt_pd->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_IAPREFIX);
234 opt_pd->opt.length =
235 clib_host_to_net_u16 (sizeof (*opt_pd) - sizeof (opt_pd->opt));
236 opt_pd->addr = pref->prefix;
237 opt_pd->prefix = pref->prefix_length;
238 opt_pd->valid = clib_host_to_net_u32 (pref->valid_lt);
239 opt_pd->preferred = clib_host_to_net_u32 (pref->preferred_lt);
240 d += sizeof (*opt_pd);
241 }
242 }
243 else
244 {
245 clib_warning ("State not implemented");
246 }
247
248 dhcp_opt_len = ((u8 *) d) - dhcp->data;
249 udp->length =
250 clib_host_to_net_u16 (sizeof (*udp) + sizeof (*dhcp) + dhcp_opt_len);
251 ip->payload_length = udp->length;
252 b->current_length =
253 sizeof (*ip) + sizeof (*udp) + sizeof (*dhcp) + dhcp_opt_len;
254
255 ip->dst_address = all_dhcp6_relay_agents_and_servers;
256
257 return b;
258}
259
260static inline u8
261check_pd_send_client_message (vlib_main_t * vm,
262 dhcp6_pd_client_state_t * client_state,
263 f64 current_time, f64 * due_time)
264{
265 vlib_buffer_t *p0;
266 vlib_frame_t *f;
267 u32 *to_next;
268 u32 next_index;
269 vlib_buffer_t *c0;
270 ip6_header_t *ip;
271 udp_header_t *udp;
272 u32 ci0;
273 int bogus_length = 0;
274
275 dhcp6_pd_send_client_message_params_t *params;
276
277 f64 now = vlib_time_now (vm);
278
279 if (!client_state->keep_sending_client_message)
280 return false;
281
282 params = &client_state->params;
283
284 if (client_state->due_time > current_time)
285 {
286 *due_time = client_state->due_time;
287 return true;
288 }
289
290 p0 = client_state->buffer;
291
292 next_index = ip6_rewrite_mcast_node.index;
293
294 c0 = vlib_buffer_copy (vm, p0);
295 ci0 = vlib_get_buffer_index (vm, c0);
296
297 ip = (ip6_header_t *) vlib_buffer_get_current (c0);
298 udp = (udp_header_t *) (ip + 1);
299
300 u16 *elapsed_field = (u16 *) ((void *) ip + client_state->elapsed_pos);
301 *elapsed_field =
302 clib_host_to_net_u16 ((u16)
303 ((now - client_state->transaction_start) * 100));
304
305 udp->checksum = 0;
306 udp->checksum =
307 ip6_tcp_udp_icmp_compute_checksum (vm, 0, ip, &bogus_length);
308
309 f = vlib_get_frame_to_node (vm, next_index);
310 to_next = vlib_frame_vector_args (f);
311 to_next[0] = ci0;
312 f->n_vectors = 1;
313 vlib_put_frame_to_node (vm, next_index, f);
314
315 if (params->mrc != 0 && --client_state->n_left == 0)
316 stop_sending_client_message (vm, client_state);
317 else
318 {
319 client_state->sleep_interval =
320 (2 + random_f64_from_to (-0.1, 0.1)) * client_state->sleep_interval;
321 if (client_state->sleep_interval > params->mrt)
322 client_state->sleep_interval =
323 (1 + random_f64_from_to (-0.1, 0.1)) * params->mrt;
324
325 client_state->due_time = current_time + client_state->sleep_interval;
326
327 if (params->mrd != 0
328 && current_time > client_state->start_time + params->mrd)
329 stop_sending_client_message (vm, client_state);
330 else
331 *due_time = client_state->due_time;
332 }
333
334 return client_state->keep_sending_client_message;
335}
336
337static uword
338send_dhcp6_pd_client_message_process (vlib_main_t * vm,
339 vlib_node_runtime_t * rt,
340 vlib_frame_t * f0)
341{
342 dhcp6_pd_client_main_t *cm = &dhcp6_pd_client_main;
343 dhcp6_pd_client_state_t *client_state;
344 uword *event_data = 0;
345 f64 sleep_time = 1e9;
346 f64 current_time;
347 f64 due_time;
348 f64 dt = 0;
349 int i;
350
351 while (true)
352 {
353 vlib_process_wait_for_event_or_clock (vm, sleep_time);
354 vlib_process_get_events (vm, &event_data);
355 vec_reset_length (event_data);
356
357 current_time = vlib_time_now (vm);
358 do
359 {
360 due_time = current_time + 1e9;
361 for (i = 0; i < vec_len (cm->client_state_by_sw_if_index); i++)
362 {
363 client_state = &cm->client_state_by_sw_if_index[i];
364 if (!client_state->entry_valid)
365 continue;
366 if (check_pd_send_client_message
367 (vm, client_state, current_time, &dt) && (dt < due_time))
368 due_time = dt;
369 }
370 current_time = vlib_time_now (vm);
371 }
372 while (due_time < current_time);
373
374 sleep_time = due_time - current_time;
375 }
376
377 return 0;
378}
379
380/* *INDENT-OFF* */
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200381VLIB_REGISTER_NODE (send_dhcp6_pd_client_message_process_node, static) = {
Juraj Sloboda81119e82018-05-25 14:02:20 +0200382 .function = send_dhcp6_pd_client_message_process,
383 .type = VLIB_NODE_TYPE_PROCESS,
384 .name = "send-dhcp6-pd-client-message-process",
385};
386/* *INDENT-ON* */
387
388void
389dhcp6_pd_send_client_message (vlib_main_t * vm, u32 sw_if_index, u8 stop,
390 dhcp6_pd_send_client_message_params_t * params)
391{
392 dhcp6_pd_client_main_t *cm = &dhcp6_pd_client_main;
393 dhcp6_pd_client_state_t *client_state = 0;
394 dhcp6_pd_client_state_t empty_state = {
395 0,
396 };
397
398 ASSERT (~0 != sw_if_index);
399
400 vec_validate_init_empty (cm->client_state_by_sw_if_index, sw_if_index,
401 empty_state);
402 client_state = &cm->client_state_by_sw_if_index[sw_if_index];
403 if (!client_state->entry_valid)
404 {
405 client_state->entry_valid = 1;
406 client_state->adj_index = ~0;
407 }
408
409 stop_sending_client_message (vm, client_state);
410
411 if (!stop)
412 {
413 client_state->keep_sending_client_message = 1;
414 vec_free (client_state->params.prefixes);
415 client_state->params = *params;
416 client_state->params.prefixes = vec_dup (params->prefixes);
417 client_state->n_left = params->mrc;
418 client_state->start_time = vlib_time_now (vm);
419 client_state->sleep_interval =
420 (1 + random_f64_from_to (-0.1, 0.1)) * params->irt;
421 client_state->due_time = 0; /* send first packet ASAP */
422 client_state->transaction_id = random_u32 (&cm->seed) & 0x00ffffff;
423 client_state->buffer =
424 create_buffer_for_client_message (vm, sw_if_index, client_state,
425 params->msg_type);
426 if (!client_state->buffer)
427 client_state->keep_sending_client_message = 0;
428 else
429 vlib_process_signal_event (vm,
430 send_dhcp6_pd_client_message_process_node.index,
431 1, 0);
432 }
433}
434
435void
436 vl_api_dhcp6_pd_send_client_message_t_handler
437 (vl_api_dhcp6_pd_send_client_message_t * mp)
438{
439 vl_api_dhcp6_pd_send_client_message_reply_t *rmp;
440 dhcp6_pd_send_client_message_params_t params;
441 vlib_main_t *vm = vlib_get_main ();
442 u32 n_prefixes;
443 u32 i;
444 int rv = 0;
445
446 VALIDATE_SW_IF_INDEX (mp);
447
448 BAD_SW_IF_INDEX_LABEL;
449 REPLY_MACRO (VL_API_DHCP6_PD_SEND_CLIENT_MESSAGE_REPLY);
450
451 if (rv != 0)
452 return;
453
454 params.sw_if_index = ntohl (mp->sw_if_index);
455 params.server_index = ntohl (mp->server_index);
456 params.irt = ntohl (mp->irt);
457 params.mrt = ntohl (mp->mrt);
458 params.mrc = ntohl (mp->mrc);
459 params.mrd = ntohl (mp->mrd);
460 params.msg_type = mp->msg_type;
461 params.T1 = ntohl (mp->T1);
462 params.T2 = ntohl (mp->T2);
463 n_prefixes = ntohl (mp->n_prefixes);
464 params.prefixes = 0;
465 if (n_prefixes > 0)
466 vec_validate (params.prefixes, n_prefixes - 1);
467 for (i = 0; i < n_prefixes; i++)
468 {
469 vl_api_dhcp6_pd_prefix_info_t *pi = &mp->prefixes[i];
470 dhcp6_pd_send_client_message_params_prefix_t *pref =
471 &params.prefixes[i];
472 pref->preferred_lt = ntohl (pi->preferred_time);
473 pref->valid_lt = ntohl (pi->valid_time);
474 memcpy (pref->prefix.as_u8, pi->prefix, 16);
475 pref->prefix_length = pi->prefix_length;
476 }
477
478 dhcp6_pd_send_client_message (vm, ntohl (mp->sw_if_index), mp->stop,
479 &params);
480}
481
482static clib_error_t *
483call_dhcp6_pd_reply_event_callbacks (void *data,
484 _vnet_dhcp6_pd_reply_event_function_list_elt_t
485 * elt)
486{
487 clib_error_t *error = 0;
488
489 while (elt)
490 {
491 error = elt->fp (data);
492 if (error)
493 return error;
494 elt = elt->next_dhcp6_pd_reply_event_function;
495 }
496
497 return error;
498}
499
500static uword
501dhcp6_pd_reply_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
502 vlib_frame_t * f)
503{
504 /* These cross the longjmp boundry (vlib_process_wait_for_event)
505 * and need to be volatile - to prevent them from being optimized into
506 * a register - which could change during suspension */
507
508 while (1)
509 {
510 vlib_process_wait_for_event (vm);
511 uword event_type = DHCP6_PD_DP_REPLY_REPORT;
512 void *event_data = vlib_process_get_event_data (vm, &event_type);
513
514 int i;
515 if (event_type == DHCP6_PD_DP_REPLY_REPORT)
516 {
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200517 prefix_report_t *events = event_data;
Juraj Sloboda81119e82018-05-25 14:02:20 +0200518 for (i = 0; i < vec_len (events); i++)
519 {
520 u32 event_size =
521 sizeof (vl_api_dhcp6_pd_reply_event_t) +
522 vec_len (events[i].prefixes) *
523 sizeof (vl_api_dhcp6_pd_prefix_info_t);
524 vl_api_dhcp6_pd_reply_event_t *event =
525 clib_mem_alloc (event_size);
526 memset (event, 0, event_size);
527
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200528 event->sw_if_index = htonl (events[i].body.sw_if_index);
529 event->server_index = htonl (events[i].body.server_index);
530 event->msg_type = events[i].body.msg_type;
531 event->T1 = htonl (events[i].body.T1);
532 event->T2 = htonl (events[i].body.T2);
533 event->inner_status_code =
534 htons (events[i].body.inner_status_code);
535 event->status_code = htons (events[i].body.status_code);
536 event->preference = events[i].body.preference;
Juraj Sloboda81119e82018-05-25 14:02:20 +0200537
538 event->n_prefixes = htonl (vec_len (events[i].prefixes));
539 vl_api_dhcp6_pd_prefix_info_t *prefix =
540 (typeof (prefix)) event->prefixes;
541 u32 j;
542 for (j = 0; j < vec_len (events[i].prefixes); j++)
543 {
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200544 dhcp6_prefix_info_t *info = &events[i].prefixes[j];
Juraj Sloboda81119e82018-05-25 14:02:20 +0200545 memcpy (prefix->prefix, &info->prefix, 16);
546 prefix->prefix_length = info->prefix_length;
547 prefix->valid_time = htonl (info->valid_time);
548 prefix->preferred_time = htonl (info->preferred_time);
549 prefix++;
550 }
551
552 dhcp6_pd_client_public_main_t *dpcpm =
553 &dhcp6_pd_client_public_main;
554 call_dhcp6_pd_reply_event_callbacks (event, dpcpm->functions);
555
556 vpe_client_registration_t *reg;
557 /* *INDENT-OFF* */
558 pool_foreach(reg, vpe_api_main.dhcp6_pd_reply_events_registrations,
559 ({
560 vl_api_registration_t *vl_reg;
561 vl_reg =
562 vl_api_client_index_to_registration (reg->client_index);
563 if (vl_reg && vl_api_can_send_msg (vl_reg))
564 {
565 vl_api_dhcp6_pd_reply_event_t *msg =
566 vl_msg_api_alloc (event_size);
567 clib_memcpy (msg, event, event_size);
568 msg->_vl_msg_id = htons (VL_API_DHCP6_PD_REPLY_EVENT);
569 msg->client_index = reg->client_index;
570 msg->pid = reg->client_pid;
571 vl_api_send_msg (vl_reg, (u8 *) msg);
572 }
573 }));
574 /* *INDENT-ON* */
575
576 clib_mem_free (event);
577 }
578 }
579 vlib_process_put_event_data (vm, event_data);
580 }
581
582 return 0;
583}
584
585/* *INDENT-OFF* */
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200586VLIB_REGISTER_NODE (dhcp6_pd_reply_process_node) = {
Juraj Sloboda81119e82018-05-25 14:02:20 +0200587 .function = dhcp6_pd_reply_process,
588 .type = VLIB_NODE_TYPE_PROCESS,
589 .name = "dhcp6-pd-reply-publisher-process",
590};
591/* *INDENT-ON* */
592
593void
594 vl_api_want_dhcp6_pd_reply_events_t_handler
595 (vl_api_want_dhcp6_pd_reply_events_t * mp)
596{
597 vpe_api_main_t *am = &vpe_api_main;
598 vl_api_want_dhcp6_pd_reply_events_reply_t *rmp;
599 int rv = 0;
600
601 uword *p =
602 hash_get (am->dhcp6_pd_reply_events_registration_hash, mp->client_index);
603 vpe_client_registration_t *rp;
604 if (p)
605 {
606 if (mp->enable_disable)
607 {
608 clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
609 rv = VNET_API_ERROR_INVALID_REGISTRATION;
610 goto reply;
611 }
612 else
613 {
614 rp =
615 pool_elt_at_index (am->dhcp6_pd_reply_events_registrations, p[0]);
616 pool_put (am->dhcp6_pd_reply_events_registrations, rp);
617 hash_unset (am->dhcp6_pd_reply_events_registration_hash,
618 mp->client_index);
619 if (pool_elts (am->dhcp6_pd_reply_events_registrations) == 0)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200620 dhcp6_pd_set_publisher_node (~0, DHCP6_PD_DP_REPORT_MAX);
Juraj Sloboda81119e82018-05-25 14:02:20 +0200621 goto reply;
622 }
623 }
624 if (mp->enable_disable == 0)
625 {
626 clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
627 rv = VNET_API_ERROR_INVALID_REGISTRATION;
628 goto reply;
629 }
630 pool_get (am->dhcp6_pd_reply_events_registrations, rp);
631 rp->client_index = mp->client_index;
632 rp->client_pid = ntohl (mp->pid);
633 hash_set (am->dhcp6_pd_reply_events_registration_hash, rp->client_index,
634 rp - am->dhcp6_pd_reply_events_registrations);
635 dhcp6_pd_set_publisher_node (dhcp6_pd_reply_process_node.index,
636 DHCP6_PD_DP_REPLY_REPORT);
637
638reply:
639 REPLY_MACRO (VL_API_WANT_DHCP6_PD_REPLY_EVENTS_REPLY);
640}
641
Juraj Sloboda81119e82018-05-25 14:02:20 +0200642static clib_error_t *
643dhcp6_pd_client_init (vlib_main_t * vm)
644{
645 dhcp6_pd_client_main_t *cm = &dhcp6_pd_client_main;
646
647 cm->vlib_main = vm;
648 cm->vnet_main = vnet_get_main ();
649
650 cm->publisher_node = ~0;
651
652 cm->seed = 0xdeaddabe;
653
Juraj Sloboda81119e82018-05-25 14:02:20 +0200654 return 0;
655}
656
657VLIB_INIT_FUNCTION (dhcp6_pd_client_init);
658
659/*
660 * fd.io coding-style-patch-verification: ON
661 *
662 * Local Variables:
663 * eval: (c-set-style "gnu")
664 * End:
665 */