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