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 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 23 | #include <vpp/stats/stats.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 24 | #include <vnet/interface.h> |
| 25 | #include <vnet/api_errno.h> |
| 26 | #include <vnet/ethernet/ethernet.h> |
| 27 | #include <vnet/ip/ip.h> |
| 28 | #include <vnet/ip/ip6_neighbor.h> |
| 29 | #include <vnet/fib/fib_table.h> |
| 30 | #include <vnet/fib/fib_api.h> |
| 31 | #include <vnet/dpo/drop_dpo.h> |
| 32 | #include <vnet/dpo/receive_dpo.h> |
| 33 | #include <vnet/dpo/lookup_dpo.h> |
| 34 | #include <vnet/dpo/classify_dpo.h> |
| 35 | #include <vnet/dpo/ip_null_dpo.h> |
| 36 | #include <vnet/ethernet/arp_packet.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 37 | #include <vnet/mfib/ip6_mfib.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 38 | #include <vnet/mfib/ip4_mfib.h> |
| 39 | #include <vnet/mfib/mfib_signal.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 40 | #include <vnet/mfib/mfib_entry.h> |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 41 | #include <vnet/ip/ip_source_and_port_range_check.h> |
| 42 | #include <vnet/fib/ip4_fib.h> |
| 43 | #include <vnet/fib/ip6_fib.h> |
| 44 | #include <vnet/ip/ip6_hop_by_hop.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 45 | |
| 46 | #include <vnet/vnet_msg_enum.h> |
| 47 | |
| 48 | #define vl_typedefs /* define message structures */ |
| 49 | #include <vnet/vnet_all_api_h.h> |
| 50 | #undef vl_typedefs |
| 51 | |
| 52 | #define vl_endianfun /* define message structures */ |
| 53 | #include <vnet/vnet_all_api_h.h> |
| 54 | #undef vl_endianfun |
| 55 | |
| 56 | /* instantiate all the print functions we know about */ |
| 57 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 58 | #define vl_printfun |
| 59 | #include <vnet/vnet_all_api_h.h> |
| 60 | #undef vl_printfun |
| 61 | |
| 62 | #include <vlibapi/api_helper_macros.h> |
| 63 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 64 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 65 | #define foreach_ip_api_msg \ |
| 66 | _(IP_FIB_DUMP, ip_fib_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 67 | _(IP6_FIB_DUMP, ip6_fib_dump) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 68 | _(IP_MFIB_DUMP, ip_mfib_dump) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 69 | _(IP6_MFIB_DUMP, ip6_mfib_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 70 | _(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 71 | _(IP_MROUTE_ADD_DEL, ip_mroute_add_del) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 72 | _(MFIB_SIGNAL_DUMP, mfib_signal_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 73 | _(IP_ADDRESS_DUMP, ip_address_dump) \ |
| 74 | _(IP_DUMP, ip_dump) \ |
| 75 | _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 76 | _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \ |
| 77 | _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \ |
| 78 | _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \ |
| 79 | _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \ |
| 80 | _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \ |
| 81 | _(RESET_FIB, reset_fib) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 82 | _(IP_ADD_DEL_ROUTE, ip_add_del_route) \ |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 83 | _(IP_TABLE_ADD_DEL, ip_table_add_del) \ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 84 | _(IP_PUNT_POLICE, ip_punt_police) \ |
| 85 | _(IP_PUNT_REDIRECT, ip_punt_redirect) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 86 | _(SET_IP_FLOW_HASH,set_ip_flow_hash) \ |
| 87 | _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \ |
| 88 | _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \ |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 89 | _(IP6ND_PROXY_ADD_DEL, ip6nd_proxy_add_del) \ |
| 90 | _(IP6ND_PROXY_DUMP, ip6nd_proxy_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 91 | _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \ |
| 92 | _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \ |
Florin Coras | 595992c | 2017-11-06 17:17:08 -0800 | [diff] [blame] | 93 | sw_interface_ip6_set_link_local_address) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 94 | _(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \ |
| 95 | _(IOAM_ENABLE, ioam_enable) \ |
| 96 | _(IOAM_DISABLE, ioam_disable) \ |
| 97 | _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \ |
| 98 | ip_source_and_port_range_check_add_del) \ |
| 99 | _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \ |
| 100 | ip_source_and_port_range_check_interface_add_del) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 101 | |
| 102 | extern void stats_dslock_with_hint (int hint, int tag); |
| 103 | extern void stats_dsunlock (void); |
| 104 | |
| 105 | static void |
Jon Loeliger | af8dfbf | 2017-11-08 13:07:39 -0600 | [diff] [blame] | 106 | send_ip_neighbor_details (u32 sw_if_index, |
| 107 | u8 is_ipv6, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 108 | u8 is_static, |
| 109 | u8 * mac_address, |
| 110 | u8 * ip_address, |
| 111 | unix_shared_memory_queue_t * q, u32 context) |
| 112 | { |
| 113 | vl_api_ip_neighbor_details_t *mp; |
| 114 | |
| 115 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 116 | memset (mp, 0, sizeof (*mp)); |
| 117 | mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS); |
| 118 | mp->context = context; |
Jon Loeliger | af8dfbf | 2017-11-08 13:07:39 -0600 | [diff] [blame] | 119 | mp->sw_if_index = htonl (sw_if_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 120 | mp->is_ipv6 = is_ipv6; |
| 121 | mp->is_static = is_static; |
| 122 | memcpy (mp->mac_address, mac_address, 6); |
| 123 | memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4); |
| 124 | |
| 125 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 126 | } |
| 127 | |
| 128 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 129 | vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp) |
| 130 | { |
| 131 | unix_shared_memory_queue_t *q; |
| 132 | |
| 133 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 134 | if (q == 0) |
| 135 | return; |
| 136 | |
| 137 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 138 | |
| 139 | if (mp->is_ipv6) |
| 140 | { |
| 141 | ip6_neighbor_t *n, *ns; |
| 142 | |
| 143 | ns = ip6_neighbors_entries (sw_if_index); |
| 144 | /* *INDENT-OFF* */ |
| 145 | vec_foreach (n, ns) |
| 146 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 147 | send_ip_neighbor_details |
Jon Loeliger | af8dfbf | 2017-11-08 13:07:39 -0600 | [diff] [blame] | 148 | (sw_if_index, mp->is_ipv6, |
| 149 | ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0), |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 150 | (u8 *) n->link_layer_address, |
| 151 | (u8 *) & (n->key.ip6_address.as_u8), |
| 152 | q, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 153 | } |
| 154 | /* *INDENT-ON* */ |
| 155 | vec_free (ns); |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | ethernet_arp_ip4_entry_t *n, *ns; |
| 160 | |
| 161 | ns = ip4_neighbor_entries (sw_if_index); |
| 162 | /* *INDENT-OFF* */ |
| 163 | vec_foreach (n, ns) |
| 164 | { |
Jon Loeliger | af8dfbf | 2017-11-08 13:07:39 -0600 | [diff] [blame] | 165 | send_ip_neighbor_details (sw_if_index, mp->is_ipv6, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 166 | ((n->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) ? 1 : 0), |
| 167 | (u8*) n->ethernet_address, |
| 168 | (u8*) & (n->ip4_address.as_u8), |
| 169 | q, mp->context); |
| 170 | } |
| 171 | /* *INDENT-ON* */ |
| 172 | vec_free (ns); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | void |
| 178 | copy_fib_next_hop (fib_route_path_encode_t * api_rpath, void *fp_arg) |
| 179 | { |
| 180 | int is_ip4; |
| 181 | vl_api_fib_path_t *fp = (vl_api_fib_path_t *) fp_arg; |
| 182 | |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 183 | if (api_rpath->rpath.frp_proto == DPO_PROTO_IP4) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 184 | fp->afi = IP46_TYPE_IP4; |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 185 | else if (api_rpath->rpath.frp_proto == DPO_PROTO_IP6) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 186 | fp->afi = IP46_TYPE_IP6; |
| 187 | else |
| 188 | { |
| 189 | is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr); |
| 190 | if (is_ip4) |
| 191 | fp->afi = IP46_TYPE_IP4; |
| 192 | else |
| 193 | fp->afi = IP46_TYPE_IP6; |
| 194 | } |
| 195 | if (fp->afi == IP46_TYPE_IP4) |
| 196 | memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip4, |
| 197 | sizeof (api_rpath->rpath.frp_addr.ip4)); |
| 198 | else |
| 199 | memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip6, |
| 200 | sizeof (api_rpath->rpath.frp_addr.ip6)); |
| 201 | } |
| 202 | |
| 203 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 204 | send_ip_fib_details (vpe_api_main_t * am, |
| 205 | unix_shared_memory_queue_t * q, |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 206 | const fib_table_t * table, |
| 207 | const fib_prefix_t * pfx, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 208 | fib_route_path_encode_t * api_rpaths, u32 context) |
| 209 | { |
| 210 | vl_api_ip_fib_details_t *mp; |
| 211 | fib_route_path_encode_t *api_rpath; |
| 212 | vl_api_fib_path_t *fp; |
| 213 | int path_count; |
| 214 | |
| 215 | path_count = vec_len (api_rpaths); |
| 216 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 217 | if (!mp) |
| 218 | return; |
| 219 | memset (mp, 0, sizeof (*mp)); |
| 220 | mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS); |
| 221 | mp->context = context; |
| 222 | |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 223 | mp->table_id = htonl (table->ft_table_id); |
| 224 | memcpy (mp->table_name, table->ft_desc, |
| 225 | clib_min (vec_len (table->ft_desc), sizeof (mp->table_name))); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 226 | mp->address_length = pfx->fp_len; |
| 227 | memcpy (mp->address, &pfx->fp_addr.ip4, sizeof (pfx->fp_addr.ip4)); |
| 228 | |
| 229 | mp->count = htonl (path_count); |
| 230 | fp = mp->path; |
| 231 | vec_foreach (api_rpath, api_rpaths) |
| 232 | { |
| 233 | memset (fp, 0, sizeof (*fp)); |
| 234 | switch (api_rpath->dpo.dpoi_type) |
| 235 | { |
| 236 | case DPO_RECEIVE: |
| 237 | fp->is_local = true; |
| 238 | break; |
| 239 | case DPO_DROP: |
| 240 | fp->is_drop = true; |
| 241 | break; |
| 242 | case DPO_IP_NULL: |
| 243 | switch (api_rpath->dpo.dpoi_index) |
| 244 | { |
| 245 | case IP_NULL_ACTION_NONE: |
| 246 | fp->is_drop = true; |
| 247 | break; |
| 248 | case IP_NULL_ACTION_SEND_ICMP_UNREACH: |
| 249 | fp->is_unreach = true; |
| 250 | break; |
| 251 | case IP_NULL_ACTION_SEND_ICMP_PROHIBIT: |
| 252 | fp->is_prohibit = true; |
| 253 | break; |
| 254 | default: |
| 255 | break; |
| 256 | } |
| 257 | break; |
| 258 | default: |
| 259 | break; |
| 260 | } |
Neale Ranns | a0a908f | 2017-08-01 11:40:03 -0700 | [diff] [blame] | 261 | fp->weight = api_rpath->rpath.frp_weight; |
| 262 | fp->preference = api_rpath->rpath.frp_preference; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 263 | fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); |
| 264 | copy_fib_next_hop (api_rpath, fp); |
| 265 | fp++; |
| 266 | } |
| 267 | |
| 268 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 269 | } |
| 270 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 271 | typedef struct vl_api_ip_fib_dump_walk_ctx_t_ |
| 272 | { |
| 273 | fib_node_index_t *feis; |
| 274 | } vl_api_ip_fib_dump_walk_ctx_t; |
| 275 | |
| 276 | static int |
| 277 | vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg) |
| 278 | { |
| 279 | vl_api_ip_fib_dump_walk_ctx_t *ctx = arg; |
| 280 | |
| 281 | vec_add1 (ctx->feis, fei); |
| 282 | |
| 283 | return (1); |
| 284 | } |
| 285 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 286 | static void |
| 287 | vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp) |
| 288 | { |
| 289 | vpe_api_main_t *am = &vpe_api_main; |
| 290 | unix_shared_memory_queue_t *q; |
| 291 | ip4_main_t *im = &ip4_main; |
| 292 | fib_table_t *fib_table; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 293 | fib_node_index_t *lfeip; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 294 | fib_prefix_t pfx; |
| 295 | u32 fib_index; |
| 296 | fib_route_path_encode_t *api_rpaths; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 297 | vl_api_ip_fib_dump_walk_ctx_t ctx = { |
| 298 | .feis = NULL, |
| 299 | }; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 300 | |
| 301 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 302 | if (q == 0) |
| 303 | return; |
| 304 | |
| 305 | /* *INDENT-OFF* */ |
| 306 | pool_foreach (fib_table, im->fibs, |
| 307 | ({ |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 308 | fib_table_walk(fib_table->ft_index, |
| 309 | FIB_PROTOCOL_IP4, |
| 310 | vl_api_ip_fib_dump_walk, |
| 311 | &ctx); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 312 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 313 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 314 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 315 | vec_sort_with_function (ctx.feis, fib_entry_cmp_for_sort); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 316 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 317 | vec_foreach (lfeip, ctx.feis) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 318 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 319 | fib_entry_get_prefix (*lfeip, &pfx); |
| 320 | fib_index = fib_entry_get_fib_index (*lfeip); |
| 321 | fib_table = fib_table_get (fib_index, pfx.fp_proto); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 322 | api_rpaths = NULL; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 323 | fib_entry_encode (*lfeip, &api_rpaths); |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 324 | send_ip_fib_details (am, q, fib_table, &pfx, api_rpaths, mp->context); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 325 | vec_free (api_rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 326 | } |
| 327 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 328 | vec_free (ctx.feis); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 332 | send_ip6_fib_details (vpe_api_main_t * am, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 333 | unix_shared_memory_queue_t * q, |
Neale Ranns | a161a6d | 2017-11-14 08:10:41 -0800 | [diff] [blame] | 334 | const fib_table_t * table, |
| 335 | const fib_prefix_t * pfx, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 336 | fib_route_path_encode_t * api_rpaths, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 337 | { |
| 338 | vl_api_ip6_fib_details_t *mp; |
| 339 | fib_route_path_encode_t *api_rpath; |
| 340 | vl_api_fib_path_t *fp; |
| 341 | int path_count; |
| 342 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 343 | path_count = vec_len (api_rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 344 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 345 | if (!mp) |
| 346 | return; |
| 347 | memset (mp, 0, sizeof (*mp)); |
| 348 | mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS); |
| 349 | mp->context = context; |
| 350 | |
Neale Ranns | a161a6d | 2017-11-14 08:10:41 -0800 | [diff] [blame] | 351 | mp->table_id = htonl (table->ft_table_id); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 352 | mp->address_length = pfx->fp_len; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 353 | memcpy (mp->address, &pfx->fp_addr.ip6, sizeof (pfx->fp_addr.ip6)); |
Neale Ranns | a161a6d | 2017-11-14 08:10:41 -0800 | [diff] [blame] | 354 | memcpy (mp->table_name, table->ft_desc, |
| 355 | clib_min (vec_len (table->ft_desc), sizeof (mp->table_name))); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 356 | |
| 357 | mp->count = htonl (path_count); |
| 358 | fp = mp->path; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 359 | vec_foreach (api_rpath, api_rpaths) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 360 | { |
| 361 | memset (fp, 0, sizeof (*fp)); |
| 362 | switch (api_rpath->dpo.dpoi_type) |
| 363 | { |
| 364 | case DPO_RECEIVE: |
| 365 | fp->is_local = true; |
| 366 | break; |
| 367 | case DPO_DROP: |
| 368 | fp->is_drop = true; |
| 369 | break; |
| 370 | case DPO_IP_NULL: |
| 371 | switch (api_rpath->dpo.dpoi_index) |
| 372 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 373 | case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_NONE: |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 374 | fp->is_drop = true; |
| 375 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 376 | case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_SEND_ICMP_UNREACH: |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 377 | fp->is_unreach = true; |
| 378 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 379 | case IP_NULL_DPO_ACTION_NUM + IP_NULL_ACTION_SEND_ICMP_PROHIBIT: |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 380 | fp->is_prohibit = true; |
| 381 | break; |
| 382 | default: |
| 383 | break; |
| 384 | } |
| 385 | break; |
| 386 | default: |
| 387 | break; |
| 388 | } |
Neale Ranns | a0a908f | 2017-08-01 11:40:03 -0700 | [diff] [blame] | 389 | fp->weight = api_rpath->rpath.frp_weight; |
| 390 | fp->preference = api_rpath->rpath.frp_preference; |
Dave Barach | 0091611 | 2017-10-18 10:54:12 -0400 | [diff] [blame] | 391 | fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 392 | copy_fib_next_hop (api_rpath, fp); |
| 393 | fp++; |
| 394 | } |
| 395 | |
| 396 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 397 | } |
| 398 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 399 | typedef struct apt_ip6_fib_show_ctx_t_ |
| 400 | { |
| 401 | u32 fib_index; |
| 402 | fib_node_index_t *entries; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 403 | } api_ip6_fib_show_ctx_t; |
| 404 | |
| 405 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 406 | 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] | 407 | { |
| 408 | api_ip6_fib_show_ctx_t *ctx = arg; |
| 409 | |
| 410 | if ((kvp->key[2] >> 32) == ctx->fib_index) |
| 411 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 412 | vec_add1 (ctx->entries, kvp->value); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
| 416 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 417 | api_ip6_fib_table_get_all (unix_shared_memory_queue_t * q, |
| 418 | vl_api_ip6_fib_dump_t * mp, |
| 419 | fib_table_t * fib_table) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 420 | { |
| 421 | vpe_api_main_t *am = &vpe_api_main; |
| 422 | ip6_main_t *im6 = &ip6_main; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 423 | fib_node_index_t *fib_entry_index; |
| 424 | api_ip6_fib_show_ctx_t ctx = { |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 425 | .fib_index = fib_table->ft_index, |
| 426 | .entries = NULL, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 427 | }; |
| 428 | fib_route_path_encode_t *api_rpaths; |
| 429 | fib_prefix_t pfx; |
| 430 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 431 | BV (clib_bihash_foreach_key_value_pair) |
| 432 | ((BVT (clib_bihash) *) & im6->ip6_table[IP6_FIB_TABLE_NON_FWDING]. |
| 433 | ip6_hash, api_ip6_fib_table_put_entries, &ctx); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 434 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 435 | vec_sort_with_function (ctx.entries, fib_entry_cmp_for_sort); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 436 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 437 | vec_foreach (fib_entry_index, ctx.entries) |
| 438 | { |
| 439 | fib_entry_get_prefix (*fib_entry_index, &pfx); |
| 440 | api_rpaths = NULL; |
| 441 | fib_entry_encode (*fib_entry_index, &api_rpaths); |
Neale Ranns | a161a6d | 2017-11-14 08:10:41 -0800 | [diff] [blame] | 442 | send_ip6_fib_details (am, q, fib_table, &pfx, api_rpaths, mp->context); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 443 | vec_free (api_rpaths); |
| 444 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 445 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 446 | vec_free (ctx.entries); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static void |
| 450 | vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp) |
| 451 | { |
| 452 | unix_shared_memory_queue_t *q; |
| 453 | ip6_main_t *im6 = &ip6_main; |
| 454 | fib_table_t *fib_table; |
| 455 | |
| 456 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 457 | if (q == 0) |
| 458 | return; |
| 459 | |
| 460 | /* *INDENT-OFF* */ |
| 461 | pool_foreach (fib_table, im6->fibs, |
| 462 | ({ |
| 463 | api_ip6_fib_table_get_all(q, mp, fib_table); |
| 464 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 465 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | static void |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 469 | send_ip_mfib_details (unix_shared_memory_queue_t * q, |
| 470 | u32 context, u32 table_id, fib_node_index_t mfei) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 471 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 472 | fib_route_path_encode_t *api_rpath, *api_rpaths = NULL; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 473 | vl_api_ip_mfib_details_t *mp; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 474 | mfib_entry_t *mfib_entry; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 475 | vl_api_fib_path_t *fp; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 476 | mfib_prefix_t pfx; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 477 | int path_count; |
| 478 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 479 | mfib_entry = mfib_entry_get (mfei); |
| 480 | mfib_entry_get_prefix (mfei, &pfx); |
| 481 | mfib_entry_encode (mfei, &api_rpaths); |
| 482 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 483 | path_count = vec_len (api_rpaths); |
| 484 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 485 | if (!mp) |
| 486 | return; |
| 487 | memset (mp, 0, sizeof (*mp)); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 488 | mp->_vl_msg_id = ntohs (VL_API_IP_MFIB_DETAILS); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 489 | mp->context = context; |
| 490 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 491 | mp->rpf_id = mfib_entry->mfe_rpf_id; |
| 492 | mp->entry_flags = mfib_entry->mfe_flags; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 493 | mp->table_id = htonl (table_id); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 494 | mp->address_length = pfx.fp_len; |
| 495 | memcpy (mp->grp_address, &pfx.fp_grp_addr.ip4, |
| 496 | sizeof (pfx.fp_grp_addr.ip4)); |
| 497 | memcpy (mp->src_address, &pfx.fp_src_addr.ip4, |
| 498 | sizeof (pfx.fp_src_addr.ip4)); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 499 | |
| 500 | mp->count = htonl (path_count); |
| 501 | fp = mp->path; |
| 502 | vec_foreach (api_rpath, api_rpaths) |
| 503 | { |
| 504 | memset (fp, 0, sizeof (*fp)); |
| 505 | |
| 506 | fp->weight = 0; |
| 507 | fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); |
| 508 | copy_fib_next_hop (api_rpath, fp); |
| 509 | fp++; |
| 510 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 511 | vec_free (api_rpaths); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 512 | |
| 513 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 514 | } |
| 515 | |
| 516 | typedef struct vl_api_ip_mfib_dump_ctc_t_ |
| 517 | { |
| 518 | fib_node_index_t *entries; |
| 519 | } vl_api_ip_mfib_dump_ctc_t; |
| 520 | |
| 521 | static int |
| 522 | vl_api_ip_mfib_table_dump_walk (fib_node_index_t fei, void *arg) |
| 523 | { |
| 524 | vl_api_ip_mfib_dump_ctc_t *ctx = arg; |
| 525 | |
| 526 | vec_add1 (ctx->entries, fei); |
| 527 | |
| 528 | return (0); |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | vl_api_ip_mfib_dump_t_handler (vl_api_ip_mfib_dump_t * mp) |
| 533 | { |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 534 | unix_shared_memory_queue_t *q; |
| 535 | ip4_main_t *im = &ip4_main; |
| 536 | mfib_table_t *mfib_table; |
| 537 | fib_node_index_t *mfeip; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 538 | vl_api_ip_mfib_dump_ctc_t ctx = { |
| 539 | .entries = NULL, |
| 540 | }; |
| 541 | |
| 542 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 543 | if (q == 0) |
| 544 | return; |
| 545 | |
| 546 | |
| 547 | /* *INDENT-OFF* */ |
| 548 | pool_foreach (mfib_table, im->mfibs, |
| 549 | ({ |
| 550 | ip4_mfib_table_walk(&mfib_table->v4, |
| 551 | vl_api_ip_mfib_table_dump_walk, |
| 552 | &ctx); |
| 553 | |
| 554 | vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort); |
| 555 | |
| 556 | vec_foreach (mfeip, ctx.entries) |
| 557 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 558 | send_ip_mfib_details (q, mp->context, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 559 | mfib_table->mft_table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 560 | *mfeip); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 561 | } |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 562 | vec_reset_length (ctx.entries); |
| 563 | |
| 564 | })); |
| 565 | /* *INDENT-ON* */ |
| 566 | |
| 567 | vec_free (ctx.entries); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | static void |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 571 | send_ip6_mfib_details (vpe_api_main_t * am, |
| 572 | unix_shared_memory_queue_t * q, |
| 573 | u32 table_id, |
| 574 | mfib_prefix_t * pfx, |
| 575 | fib_route_path_encode_t * api_rpaths, u32 context) |
| 576 | { |
| 577 | vl_api_ip6_mfib_details_t *mp; |
| 578 | fib_route_path_encode_t *api_rpath; |
| 579 | vl_api_fib_path_t *fp; |
| 580 | int path_count; |
| 581 | |
| 582 | path_count = vec_len (api_rpaths); |
| 583 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 584 | if (!mp) |
| 585 | return; |
| 586 | memset (mp, 0, sizeof (*mp)); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 587 | mp->_vl_msg_id = ntohs (VL_API_IP6_MFIB_DETAILS); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 588 | mp->context = context; |
| 589 | |
| 590 | mp->table_id = htonl (table_id); |
| 591 | mp->address_length = pfx->fp_len; |
| 592 | memcpy (mp->grp_address, &pfx->fp_grp_addr.ip6, |
| 593 | sizeof (pfx->fp_grp_addr.ip6)); |
| 594 | memcpy (mp->src_address, &pfx->fp_src_addr.ip6, |
| 595 | sizeof (pfx->fp_src_addr.ip6)); |
| 596 | |
| 597 | mp->count = htonl (path_count); |
| 598 | fp = mp->path; |
| 599 | vec_foreach (api_rpath, api_rpaths) |
| 600 | { |
| 601 | memset (fp, 0, sizeof (*fp)); |
| 602 | |
| 603 | fp->weight = 0; |
| 604 | fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); |
| 605 | copy_fib_next_hop (api_rpath, fp); |
| 606 | fp++; |
| 607 | } |
| 608 | |
| 609 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 610 | } |
| 611 | |
| 612 | typedef struct vl_api_ip6_mfib_dump_ctc_t_ |
| 613 | { |
| 614 | fib_node_index_t *entries; |
| 615 | } vl_api_ip6_mfib_dump_ctc_t; |
| 616 | |
| 617 | static int |
| 618 | vl_api_ip6_mfib_table_dump_walk (fib_node_index_t fei, void *arg) |
| 619 | { |
| 620 | vl_api_ip6_mfib_dump_ctc_t *ctx = arg; |
| 621 | |
| 622 | vec_add1 (ctx->entries, fei); |
| 623 | |
| 624 | return (0); |
| 625 | } |
| 626 | |
| 627 | static void |
| 628 | vl_api_ip6_mfib_dump_t_handler (vl_api_ip6_mfib_dump_t * mp) |
| 629 | { |
| 630 | vpe_api_main_t *am = &vpe_api_main; |
| 631 | unix_shared_memory_queue_t *q; |
| 632 | ip6_main_t *im = &ip6_main; |
| 633 | mfib_table_t *mfib_table; |
| 634 | fib_node_index_t *mfeip; |
| 635 | mfib_prefix_t pfx; |
| 636 | fib_route_path_encode_t *api_rpaths = NULL; |
| 637 | vl_api_ip6_mfib_dump_ctc_t ctx = { |
| 638 | .entries = NULL, |
| 639 | }; |
| 640 | |
| 641 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 642 | if (q == 0) |
| 643 | return; |
| 644 | |
| 645 | |
| 646 | /* *INDENT-OFF* */ |
| 647 | pool_foreach (mfib_table, im->mfibs, |
| 648 | ({ |
| 649 | ip6_mfib_table_walk(&mfib_table->v6, |
| 650 | vl_api_ip6_mfib_table_dump_walk, |
| 651 | &ctx); |
| 652 | |
| 653 | vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort); |
| 654 | |
| 655 | vec_foreach(mfeip, ctx.entries) |
| 656 | { |
| 657 | mfib_entry_get_prefix (*mfeip, &pfx); |
| 658 | mfib_entry_encode (*mfeip, &api_rpaths); |
| 659 | send_ip6_mfib_details (am, q, |
| 660 | mfib_table->mft_table_id, |
| 661 | &pfx, api_rpaths, |
| 662 | mp->context); |
| 663 | } |
| 664 | vec_reset_length (api_rpaths); |
| 665 | vec_reset_length (ctx.entries); |
| 666 | |
| 667 | })); |
| 668 | /* *INDENT-ON* */ |
| 669 | |
| 670 | vec_free (ctx.entries); |
| 671 | vec_free (api_rpaths); |
| 672 | } |
| 673 | |
| 674 | static void |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 675 | vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp, |
| 676 | vlib_main_t * vm) |
| 677 | { |
| 678 | vl_api_ip_punt_police_reply_t *rmp; |
| 679 | int rv = 0; |
| 680 | |
| 681 | if (mp->is_ip6) |
| 682 | ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index)); |
| 683 | else |
| 684 | ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index)); |
| 685 | |
| 686 | REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY); |
| 687 | } |
| 688 | |
| 689 | static void |
| 690 | vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp, |
| 691 | vlib_main_t * vm) |
| 692 | { |
| 693 | vl_api_ip_punt_redirect_reply_t *rmp; |
| 694 | int rv = 0; |
| 695 | |
| 696 | if (mp->is_add) |
| 697 | { |
| 698 | ip46_address_t nh; |
| 699 | |
| 700 | memset (&nh, 0, sizeof (nh)); |
| 701 | |
| 702 | if (mp->is_ip6) |
| 703 | { |
| 704 | memcpy (&nh.ip6, mp->nh, sizeof (nh.ip6)); |
| 705 | |
| 706 | ip6_punt_redirect_add (ntohl (mp->rx_sw_if_index), |
| 707 | ntohl (mp->tx_sw_if_index), &nh); |
| 708 | } |
| 709 | else |
| 710 | { |
| 711 | memcpy (&nh.ip4, mp->nh, sizeof (nh.ip4)); |
| 712 | |
| 713 | ip4_punt_redirect_add (ntohl (mp->rx_sw_if_index), |
| 714 | ntohl (mp->tx_sw_if_index), &nh); |
| 715 | } |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | if (mp->is_ip6) |
| 720 | { |
| 721 | ip6_punt_redirect_del (ntohl (mp->rx_sw_if_index)); |
| 722 | } |
| 723 | else |
| 724 | { |
| 725 | ip4_punt_redirect_del (ntohl (mp->rx_sw_if_index)); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY); |
| 730 | } |
| 731 | |
| 732 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 733 | vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp, |
| 734 | vlib_main_t * vm) |
| 735 | { |
| 736 | vl_api_ip_neighbor_add_del_reply_t *rmp; |
| 737 | vnet_main_t *vnm = vnet_get_main (); |
| 738 | int rv = 0; |
| 739 | |
| 740 | VALIDATE_SW_IF_INDEX (mp); |
| 741 | |
| 742 | stats_dslock_with_hint (1 /* release hint */ , 7 /* tag */ ); |
| 743 | |
| 744 | /* |
| 745 | * there's no validation here of the ND/ARP entry being added. |
| 746 | * The expectation is that the FIB will ensure that nothing bad |
| 747 | * will come of adding bogus entries. |
| 748 | */ |
| 749 | if (mp->is_ipv6) |
| 750 | { |
| 751 | if (mp->is_add) |
| 752 | rv = vnet_set_ip6_ethernet_neighbor |
| 753 | (vm, ntohl (mp->sw_if_index), |
| 754 | (ip6_address_t *) (mp->dst_address), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 755 | mp->mac_address, sizeof (mp->mac_address), mp->is_static, |
| 756 | mp->is_no_adj_fib); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 757 | else |
| 758 | rv = vnet_unset_ip6_ethernet_neighbor |
| 759 | (vm, ntohl (mp->sw_if_index), |
| 760 | (ip6_address_t *) (mp->dst_address), |
| 761 | mp->mac_address, sizeof (mp->mac_address)); |
| 762 | } |
| 763 | else |
| 764 | { |
| 765 | ethernet_arp_ip4_over_ethernet_address_t a; |
| 766 | |
| 767 | clib_memcpy (&a.ethernet, mp->mac_address, 6); |
| 768 | clib_memcpy (&a.ip4, mp->dst_address, 4); |
| 769 | |
| 770 | if (mp->is_add) |
| 771 | 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] | 772 | &a, mp->is_static, |
| 773 | mp->is_no_adj_fib); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 774 | else |
| 775 | rv = |
| 776 | vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a); |
| 777 | } |
| 778 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 779 | stats_dsunlock (); |
Neale Ranns | 8edad03 | 2017-10-09 05:26:13 -0700 | [diff] [blame] | 780 | |
| 781 | BAD_SW_IF_INDEX_LABEL; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 782 | REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY); |
| 783 | } |
| 784 | |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 785 | void |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 786 | ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api) |
| 787 | { |
| 788 | u32 fib_index, mfib_index; |
| 789 | |
| 790 | /* |
| 791 | * ignore action on the default table - this is always present |
| 792 | * and cannot be added nor deleted from the API |
| 793 | */ |
| 794 | if (0 != table_id) |
| 795 | { |
| 796 | /* |
| 797 | * The API holds only one lock on the table. |
| 798 | * i.e. it can be added many times via the API but needs to be |
| 799 | * deleted only once. |
| 800 | * The FIB index for unicast and multicast is not necessarily the |
| 801 | * same, since internal VPP systesm (like LISP and SR) create |
| 802 | * their own unicast tables. |
| 803 | */ |
| 804 | fib_index = fib_table_find (fproto, table_id); |
| 805 | mfib_index = mfib_table_find (fproto, table_id); |
| 806 | |
| 807 | if (~0 != fib_index) |
| 808 | { |
| 809 | fib_table_unlock (fib_index, fproto, |
| 810 | (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI)); |
| 811 | } |
| 812 | if (~0 != mfib_index) |
| 813 | { |
| 814 | mfib_table_unlock (mfib_index, fproto, |
| 815 | (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI)); |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | void |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 821 | vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp) |
| 822 | { |
| 823 | vl_api_ip_table_add_del_reply_t *rmp; |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 824 | fib_protocol_t fproto = (mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 825 | u32 table_id = ntohl (mp->table_id); |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 826 | int rv = 0; |
| 827 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 828 | if (mp->is_add) |
| 829 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 830 | ip_table_create (fproto, table_id, 1, mp->name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 831 | } |
| 832 | else |
| 833 | { |
| 834 | ip_table_delete (fproto, table_id, 1); |
| 835 | } |
| 836 | |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 837 | REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY); |
| 838 | } |
| 839 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 840 | int |
| 841 | add_del_route_t_handler (u8 is_multipath, |
| 842 | u8 is_add, |
| 843 | u8 is_drop, |
| 844 | u8 is_unreach, |
| 845 | u8 is_prohibit, |
| 846 | u8 is_local, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 847 | u8 is_multicast, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 848 | u8 is_classify, |
| 849 | u32 classify_table_index, |
| 850 | u8 is_resolve_host, |
| 851 | u8 is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 852 | u8 is_interface_rx, |
| 853 | u8 is_rpf_id, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame^] | 854 | u8 is_dvr, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 855 | u8 is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 856 | u8 is_udp_encap, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 857 | u32 fib_index, |
| 858 | const fib_prefix_t * prefix, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 859 | dpo_proto_t next_hop_proto, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 860 | const ip46_address_t * next_hop, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 861 | u32 next_hop_id, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 862 | u32 next_hop_sw_if_index, |
| 863 | u8 next_hop_fib_index, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 864 | u16 next_hop_weight, |
| 865 | u16 next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 866 | mpls_label_t next_hop_via_label, |
| 867 | mpls_label_t * next_hop_out_label_stack) |
| 868 | { |
| 869 | vnet_classify_main_t *cm = &vnet_classify_main; |
| 870 | fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE; |
| 871 | fib_route_path_t path = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 872 | .frp_proto = next_hop_proto, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 873 | .frp_addr = (NULL == next_hop ? zero_addr : *next_hop), |
| 874 | .frp_sw_if_index = next_hop_sw_if_index, |
| 875 | .frp_fib_index = next_hop_fib_index, |
| 876 | .frp_weight = next_hop_weight, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 877 | .frp_preference = next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 878 | .frp_label_stack = next_hop_out_label_stack, |
| 879 | }; |
| 880 | fib_route_path_t *paths = NULL; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 881 | fib_entry_flag_t entry_flags = FIB_ENTRY_FLAG_NONE; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 882 | |
Neale Ranns | caac350 | 2017-09-18 18:04:10 -0700 | [diff] [blame] | 883 | /* |
| 884 | * the special INVALID label meams we are not recursing via a |
| 885 | * label. Exp-null value is never a valid via-label so that |
| 886 | * also means it's not a via-label and means clients that set |
| 887 | * it to 0 by default get the expected behaviour |
| 888 | */ |
| 889 | if ((MPLS_LABEL_INVALID != next_hop_via_label) && (0 != next_hop_via_label)) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 890 | { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 891 | path.frp_proto = DPO_PROTO_MPLS; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 892 | path.frp_local_label = next_hop_via_label; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 893 | path.frp_eos = MPLS_NON_EOS; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 894 | } |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame^] | 895 | if (is_dvr) |
| 896 | path_flags |= FIB_ROUTE_PATH_DVR; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 897 | if (is_resolve_host) |
| 898 | path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST; |
| 899 | if (is_resolve_attached) |
| 900 | path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 901 | if (is_interface_rx) |
| 902 | path_flags |= FIB_ROUTE_PATH_INTF_RX; |
| 903 | if (is_rpf_id) |
| 904 | path_flags |= FIB_ROUTE_PATH_RPF_ID; |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 905 | if (is_source_lookup) |
| 906 | path_flags |= FIB_ROUTE_PATH_SOURCE_LOOKUP; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 907 | if (is_multicast) |
| 908 | entry_flags |= FIB_ENTRY_FLAG_MULTICAST; |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 909 | if (is_udp_encap) |
| 910 | { |
| 911 | path_flags |= FIB_ROUTE_PATH_UDP_ENCAP; |
| 912 | path.frp_udp_encap_id = next_hop_id; |
| 913 | } |
Florin Coras | 79ae2d3 | 2017-12-16 08:31:06 -0800 | [diff] [blame] | 914 | if (path.frp_sw_if_index == ~0 && ip46_address_is_zero (&path.frp_addr) |
| 915 | && path.frp_fib_index != ~0) |
| 916 | { |
| 917 | path_flags |= FIB_ROUTE_PATH_DEAG; |
| 918 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 919 | |
| 920 | path.frp_flags = path_flags; |
| 921 | |
| 922 | if (is_multipath) |
| 923 | { |
| 924 | stats_dslock_with_hint (1 /* release hint */ , 10 /* tag */ ); |
| 925 | |
| 926 | |
| 927 | vec_add1 (paths, path); |
| 928 | |
| 929 | if (is_add) |
| 930 | fib_table_entry_path_add2 (fib_index, |
| 931 | prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 932 | FIB_SOURCE_API, entry_flags, paths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 933 | else |
| 934 | fib_table_entry_path_remove2 (fib_index, |
| 935 | prefix, FIB_SOURCE_API, paths); |
| 936 | |
| 937 | vec_free (paths); |
| 938 | stats_dsunlock (); |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ ); |
| 943 | |
| 944 | if (is_drop || is_local || is_classify || is_unreach || is_prohibit) |
| 945 | { |
| 946 | /* |
| 947 | * special route types that link directly to the adj |
| 948 | */ |
| 949 | if (is_add) |
| 950 | { |
| 951 | dpo_id_t dpo = DPO_INVALID; |
| 952 | dpo_proto_t dproto; |
| 953 | |
| 954 | dproto = fib_proto_to_dpo (prefix->fp_proto); |
| 955 | |
| 956 | if (is_drop) |
| 957 | ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo); |
| 958 | else if (is_local) |
| 959 | receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo); |
| 960 | else if (is_unreach) |
| 961 | ip_null_dpo_add_and_lock (dproto, |
| 962 | IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo); |
| 963 | else if (is_prohibit) |
| 964 | ip_null_dpo_add_and_lock (dproto, |
| 965 | IP_NULL_ACTION_SEND_ICMP_PROHIBIT, |
| 966 | &dpo); |
| 967 | else if (is_classify) |
| 968 | { |
| 969 | if (pool_is_free_index (cm->tables, |
| 970 | ntohl (classify_table_index))) |
| 971 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 972 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 973 | return VNET_API_ERROR_NO_SUCH_TABLE; |
| 974 | } |
| 975 | |
| 976 | dpo_set (&dpo, DPO_CLASSIFY, dproto, |
| 977 | classify_dpo_create (dproto, |
| 978 | ntohl (classify_table_index))); |
| 979 | } |
| 980 | else |
| 981 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 982 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 983 | return VNET_API_ERROR_NO_SUCH_TABLE; |
| 984 | } |
| 985 | |
| 986 | fib_table_entry_special_dpo_update (fib_index, |
| 987 | prefix, |
| 988 | FIB_SOURCE_API, |
| 989 | FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); |
| 990 | dpo_reset (&dpo); |
| 991 | } |
| 992 | else |
| 993 | { |
| 994 | fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API); |
| 995 | } |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | if (is_add) |
| 1000 | { |
| 1001 | vec_add1 (paths, path); |
| 1002 | fib_table_entry_update (fib_index, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1003 | prefix, FIB_SOURCE_API, entry_flags, paths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1004 | vec_free (paths); |
| 1005 | } |
| 1006 | else |
| 1007 | { |
| 1008 | fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API); |
| 1009 | } |
| 1010 | } |
| 1011 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1012 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1013 | return (0); |
| 1014 | } |
| 1015 | |
| 1016 | int |
| 1017 | add_del_route_check (fib_protocol_t table_proto, |
| 1018 | u32 table_id, |
| 1019 | u32 next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1020 | dpo_proto_t next_hop_table_proto, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1021 | u32 next_hop_table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1022 | u8 is_rpf_id, u32 * fib_index, u32 * next_hop_fib_index) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1023 | { |
| 1024 | vnet_main_t *vnm = vnet_get_main (); |
| 1025 | |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 1026 | /* Temporaray whilst I do the CSIT dance */ |
| 1027 | u8 create_missing_tables = 1; |
| 1028 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1029 | *fib_index = fib_table_find (table_proto, ntohl (table_id)); |
| 1030 | if (~0 == *fib_index) |
| 1031 | { |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 1032 | if (create_missing_tables) |
| 1033 | { |
| 1034 | *fib_index = fib_table_find_or_create_and_lock (table_proto, |
| 1035 | ntohl (table_id), |
| 1036 | FIB_SOURCE_API); |
| 1037 | } |
| 1038 | else |
| 1039 | { |
| 1040 | /* No such VRF, and we weren't asked to create one */ |
| 1041 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 1042 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1043 | } |
| 1044 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1045 | if (!is_rpf_id && ~0 != ntohl (next_hop_sw_if_index)) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1046 | { |
| 1047 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, |
| 1048 | ntohl (next_hop_sw_if_index))) |
| 1049 | { |
| 1050 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 1051 | } |
| 1052 | } |
| 1053 | else |
| 1054 | { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1055 | fib_protocol_t fib_nh_proto; |
| 1056 | |
| 1057 | if (next_hop_table_proto > DPO_PROTO_MPLS) |
| 1058 | return (0); |
| 1059 | |
| 1060 | fib_nh_proto = dpo_proto_to_fib (next_hop_table_proto); |
| 1061 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1062 | if (is_rpf_id) |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1063 | *next_hop_fib_index = mfib_table_find (fib_nh_proto, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1064 | ntohl (next_hop_table_id)); |
| 1065 | else |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1066 | *next_hop_fib_index = fib_table_find (fib_nh_proto, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1067 | ntohl (next_hop_table_id)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1068 | |
| 1069 | if (~0 == *next_hop_fib_index) |
| 1070 | { |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 1071 | if (create_missing_tables) |
| 1072 | { |
| 1073 | if (is_rpf_id) |
| 1074 | *next_hop_fib_index = |
| 1075 | mfib_table_find_or_create_and_lock (fib_nh_proto, |
| 1076 | ntohl |
| 1077 | (next_hop_table_id), |
| 1078 | MFIB_SOURCE_API); |
| 1079 | else |
| 1080 | *next_hop_fib_index = |
| 1081 | fib_table_find_or_create_and_lock (fib_nh_proto, |
| 1082 | ntohl |
| 1083 | (next_hop_table_id), |
| 1084 | FIB_SOURCE_API); |
| 1085 | } |
| 1086 | else |
| 1087 | { |
| 1088 | /* No such VRF, and we weren't asked to create one */ |
| 1089 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 1090 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | return (0); |
| 1095 | } |
| 1096 | |
| 1097 | static int |
| 1098 | ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1099 | { |
| 1100 | u32 fib_index, next_hop_fib_index; |
| 1101 | mpls_label_t *label_stack = NULL; |
| 1102 | int rv, ii, n_labels;; |
| 1103 | |
| 1104 | rv = add_del_route_check (FIB_PROTOCOL_IP4, |
| 1105 | mp->table_id, |
| 1106 | mp->next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1107 | DPO_PROTO_IP4, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1108 | mp->next_hop_table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1109 | 0, &fib_index, &next_hop_fib_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1110 | |
| 1111 | if (0 != rv) |
| 1112 | return (rv); |
| 1113 | |
| 1114 | fib_prefix_t pfx = { |
| 1115 | .fp_len = mp->dst_address_length, |
| 1116 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1117 | }; |
| 1118 | clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4)); |
| 1119 | |
| 1120 | ip46_address_t nh; |
| 1121 | memset (&nh, 0, sizeof (nh)); |
| 1122 | memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4)); |
| 1123 | |
| 1124 | n_labels = mp->next_hop_n_out_labels; |
| 1125 | if (n_labels == 0) |
| 1126 | ; |
| 1127 | else if (1 == n_labels) |
| 1128 | vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0])); |
| 1129 | else |
| 1130 | { |
| 1131 | vec_validate (label_stack, n_labels - 1); |
| 1132 | for (ii = 0; ii < n_labels; ii++) |
| 1133 | label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]); |
| 1134 | } |
| 1135 | |
| 1136 | return (add_del_route_t_handler (mp->is_multipath, |
| 1137 | mp->is_add, |
| 1138 | mp->is_drop, |
| 1139 | mp->is_unreach, |
| 1140 | mp->is_prohibit, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1141 | mp->is_local, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1142 | mp->is_classify, |
| 1143 | mp->classify_table_index, |
| 1144 | mp->is_resolve_host, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1145 | mp->is_resolve_attached, 0, 0, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame^] | 1146 | mp->is_dvr, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 1147 | mp->is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1148 | mp->is_udp_encap, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1149 | fib_index, &pfx, DPO_PROTO_IP4, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1150 | &nh, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1151 | ntohl (mp->next_hop_id), |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1152 | ntohl (mp->next_hop_sw_if_index), |
| 1153 | next_hop_fib_index, |
| 1154 | mp->next_hop_weight, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1155 | mp->next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1156 | ntohl (mp->next_hop_via_label), |
| 1157 | label_stack)); |
| 1158 | } |
| 1159 | |
| 1160 | static int |
| 1161 | ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1162 | { |
| 1163 | u32 fib_index, next_hop_fib_index; |
| 1164 | mpls_label_t *label_stack = NULL; |
| 1165 | int rv, ii, n_labels;; |
| 1166 | |
| 1167 | rv = add_del_route_check (FIB_PROTOCOL_IP6, |
| 1168 | mp->table_id, |
| 1169 | mp->next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1170 | DPO_PROTO_IP6, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1171 | mp->next_hop_table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1172 | 0, &fib_index, &next_hop_fib_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1173 | |
| 1174 | if (0 != rv) |
| 1175 | return (rv); |
| 1176 | |
| 1177 | fib_prefix_t pfx = { |
| 1178 | .fp_len = mp->dst_address_length, |
| 1179 | .fp_proto = FIB_PROTOCOL_IP6, |
| 1180 | }; |
| 1181 | clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6)); |
| 1182 | |
| 1183 | ip46_address_t nh; |
| 1184 | memset (&nh, 0, sizeof (nh)); |
| 1185 | memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6)); |
| 1186 | |
| 1187 | n_labels = mp->next_hop_n_out_labels; |
| 1188 | if (n_labels == 0) |
| 1189 | ; |
| 1190 | else if (1 == n_labels) |
| 1191 | vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0])); |
| 1192 | else |
| 1193 | { |
| 1194 | vec_validate (label_stack, n_labels - 1); |
| 1195 | for (ii = 0; ii < n_labels; ii++) |
| 1196 | label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]); |
| 1197 | } |
| 1198 | |
| 1199 | return (add_del_route_t_handler (mp->is_multipath, |
| 1200 | mp->is_add, |
| 1201 | mp->is_drop, |
| 1202 | mp->is_unreach, |
| 1203 | mp->is_prohibit, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1204 | mp->is_local, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1205 | mp->is_classify, |
| 1206 | mp->classify_table_index, |
| 1207 | mp->is_resolve_host, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1208 | mp->is_resolve_attached, 0, 0, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame^] | 1209 | mp->is_dvr, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 1210 | mp->is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1211 | mp->is_udp_encap, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1212 | fib_index, &pfx, DPO_PROTO_IP6, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1213 | &nh, ntohl (mp->next_hop_id), |
| 1214 | ntohl (mp->next_hop_sw_if_index), |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1215 | next_hop_fib_index, |
| 1216 | mp->next_hop_weight, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1217 | mp->next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1218 | ntohl (mp->next_hop_via_label), |
| 1219 | label_stack)); |
| 1220 | } |
| 1221 | |
| 1222 | void |
| 1223 | vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1224 | { |
| 1225 | vl_api_ip_add_del_route_reply_t *rmp; |
| 1226 | int rv; |
| 1227 | vnet_main_t *vnm = vnet_get_main (); |
| 1228 | |
| 1229 | vnm->api_errno = 0; |
| 1230 | |
| 1231 | if (mp->is_ipv6) |
| 1232 | rv = ip6_add_del_route_t_handler (mp); |
| 1233 | else |
| 1234 | rv = ip4_add_del_route_t_handler (mp); |
| 1235 | |
| 1236 | rv = (rv == 0) ? vnm->api_errno : rv; |
| 1237 | |
| 1238 | REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY); |
| 1239 | } |
| 1240 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1241 | void |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1242 | ip_table_create (fib_protocol_t fproto, |
| 1243 | u32 table_id, u8 is_api, const u8 * name) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1244 | { |
| 1245 | u32 fib_index, mfib_index; |
| 1246 | |
| 1247 | /* |
| 1248 | * ignore action on the default table - this is always present |
| 1249 | * and cannot be added nor deleted from the API |
| 1250 | */ |
| 1251 | if (0 != table_id) |
| 1252 | { |
| 1253 | /* |
| 1254 | * The API holds only one lock on the table. |
| 1255 | * i.e. it can be added many times via the API but needs to be |
| 1256 | * deleted only once. |
| 1257 | * The FIB index for unicast and multicast is not necessarily the |
| 1258 | * same, since internal VPP systesm (like LISP and SR) create |
| 1259 | * their own unicast tables. |
| 1260 | */ |
| 1261 | fib_index = fib_table_find (fproto, table_id); |
| 1262 | mfib_index = mfib_table_find (fproto, table_id); |
| 1263 | |
| 1264 | if (~0 == fib_index) |
| 1265 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1266 | fib_table_find_or_create_and_lock_w_name (fproto, table_id, |
| 1267 | (is_api ? |
| 1268 | FIB_SOURCE_API : |
| 1269 | FIB_SOURCE_CLI), name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1270 | } |
| 1271 | if (~0 == mfib_index) |
| 1272 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1273 | mfib_table_find_or_create_and_lock_w_name (fproto, table_id, |
| 1274 | (is_api ? |
| 1275 | MFIB_SOURCE_API : |
| 1276 | MFIB_SOURCE_CLI), name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1281 | static int |
| 1282 | add_del_mroute_check (fib_protocol_t table_proto, |
| 1283 | u32 table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1284 | u32 next_hop_sw_if_index, u8 is_local, u32 * fib_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1285 | { |
| 1286 | vnet_main_t *vnm = vnet_get_main (); |
| 1287 | |
| 1288 | *fib_index = mfib_table_find (table_proto, ntohl (table_id)); |
| 1289 | if (~0 == *fib_index) |
| 1290 | { |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1291 | /* No such table */ |
| 1292 | return VNET_API_ERROR_NO_SUCH_FIB; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | if (~0 != ntohl (next_hop_sw_if_index)) |
| 1296 | { |
| 1297 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, |
| 1298 | ntohl (next_hop_sw_if_index))) |
| 1299 | { |
| 1300 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | return (0); |
| 1305 | } |
| 1306 | |
| 1307 | static int |
| 1308 | mroute_add_del_handler (u8 is_add, |
| 1309 | u8 is_local, |
| 1310 | u32 fib_index, |
| 1311 | const mfib_prefix_t * prefix, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1312 | dpo_proto_t nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1313 | u32 entry_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1314 | fib_rpf_id_t rpf_id, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1315 | u32 next_hop_sw_if_index, u32 itf_flags, u32 bier_imp) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1316 | { |
| 1317 | stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ ); |
| 1318 | |
| 1319 | fib_route_path_t path = { |
| 1320 | .frp_sw_if_index = next_hop_sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1321 | .frp_proto = nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1322 | }; |
| 1323 | |
| 1324 | if (is_local) |
| 1325 | path.frp_flags |= FIB_ROUTE_PATH_LOCAL; |
| 1326 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1327 | if (DPO_PROTO_BIER == nh_proto) |
| 1328 | { |
| 1329 | path.frp_bier_imp = bier_imp; |
| 1330 | path.frp_flags = FIB_ROUTE_PATH_BIER_IMP; |
| 1331 | } |
| 1332 | else if (!is_local && ~0 == next_hop_sw_if_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1333 | { |
| 1334 | mfib_table_entry_update (fib_index, prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1335 | MFIB_SOURCE_API, rpf_id, entry_flags); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1336 | goto done; |
| 1337 | } |
| 1338 | |
| 1339 | if (is_add) |
| 1340 | { |
| 1341 | mfib_table_entry_path_update (fib_index, prefix, |
| 1342 | MFIB_SOURCE_API, &path, itf_flags); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1343 | } |
| 1344 | else |
| 1345 | { |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1346 | mfib_table_entry_path_remove (fib_index, prefix, |
| 1347 | MFIB_SOURCE_API, &path); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1350 | done: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1351 | stats_dsunlock (); |
| 1352 | return (0); |
| 1353 | } |
| 1354 | |
| 1355 | static int |
| 1356 | api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 1357 | { |
| 1358 | fib_protocol_t fproto; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1359 | dpo_proto_t nh_proto; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1360 | u32 fib_index; |
| 1361 | int rv; |
| 1362 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1363 | nh_proto = mp->next_hop_afi; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1364 | fproto = (mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 1365 | rv = add_del_mroute_check (fproto, |
| 1366 | mp->table_id, |
| 1367 | mp->next_hop_sw_if_index, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1368 | mp->is_local, &fib_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1369 | |
| 1370 | if (0 != rv) |
| 1371 | return (rv); |
| 1372 | |
| 1373 | mfib_prefix_t pfx = { |
| 1374 | .fp_len = ntohs (mp->grp_address_length), |
| 1375 | .fp_proto = fproto, |
| 1376 | }; |
| 1377 | |
| 1378 | if (FIB_PROTOCOL_IP4 == fproto) |
| 1379 | { |
| 1380 | clib_memcpy (&pfx.fp_grp_addr.ip4, mp->grp_address, |
| 1381 | sizeof (pfx.fp_grp_addr.ip4)); |
| 1382 | clib_memcpy (&pfx.fp_src_addr.ip4, mp->src_address, |
| 1383 | sizeof (pfx.fp_src_addr.ip4)); |
| 1384 | } |
| 1385 | else |
| 1386 | { |
| 1387 | clib_memcpy (&pfx.fp_grp_addr.ip6, mp->grp_address, |
| 1388 | sizeof (pfx.fp_grp_addr.ip6)); |
| 1389 | clib_memcpy (&pfx.fp_src_addr.ip6, mp->src_address, |
| 1390 | sizeof (pfx.fp_src_addr.ip6)); |
| 1391 | } |
| 1392 | |
| 1393 | return (mroute_add_del_handler (mp->is_add, |
| 1394 | mp->is_local, |
| 1395 | fib_index, &pfx, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1396 | nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1397 | ntohl (mp->entry_flags), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1398 | ntohl (mp->rpf_id), |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1399 | ntohl (mp->next_hop_sw_if_index), |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1400 | ntohl (mp->itf_flags), |
| 1401 | ntohl (mp->bier_imp))); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | void |
| 1405 | vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 1406 | { |
| 1407 | vl_api_ip_mroute_add_del_reply_t *rmp; |
| 1408 | int rv; |
| 1409 | vnet_main_t *vnm = vnet_get_main (); |
| 1410 | |
| 1411 | vnm->api_errno = 0; |
| 1412 | |
| 1413 | rv = api_mroute_add_del_t_handler (mp); |
| 1414 | |
| 1415 | rv = (rv == 0) ? vnm->api_errno : rv; |
| 1416 | |
| 1417 | REPLY_MACRO (VL_API_IP_MROUTE_ADD_DEL_REPLY); |
| 1418 | } |
| 1419 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1420 | static void |
| 1421 | send_ip_details (vpe_api_main_t * am, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1422 | unix_shared_memory_queue_t * q, u32 sw_if_index, |
| 1423 | u8 is_ipv6, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1424 | { |
| 1425 | vl_api_ip_details_t *mp; |
| 1426 | |
| 1427 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1428 | memset (mp, 0, sizeof (*mp)); |
| 1429 | mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS); |
| 1430 | |
| 1431 | mp->sw_if_index = ntohl (sw_if_index); |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1432 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1433 | mp->context = context; |
| 1434 | |
| 1435 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1436 | } |
| 1437 | |
| 1438 | static void |
| 1439 | send_ip_address_details (vpe_api_main_t * am, |
| 1440 | unix_shared_memory_queue_t * q, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1441 | u8 * ip, u16 prefix_length, |
| 1442 | u32 sw_if_index, u8 is_ipv6, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1443 | { |
| 1444 | vl_api_ip_address_details_t *mp; |
| 1445 | |
| 1446 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1447 | memset (mp, 0, sizeof (*mp)); |
| 1448 | mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS); |
| 1449 | |
| 1450 | if (is_ipv6) |
| 1451 | { |
| 1452 | clib_memcpy (&mp->ip, ip, sizeof (mp->ip)); |
| 1453 | } |
| 1454 | else |
| 1455 | { |
| 1456 | u32 *tp = (u32 *) mp->ip; |
| 1457 | *tp = *(u32 *) ip; |
| 1458 | } |
| 1459 | mp->prefix_length = prefix_length; |
| 1460 | mp->context = context; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1461 | mp->sw_if_index = htonl (sw_if_index); |
| 1462 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1463 | |
| 1464 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1465 | } |
| 1466 | |
| 1467 | static void |
| 1468 | vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp) |
| 1469 | { |
| 1470 | vpe_api_main_t *am = &vpe_api_main; |
| 1471 | unix_shared_memory_queue_t *q; |
| 1472 | ip6_address_t *r6; |
| 1473 | ip4_address_t *r4; |
| 1474 | ip6_main_t *im6 = &ip6_main; |
| 1475 | ip4_main_t *im4 = &ip4_main; |
| 1476 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 1477 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 1478 | ip_interface_address_t *ia = 0; |
| 1479 | u32 sw_if_index = ~0; |
| 1480 | int rv __attribute__ ((unused)) = 0; |
| 1481 | |
| 1482 | VALIDATE_SW_IF_INDEX (mp); |
| 1483 | |
| 1484 | sw_if_index = ntohl (mp->sw_if_index); |
| 1485 | |
| 1486 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1487 | if (q == 0) |
| 1488 | return; |
| 1489 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1490 | if (mp->is_ipv6) |
| 1491 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1492 | /* *INDENT-OFF* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1493 | foreach_ip_interface_address (lm6, ia, sw_if_index, |
| 1494 | 1 /* honor unnumbered */, |
| 1495 | ({ |
| 1496 | r6 = ip_interface_address_get_address (lm6, ia); |
| 1497 | u16 prefix_length = ia->address_length; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1498 | send_ip_address_details(am, q, (u8*)r6, prefix_length, |
| 1499 | sw_if_index, 1, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1500 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1501 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1502 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1503 | else |
| 1504 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1505 | /* *INDENT-OFF* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1506 | foreach_ip_interface_address (lm4, ia, sw_if_index, |
| 1507 | 1 /* honor unnumbered */, |
| 1508 | ({ |
| 1509 | r4 = ip_interface_address_get_address (lm4, ia); |
| 1510 | u16 prefix_length = ia->address_length; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1511 | send_ip_address_details(am, q, (u8*)r4, prefix_length, |
| 1512 | sw_if_index, 0, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1513 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1514 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1515 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1516 | BAD_SW_IF_INDEX_LABEL; |
| 1517 | } |
| 1518 | |
| 1519 | static void |
| 1520 | vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp) |
| 1521 | { |
| 1522 | vpe_api_main_t *am = &vpe_api_main; |
| 1523 | vnet_main_t *vnm = vnet_get_main (); |
| 1524 | vlib_main_t *vm = vlib_get_main (); |
| 1525 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1526 | unix_shared_memory_queue_t *q; |
| 1527 | vnet_sw_interface_t *si, *sorted_sis; |
| 1528 | u32 sw_if_index = ~0; |
| 1529 | |
| 1530 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1531 | if (q == 0) |
| 1532 | { |
| 1533 | return; |
| 1534 | } |
| 1535 | |
| 1536 | /* Gather interfaces. */ |
| 1537 | sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
| 1538 | _vec_len (sorted_sis) = 0; |
| 1539 | /* *INDENT-OFF* */ |
| 1540 | pool_foreach (si, im->sw_interfaces, |
| 1541 | ({ |
| 1542 | vec_add1 (sorted_sis, si[0]); |
| 1543 | })); |
| 1544 | /* *INDENT-ON* */ |
| 1545 | |
| 1546 | vec_foreach (si, sorted_sis) |
| 1547 | { |
| 1548 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) |
| 1549 | { |
| 1550 | if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) |
| 1551 | { |
| 1552 | continue; |
| 1553 | } |
| 1554 | sw_if_index = si->sw_if_index; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1555 | 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] | 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | static void |
| 1561 | set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1562 | { |
| 1563 | vl_api_set_ip_flow_hash_reply_t *rmp; |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1564 | int rv; |
| 1565 | u32 table_id; |
| 1566 | flow_hash_config_t flow_hash_config = 0; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1567 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1568 | table_id = ntohl (mp->vrf_id); |
| 1569 | |
| 1570 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1571 | foreach_flow_hash_bit; |
| 1572 | #undef _ |
| 1573 | |
| 1574 | rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1575 | |
| 1576 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1577 | } |
| 1578 | |
| 1579 | static void |
| 1580 | set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1581 | { |
| 1582 | vl_api_set_ip_flow_hash_reply_t *rmp; |
| 1583 | int rv; |
| 1584 | u32 table_id; |
| 1585 | flow_hash_config_t flow_hash_config = 0; |
| 1586 | |
| 1587 | table_id = ntohl (mp->vrf_id); |
| 1588 | |
| 1589 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1590 | foreach_flow_hash_bit; |
| 1591 | #undef _ |
| 1592 | |
| 1593 | rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config); |
| 1594 | |
| 1595 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | static void |
| 1600 | vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp) |
| 1601 | { |
| 1602 | if (mp->is_ipv6 == 0) |
| 1603 | set_ip4_flow_hash (mp); |
| 1604 | else |
| 1605 | set_ip6_flow_hash (mp); |
| 1606 | } |
| 1607 | |
| 1608 | static void |
| 1609 | vl_api_sw_interface_ip6nd_ra_config_t_handler |
| 1610 | (vl_api_sw_interface_ip6nd_ra_config_t * mp) |
| 1611 | { |
| 1612 | vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp; |
| 1613 | vlib_main_t *vm = vlib_get_main (); |
| 1614 | int rv = 0; |
| 1615 | u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, |
| 1616 | default_router; |
| 1617 | |
| 1618 | is_no = mp->is_no == 1; |
| 1619 | suppress = mp->suppress == 1; |
| 1620 | managed = mp->managed == 1; |
| 1621 | other = mp->other == 1; |
| 1622 | ll_option = mp->ll_option == 1; |
| 1623 | send_unicast = mp->send_unicast == 1; |
| 1624 | cease = mp->cease == 1; |
| 1625 | default_router = mp->default_router == 1; |
| 1626 | |
| 1627 | VALIDATE_SW_IF_INDEX (mp); |
| 1628 | |
| 1629 | rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index), |
| 1630 | suppress, managed, other, |
| 1631 | ll_option, send_unicast, cease, |
| 1632 | default_router, ntohl (mp->lifetime), |
| 1633 | ntohl (mp->initial_count), |
| 1634 | ntohl (mp->initial_interval), |
| 1635 | ntohl (mp->max_interval), |
| 1636 | ntohl (mp->min_interval), is_no); |
| 1637 | |
| 1638 | BAD_SW_IF_INDEX_LABEL; |
| 1639 | |
| 1640 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY); |
| 1641 | } |
| 1642 | |
| 1643 | static void |
| 1644 | vl_api_sw_interface_ip6nd_ra_prefix_t_handler |
| 1645 | (vl_api_sw_interface_ip6nd_ra_prefix_t * mp) |
| 1646 | { |
| 1647 | vlib_main_t *vm = vlib_get_main (); |
| 1648 | vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp; |
| 1649 | int rv = 0; |
| 1650 | u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink; |
| 1651 | |
| 1652 | VALIDATE_SW_IF_INDEX (mp); |
| 1653 | |
| 1654 | is_no = mp->is_no == 1; |
| 1655 | use_default = mp->use_default == 1; |
| 1656 | no_advertise = mp->no_advertise == 1; |
| 1657 | off_link = mp->off_link == 1; |
| 1658 | no_autoconfig = mp->no_autoconfig == 1; |
| 1659 | no_onlink = mp->no_onlink == 1; |
| 1660 | |
| 1661 | rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index), |
| 1662 | (ip6_address_t *) mp->address, |
| 1663 | mp->address_length, use_default, |
| 1664 | ntohl (mp->val_lifetime), |
| 1665 | ntohl (mp->pref_lifetime), no_advertise, |
| 1666 | off_link, no_autoconfig, no_onlink, is_no); |
| 1667 | |
| 1668 | BAD_SW_IF_INDEX_LABEL; |
| 1669 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY); |
| 1670 | } |
| 1671 | |
| 1672 | static void |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1673 | send_ip6nd_proxy_details (unix_shared_memory_queue_t * q, |
| 1674 | u32 context, |
| 1675 | const ip46_address_t * addr, u32 sw_if_index) |
| 1676 | { |
| 1677 | vl_api_ip6nd_proxy_details_t *mp; |
| 1678 | |
| 1679 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1680 | memset (mp, 0, sizeof (*mp)); |
| 1681 | mp->_vl_msg_id = ntohs (VL_API_IP6ND_PROXY_DETAILS); |
| 1682 | mp->context = context; |
| 1683 | mp->sw_if_index = htonl (sw_if_index); |
| 1684 | memcpy (mp->address, addr, 16); |
| 1685 | |
| 1686 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1687 | } |
| 1688 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1689 | typedef struct api_ip6nd_proxy_fib_table_walk_ctx_t_ |
| 1690 | { |
| 1691 | u32 *indices; |
| 1692 | } api_ip6nd_proxy_fib_table_walk_ctx_t; |
| 1693 | |
| 1694 | static int |
| 1695 | api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg) |
| 1696 | { |
| 1697 | api_ip6nd_proxy_fib_table_walk_ctx_t *ctx = arg; |
| 1698 | |
| 1699 | if (fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND_PROXY)) |
| 1700 | { |
| 1701 | vec_add1 (ctx->indices, fei); |
| 1702 | } |
| 1703 | |
| 1704 | return (1); |
| 1705 | } |
| 1706 | |
| 1707 | static void |
| 1708 | vl_api_ip6nd_proxy_dump_t_handler (vl_api_ip6nd_proxy_dump_t * mp) |
| 1709 | { |
| 1710 | ip6_main_t *im6 = &ip6_main; |
| 1711 | fib_table_t *fib_table; |
| 1712 | api_ip6nd_proxy_fib_table_walk_ctx_t ctx = { |
| 1713 | .indices = NULL, |
| 1714 | }; |
| 1715 | fib_node_index_t *feip; |
| 1716 | fib_prefix_t pfx; |
| 1717 | unix_shared_memory_queue_t *q; |
| 1718 | |
| 1719 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1720 | if (q == 0) |
| 1721 | { |
| 1722 | return; |
| 1723 | } |
| 1724 | |
| 1725 | /* *INDENT-OFF* */ |
| 1726 | pool_foreach (fib_table, im6->fibs, |
| 1727 | ({ |
| 1728 | fib_table_walk(fib_table->ft_index, |
| 1729 | FIB_PROTOCOL_IP6, |
| 1730 | api_ip6nd_proxy_fib_table_walk, |
| 1731 | &ctx); |
| 1732 | })); |
| 1733 | /* *INDENT-ON* */ |
| 1734 | |
| 1735 | vec_sort_with_function (ctx.indices, fib_entry_cmp_for_sort); |
| 1736 | |
| 1737 | vec_foreach (feip, ctx.indices) |
| 1738 | { |
| 1739 | fib_entry_get_prefix (*feip, &pfx); |
| 1740 | |
| 1741 | send_ip6nd_proxy_details (q, |
| 1742 | mp->context, |
| 1743 | &pfx.fp_addr, |
| 1744 | fib_entry_get_resolving_interface (*feip)); |
| 1745 | } |
| 1746 | |
| 1747 | vec_free (ctx.indices); |
| 1748 | } |
| 1749 | |
| 1750 | static void |
| 1751 | vl_api_ip6nd_proxy_add_del_t_handler (vl_api_ip6nd_proxy_add_del_t * mp) |
| 1752 | { |
| 1753 | vl_api_ip6nd_proxy_add_del_reply_t *rmp; |
| 1754 | int rv = 0; |
| 1755 | |
| 1756 | VALIDATE_SW_IF_INDEX (mp); |
| 1757 | |
| 1758 | rv = ip6_neighbor_proxy_add_del (ntohl (mp->sw_if_index), |
| 1759 | (ip6_address_t *) mp->address, mp->is_del); |
| 1760 | |
| 1761 | BAD_SW_IF_INDEX_LABEL; |
| 1762 | REPLY_MACRO (VL_API_IP6ND_PROXY_ADD_DEL_REPLY); |
| 1763 | } |
| 1764 | |
| 1765 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1766 | vl_api_sw_interface_ip6_enable_disable_t_handler |
| 1767 | (vl_api_sw_interface_ip6_enable_disable_t * mp) |
| 1768 | { |
| 1769 | vlib_main_t *vm = vlib_get_main (); |
| 1770 | vl_api_sw_interface_ip6_enable_disable_reply_t *rmp; |
| 1771 | vnet_main_t *vnm = vnet_get_main (); |
| 1772 | int rv = 0; |
| 1773 | clib_error_t *error; |
| 1774 | |
| 1775 | vnm->api_errno = 0; |
| 1776 | |
| 1777 | VALIDATE_SW_IF_INDEX (mp); |
| 1778 | |
| 1779 | error = |
| 1780 | (mp->enable == 1) ? enable_ip6_interface (vm, |
| 1781 | ntohl (mp->sw_if_index)) : |
| 1782 | disable_ip6_interface (vm, ntohl (mp->sw_if_index)); |
| 1783 | |
| 1784 | if (error) |
| 1785 | { |
| 1786 | clib_error_report (error); |
| 1787 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1788 | } |
| 1789 | else |
| 1790 | { |
| 1791 | rv = vnm->api_errno; |
| 1792 | } |
| 1793 | |
| 1794 | BAD_SW_IF_INDEX_LABEL; |
| 1795 | |
| 1796 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY); |
| 1797 | } |
| 1798 | |
| 1799 | static void |
| 1800 | vl_api_sw_interface_ip6_set_link_local_address_t_handler |
| 1801 | (vl_api_sw_interface_ip6_set_link_local_address_t * mp) |
| 1802 | { |
| 1803 | vlib_main_t *vm = vlib_get_main (); |
| 1804 | vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp; |
| 1805 | int rv = 0; |
| 1806 | clib_error_t *error; |
| 1807 | vnet_main_t *vnm = vnet_get_main (); |
| 1808 | |
| 1809 | vnm->api_errno = 0; |
| 1810 | |
| 1811 | VALIDATE_SW_IF_INDEX (mp); |
| 1812 | |
| 1813 | error = set_ip6_link_local_address (vm, |
| 1814 | ntohl (mp->sw_if_index), |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 1815 | (ip6_address_t *) mp->address); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1816 | if (error) |
| 1817 | { |
| 1818 | clib_error_report (error); |
| 1819 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1820 | } |
| 1821 | else |
| 1822 | { |
| 1823 | rv = vnm->api_errno; |
| 1824 | } |
| 1825 | |
| 1826 | BAD_SW_IF_INDEX_LABEL; |
| 1827 | |
| 1828 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY); |
| 1829 | } |
| 1830 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1831 | void |
| 1832 | vl_mfib_signal_send_one (unix_shared_memory_queue_t * q, |
| 1833 | u32 context, const mfib_signal_t * mfs) |
| 1834 | { |
| 1835 | vl_api_mfib_signal_details_t *mp; |
| 1836 | mfib_prefix_t prefix; |
| 1837 | mfib_table_t *mfib; |
| 1838 | mfib_itf_t *mfi; |
| 1839 | |
| 1840 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1841 | |
| 1842 | memset (mp, 0, sizeof (*mp)); |
| 1843 | mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS); |
| 1844 | mp->context = context; |
| 1845 | |
| 1846 | mfi = mfib_itf_get (mfs->mfs_itf); |
| 1847 | mfib_entry_get_prefix (mfs->mfs_entry, &prefix); |
| 1848 | mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry), |
| 1849 | prefix.fp_proto); |
| 1850 | mp->table_id = ntohl (mfib->mft_table_id); |
| 1851 | mp->sw_if_index = ntohl (mfi->mfi_sw_if_index); |
| 1852 | |
| 1853 | if (FIB_PROTOCOL_IP4 == prefix.fp_proto) |
| 1854 | { |
| 1855 | mp->grp_address_len = ntohs (prefix.fp_len); |
| 1856 | |
| 1857 | memcpy (mp->grp_address, &prefix.fp_grp_addr.ip4, 4); |
| 1858 | if (prefix.fp_len > 32) |
| 1859 | { |
| 1860 | memcpy (mp->src_address, &prefix.fp_src_addr.ip4, 4); |
| 1861 | } |
| 1862 | } |
| 1863 | else |
| 1864 | { |
| 1865 | mp->grp_address_len = ntohs (prefix.fp_len); |
| 1866 | |
| 1867 | ASSERT (0); |
| 1868 | } |
| 1869 | |
| 1870 | if (0 != mfs->mfs_buffer_len) |
| 1871 | { |
| 1872 | mp->ip_packet_len = ntohs (mfs->mfs_buffer_len); |
| 1873 | |
| 1874 | memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len); |
| 1875 | } |
| 1876 | else |
| 1877 | { |
| 1878 | mp->ip_packet_len = 0; |
| 1879 | } |
| 1880 | |
| 1881 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1882 | } |
| 1883 | |
| 1884 | static void |
| 1885 | vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp) |
| 1886 | { |
| 1887 | unix_shared_memory_queue_t *q; |
| 1888 | |
| 1889 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1890 | if (q == 0) |
| 1891 | { |
| 1892 | return; |
| 1893 | } |
| 1894 | |
| 1895 | while (q->cursize < q->maxsize && mfib_signal_send_one (q, mp->context)) |
| 1896 | ; |
| 1897 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1898 | |
Florin Coras | 595992c | 2017-11-06 17:17:08 -0800 | [diff] [blame] | 1899 | static void |
| 1900 | vl_api_ip_container_proxy_add_del_t_handler |
| 1901 | (vl_api_ip_container_proxy_add_del_t * mp) |
| 1902 | { |
| 1903 | vl_api_ip_container_proxy_add_del_reply_t *rmp; |
| 1904 | vnet_ip_container_proxy_args_t args; |
| 1905 | int rv = 0; |
| 1906 | clib_error_t *error; |
| 1907 | |
| 1908 | memset (&args, 0, sizeof (args)); |
| 1909 | ip_set (&args.prefix.fp_addr, mp->ip, mp->is_ip4); |
| 1910 | args.prefix.fp_len = mp->plen ? mp->plen : (mp->is_ip4 ? 32 : 128); |
| 1911 | args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index); |
| 1912 | args.is_add = mp->is_add; |
| 1913 | if ((error = vnet_ip_container_proxy_add_del (&args))) |
| 1914 | { |
| 1915 | rv = clib_error_get_code (error); |
| 1916 | clib_error_report (error); |
| 1917 | } |
| 1918 | |
| 1919 | REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY); |
| 1920 | } |
| 1921 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1922 | static void |
| 1923 | vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp) |
| 1924 | { |
| 1925 | int rv = 0; |
| 1926 | vl_api_ioam_enable_reply_t *rmp; |
| 1927 | clib_error_t *error; |
| 1928 | |
| 1929 | /* Ignoring the profile id as currently a single profile |
| 1930 | * is supported */ |
| 1931 | error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable, |
| 1932 | mp->seqno, mp->analyse); |
| 1933 | if (error) |
| 1934 | { |
| 1935 | clib_error_report (error); |
| 1936 | rv = clib_error_get_code (error); |
| 1937 | } |
| 1938 | |
| 1939 | REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY); |
| 1940 | } |
| 1941 | |
| 1942 | static void |
| 1943 | vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp) |
| 1944 | { |
| 1945 | int rv = 0; |
| 1946 | vl_api_ioam_disable_reply_t *rmp; |
| 1947 | clib_error_t *error; |
| 1948 | |
| 1949 | error = clear_ioam_rewrite_fn (); |
| 1950 | if (error) |
| 1951 | { |
| 1952 | clib_error_report (error); |
| 1953 | rv = clib_error_get_code (error); |
| 1954 | } |
| 1955 | |
| 1956 | REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY); |
| 1957 | } |
| 1958 | |
| 1959 | static void |
| 1960 | vl_api_ip_source_and_port_range_check_add_del_t_handler |
| 1961 | (vl_api_ip_source_and_port_range_check_add_del_t * mp) |
| 1962 | { |
| 1963 | vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp; |
| 1964 | int rv = 0; |
| 1965 | |
| 1966 | u8 is_ipv6 = mp->is_ipv6; |
| 1967 | u8 is_add = mp->is_add; |
| 1968 | u8 mask_length = mp->mask_length; |
| 1969 | ip4_address_t ip4_addr; |
| 1970 | ip6_address_t ip6_addr; |
| 1971 | u16 *low_ports = 0; |
| 1972 | u16 *high_ports = 0; |
| 1973 | u32 vrf_id; |
| 1974 | u16 tmp_low, tmp_high; |
| 1975 | u8 num_ranges; |
| 1976 | int i; |
| 1977 | |
| 1978 | // Validate port range |
| 1979 | num_ranges = mp->number_of_ranges; |
| 1980 | if (num_ranges > 32) |
| 1981 | { // This is size of array in VPE.API |
| 1982 | rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY; |
| 1983 | goto reply; |
| 1984 | } |
| 1985 | |
| 1986 | vec_reset_length (low_ports); |
| 1987 | vec_reset_length (high_ports); |
| 1988 | |
| 1989 | for (i = 0; i < num_ranges; i++) |
| 1990 | { |
| 1991 | tmp_low = mp->low_ports[i]; |
| 1992 | tmp_high = mp->high_ports[i]; |
| 1993 | // If tmp_low <= tmp_high then only need to check tmp_low = 0 |
| 1994 | // If tmp_low <= tmp_high then only need to check tmp_high > 65535 |
| 1995 | if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535) |
| 1996 | { |
| 1997 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1998 | goto reply; |
| 1999 | } |
| 2000 | vec_add1 (low_ports, tmp_low); |
| 2001 | vec_add1 (high_ports, tmp_high + 1); |
| 2002 | } |
| 2003 | |
| 2004 | // Validate mask_length |
| 2005 | if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32)) |
| 2006 | { |
| 2007 | rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH; |
| 2008 | goto reply; |
| 2009 | } |
| 2010 | |
| 2011 | vrf_id = ntohl (mp->vrf_id); |
| 2012 | |
| 2013 | if (vrf_id < 1) |
| 2014 | { |
| 2015 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 2016 | goto reply; |
| 2017 | } |
| 2018 | |
| 2019 | |
| 2020 | if (is_ipv6) |
| 2021 | { |
| 2022 | clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8)); |
| 2023 | rv = ip6_source_and_port_range_check_add_del (&ip6_addr, |
| 2024 | mask_length, |
| 2025 | vrf_id, |
| 2026 | low_ports, |
| 2027 | high_ports, is_add); |
| 2028 | } |
| 2029 | else |
| 2030 | { |
| 2031 | clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr)); |
| 2032 | rv = ip4_source_and_port_range_check_add_del (&ip4_addr, |
| 2033 | mask_length, |
| 2034 | vrf_id, |
| 2035 | low_ports, |
| 2036 | high_ports, is_add); |
| 2037 | } |
| 2038 | |
| 2039 | reply: |
| 2040 | vec_free (low_ports); |
| 2041 | vec_free (high_ports); |
| 2042 | REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY); |
| 2043 | } |
| 2044 | |
| 2045 | static void |
| 2046 | vl_api_ip_source_and_port_range_check_interface_add_del_t_handler |
| 2047 | (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp) |
| 2048 | { |
| 2049 | vlib_main_t *vm = vlib_get_main (); |
| 2050 | vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp; |
| 2051 | ip4_main_t *im = &ip4_main; |
| 2052 | int rv; |
| 2053 | u32 sw_if_index; |
| 2054 | u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; |
| 2055 | u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; |
| 2056 | uword *p = 0; |
| 2057 | int i; |
| 2058 | |
| 2059 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] = |
| 2060 | ntohl (mp->tcp_out_vrf_id); |
| 2061 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] = |
| 2062 | ntohl (mp->udp_out_vrf_id); |
| 2063 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] = |
| 2064 | ntohl (mp->tcp_in_vrf_id); |
| 2065 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] = |
| 2066 | ntohl (mp->udp_in_vrf_id); |
| 2067 | |
| 2068 | |
| 2069 | for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++) |
| 2070 | { |
| 2071 | if (vrf_id[i] != 0 && vrf_id[i] != ~0) |
| 2072 | { |
| 2073 | p = hash_get (im->fib_index_by_table_id, vrf_id[i]); |
| 2074 | |
| 2075 | if (p == 0) |
| 2076 | { |
| 2077 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 2078 | goto reply; |
| 2079 | } |
| 2080 | |
| 2081 | fib_index[i] = p[0]; |
| 2082 | } |
| 2083 | else |
| 2084 | fib_index[i] = ~0; |
| 2085 | } |
| 2086 | sw_if_index = ntohl (mp->sw_if_index); |
| 2087 | |
| 2088 | VALIDATE_SW_IF_INDEX (mp); |
| 2089 | |
| 2090 | rv = |
| 2091 | set_ip_source_and_port_range_check (vm, fib_index, sw_if_index, |
| 2092 | mp->is_add); |
| 2093 | |
| 2094 | BAD_SW_IF_INDEX_LABEL; |
| 2095 | reply: |
| 2096 | |
| 2097 | REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY); |
| 2098 | } |
| 2099 | |
| 2100 | #define IP4_ARP_EVENT 3 |
| 2101 | #define IP6_ND_EVENT 4 |
| 2102 | |
| 2103 | static int arp_change_delete_callback (u32 pool_index, u8 * notused); |
| 2104 | static int nd_change_delete_callback (u32 pool_index, u8 * notused); |
| 2105 | static vlib_node_registration_t ip_resolver_process_node; |
| 2106 | |
| 2107 | static void |
| 2108 | handle_ip4_arp_event (u32 pool_index) |
| 2109 | { |
| 2110 | vpe_api_main_t *vam = &vpe_api_main; |
| 2111 | vnet_main_t *vnm = vam->vnet_main; |
| 2112 | vlib_main_t *vm = vam->vlib_main; |
| 2113 | vl_api_ip4_arp_event_t *event; |
| 2114 | vl_api_ip4_arp_event_t *mp; |
| 2115 | unix_shared_memory_queue_t *q; |
| 2116 | |
| 2117 | /* Client can cancel, die, etc. */ |
| 2118 | if (pool_is_free_index (vam->arp_events, pool_index)) |
| 2119 | return; |
| 2120 | |
| 2121 | event = pool_elt_at_index (vam->arp_events, pool_index); |
| 2122 | |
| 2123 | q = vl_api_client_index_to_input_queue (event->client_index); |
| 2124 | if (!q) |
| 2125 | { |
| 2126 | (void) vnet_add_del_ip4_arp_change_event |
| 2127 | (vnm, arp_change_delete_callback, |
| 2128 | event->pid, &event->address, |
| 2129 | ip_resolver_process_node.index, IP4_ARP_EVENT, |
| 2130 | ~0 /* pool index, notused */ , 0 /* is_add */ ); |
| 2131 | return; |
| 2132 | } |
| 2133 | |
| 2134 | if (q->cursize < q->maxsize) |
| 2135 | { |
| 2136 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 2137 | clib_memcpy (mp, event, sizeof (*mp)); |
| 2138 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 2139 | } |
| 2140 | else |
| 2141 | { |
| 2142 | static f64 last_time; |
| 2143 | /* |
| 2144 | * Throttle syslog msgs. |
| 2145 | * It's pretty tempting to just revoke the registration... |
| 2146 | */ |
| 2147 | if (vlib_time_now (vm) > last_time + 10.0) |
| 2148 | { |
| 2149 | clib_warning ("arp event for %U to pid %d: queue stuffed!", |
| 2150 | format_ip4_address, &event->address, event->pid); |
| 2151 | last_time = vlib_time_now (vm); |
| 2152 | } |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | void |
| 2157 | handle_ip6_nd_event (u32 pool_index) |
| 2158 | { |
| 2159 | vpe_api_main_t *vam = &vpe_api_main; |
| 2160 | vnet_main_t *vnm = vam->vnet_main; |
| 2161 | vlib_main_t *vm = vam->vlib_main; |
| 2162 | vl_api_ip6_nd_event_t *event; |
| 2163 | vl_api_ip6_nd_event_t *mp; |
| 2164 | unix_shared_memory_queue_t *q; |
| 2165 | |
| 2166 | /* Client can cancel, die, etc. */ |
| 2167 | if (pool_is_free_index (vam->nd_events, pool_index)) |
| 2168 | return; |
| 2169 | |
| 2170 | event = pool_elt_at_index (vam->nd_events, pool_index); |
| 2171 | |
| 2172 | q = vl_api_client_index_to_input_queue (event->client_index); |
| 2173 | if (!q) |
| 2174 | { |
| 2175 | (void) vnet_add_del_ip6_nd_change_event |
| 2176 | (vnm, nd_change_delete_callback, |
| 2177 | event->pid, &event->address, |
| 2178 | ip_resolver_process_node.index, IP6_ND_EVENT, |
| 2179 | ~0 /* pool index, notused */ , 0 /* is_add */ ); |
| 2180 | return; |
| 2181 | } |
| 2182 | |
| 2183 | if (q->cursize < q->maxsize) |
| 2184 | { |
| 2185 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 2186 | clib_memcpy (mp, event, sizeof (*mp)); |
| 2187 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 2188 | } |
| 2189 | else |
| 2190 | { |
| 2191 | static f64 last_time; |
| 2192 | /* |
| 2193 | * Throttle syslog msgs. |
| 2194 | * It's pretty tempting to just revoke the registration... |
| 2195 | */ |
| 2196 | if (vlib_time_now (vm) > last_time + 10.0) |
| 2197 | { |
| 2198 | clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!", |
| 2199 | format_ip6_address, &event->address, event->pid); |
| 2200 | last_time = vlib_time_now (vm); |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | static uword |
| 2206 | resolver_process (vlib_main_t * vm, |
| 2207 | vlib_node_runtime_t * rt, vlib_frame_t * f) |
| 2208 | { |
| 2209 | volatile f64 timeout = 100.0; |
| 2210 | volatile uword *event_data = 0; |
| 2211 | |
| 2212 | while (1) |
| 2213 | { |
| 2214 | vlib_process_wait_for_event_or_clock (vm, timeout); |
| 2215 | |
| 2216 | uword event_type = |
| 2217 | vlib_process_get_events (vm, (uword **) & event_data); |
| 2218 | |
| 2219 | int i; |
| 2220 | switch (event_type) |
| 2221 | { |
| 2222 | case IP4_ARP_EVENT: |
| 2223 | for (i = 0; i < vec_len (event_data); i++) |
| 2224 | handle_ip4_arp_event (event_data[i]); |
| 2225 | break; |
| 2226 | |
| 2227 | case IP6_ND_EVENT: |
| 2228 | for (i = 0; i < vec_len (event_data); i++) |
| 2229 | handle_ip6_nd_event (event_data[i]); |
| 2230 | break; |
| 2231 | |
| 2232 | case ~0: /* timeout */ |
| 2233 | break; |
| 2234 | } |
| 2235 | |
| 2236 | vec_reset_length (event_data); |
| 2237 | } |
| 2238 | return 0; /* or not */ |
| 2239 | } |
| 2240 | |
| 2241 | /* *INDENT-OFF* */ |
| 2242 | VLIB_REGISTER_NODE (ip_resolver_process_node,static) = { |
| 2243 | .function = resolver_process, |
| 2244 | .type = VLIB_NODE_TYPE_PROCESS, |
| 2245 | .name = "ip-route-resolver-process", |
| 2246 | }; |
| 2247 | /* *INDENT-ON* */ |
| 2248 | |
| 2249 | static int |
| 2250 | nd_change_data_callback (u32 pool_index, u8 * new_mac, |
| 2251 | u32 sw_if_index, ip6_address_t * address) |
| 2252 | { |
| 2253 | vpe_api_main_t *am = &vpe_api_main; |
| 2254 | vl_api_ip6_nd_event_t *event; |
| 2255 | |
| 2256 | if (pool_is_free_index (am->nd_events, pool_index)) |
| 2257 | return 1; |
| 2258 | |
| 2259 | event = pool_elt_at_index (am->nd_events, pool_index); |
| 2260 | if (eth_mac_equal (event->new_mac, new_mac) && |
| 2261 | sw_if_index == ntohl (event->sw_if_index)) |
| 2262 | { |
| 2263 | return 1; |
| 2264 | } |
| 2265 | |
| 2266 | clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac)); |
| 2267 | event->sw_if_index = htonl (sw_if_index); |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
| 2271 | static int |
| 2272 | arp_change_delete_callback (u32 pool_index, u8 * notused) |
| 2273 | { |
| 2274 | vpe_api_main_t *am = &vpe_api_main; |
| 2275 | |
| 2276 | if (pool_is_free_index (am->arp_events, pool_index)) |
| 2277 | return 1; |
| 2278 | |
| 2279 | pool_put_index (am->arp_events, pool_index); |
| 2280 | return 0; |
| 2281 | } |
| 2282 | |
| 2283 | static int |
| 2284 | nd_change_delete_callback (u32 pool_index, u8 * notused) |
| 2285 | { |
| 2286 | vpe_api_main_t *am = &vpe_api_main; |
| 2287 | |
| 2288 | if (pool_is_free_index (am->nd_events, pool_index)) |
| 2289 | return 1; |
| 2290 | |
| 2291 | pool_put_index (am->nd_events, pool_index); |
| 2292 | return 0; |
| 2293 | } |
| 2294 | |
| 2295 | static vlib_node_registration_t wc_arp_process_node; |
| 2296 | |
| 2297 | enum |
| 2298 | { WC_ARP_REPORT, WC_ND_REPORT }; |
| 2299 | |
| 2300 | static uword |
| 2301 | wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) |
| 2302 | { |
| 2303 | /* These cross the longjmp boundry (vlib_process_wait_for_event) |
| 2304 | * and need to be volatile - to prevent them from being optimized into |
| 2305 | * a register - which could change during suspension */ |
| 2306 | |
| 2307 | volatile wc_arp_report_t arp_prev = { 0 }; |
| 2308 | volatile wc_nd_report_t nd_prev = { 0 }; |
| 2309 | volatile f64 last_arp = vlib_time_now (vm); |
| 2310 | volatile f64 last_nd = vlib_time_now (vm); |
| 2311 | |
| 2312 | while (1) |
| 2313 | { |
| 2314 | vlib_process_wait_for_event (vm); |
| 2315 | uword event_type = WC_ARP_REPORT; |
| 2316 | void *event_data = vlib_process_get_event_data (vm, &event_type); |
| 2317 | |
| 2318 | f64 now = vlib_time_now (vm); |
| 2319 | int i; |
| 2320 | if (event_type == WC_ARP_REPORT) |
| 2321 | { |
| 2322 | wc_arp_report_t *arp_events = event_data; |
| 2323 | for (i = 0; i < vec_len (arp_events); i++) |
| 2324 | { |
| 2325 | /* discard dup event */ |
| 2326 | if (arp_prev.ip4 == arp_events[i].ip4 && |
| 2327 | eth_mac_equal ((u8 *) arp_prev.mac, arp_events[i].mac) && |
| 2328 | arp_prev.sw_if_index == arp_events[i].sw_if_index && |
| 2329 | (now - last_arp) < 10.0) |
| 2330 | { |
| 2331 | continue; |
| 2332 | } |
| 2333 | arp_prev = arp_events[i]; |
| 2334 | last_arp = now; |
| 2335 | vpe_client_registration_t *reg; |
| 2336 | /* *INDENT-OFF* */ |
| 2337 | pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations, |
| 2338 | ({ |
| 2339 | unix_shared_memory_queue_t *q; |
| 2340 | q = vl_api_client_index_to_input_queue (reg->client_index); |
| 2341 | if (q && q->cursize < q->maxsize) |
| 2342 | { |
| 2343 | vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event); |
| 2344 | memset (event, 0, sizeof *event); |
| 2345 | event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT); |
| 2346 | event->client_index = reg->client_index; |
| 2347 | event->pid = reg->client_pid; |
| 2348 | event->mac_ip = 1; |
| 2349 | event->address = arp_events[i].ip4; |
| 2350 | event->sw_if_index = htonl(arp_events[i].sw_if_index); |
| 2351 | memcpy(event->new_mac, arp_events[i].mac, sizeof event->new_mac); |
| 2352 | vl_msg_api_send_shmem (q, (u8 *) &event); |
| 2353 | } |
| 2354 | })); |
| 2355 | /* *INDENT-ON* */ |
| 2356 | } |
| 2357 | } |
| 2358 | else if (event_type == WC_ND_REPORT) |
| 2359 | { |
| 2360 | wc_nd_report_t *nd_events = event_data; |
| 2361 | for (i = 0; i < vec_len (nd_events); i++) |
| 2362 | { |
| 2363 | /* discard dup event */ |
| 2364 | if (ip6_address_is_equal |
| 2365 | ((ip6_address_t *) & nd_prev.ip6, &nd_events[i].ip6) |
| 2366 | && eth_mac_equal ((u8 *) nd_prev.mac, nd_events[i].mac) |
| 2367 | && nd_prev.sw_if_index == nd_events[i].sw_if_index |
| 2368 | && (now - last_nd) < 10.0) |
| 2369 | { |
| 2370 | continue; |
| 2371 | } |
| 2372 | nd_prev = nd_events[i]; |
| 2373 | last_nd = now; |
| 2374 | vpe_client_registration_t *reg; |
| 2375 | /* *INDENT-OFF* */ |
| 2376 | pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations, |
| 2377 | ({ |
| 2378 | unix_shared_memory_queue_t *q; |
| 2379 | q = vl_api_client_index_to_input_queue (reg->client_index); |
| 2380 | if (q && q->cursize < q->maxsize) |
| 2381 | { |
| 2382 | vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event); |
| 2383 | memset (event, 0, sizeof *event); |
| 2384 | event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT); |
| 2385 | event->client_index = reg->client_index; |
| 2386 | event->pid = reg->client_pid; |
| 2387 | event->mac_ip = 1; |
| 2388 | memcpy(event->address, nd_events[i].ip6.as_u8, sizeof event->address); |
| 2389 | event->sw_if_index = htonl(nd_events[i].sw_if_index); |
| 2390 | memcpy(event->new_mac, nd_events[i].mac, sizeof event->new_mac); |
| 2391 | vl_msg_api_send_shmem (q, (u8 *) &event); |
| 2392 | } |
| 2393 | })); |
| 2394 | /* *INDENT-ON* */ |
| 2395 | } |
| 2396 | } |
| 2397 | vlib_process_put_event_data (vm, event_data); |
| 2398 | } |
| 2399 | |
| 2400 | return 0; |
| 2401 | } |
| 2402 | |
| 2403 | /* *INDENT-OFF* */ |
| 2404 | VLIB_REGISTER_NODE (wc_arp_process_node,static) = { |
| 2405 | .function = wc_arp_process, |
| 2406 | .type = VLIB_NODE_TYPE_PROCESS, |
| 2407 | .name = "wildcard-ip4-arp-publisher-process", |
| 2408 | }; |
| 2409 | /* *INDENT-ON* */ |
| 2410 | |
| 2411 | static int |
| 2412 | arp_change_data_callback (u32 pool_index, u8 * new_mac, |
| 2413 | u32 sw_if_index, u32 address) |
| 2414 | { |
| 2415 | vpe_api_main_t *am = &vpe_api_main; |
| 2416 | vl_api_ip4_arp_event_t *event; |
| 2417 | |
| 2418 | if (pool_is_free_index (am->arp_events, pool_index)) |
| 2419 | return 1; |
| 2420 | |
| 2421 | event = pool_elt_at_index (am->arp_events, pool_index); |
| 2422 | if (eth_mac_equal (event->new_mac, new_mac) && |
| 2423 | sw_if_index == ntohl (event->sw_if_index)) |
| 2424 | { |
| 2425 | return 1; |
| 2426 | } |
| 2427 | |
| 2428 | clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac)); |
| 2429 | event->sw_if_index = htonl (sw_if_index); |
| 2430 | return 0; |
| 2431 | } |
| 2432 | |
| 2433 | static void |
| 2434 | vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp) |
| 2435 | { |
| 2436 | vpe_api_main_t *am = &vpe_api_main; |
| 2437 | vnet_main_t *vnm = vnet_get_main (); |
| 2438 | vl_api_want_ip4_arp_events_reply_t *rmp; |
| 2439 | int rv = 0; |
| 2440 | |
| 2441 | if (mp->address == 0) |
| 2442 | { |
| 2443 | uword *p = |
| 2444 | hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index); |
| 2445 | vpe_client_registration_t *rp; |
| 2446 | if (p) |
| 2447 | { |
| 2448 | if (mp->enable_disable) |
| 2449 | { |
| 2450 | clib_warning ("pid %d: already enabled...", mp->pid); |
| 2451 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2452 | goto reply; |
| 2453 | } |
| 2454 | else |
| 2455 | { |
| 2456 | rp = |
| 2457 | pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]); |
| 2458 | pool_put (am->wc_ip4_arp_events_registrations, rp); |
| 2459 | hash_unset (am->wc_ip4_arp_events_registration_hash, |
| 2460 | mp->client_index); |
| 2461 | if (pool_elts (am->wc_ip4_arp_events_registrations) == 0) |
| 2462 | wc_arp_set_publisher_node (~0, WC_ARP_REPORT); |
| 2463 | goto reply; |
| 2464 | } |
| 2465 | } |
| 2466 | if (mp->enable_disable == 0) |
| 2467 | { |
| 2468 | clib_warning ("pid %d: already disabled...", mp->pid); |
| 2469 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2470 | goto reply; |
| 2471 | } |
| 2472 | pool_get (am->wc_ip4_arp_events_registrations, rp); |
| 2473 | rp->client_index = mp->client_index; |
| 2474 | rp->client_pid = mp->pid; |
| 2475 | hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index, |
| 2476 | rp - am->wc_ip4_arp_events_registrations); |
| 2477 | wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT); |
| 2478 | goto reply; |
| 2479 | } |
| 2480 | |
| 2481 | if (mp->enable_disable) |
| 2482 | { |
| 2483 | vl_api_ip4_arp_event_t *event; |
| 2484 | pool_get (am->arp_events, event); |
| 2485 | rv = vnet_add_del_ip4_arp_change_event |
| 2486 | (vnm, arp_change_data_callback, |
| 2487 | mp->pid, &mp->address /* addr, in net byte order */ , |
| 2488 | ip_resolver_process_node.index, |
| 2489 | IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ ); |
| 2490 | |
| 2491 | if (rv) |
| 2492 | { |
| 2493 | pool_put (am->arp_events, event); |
| 2494 | goto reply; |
| 2495 | } |
| 2496 | memset (event, 0, sizeof (*event)); |
| 2497 | |
| 2498 | /* Python API expects events to have no context */ |
| 2499 | event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT); |
| 2500 | event->client_index = mp->client_index; |
| 2501 | event->address = mp->address; |
| 2502 | event->pid = mp->pid; |
| 2503 | if (mp->address == 0) |
| 2504 | event->mac_ip = 1; |
| 2505 | } |
| 2506 | else |
| 2507 | { |
| 2508 | rv = vnet_add_del_ip4_arp_change_event |
| 2509 | (vnm, arp_change_delete_callback, |
| 2510 | mp->pid, &mp->address /* addr, in net byte order */ , |
| 2511 | ip_resolver_process_node.index, |
| 2512 | IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ ); |
| 2513 | } |
| 2514 | reply: |
| 2515 | REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY); |
| 2516 | } |
| 2517 | |
| 2518 | static void |
| 2519 | vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp) |
| 2520 | { |
| 2521 | vpe_api_main_t *am = &vpe_api_main; |
| 2522 | vnet_main_t *vnm = vnet_get_main (); |
| 2523 | vl_api_want_ip6_nd_events_reply_t *rmp; |
| 2524 | int rv = 0; |
| 2525 | |
| 2526 | if (ip6_address_is_zero ((ip6_address_t *) mp->address)) |
| 2527 | { |
| 2528 | uword *p = |
| 2529 | hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index); |
| 2530 | vpe_client_registration_t *rp; |
| 2531 | if (p) |
| 2532 | { |
| 2533 | if (mp->enable_disable) |
| 2534 | { |
| 2535 | clib_warning ("pid %d: already enabled...", mp->pid); |
| 2536 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2537 | goto reply; |
| 2538 | } |
| 2539 | else |
| 2540 | { |
| 2541 | rp = |
| 2542 | pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]); |
| 2543 | pool_put (am->wc_ip6_nd_events_registrations, rp); |
| 2544 | hash_unset (am->wc_ip6_nd_events_registration_hash, |
| 2545 | mp->client_index); |
| 2546 | if (pool_elts (am->wc_ip6_nd_events_registrations) == 0) |
| 2547 | wc_nd_set_publisher_node (~0, 2); |
| 2548 | goto reply; |
| 2549 | } |
| 2550 | } |
| 2551 | if (mp->enable_disable == 0) |
| 2552 | { |
| 2553 | clib_warning ("pid %d: already disabled...", mp->pid); |
| 2554 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2555 | goto reply; |
| 2556 | } |
| 2557 | pool_get (am->wc_ip6_nd_events_registrations, rp); |
| 2558 | rp->client_index = mp->client_index; |
| 2559 | rp->client_pid = mp->pid; |
| 2560 | hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index, |
| 2561 | rp - am->wc_ip6_nd_events_registrations); |
| 2562 | wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT); |
| 2563 | goto reply; |
| 2564 | } |
| 2565 | |
| 2566 | if (mp->enable_disable) |
| 2567 | { |
| 2568 | vl_api_ip6_nd_event_t *event; |
| 2569 | pool_get (am->nd_events, event); |
| 2570 | |
| 2571 | rv = vnet_add_del_ip6_nd_change_event |
| 2572 | (vnm, nd_change_data_callback, |
| 2573 | mp->pid, mp->address /* addr, in net byte order */ , |
| 2574 | ip_resolver_process_node.index, |
| 2575 | IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ ); |
| 2576 | |
| 2577 | if (rv) |
| 2578 | { |
| 2579 | pool_put (am->nd_events, event); |
| 2580 | goto reply; |
| 2581 | } |
| 2582 | memset (event, 0, sizeof (*event)); |
| 2583 | |
| 2584 | event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT); |
| 2585 | event->client_index = mp->client_index; |
| 2586 | clib_memcpy (event->address, mp->address, sizeof event->address); |
| 2587 | event->pid = mp->pid; |
| 2588 | } |
| 2589 | else |
| 2590 | { |
| 2591 | rv = vnet_add_del_ip6_nd_change_event |
| 2592 | (vnm, nd_change_delete_callback, |
| 2593 | mp->pid, mp->address /* addr, in net byte order */ , |
| 2594 | ip_resolver_process_node.index, |
| 2595 | IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ ); |
| 2596 | } |
| 2597 | reply: |
| 2598 | REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY); |
| 2599 | } |
| 2600 | |
| 2601 | static void |
| 2602 | vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp) |
| 2603 | { |
| 2604 | vl_api_proxy_arp_add_del_reply_t *rmp; |
| 2605 | u32 fib_index; |
| 2606 | int rv; |
| 2607 | ip4_main_t *im = &ip4_main; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2608 | int vnet_proxy_arp_add_del (ip4_address_t * lo_addr, |
| 2609 | ip4_address_t * hi_addr, |
| 2610 | u32 fib_index, int is_del); |
| 2611 | uword *p; |
| 2612 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2613 | stats_dslock_with_hint (1 /* release hint */ , 6 /* tag */ ); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2614 | |
| 2615 | p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id)); |
| 2616 | |
| 2617 | if (!p) |
| 2618 | { |
| 2619 | rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2620 | goto out; |
| 2621 | } |
| 2622 | |
| 2623 | fib_index = p[0]; |
| 2624 | |
| 2625 | rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address, |
| 2626 | (ip4_address_t *) mp->hi_address, |
| 2627 | fib_index, mp->is_add == 0); |
| 2628 | |
| 2629 | out: |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2630 | stats_dsunlock (); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2631 | REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY); |
| 2632 | } |
| 2633 | |
| 2634 | static void |
| 2635 | vl_api_proxy_arp_intfc_enable_disable_t_handler |
| 2636 | (vl_api_proxy_arp_intfc_enable_disable_t * mp) |
| 2637 | { |
| 2638 | int rv = 0; |
| 2639 | vnet_main_t *vnm = vnet_get_main (); |
| 2640 | vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp; |
| 2641 | |
| 2642 | VALIDATE_SW_IF_INDEX (mp); |
| 2643 | |
| 2644 | vnet_sw_interface_t *si = |
| 2645 | vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index)); |
| 2646 | |
| 2647 | ASSERT (si); |
| 2648 | |
| 2649 | if (mp->enable_disable) |
| 2650 | si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP; |
| 2651 | else |
| 2652 | si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP; |
| 2653 | |
| 2654 | BAD_SW_IF_INDEX_LABEL; |
| 2655 | |
| 2656 | REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY); |
| 2657 | } |
| 2658 | |
| 2659 | static int |
| 2660 | ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2661 | { |
| 2662 | vnet_main_t *vnm = vnet_get_main (); |
| 2663 | vnet_interface_main_t *im = &vnm->interface_main; |
| 2664 | ip4_main_t *im4 = &ip4_main; |
| 2665 | static u32 *sw_if_indices_to_shut; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2666 | fib_table_t *fib_table; |
| 2667 | ip4_fib_t *fib; |
| 2668 | u32 sw_if_index; |
| 2669 | int i; |
| 2670 | int rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2671 | u32 target_fib_id = ntohl (mp->vrf_id); |
| 2672 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2673 | stats_dslock_with_hint (1 /* release hint */ , 8 /* tag */ ); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2674 | |
| 2675 | /* *INDENT-OFF* */ |
| 2676 | pool_foreach (fib_table, im4->fibs, |
| 2677 | ({ |
| 2678 | vnet_sw_interface_t * si; |
| 2679 | |
| 2680 | fib = pool_elt_at_index (im4->v4_fibs, fib_table->ft_index); |
| 2681 | |
| 2682 | if (fib->table_id != target_fib_id) |
| 2683 | continue; |
| 2684 | |
| 2685 | /* remove any mpls encap/decap labels */ |
| 2686 | mpls_fib_reset_labels (fib->table_id); |
| 2687 | |
| 2688 | /* remove any proxy arps in this fib */ |
| 2689 | vnet_proxy_arp_fib_reset (fib->table_id); |
| 2690 | |
| 2691 | /* Set the flow hash for this fib to the default */ |
| 2692 | vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT); |
| 2693 | |
| 2694 | vec_reset_length (sw_if_indices_to_shut); |
| 2695 | |
| 2696 | /* Shut down interfaces in this FIB / clean out intfc routes */ |
| 2697 | pool_foreach (si, im->sw_interfaces, |
| 2698 | ({ |
| 2699 | u32 sw_if_index = si->sw_if_index; |
| 2700 | |
| 2701 | if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index) |
| 2702 | && (im4->fib_index_by_sw_if_index[si->sw_if_index] == |
| 2703 | fib->index)) |
| 2704 | vec_add1 (sw_if_indices_to_shut, si->sw_if_index); |
| 2705 | })); |
| 2706 | |
| 2707 | for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) { |
| 2708 | sw_if_index = sw_if_indices_to_shut[i]; |
| 2709 | |
| 2710 | u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index); |
| 2711 | flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 2712 | vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 2713 | } |
| 2714 | |
| 2715 | fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API); |
| 2716 | |
| 2717 | rv = 0; |
| 2718 | break; |
| 2719 | })); /* pool_foreach (fib) */ |
| 2720 | /* *INDENT-ON* */ |
| 2721 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2722 | stats_dsunlock (); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2723 | return rv; |
| 2724 | } |
| 2725 | |
| 2726 | static int |
| 2727 | ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2728 | { |
| 2729 | vnet_main_t *vnm = vnet_get_main (); |
| 2730 | vnet_interface_main_t *im = &vnm->interface_main; |
| 2731 | ip6_main_t *im6 = &ip6_main; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2732 | static u32 *sw_if_indices_to_shut; |
| 2733 | fib_table_t *fib_table; |
| 2734 | ip6_fib_t *fib; |
| 2735 | u32 sw_if_index; |
| 2736 | int i; |
| 2737 | int rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2738 | u32 target_fib_id = ntohl (mp->vrf_id); |
| 2739 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2740 | stats_dslock_with_hint (1 /* release hint */ , 9 /* tag */ ); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2741 | |
| 2742 | /* *INDENT-OFF* */ |
| 2743 | pool_foreach (fib_table, im6->fibs, |
| 2744 | ({ |
| 2745 | vnet_sw_interface_t * si; |
| 2746 | |
| 2747 | fib = pool_elt_at_index (im6->v6_fibs, fib_table->ft_index); |
| 2748 | |
| 2749 | if (fib->table_id != target_fib_id) |
| 2750 | continue; |
| 2751 | |
| 2752 | vec_reset_length (sw_if_indices_to_shut); |
| 2753 | |
| 2754 | /* Set the flow hash for this fib to the default */ |
| 2755 | vnet_set_ip6_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT); |
| 2756 | |
| 2757 | /* Shut down interfaces in this FIB / clean out intfc routes */ |
| 2758 | pool_foreach (si, im->sw_interfaces, |
| 2759 | ({ |
| 2760 | if (im6->fib_index_by_sw_if_index[si->sw_if_index] == |
| 2761 | fib->index) |
| 2762 | vec_add1 (sw_if_indices_to_shut, si->sw_if_index); |
| 2763 | })); |
| 2764 | |
| 2765 | for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) { |
| 2766 | sw_if_index = sw_if_indices_to_shut[i]; |
| 2767 | |
| 2768 | u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index); |
| 2769 | flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 2770 | vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 2771 | } |
| 2772 | |
| 2773 | fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API); |
| 2774 | |
| 2775 | rv = 0; |
| 2776 | break; |
| 2777 | })); /* pool_foreach (fib) */ |
| 2778 | /* *INDENT-ON* */ |
| 2779 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2780 | stats_dsunlock (); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2781 | return rv; |
| 2782 | } |
| 2783 | |
| 2784 | static void |
| 2785 | vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2786 | { |
| 2787 | int rv; |
| 2788 | vl_api_reset_fib_reply_t *rmp; |
| 2789 | |
| 2790 | if (mp->is_ipv6) |
| 2791 | rv = ip6_reset_fib_t_handler (mp); |
| 2792 | else |
| 2793 | rv = ip4_reset_fib_t_handler (mp); |
| 2794 | |
| 2795 | REPLY_MACRO (VL_API_RESET_FIB_REPLY); |
| 2796 | } |
| 2797 | |
| 2798 | static void |
| 2799 | vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp) |
| 2800 | { |
| 2801 | int rv; |
| 2802 | vl_api_set_arp_neighbor_limit_reply_t *rmp; |
| 2803 | vnet_main_t *vnm = vnet_get_main (); |
| 2804 | clib_error_t *error; |
| 2805 | |
| 2806 | vnm->api_errno = 0; |
| 2807 | |
| 2808 | if (mp->is_ipv6) |
| 2809 | error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit)); |
| 2810 | else |
| 2811 | error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit)); |
| 2812 | |
| 2813 | if (error) |
| 2814 | { |
| 2815 | clib_error_report (error); |
| 2816 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 2817 | } |
| 2818 | else |
| 2819 | { |
| 2820 | rv = vnm->api_errno; |
| 2821 | } |
| 2822 | |
| 2823 | REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY); |
| 2824 | } |
| 2825 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 2826 | #define vl_msg_name_crc_list |
| 2827 | #include <vnet/ip/ip.api.h> |
| 2828 | #undef vl_msg_name_crc_list |
| 2829 | |
| 2830 | static void |
| 2831 | setup_message_id_table (api_main_t * am) |
| 2832 | { |
| 2833 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 2834 | foreach_vl_msg_name_crc_ip; |
| 2835 | #undef _ |
| 2836 | } |
| 2837 | |
| 2838 | static clib_error_t * |
| 2839 | ip_api_hookup (vlib_main_t * vm) |
| 2840 | { |
| 2841 | api_main_t *am = &api_main; |
| 2842 | |
| 2843 | #define _(N,n) \ |
| 2844 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 2845 | vl_api_##n##_t_handler, \ |
| 2846 | vl_noop_handler, \ |
| 2847 | vl_api_##n##_t_endian, \ |
| 2848 | vl_api_##n##_t_print, \ |
| 2849 | sizeof(vl_api_##n##_t), 1); |
| 2850 | foreach_ip_api_msg; |
| 2851 | #undef _ |
| 2852 | |
| 2853 | /* |
| 2854 | * Set up the (msg_name, crc, message-id) table |
| 2855 | */ |
| 2856 | setup_message_id_table (am); |
| 2857 | |
| 2858 | return 0; |
| 2859 | } |
| 2860 | |
| 2861 | VLIB_API_INIT_FUNCTION (ip_api_hookup); |
| 2862 | |
| 2863 | /* |
| 2864 | * fd.io coding-style-patch-verification: ON |
| 2865 | * |
| 2866 | * Local Variables: |
| 2867 | * eval: (c-set-style "gnu") |
| 2868 | * End: |
| 2869 | */ |