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