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