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