2 *------------------------------------------------------------------
3 * dhcp_api.c - dhcp api
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <dhcp/dhcp_proxy.h>
26 #include <dhcp/client.h>
27 #include <dhcp/dhcp6_pd_client_dp.h>
28 #include <dhcp/dhcp6_ia_na_client_dp.h>
29 #include <dhcp/dhcp6_client_common_dp.h>
30 #include <vnet/fib/fib_table.h>
31 #include <vnet/ip/ip_types_api.h>
33 /* define message IDs */
34 #include <vnet/format_fns.h>
35 #include <dhcp/dhcp.api_enum.h>
36 #include <dhcp/dhcp.api_types.h>
39 * Base message ID fot the plugin
41 static u32 dhcp_base_msg_id;
42 #define REPLY_MSG_ID_BASE dhcp_base_msg_id
44 #include <vlibapi/api_helper_macros.h>
46 #define DHCP_PLUGIN_VERSION_MAJOR 1
47 #define DHCP_PLUGIN_VERSION_MINOR 0
50 vl_api_dhcp_plugin_get_version_t_handler (vl_api_dhcp_plugin_get_version_t *
53 vl_api_dhcp_plugin_get_version_reply_t *rmp;
54 int msg_size = sizeof (*rmp);
55 vl_api_registration_t *reg;
57 reg = vl_api_client_index_to_registration (mp->client_index);
61 rmp = vl_msg_api_alloc (msg_size);
62 clib_memset (rmp, 0, msg_size);
64 ntohs (VL_API_DHCP_PLUGIN_GET_VERSION_REPLY + REPLY_MSG_ID_BASE);
65 rmp->context = mp->context;
66 rmp->major = htonl (DHCP_PLUGIN_VERSION_MAJOR);
67 rmp->minor = htonl (DHCP_PLUGIN_VERSION_MINOR);
69 vl_api_send_msg (reg, (u8 *) rmp);
73 vl_api_dhcp_plugin_control_ping_t_handler (vl_api_dhcp_plugin_control_ping_t *
76 vl_api_dhcp_plugin_control_ping_reply_t *rmp;
80 REPLY_MACRO2 (VL_API_DHCP_PLUGIN_CONTROL_PING_REPLY,
82 rmp->vpe_pid = ntohl (getpid ());
88 vl_api_dhcp6_duid_ll_set_t_handler (vl_api_dhcp6_duid_ll_set_t * mp)
90 vl_api_dhcp6_duid_ll_set_reply_t *rmp;
91 dhcpv6_duid_ll_string_t *duid;
94 duid = (dhcpv6_duid_ll_string_t *) mp->duid_ll;
95 if (duid->duid_type != htonl (DHCPV6_DUID_LL))
97 rv = VNET_API_ERROR_INVALID_VALUE;
100 clib_memcpy (&client_duid, &duid, sizeof (client_duid));
103 REPLY_MACRO (VL_API_DHCP6_DUID_LL_SET_REPLY);
107 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
109 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
113 mp->vpn_ascii_id[sizeof (mp->vpn_ascii_id) - 1] = 0;
114 vpn_ascii_id = format (0, "%s", mp->vpn_ascii_id);
116 dhcp_proxy_set_vss ((mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4),
117 ntohl (mp->tbl_id), ntohl (mp->vss_type),
118 vpn_ascii_id, ntohl (mp->oui), ntohl (mp->vpn_index),
121 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
125 static void vl_api_dhcp_proxy_config_t_handler
126 (vl_api_dhcp_proxy_config_t * mp)
128 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
129 ip46_address_t src, server;
132 if (mp->dhcp_src_address.af != mp->dhcp_server.af)
134 rv = VNET_API_ERROR_INVALID_ARGUMENT;
138 ip_address_decode (&mp->dhcp_src_address, &src);
139 ip_address_decode (&mp->dhcp_server, &server);
141 if (mp->dhcp_src_address.af == ADDRESS_IP4)
143 rv = dhcp4_proxy_set_server (&server,
145 (u32) ntohl (mp->rx_vrf_id),
146 (u32) ntohl (mp->server_vrf_id),
147 (int) (mp->is_add == 0));
151 rv = dhcp6_proxy_set_server (&server,
153 (u32) ntohl (mp->rx_vrf_id),
154 (u32) ntohl (mp->server_vrf_id),
155 (int) (mp->is_add == 0));
159 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
163 vl_api_dhcp_proxy_dump_t_handler (vl_api_dhcp_proxy_dump_t * mp)
165 vl_api_registration_t *reg;
167 reg = vl_api_client_index_to_registration (mp->client_index);
171 dhcp_proxy_dump ((mp->is_ip6 == 1 ?
172 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4), reg, mp->context);
176 dhcp_send_details (fib_protocol_t proto,
177 void *opaque, u32 context, dhcp_proxy_t * proxy)
179 vl_api_dhcp_proxy_details_t *mp;
180 vl_api_registration_t *reg = opaque;
181 vl_api_dhcp_server_t *v_server;
182 dhcp_server_t *server;
188 count = vec_len (proxy->dhcp_servers);
189 n = sizeof (*mp) + (count * sizeof (vl_api_dhcp_server_t));
190 mp = vl_msg_api_alloc (n);
193 clib_memset (mp, 0, n);
194 mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_DETAILS + REPLY_MSG_ID_BASE);
195 mp->context = context;
198 mp->is_ipv6 = (proto == FIB_PROTOCOL_IP6);
200 htonl (dhcp_proxy_rx_table_get_table_id (proto, proxy->rx_fib_index));
202 vss = dhcp_get_vss_info (&dhcp_proxy_main, proxy->rx_fib_index, proto);
206 mp->vss_type = ntohl (vss->vss_type);
207 if (vss->vss_type == VSS_TYPE_ASCII)
209 u32 id_len = vec_len (vss->vpn_ascii_id);
210 clib_memcpy (mp->vss_vpn_ascii_id, vss->vpn_ascii_id, id_len);
212 else if (vss->vss_type == VSS_TYPE_VPN_ID)
214 u32 oui = ((u32) vss->vpn_id[0] << 16) + ((u32) vss->vpn_id[1] << 8)
215 + ((u32) vss->vpn_id[2]);
216 u32 fib_id = ((u32) vss->vpn_id[3] << 24) +
217 ((u32) vss->vpn_id[4] << 16) + ((u32) vss->vpn_id[5] << 8) +
218 ((u32) vss->vpn_id[6]);
219 mp->vss_oui = htonl (oui);
220 mp->vss_fib_id = htonl (fib_id);
224 mp->vss_type = VSS_TYPE_INVALID;
226 vec_foreach_index (count, proxy->dhcp_servers)
228 server = &proxy->dhcp_servers[count];
229 v_server = &mp->servers[count];
231 s_fib = fib_table_get (server->server_fib_index, proto);
233 v_server->server_vrf_id = htonl (s_fib->ft_table_id);
237 memcpy (&v_server->dhcp_server.un, &server->dhcp_server.ip6, 16);
241 /* put the address in the first bytes */
242 memcpy (&v_server->dhcp_server.un, &server->dhcp_server.ip4, 4);
248 memcpy (&mp->dhcp_src_address.un, &proxy->dhcp_src_address.ip6, 16);
252 /* put the address in the first bytes */
253 memcpy (&mp->dhcp_src_address.un, &proxy->dhcp_src_address.ip4, 4);
255 vl_api_send_msg (reg, (u8 *) mp);
259 dhcp_client_lease_encode (vl_api_dhcp_lease_t * lease,
260 const dhcp_client_t * client)
265 lease->is_ipv6 = 0; // only support IPv4 clients
266 lease->sw_if_index = ntohl (client->sw_if_index);
267 lease->state = ntohl (client->state);
268 len = clib_min (sizeof (lease->hostname) - 1, vec_len (client->hostname));
269 clib_memcpy (&lease->hostname, client->hostname, len);
270 lease->hostname[len] = 0;
272 lease->mask_width = client->installed.subnet_mask_width;
273 clib_memcpy (&lease->host_address.un,
274 (u8 *) & client->installed.leased_address,
275 sizeof (ip4_address_t));
276 clib_memcpy (&lease->router_address.un,
277 (u8 *) & client->installed.router_address,
278 sizeof (ip4_address_t));
280 lease->count = vec_len (client->domain_server_address);
281 for (i = 0; i < lease->count; i++)
282 clib_memcpy (&lease->domain_server[i].address.un.ip4,
283 (u8 *) &client->domain_server_address[i],
284 sizeof (ip4_address_t));
286 clib_memcpy (&lease->host_mac[0], client->client_hardware_address, 6);
290 dhcp_client_data_encode (vl_api_dhcp_client_t * vclient,
291 const dhcp_client_t * client)
295 vclient->sw_if_index = ntohl (client->sw_if_index);
296 len = clib_min (sizeof (vclient->hostname) - 1, vec_len (client->hostname));
297 clib_memcpy (&vclient->hostname, client->hostname, len);
298 vclient->hostname[len] = 0;
300 len = clib_min (sizeof (vclient->id) - 1,
301 vec_len (client->client_identifier));
302 clib_memcpy (&vclient->id, client->client_identifier, len);
303 vclient->id[len] = 0;
305 if (NULL != client->event_callback)
306 vclient->want_dhcp_event = 1;
308 vclient->want_dhcp_event = 0;
309 vclient->set_broadcast_flag = client->set_broadcast_flag;
310 vclient->dscp = ip_dscp_encode (client->dscp);
311 vclient->pid = client->pid;
315 dhcp_compl_event_callback (u32 client_index, const dhcp_client_t * client)
317 vl_api_registration_t *reg;
318 vl_api_dhcp_compl_event_t *mp;
320 reg = vl_api_client_index_to_registration (client_index);
324 mp = vl_msg_api_alloc (sizeof (*mp) +
325 sizeof (vl_api_domain_server_t) *
326 vec_len (client->domain_server_address));
327 mp->client_index = client_index;
328 mp->pid = client->pid;
329 dhcp_client_lease_encode (&mp->lease, client);
331 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT + REPLY_MSG_ID_BASE);
333 vl_api_send_msg (reg, (u8 *) mp);
336 static void vl_api_dhcp_client_config_t_handler
337 (vl_api_dhcp_client_config_t * mp)
339 vlib_main_t *vm = vlib_get_main ();
340 vl_api_dhcp_client_config_reply_t *rmp;
345 VALIDATE_SW_IF_INDEX (&(mp->client));
347 sw_if_index = ntohl (mp->client.sw_if_index);
348 dscp = ip_dscp_decode (mp->client.dscp);
350 rv = dhcp_client_config (mp->is_add,
356 (mp->client.want_dhcp_event ?
357 dhcp_compl_event_callback :
359 mp->client.set_broadcast_flag,
360 dscp, mp->client.pid);
362 BAD_SW_IF_INDEX_LABEL;
363 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
366 typedef struct dhcp_client_send_walk_ctx_t_
368 vl_api_registration_t *reg;
370 } dhcp_client_send_walk_ctx_t;
373 send_dhcp_client_entry (const dhcp_client_t * client, void *arg)
375 dhcp_client_send_walk_ctx_t *ctx;
376 vl_api_dhcp_client_details_t *mp;
382 count = vec_len (client->domain_server_address);
383 n = sizeof (*mp) + (count * sizeof (vl_api_domain_server_t));
384 mp = vl_msg_api_alloc (n);
387 clib_memset (mp, 0, n);
389 mp->_vl_msg_id = ntohs (VL_API_DHCP_CLIENT_DETAILS + REPLY_MSG_ID_BASE);
390 mp->context = ctx->context;
392 dhcp_client_data_encode (&mp->client, client);
393 dhcp_client_lease_encode (&mp->lease, client);
395 vl_api_send_msg (ctx->reg, (u8 *) mp);
401 vl_api_dhcp_client_dump_t_handler (vl_api_dhcp_client_dump_t * mp)
403 vl_api_registration_t *reg;
405 reg = vl_api_client_index_to_registration (mp->client_index);
409 dhcp_client_send_walk_ctx_t ctx = {
411 .context = mp->context,
413 dhcp_client_walk (send_dhcp_client_entry, &ctx);
417 vl_api_dhcp6_clients_enable_disable_t_handler
418 (vl_api_dhcp6_clients_enable_disable_t * mp)
420 vl_api_dhcp6_clients_enable_disable_reply_t *rmp;
423 dhcp6_clients_enable_disable (mp->enable);
425 REPLY_MACRO (VL_API_DHCP6_CLIENTS_ENABLE_DISABLE_REPLY);
429 vl_api_want_dhcp6_reply_events_t_handler
430 (vl_api_want_dhcp6_reply_events_t * mp)
432 vpe_api_main_t *am = &vpe_api_main;
433 vl_api_want_dhcp6_reply_events_reply_t *rmp;
437 hash_get (am->dhcp6_reply_events_registration_hash, mp->client_index);
438 vpe_client_registration_t *rp;
441 if (mp->enable_disable)
443 clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
444 rv = VNET_API_ERROR_INVALID_REGISTRATION;
449 rp = pool_elt_at_index (am->dhcp6_reply_events_registrations, p[0]);
450 pool_put (am->dhcp6_reply_events_registrations, rp);
451 hash_unset (am->dhcp6_reply_events_registration_hash,
453 if (pool_elts (am->dhcp6_reply_events_registrations) == 0)
454 dhcp6_set_publisher_node (~0, DHCP6_DP_REPORT_MAX);
458 if (mp->enable_disable == 0)
460 clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
461 rv = VNET_API_ERROR_INVALID_REGISTRATION;
464 pool_get (am->dhcp6_reply_events_registrations, rp);
465 rp->client_index = mp->client_index;
466 rp->client_pid = ntohl (mp->pid);
467 hash_set (am->dhcp6_reply_events_registration_hash, rp->client_index,
468 rp - am->dhcp6_reply_events_registrations);
469 dhcp6_set_publisher_node (dhcp6_reply_process_node.index,
470 DHCP6_DP_REPLY_REPORT);
473 REPLY_MACRO (VL_API_WANT_DHCP6_REPLY_EVENTS_REPLY);
477 vl_api_want_dhcp6_pd_reply_events_t_handler
478 (vl_api_want_dhcp6_pd_reply_events_t * mp)
480 vpe_api_main_t *am = &vpe_api_main;
481 vl_api_want_dhcp6_pd_reply_events_reply_t *rmp;
485 hash_get (am->dhcp6_pd_reply_events_registration_hash, mp->client_index);
486 vpe_client_registration_t *rp;
489 if (mp->enable_disable)
491 clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
492 rv = VNET_API_ERROR_INVALID_REGISTRATION;
498 pool_elt_at_index (am->dhcp6_pd_reply_events_registrations, p[0]);
499 pool_put (am->dhcp6_pd_reply_events_registrations, rp);
500 hash_unset (am->dhcp6_pd_reply_events_registration_hash,
502 if (pool_elts (am->dhcp6_pd_reply_events_registrations) == 0)
503 dhcp6_pd_set_publisher_node (~0, DHCP6_PD_DP_REPORT_MAX);
507 if (mp->enable_disable == 0)
509 clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
510 rv = VNET_API_ERROR_INVALID_REGISTRATION;
513 pool_get (am->dhcp6_pd_reply_events_registrations, rp);
514 rp->client_index = mp->client_index;
515 rp->client_pid = ntohl (mp->pid);
516 hash_set (am->dhcp6_pd_reply_events_registration_hash, rp->client_index,
517 rp - am->dhcp6_pd_reply_events_registrations);
518 dhcp6_pd_set_publisher_node (dhcp6_pd_reply_process_node.index,
519 DHCP6_PD_DP_REPLY_REPORT);
522 REPLY_MACRO (VL_API_WANT_DHCP6_PD_REPLY_EVENTS_REPLY);
526 vl_api_dhcp6_send_client_message_t_handler
527 (vl_api_dhcp6_send_client_message_t * mp)
529 vl_api_dhcp6_send_client_message_reply_t *rmp;
530 dhcp6_send_client_message_params_t params;
531 vlib_main_t *vm = vlib_get_main ();
536 VALIDATE_SW_IF_INDEX (mp);
538 BAD_SW_IF_INDEX_LABEL;
539 REPLY_MACRO (VL_API_DHCP6_SEND_CLIENT_MESSAGE_REPLY);
544 params.sw_if_index = ntohl (mp->sw_if_index);
545 params.server_index = ntohl (mp->server_index);
546 params.irt = ntohl (mp->irt);
547 params.mrt = ntohl (mp->mrt);
548 params.mrc = ntohl (mp->mrc);
549 params.mrd = ntohl (mp->mrd);
550 params.msg_type = ntohl (mp->msg_type);
551 params.T1 = ntohl (mp->T1);
552 params.T2 = ntohl (mp->T2);
553 n_addresses = ntohl (mp->n_addresses);
554 /* Make sure that the number of addresses is sane */
555 if (n_addresses * sizeof (params.addresses) > vl_msg_api_max_length (mp))
557 rv = VNET_API_ERROR_INVALID_VALUE;
558 goto bad_sw_if_index;
560 params.addresses = 0;
562 vec_validate (params.addresses, n_addresses - 1);
563 for (i = 0; i < n_addresses; i++)
565 vl_api_dhcp6_address_info_t *ai = &mp->addresses[i];
566 dhcp6_send_client_message_params_address_t *addr = ¶ms.addresses[i];
567 addr->preferred_lt = ntohl (ai->preferred_time);
568 addr->valid_lt = ntohl (ai->valid_time);
569 ip6_address_decode (ai->address, &addr->address);
572 dhcp6_send_client_message (vm, ntohl (mp->sw_if_index), mp->stop, ¶ms);
576 vl_api_dhcp6_pd_send_client_message_t_handler
577 (vl_api_dhcp6_pd_send_client_message_t * mp)
579 vl_api_dhcp6_pd_send_client_message_reply_t *rmp;
580 dhcp6_pd_send_client_message_params_t params;
581 vlib_main_t *vm = vlib_get_main ();
586 VALIDATE_SW_IF_INDEX (mp);
588 BAD_SW_IF_INDEX_LABEL;
589 REPLY_MACRO (VL_API_DHCP6_PD_SEND_CLIENT_MESSAGE_REPLY);
594 params.sw_if_index = ntohl (mp->sw_if_index);
595 params.server_index = ntohl (mp->server_index);
596 params.irt = ntohl (mp->irt);
597 params.mrt = ntohl (mp->mrt);
598 params.mrc = ntohl (mp->mrc);
599 params.mrd = ntohl (mp->mrd);
600 params.msg_type = ntohl (mp->msg_type);
601 params.T1 = ntohl (mp->T1);
602 params.T2 = ntohl (mp->T2);
603 n_prefixes = ntohl (mp->n_prefixes);
605 /* Minimal check to see that the number of prefixes is sane */
606 if (n_prefixes * sizeof (params.prefixes) > vl_msg_api_max_length (mp))
608 rv = VNET_API_ERROR_INVALID_VALUE;
609 goto bad_sw_if_index;
614 vec_validate (params.prefixes, n_prefixes - 1);
615 for (i = 0; i < n_prefixes; i++)
617 vl_api_dhcp6_pd_prefix_info_t *pi = &mp->prefixes[i];
618 dhcp6_pd_send_client_message_params_prefix_t *pref =
620 pref->preferred_lt = ntohl (pi->preferred_time);
621 pref->valid_lt = ntohl (pi->valid_time);
622 ip6_address_decode (pi->prefix.address, &pref->prefix);
623 pref->prefix_length = pi->prefix.len;
626 dhcp6_pd_send_client_message (vm, ntohl (mp->sw_if_index), mp->stop,
630 static clib_error_t *
631 call_dhcp6_reply_event_callbacks (void *data,
632 _vnet_dhcp6_reply_event_function_list_elt_t
635 clib_error_t *error = 0;
639 error = elt->fp (data);
642 elt = elt->next_dhcp6_reply_event_function;
649 dhcp6_reply_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
652 /* These cross the longjmp boundary (vlib_process_wait_for_event)
653 * and need to be volatile - to prevent them from being optimized into
654 * a register - which could change during suspension */
658 vlib_process_wait_for_event (vm);
659 uword event_type = DHCP6_DP_REPLY_REPORT;
660 void *event_data = vlib_process_get_event_data (vm, &event_type);
663 if (event_type == DHCP6_DP_REPLY_REPORT)
665 address_report_t *events = event_data;
666 for (i = 0; i < vec_len (events); i++)
669 sizeof (vl_api_dhcp6_reply_event_t) +
670 vec_len (events[i].addresses) *
671 sizeof (vl_api_dhcp6_address_info_t);
672 vl_api_dhcp6_reply_event_t *event = clib_mem_alloc (event_size);
673 clib_memset (event, 0, event_size);
675 event->sw_if_index = htonl (events[i].body.sw_if_index);
676 event->server_index = htonl (events[i].body.server_index);
677 event->msg_type = events[i].body.msg_type;
678 event->T1 = htonl (events[i].body.T1);
679 event->T2 = htonl (events[i].body.T2);
680 event->inner_status_code =
681 htons (events[i].body.inner_status_code);
682 event->status_code = htons (events[i].body.status_code);
683 event->preference = events[i].body.preference;
685 event->n_addresses = htonl (vec_len (events[i].addresses));
686 vl_api_dhcp6_address_info_t *address =
687 (typeof (address)) event->addresses;
689 for (j = 0; j < vec_len (events[i].addresses); j++)
691 dhcp6_address_info_t *info = &events[i].addresses[j];
692 ip6_address_encode (&info->address, address->address);
693 address->valid_time = htonl (info->valid_time);
694 address->preferred_time = htonl (info->preferred_time);
697 vec_free (events[i].addresses);
699 dhcp6_ia_na_client_public_main_t *dcpm =
700 &dhcp6_ia_na_client_public_main;
701 call_dhcp6_reply_event_callbacks (event, dcpm->functions);
703 vpe_client_registration_t *reg;
705 pool_foreach (reg, vpe_api_main.dhcp6_reply_events_registrations)
707 vl_api_registration_t *vl_reg;
709 vl_api_client_index_to_registration (reg->client_index);
710 if (vl_reg && vl_api_can_send_msg (vl_reg))
712 vl_api_dhcp6_reply_event_t *msg =
713 vl_msg_api_alloc (event_size);
714 clib_memcpy (msg, event, event_size);
715 msg->_vl_msg_id = htons (VL_API_DHCP6_REPLY_EVENT + REPLY_MSG_ID_BASE);
716 msg->client_index = reg->client_index;
717 msg->pid = reg->client_pid;
718 vl_api_send_msg (vl_reg, (u8 *) msg);
723 clib_mem_free (event);
726 vlib_process_put_event_data (vm, event_data);
733 VLIB_REGISTER_NODE (dhcp6_reply_process_node) = {
734 .function = dhcp6_reply_process,
735 .type = VLIB_NODE_TYPE_PROCESS,
736 .name = "dhcp6-reply-publisher-process",
740 static clib_error_t *
741 call_dhcp6_pd_reply_event_callbacks (void *data,
742 _vnet_dhcp6_pd_reply_event_function_list_elt_t
745 clib_error_t *error = 0;
749 error = elt->fp (data);
752 elt = elt->next_dhcp6_pd_reply_event_function;
759 dhcp6_pd_reply_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
762 /* These cross the longjmp boundary (vlib_process_wait_for_event)
763 * and need to be volatile - to prevent them from being optimized into
764 * a register - which could change during suspension */
768 vlib_process_wait_for_event (vm);
769 uword event_type = DHCP6_PD_DP_REPLY_REPORT;
770 void *event_data = vlib_process_get_event_data (vm, &event_type);
773 if (event_type == DHCP6_PD_DP_REPLY_REPORT)
775 prefix_report_t *events = event_data;
776 for (i = 0; i < vec_len (events); i++)
779 sizeof (vl_api_dhcp6_pd_reply_event_t) +
780 vec_len (events[i].prefixes) *
781 sizeof (vl_api_dhcp6_pd_prefix_info_t);
782 vl_api_dhcp6_pd_reply_event_t *event =
783 clib_mem_alloc (event_size);
784 clib_memset (event, 0, event_size);
786 event->sw_if_index = htonl (events[i].body.sw_if_index);
787 event->server_index = htonl (events[i].body.server_index);
788 event->msg_type = events[i].body.msg_type;
789 event->T1 = htonl (events[i].body.T1);
790 event->T2 = htonl (events[i].body.T2);
791 event->inner_status_code =
792 htons (events[i].body.inner_status_code);
793 event->status_code = htons (events[i].body.status_code);
794 event->preference = events[i].body.preference;
796 event->n_prefixes = htonl (vec_len (events[i].prefixes));
797 vl_api_dhcp6_pd_prefix_info_t *prefix =
798 (typeof (prefix)) event->prefixes;
800 for (j = 0; j < vec_len (events[i].prefixes); j++)
802 dhcp6_prefix_info_t *info = &events[i].prefixes[j];
803 ip6_address_encode (&info->prefix, prefix->prefix.address);
804 prefix->prefix.len = info->prefix_length;
805 prefix->valid_time = htonl (info->valid_time);
806 prefix->preferred_time = htonl (info->preferred_time);
809 vec_free (events[i].prefixes);
811 dhcp6_pd_client_public_main_t *dpcpm =
812 &dhcp6_pd_client_public_main;
813 call_dhcp6_pd_reply_event_callbacks (event, dpcpm->functions);
815 vpe_client_registration_t *reg;
817 pool_foreach (reg, vpe_api_main.dhcp6_pd_reply_events_registrations)
819 vl_api_registration_t *vl_reg;
821 vl_api_client_index_to_registration (reg->client_index);
822 if (vl_reg && vl_api_can_send_msg (vl_reg))
824 vl_api_dhcp6_pd_reply_event_t *msg =
825 vl_msg_api_alloc (event_size);
826 clib_memcpy (msg, event, event_size);
827 msg->_vl_msg_id = htons (VL_API_DHCP6_PD_REPLY_EVENT + REPLY_MSG_ID_BASE);
828 msg->client_index = reg->client_index;
829 msg->pid = reg->client_pid;
830 vl_api_send_msg (vl_reg, (u8 *) msg);
835 clib_mem_free (event);
838 vlib_process_put_event_data (vm, event_data);
845 VLIB_REGISTER_NODE (dhcp6_pd_reply_process_node) = {
846 .function = dhcp6_pd_reply_process,
847 .type = VLIB_NODE_TYPE_PROCESS,
848 .name = "dhcp6-pd-reply-publisher-process",
854 * Add vpe's API message handlers to the table.
855 * vlib has already mapped shared memory and
856 * added the client registration handlers.
857 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
859 #include <dhcp/dhcp.api.c>
861 static clib_error_t *
862 dhcp_api_hookup (vlib_main_t * vm)
865 * Set up the (msg_name, crc, message-id) table
867 dhcp_base_msg_id = setup_message_id_table ();
869 dhcp6_pd_set_publisher_node (dhcp6_pd_reply_process_node.index,
870 DHCP6_PD_DP_REPLY_REPORT);
871 dhcp6_set_publisher_node (dhcp6_reply_process_node.index,
872 DHCP6_DP_REPLY_REPORT);
877 VLIB_API_INIT_FUNCTION (dhcp_api_hookup);
879 #include <vlib/unix/plugin.h>
880 #include <vpp/app/version.h>
883 VLIB_PLUGIN_REGISTER () = {
884 .version = VPP_BUILD_VER,
885 .description = "Dynamic Host Configuration Protocol (DHCP)",
890 * fd.io coding-style-patch-verification: ON
893 * eval: (c-set-style "gnu")