Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * dhcp_api.c - dhcp api |
| 4 | * |
| 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: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 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 | *------------------------------------------------------------------ |
| 18 | */ |
| 19 | |
| 20 | #include <vnet/vnet.h> |
| 21 | #include <vlibmemory/api.h> |
| 22 | |
| 23 | #include <vnet/interface.h> |
| 24 | #include <vnet/api_errno.h> |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 25 | #include <vnet/dhcp/dhcp_proxy.h> |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 26 | #include <vnet/dhcp/client.h> |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 27 | #include <vnet/dhcp/dhcp6_pd_client_dp.h> |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 28 | #include <vnet/dhcp/dhcp6_ia_na_client_dp.h> |
| 29 | #include <vnet/dhcp/dhcp6_client_common_dp.h> |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 30 | #include <vnet/fib/fib_table.h> |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 31 | |
| 32 | #include <vnet/vnet_msg_enum.h> |
| 33 | |
| 34 | #define vl_typedefs /* define message structures */ |
| 35 | #include <vnet/vnet_all_api_h.h> |
| 36 | #undef vl_typedefs |
| 37 | |
| 38 | #define vl_endianfun /* define message structures */ |
| 39 | #include <vnet/vnet_all_api_h.h> |
| 40 | #undef vl_endianfun |
| 41 | |
| 42 | /* instantiate all the print functions we know about */ |
| 43 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 44 | #define vl_printfun |
| 45 | #include <vnet/vnet_all_api_h.h> |
| 46 | #undef vl_printfun |
| 47 | |
| 48 | #include <vlibapi/api_helper_macros.h> |
| 49 | |
| 50 | #define foreach_vpe_api_msg \ |
| 51 | _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \ |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 52 | _(DHCP_PROXY_DUMP,dhcp_proxy_dump) \ |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 53 | _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \ |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 54 | _(DHCP_CLIENT_CONFIG, dhcp_client_config) \ |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 55 | _(DHCP_CLIENT_DUMP, dhcp_client_dump) \ |
| 56 | _(WANT_DHCP6_PD_REPLY_EVENTS, want_dhcp6_pd_reply_events) \ |
| 57 | _(DHCP6_PD_SEND_CLIENT_MESSAGE, dhcp6_pd_send_client_message) \ |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 58 | _(WANT_DHCP6_REPLY_EVENTS, want_dhcp6_reply_events) \ |
| 59 | _(DHCP6_SEND_CLIENT_MESSAGE, dhcp6_send_client_message) \ |
| 60 | _(DHCP6_CLIENTS_ENABLE_DISABLE, dhcp6_clients_enable_disable) \ |
Juraj Sloboda | d9778c2 | 2018-06-12 10:21:05 +0200 | [diff] [blame] | 61 | _(DHCP6_DUID_LL_SET, dhcp6_duid_ll_set) |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 62 | |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 63 | |
| 64 | static void |
| 65 | vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp) |
| 66 | { |
| 67 | vl_api_dhcp_proxy_set_vss_reply_t *rmp; |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 68 | u8 *vpn_ascii_id; |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 69 | int rv; |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 70 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 71 | mp->vpn_ascii_id[sizeof (mp->vpn_ascii_id) - 1] = 0; |
| 72 | vpn_ascii_id = format (0, "%s", mp->vpn_ascii_id); |
| 73 | rv = |
| 74 | dhcp_proxy_set_vss ((mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4), |
| 75 | ntohl (mp->tbl_id), mp->vss_type, vpn_ascii_id, |
| 76 | ntohl (mp->oui), ntohl (mp->vpn_index), |
| 77 | mp->is_add == 0); |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 78 | |
| 79 | REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | static void vl_api_dhcp_proxy_config_t_handler |
| 84 | (vl_api_dhcp_proxy_config_t * mp) |
| 85 | { |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 86 | vl_api_dhcp_proxy_set_vss_reply_t *rmp; |
| 87 | ip46_address_t src, server; |
| 88 | int rv = -1; |
| 89 | |
| 90 | if (mp->is_ipv6) |
| 91 | { |
| 92 | clib_memcpy (&src.ip6, mp->dhcp_src_address, sizeof (src.ip6)); |
| 93 | clib_memcpy (&server.ip6, mp->dhcp_server, sizeof (server.ip6)); |
| 94 | |
| 95 | rv = dhcp6_proxy_set_server (&server, |
| 96 | &src, |
| 97 | (u32) ntohl (mp->rx_vrf_id), |
| 98 | (u32) ntohl (mp->server_vrf_id), |
| 99 | (int) (mp->is_add == 0)); |
| 100 | } |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 101 | else |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 102 | { |
| 103 | ip46_address_reset (&src); |
| 104 | ip46_address_reset (&server); |
| 105 | |
| 106 | clib_memcpy (&src.ip4, mp->dhcp_src_address, sizeof (src.ip4)); |
| 107 | clib_memcpy (&server.ip4, mp->dhcp_server, sizeof (server.ip4)); |
| 108 | |
| 109 | rv = dhcp4_proxy_set_server (&server, |
| 110 | &src, |
| 111 | (u32) ntohl (mp->rx_vrf_id), |
| 112 | (u32) ntohl (mp->server_vrf_id), |
| 113 | (int) (mp->is_add == 0)); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY); |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 120 | static void |
| 121 | vl_api_dhcp_proxy_dump_t_handler (vl_api_dhcp_proxy_dump_t * mp) |
| 122 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 123 | vl_api_registration_t *reg; |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 124 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 125 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 126 | if (!reg) |
| 127 | return;; |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 128 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 129 | dhcp_proxy_dump ((mp->is_ip6 == 1 ? |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 130 | FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4), reg, mp->context); |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 134 | dhcp_send_details (fib_protocol_t proto, |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 135 | void *opaque, u32 context, dhcp_proxy_t * proxy) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 136 | { |
| 137 | vl_api_dhcp_proxy_details_t *mp; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 138 | vl_api_registration_t *reg = opaque; |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 139 | vl_api_dhcp_server_t *v_server; |
| 140 | dhcp_server_t *server; |
| 141 | fib_table_t *s_fib; |
| 142 | dhcp_vss_t *vss; |
| 143 | u32 count; |
| 144 | size_t n; |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 145 | |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 146 | count = vec_len (proxy->dhcp_servers); |
| 147 | n = sizeof (*mp) + (count * sizeof (vl_api_dhcp_server_t)); |
| 148 | mp = vl_msg_api_alloc (n); |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 149 | if (!mp) |
| 150 | return; |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 151 | memset (mp, 0, n); |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 152 | mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_DETAILS); |
| 153 | mp->context = context; |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 154 | mp->count = count; |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 155 | |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 156 | mp->is_ipv6 = (proto == FIB_PROTOCOL_IP6); |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 157 | mp->rx_vrf_id = |
| 158 | htonl (dhcp_proxy_rx_table_get_table_id (proto, proxy->rx_fib_index)); |
| 159 | |
| 160 | vss = dhcp_get_vss_info (&dhcp_proxy_main, proxy->rx_fib_index, proto); |
| 161 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 162 | if (vss) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 163 | { |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 164 | mp->vss_type = vss->vss_type; |
| 165 | if (vss->vss_type == VSS_TYPE_ASCII) |
| 166 | { |
| 167 | u32 id_len = vec_len (vss->vpn_ascii_id); |
| 168 | clib_memcpy (mp->vss_vpn_ascii_id, vss->vpn_ascii_id, id_len); |
| 169 | } |
| 170 | else if (vss->vss_type == VSS_TYPE_VPN_ID) |
| 171 | { |
| 172 | u32 oui = ((u32) vss->vpn_id[0] << 16) + ((u32) vss->vpn_id[1] << 8) |
| 173 | + ((u32) vss->vpn_id[2]); |
| 174 | u32 fib_id = ((u32) vss->vpn_id[3] << 24) + |
| 175 | ((u32) vss->vpn_id[4] << 16) + ((u32) vss->vpn_id[5] << 8) + |
| 176 | ((u32) vss->vpn_id[6]); |
| 177 | mp->vss_oui = htonl (oui); |
| 178 | mp->vss_fib_id = htonl (fib_id); |
| 179 | } |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 180 | } |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 181 | else |
| 182 | mp->vss_type = VSS_TYPE_INVALID; |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 183 | |
| 184 | vec_foreach_index (count, proxy->dhcp_servers) |
| 185 | { |
| 186 | server = &proxy->dhcp_servers[count]; |
| 187 | v_server = &mp->servers[count]; |
| 188 | |
| 189 | s_fib = fib_table_get (server->server_fib_index, proto); |
| 190 | |
| 191 | v_server->server_vrf_id = htonl (s_fib->ft_table_id); |
| 192 | |
| 193 | if (mp->is_ipv6) |
| 194 | { |
| 195 | memcpy (v_server->dhcp_server, &server->dhcp_server.ip6, 16); |
| 196 | } |
| 197 | else |
| 198 | { |
| 199 | /* put the address in the first bytes */ |
| 200 | memcpy (v_server->dhcp_server, &server->dhcp_server.ip4, 4); |
| 201 | } |
| 202 | } |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 203 | |
| 204 | if (mp->is_ipv6) |
| 205 | { |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 206 | memcpy (mp->dhcp_src_address, &proxy->dhcp_src_address.ip6, 16); |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 207 | } |
| 208 | else |
| 209 | { |
| 210 | /* put the address in the first bytes */ |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 211 | memcpy (mp->dhcp_src_address, &proxy->dhcp_src_address.ip4, 4); |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 212 | } |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 213 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 216 | static void |
| 217 | dhcp_client_lease_encode (vl_api_dhcp_lease_t * lease, |
| 218 | const dhcp_client_t * client) |
| 219 | { |
| 220 | size_t len; |
| 221 | |
| 222 | lease->is_ipv6 = 0; // only support IPv6 clients |
| 223 | lease->sw_if_index = ntohl (client->sw_if_index); |
| 224 | lease->state = client->state; |
| 225 | len = clib_min (sizeof (lease->hostname) - 1, vec_len (client->hostname)); |
| 226 | clib_memcpy (&lease->hostname, client->hostname, len); |
| 227 | lease->hostname[len] = 0; |
| 228 | |
| 229 | lease->mask_width = client->subnet_mask_width; |
| 230 | clib_memcpy (&lease->host_address[0], (u8 *) & client->leased_address, 4); |
| 231 | clib_memcpy (&lease->router_address[0], (u8 *) & client->router_address, 4); |
| 232 | |
| 233 | if (NULL != client->l2_rewrite) |
| 234 | clib_memcpy (&lease->host_mac[0], client->l2_rewrite + 6, 6); |
| 235 | } |
| 236 | |
| 237 | static void |
| 238 | dhcp_client_data_encode (vl_api_dhcp_client_t * vclient, |
| 239 | const dhcp_client_t * client) |
| 240 | { |
| 241 | size_t len; |
| 242 | |
| 243 | vclient->sw_if_index = ntohl (client->sw_if_index); |
| 244 | len = clib_min (sizeof (vclient->hostname) - 1, vec_len (client->hostname)); |
| 245 | clib_memcpy (&vclient->hostname, client->hostname, len); |
| 246 | vclient->hostname[len] = 0; |
| 247 | |
| 248 | len = clib_min (sizeof (vclient->id) - 1, |
| 249 | vec_len (client->client_identifier)); |
| 250 | clib_memcpy (&vclient->id, client->client_identifier, len); |
| 251 | vclient->id[len] = 0; |
| 252 | |
| 253 | if (NULL != client->event_callback) |
| 254 | vclient->want_dhcp_event = 1; |
| 255 | else |
| 256 | vclient->want_dhcp_event = 0; |
| 257 | vclient->set_broadcast_flag = client->set_broadcast_flag; |
| 258 | vclient->pid = client->pid; |
| 259 | } |
| 260 | |
| 261 | static void |
| 262 | dhcp_compl_event_callback (u32 client_index, const dhcp_client_t * client) |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 263 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 264 | vl_api_registration_t *reg; |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 265 | vl_api_dhcp_compl_event_t *mp; |
| 266 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 267 | reg = vl_api_client_index_to_registration (client_index); |
| 268 | if (!reg) |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 269 | return; |
| 270 | |
| 271 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 272 | mp->client_index = client_index; |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 273 | mp->pid = client->pid; |
| 274 | dhcp_client_lease_encode (&mp->lease, client); |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 275 | |
| 276 | mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT); |
| 277 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 278 | vl_api_send_msg (reg, (u8 *) mp); |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 281 | static void vl_api_dhcp_client_config_t_handler |
| 282 | (vl_api_dhcp_client_config_t * mp) |
| 283 | { |
| 284 | vlib_main_t *vm = vlib_get_main (); |
| 285 | vl_api_dhcp_client_config_reply_t *rmp; |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 286 | u32 sw_if_index; |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 287 | int rv = 0; |
| 288 | |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 289 | sw_if_index = ntohl (mp->client.sw_if_index); |
| 290 | if (!vnet_sw_if_index_is_api_valid (sw_if_index)) |
| 291 | { |
| 292 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 293 | goto bad_sw_if_index; |
| 294 | } |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 295 | |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 296 | rv = dhcp_client_config (mp->is_add, |
| 297 | mp->client_index, |
| 298 | vm, |
| 299 | sw_if_index, |
| 300 | mp->client.hostname, |
| 301 | mp->client.id, |
| 302 | (mp->client.want_dhcp_event ? |
| 303 | dhcp_compl_event_callback : |
| 304 | NULL), |
| 305 | mp->client.set_broadcast_flag, mp->client.pid); |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 306 | |
| 307 | BAD_SW_IF_INDEX_LABEL; |
| 308 | |
| 309 | REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY); |
| 310 | } |
| 311 | |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 312 | typedef struct dhcp_client_send_walk_ctx_t_ |
| 313 | { |
| 314 | vl_api_registration_t *reg; |
| 315 | u32 context; |
| 316 | } dhcp_client_send_walk_ctx_t; |
| 317 | |
| 318 | static int |
| 319 | send_dhcp_client_entry (const dhcp_client_t * client, void *arg) |
| 320 | { |
| 321 | dhcp_client_send_walk_ctx_t *ctx; |
| 322 | vl_api_dhcp_client_details_t *mp; |
| 323 | |
| 324 | ctx = arg; |
| 325 | |
| 326 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 327 | memset (mp, 0, sizeof (*mp)); |
| 328 | |
| 329 | mp->_vl_msg_id = ntohs (VL_API_DHCP_CLIENT_DETAILS); |
| 330 | mp->context = ctx->context; |
| 331 | |
| 332 | dhcp_client_data_encode (&mp->client, client); |
| 333 | dhcp_client_lease_encode (&mp->lease, client); |
| 334 | |
| 335 | vl_api_send_msg (ctx->reg, (u8 *) mp); |
| 336 | |
| 337 | return (1); |
| 338 | } |
| 339 | |
| 340 | static void |
| 341 | vl_api_dhcp_client_dump_t_handler (vl_api_dhcp_client_dump_t * mp) |
| 342 | { |
| 343 | vl_api_registration_t *reg; |
| 344 | |
| 345 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 346 | if (!reg) |
| 347 | return; |
| 348 | |
| 349 | dhcp_client_send_walk_ctx_t ctx = { |
| 350 | .reg = reg, |
| 351 | .context = mp->context, |
| 352 | }; |
| 353 | dhcp_client_walk (send_dhcp_client_entry, &ctx); |
| 354 | } |
| 355 | |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 356 | /* |
| 357 | * dhcp_api_hookup |
| 358 | * Add vpe's API message handlers to the table. |
| 359 | * vlib has alread mapped shared memory and |
| 360 | * added the client registration handlers. |
| 361 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 362 | */ |
| 363 | #define vl_msg_name_crc_list |
| 364 | #include <vnet/vnet_all_api_h.h> |
| 365 | #undef vl_msg_name_crc_list |
| 366 | |
| 367 | static void |
| 368 | setup_message_id_table (api_main_t * am) |
| 369 | { |
| 370 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 371 | foreach_vl_msg_name_crc_dhcp; |
| 372 | #undef _ |
| 373 | } |
| 374 | |
| 375 | static clib_error_t * |
| 376 | dhcp_api_hookup (vlib_main_t * vm) |
| 377 | { |
| 378 | api_main_t *am = &api_main; |
| 379 | |
| 380 | #define _(N,n) \ |
| 381 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 382 | vl_api_##n##_t_handler, \ |
| 383 | vl_noop_handler, \ |
| 384 | vl_api_##n##_t_endian, \ |
| 385 | vl_api_##n##_t_print, \ |
| 386 | sizeof(vl_api_##n##_t), 1); |
| 387 | foreach_vpe_api_msg; |
| 388 | #undef _ |
| 389 | |
| 390 | /* |
| 391 | * Set up the (msg_name, crc, message-id) table |
| 392 | */ |
| 393 | setup_message_id_table (am); |
| 394 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 395 | dhcp6_pd_set_publisher_node (dhcp6_pd_reply_process_node.index, |
| 396 | DHCP6_PD_DP_REPLY_REPORT); |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 397 | dhcp6_set_publisher_node (dhcp6_reply_process_node.index, |
| 398 | DHCP6_DP_REPLY_REPORT); |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 399 | |
Pavel Kotucek | c8d8770 | 2017-01-25 07:25:32 +0100 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | VLIB_API_INIT_FUNCTION (dhcp_api_hookup); |
| 404 | |
| 405 | /* |
| 406 | * fd.io coding-style-patch-verification: ON |
| 407 | * |
| 408 | * Local Variables: |
| 409 | * eval: (c-set-style "gnu") |
| 410 | * End: |
| 411 | */ |