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 | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 854 | u8 is_l2_bridged, |
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 | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 895 | if (is_l2_bridged) |
| 896 | path.frp_proto = DPO_PROTO_ETHERNET; |
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 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 914 | |
| 915 | path.frp_flags = path_flags; |
| 916 | |
| 917 | if (is_multipath) |
| 918 | { |
| 919 | stats_dslock_with_hint (1 /* release hint */ , 10 /* tag */ ); |
| 920 | |
| 921 | |
| 922 | vec_add1 (paths, path); |
| 923 | |
| 924 | if (is_add) |
| 925 | fib_table_entry_path_add2 (fib_index, |
| 926 | prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 927 | FIB_SOURCE_API, entry_flags, paths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 928 | else |
| 929 | fib_table_entry_path_remove2 (fib_index, |
| 930 | prefix, FIB_SOURCE_API, paths); |
| 931 | |
| 932 | vec_free (paths); |
| 933 | stats_dsunlock (); |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ ); |
| 938 | |
| 939 | if (is_drop || is_local || is_classify || is_unreach || is_prohibit) |
| 940 | { |
| 941 | /* |
| 942 | * special route types that link directly to the adj |
| 943 | */ |
| 944 | if (is_add) |
| 945 | { |
| 946 | dpo_id_t dpo = DPO_INVALID; |
| 947 | dpo_proto_t dproto; |
| 948 | |
| 949 | dproto = fib_proto_to_dpo (prefix->fp_proto); |
| 950 | |
| 951 | if (is_drop) |
| 952 | ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo); |
| 953 | else if (is_local) |
| 954 | receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo); |
| 955 | else if (is_unreach) |
| 956 | ip_null_dpo_add_and_lock (dproto, |
| 957 | IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo); |
| 958 | else if (is_prohibit) |
| 959 | ip_null_dpo_add_and_lock (dproto, |
| 960 | IP_NULL_ACTION_SEND_ICMP_PROHIBIT, |
| 961 | &dpo); |
| 962 | else if (is_classify) |
| 963 | { |
| 964 | if (pool_is_free_index (cm->tables, |
| 965 | ntohl (classify_table_index))) |
| 966 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 967 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 968 | return VNET_API_ERROR_NO_SUCH_TABLE; |
| 969 | } |
| 970 | |
| 971 | dpo_set (&dpo, DPO_CLASSIFY, dproto, |
| 972 | classify_dpo_create (dproto, |
| 973 | ntohl (classify_table_index))); |
| 974 | } |
| 975 | else |
| 976 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 977 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 978 | return VNET_API_ERROR_NO_SUCH_TABLE; |
| 979 | } |
| 980 | |
| 981 | fib_table_entry_special_dpo_update (fib_index, |
| 982 | prefix, |
| 983 | FIB_SOURCE_API, |
| 984 | FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); |
| 985 | dpo_reset (&dpo); |
| 986 | } |
| 987 | else |
| 988 | { |
| 989 | fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API); |
| 990 | } |
| 991 | } |
| 992 | else |
| 993 | { |
| 994 | if (is_add) |
| 995 | { |
| 996 | vec_add1 (paths, path); |
| 997 | fib_table_entry_update (fib_index, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 998 | prefix, FIB_SOURCE_API, entry_flags, paths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 999 | vec_free (paths); |
| 1000 | } |
| 1001 | else |
| 1002 | { |
| 1003 | fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API); |
| 1004 | } |
| 1005 | } |
| 1006 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1007 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1008 | return (0); |
| 1009 | } |
| 1010 | |
| 1011 | int |
| 1012 | add_del_route_check (fib_protocol_t table_proto, |
| 1013 | u32 table_id, |
| 1014 | u32 next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1015 | dpo_proto_t next_hop_table_proto, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1016 | u32 next_hop_table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1017 | u8 is_rpf_id, u32 * fib_index, u32 * next_hop_fib_index) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1018 | { |
| 1019 | vnet_main_t *vnm = vnet_get_main (); |
| 1020 | |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 1021 | /* Temporaray whilst I do the CSIT dance */ |
| 1022 | u8 create_missing_tables = 1; |
| 1023 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1024 | *fib_index = fib_table_find (table_proto, ntohl (table_id)); |
| 1025 | if (~0 == *fib_index) |
| 1026 | { |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 1027 | if (create_missing_tables) |
| 1028 | { |
| 1029 | *fib_index = fib_table_find_or_create_and_lock (table_proto, |
| 1030 | ntohl (table_id), |
| 1031 | FIB_SOURCE_API); |
| 1032 | } |
| 1033 | else |
| 1034 | { |
| 1035 | /* No such VRF, and we weren't asked to create one */ |
| 1036 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 1037 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1038 | } |
| 1039 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1040 | if (!is_rpf_id && ~0 != ntohl (next_hop_sw_if_index)) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1041 | { |
| 1042 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, |
| 1043 | ntohl (next_hop_sw_if_index))) |
| 1044 | { |
| 1045 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 1046 | } |
| 1047 | } |
| 1048 | else |
| 1049 | { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1050 | fib_protocol_t fib_nh_proto; |
| 1051 | |
| 1052 | if (next_hop_table_proto > DPO_PROTO_MPLS) |
| 1053 | return (0); |
| 1054 | |
| 1055 | fib_nh_proto = dpo_proto_to_fib (next_hop_table_proto); |
| 1056 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1057 | if (is_rpf_id) |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1058 | *next_hop_fib_index = mfib_table_find (fib_nh_proto, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1059 | ntohl (next_hop_table_id)); |
| 1060 | else |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1061 | *next_hop_fib_index = fib_table_find (fib_nh_proto, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1062 | ntohl (next_hop_table_id)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1063 | |
| 1064 | if (~0 == *next_hop_fib_index) |
| 1065 | { |
Florin Coras | d0a5972 | 2017-10-15 17:41:21 +0000 | [diff] [blame] | 1066 | if (create_missing_tables) |
| 1067 | { |
| 1068 | if (is_rpf_id) |
| 1069 | *next_hop_fib_index = |
| 1070 | mfib_table_find_or_create_and_lock (fib_nh_proto, |
| 1071 | ntohl |
| 1072 | (next_hop_table_id), |
| 1073 | MFIB_SOURCE_API); |
| 1074 | else |
| 1075 | *next_hop_fib_index = |
| 1076 | fib_table_find_or_create_and_lock (fib_nh_proto, |
| 1077 | ntohl |
| 1078 | (next_hop_table_id), |
| 1079 | FIB_SOURCE_API); |
| 1080 | } |
| 1081 | else |
| 1082 | { |
| 1083 | /* No such VRF, and we weren't asked to create one */ |
| 1084 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 1085 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | return (0); |
| 1090 | } |
| 1091 | |
| 1092 | static int |
| 1093 | ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1094 | { |
| 1095 | u32 fib_index, next_hop_fib_index; |
| 1096 | mpls_label_t *label_stack = NULL; |
| 1097 | int rv, ii, n_labels;; |
| 1098 | |
| 1099 | rv = add_del_route_check (FIB_PROTOCOL_IP4, |
| 1100 | mp->table_id, |
| 1101 | mp->next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1102 | DPO_PROTO_IP4, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1103 | mp->next_hop_table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1104 | 0, &fib_index, &next_hop_fib_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1105 | |
| 1106 | if (0 != rv) |
| 1107 | return (rv); |
| 1108 | |
| 1109 | fib_prefix_t pfx = { |
| 1110 | .fp_len = mp->dst_address_length, |
| 1111 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1112 | }; |
| 1113 | clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4)); |
| 1114 | |
| 1115 | ip46_address_t nh; |
| 1116 | memset (&nh, 0, sizeof (nh)); |
| 1117 | memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4)); |
| 1118 | |
| 1119 | n_labels = mp->next_hop_n_out_labels; |
| 1120 | if (n_labels == 0) |
| 1121 | ; |
| 1122 | else if (1 == n_labels) |
| 1123 | vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0])); |
| 1124 | else |
| 1125 | { |
| 1126 | vec_validate (label_stack, n_labels - 1); |
| 1127 | for (ii = 0; ii < n_labels; ii++) |
| 1128 | label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]); |
| 1129 | } |
| 1130 | |
| 1131 | return (add_del_route_t_handler (mp->is_multipath, |
| 1132 | mp->is_add, |
| 1133 | mp->is_drop, |
| 1134 | mp->is_unreach, |
| 1135 | mp->is_prohibit, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1136 | mp->is_local, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1137 | mp->is_classify, |
| 1138 | mp->classify_table_index, |
| 1139 | mp->is_resolve_host, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1140 | mp->is_resolve_attached, 0, 0, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 1141 | mp->is_l2_bridged, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 1142 | mp->is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1143 | mp->is_udp_encap, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1144 | fib_index, &pfx, DPO_PROTO_IP4, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1145 | &nh, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1146 | ntohl (mp->next_hop_id), |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1147 | ntohl (mp->next_hop_sw_if_index), |
| 1148 | next_hop_fib_index, |
| 1149 | mp->next_hop_weight, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1150 | mp->next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1151 | ntohl (mp->next_hop_via_label), |
| 1152 | label_stack)); |
| 1153 | } |
| 1154 | |
| 1155 | static int |
| 1156 | ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1157 | { |
| 1158 | u32 fib_index, next_hop_fib_index; |
| 1159 | mpls_label_t *label_stack = NULL; |
| 1160 | int rv, ii, n_labels;; |
| 1161 | |
| 1162 | rv = add_del_route_check (FIB_PROTOCOL_IP6, |
| 1163 | mp->table_id, |
| 1164 | mp->next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1165 | DPO_PROTO_IP6, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1166 | mp->next_hop_table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1167 | 0, &fib_index, &next_hop_fib_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1168 | |
| 1169 | if (0 != rv) |
| 1170 | return (rv); |
| 1171 | |
| 1172 | fib_prefix_t pfx = { |
| 1173 | .fp_len = mp->dst_address_length, |
| 1174 | .fp_proto = FIB_PROTOCOL_IP6, |
| 1175 | }; |
| 1176 | clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6)); |
| 1177 | |
| 1178 | ip46_address_t nh; |
| 1179 | memset (&nh, 0, sizeof (nh)); |
| 1180 | memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6)); |
| 1181 | |
| 1182 | n_labels = mp->next_hop_n_out_labels; |
| 1183 | if (n_labels == 0) |
| 1184 | ; |
| 1185 | else if (1 == n_labels) |
| 1186 | vec_add1 (label_stack, ntohl (mp->next_hop_out_label_stack[0])); |
| 1187 | else |
| 1188 | { |
| 1189 | vec_validate (label_stack, n_labels - 1); |
| 1190 | for (ii = 0; ii < n_labels; ii++) |
| 1191 | label_stack[ii] = ntohl (mp->next_hop_out_label_stack[ii]); |
| 1192 | } |
| 1193 | |
| 1194 | return (add_del_route_t_handler (mp->is_multipath, |
| 1195 | mp->is_add, |
| 1196 | mp->is_drop, |
| 1197 | mp->is_unreach, |
| 1198 | mp->is_prohibit, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1199 | mp->is_local, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1200 | mp->is_classify, |
| 1201 | mp->classify_table_index, |
| 1202 | mp->is_resolve_host, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1203 | mp->is_resolve_attached, 0, 0, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 1204 | mp->is_l2_bridged, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 1205 | mp->is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1206 | mp->is_udp_encap, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1207 | fib_index, &pfx, DPO_PROTO_IP6, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1208 | &nh, ntohl (mp->next_hop_id), |
| 1209 | ntohl (mp->next_hop_sw_if_index), |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1210 | next_hop_fib_index, |
| 1211 | mp->next_hop_weight, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1212 | mp->next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1213 | ntohl (mp->next_hop_via_label), |
| 1214 | label_stack)); |
| 1215 | } |
| 1216 | |
| 1217 | void |
| 1218 | vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1219 | { |
| 1220 | vl_api_ip_add_del_route_reply_t *rmp; |
| 1221 | int rv; |
| 1222 | vnet_main_t *vnm = vnet_get_main (); |
| 1223 | |
| 1224 | vnm->api_errno = 0; |
| 1225 | |
| 1226 | if (mp->is_ipv6) |
| 1227 | rv = ip6_add_del_route_t_handler (mp); |
| 1228 | else |
| 1229 | rv = ip4_add_del_route_t_handler (mp); |
| 1230 | |
| 1231 | rv = (rv == 0) ? vnm->api_errno : rv; |
| 1232 | |
| 1233 | REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY); |
| 1234 | } |
| 1235 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1236 | void |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1237 | ip_table_create (fib_protocol_t fproto, |
| 1238 | u32 table_id, u8 is_api, const u8 * name) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1239 | { |
| 1240 | u32 fib_index, mfib_index; |
| 1241 | |
| 1242 | /* |
| 1243 | * ignore action on the default table - this is always present |
| 1244 | * and cannot be added nor deleted from the API |
| 1245 | */ |
| 1246 | if (0 != table_id) |
| 1247 | { |
| 1248 | /* |
| 1249 | * The API holds only one lock on the table. |
| 1250 | * i.e. it can be added many times via the API but needs to be |
| 1251 | * deleted only once. |
| 1252 | * The FIB index for unicast and multicast is not necessarily the |
| 1253 | * same, since internal VPP systesm (like LISP and SR) create |
| 1254 | * their own unicast tables. |
| 1255 | */ |
| 1256 | fib_index = fib_table_find (fproto, table_id); |
| 1257 | mfib_index = mfib_table_find (fproto, table_id); |
| 1258 | |
| 1259 | if (~0 == fib_index) |
| 1260 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1261 | fib_table_find_or_create_and_lock_w_name (fproto, table_id, |
| 1262 | (is_api ? |
| 1263 | FIB_SOURCE_API : |
| 1264 | FIB_SOURCE_CLI), name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1265 | } |
| 1266 | if (~0 == mfib_index) |
| 1267 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1268 | mfib_table_find_or_create_and_lock_w_name (fproto, table_id, |
| 1269 | (is_api ? |
| 1270 | MFIB_SOURCE_API : |
| 1271 | MFIB_SOURCE_CLI), name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1276 | static int |
| 1277 | add_del_mroute_check (fib_protocol_t table_proto, |
| 1278 | u32 table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1279 | u32 next_hop_sw_if_index, u8 is_local, u32 * fib_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1280 | { |
| 1281 | vnet_main_t *vnm = vnet_get_main (); |
| 1282 | |
| 1283 | *fib_index = mfib_table_find (table_proto, ntohl (table_id)); |
| 1284 | if (~0 == *fib_index) |
| 1285 | { |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1286 | /* No such table */ |
| 1287 | return VNET_API_ERROR_NO_SUCH_FIB; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | if (~0 != ntohl (next_hop_sw_if_index)) |
| 1291 | { |
| 1292 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, |
| 1293 | ntohl (next_hop_sw_if_index))) |
| 1294 | { |
| 1295 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | return (0); |
| 1300 | } |
| 1301 | |
| 1302 | static int |
| 1303 | mroute_add_del_handler (u8 is_add, |
| 1304 | u8 is_local, |
| 1305 | u32 fib_index, |
| 1306 | const mfib_prefix_t * prefix, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1307 | dpo_proto_t nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1308 | u32 entry_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1309 | fib_rpf_id_t rpf_id, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1310 | u32 next_hop_sw_if_index, u32 itf_flags, u32 bier_imp) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1311 | { |
| 1312 | stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ ); |
| 1313 | |
| 1314 | fib_route_path_t path = { |
| 1315 | .frp_sw_if_index = next_hop_sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1316 | .frp_proto = nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1317 | }; |
| 1318 | |
| 1319 | if (is_local) |
| 1320 | path.frp_flags |= FIB_ROUTE_PATH_LOCAL; |
| 1321 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1322 | if (DPO_PROTO_BIER == nh_proto) |
| 1323 | { |
| 1324 | path.frp_bier_imp = bier_imp; |
| 1325 | path.frp_flags = FIB_ROUTE_PATH_BIER_IMP; |
| 1326 | } |
| 1327 | else if (!is_local && ~0 == next_hop_sw_if_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1328 | { |
| 1329 | mfib_table_entry_update (fib_index, prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1330 | MFIB_SOURCE_API, rpf_id, entry_flags); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1331 | goto done; |
| 1332 | } |
| 1333 | |
| 1334 | if (is_add) |
| 1335 | { |
| 1336 | mfib_table_entry_path_update (fib_index, prefix, |
| 1337 | MFIB_SOURCE_API, &path, itf_flags); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1338 | } |
| 1339 | else |
| 1340 | { |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1341 | mfib_table_entry_path_remove (fib_index, prefix, |
| 1342 | MFIB_SOURCE_API, &path); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1345 | done: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1346 | stats_dsunlock (); |
| 1347 | return (0); |
| 1348 | } |
| 1349 | |
| 1350 | static int |
| 1351 | api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 1352 | { |
| 1353 | fib_protocol_t fproto; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1354 | dpo_proto_t nh_proto; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1355 | u32 fib_index; |
| 1356 | int rv; |
| 1357 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1358 | nh_proto = mp->next_hop_afi; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1359 | fproto = (mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 1360 | rv = add_del_mroute_check (fproto, |
| 1361 | mp->table_id, |
| 1362 | mp->next_hop_sw_if_index, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1363 | mp->is_local, &fib_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1364 | |
| 1365 | if (0 != rv) |
| 1366 | return (rv); |
| 1367 | |
| 1368 | mfib_prefix_t pfx = { |
| 1369 | .fp_len = ntohs (mp->grp_address_length), |
| 1370 | .fp_proto = fproto, |
| 1371 | }; |
| 1372 | |
| 1373 | if (FIB_PROTOCOL_IP4 == fproto) |
| 1374 | { |
| 1375 | clib_memcpy (&pfx.fp_grp_addr.ip4, mp->grp_address, |
| 1376 | sizeof (pfx.fp_grp_addr.ip4)); |
| 1377 | clib_memcpy (&pfx.fp_src_addr.ip4, mp->src_address, |
| 1378 | sizeof (pfx.fp_src_addr.ip4)); |
| 1379 | } |
| 1380 | else |
| 1381 | { |
| 1382 | clib_memcpy (&pfx.fp_grp_addr.ip6, mp->grp_address, |
| 1383 | sizeof (pfx.fp_grp_addr.ip6)); |
| 1384 | clib_memcpy (&pfx.fp_src_addr.ip6, mp->src_address, |
| 1385 | sizeof (pfx.fp_src_addr.ip6)); |
| 1386 | } |
| 1387 | |
| 1388 | return (mroute_add_del_handler (mp->is_add, |
| 1389 | mp->is_local, |
| 1390 | fib_index, &pfx, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1391 | nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1392 | ntohl (mp->entry_flags), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1393 | ntohl (mp->rpf_id), |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1394 | ntohl (mp->next_hop_sw_if_index), |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1395 | ntohl (mp->itf_flags), |
| 1396 | ntohl (mp->bier_imp))); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | void |
| 1400 | vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 1401 | { |
| 1402 | vl_api_ip_mroute_add_del_reply_t *rmp; |
| 1403 | int rv; |
| 1404 | vnet_main_t *vnm = vnet_get_main (); |
| 1405 | |
| 1406 | vnm->api_errno = 0; |
| 1407 | |
| 1408 | rv = api_mroute_add_del_t_handler (mp); |
| 1409 | |
| 1410 | rv = (rv == 0) ? vnm->api_errno : rv; |
| 1411 | |
| 1412 | REPLY_MACRO (VL_API_IP_MROUTE_ADD_DEL_REPLY); |
| 1413 | } |
| 1414 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1415 | static void |
| 1416 | send_ip_details (vpe_api_main_t * am, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1417 | unix_shared_memory_queue_t * q, u32 sw_if_index, |
| 1418 | u8 is_ipv6, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1419 | { |
| 1420 | vl_api_ip_details_t *mp; |
| 1421 | |
| 1422 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1423 | memset (mp, 0, sizeof (*mp)); |
| 1424 | mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS); |
| 1425 | |
| 1426 | mp->sw_if_index = ntohl (sw_if_index); |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1427 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1428 | mp->context = context; |
| 1429 | |
| 1430 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1431 | } |
| 1432 | |
| 1433 | static void |
| 1434 | send_ip_address_details (vpe_api_main_t * am, |
| 1435 | unix_shared_memory_queue_t * q, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1436 | u8 * ip, u16 prefix_length, |
| 1437 | u32 sw_if_index, u8 is_ipv6, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1438 | { |
| 1439 | vl_api_ip_address_details_t *mp; |
| 1440 | |
| 1441 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1442 | memset (mp, 0, sizeof (*mp)); |
| 1443 | mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS); |
| 1444 | |
| 1445 | if (is_ipv6) |
| 1446 | { |
| 1447 | clib_memcpy (&mp->ip, ip, sizeof (mp->ip)); |
| 1448 | } |
| 1449 | else |
| 1450 | { |
| 1451 | u32 *tp = (u32 *) mp->ip; |
| 1452 | *tp = *(u32 *) ip; |
| 1453 | } |
| 1454 | mp->prefix_length = prefix_length; |
| 1455 | mp->context = context; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1456 | mp->sw_if_index = htonl (sw_if_index); |
| 1457 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1458 | |
| 1459 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1460 | } |
| 1461 | |
| 1462 | static void |
| 1463 | vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp) |
| 1464 | { |
| 1465 | vpe_api_main_t *am = &vpe_api_main; |
| 1466 | unix_shared_memory_queue_t *q; |
| 1467 | ip6_address_t *r6; |
| 1468 | ip4_address_t *r4; |
| 1469 | ip6_main_t *im6 = &ip6_main; |
| 1470 | ip4_main_t *im4 = &ip4_main; |
| 1471 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 1472 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 1473 | ip_interface_address_t *ia = 0; |
| 1474 | u32 sw_if_index = ~0; |
| 1475 | int rv __attribute__ ((unused)) = 0; |
| 1476 | |
| 1477 | VALIDATE_SW_IF_INDEX (mp); |
| 1478 | |
| 1479 | sw_if_index = ntohl (mp->sw_if_index); |
| 1480 | |
| 1481 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1482 | if (q == 0) |
| 1483 | return; |
| 1484 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1485 | if (mp->is_ipv6) |
| 1486 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1487 | /* *INDENT-OFF* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1488 | foreach_ip_interface_address (lm6, ia, sw_if_index, |
| 1489 | 1 /* honor unnumbered */, |
| 1490 | ({ |
| 1491 | r6 = ip_interface_address_get_address (lm6, ia); |
| 1492 | u16 prefix_length = ia->address_length; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1493 | send_ip_address_details(am, q, (u8*)r6, prefix_length, |
| 1494 | sw_if_index, 1, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1495 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1496 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1497 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1498 | else |
| 1499 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1500 | /* *INDENT-OFF* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1501 | foreach_ip_interface_address (lm4, ia, sw_if_index, |
| 1502 | 1 /* honor unnumbered */, |
| 1503 | ({ |
| 1504 | r4 = ip_interface_address_get_address (lm4, ia); |
| 1505 | u16 prefix_length = ia->address_length; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1506 | send_ip_address_details(am, q, (u8*)r4, prefix_length, |
| 1507 | sw_if_index, 0, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1508 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1509 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1510 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1511 | BAD_SW_IF_INDEX_LABEL; |
| 1512 | } |
| 1513 | |
| 1514 | static void |
| 1515 | vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp) |
| 1516 | { |
| 1517 | vpe_api_main_t *am = &vpe_api_main; |
| 1518 | vnet_main_t *vnm = vnet_get_main (); |
| 1519 | vlib_main_t *vm = vlib_get_main (); |
| 1520 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1521 | unix_shared_memory_queue_t *q; |
| 1522 | vnet_sw_interface_t *si, *sorted_sis; |
| 1523 | u32 sw_if_index = ~0; |
| 1524 | |
| 1525 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1526 | if (q == 0) |
| 1527 | { |
| 1528 | return; |
| 1529 | } |
| 1530 | |
| 1531 | /* Gather interfaces. */ |
| 1532 | sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
| 1533 | _vec_len (sorted_sis) = 0; |
| 1534 | /* *INDENT-OFF* */ |
| 1535 | pool_foreach (si, im->sw_interfaces, |
| 1536 | ({ |
| 1537 | vec_add1 (sorted_sis, si[0]); |
| 1538 | })); |
| 1539 | /* *INDENT-ON* */ |
| 1540 | |
| 1541 | vec_foreach (si, sorted_sis) |
| 1542 | { |
| 1543 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) |
| 1544 | { |
| 1545 | if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) |
| 1546 | { |
| 1547 | continue; |
| 1548 | } |
| 1549 | sw_if_index = si->sw_if_index; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1550 | 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] | 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | static void |
| 1556 | set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1557 | { |
| 1558 | vl_api_set_ip_flow_hash_reply_t *rmp; |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1559 | int rv; |
| 1560 | u32 table_id; |
| 1561 | flow_hash_config_t flow_hash_config = 0; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1562 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1563 | table_id = ntohl (mp->vrf_id); |
| 1564 | |
| 1565 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1566 | foreach_flow_hash_bit; |
| 1567 | #undef _ |
| 1568 | |
| 1569 | rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1570 | |
| 1571 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1572 | } |
| 1573 | |
| 1574 | static void |
| 1575 | set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1576 | { |
| 1577 | vl_api_set_ip_flow_hash_reply_t *rmp; |
| 1578 | int rv; |
| 1579 | u32 table_id; |
| 1580 | flow_hash_config_t flow_hash_config = 0; |
| 1581 | |
| 1582 | table_id = ntohl (mp->vrf_id); |
| 1583 | |
| 1584 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1585 | foreach_flow_hash_bit; |
| 1586 | #undef _ |
| 1587 | |
| 1588 | rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config); |
| 1589 | |
| 1590 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | static void |
| 1595 | vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp) |
| 1596 | { |
| 1597 | if (mp->is_ipv6 == 0) |
| 1598 | set_ip4_flow_hash (mp); |
| 1599 | else |
| 1600 | set_ip6_flow_hash (mp); |
| 1601 | } |
| 1602 | |
| 1603 | static void |
| 1604 | vl_api_sw_interface_ip6nd_ra_config_t_handler |
| 1605 | (vl_api_sw_interface_ip6nd_ra_config_t * mp) |
| 1606 | { |
| 1607 | vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp; |
| 1608 | vlib_main_t *vm = vlib_get_main (); |
| 1609 | int rv = 0; |
| 1610 | u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, |
| 1611 | default_router; |
| 1612 | |
| 1613 | is_no = mp->is_no == 1; |
| 1614 | suppress = mp->suppress == 1; |
| 1615 | managed = mp->managed == 1; |
| 1616 | other = mp->other == 1; |
| 1617 | ll_option = mp->ll_option == 1; |
| 1618 | send_unicast = mp->send_unicast == 1; |
| 1619 | cease = mp->cease == 1; |
| 1620 | default_router = mp->default_router == 1; |
| 1621 | |
| 1622 | VALIDATE_SW_IF_INDEX (mp); |
| 1623 | |
| 1624 | rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index), |
| 1625 | suppress, managed, other, |
| 1626 | ll_option, send_unicast, cease, |
| 1627 | default_router, ntohl (mp->lifetime), |
| 1628 | ntohl (mp->initial_count), |
| 1629 | ntohl (mp->initial_interval), |
| 1630 | ntohl (mp->max_interval), |
| 1631 | ntohl (mp->min_interval), is_no); |
| 1632 | |
| 1633 | BAD_SW_IF_INDEX_LABEL; |
| 1634 | |
| 1635 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY); |
| 1636 | } |
| 1637 | |
| 1638 | static void |
| 1639 | vl_api_sw_interface_ip6nd_ra_prefix_t_handler |
| 1640 | (vl_api_sw_interface_ip6nd_ra_prefix_t * mp) |
| 1641 | { |
| 1642 | vlib_main_t *vm = vlib_get_main (); |
| 1643 | vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp; |
| 1644 | int rv = 0; |
| 1645 | u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink; |
| 1646 | |
| 1647 | VALIDATE_SW_IF_INDEX (mp); |
| 1648 | |
| 1649 | is_no = mp->is_no == 1; |
| 1650 | use_default = mp->use_default == 1; |
| 1651 | no_advertise = mp->no_advertise == 1; |
| 1652 | off_link = mp->off_link == 1; |
| 1653 | no_autoconfig = mp->no_autoconfig == 1; |
| 1654 | no_onlink = mp->no_onlink == 1; |
| 1655 | |
| 1656 | rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index), |
| 1657 | (ip6_address_t *) mp->address, |
| 1658 | mp->address_length, use_default, |
| 1659 | ntohl (mp->val_lifetime), |
| 1660 | ntohl (mp->pref_lifetime), no_advertise, |
| 1661 | off_link, no_autoconfig, no_onlink, is_no); |
| 1662 | |
| 1663 | BAD_SW_IF_INDEX_LABEL; |
| 1664 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY); |
| 1665 | } |
| 1666 | |
| 1667 | static void |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1668 | send_ip6nd_proxy_details (unix_shared_memory_queue_t * q, |
| 1669 | u32 context, |
| 1670 | const ip46_address_t * addr, u32 sw_if_index) |
| 1671 | { |
| 1672 | vl_api_ip6nd_proxy_details_t *mp; |
| 1673 | |
| 1674 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1675 | memset (mp, 0, sizeof (*mp)); |
| 1676 | mp->_vl_msg_id = ntohs (VL_API_IP6ND_PROXY_DETAILS); |
| 1677 | mp->context = context; |
| 1678 | mp->sw_if_index = htonl (sw_if_index); |
| 1679 | memcpy (mp->address, addr, 16); |
| 1680 | |
| 1681 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1682 | } |
| 1683 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1684 | typedef struct api_ip6nd_proxy_fib_table_walk_ctx_t_ |
| 1685 | { |
| 1686 | u32 *indices; |
| 1687 | } api_ip6nd_proxy_fib_table_walk_ctx_t; |
| 1688 | |
| 1689 | static int |
| 1690 | api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg) |
| 1691 | { |
| 1692 | api_ip6nd_proxy_fib_table_walk_ctx_t *ctx = arg; |
| 1693 | |
| 1694 | if (fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND_PROXY)) |
| 1695 | { |
| 1696 | vec_add1 (ctx->indices, fei); |
| 1697 | } |
| 1698 | |
| 1699 | return (1); |
| 1700 | } |
| 1701 | |
| 1702 | static void |
| 1703 | vl_api_ip6nd_proxy_dump_t_handler (vl_api_ip6nd_proxy_dump_t * mp) |
| 1704 | { |
| 1705 | ip6_main_t *im6 = &ip6_main; |
| 1706 | fib_table_t *fib_table; |
| 1707 | api_ip6nd_proxy_fib_table_walk_ctx_t ctx = { |
| 1708 | .indices = NULL, |
| 1709 | }; |
| 1710 | fib_node_index_t *feip; |
| 1711 | fib_prefix_t pfx; |
| 1712 | unix_shared_memory_queue_t *q; |
| 1713 | |
| 1714 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1715 | if (q == 0) |
| 1716 | { |
| 1717 | return; |
| 1718 | } |
| 1719 | |
| 1720 | /* *INDENT-OFF* */ |
| 1721 | pool_foreach (fib_table, im6->fibs, |
| 1722 | ({ |
| 1723 | fib_table_walk(fib_table->ft_index, |
| 1724 | FIB_PROTOCOL_IP6, |
| 1725 | api_ip6nd_proxy_fib_table_walk, |
| 1726 | &ctx); |
| 1727 | })); |
| 1728 | /* *INDENT-ON* */ |
| 1729 | |
| 1730 | vec_sort_with_function (ctx.indices, fib_entry_cmp_for_sort); |
| 1731 | |
| 1732 | vec_foreach (feip, ctx.indices) |
| 1733 | { |
| 1734 | fib_entry_get_prefix (*feip, &pfx); |
| 1735 | |
| 1736 | send_ip6nd_proxy_details (q, |
| 1737 | mp->context, |
| 1738 | &pfx.fp_addr, |
| 1739 | fib_entry_get_resolving_interface (*feip)); |
| 1740 | } |
| 1741 | |
| 1742 | vec_free (ctx.indices); |
| 1743 | } |
| 1744 | |
| 1745 | static void |
| 1746 | vl_api_ip6nd_proxy_add_del_t_handler (vl_api_ip6nd_proxy_add_del_t * mp) |
| 1747 | { |
| 1748 | vl_api_ip6nd_proxy_add_del_reply_t *rmp; |
| 1749 | int rv = 0; |
| 1750 | |
| 1751 | VALIDATE_SW_IF_INDEX (mp); |
| 1752 | |
| 1753 | rv = ip6_neighbor_proxy_add_del (ntohl (mp->sw_if_index), |
| 1754 | (ip6_address_t *) mp->address, mp->is_del); |
| 1755 | |
| 1756 | BAD_SW_IF_INDEX_LABEL; |
| 1757 | REPLY_MACRO (VL_API_IP6ND_PROXY_ADD_DEL_REPLY); |
| 1758 | } |
| 1759 | |
| 1760 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1761 | vl_api_sw_interface_ip6_enable_disable_t_handler |
| 1762 | (vl_api_sw_interface_ip6_enable_disable_t * mp) |
| 1763 | { |
| 1764 | vlib_main_t *vm = vlib_get_main (); |
| 1765 | vl_api_sw_interface_ip6_enable_disable_reply_t *rmp; |
| 1766 | vnet_main_t *vnm = vnet_get_main (); |
| 1767 | int rv = 0; |
| 1768 | clib_error_t *error; |
| 1769 | |
| 1770 | vnm->api_errno = 0; |
| 1771 | |
| 1772 | VALIDATE_SW_IF_INDEX (mp); |
| 1773 | |
| 1774 | error = |
| 1775 | (mp->enable == 1) ? enable_ip6_interface (vm, |
| 1776 | ntohl (mp->sw_if_index)) : |
| 1777 | disable_ip6_interface (vm, ntohl (mp->sw_if_index)); |
| 1778 | |
| 1779 | if (error) |
| 1780 | { |
| 1781 | clib_error_report (error); |
| 1782 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1783 | } |
| 1784 | else |
| 1785 | { |
| 1786 | rv = vnm->api_errno; |
| 1787 | } |
| 1788 | |
| 1789 | BAD_SW_IF_INDEX_LABEL; |
| 1790 | |
| 1791 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY); |
| 1792 | } |
| 1793 | |
| 1794 | static void |
| 1795 | vl_api_sw_interface_ip6_set_link_local_address_t_handler |
| 1796 | (vl_api_sw_interface_ip6_set_link_local_address_t * mp) |
| 1797 | { |
| 1798 | vlib_main_t *vm = vlib_get_main (); |
| 1799 | vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp; |
| 1800 | int rv = 0; |
| 1801 | clib_error_t *error; |
| 1802 | vnet_main_t *vnm = vnet_get_main (); |
| 1803 | |
| 1804 | vnm->api_errno = 0; |
| 1805 | |
| 1806 | VALIDATE_SW_IF_INDEX (mp); |
| 1807 | |
| 1808 | error = set_ip6_link_local_address (vm, |
| 1809 | ntohl (mp->sw_if_index), |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 1810 | (ip6_address_t *) mp->address); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1811 | if (error) |
| 1812 | { |
| 1813 | clib_error_report (error); |
| 1814 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1815 | } |
| 1816 | else |
| 1817 | { |
| 1818 | rv = vnm->api_errno; |
| 1819 | } |
| 1820 | |
| 1821 | BAD_SW_IF_INDEX_LABEL; |
| 1822 | |
| 1823 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY); |
| 1824 | } |
| 1825 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1826 | void |
| 1827 | vl_mfib_signal_send_one (unix_shared_memory_queue_t * q, |
| 1828 | u32 context, const mfib_signal_t * mfs) |
| 1829 | { |
| 1830 | vl_api_mfib_signal_details_t *mp; |
| 1831 | mfib_prefix_t prefix; |
| 1832 | mfib_table_t *mfib; |
| 1833 | mfib_itf_t *mfi; |
| 1834 | |
| 1835 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1836 | |
| 1837 | memset (mp, 0, sizeof (*mp)); |
| 1838 | mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS); |
| 1839 | mp->context = context; |
| 1840 | |
| 1841 | mfi = mfib_itf_get (mfs->mfs_itf); |
| 1842 | mfib_entry_get_prefix (mfs->mfs_entry, &prefix); |
| 1843 | mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry), |
| 1844 | prefix.fp_proto); |
| 1845 | mp->table_id = ntohl (mfib->mft_table_id); |
| 1846 | mp->sw_if_index = ntohl (mfi->mfi_sw_if_index); |
| 1847 | |
| 1848 | if (FIB_PROTOCOL_IP4 == prefix.fp_proto) |
| 1849 | { |
| 1850 | mp->grp_address_len = ntohs (prefix.fp_len); |
| 1851 | |
| 1852 | memcpy (mp->grp_address, &prefix.fp_grp_addr.ip4, 4); |
| 1853 | if (prefix.fp_len > 32) |
| 1854 | { |
| 1855 | memcpy (mp->src_address, &prefix.fp_src_addr.ip4, 4); |
| 1856 | } |
| 1857 | } |
| 1858 | else |
| 1859 | { |
| 1860 | mp->grp_address_len = ntohs (prefix.fp_len); |
| 1861 | |
| 1862 | ASSERT (0); |
| 1863 | } |
| 1864 | |
| 1865 | if (0 != mfs->mfs_buffer_len) |
| 1866 | { |
| 1867 | mp->ip_packet_len = ntohs (mfs->mfs_buffer_len); |
| 1868 | |
| 1869 | memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len); |
| 1870 | } |
| 1871 | else |
| 1872 | { |
| 1873 | mp->ip_packet_len = 0; |
| 1874 | } |
| 1875 | |
| 1876 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 1877 | } |
| 1878 | |
| 1879 | static void |
| 1880 | vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp) |
| 1881 | { |
| 1882 | unix_shared_memory_queue_t *q; |
| 1883 | |
| 1884 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1885 | if (q == 0) |
| 1886 | { |
| 1887 | return; |
| 1888 | } |
| 1889 | |
| 1890 | while (q->cursize < q->maxsize && mfib_signal_send_one (q, mp->context)) |
| 1891 | ; |
| 1892 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1893 | |
Florin Coras | 595992c | 2017-11-06 17:17:08 -0800 | [diff] [blame] | 1894 | static void |
| 1895 | vl_api_ip_container_proxy_add_del_t_handler |
| 1896 | (vl_api_ip_container_proxy_add_del_t * mp) |
| 1897 | { |
| 1898 | vl_api_ip_container_proxy_add_del_reply_t *rmp; |
| 1899 | vnet_ip_container_proxy_args_t args; |
| 1900 | int rv = 0; |
| 1901 | clib_error_t *error; |
| 1902 | |
| 1903 | memset (&args, 0, sizeof (args)); |
| 1904 | ip_set (&args.prefix.fp_addr, mp->ip, mp->is_ip4); |
| 1905 | args.prefix.fp_len = mp->plen ? mp->plen : (mp->is_ip4 ? 32 : 128); |
| 1906 | args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index); |
| 1907 | args.is_add = mp->is_add; |
| 1908 | if ((error = vnet_ip_container_proxy_add_del (&args))) |
| 1909 | { |
| 1910 | rv = clib_error_get_code (error); |
| 1911 | clib_error_report (error); |
| 1912 | } |
| 1913 | |
| 1914 | REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY); |
| 1915 | } |
| 1916 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1917 | static void |
| 1918 | vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp) |
| 1919 | { |
| 1920 | int rv = 0; |
| 1921 | vl_api_ioam_enable_reply_t *rmp; |
| 1922 | clib_error_t *error; |
| 1923 | |
| 1924 | /* Ignoring the profile id as currently a single profile |
| 1925 | * is supported */ |
| 1926 | error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable, |
| 1927 | mp->seqno, mp->analyse); |
| 1928 | if (error) |
| 1929 | { |
| 1930 | clib_error_report (error); |
| 1931 | rv = clib_error_get_code (error); |
| 1932 | } |
| 1933 | |
| 1934 | REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY); |
| 1935 | } |
| 1936 | |
| 1937 | static void |
| 1938 | vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp) |
| 1939 | { |
| 1940 | int rv = 0; |
| 1941 | vl_api_ioam_disable_reply_t *rmp; |
| 1942 | clib_error_t *error; |
| 1943 | |
| 1944 | error = clear_ioam_rewrite_fn (); |
| 1945 | if (error) |
| 1946 | { |
| 1947 | clib_error_report (error); |
| 1948 | rv = clib_error_get_code (error); |
| 1949 | } |
| 1950 | |
| 1951 | REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY); |
| 1952 | } |
| 1953 | |
| 1954 | static void |
| 1955 | vl_api_ip_source_and_port_range_check_add_del_t_handler |
| 1956 | (vl_api_ip_source_and_port_range_check_add_del_t * mp) |
| 1957 | { |
| 1958 | vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp; |
| 1959 | int rv = 0; |
| 1960 | |
| 1961 | u8 is_ipv6 = mp->is_ipv6; |
| 1962 | u8 is_add = mp->is_add; |
| 1963 | u8 mask_length = mp->mask_length; |
| 1964 | ip4_address_t ip4_addr; |
| 1965 | ip6_address_t ip6_addr; |
| 1966 | u16 *low_ports = 0; |
| 1967 | u16 *high_ports = 0; |
| 1968 | u32 vrf_id; |
| 1969 | u16 tmp_low, tmp_high; |
| 1970 | u8 num_ranges; |
| 1971 | int i; |
| 1972 | |
| 1973 | // Validate port range |
| 1974 | num_ranges = mp->number_of_ranges; |
| 1975 | if (num_ranges > 32) |
| 1976 | { // This is size of array in VPE.API |
| 1977 | rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY; |
| 1978 | goto reply; |
| 1979 | } |
| 1980 | |
| 1981 | vec_reset_length (low_ports); |
| 1982 | vec_reset_length (high_ports); |
| 1983 | |
| 1984 | for (i = 0; i < num_ranges; i++) |
| 1985 | { |
| 1986 | tmp_low = mp->low_ports[i]; |
| 1987 | tmp_high = mp->high_ports[i]; |
| 1988 | // If tmp_low <= tmp_high then only need to check tmp_low = 0 |
| 1989 | // If tmp_low <= tmp_high then only need to check tmp_high > 65535 |
| 1990 | if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535) |
| 1991 | { |
| 1992 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1993 | goto reply; |
| 1994 | } |
| 1995 | vec_add1 (low_ports, tmp_low); |
| 1996 | vec_add1 (high_ports, tmp_high + 1); |
| 1997 | } |
| 1998 | |
| 1999 | // Validate mask_length |
| 2000 | if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32)) |
| 2001 | { |
| 2002 | rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH; |
| 2003 | goto reply; |
| 2004 | } |
| 2005 | |
| 2006 | vrf_id = ntohl (mp->vrf_id); |
| 2007 | |
| 2008 | if (vrf_id < 1) |
| 2009 | { |
| 2010 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 2011 | goto reply; |
| 2012 | } |
| 2013 | |
| 2014 | |
| 2015 | if (is_ipv6) |
| 2016 | { |
| 2017 | clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8)); |
| 2018 | rv = ip6_source_and_port_range_check_add_del (&ip6_addr, |
| 2019 | mask_length, |
| 2020 | vrf_id, |
| 2021 | low_ports, |
| 2022 | high_ports, is_add); |
| 2023 | } |
| 2024 | else |
| 2025 | { |
| 2026 | clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr)); |
| 2027 | rv = ip4_source_and_port_range_check_add_del (&ip4_addr, |
| 2028 | mask_length, |
| 2029 | vrf_id, |
| 2030 | low_ports, |
| 2031 | high_ports, is_add); |
| 2032 | } |
| 2033 | |
| 2034 | reply: |
| 2035 | vec_free (low_ports); |
| 2036 | vec_free (high_ports); |
| 2037 | REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY); |
| 2038 | } |
| 2039 | |
| 2040 | static void |
| 2041 | vl_api_ip_source_and_port_range_check_interface_add_del_t_handler |
| 2042 | (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp) |
| 2043 | { |
| 2044 | vlib_main_t *vm = vlib_get_main (); |
| 2045 | vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp; |
| 2046 | ip4_main_t *im = &ip4_main; |
| 2047 | int rv; |
| 2048 | u32 sw_if_index; |
| 2049 | u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; |
| 2050 | u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; |
| 2051 | uword *p = 0; |
| 2052 | int i; |
| 2053 | |
| 2054 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] = |
| 2055 | ntohl (mp->tcp_out_vrf_id); |
| 2056 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] = |
| 2057 | ntohl (mp->udp_out_vrf_id); |
| 2058 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] = |
| 2059 | ntohl (mp->tcp_in_vrf_id); |
| 2060 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] = |
| 2061 | ntohl (mp->udp_in_vrf_id); |
| 2062 | |
| 2063 | |
| 2064 | for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++) |
| 2065 | { |
| 2066 | if (vrf_id[i] != 0 && vrf_id[i] != ~0) |
| 2067 | { |
| 2068 | p = hash_get (im->fib_index_by_table_id, vrf_id[i]); |
| 2069 | |
| 2070 | if (p == 0) |
| 2071 | { |
| 2072 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 2073 | goto reply; |
| 2074 | } |
| 2075 | |
| 2076 | fib_index[i] = p[0]; |
| 2077 | } |
| 2078 | else |
| 2079 | fib_index[i] = ~0; |
| 2080 | } |
| 2081 | sw_if_index = ntohl (mp->sw_if_index); |
| 2082 | |
| 2083 | VALIDATE_SW_IF_INDEX (mp); |
| 2084 | |
| 2085 | rv = |
| 2086 | set_ip_source_and_port_range_check (vm, fib_index, sw_if_index, |
| 2087 | mp->is_add); |
| 2088 | |
| 2089 | BAD_SW_IF_INDEX_LABEL; |
| 2090 | reply: |
| 2091 | |
| 2092 | REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY); |
| 2093 | } |
| 2094 | |
| 2095 | #define IP4_ARP_EVENT 3 |
| 2096 | #define IP6_ND_EVENT 4 |
| 2097 | |
| 2098 | static int arp_change_delete_callback (u32 pool_index, u8 * notused); |
| 2099 | static int nd_change_delete_callback (u32 pool_index, u8 * notused); |
| 2100 | static vlib_node_registration_t ip_resolver_process_node; |
| 2101 | |
| 2102 | static void |
| 2103 | handle_ip4_arp_event (u32 pool_index) |
| 2104 | { |
| 2105 | vpe_api_main_t *vam = &vpe_api_main; |
| 2106 | vnet_main_t *vnm = vam->vnet_main; |
| 2107 | vlib_main_t *vm = vam->vlib_main; |
| 2108 | vl_api_ip4_arp_event_t *event; |
| 2109 | vl_api_ip4_arp_event_t *mp; |
| 2110 | unix_shared_memory_queue_t *q; |
| 2111 | |
| 2112 | /* Client can cancel, die, etc. */ |
| 2113 | if (pool_is_free_index (vam->arp_events, pool_index)) |
| 2114 | return; |
| 2115 | |
| 2116 | event = pool_elt_at_index (vam->arp_events, pool_index); |
| 2117 | |
| 2118 | q = vl_api_client_index_to_input_queue (event->client_index); |
| 2119 | if (!q) |
| 2120 | { |
| 2121 | (void) vnet_add_del_ip4_arp_change_event |
| 2122 | (vnm, arp_change_delete_callback, |
| 2123 | event->pid, &event->address, |
| 2124 | ip_resolver_process_node.index, IP4_ARP_EVENT, |
| 2125 | ~0 /* pool index, notused */ , 0 /* is_add */ ); |
| 2126 | return; |
| 2127 | } |
| 2128 | |
| 2129 | if (q->cursize < q->maxsize) |
| 2130 | { |
| 2131 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 2132 | clib_memcpy (mp, event, sizeof (*mp)); |
| 2133 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 2134 | } |
| 2135 | else |
| 2136 | { |
| 2137 | static f64 last_time; |
| 2138 | /* |
| 2139 | * Throttle syslog msgs. |
| 2140 | * It's pretty tempting to just revoke the registration... |
| 2141 | */ |
| 2142 | if (vlib_time_now (vm) > last_time + 10.0) |
| 2143 | { |
| 2144 | clib_warning ("arp event for %U to pid %d: queue stuffed!", |
| 2145 | format_ip4_address, &event->address, event->pid); |
| 2146 | last_time = vlib_time_now (vm); |
| 2147 | } |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | void |
| 2152 | handle_ip6_nd_event (u32 pool_index) |
| 2153 | { |
| 2154 | vpe_api_main_t *vam = &vpe_api_main; |
| 2155 | vnet_main_t *vnm = vam->vnet_main; |
| 2156 | vlib_main_t *vm = vam->vlib_main; |
| 2157 | vl_api_ip6_nd_event_t *event; |
| 2158 | vl_api_ip6_nd_event_t *mp; |
| 2159 | unix_shared_memory_queue_t *q; |
| 2160 | |
| 2161 | /* Client can cancel, die, etc. */ |
| 2162 | if (pool_is_free_index (vam->nd_events, pool_index)) |
| 2163 | return; |
| 2164 | |
| 2165 | event = pool_elt_at_index (vam->nd_events, pool_index); |
| 2166 | |
| 2167 | q = vl_api_client_index_to_input_queue (event->client_index); |
| 2168 | if (!q) |
| 2169 | { |
| 2170 | (void) vnet_add_del_ip6_nd_change_event |
| 2171 | (vnm, nd_change_delete_callback, |
| 2172 | event->pid, &event->address, |
| 2173 | ip_resolver_process_node.index, IP6_ND_EVENT, |
| 2174 | ~0 /* pool index, notused */ , 0 /* is_add */ ); |
| 2175 | return; |
| 2176 | } |
| 2177 | |
| 2178 | if (q->cursize < q->maxsize) |
| 2179 | { |
| 2180 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 2181 | clib_memcpy (mp, event, sizeof (*mp)); |
| 2182 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 2183 | } |
| 2184 | else |
| 2185 | { |
| 2186 | static f64 last_time; |
| 2187 | /* |
| 2188 | * Throttle syslog msgs. |
| 2189 | * It's pretty tempting to just revoke the registration... |
| 2190 | */ |
| 2191 | if (vlib_time_now (vm) > last_time + 10.0) |
| 2192 | { |
| 2193 | clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!", |
| 2194 | format_ip6_address, &event->address, event->pid); |
| 2195 | last_time = vlib_time_now (vm); |
| 2196 | } |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | static uword |
| 2201 | resolver_process (vlib_main_t * vm, |
| 2202 | vlib_node_runtime_t * rt, vlib_frame_t * f) |
| 2203 | { |
| 2204 | volatile f64 timeout = 100.0; |
| 2205 | volatile uword *event_data = 0; |
| 2206 | |
| 2207 | while (1) |
| 2208 | { |
| 2209 | vlib_process_wait_for_event_or_clock (vm, timeout); |
| 2210 | |
| 2211 | uword event_type = |
| 2212 | vlib_process_get_events (vm, (uword **) & event_data); |
| 2213 | |
| 2214 | int i; |
| 2215 | switch (event_type) |
| 2216 | { |
| 2217 | case IP4_ARP_EVENT: |
| 2218 | for (i = 0; i < vec_len (event_data); i++) |
| 2219 | handle_ip4_arp_event (event_data[i]); |
| 2220 | break; |
| 2221 | |
| 2222 | case IP6_ND_EVENT: |
| 2223 | for (i = 0; i < vec_len (event_data); i++) |
| 2224 | handle_ip6_nd_event (event_data[i]); |
| 2225 | break; |
| 2226 | |
| 2227 | case ~0: /* timeout */ |
| 2228 | break; |
| 2229 | } |
| 2230 | |
| 2231 | vec_reset_length (event_data); |
| 2232 | } |
| 2233 | return 0; /* or not */ |
| 2234 | } |
| 2235 | |
| 2236 | /* *INDENT-OFF* */ |
| 2237 | VLIB_REGISTER_NODE (ip_resolver_process_node,static) = { |
| 2238 | .function = resolver_process, |
| 2239 | .type = VLIB_NODE_TYPE_PROCESS, |
| 2240 | .name = "ip-route-resolver-process", |
| 2241 | }; |
| 2242 | /* *INDENT-ON* */ |
| 2243 | |
| 2244 | static int |
| 2245 | nd_change_data_callback (u32 pool_index, u8 * new_mac, |
| 2246 | u32 sw_if_index, ip6_address_t * address) |
| 2247 | { |
| 2248 | vpe_api_main_t *am = &vpe_api_main; |
| 2249 | vl_api_ip6_nd_event_t *event; |
| 2250 | |
| 2251 | if (pool_is_free_index (am->nd_events, pool_index)) |
| 2252 | return 1; |
| 2253 | |
| 2254 | event = pool_elt_at_index (am->nd_events, pool_index); |
| 2255 | if (eth_mac_equal (event->new_mac, new_mac) && |
| 2256 | sw_if_index == ntohl (event->sw_if_index)) |
| 2257 | { |
| 2258 | return 1; |
| 2259 | } |
| 2260 | |
| 2261 | clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac)); |
| 2262 | event->sw_if_index = htonl (sw_if_index); |
| 2263 | return 0; |
| 2264 | } |
| 2265 | |
| 2266 | static int |
| 2267 | arp_change_delete_callback (u32 pool_index, u8 * notused) |
| 2268 | { |
| 2269 | vpe_api_main_t *am = &vpe_api_main; |
| 2270 | |
| 2271 | if (pool_is_free_index (am->arp_events, pool_index)) |
| 2272 | return 1; |
| 2273 | |
| 2274 | pool_put_index (am->arp_events, pool_index); |
| 2275 | return 0; |
| 2276 | } |
| 2277 | |
| 2278 | static int |
| 2279 | nd_change_delete_callback (u32 pool_index, u8 * notused) |
| 2280 | { |
| 2281 | vpe_api_main_t *am = &vpe_api_main; |
| 2282 | |
| 2283 | if (pool_is_free_index (am->nd_events, pool_index)) |
| 2284 | return 1; |
| 2285 | |
| 2286 | pool_put_index (am->nd_events, pool_index); |
| 2287 | return 0; |
| 2288 | } |
| 2289 | |
| 2290 | static vlib_node_registration_t wc_arp_process_node; |
| 2291 | |
| 2292 | enum |
| 2293 | { WC_ARP_REPORT, WC_ND_REPORT }; |
| 2294 | |
| 2295 | static uword |
| 2296 | wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) |
| 2297 | { |
| 2298 | /* These cross the longjmp boundry (vlib_process_wait_for_event) |
| 2299 | * and need to be volatile - to prevent them from being optimized into |
| 2300 | * a register - which could change during suspension */ |
| 2301 | |
| 2302 | volatile wc_arp_report_t arp_prev = { 0 }; |
| 2303 | volatile wc_nd_report_t nd_prev = { 0 }; |
| 2304 | volatile f64 last_arp = vlib_time_now (vm); |
| 2305 | volatile f64 last_nd = vlib_time_now (vm); |
| 2306 | |
| 2307 | while (1) |
| 2308 | { |
| 2309 | vlib_process_wait_for_event (vm); |
| 2310 | uword event_type = WC_ARP_REPORT; |
| 2311 | void *event_data = vlib_process_get_event_data (vm, &event_type); |
| 2312 | |
| 2313 | f64 now = vlib_time_now (vm); |
| 2314 | int i; |
| 2315 | if (event_type == WC_ARP_REPORT) |
| 2316 | { |
| 2317 | wc_arp_report_t *arp_events = event_data; |
| 2318 | for (i = 0; i < vec_len (arp_events); i++) |
| 2319 | { |
| 2320 | /* discard dup event */ |
| 2321 | if (arp_prev.ip4 == arp_events[i].ip4 && |
| 2322 | eth_mac_equal ((u8 *) arp_prev.mac, arp_events[i].mac) && |
| 2323 | arp_prev.sw_if_index == arp_events[i].sw_if_index && |
| 2324 | (now - last_arp) < 10.0) |
| 2325 | { |
| 2326 | continue; |
| 2327 | } |
| 2328 | arp_prev = arp_events[i]; |
| 2329 | last_arp = now; |
| 2330 | vpe_client_registration_t *reg; |
| 2331 | /* *INDENT-OFF* */ |
| 2332 | pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations, |
| 2333 | ({ |
| 2334 | unix_shared_memory_queue_t *q; |
| 2335 | q = vl_api_client_index_to_input_queue (reg->client_index); |
| 2336 | if (q && q->cursize < q->maxsize) |
| 2337 | { |
| 2338 | vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event); |
| 2339 | memset (event, 0, sizeof *event); |
| 2340 | event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT); |
| 2341 | event->client_index = reg->client_index; |
| 2342 | event->pid = reg->client_pid; |
| 2343 | event->mac_ip = 1; |
| 2344 | event->address = arp_events[i].ip4; |
| 2345 | event->sw_if_index = htonl(arp_events[i].sw_if_index); |
| 2346 | memcpy(event->new_mac, arp_events[i].mac, sizeof event->new_mac); |
| 2347 | vl_msg_api_send_shmem (q, (u8 *) &event); |
| 2348 | } |
| 2349 | })); |
| 2350 | /* *INDENT-ON* */ |
| 2351 | } |
| 2352 | } |
| 2353 | else if (event_type == WC_ND_REPORT) |
| 2354 | { |
| 2355 | wc_nd_report_t *nd_events = event_data; |
| 2356 | for (i = 0; i < vec_len (nd_events); i++) |
| 2357 | { |
| 2358 | /* discard dup event */ |
| 2359 | if (ip6_address_is_equal |
| 2360 | ((ip6_address_t *) & nd_prev.ip6, &nd_events[i].ip6) |
| 2361 | && eth_mac_equal ((u8 *) nd_prev.mac, nd_events[i].mac) |
| 2362 | && nd_prev.sw_if_index == nd_events[i].sw_if_index |
| 2363 | && (now - last_nd) < 10.0) |
| 2364 | { |
| 2365 | continue; |
| 2366 | } |
| 2367 | nd_prev = nd_events[i]; |
| 2368 | last_nd = now; |
| 2369 | vpe_client_registration_t *reg; |
| 2370 | /* *INDENT-OFF* */ |
| 2371 | pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations, |
| 2372 | ({ |
| 2373 | unix_shared_memory_queue_t *q; |
| 2374 | q = vl_api_client_index_to_input_queue (reg->client_index); |
| 2375 | if (q && q->cursize < q->maxsize) |
| 2376 | { |
| 2377 | vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event); |
| 2378 | memset (event, 0, sizeof *event); |
| 2379 | event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT); |
| 2380 | event->client_index = reg->client_index; |
| 2381 | event->pid = reg->client_pid; |
| 2382 | event->mac_ip = 1; |
| 2383 | memcpy(event->address, nd_events[i].ip6.as_u8, sizeof event->address); |
| 2384 | event->sw_if_index = htonl(nd_events[i].sw_if_index); |
| 2385 | memcpy(event->new_mac, nd_events[i].mac, sizeof event->new_mac); |
| 2386 | vl_msg_api_send_shmem (q, (u8 *) &event); |
| 2387 | } |
| 2388 | })); |
| 2389 | /* *INDENT-ON* */ |
| 2390 | } |
| 2391 | } |
| 2392 | vlib_process_put_event_data (vm, event_data); |
| 2393 | } |
| 2394 | |
| 2395 | return 0; |
| 2396 | } |
| 2397 | |
| 2398 | /* *INDENT-OFF* */ |
| 2399 | VLIB_REGISTER_NODE (wc_arp_process_node,static) = { |
| 2400 | .function = wc_arp_process, |
| 2401 | .type = VLIB_NODE_TYPE_PROCESS, |
| 2402 | .name = "wildcard-ip4-arp-publisher-process", |
| 2403 | }; |
| 2404 | /* *INDENT-ON* */ |
| 2405 | |
| 2406 | static int |
| 2407 | arp_change_data_callback (u32 pool_index, u8 * new_mac, |
| 2408 | u32 sw_if_index, u32 address) |
| 2409 | { |
| 2410 | vpe_api_main_t *am = &vpe_api_main; |
| 2411 | vl_api_ip4_arp_event_t *event; |
| 2412 | |
| 2413 | if (pool_is_free_index (am->arp_events, pool_index)) |
| 2414 | return 1; |
| 2415 | |
| 2416 | event = pool_elt_at_index (am->arp_events, pool_index); |
| 2417 | if (eth_mac_equal (event->new_mac, new_mac) && |
| 2418 | sw_if_index == ntohl (event->sw_if_index)) |
| 2419 | { |
| 2420 | return 1; |
| 2421 | } |
| 2422 | |
| 2423 | clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac)); |
| 2424 | event->sw_if_index = htonl (sw_if_index); |
| 2425 | return 0; |
| 2426 | } |
| 2427 | |
| 2428 | static void |
| 2429 | vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp) |
| 2430 | { |
| 2431 | vpe_api_main_t *am = &vpe_api_main; |
| 2432 | vnet_main_t *vnm = vnet_get_main (); |
| 2433 | vl_api_want_ip4_arp_events_reply_t *rmp; |
| 2434 | int rv = 0; |
| 2435 | |
| 2436 | if (mp->address == 0) |
| 2437 | { |
| 2438 | uword *p = |
| 2439 | hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index); |
| 2440 | vpe_client_registration_t *rp; |
| 2441 | if (p) |
| 2442 | { |
| 2443 | if (mp->enable_disable) |
| 2444 | { |
| 2445 | clib_warning ("pid %d: already enabled...", mp->pid); |
| 2446 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2447 | goto reply; |
| 2448 | } |
| 2449 | else |
| 2450 | { |
| 2451 | rp = |
| 2452 | pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]); |
| 2453 | pool_put (am->wc_ip4_arp_events_registrations, rp); |
| 2454 | hash_unset (am->wc_ip4_arp_events_registration_hash, |
| 2455 | mp->client_index); |
| 2456 | if (pool_elts (am->wc_ip4_arp_events_registrations) == 0) |
| 2457 | wc_arp_set_publisher_node (~0, WC_ARP_REPORT); |
| 2458 | goto reply; |
| 2459 | } |
| 2460 | } |
| 2461 | if (mp->enable_disable == 0) |
| 2462 | { |
| 2463 | clib_warning ("pid %d: already disabled...", mp->pid); |
| 2464 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2465 | goto reply; |
| 2466 | } |
| 2467 | pool_get (am->wc_ip4_arp_events_registrations, rp); |
| 2468 | rp->client_index = mp->client_index; |
| 2469 | rp->client_pid = mp->pid; |
| 2470 | hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index, |
| 2471 | rp - am->wc_ip4_arp_events_registrations); |
| 2472 | wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT); |
| 2473 | goto reply; |
| 2474 | } |
| 2475 | |
| 2476 | if (mp->enable_disable) |
| 2477 | { |
| 2478 | vl_api_ip4_arp_event_t *event; |
| 2479 | pool_get (am->arp_events, event); |
| 2480 | rv = vnet_add_del_ip4_arp_change_event |
| 2481 | (vnm, arp_change_data_callback, |
| 2482 | mp->pid, &mp->address /* addr, in net byte order */ , |
| 2483 | ip_resolver_process_node.index, |
| 2484 | IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ ); |
| 2485 | |
| 2486 | if (rv) |
| 2487 | { |
| 2488 | pool_put (am->arp_events, event); |
| 2489 | goto reply; |
| 2490 | } |
| 2491 | memset (event, 0, sizeof (*event)); |
| 2492 | |
| 2493 | /* Python API expects events to have no context */ |
| 2494 | event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT); |
| 2495 | event->client_index = mp->client_index; |
| 2496 | event->address = mp->address; |
| 2497 | event->pid = mp->pid; |
| 2498 | if (mp->address == 0) |
| 2499 | event->mac_ip = 1; |
| 2500 | } |
| 2501 | else |
| 2502 | { |
| 2503 | rv = vnet_add_del_ip4_arp_change_event |
| 2504 | (vnm, arp_change_delete_callback, |
| 2505 | mp->pid, &mp->address /* addr, in net byte order */ , |
| 2506 | ip_resolver_process_node.index, |
| 2507 | IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ ); |
| 2508 | } |
| 2509 | reply: |
| 2510 | REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY); |
| 2511 | } |
| 2512 | |
| 2513 | static void |
| 2514 | vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp) |
| 2515 | { |
| 2516 | vpe_api_main_t *am = &vpe_api_main; |
| 2517 | vnet_main_t *vnm = vnet_get_main (); |
| 2518 | vl_api_want_ip6_nd_events_reply_t *rmp; |
| 2519 | int rv = 0; |
| 2520 | |
| 2521 | if (ip6_address_is_zero ((ip6_address_t *) mp->address)) |
| 2522 | { |
| 2523 | uword *p = |
| 2524 | hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index); |
| 2525 | vpe_client_registration_t *rp; |
| 2526 | if (p) |
| 2527 | { |
| 2528 | if (mp->enable_disable) |
| 2529 | { |
| 2530 | clib_warning ("pid %d: already enabled...", mp->pid); |
| 2531 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2532 | goto reply; |
| 2533 | } |
| 2534 | else |
| 2535 | { |
| 2536 | rp = |
| 2537 | pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]); |
| 2538 | pool_put (am->wc_ip6_nd_events_registrations, rp); |
| 2539 | hash_unset (am->wc_ip6_nd_events_registration_hash, |
| 2540 | mp->client_index); |
| 2541 | if (pool_elts (am->wc_ip6_nd_events_registrations) == 0) |
| 2542 | wc_nd_set_publisher_node (~0, 2); |
| 2543 | goto reply; |
| 2544 | } |
| 2545 | } |
| 2546 | if (mp->enable_disable == 0) |
| 2547 | { |
| 2548 | clib_warning ("pid %d: already disabled...", mp->pid); |
| 2549 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2550 | goto reply; |
| 2551 | } |
| 2552 | pool_get (am->wc_ip6_nd_events_registrations, rp); |
| 2553 | rp->client_index = mp->client_index; |
| 2554 | rp->client_pid = mp->pid; |
| 2555 | hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index, |
| 2556 | rp - am->wc_ip6_nd_events_registrations); |
| 2557 | wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT); |
| 2558 | goto reply; |
| 2559 | } |
| 2560 | |
| 2561 | if (mp->enable_disable) |
| 2562 | { |
| 2563 | vl_api_ip6_nd_event_t *event; |
| 2564 | pool_get (am->nd_events, event); |
| 2565 | |
| 2566 | rv = vnet_add_del_ip6_nd_change_event |
| 2567 | (vnm, nd_change_data_callback, |
| 2568 | mp->pid, mp->address /* addr, in net byte order */ , |
| 2569 | ip_resolver_process_node.index, |
| 2570 | IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ ); |
| 2571 | |
| 2572 | if (rv) |
| 2573 | { |
| 2574 | pool_put (am->nd_events, event); |
| 2575 | goto reply; |
| 2576 | } |
| 2577 | memset (event, 0, sizeof (*event)); |
| 2578 | |
| 2579 | event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT); |
| 2580 | event->client_index = mp->client_index; |
| 2581 | clib_memcpy (event->address, mp->address, sizeof event->address); |
| 2582 | event->pid = mp->pid; |
| 2583 | } |
| 2584 | else |
| 2585 | { |
| 2586 | rv = vnet_add_del_ip6_nd_change_event |
| 2587 | (vnm, nd_change_delete_callback, |
| 2588 | mp->pid, mp->address /* addr, in net byte order */ , |
| 2589 | ip_resolver_process_node.index, |
| 2590 | IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ ); |
| 2591 | } |
| 2592 | reply: |
| 2593 | REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY); |
| 2594 | } |
| 2595 | |
| 2596 | static void |
| 2597 | vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp) |
| 2598 | { |
| 2599 | vl_api_proxy_arp_add_del_reply_t *rmp; |
| 2600 | u32 fib_index; |
| 2601 | int rv; |
| 2602 | ip4_main_t *im = &ip4_main; |
| 2603 | stats_main_t *sm = &stats_main; |
| 2604 | int vnet_proxy_arp_add_del (ip4_address_t * lo_addr, |
| 2605 | ip4_address_t * hi_addr, |
| 2606 | u32 fib_index, int is_del); |
| 2607 | uword *p; |
| 2608 | |
| 2609 | dslock (sm, 1 /* release hint */ , 6 /* tag */ ); |
| 2610 | |
| 2611 | p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id)); |
| 2612 | |
| 2613 | if (!p) |
| 2614 | { |
| 2615 | rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2616 | goto out; |
| 2617 | } |
| 2618 | |
| 2619 | fib_index = p[0]; |
| 2620 | |
| 2621 | rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address, |
| 2622 | (ip4_address_t *) mp->hi_address, |
| 2623 | fib_index, mp->is_add == 0); |
| 2624 | |
| 2625 | out: |
| 2626 | dsunlock (sm); |
| 2627 | REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY); |
| 2628 | } |
| 2629 | |
| 2630 | static void |
| 2631 | vl_api_proxy_arp_intfc_enable_disable_t_handler |
| 2632 | (vl_api_proxy_arp_intfc_enable_disable_t * mp) |
| 2633 | { |
| 2634 | int rv = 0; |
| 2635 | vnet_main_t *vnm = vnet_get_main (); |
| 2636 | vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp; |
| 2637 | |
| 2638 | VALIDATE_SW_IF_INDEX (mp); |
| 2639 | |
| 2640 | vnet_sw_interface_t *si = |
| 2641 | vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index)); |
| 2642 | |
| 2643 | ASSERT (si); |
| 2644 | |
| 2645 | if (mp->enable_disable) |
| 2646 | si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP; |
| 2647 | else |
| 2648 | si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP; |
| 2649 | |
| 2650 | BAD_SW_IF_INDEX_LABEL; |
| 2651 | |
| 2652 | REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY); |
| 2653 | } |
| 2654 | |
| 2655 | static int |
| 2656 | ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2657 | { |
| 2658 | vnet_main_t *vnm = vnet_get_main (); |
| 2659 | vnet_interface_main_t *im = &vnm->interface_main; |
| 2660 | ip4_main_t *im4 = &ip4_main; |
| 2661 | static u32 *sw_if_indices_to_shut; |
| 2662 | stats_main_t *sm = &stats_main; |
| 2663 | fib_table_t *fib_table; |
| 2664 | ip4_fib_t *fib; |
| 2665 | u32 sw_if_index; |
| 2666 | int i; |
| 2667 | int rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2668 | u32 target_fib_id = ntohl (mp->vrf_id); |
| 2669 | |
| 2670 | dslock (sm, 1 /* release hint */ , 8 /* tag */ ); |
| 2671 | |
| 2672 | /* *INDENT-OFF* */ |
| 2673 | pool_foreach (fib_table, im4->fibs, |
| 2674 | ({ |
| 2675 | vnet_sw_interface_t * si; |
| 2676 | |
| 2677 | fib = pool_elt_at_index (im4->v4_fibs, fib_table->ft_index); |
| 2678 | |
| 2679 | if (fib->table_id != target_fib_id) |
| 2680 | continue; |
| 2681 | |
| 2682 | /* remove any mpls encap/decap labels */ |
| 2683 | mpls_fib_reset_labels (fib->table_id); |
| 2684 | |
| 2685 | /* remove any proxy arps in this fib */ |
| 2686 | vnet_proxy_arp_fib_reset (fib->table_id); |
| 2687 | |
| 2688 | /* Set the flow hash for this fib to the default */ |
| 2689 | vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT); |
| 2690 | |
| 2691 | vec_reset_length (sw_if_indices_to_shut); |
| 2692 | |
| 2693 | /* Shut down interfaces in this FIB / clean out intfc routes */ |
| 2694 | pool_foreach (si, im->sw_interfaces, |
| 2695 | ({ |
| 2696 | u32 sw_if_index = si->sw_if_index; |
| 2697 | |
| 2698 | if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index) |
| 2699 | && (im4->fib_index_by_sw_if_index[si->sw_if_index] == |
| 2700 | fib->index)) |
| 2701 | vec_add1 (sw_if_indices_to_shut, si->sw_if_index); |
| 2702 | })); |
| 2703 | |
| 2704 | for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) { |
| 2705 | sw_if_index = sw_if_indices_to_shut[i]; |
| 2706 | |
| 2707 | u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index); |
| 2708 | flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 2709 | vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 2710 | } |
| 2711 | |
| 2712 | fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API); |
| 2713 | |
| 2714 | rv = 0; |
| 2715 | break; |
| 2716 | })); /* pool_foreach (fib) */ |
| 2717 | /* *INDENT-ON* */ |
| 2718 | |
| 2719 | dsunlock (sm); |
| 2720 | return rv; |
| 2721 | } |
| 2722 | |
| 2723 | static int |
| 2724 | ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2725 | { |
| 2726 | vnet_main_t *vnm = vnet_get_main (); |
| 2727 | vnet_interface_main_t *im = &vnm->interface_main; |
| 2728 | ip6_main_t *im6 = &ip6_main; |
| 2729 | stats_main_t *sm = &stats_main; |
| 2730 | static u32 *sw_if_indices_to_shut; |
| 2731 | fib_table_t *fib_table; |
| 2732 | ip6_fib_t *fib; |
| 2733 | u32 sw_if_index; |
| 2734 | int i; |
| 2735 | int rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2736 | u32 target_fib_id = ntohl (mp->vrf_id); |
| 2737 | |
| 2738 | dslock (sm, 1 /* release hint */ , 9 /* tag */ ); |
| 2739 | |
| 2740 | /* *INDENT-OFF* */ |
| 2741 | pool_foreach (fib_table, im6->fibs, |
| 2742 | ({ |
| 2743 | vnet_sw_interface_t * si; |
| 2744 | |
| 2745 | fib = pool_elt_at_index (im6->v6_fibs, fib_table->ft_index); |
| 2746 | |
| 2747 | if (fib->table_id != target_fib_id) |
| 2748 | continue; |
| 2749 | |
| 2750 | vec_reset_length (sw_if_indices_to_shut); |
| 2751 | |
| 2752 | /* Set the flow hash for this fib to the default */ |
| 2753 | vnet_set_ip6_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT); |
| 2754 | |
| 2755 | /* Shut down interfaces in this FIB / clean out intfc routes */ |
| 2756 | pool_foreach (si, im->sw_interfaces, |
| 2757 | ({ |
| 2758 | if (im6->fib_index_by_sw_if_index[si->sw_if_index] == |
| 2759 | fib->index) |
| 2760 | vec_add1 (sw_if_indices_to_shut, si->sw_if_index); |
| 2761 | })); |
| 2762 | |
| 2763 | for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) { |
| 2764 | sw_if_index = sw_if_indices_to_shut[i]; |
| 2765 | |
| 2766 | u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index); |
| 2767 | flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 2768 | vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 2769 | } |
| 2770 | |
| 2771 | fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API); |
| 2772 | |
| 2773 | rv = 0; |
| 2774 | break; |
| 2775 | })); /* pool_foreach (fib) */ |
| 2776 | /* *INDENT-ON* */ |
| 2777 | |
| 2778 | dsunlock (sm); |
| 2779 | return rv; |
| 2780 | } |
| 2781 | |
| 2782 | static void |
| 2783 | vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2784 | { |
| 2785 | int rv; |
| 2786 | vl_api_reset_fib_reply_t *rmp; |
| 2787 | |
| 2788 | if (mp->is_ipv6) |
| 2789 | rv = ip6_reset_fib_t_handler (mp); |
| 2790 | else |
| 2791 | rv = ip4_reset_fib_t_handler (mp); |
| 2792 | |
| 2793 | REPLY_MACRO (VL_API_RESET_FIB_REPLY); |
| 2794 | } |
| 2795 | |
| 2796 | static void |
| 2797 | vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp) |
| 2798 | { |
| 2799 | int rv; |
| 2800 | vl_api_set_arp_neighbor_limit_reply_t *rmp; |
| 2801 | vnet_main_t *vnm = vnet_get_main (); |
| 2802 | clib_error_t *error; |
| 2803 | |
| 2804 | vnm->api_errno = 0; |
| 2805 | |
| 2806 | if (mp->is_ipv6) |
| 2807 | error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit)); |
| 2808 | else |
| 2809 | error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit)); |
| 2810 | |
| 2811 | if (error) |
| 2812 | { |
| 2813 | clib_error_report (error); |
| 2814 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 2815 | } |
| 2816 | else |
| 2817 | { |
| 2818 | rv = vnm->api_errno; |
| 2819 | } |
| 2820 | |
| 2821 | REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY); |
| 2822 | } |
| 2823 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 2824 | #define vl_msg_name_crc_list |
| 2825 | #include <vnet/ip/ip.api.h> |
| 2826 | #undef vl_msg_name_crc_list |
| 2827 | |
| 2828 | static void |
| 2829 | setup_message_id_table (api_main_t * am) |
| 2830 | { |
| 2831 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 2832 | foreach_vl_msg_name_crc_ip; |
| 2833 | #undef _ |
| 2834 | } |
| 2835 | |
| 2836 | static clib_error_t * |
| 2837 | ip_api_hookup (vlib_main_t * vm) |
| 2838 | { |
| 2839 | api_main_t *am = &api_main; |
| 2840 | |
| 2841 | #define _(N,n) \ |
| 2842 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 2843 | vl_api_##n##_t_handler, \ |
| 2844 | vl_noop_handler, \ |
| 2845 | vl_api_##n##_t_endian, \ |
| 2846 | vl_api_##n##_t_print, \ |
| 2847 | sizeof(vl_api_##n##_t), 1); |
| 2848 | foreach_ip_api_msg; |
| 2849 | #undef _ |
| 2850 | |
| 2851 | /* |
| 2852 | * Set up the (msg_name, crc, message-id) table |
| 2853 | */ |
| 2854 | setup_message_id_table (am); |
| 2855 | |
| 2856 | return 0; |
| 2857 | } |
| 2858 | |
| 2859 | VLIB_API_INIT_FUNCTION (ip_api_hookup); |
| 2860 | |
| 2861 | /* |
| 2862 | * fd.io coding-style-patch-verification: ON |
| 2863 | * |
| 2864 | * Local Variables: |
| 2865 | * eval: (c-set-style "gnu") |
| 2866 | * End: |
| 2867 | */ |