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