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