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