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