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