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