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