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