Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * ip_api.c - vnet ip 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> |
| 25 | #include <vnet/ethernet/ethernet.h> |
| 26 | #include <vnet/ip/ip.h> |
| 27 | #include <vnet/ip/ip6_neighbor.h> |
| 28 | #include <vnet/fib/fib_table.h> |
| 29 | #include <vnet/fib/fib_api.h> |
| 30 | #include <vnet/dpo/drop_dpo.h> |
| 31 | #include <vnet/dpo/receive_dpo.h> |
| 32 | #include <vnet/dpo/lookup_dpo.h> |
| 33 | #include <vnet/dpo/classify_dpo.h> |
| 34 | #include <vnet/dpo/ip_null_dpo.h> |
| 35 | #include <vnet/ethernet/arp_packet.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 36 | #include <vnet/mfib/ip6_mfib.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 37 | #include <vnet/mfib/ip4_mfib.h> |
| 38 | #include <vnet/mfib/mfib_signal.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 39 | #include <vnet/mfib/mfib_entry.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 40 | |
| 41 | #include <vnet/vnet_msg_enum.h> |
| 42 | |
| 43 | #define vl_typedefs /* define message structures */ |
| 44 | #include <vnet/vnet_all_api_h.h> |
| 45 | #undef vl_typedefs |
| 46 | |
| 47 | #define vl_endianfun /* define message structures */ |
| 48 | #include <vnet/vnet_all_api_h.h> |
| 49 | #undef vl_endianfun |
| 50 | |
| 51 | /* instantiate all the print functions we know about */ |
| 52 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 53 | #define vl_printfun |
| 54 | #include <vnet/vnet_all_api_h.h> |
| 55 | #undef vl_printfun |
| 56 | |
| 57 | #include <vlibapi/api_helper_macros.h> |
| 58 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 59 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 60 | #define foreach_ip_api_msg \ |
| 61 | _(IP_FIB_DUMP, ip_fib_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 62 | _(IP6_FIB_DUMP, ip6_fib_dump) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 63 | _(IP_MFIB_DUMP, ip_mfib_dump) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 64 | _(IP6_MFIB_DUMP, ip6_mfib_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 65 | _(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 66 | _(IP_MROUTE_ADD_DEL, ip_mroute_add_del) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 67 | _(MFIB_SIGNAL_DUMP, mfib_signal_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 68 | _(IP_ADDRESS_DUMP, ip_address_dump) \ |
| 69 | _(IP_DUMP, ip_dump) \ |
| 70 | _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \ |
| 71 | _(IP_ADD_DEL_ROUTE, ip_add_del_route) \ |
| 72 | _(SET_IP_FLOW_HASH,set_ip_flow_hash) \ |
| 73 | _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \ |
| 74 | _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \ |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 75 | _(IP6ND_PROXY_ADD_DEL, ip6nd_proxy_add_del) \ |
| 76 | _(IP6ND_PROXY_DUMP, ip6nd_proxy_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 77 | _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \ |
| 78 | _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \ |
| 79 | sw_interface_ip6_set_link_local_address) |
| 80 | |
| 81 | extern void stats_dslock_with_hint (int hint, int tag); |
| 82 | extern void stats_dsunlock (void); |
| 83 | |
| 84 | static void |
| 85 | send_ip_neighbor_details (u8 is_ipv6, |
| 86 | u8 is_static, |
| 87 | u8 * mac_address, |
| 88 | u8 * ip_address, |
| 89 | unix_shared_memory_queue_t * q, u32 context) |
| 90 | { |
| 91 | vl_api_ip_neighbor_details_t *mp; |
| 92 | |
| 93 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 94 | memset (mp, 0, sizeof (*mp)); |
| 95 | mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS); |
| 96 | mp->context = context; |
| 97 | mp->is_ipv6 = is_ipv6; |
| 98 | mp->is_static = is_static; |
| 99 | memcpy (mp->mac_address, mac_address, 6); |
| 100 | memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4); |
| 101 | |
| 102 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 103 | } |
| 104 | |
| 105 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 106 | vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp) |
| 107 | { |
| 108 | unix_shared_memory_queue_t *q; |
| 109 | |
| 110 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 111 | if (q == 0) |
| 112 | return; |
| 113 | |
| 114 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 115 | |
| 116 | if (mp->is_ipv6) |
| 117 | { |
| 118 | ip6_neighbor_t *n, *ns; |
| 119 | |
| 120 | ns = ip6_neighbors_entries (sw_if_index); |
| 121 | /* *INDENT-OFF* */ |
| 122 | vec_foreach (n, ns) |
| 123 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 124 | send_ip_neighbor_details |
| 125 | (mp->is_ipv6, ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0), |
| 126 | (u8 *) n->link_layer_address, |
| 127 | (u8 *) & (n->key.ip6_address.as_u8), |
| 128 | q, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 129 | } |
| 130 | /* *INDENT-ON* */ |
| 131 | vec_free (ns); |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | ethernet_arp_ip4_entry_t *n, *ns; |
| 136 | |
| 137 | ns = ip4_neighbor_entries (sw_if_index); |
| 138 | /* *INDENT-OFF* */ |
| 139 | vec_foreach (n, ns) |
| 140 | { |
| 141 | send_ip_neighbor_details (mp->is_ipv6, |
| 142 | ((n->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) ? 1 : 0), |
| 143 | (u8*) n->ethernet_address, |
| 144 | (u8*) & (n->ip4_address.as_u8), |
| 145 | q, mp->context); |
| 146 | } |
| 147 | /* *INDENT-ON* */ |
| 148 | vec_free (ns); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | |
| 153 | void |
| 154 | copy_fib_next_hop (fib_route_path_encode_t * api_rpath, void *fp_arg) |
| 155 | { |
| 156 | int is_ip4; |
| 157 | vl_api_fib_path_t *fp = (vl_api_fib_path_t *) fp_arg; |
| 158 | |
| 159 | if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4) |
| 160 | fp->afi = IP46_TYPE_IP4; |
| 161 | else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6) |
| 162 | fp->afi = IP46_TYPE_IP6; |
| 163 | else |
| 164 | { |
| 165 | is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr); |
| 166 | if (is_ip4) |
| 167 | fp->afi = IP46_TYPE_IP4; |
| 168 | else |
| 169 | fp->afi = IP46_TYPE_IP6; |
| 170 | } |
| 171 | if (fp->afi == IP46_TYPE_IP4) |
| 172 | memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip4, |
| 173 | sizeof (api_rpath->rpath.frp_addr.ip4)); |
| 174 | else |
| 175 | memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip6, |
| 176 | sizeof (api_rpath->rpath.frp_addr.ip6)); |
| 177 | } |
| 178 | |
| 179 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 180 | send_ip_fib_details (vpe_api_main_t * am, |
| 181 | unix_shared_memory_queue_t * q, |
| 182 | u32 table_id, fib_prefix_t * pfx, |
| 183 | fib_route_path_encode_t * api_rpaths, u32 context) |
| 184 | { |
| 185 | vl_api_ip_fib_details_t *mp; |
| 186 | fib_route_path_encode_t *api_rpath; |
| 187 | vl_api_fib_path_t *fp; |
| 188 | int path_count; |
| 189 | |
| 190 | path_count = vec_len (api_rpaths); |
| 191 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 192 | if (!mp) |
| 193 | return; |
| 194 | memset (mp, 0, sizeof (*mp)); |
| 195 | mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS); |
| 196 | mp->context = context; |
| 197 | |
| 198 | mp->table_id = htonl (table_id); |
| 199 | mp->address_length = pfx->fp_len; |
| 200 | memcpy (mp->address, &pfx->fp_addr.ip4, sizeof (pfx->fp_addr.ip4)); |
| 201 | |
| 202 | mp->count = htonl (path_count); |
| 203 | fp = mp->path; |
| 204 | vec_foreach (api_rpath, api_rpaths) |
| 205 | { |
| 206 | memset (fp, 0, sizeof (*fp)); |
| 207 | switch (api_rpath->dpo.dpoi_type) |
| 208 | { |
| 209 | case DPO_RECEIVE: |
| 210 | fp->is_local = true; |
| 211 | break; |
| 212 | case DPO_DROP: |
| 213 | fp->is_drop = true; |
| 214 | break; |
| 215 | case DPO_IP_NULL: |
| 216 | switch (api_rpath->dpo.dpoi_index) |
| 217 | { |
| 218 | case IP_NULL_ACTION_NONE: |
| 219 | fp->is_drop = true; |
| 220 | break; |
| 221 | case IP_NULL_ACTION_SEND_ICMP_UNREACH: |
| 222 | fp->is_unreach = true; |
| 223 | break; |
| 224 | case IP_NULL_ACTION_SEND_ICMP_PROHIBIT: |
| 225 | fp->is_prohibit = true; |
| 226 | break; |
| 227 | default: |
| 228 | break; |
| 229 | } |
| 230 | break; |
| 231 | default: |
| 232 | break; |
| 233 | } |
| 234 | fp->weight = htonl (api_rpath->rpath.frp_weight); |
| 235 | fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); |
| 236 | copy_fib_next_hop (api_rpath, fp); |
| 237 | fp++; |
| 238 | } |
| 239 | |
| 240 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 241 | } |
| 242 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 243 | typedef struct vl_api_ip_fib_dump_walk_ctx_t_ |
| 244 | { |
| 245 | fib_node_index_t *feis; |
| 246 | } vl_api_ip_fib_dump_walk_ctx_t; |
| 247 | |
| 248 | static int |
| 249 | vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg) |
| 250 | { |
| 251 | vl_api_ip_fib_dump_walk_ctx_t *ctx = arg; |
| 252 | |
| 253 | vec_add1 (ctx->feis, fei); |
| 254 | |
| 255 | return (1); |
| 256 | } |
| 257 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 258 | static void |
| 259 | vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp) |
| 260 | { |
| 261 | vpe_api_main_t *am = &vpe_api_main; |
| 262 | unix_shared_memory_queue_t *q; |
| 263 | ip4_main_t *im = &ip4_main; |
| 264 | fib_table_t *fib_table; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 265 | fib_node_index_t *lfeip; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 266 | fib_prefix_t pfx; |
| 267 | u32 fib_index; |
| 268 | fib_route_path_encode_t *api_rpaths; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 269 | vl_api_ip_fib_dump_walk_ctx_t ctx = { |
| 270 | .feis = NULL, |
| 271 | }; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 272 | |
| 273 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 274 | if (q == 0) |
| 275 | return; |
| 276 | |
| 277 | /* *INDENT-OFF* */ |
| 278 | pool_foreach (fib_table, im->fibs, |
| 279 | ({ |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 280 | fib_table_walk(fib_table->ft_index, |
| 281 | FIB_PROTOCOL_IP4, |
| 282 | vl_api_ip_fib_dump_walk, |
| 283 | &ctx); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 284 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 285 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 286 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 287 | vec_sort_with_function (ctx.feis, fib_entry_cmp_for_sort); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 288 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 289 | vec_foreach (lfeip, ctx.feis) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 290 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 291 | fib_entry_get_prefix (*lfeip, &pfx); |
| 292 | fib_index = fib_entry_get_fib_index (*lfeip); |
| 293 | fib_table = fib_table_get (fib_index, pfx.fp_proto); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 294 | api_rpaths = NULL; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 295 | fib_entry_encode (*lfeip, &api_rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 296 | send_ip_fib_details (am, q, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 297 | fib_table->ft_table_id, &pfx, api_rpaths, |
| 298 | mp->context); |
| 299 | vec_free (api_rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 300 | } |
| 301 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 302 | vec_free (ctx.feis); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 306 | send_ip6_fib_details (vpe_api_main_t * am, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 307 | unix_shared_memory_queue_t * q, |
| 308 | u32 table_id, fib_prefix_t * pfx, |
| 309 | fib_route_path_encode_t * api_rpaths, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 310 | { |
| 311 | vl_api_ip6_fib_details_t *mp; |
| 312 | fib_route_path_encode_t *api_rpath; |
| 313 | vl_api_fib_path_t *fp; |
| 314 | int path_count; |
| 315 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 316 | path_count = vec_len (api_rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 317 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 318 | if (!mp) |
| 319 | return; |
| 320 | memset (mp, 0, sizeof (*mp)); |
| 321 | mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS); |
| 322 | mp->context = context; |
| 323 | |
| 324 | mp->table_id = htonl (table_id); |
| 325 | mp->address_length = pfx->fp_len; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 326 | memcpy (mp->address, &pfx->fp_addr.ip6, sizeof (pfx->fp_addr.ip6)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 327 | |
| 328 | mp->count = htonl (path_count); |
| 329 | fp = mp->path; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 330 | vec_foreach (api_rpath, api_rpaths) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 331 | { |
| 332 | memset (fp, 0, sizeof (*fp)); |
| 333 | switch (api_rpath->dpo.dpoi_type) |
| 334 | { |
| 335 | case DPO_RECEIVE: |
| 336 | fp->is_local = true; |
| 337 | break; |
| 338 | case DPO_DROP: |
| 339 | fp->is_drop = true; |
| 340 | break; |
| 341 | case DPO_IP_NULL: |
| 342 | switch (api_rpath->dpo.dpoi_index) |
| 343 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 344 | case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_NONE: |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 345 | fp->is_drop = true; |
| 346 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 347 | case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_SEND_ICMP_UNREACH: |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 348 | fp->is_unreach = true; |
| 349 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 350 | case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_SEND_ICMP_PROHIBIT: |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 351 | fp->is_prohibit = true; |
| 352 | break; |
| 353 | default: |
| 354 | break; |
| 355 | } |
| 356 | break; |
| 357 | default: |
| 358 | break; |
| 359 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 360 | fp->weight = htonl (api_rpath->rpath.frp_weight); |
| 361 | fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 362 | copy_fib_next_hop (api_rpath, fp); |
| 363 | fp++; |
| 364 | } |
| 365 | |
| 366 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 367 | } |
| 368 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 369 | typedef struct apt_ip6_fib_show_ctx_t_ |
| 370 | { |
| 371 | u32 fib_index; |
| 372 | fib_node_index_t *entries; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 373 | } api_ip6_fib_show_ctx_t; |
| 374 | |
| 375 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 376 | api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp, void *arg) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 377 | { |
| 378 | api_ip6_fib_show_ctx_t *ctx = arg; |
| 379 | |
| 380 | if ((kvp->key[2] >> 32) == ctx->fib_index) |
| 381 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 382 | vec_add1 (ctx->entries, kvp->value); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| 386 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 387 | api_ip6_fib_table_get_all (unix_shared_memory_queue_t * q, |
| 388 | vl_api_ip6_fib_dump_t * mp, |
| 389 | fib_table_t * fib_table) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 390 | { |
| 391 | vpe_api_main_t *am = &vpe_api_main; |
| 392 | ip6_main_t *im6 = &ip6_main; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 393 | fib_node_index_t *fib_entry_index; |
| 394 | api_ip6_fib_show_ctx_t ctx = { |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 395 | .fib_index = fib_table->ft_index, |
| 396 | .entries = NULL, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 397 | }; |
| 398 | fib_route_path_encode_t *api_rpaths; |
| 399 | fib_prefix_t pfx; |
| 400 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 401 | BV (clib_bihash_foreach_key_value_pair) |
| 402 | ((BVT (clib_bihash) *) & im6->ip6_table[IP6_FIB_TABLE_NON_FWDING]. |
| 403 | ip6_hash, api_ip6_fib_table_put_entries, &ctx); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 404 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 405 | vec_sort_with_function (ctx.entries, fib_entry_cmp_for_sort); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 406 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 407 | vec_foreach (fib_entry_index, ctx.entries) |
| 408 | { |
| 409 | fib_entry_get_prefix (*fib_entry_index, &pfx); |
| 410 | api_rpaths = NULL; |
| 411 | fib_entry_encode (*fib_entry_index, &api_rpaths); |
| 412 | send_ip6_fib_details (am, q, |
| 413 | fib_table->ft_table_id, |
| 414 | &pfx, api_rpaths, mp->context); |
| 415 | vec_free (api_rpaths); |
| 416 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 417 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 418 | vec_free (ctx.entries); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | static void |
| 422 | vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp) |
| 423 | { |
| 424 | unix_shared_memory_queue_t *q; |
| 425 | ip6_main_t *im6 = &ip6_main; |
| 426 | fib_table_t *fib_table; |
| 427 | |
| 428 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 429 | if (q == 0) |
| 430 | return; |
| 431 | |
| 432 | /* *INDENT-OFF* */ |
| 433 | pool_foreach (fib_table, im6->fibs, |
| 434 | ({ |
| 435 | api_ip6_fib_table_get_all(q, mp, fib_table); |
| 436 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 437 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static void |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 441 | send_ip_mfib_details (unix_shared_memory_queue_t * q, |
| 442 | u32 context, u32 table_id, fib_node_index_t mfei) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 443 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 444 | fib_route_path_encode_t *api_rpath, *api_rpaths = NULL; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 445 | vl_api_ip_mfib_details_t *mp; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 446 | mfib_entry_t *mfib_entry; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 447 | vl_api_fib_path_t *fp; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 448 | mfib_prefix_t pfx; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 449 | int path_count; |
| 450 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 451 | mfib_entry = mfib_entry_get (mfei); |
| 452 | mfib_entry_get_prefix (mfei, &pfx); |
| 453 | mfib_entry_encode (mfei, &api_rpaths); |
| 454 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 455 | path_count = vec_len (api_rpaths); |
| 456 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 457 | if (!mp) |
| 458 | return; |
| 459 | memset (mp, 0, sizeof (*mp)); |
| 460 | mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS); |
| 461 | mp->context = context; |
| 462 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 463 | mp->rpf_id = mfib_entry->mfe_rpf_id; |
| 464 | mp->entry_flags = mfib_entry->mfe_flags; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 465 | mp->table_id = htonl (table_id); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 466 | mp->address_length = pfx.fp_len; |
| 467 | memcpy (mp->grp_address, &pfx.fp_grp_addr.ip4, |
| 468 | sizeof (pfx.fp_grp_addr.ip4)); |
| 469 | memcpy (mp->src_address, &pfx.fp_src_addr.ip4, |
| 470 | sizeof (pfx.fp_src_addr.ip4)); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 471 | |
| 472 | mp->count = htonl (path_count); |
| 473 | fp = mp->path; |
| 474 | vec_foreach (api_rpath, api_rpaths) |
| 475 | { |
| 476 | memset (fp, 0, sizeof (*fp)); |
| 477 | |
| 478 | fp->weight = 0; |
| 479 | fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); |
| 480 | copy_fib_next_hop (api_rpath, fp); |
| 481 | fp++; |
| 482 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 483 | vec_free (api_rpaths); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 484 | |
| 485 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 486 | } |
| 487 | |
| 488 | typedef struct vl_api_ip_mfib_dump_ctc_t_ |
| 489 | { |
| 490 | fib_node_index_t *entries; |
| 491 | } vl_api_ip_mfib_dump_ctc_t; |
| 492 | |
| 493 | static int |
| 494 | vl_api_ip_mfib_table_dump_walk (fib_node_index_t fei, void *arg) |
| 495 | { |
| 496 | vl_api_ip_mfib_dump_ctc_t *ctx = arg; |
| 497 | |
| 498 | vec_add1 (ctx->entries, fei); |
| 499 | |
| 500 | return (0); |
| 501 | } |
| 502 | |
| 503 | static void |
| 504 | vl_api_ip_mfib_dump_t_handler (vl_api_ip_mfib_dump_t * mp) |
| 505 | { |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 506 | unix_shared_memory_queue_t *q; |
| 507 | ip4_main_t *im = &ip4_main; |
| 508 | mfib_table_t *mfib_table; |
| 509 | fib_node_index_t *mfeip; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 510 | vl_api_ip_mfib_dump_ctc_t ctx = { |
| 511 | .entries = NULL, |
| 512 | }; |
| 513 | |
| 514 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 515 | if (q == 0) |
| 516 | return; |
| 517 | |
| 518 | |
| 519 | /* *INDENT-OFF* */ |
| 520 | pool_foreach (mfib_table, im->mfibs, |
| 521 | ({ |
| 522 | ip4_mfib_table_walk(&mfib_table->v4, |
| 523 | vl_api_ip_mfib_table_dump_walk, |
| 524 | &ctx); |
| 525 | |
| 526 | vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort); |
| 527 | |
| 528 | vec_foreach (mfeip, ctx.entries) |
| 529 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 530 | send_ip_mfib_details (q, mp->context, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 531 | mfib_table->mft_table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 532 | *mfeip); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 533 | } |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 534 | vec_reset_length (ctx.entries); |
| 535 | |
| 536 | })); |
| 537 | /* *INDENT-ON* */ |
| 538 | |
| 539 | vec_free (ctx.entries); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static void |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 543 | send_ip6_mfib_details (vpe_api_main_t * am, |
| 544 | unix_shared_memory_queue_t * q, |
| 545 | u32 table_id, |
| 546 | mfib_prefix_t * pfx, |
| 547 | fib_route_path_encode_t * api_rpaths, u32 context) |
| 548 | { |
| 549 | vl_api_ip6_mfib_details_t *mp; |
| 550 | fib_route_path_encode_t *api_rpath; |
| 551 | vl_api_fib_path_t *fp; |
| 552 | int path_count; |
| 553 | |
| 554 | path_count = vec_len (api_rpaths); |
| 555 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 556 | if (!mp) |
| 557 | return; |
| 558 | memset (mp, 0, sizeof (*mp)); |
| 559 | mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS); |
| 560 | mp->context = context; |
| 561 | |
| 562 | mp->table_id = htonl (table_id); |
| 563 | mp->address_length = pfx->fp_len; |
| 564 | memcpy (mp->grp_address, &pfx->fp_grp_addr.ip6, |
| 565 | sizeof (pfx->fp_grp_addr.ip6)); |
| 566 | memcpy (mp->src_address, &pfx->fp_src_addr.ip6, |
| 567 | sizeof (pfx->fp_src_addr.ip6)); |
| 568 | |
| 569 | mp->count = htonl (path_count); |
| 570 | fp = mp->path; |
| 571 | vec_foreach (api_rpath, api_rpaths) |
| 572 | { |
| 573 | memset (fp, 0, sizeof (*fp)); |
| 574 | |
| 575 | fp->weight = 0; |
| 576 | fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); |
| 577 | copy_fib_next_hop (api_rpath, fp); |
| 578 | fp++; |
| 579 | } |
| 580 | |
| 581 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 582 | } |
| 583 | |
| 584 | typedef struct vl_api_ip6_mfib_dump_ctc_t_ |
| 585 | { |
| 586 | fib_node_index_t *entries; |
| 587 | } vl_api_ip6_mfib_dump_ctc_t; |
| 588 | |
| 589 | static int |
| 590 | vl_api_ip6_mfib_table_dump_walk (fib_node_index_t fei, void *arg) |
| 591 | { |
| 592 | vl_api_ip6_mfib_dump_ctc_t *ctx = arg; |
| 593 | |
| 594 | vec_add1 (ctx->entries, fei); |
| 595 | |
| 596 | return (0); |
| 597 | } |
| 598 | |
| 599 | static void |
| 600 | vl_api_ip6_mfib_dump_t_handler (vl_api_ip6_mfib_dump_t * mp) |
| 601 | { |
| 602 | vpe_api_main_t *am = &vpe_api_main; |
| 603 | unix_shared_memory_queue_t *q; |
| 604 | ip6_main_t *im = &ip6_main; |
| 605 | mfib_table_t *mfib_table; |
| 606 | fib_node_index_t *mfeip; |
| 607 | mfib_prefix_t pfx; |
| 608 | fib_route_path_encode_t *api_rpaths = NULL; |
| 609 | vl_api_ip6_mfib_dump_ctc_t ctx = { |
| 610 | .entries = NULL, |
| 611 | }; |
| 612 | |
| 613 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 614 | if (q == 0) |
| 615 | return; |
| 616 | |
| 617 | |
| 618 | /* *INDENT-OFF* */ |
| 619 | pool_foreach (mfib_table, im->mfibs, |
| 620 | ({ |
| 621 | ip6_mfib_table_walk(&mfib_table->v6, |
| 622 | vl_api_ip6_mfib_table_dump_walk, |
| 623 | &ctx); |
| 624 | |
| 625 | vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort); |
| 626 | |
| 627 | vec_foreach(mfeip, ctx.entries) |
| 628 | { |
| 629 | mfib_entry_get_prefix (*mfeip, &pfx); |
| 630 | mfib_entry_encode (*mfeip, &api_rpaths); |
| 631 | send_ip6_mfib_details (am, q, |
| 632 | mfib_table->mft_table_id, |
| 633 | &pfx, api_rpaths, |
| 634 | mp->context); |
| 635 | } |
| 636 | vec_reset_length (api_rpaths); |
| 637 | vec_reset_length (ctx.entries); |
| 638 | |
| 639 | })); |
| 640 | /* *INDENT-ON* */ |
| 641 | |
| 642 | vec_free (ctx.entries); |
| 643 | vec_free (api_rpaths); |
| 644 | } |
| 645 | |
| 646 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 647 | vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp, |
| 648 | vlib_main_t * vm) |
| 649 | { |
| 650 | vl_api_ip_neighbor_add_del_reply_t *rmp; |
| 651 | vnet_main_t *vnm = vnet_get_main (); |
| 652 | int rv = 0; |
| 653 | |
| 654 | VALIDATE_SW_IF_INDEX (mp); |
| 655 | |
| 656 | stats_dslock_with_hint (1 /* release hint */ , 7 /* tag */ ); |
| 657 | |
| 658 | /* |
| 659 | * there's no validation here of the ND/ARP entry being added. |
| 660 | * The expectation is that the FIB will ensure that nothing bad |
| 661 | * will come of adding bogus entries. |
| 662 | */ |
| 663 | if (mp->is_ipv6) |
| 664 | { |
| 665 | if (mp->is_add) |
| 666 | rv = vnet_set_ip6_ethernet_neighbor |
| 667 | (vm, ntohl (mp->sw_if_index), |
| 668 | (ip6_address_t *) (mp->dst_address), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 669 | mp->mac_address, sizeof (mp->mac_address), mp->is_static, |
| 670 | mp->is_no_adj_fib); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 671 | else |
| 672 | rv = vnet_unset_ip6_ethernet_neighbor |
| 673 | (vm, ntohl (mp->sw_if_index), |
| 674 | (ip6_address_t *) (mp->dst_address), |
| 675 | mp->mac_address, sizeof (mp->mac_address)); |
| 676 | } |
| 677 | else |
| 678 | { |
| 679 | ethernet_arp_ip4_over_ethernet_address_t a; |
| 680 | |
| 681 | clib_memcpy (&a.ethernet, mp->mac_address, 6); |
| 682 | clib_memcpy (&a.ip4, mp->dst_address, 4); |
| 683 | |
| 684 | if (mp->is_add) |
| 685 | rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 686 | &a, mp->is_static, |
| 687 | mp->is_no_adj_fib); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 688 | else |
| 689 | rv = |
| 690 | vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a); |
| 691 | } |
| 692 | |
| 693 | BAD_SW_IF_INDEX_LABEL; |
| 694 | |
| 695 | stats_dsunlock (); |
| 696 | REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY); |
| 697 | } |
| 698 | |
| 699 | int |
| 700 | add_del_route_t_handler (u8 is_multipath, |
| 701 | u8 is_add, |
| 702 | u8 is_drop, |
| 703 | u8 is_unreach, |
| 704 | u8 is_prohibit, |
| 705 | u8 is_local, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 706 | u8 is_multicast, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 707 | u8 is_classify, |
| 708 | u32 classify_table_index, |
| 709 | u8 is_resolve_host, |
| 710 | u8 is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 711 | u8 is_interface_rx, |
| 712 | u8 is_rpf_id, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 713 | u32 fib_index, |
| 714 | const fib_prefix_t * prefix, |
| 715 | u8 next_hop_proto_is_ip4, |
| 716 | const ip46_address_t * next_hop, |
| 717 | u32 next_hop_sw_if_index, |
| 718 | u8 next_hop_fib_index, |
| 719 | u32 next_hop_weight, |
| 720 | mpls_label_t next_hop_via_label, |
| 721 | mpls_label_t * next_hop_out_label_stack) |
| 722 | { |
| 723 | vnet_classify_main_t *cm = &vnet_classify_main; |
| 724 | fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE; |
| 725 | fib_route_path_t path = { |
| 726 | .frp_proto = (next_hop_proto_is_ip4 ? |
| 727 | FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6), |
| 728 | .frp_addr = (NULL == next_hop ? zero_addr : *next_hop), |
| 729 | .frp_sw_if_index = next_hop_sw_if_index, |
| 730 | .frp_fib_index = next_hop_fib_index, |
| 731 | .frp_weight = next_hop_weight, |
| 732 | .frp_label_stack = next_hop_out_label_stack, |
| 733 | }; |
| 734 | fib_route_path_t *paths = NULL; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 735 | fib_entry_flag_t entry_flags = FIB_ENTRY_FLAG_NONE; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 736 | |
| 737 | if (MPLS_LABEL_INVALID != next_hop_via_label) |
| 738 | { |
| 739 | path.frp_proto = FIB_PROTOCOL_MPLS; |
| 740 | path.frp_local_label = next_hop_via_label; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 741 | path.frp_eos = MPLS_NON_EOS; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 742 | } |
| 743 | if (is_resolve_host) |
| 744 | path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST; |
| 745 | if (is_resolve_attached) |
| 746 | path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 747 | if (is_interface_rx) |
| 748 | path_flags |= FIB_ROUTE_PATH_INTF_RX; |
| 749 | if (is_rpf_id) |
| 750 | path_flags |= FIB_ROUTE_PATH_RPF_ID; |
| 751 | if (is_multicast) |
| 752 | entry_flags |= FIB_ENTRY_FLAG_MULTICAST; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 753 | |
| 754 | path.frp_flags = path_flags; |
| 755 | |
| 756 | if (is_multipath) |
| 757 | { |
| 758 | stats_dslock_with_hint (1 /* release hint */ , 10 /* tag */ ); |
| 759 | |
| 760 | |
| 761 | vec_add1 (paths, path); |
| 762 | |
| 763 | if (is_add) |
| 764 | fib_table_entry_path_add2 (fib_index, |
| 765 | prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 766 | FIB_SOURCE_API, entry_flags, paths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 767 | else |
| 768 | fib_table_entry_path_remove2 (fib_index, |
| 769 | prefix, FIB_SOURCE_API, paths); |
| 770 | |
| 771 | vec_free (paths); |
| 772 | stats_dsunlock (); |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ ); |
| 777 | |
| 778 | if (is_drop || is_local || is_classify || is_unreach || is_prohibit) |
| 779 | { |
| 780 | /* |
| 781 | * special route types that link directly to the adj |
| 782 | */ |
| 783 | if (is_add) |
| 784 | { |
| 785 | dpo_id_t dpo = DPO_INVALID; |
| 786 | dpo_proto_t dproto; |
| 787 | |
| 788 | dproto = fib_proto_to_dpo (prefix->fp_proto); |
| 789 | |
| 790 | if (is_drop) |
| 791 | ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo); |
| 792 | else if (is_local) |
| 793 | receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo); |
| 794 | else if (is_unreach) |
| 795 | ip_null_dpo_add_and_lock (dproto, |
| 796 | IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo); |
| 797 | else if (is_prohibit) |
| 798 | ip_null_dpo_add_and_lock (dproto, |
| 799 | IP_NULL_ACTION_SEND_ICMP_PROHIBIT, |
| 800 | &dpo); |
| 801 | else if (is_classify) |
| 802 | { |
| 803 | if (pool_is_free_index (cm->tables, |
| 804 | ntohl (classify_table_index))) |
| 805 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 806 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 807 | return VNET_API_ERROR_NO_SUCH_TABLE; |
| 808 | } |
| 809 | |
| 810 | dpo_set (&dpo, DPO_CLASSIFY, dproto, |
| 811 | classify_dpo_create (dproto, |
| 812 | ntohl (classify_table_index))); |
| 813 | } |
| 814 | else |
| 815 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 816 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 817 | return VNET_API_ERROR_NO_SUCH_TABLE; |
| 818 | } |
| 819 | |
| 820 | fib_table_entry_special_dpo_update (fib_index, |
| 821 | prefix, |
| 822 | FIB_SOURCE_API, |
| 823 | FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); |
| 824 | dpo_reset (&dpo); |
| 825 | } |
| 826 | else |
| 827 | { |
| 828 | fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API); |
| 829 | } |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | if (is_add) |
| 834 | { |
| 835 | vec_add1 (paths, path); |
| 836 | fib_table_entry_update (fib_index, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 837 | prefix, FIB_SOURCE_API, entry_flags, paths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 838 | vec_free (paths); |
| 839 | } |
| 840 | else |
| 841 | { |
| 842 | fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API); |
| 843 | } |
| 844 | } |
| 845 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 846 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 847 | return (0); |
| 848 | } |
| 849 | |
| 850 | int |
| 851 | add_del_route_check (fib_protocol_t table_proto, |
| 852 | u32 table_id, |
| 853 | u32 next_hop_sw_if_index, |
| 854 | fib_protocol_t next_hop_table_proto, |
| 855 | u32 next_hop_table_id, |
| 856 | u8 create_missing_tables, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 857 | u8 is_rpf_id, u32 * fib_index, u32 * next_hop_fib_index) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 858 | { |
| 859 | vnet_main_t *vnm = vnet_get_main (); |
| 860 | |
| 861 | *fib_index = fib_table_find (table_proto, ntohl (table_id)); |
| 862 | if (~0 == *fib_index) |
| 863 | { |
| 864 | if (create_missing_tables) |
| 865 | { |
| 866 | *fib_index = fib_table_find_or_create_and_lock (table_proto, |
| 867 | ntohl (table_id)); |
| 868 | } |
| 869 | else |
| 870 | { |
| 871 | /* No such VRF, and we weren't asked to create one */ |
| 872 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 873 | } |
| 874 | } |
| 875 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 876 | if (!is_rpf_id && ~0 != ntohl (next_hop_sw_if_index)) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 877 | { |
| 878 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, |
| 879 | ntohl (next_hop_sw_if_index))) |
| 880 | { |
| 881 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 882 | } |
| 883 | } |
| 884 | else |
| 885 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 886 | if (is_rpf_id) |
| 887 | *next_hop_fib_index = mfib_table_find (next_hop_table_proto, |
| 888 | ntohl (next_hop_table_id)); |
| 889 | else |
| 890 | *next_hop_fib_index = fib_table_find (next_hop_table_proto, |
| 891 | ntohl (next_hop_table_id)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 892 | |
| 893 | if (~0 == *next_hop_fib_index) |
| 894 | { |
| 895 | if (create_missing_tables) |
| 896 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 897 | if (is_rpf_id) |
| 898 | *next_hop_fib_index = |
| 899 | mfib_table_find_or_create_and_lock (next_hop_table_proto, |
| 900 | ntohl |
| 901 | (next_hop_table_id)); |
| 902 | else |
| 903 | *next_hop_fib_index = |
| 904 | fib_table_find_or_create_and_lock (next_hop_table_proto, |
| 905 | ntohl |
| 906 | (next_hop_table_id)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 907 | } |
| 908 | else |
| 909 | { |
| 910 | /* No such VRF, and we weren't asked to create one */ |
| 911 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | return (0); |
| 917 | } |
| 918 | |
| 919 | static int |
| 920 | ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 921 | { |
| 922 | u32 fib_index, next_hop_fib_index; |
| 923 | mpls_label_t *label_stack = NULL; |
| 924 | int rv, ii, n_labels;; |
| 925 | |
| 926 | rv = add_del_route_check (FIB_PROTOCOL_IP4, |
| 927 | mp->table_id, |
| 928 | mp->next_hop_sw_if_index, |
| 929 | FIB_PROTOCOL_IP4, |
| 930 | mp->next_hop_table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 931 | mp->create_vrf_if_needed, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 932 | &fib_index, &next_hop_fib_index); |
| 933 | |
| 934 | if (0 != rv) |
| 935 | return (rv); |
| 936 | |
| 937 | fib_prefix_t pfx = { |
| 938 | .fp_len = mp->dst_address_length, |
| 939 | .fp_proto = FIB_PROTOCOL_IP4, |
| 940 | }; |
| 941 | clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4)); |
| 942 | |
| 943 | ip46_address_t nh; |
| 944 | memset (&nh, 0, sizeof (nh)); |
| 945 | memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4)); |
| 946 | |
| 947 | n_labels = mp->next_hop_n_out_labels; |
| 948 | if (n_labels == 0) |
| 949 | ; |
| 950 | else if (1 == n_labels) |
| 951 | vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0])); |
| 952 | else |
| 953 | { |
| 954 | vec_validate (label_stack, n_labels - 1); |
| 955 | for (ii = 0; ii < n_labels; ii++) |
| 956 | label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]); |
| 957 | } |
| 958 | |
| 959 | return (add_del_route_t_handler (mp->is_multipath, |
| 960 | mp->is_add, |
| 961 | mp->is_drop, |
| 962 | mp->is_unreach, |
| 963 | mp->is_prohibit, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 964 | mp->is_local, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 965 | mp->is_classify, |
| 966 | mp->classify_table_index, |
| 967 | mp->is_resolve_host, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 968 | mp->is_resolve_attached, 0, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 969 | fib_index, &pfx, 1, |
| 970 | &nh, |
| 971 | ntohl (mp->next_hop_sw_if_index), |
| 972 | next_hop_fib_index, |
| 973 | mp->next_hop_weight, |
| 974 | ntohl (mp->next_hop_via_label), |
| 975 | label_stack)); |
| 976 | } |
| 977 | |
| 978 | static int |
| 979 | ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 980 | { |
| 981 | u32 fib_index, next_hop_fib_index; |
| 982 | mpls_label_t *label_stack = NULL; |
| 983 | int rv, ii, n_labels;; |
| 984 | |
| 985 | rv = add_del_route_check (FIB_PROTOCOL_IP6, |
| 986 | mp->table_id, |
| 987 | mp->next_hop_sw_if_index, |
| 988 | FIB_PROTOCOL_IP6, |
| 989 | mp->next_hop_table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 990 | mp->create_vrf_if_needed, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 991 | &fib_index, &next_hop_fib_index); |
| 992 | |
| 993 | if (0 != rv) |
| 994 | return (rv); |
| 995 | |
| 996 | fib_prefix_t pfx = { |
| 997 | .fp_len = mp->dst_address_length, |
| 998 | .fp_proto = FIB_PROTOCOL_IP6, |
| 999 | }; |
| 1000 | clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6)); |
| 1001 | |
| 1002 | ip46_address_t nh; |
| 1003 | memset (&nh, 0, sizeof (nh)); |
| 1004 | memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6)); |
| 1005 | |
| 1006 | n_labels = mp->next_hop_n_out_labels; |
| 1007 | if (n_labels == 0) |
| 1008 | ; |
| 1009 | else if (1 == n_labels) |
| 1010 | vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0])); |
| 1011 | else |
| 1012 | { |
| 1013 | vec_validate (label_stack, n_labels - 1); |
| 1014 | for (ii = 0; ii < n_labels; ii++) |
| 1015 | label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]); |
| 1016 | } |
| 1017 | |
| 1018 | return (add_del_route_t_handler (mp->is_multipath, |
| 1019 | mp->is_add, |
| 1020 | mp->is_drop, |
| 1021 | mp->is_unreach, |
| 1022 | mp->is_prohibit, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1023 | mp->is_local, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1024 | mp->is_classify, |
| 1025 | mp->classify_table_index, |
| 1026 | mp->is_resolve_host, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1027 | mp->is_resolve_attached, 0, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1028 | fib_index, &pfx, 0, |
| 1029 | &nh, ntohl (mp->next_hop_sw_if_index), |
| 1030 | next_hop_fib_index, |
| 1031 | mp->next_hop_weight, |
| 1032 | ntohl (mp->next_hop_via_label), |
| 1033 | label_stack)); |
| 1034 | } |
| 1035 | |
| 1036 | void |
| 1037 | vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1038 | { |
| 1039 | vl_api_ip_add_del_route_reply_t *rmp; |
| 1040 | int rv; |
| 1041 | vnet_main_t *vnm = vnet_get_main (); |
| 1042 | |
| 1043 | vnm->api_errno = 0; |
| 1044 | |
| 1045 | if (mp->is_ipv6) |
| 1046 | rv = ip6_add_del_route_t_handler (mp); |
| 1047 | else |
| 1048 | rv = ip4_add_del_route_t_handler (mp); |
| 1049 | |
| 1050 | rv = (rv == 0) ? vnm->api_errno : rv; |
| 1051 | |
| 1052 | REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY); |
| 1053 | } |
| 1054 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1055 | static int |
| 1056 | add_del_mroute_check (fib_protocol_t table_proto, |
| 1057 | u32 table_id, |
| 1058 | u32 next_hop_sw_if_index, |
| 1059 | u8 is_local, u8 create_missing_tables, u32 * fib_index) |
| 1060 | { |
| 1061 | vnet_main_t *vnm = vnet_get_main (); |
| 1062 | |
| 1063 | *fib_index = mfib_table_find (table_proto, ntohl (table_id)); |
| 1064 | if (~0 == *fib_index) |
| 1065 | { |
| 1066 | if (create_missing_tables) |
| 1067 | { |
| 1068 | *fib_index = mfib_table_find_or_create_and_lock (table_proto, |
| 1069 | ntohl (table_id)); |
| 1070 | } |
| 1071 | else |
| 1072 | { |
| 1073 | /* No such VRF, and we weren't asked to create one */ |
| 1074 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | if (~0 != ntohl (next_hop_sw_if_index)) |
| 1079 | { |
| 1080 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, |
| 1081 | ntohl (next_hop_sw_if_index))) |
| 1082 | { |
| 1083 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | return (0); |
| 1088 | } |
| 1089 | |
| 1090 | static int |
| 1091 | mroute_add_del_handler (u8 is_add, |
| 1092 | u8 is_local, |
| 1093 | u32 fib_index, |
| 1094 | const mfib_prefix_t * prefix, |
| 1095 | u32 entry_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1096 | fib_rpf_id_t rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1097 | u32 next_hop_sw_if_index, u32 itf_flags) |
| 1098 | { |
| 1099 | stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ ); |
| 1100 | |
| 1101 | fib_route_path_t path = { |
| 1102 | .frp_sw_if_index = next_hop_sw_if_index, |
| 1103 | .frp_proto = prefix->fp_proto, |
| 1104 | }; |
| 1105 | |
| 1106 | if (is_local) |
| 1107 | path.frp_flags |= FIB_ROUTE_PATH_LOCAL; |
| 1108 | |
| 1109 | |
| 1110 | if (!is_local && ~0 == next_hop_sw_if_index) |
| 1111 | { |
| 1112 | mfib_table_entry_update (fib_index, prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1113 | MFIB_SOURCE_API, rpf_id, entry_flags); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1114 | } |
| 1115 | else |
| 1116 | { |
| 1117 | if (is_add) |
| 1118 | { |
| 1119 | mfib_table_entry_path_update (fib_index, prefix, |
| 1120 | MFIB_SOURCE_API, &path, itf_flags); |
| 1121 | } |
| 1122 | else |
| 1123 | { |
| 1124 | mfib_table_entry_path_remove (fib_index, prefix, |
| 1125 | MFIB_SOURCE_API, &path); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | stats_dsunlock (); |
| 1130 | return (0); |
| 1131 | } |
| 1132 | |
| 1133 | static int |
| 1134 | api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 1135 | { |
| 1136 | fib_protocol_t fproto; |
| 1137 | u32 fib_index; |
| 1138 | int rv; |
| 1139 | |
| 1140 | fproto = (mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 1141 | rv = add_del_mroute_check (fproto, |
| 1142 | mp->table_id, |
| 1143 | mp->next_hop_sw_if_index, |
| 1144 | mp->is_local, |
| 1145 | mp->create_vrf_if_needed, &fib_index); |
| 1146 | |
| 1147 | if (0 != rv) |
| 1148 | return (rv); |
| 1149 | |
| 1150 | mfib_prefix_t pfx = { |
| 1151 | .fp_len = ntohs (mp->grp_address_length), |
| 1152 | .fp_proto = fproto, |
| 1153 | }; |
| 1154 | |
| 1155 | if (FIB_PROTOCOL_IP4 == fproto) |
| 1156 | { |
| 1157 | clib_memcpy (&pfx.fp_grp_addr.ip4, mp->grp_address, |
| 1158 | sizeof (pfx.fp_grp_addr.ip4)); |
| 1159 | clib_memcpy (&pfx.fp_src_addr.ip4, mp->src_address, |
| 1160 | sizeof (pfx.fp_src_addr.ip4)); |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | clib_memcpy (&pfx.fp_grp_addr.ip6, mp->grp_address, |
| 1165 | sizeof (pfx.fp_grp_addr.ip6)); |
| 1166 | clib_memcpy (&pfx.fp_src_addr.ip6, mp->src_address, |
| 1167 | sizeof (pfx.fp_src_addr.ip6)); |
| 1168 | } |
| 1169 | |
| 1170 | return (mroute_add_del_handler (mp->is_add, |
| 1171 | mp->is_local, |
| 1172 | fib_index, &pfx, |
| 1173 | ntohl (mp->entry_flags), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1174 | ntohl (mp->rpf_id), |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1175 | ntohl (mp->next_hop_sw_if_index), |
| 1176 | ntohl (mp->itf_flags))); |
| 1177 | } |
| 1178 | |
| 1179 | void |
| 1180 | vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 1181 | { |
| 1182 | vl_api_ip_mroute_add_del_reply_t *rmp; |
| 1183 | int rv; |
| 1184 | vnet_main_t *vnm = vnet_get_main (); |
| 1185 | |
| 1186 | vnm->api_errno = 0; |
| 1187 | |
| 1188 | rv = api_mroute_add_del_t_handler (mp); |
| 1189 | |
| 1190 | rv = (rv == 0) ? vnm->api_errno : rv; |
| 1191 | |
| 1192 | REPLY_MACRO (VL_API_IP_MROUTE_ADD_DEL_REPLY); |
| 1193 | } |
| 1194 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1195 | static void |
| 1196 | send_ip_details (vpe_api_main_t * am, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1197 | unix_shared_memory_queue_t * q, u32 sw_if_index, |
| 1198 | u8 is_ipv6, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1199 | { |
| 1200 | vl_api_ip_details_t *mp; |
| 1201 | |
| 1202 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1203 | memset (mp, 0, sizeof (*mp)); |
| 1204 | mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS); |
| 1205 | |
| 1206 | mp->sw_if_index = ntohl (sw_if_index); |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1207 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1208 | mp->context = context; |
| 1209 | |
| 1210 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1211 | } |
| 1212 | |
| 1213 | static void |
| 1214 | send_ip_address_details (vpe_api_main_t * am, |
| 1215 | unix_shared_memory_queue_t * q, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1216 | u8 * ip, u16 prefix_length, |
| 1217 | u32 sw_if_index, u8 is_ipv6, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1218 | { |
| 1219 | vl_api_ip_address_details_t *mp; |
| 1220 | |
| 1221 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1222 | memset (mp, 0, sizeof (*mp)); |
| 1223 | mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS); |
| 1224 | |
| 1225 | if (is_ipv6) |
| 1226 | { |
| 1227 | clib_memcpy (&mp->ip, ip, sizeof (mp->ip)); |
| 1228 | } |
| 1229 | else |
| 1230 | { |
| 1231 | u32 *tp = (u32 *) mp->ip; |
| 1232 | *tp = *(u32 *) ip; |
| 1233 | } |
| 1234 | mp->prefix_length = prefix_length; |
| 1235 | mp->context = context; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1236 | mp->sw_if_index = htonl (sw_if_index); |
| 1237 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1238 | |
| 1239 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1240 | } |
| 1241 | |
| 1242 | static void |
| 1243 | vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp) |
| 1244 | { |
| 1245 | vpe_api_main_t *am = &vpe_api_main; |
| 1246 | unix_shared_memory_queue_t *q; |
| 1247 | ip6_address_t *r6; |
| 1248 | ip4_address_t *r4; |
| 1249 | ip6_main_t *im6 = &ip6_main; |
| 1250 | ip4_main_t *im4 = &ip4_main; |
| 1251 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 1252 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 1253 | ip_interface_address_t *ia = 0; |
| 1254 | u32 sw_if_index = ~0; |
| 1255 | int rv __attribute__ ((unused)) = 0; |
| 1256 | |
| 1257 | VALIDATE_SW_IF_INDEX (mp); |
| 1258 | |
| 1259 | sw_if_index = ntohl (mp->sw_if_index); |
| 1260 | |
| 1261 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1262 | if (q == 0) |
| 1263 | return; |
| 1264 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1265 | if (mp->is_ipv6) |
| 1266 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1267 | /* *INDENT-OFF* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1268 | foreach_ip_interface_address (lm6, ia, sw_if_index, |
| 1269 | 1 /* honor unnumbered */, |
| 1270 | ({ |
| 1271 | r6 = ip_interface_address_get_address (lm6, ia); |
| 1272 | u16 prefix_length = ia->address_length; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1273 | send_ip_address_details(am, q, (u8*)r6, prefix_length, |
| 1274 | sw_if_index, 1, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1275 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1276 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1277 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1278 | else |
| 1279 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1280 | /* *INDENT-OFF* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1281 | foreach_ip_interface_address (lm4, ia, sw_if_index, |
| 1282 | 1 /* honor unnumbered */, |
| 1283 | ({ |
| 1284 | r4 = ip_interface_address_get_address (lm4, ia); |
| 1285 | u16 prefix_length = ia->address_length; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1286 | send_ip_address_details(am, q, (u8*)r4, prefix_length, |
| 1287 | sw_if_index, 0, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1288 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1289 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1290 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1291 | BAD_SW_IF_INDEX_LABEL; |
| 1292 | } |
| 1293 | |
| 1294 | static void |
| 1295 | vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp) |
| 1296 | { |
| 1297 | vpe_api_main_t *am = &vpe_api_main; |
| 1298 | vnet_main_t *vnm = vnet_get_main (); |
| 1299 | vlib_main_t *vm = vlib_get_main (); |
| 1300 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1301 | unix_shared_memory_queue_t *q; |
| 1302 | vnet_sw_interface_t *si, *sorted_sis; |
| 1303 | u32 sw_if_index = ~0; |
| 1304 | |
| 1305 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1306 | if (q == 0) |
| 1307 | { |
| 1308 | return; |
| 1309 | } |
| 1310 | |
| 1311 | /* Gather interfaces. */ |
| 1312 | sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
| 1313 | _vec_len (sorted_sis) = 0; |
| 1314 | /* *INDENT-OFF* */ |
| 1315 | pool_foreach (si, im->sw_interfaces, |
| 1316 | ({ |
| 1317 | vec_add1 (sorted_sis, si[0]); |
| 1318 | })); |
| 1319 | /* *INDENT-ON* */ |
| 1320 | |
| 1321 | vec_foreach (si, sorted_sis) |
| 1322 | { |
| 1323 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) |
| 1324 | { |
| 1325 | if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) |
| 1326 | { |
| 1327 | continue; |
| 1328 | } |
| 1329 | sw_if_index = si->sw_if_index; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1330 | send_ip_details (am, q, sw_if_index, mp->is_ipv6, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | static void |
| 1336 | set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1337 | { |
| 1338 | vl_api_set_ip_flow_hash_reply_t *rmp; |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1339 | int rv; |
| 1340 | u32 table_id; |
| 1341 | flow_hash_config_t flow_hash_config = 0; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1342 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1343 | table_id = ntohl (mp->vrf_id); |
| 1344 | |
| 1345 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1346 | foreach_flow_hash_bit; |
| 1347 | #undef _ |
| 1348 | |
| 1349 | rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1350 | |
| 1351 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1352 | } |
| 1353 | |
| 1354 | static void |
| 1355 | set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1356 | { |
| 1357 | vl_api_set_ip_flow_hash_reply_t *rmp; |
| 1358 | int rv; |
| 1359 | u32 table_id; |
| 1360 | flow_hash_config_t flow_hash_config = 0; |
| 1361 | |
| 1362 | table_id = ntohl (mp->vrf_id); |
| 1363 | |
| 1364 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1365 | foreach_flow_hash_bit; |
| 1366 | #undef _ |
| 1367 | |
| 1368 | rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config); |
| 1369 | |
| 1370 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1371 | } |
| 1372 | |
| 1373 | |
| 1374 | static void |
| 1375 | vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp) |
| 1376 | { |
| 1377 | if (mp->is_ipv6 == 0) |
| 1378 | set_ip4_flow_hash (mp); |
| 1379 | else |
| 1380 | set_ip6_flow_hash (mp); |
| 1381 | } |
| 1382 | |
| 1383 | static void |
| 1384 | vl_api_sw_interface_ip6nd_ra_config_t_handler |
| 1385 | (vl_api_sw_interface_ip6nd_ra_config_t * mp) |
| 1386 | { |
| 1387 | vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp; |
| 1388 | vlib_main_t *vm = vlib_get_main (); |
| 1389 | int rv = 0; |
| 1390 | u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, |
| 1391 | default_router; |
| 1392 | |
| 1393 | is_no = mp->is_no == 1; |
| 1394 | suppress = mp->suppress == 1; |
| 1395 | managed = mp->managed == 1; |
| 1396 | other = mp->other == 1; |
| 1397 | ll_option = mp->ll_option == 1; |
| 1398 | send_unicast = mp->send_unicast == 1; |
| 1399 | cease = mp->cease == 1; |
| 1400 | default_router = mp->default_router == 1; |
| 1401 | |
| 1402 | VALIDATE_SW_IF_INDEX (mp); |
| 1403 | |
| 1404 | rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index), |
| 1405 | suppress, managed, other, |
| 1406 | ll_option, send_unicast, cease, |
| 1407 | default_router, ntohl (mp->lifetime), |
| 1408 | ntohl (mp->initial_count), |
| 1409 | ntohl (mp->initial_interval), |
| 1410 | ntohl (mp->max_interval), |
| 1411 | ntohl (mp->min_interval), is_no); |
| 1412 | |
| 1413 | BAD_SW_IF_INDEX_LABEL; |
| 1414 | |
| 1415 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY); |
| 1416 | } |
| 1417 | |
| 1418 | static void |
| 1419 | vl_api_sw_interface_ip6nd_ra_prefix_t_handler |
| 1420 | (vl_api_sw_interface_ip6nd_ra_prefix_t * mp) |
| 1421 | { |
| 1422 | vlib_main_t *vm = vlib_get_main (); |
| 1423 | vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp; |
| 1424 | int rv = 0; |
| 1425 | u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink; |
| 1426 | |
| 1427 | VALIDATE_SW_IF_INDEX (mp); |
| 1428 | |
| 1429 | is_no = mp->is_no == 1; |
| 1430 | use_default = mp->use_default == 1; |
| 1431 | no_advertise = mp->no_advertise == 1; |
| 1432 | off_link = mp->off_link == 1; |
| 1433 | no_autoconfig = mp->no_autoconfig == 1; |
| 1434 | no_onlink = mp->no_onlink == 1; |
| 1435 | |
| 1436 | rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index), |
| 1437 | (ip6_address_t *) mp->address, |
| 1438 | mp->address_length, use_default, |
| 1439 | ntohl (mp->val_lifetime), |
| 1440 | ntohl (mp->pref_lifetime), no_advertise, |
| 1441 | off_link, no_autoconfig, no_onlink, is_no); |
| 1442 | |
| 1443 | BAD_SW_IF_INDEX_LABEL; |
| 1444 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY); |
| 1445 | } |
| 1446 | |
| 1447 | static void |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1448 | send_ip6nd_proxy_details (unix_shared_memory_queue_t * q, |
| 1449 | u32 context, |
| 1450 | const ip46_address_t * addr, u32 sw_if_index) |
| 1451 | { |
| 1452 | vl_api_ip6nd_proxy_details_t *mp; |
| 1453 | |
| 1454 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1455 | memset (mp, 0, sizeof (*mp)); |
| 1456 | mp->_vl_msg_id = ntohs (VL_API_IP6ND_PROXY_DETAILS); |
| 1457 | mp->context = context; |
| 1458 | mp->sw_if_index = htonl (sw_if_index); |
| 1459 | memcpy (mp->address, addr, 16); |
| 1460 | |
| 1461 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1462 | } |
| 1463 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1464 | typedef struct api_ip6nd_proxy_fib_table_walk_ctx_t_ |
| 1465 | { |
| 1466 | u32 *indices; |
| 1467 | } api_ip6nd_proxy_fib_table_walk_ctx_t; |
| 1468 | |
| 1469 | static int |
| 1470 | api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg) |
| 1471 | { |
| 1472 | api_ip6nd_proxy_fib_table_walk_ctx_t *ctx = arg; |
| 1473 | |
| 1474 | if (fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND_PROXY)) |
| 1475 | { |
| 1476 | vec_add1 (ctx->indices, fei); |
| 1477 | } |
| 1478 | |
| 1479 | return (1); |
| 1480 | } |
| 1481 | |
| 1482 | static void |
| 1483 | vl_api_ip6nd_proxy_dump_t_handler (vl_api_ip6nd_proxy_dump_t * mp) |
| 1484 | { |
| 1485 | ip6_main_t *im6 = &ip6_main; |
| 1486 | fib_table_t *fib_table; |
| 1487 | api_ip6nd_proxy_fib_table_walk_ctx_t ctx = { |
| 1488 | .indices = NULL, |
| 1489 | }; |
| 1490 | fib_node_index_t *feip; |
| 1491 | fib_prefix_t pfx; |
| 1492 | unix_shared_memory_queue_t *q; |
| 1493 | |
| 1494 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1495 | if (q == 0) |
| 1496 | { |
| 1497 | return; |
| 1498 | } |
| 1499 | |
| 1500 | /* *INDENT-OFF* */ |
| 1501 | pool_foreach (fib_table, im6->fibs, |
| 1502 | ({ |
| 1503 | fib_table_walk(fib_table->ft_index, |
| 1504 | FIB_PROTOCOL_IP6, |
| 1505 | api_ip6nd_proxy_fib_table_walk, |
| 1506 | &ctx); |
| 1507 | })); |
| 1508 | /* *INDENT-ON* */ |
| 1509 | |
| 1510 | vec_sort_with_function (ctx.indices, fib_entry_cmp_for_sort); |
| 1511 | |
| 1512 | vec_foreach (feip, ctx.indices) |
| 1513 | { |
| 1514 | fib_entry_get_prefix (*feip, &pfx); |
| 1515 | |
| 1516 | send_ip6nd_proxy_details (q, |
| 1517 | mp->context, |
| 1518 | &pfx.fp_addr, |
| 1519 | fib_entry_get_resolving_interface (*feip)); |
| 1520 | } |
| 1521 | |
| 1522 | vec_free (ctx.indices); |
| 1523 | } |
| 1524 | |
| 1525 | static void |
| 1526 | vl_api_ip6nd_proxy_add_del_t_handler (vl_api_ip6nd_proxy_add_del_t * mp) |
| 1527 | { |
| 1528 | vl_api_ip6nd_proxy_add_del_reply_t *rmp; |
| 1529 | int rv = 0; |
| 1530 | |
| 1531 | VALIDATE_SW_IF_INDEX (mp); |
| 1532 | |
| 1533 | rv = ip6_neighbor_proxy_add_del (ntohl (mp->sw_if_index), |
| 1534 | (ip6_address_t *) mp->address, mp->is_del); |
| 1535 | |
| 1536 | BAD_SW_IF_INDEX_LABEL; |
| 1537 | REPLY_MACRO (VL_API_IP6ND_PROXY_ADD_DEL_REPLY); |
| 1538 | } |
| 1539 | |
| 1540 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1541 | vl_api_sw_interface_ip6_enable_disable_t_handler |
| 1542 | (vl_api_sw_interface_ip6_enable_disable_t * mp) |
| 1543 | { |
| 1544 | vlib_main_t *vm = vlib_get_main (); |
| 1545 | vl_api_sw_interface_ip6_enable_disable_reply_t *rmp; |
| 1546 | vnet_main_t *vnm = vnet_get_main (); |
| 1547 | int rv = 0; |
| 1548 | clib_error_t *error; |
| 1549 | |
| 1550 | vnm->api_errno = 0; |
| 1551 | |
| 1552 | VALIDATE_SW_IF_INDEX (mp); |
| 1553 | |
| 1554 | error = |
| 1555 | (mp->enable == 1) ? enable_ip6_interface (vm, |
| 1556 | ntohl (mp->sw_if_index)) : |
| 1557 | disable_ip6_interface (vm, ntohl (mp->sw_if_index)); |
| 1558 | |
| 1559 | if (error) |
| 1560 | { |
| 1561 | clib_error_report (error); |
| 1562 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1563 | } |
| 1564 | else |
| 1565 | { |
| 1566 | rv = vnm->api_errno; |
| 1567 | } |
| 1568 | |
| 1569 | BAD_SW_IF_INDEX_LABEL; |
| 1570 | |
| 1571 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY); |
| 1572 | } |
| 1573 | |
| 1574 | static void |
| 1575 | vl_api_sw_interface_ip6_set_link_local_address_t_handler |
| 1576 | (vl_api_sw_interface_ip6_set_link_local_address_t * mp) |
| 1577 | { |
| 1578 | vlib_main_t *vm = vlib_get_main (); |
| 1579 | vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp; |
| 1580 | int rv = 0; |
| 1581 | clib_error_t *error; |
| 1582 | vnet_main_t *vnm = vnet_get_main (); |
| 1583 | |
| 1584 | vnm->api_errno = 0; |
| 1585 | |
| 1586 | VALIDATE_SW_IF_INDEX (mp); |
| 1587 | |
| 1588 | error = set_ip6_link_local_address (vm, |
| 1589 | ntohl (mp->sw_if_index), |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 1590 | (ip6_address_t *) mp->address); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1591 | if (error) |
| 1592 | { |
| 1593 | clib_error_report (error); |
| 1594 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1595 | } |
| 1596 | else |
| 1597 | { |
| 1598 | rv = vnm->api_errno; |
| 1599 | } |
| 1600 | |
| 1601 | BAD_SW_IF_INDEX_LABEL; |
| 1602 | |
| 1603 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY); |
| 1604 | } |
| 1605 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1606 | void |
| 1607 | vl_mfib_signal_send_one (unix_shared_memory_queue_t * q, |
| 1608 | u32 context, const mfib_signal_t * mfs) |
| 1609 | { |
| 1610 | vl_api_mfib_signal_details_t *mp; |
| 1611 | mfib_prefix_t prefix; |
| 1612 | mfib_table_t *mfib; |
| 1613 | mfib_itf_t *mfi; |
| 1614 | |
| 1615 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1616 | |
| 1617 | memset (mp, 0, sizeof (*mp)); |
| 1618 | mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS); |
| 1619 | mp->context = context; |
| 1620 | |
| 1621 | mfi = mfib_itf_get (mfs->mfs_itf); |
| 1622 | mfib_entry_get_prefix (mfs->mfs_entry, &prefix); |
| 1623 | mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry), |
| 1624 | prefix.fp_proto); |
| 1625 | mp->table_id = ntohl (mfib->mft_table_id); |
| 1626 | mp->sw_if_index = ntohl (mfi->mfi_sw_if_index); |
| 1627 | |
| 1628 | if (FIB_PROTOCOL_IP4 == prefix.fp_proto) |
| 1629 | { |
| 1630 | mp->grp_address_len = ntohs (prefix.fp_len); |
| 1631 | |
| 1632 | memcpy (mp->grp_address, &prefix.fp_grp_addr.ip4, 4); |
| 1633 | if (prefix.fp_len > 32) |
| 1634 | { |
| 1635 | memcpy (mp->src_address, &prefix.fp_src_addr.ip4, 4); |
| 1636 | } |
| 1637 | } |
| 1638 | else |
| 1639 | { |
| 1640 | mp->grp_address_len = ntohs (prefix.fp_len); |
| 1641 | |
| 1642 | ASSERT (0); |
| 1643 | } |
| 1644 | |
| 1645 | if (0 != mfs->mfs_buffer_len) |
| 1646 | { |
| 1647 | mp->ip_packet_len = ntohs (mfs->mfs_buffer_len); |
| 1648 | |
| 1649 | memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len); |
| 1650 | } |
| 1651 | else |
| 1652 | { |
| 1653 | mp->ip_packet_len = 0; |
| 1654 | } |
| 1655 | |
| 1656 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1657 | } |
| 1658 | |
| 1659 | static void |
| 1660 | vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp) |
| 1661 | { |
| 1662 | unix_shared_memory_queue_t *q; |
| 1663 | |
| 1664 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1665 | if (q == 0) |
| 1666 | { |
| 1667 | return; |
| 1668 | } |
| 1669 | |
| 1670 | while (q->cursize < q->maxsize && mfib_signal_send_one (q, mp->context)) |
| 1671 | ; |
| 1672 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1673 | |
| 1674 | #define vl_msg_name_crc_list |
| 1675 | #include <vnet/ip/ip.api.h> |
| 1676 | #undef vl_msg_name_crc_list |
| 1677 | |
| 1678 | static void |
| 1679 | setup_message_id_table (api_main_t * am) |
| 1680 | { |
| 1681 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1682 | foreach_vl_msg_name_crc_ip; |
| 1683 | #undef _ |
| 1684 | } |
| 1685 | |
| 1686 | static clib_error_t * |
| 1687 | ip_api_hookup (vlib_main_t * vm) |
| 1688 | { |
| 1689 | api_main_t *am = &api_main; |
| 1690 | |
| 1691 | #define _(N,n) \ |
| 1692 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1693 | vl_api_##n##_t_handler, \ |
| 1694 | vl_noop_handler, \ |
| 1695 | vl_api_##n##_t_endian, \ |
| 1696 | vl_api_##n##_t_print, \ |
| 1697 | sizeof(vl_api_##n##_t), 1); |
| 1698 | foreach_ip_api_msg; |
| 1699 | #undef _ |
| 1700 | |
| 1701 | /* |
| 1702 | * Set up the (msg_name, crc, message-id) table |
| 1703 | */ |
| 1704 | setup_message_id_table (am); |
| 1705 | |
| 1706 | return 0; |
| 1707 | } |
| 1708 | |
| 1709 | VLIB_API_INIT_FUNCTION (ip_api_hookup); |
| 1710 | |
| 1711 | /* |
| 1712 | * fd.io coding-style-patch-verification: ON |
| 1713 | * |
| 1714 | * Local Variables: |
| 1715 | * eval: (c-set-style "gnu") |
| 1716 | * End: |
| 1717 | */ |