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