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> |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 28 | #include <vnet/ip/ip_types_api.h> |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 29 | #include <vnet/ip/ip_punt_drop.h> |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 30 | #include <vnet/ip/ip_types_api.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 31 | #include <vnet/fib/fib_table.h> |
| 32 | #include <vnet/fib/fib_api.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 33 | #include <vnet/ethernet/arp_packet.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 34 | #include <vnet/mfib/ip6_mfib.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 35 | #include <vnet/mfib/ip4_mfib.h> |
| 36 | #include <vnet/mfib/mfib_signal.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 37 | #include <vnet/mfib/mfib_entry.h> |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 38 | #include <vnet/mfib/mfib_api.h> |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 39 | #include <vnet/ip/ip_source_and_port_range_check.h> |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 40 | #include <vnet/fib/fib_path_list.h> |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 41 | #include <vnet/ip/ip6_hop_by_hop.h> |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 42 | #include <vnet/ip/ip6_link.h> |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 43 | #include <vnet/ip/reass/ip4_sv_reass.h> |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 44 | #include <vnet/ip/reass/ip4_full_reass.h> |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 45 | #include <vnet/ip/reass/ip6_sv_reass.h> |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 46 | #include <vnet/ip/reass/ip6_full_reass.h> |
Steven Luong | c3ed1c9 | 2020-07-27 10:06:58 -0700 | [diff] [blame] | 47 | #include <vnet/ip/ip_table.h> |
Neale Ranns | e403113 | 2020-10-26 13:00:06 +0000 | [diff] [blame] | 48 | #include <vnet/ip/ip_container_proxy.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 49 | |
| 50 | #include <vnet/vnet_msg_enum.h> |
| 51 | |
| 52 | #define vl_typedefs /* define message structures */ |
| 53 | #include <vnet/vnet_all_api_h.h> |
| 54 | #undef vl_typedefs |
| 55 | |
| 56 | #define vl_endianfun /* define message structures */ |
| 57 | #include <vnet/vnet_all_api_h.h> |
| 58 | #undef vl_endianfun |
| 59 | |
| 60 | /* instantiate all the print functions we know about */ |
| 61 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 62 | #define vl_printfun |
| 63 | #include <vnet/vnet_all_api_h.h> |
| 64 | #undef vl_printfun |
| 65 | |
| 66 | #include <vlibapi/api_helper_macros.h> |
| 67 | |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 68 | #include <vnet/format_fns.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 69 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 70 | #define foreach_ip_api_msg \ |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 71 | _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable) \ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 72 | _(IP_TABLE_DUMP, ip_table_dump) \ |
| 73 | _(IP_ROUTE_DUMP, ip_route_dump) \ |
| 74 | _(IP_MTABLE_DUMP, ip_mtable_dump) \ |
| 75 | _(IP_MROUTE_DUMP, ip_mroute_dump) \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 76 | _(IP_MROUTE_ADD_DEL, ip_mroute_add_del) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 77 | _(MFIB_SIGNAL_DUMP, mfib_signal_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 78 | _(IP_ADDRESS_DUMP, ip_address_dump) \ |
Neale Ranns | 9e2f915 | 2018-05-18 02:27:10 -0700 | [diff] [blame] | 79 | _(IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 80 | _(IP_DUMP, ip_dump) \ |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 81 | _(IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin) \ |
| 82 | _(IP_TABLE_REPLACE_END, ip_table_replace_end) \ |
| 83 | _(IP_TABLE_FLUSH, ip_table_flush) \ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 84 | _(IP_ROUTE_ADD_DEL, ip_route_add_del) \ |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 85 | _(IP_ROUTE_LOOKUP, ip_route_lookup) \ |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 86 | _(IP_TABLE_ADD_DEL, ip_table_add_del) \ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 87 | _(IP_PUNT_POLICE, ip_punt_police) \ |
| 88 | _(IP_PUNT_REDIRECT, ip_punt_redirect) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 89 | _(SET_IP_FLOW_HASH,set_ip_flow_hash) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 90 | _(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \ |
Matus Fabian | 75b9f45 | 2018-10-02 23:27:21 -0700 | [diff] [blame] | 91 | _(IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 92 | _(IOAM_ENABLE, ioam_enable) \ |
| 93 | _(IOAM_DISABLE, ioam_disable) \ |
| 94 | _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \ |
| 95 | ip_source_and_port_range_check_add_del) \ |
| 96 | _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 97 | ip_source_and_port_range_check_interface_add_del) \ |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 98 | _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \ |
| 99 | sw_interface_ip6_set_link_local_address) \ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 100 | _(IP_REASSEMBLY_SET, ip_reassembly_set) \ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 101 | _(IP_REASSEMBLY_GET, ip_reassembly_get) \ |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 102 | _(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \ |
| 103 | _(IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump) |
| 104 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 105 | static void |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 106 | vl_api_sw_interface_ip6_enable_disable_t_handler |
| 107 | (vl_api_sw_interface_ip6_enable_disable_t * mp) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 108 | { |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 109 | vl_api_sw_interface_ip6_enable_disable_reply_t *rmp; |
| 110 | int rv = 0; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 111 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 112 | VALIDATE_SW_IF_INDEX (mp); |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 113 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 114 | rv = ((mp->enable == 1) ? |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 115 | ip6_link_enable (ntohl (mp->sw_if_index), NULL) : |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 116 | ip6_link_disable (ntohl (mp->sw_if_index))); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 117 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 118 | BAD_SW_IF_INDEX_LABEL; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 119 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 120 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 121 | } |
| 122 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 123 | static void |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 124 | send_ip_table_details (vpe_api_main_t * am, |
| 125 | vl_api_registration_t * reg, |
| 126 | u32 context, const fib_table_t * table) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 127 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 128 | vl_api_ip_table_details_t *mp; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 129 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 130 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 131 | if (!mp) |
| 132 | return; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 133 | clib_memset (mp, 0, sizeof (*mp)); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 134 | mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 135 | mp->context = context; |
| 136 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 137 | mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6); |
| 138 | mp->table.table_id = htonl (table->ft_table_id); |
| 139 | memcpy (mp->table.name, table->ft_desc, |
| 140 | clib_min (vec_len (table->ft_desc), sizeof (mp->table.name))); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 141 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 142 | vl_api_send_msg (reg, (u8 *) mp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 145 | static void |
| 146 | vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp) |
| 147 | { |
| 148 | vpe_api_main_t *am = &vpe_api_main; |
| 149 | vl_api_registration_t *reg; |
| 150 | fib_table_t *fib_table; |
| 151 | |
| 152 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 153 | if (!reg) |
| 154 | return; |
| 155 | |
| 156 | /* *INDENT-OFF* */ |
| 157 | pool_foreach (fib_table, ip4_main.fibs, |
| 158 | ({ |
| 159 | send_ip_table_details(am, reg, mp->context, fib_table); |
| 160 | })); |
| 161 | pool_foreach (fib_table, ip6_main.fibs, |
| 162 | ({ |
| 163 | /* don't send link locals */ |
| 164 | if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL) |
| 165 | continue; |
| 166 | send_ip_table_details(am, reg, mp->context, fib_table); |
| 167 | })); |
| 168 | /* *INDENT-ON* */ |
| 169 | } |
| 170 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 171 | typedef struct vl_api_ip_fib_dump_walk_ctx_t_ |
| 172 | { |
| 173 | fib_node_index_t *feis; |
| 174 | } vl_api_ip_fib_dump_walk_ctx_t; |
| 175 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 176 | static fib_table_walk_rc_t |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 177 | vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg) |
| 178 | { |
| 179 | vl_api_ip_fib_dump_walk_ctx_t *ctx = arg; |
| 180 | |
| 181 | vec_add1 (ctx->feis, fei); |
| 182 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 183 | return (FIB_TABLE_WALK_CONTINUE); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 186 | static void |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 187 | send_ip_route_details (vpe_api_main_t * am, |
| 188 | vl_api_registration_t * reg, |
| 189 | u32 context, fib_node_index_t fib_entry_index) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 190 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 191 | fib_route_path_t *rpaths, *rpath; |
| 192 | vl_api_ip_route_details_t *mp; |
Neale Ranns | c5d4317 | 2018-07-30 08:04:40 -0700 | [diff] [blame] | 193 | const fib_prefix_t *pfx; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 194 | vl_api_fib_path_t *fp; |
| 195 | int path_count; |
| 196 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 197 | rpaths = NULL; |
| 198 | pfx = fib_entry_get_prefix (fib_entry_index); |
| 199 | rpaths = fib_entry_encode (fib_entry_index); |
| 200 | |
| 201 | path_count = vec_len (rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 202 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 203 | if (!mp) |
| 204 | return; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 205 | clib_memset (mp, 0, sizeof (*mp)); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 206 | mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 207 | mp->context = context; |
| 208 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 209 | ip_prefix_encode (pfx, &mp->route.prefix); |
| 210 | mp->route.table_id = |
| 211 | htonl (fib_table_get_table_id |
| 212 | (fib_entry_get_fib_index (fib_entry_index), pfx->fp_proto)); |
| 213 | mp->route.n_paths = path_count; |
| 214 | mp->route.stats_index = |
| 215 | htonl (fib_table_entry_get_stats_index |
| 216 | (fib_entry_get_fib_index (fib_entry_index), pfx)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 217 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 218 | fp = mp->route.paths; |
| 219 | vec_foreach (rpath, rpaths) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 220 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 221 | fib_api_path_encode (rpath, fp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 222 | fp++; |
| 223 | } |
| 224 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 225 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 226 | vec_free (rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 229 | typedef struct apt_ip6_fib_show_ctx_t_ |
| 230 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 231 | fib_node_index_t *entries; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 232 | } api_ip6_fib_show_ctx_t; |
| 233 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 234 | static void |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 235 | 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] | 236 | { |
| 237 | vpe_api_main_t *am = &vpe_api_main; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 238 | fib_node_index_t *fib_entry_index; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 239 | vl_api_registration_t *reg; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 240 | fib_protocol_t fproto; |
| 241 | u32 fib_index; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 242 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 243 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 244 | if (!reg) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 245 | return; |
| 246 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 247 | vl_api_ip_fib_dump_walk_ctx_t ctx = { |
| 248 | .feis = NULL, |
| 249 | }; |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 250 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 251 | fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 252 | fib_index = fib_table_find (fproto, ntohl (mp->table.table_id)); |
| 253 | |
| 254 | if (INDEX_INVALID == fib_index) |
| 255 | return; |
| 256 | |
| 257 | fib_table_walk (fib_index, fproto, vl_api_ip_fib_dump_walk, &ctx); |
| 258 | |
| 259 | vec_foreach (fib_entry_index, ctx.feis) |
| 260 | { |
| 261 | send_ip_route_details (am, reg, mp->context, *fib_entry_index); |
| 262 | } |
| 263 | |
| 264 | vec_free (ctx.feis); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static void |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 268 | send_ip_mtable_details (vl_api_registration_t * reg, |
| 269 | u32 context, const mfib_table_t * mfib_table) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 270 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 271 | vl_api_ip_mtable_details_t *mp; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 272 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 273 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 274 | if (!mp) |
| 275 | return; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 276 | memset (mp, 0, sizeof (*mp)); |
| 277 | mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 278 | mp->context = context; |
| 279 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 280 | mp->table.table_id = htonl (mfib_table->mft_table_id); |
| 281 | mp->table.is_ip6 = (FIB_PROTOCOL_IP6 == mfib_table->mft_proto); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 282 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 283 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 286 | static void |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 287 | 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] | 288 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 289 | vl_api_registration_t *reg; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 290 | mfib_table_t *mfib_table; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 291 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 292 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 293 | if (!reg) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 294 | return; |
| 295 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 296 | /* *INDENT-OFF* */ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 297 | pool_foreach (mfib_table, ip4_main.mfibs, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 298 | ({ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 299 | send_ip_mtable_details (reg, mp->context, mfib_table); |
| 300 | })); |
| 301 | pool_foreach (mfib_table, ip6_main.mfibs, |
| 302 | ({ |
| 303 | send_ip_mtable_details (reg, mp->context, mfib_table); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 304 | })); |
| 305 | /* *INDENT-ON* */ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 308 | typedef struct vl_api_ip_mfib_dump_ctx_t_ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 309 | { |
| 310 | fib_node_index_t *entries; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 311 | } vl_api_ip_mfib_dump_ctx_t; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 312 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 313 | static walk_rc_t |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 314 | mfib_route_dump_walk (fib_node_index_t fei, void *arg) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 315 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 316 | vl_api_ip_mfib_dump_ctx_t *ctx = arg; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 317 | |
| 318 | vec_add1 (ctx->entries, fei); |
| 319 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 320 | return (WALK_CONTINUE); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static void |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 324 | send_ip_mroute_details (vpe_api_main_t * am, |
| 325 | vl_api_registration_t * reg, |
| 326 | u32 context, fib_node_index_t mfib_entry_index) |
| 327 | { |
| 328 | fib_route_path_t *rpaths, *rpath; |
| 329 | vl_api_ip_mroute_details_t *mp; |
| 330 | const mfib_prefix_t *pfx; |
| 331 | vl_api_mfib_path_t *fp; |
Matthew Smith | a2bbeb8 | 2020-09-17 16:33:10 -0500 | [diff] [blame] | 332 | u8 path_count; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 333 | |
| 334 | rpaths = NULL; |
| 335 | pfx = mfib_entry_get_prefix (mfib_entry_index); |
| 336 | rpaths = mfib_entry_encode (mfib_entry_index); |
| 337 | |
| 338 | path_count = vec_len (rpaths); |
| 339 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 340 | if (!mp) |
| 341 | return; |
| 342 | clib_memset (mp, 0, sizeof (*mp)); |
| 343 | mp->_vl_msg_id = ntohs (VL_API_IP_MROUTE_DETAILS); |
| 344 | mp->context = context; |
| 345 | |
| 346 | ip_mprefix_encode (pfx, &mp->route.prefix); |
| 347 | mp->route.table_id = |
| 348 | htonl (mfib_table_get_table_id |
| 349 | (mfib_entry_get_fib_index (mfib_entry_index), pfx->fp_proto)); |
Matthew Smith | a2bbeb8 | 2020-09-17 16:33:10 -0500 | [diff] [blame] | 350 | mp->route.n_paths = path_count; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 351 | fp = mp->route.paths; |
| 352 | vec_foreach (rpath, rpaths) |
| 353 | { |
| 354 | mfib_api_path_encode (rpath, fp); |
| 355 | fp++; |
| 356 | } |
| 357 | |
| 358 | vl_api_send_msg (reg, (u8 *) mp); |
| 359 | vec_free (rpaths); |
| 360 | } |
| 361 | |
| 362 | static void |
| 363 | 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] | 364 | { |
| 365 | vpe_api_main_t *am = &vpe_api_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 366 | vl_api_registration_t *reg; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 367 | fib_node_index_t *mfeip; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 368 | fib_protocol_t fproto; |
| 369 | u32 fib_index; |
| 370 | |
| 371 | vl_api_ip_mfib_dump_ctx_t ctx = { |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 372 | .entries = NULL, |
| 373 | }; |
| 374 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 375 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 376 | if (!reg) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 377 | return; |
| 378 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 379 | fproto = fib_ip_proto (mp->table.is_ip6); |
| 380 | fib_index = mfib_table_find (fproto, ntohl (mp->table.table_id)); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 381 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 382 | if (INDEX_INVALID == fib_index) |
| 383 | return; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 384 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 385 | mfib_table_walk (fib_index, fproto, mfib_route_dump_walk, &ctx); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 386 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 387 | vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 388 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 389 | vec_foreach (mfeip, ctx.entries) |
| 390 | { |
| 391 | send_ip_mroute_details (am, reg, mp->context, *mfeip); |
| 392 | } |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 393 | |
| 394 | vec_free (ctx.entries); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | static void |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 398 | vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp, |
| 399 | vlib_main_t * vm) |
| 400 | { |
| 401 | vl_api_ip_punt_police_reply_t *rmp; |
| 402 | int rv = 0; |
| 403 | |
| 404 | if (mp->is_ip6) |
| 405 | ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index)); |
| 406 | else |
| 407 | ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index)); |
| 408 | |
| 409 | REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY); |
| 410 | } |
| 411 | |
| 412 | static void |
| 413 | vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp, |
| 414 | vlib_main_t * vm) |
| 415 | { |
| 416 | vl_api_ip_punt_redirect_reply_t *rmp; |
| 417 | int rv = 0; |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 418 | ip46_type_t ipv; |
| 419 | ip46_address_t nh; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 420 | |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 421 | if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index))) |
| 422 | goto bad_sw_if_index; |
| 423 | |
| 424 | ipv = ip_address_decode (&mp->punt.nh, &nh); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 425 | if (mp->is_add) |
| 426 | { |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 427 | if (ipv == IP46_TYPE_IP6) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 428 | { |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 429 | ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index), |
| 430 | ntohl (mp->punt.tx_sw_if_index), &nh); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 431 | } |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 432 | else if (ipv == IP46_TYPE_IP4) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 433 | { |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 434 | ip4_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index), |
| 435 | ntohl (mp->punt.tx_sw_if_index), &nh); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | else |
| 439 | { |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 440 | if (ipv == IP46_TYPE_IP6) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 441 | { |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 442 | ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index)); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 443 | } |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 444 | else if (ipv == IP46_TYPE_IP4) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 445 | { |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 446 | ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index)); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 450 | BAD_SW_IF_INDEX_LABEL; |
| 451 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 452 | REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY); |
| 453 | } |
| 454 | |
Steven Luong | c3ed1c9 | 2020-07-27 10:06:58 -0700 | [diff] [blame] | 455 | static clib_error_t * |
| 456 | call_elf_section_ip_table_callbacks (vnet_main_t * vnm, u32 table_id, |
| 457 | u32 flags, |
| 458 | _vnet_ip_table_function_list_elt_t ** |
| 459 | elts) |
| 460 | { |
| 461 | _vnet_ip_table_function_list_elt_t *elt; |
| 462 | vnet_ip_table_function_priority_t prio; |
| 463 | clib_error_t *error = 0; |
| 464 | |
| 465 | for (prio = VNET_IP_TABLE_FUNC_PRIORITY_LOW; |
| 466 | prio <= VNET_IP_TABLE_FUNC_PRIORITY_HIGH; prio++) |
| 467 | { |
| 468 | elt = elts[prio]; |
| 469 | |
| 470 | while (elt) |
| 471 | { |
| 472 | error = elt->fp (vnm, table_id, flags); |
| 473 | if (error) |
| 474 | return error; |
| 475 | elt = elt->next_ip_table_function; |
| 476 | } |
| 477 | } |
| 478 | return error; |
| 479 | } |
| 480 | |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 481 | void |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 482 | ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api) |
| 483 | { |
| 484 | u32 fib_index, mfib_index; |
Steven Luong | c3ed1c9 | 2020-07-27 10:06:58 -0700 | [diff] [blame] | 485 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 486 | |
| 487 | /* |
| 488 | * ignore action on the default table - this is always present |
| 489 | * and cannot be added nor deleted from the API |
| 490 | */ |
| 491 | if (0 != table_id) |
| 492 | { |
| 493 | /* |
| 494 | * The API holds only one lock on the table. |
| 495 | * i.e. it can be added many times via the API but needs to be |
| 496 | * deleted only once. |
| 497 | * The FIB index for unicast and multicast is not necessarily the |
| 498 | * same, since internal VPP systesm (like LISP and SR) create |
| 499 | * their own unicast tables. |
| 500 | */ |
| 501 | fib_index = fib_table_find (fproto, table_id); |
| 502 | mfib_index = mfib_table_find (fproto, table_id); |
| 503 | |
Steven Luong | c3ed1c9 | 2020-07-27 10:06:58 -0700 | [diff] [blame] | 504 | if ((~0 != fib_index) || (~0 != mfib_index)) |
| 505 | call_elf_section_ip_table_callbacks (vnm, table_id, 0 /* is_add */ , |
| 506 | vnm->ip_table_add_del_functions); |
| 507 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 508 | if (~0 != fib_index) |
| 509 | { |
| 510 | fib_table_unlock (fib_index, fproto, |
| 511 | (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI)); |
| 512 | } |
| 513 | if (~0 != mfib_index) |
| 514 | { |
| 515 | mfib_table_unlock (mfib_index, fproto, |
| 516 | (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI)); |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | void |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 522 | vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp) |
| 523 | { |
| 524 | vl_api_ip_table_add_del_reply_t *rmp; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 525 | fib_protocol_t fproto = (mp->table.is_ip6 ? |
| 526 | FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 527 | u32 table_id = ntohl (mp->table.table_id); |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 528 | int rv = 0; |
| 529 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 530 | if (mp->is_add) |
| 531 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 532 | ip_table_create (fproto, table_id, 1, mp->table.name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 533 | } |
| 534 | else |
| 535 | { |
| 536 | ip_table_delete (fproto, table_id, 1); |
| 537 | } |
| 538 | |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 539 | REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY); |
| 540 | } |
| 541 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 542 | static int |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 543 | 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] | 544 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 545 | fib_route_path_t *rpaths = NULL, *rpath; |
| 546 | fib_entry_flag_t entry_flags; |
| 547 | vl_api_fib_path_t *apath; |
| 548 | fib_prefix_t pfx; |
| 549 | u32 fib_index; |
| 550 | int rv, ii; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 551 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 552 | entry_flags = FIB_ENTRY_FLAG_NONE; |
| 553 | ip_prefix_decode (&mp->route.prefix, &pfx); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 554 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 555 | rv = fib_api_table_id_decode (pfx.fp_proto, |
| 556 | ntohl (mp->route.table_id), &fib_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 557 | if (0 != rv) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 558 | goto out; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 559 | |
Neale Ranns | c2ac235 | 2019-07-02 14:33:29 +0000 | [diff] [blame] | 560 | if (0 != mp->route.n_paths) |
| 561 | vec_validate (rpaths, mp->route.n_paths - 1); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 562 | |
| 563 | for (ii = 0; ii < mp->route.n_paths; ii++) |
| 564 | { |
| 565 | apath = &mp->route.paths[ii]; |
| 566 | rpath = &rpaths[ii]; |
| 567 | |
| 568 | rv = fib_api_path_decode (apath, rpath); |
| 569 | |
| 570 | if ((rpath->frp_flags & FIB_ROUTE_PATH_LOCAL) && |
| 571 | (~0 == rpath->frp_sw_if_index)) |
| 572 | entry_flags |= (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL); |
| 573 | |
| 574 | if (0 != rv) |
| 575 | goto out; |
| 576 | } |
| 577 | |
Neale Ranns | c2ac235 | 2019-07-02 14:33:29 +0000 | [diff] [blame] | 578 | rv = fib_api_route_add_del (mp->is_add, |
| 579 | mp->is_multipath, |
| 580 | fib_index, &pfx, entry_flags, rpaths); |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 581 | |
| 582 | if (mp->is_add && 0 == rv) |
| 583 | *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx); |
| 584 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 585 | out: |
| 586 | vec_free (rpaths); |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 587 | |
| 588 | return (rv); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | void |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 592 | 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] | 593 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 594 | vl_api_ip_route_add_del_reply_t *rmp; |
| 595 | u32 stats_index = ~0; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 596 | int rv; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 597 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 598 | rv = ip_route_add_del_t_handler (mp, &stats_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 599 | |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 600 | /* *INDENT-OFF* */ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 601 | REPLY_MACRO2 (VL_API_IP_ROUTE_ADD_DEL_REPLY, |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 602 | ({ |
| 603 | rmp->stats_index = htonl (stats_index); |
| 604 | })) |
| 605 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 606 | } |
| 607 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 608 | void |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 609 | vl_api_ip_route_lookup_t_handler (vl_api_ip_route_lookup_t * mp) |
| 610 | { |
| 611 | vl_api_ip_route_lookup_reply_t *rmp = NULL; |
| 612 | fib_route_path_t *rpaths = NULL, *rpath; |
| 613 | const fib_prefix_t *pfx = NULL; |
| 614 | fib_prefix_t lookup; |
| 615 | vl_api_fib_path_t *fp; |
| 616 | fib_node_index_t fib_entry_index; |
| 617 | u32 fib_index; |
| 618 | int npaths = 0; |
| 619 | int rv; |
| 620 | |
| 621 | ip_prefix_decode (&mp->prefix, &lookup); |
| 622 | rv = fib_api_table_id_decode (lookup.fp_proto, ntohl (mp->table_id), |
| 623 | &fib_index); |
| 624 | if (PREDICT_TRUE (!rv)) |
| 625 | { |
| 626 | if (mp->exact) |
| 627 | fib_entry_index = fib_table_lookup_exact_match (fib_index, &lookup); |
| 628 | else |
| 629 | fib_entry_index = fib_table_lookup (fib_index, &lookup); |
| 630 | if (fib_entry_index == FIB_NODE_INDEX_INVALID) |
| 631 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 632 | else |
| 633 | { |
| 634 | pfx = fib_entry_get_prefix (fib_entry_index); |
| 635 | rpaths = fib_entry_encode (fib_entry_index); |
| 636 | npaths = vec_len (rpaths); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /* *INDENT-OFF* */ |
| 641 | REPLY_MACRO3_ZERO(VL_API_IP_ROUTE_LOOKUP_REPLY, |
| 642 | npaths * sizeof (*fp), |
| 643 | ({ |
| 644 | if (!rv) |
| 645 | { |
| 646 | ip_prefix_encode (pfx, &rmp->route.prefix); |
| 647 | rmp->route.table_id = mp->table_id; |
| 648 | rmp->route.n_paths = npaths; |
| 649 | rmp->route.stats_index = fib_table_entry_get_stats_index (fib_index, pfx); |
| 650 | rmp->route.stats_index = htonl (rmp->route.stats_index); |
| 651 | |
| 652 | fp = rmp->route.paths; |
| 653 | vec_foreach (rpath, rpaths) |
| 654 | { |
| 655 | fib_api_path_encode (rpath, fp); |
| 656 | fp++; |
| 657 | } |
| 658 | } |
| 659 | })); |
| 660 | /* *INDENT-ON* */ |
| 661 | vec_free (rpaths); |
| 662 | } |
| 663 | |
| 664 | void |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 665 | ip_table_create (fib_protocol_t fproto, |
| 666 | u32 table_id, u8 is_api, const u8 * name) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 667 | { |
| 668 | u32 fib_index, mfib_index; |
Steven Luong | c3ed1c9 | 2020-07-27 10:06:58 -0700 | [diff] [blame] | 669 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 670 | |
| 671 | /* |
| 672 | * ignore action on the default table - this is always present |
| 673 | * and cannot be added nor deleted from the API |
| 674 | */ |
| 675 | if (0 != table_id) |
| 676 | { |
| 677 | /* |
| 678 | * The API holds only one lock on the table. |
| 679 | * i.e. it can be added many times via the API but needs to be |
| 680 | * deleted only once. |
| 681 | * The FIB index for unicast and multicast is not necessarily the |
| 682 | * same, since internal VPP systesm (like LISP and SR) create |
| 683 | * their own unicast tables. |
| 684 | */ |
| 685 | fib_index = fib_table_find (fproto, table_id); |
| 686 | mfib_index = mfib_table_find (fproto, table_id); |
| 687 | |
| 688 | if (~0 == fib_index) |
| 689 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 690 | fib_table_find_or_create_and_lock_w_name (fproto, table_id, |
| 691 | (is_api ? |
| 692 | FIB_SOURCE_API : |
| 693 | FIB_SOURCE_CLI), name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 694 | } |
| 695 | if (~0 == mfib_index) |
| 696 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 697 | mfib_table_find_or_create_and_lock_w_name (fproto, table_id, |
| 698 | (is_api ? |
| 699 | MFIB_SOURCE_API : |
| 700 | MFIB_SOURCE_CLI), name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 701 | } |
Steven Luong | c3ed1c9 | 2020-07-27 10:06:58 -0700 | [diff] [blame] | 702 | |
| 703 | if ((~0 == fib_index) || (~0 == mfib_index)) |
| 704 | call_elf_section_ip_table_callbacks (vnm, table_id, 1 /* is_add */ , |
| 705 | vnm->ip_table_add_del_functions); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 709 | static u32 |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 710 | mroute_add_del_handler (u8 is_add, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 711 | u8 is_multipath, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 712 | u32 fib_index, |
| 713 | const mfib_prefix_t * prefix, |
| 714 | u32 entry_flags, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 715 | u32 rpf_id, fib_route_path_t * rpaths) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 716 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 717 | u32 mfib_entry_index = ~0; |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 718 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 719 | if (0 == vec_len (rpaths)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 720 | { |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 721 | mfib_entry_index = mfib_table_entry_update (fib_index, prefix, |
| 722 | MFIB_SOURCE_API, |
| 723 | rpf_id, entry_flags); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 724 | } |
| 725 | else |
| 726 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 727 | if (is_add) |
| 728 | { |
| 729 | mfib_entry_index = |
| 730 | mfib_table_entry_paths_update (fib_index, prefix, |
| 731 | MFIB_SOURCE_API, rpaths); |
| 732 | } |
| 733 | else |
| 734 | { |
| 735 | mfib_table_entry_paths_remove (fib_index, prefix, |
| 736 | MFIB_SOURCE_API, rpaths); |
| 737 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 740 | return (mfib_entry_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | static int |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 744 | api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp, |
| 745 | u32 * stats_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 746 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 747 | fib_route_path_t *rpath, *rpaths = NULL; |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 748 | fib_node_index_t mfib_entry_index; |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 749 | mfib_entry_flags_t eflags; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 750 | mfib_prefix_t pfx; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 751 | u32 fib_index; |
| 752 | int rv; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 753 | u16 ii; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 754 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 755 | ip_mprefix_decode (&mp->route.prefix, &pfx); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 756 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 757 | rv = mfib_api_table_id_decode (pfx.fp_proto, |
| 758 | ntohl (mp->route.table_id), &fib_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 759 | if (0 != rv) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 760 | goto out; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 761 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 762 | vec_validate (rpaths, mp->route.n_paths - 1); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 763 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 764 | for (ii = 0; ii < mp->route.n_paths; ii++) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 765 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 766 | rpath = &rpaths[ii]; |
| 767 | |
| 768 | rv = mfib_api_path_decode (&mp->route.paths[ii], rpath); |
| 769 | |
| 770 | if (0 != rv) |
| 771 | goto out; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 774 | eflags = mfib_api_path_entry_flags_decode (mp->route.entry_flags); |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 775 | mfib_entry_index = mroute_add_del_handler (mp->is_add, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 776 | mp->is_add, |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 777 | fib_index, &pfx, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 778 | eflags, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 779 | ntohl (mp->route.rpf_id), |
| 780 | rpaths); |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 781 | |
| 782 | if (~0 != mfib_entry_index) |
| 783 | *stats_index = mfib_entry_get_stats_index (mfib_entry_index); |
| 784 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 785 | out: |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 786 | return (rv); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | void |
| 790 | vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 791 | { |
| 792 | vl_api_ip_mroute_add_del_reply_t *rmp; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 793 | u32 stats_index = ~0; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 794 | int rv; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 795 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 796 | rv = api_mroute_add_del_t_handler (mp, &stats_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 797 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 798 | /* *INDENT-OFF* */ |
| 799 | REPLY_MACRO2 (VL_API_IP_MROUTE_ADD_DEL_REPLY, |
| 800 | ({ |
| 801 | rmp->stats_index = htonl (stats_index); |
| 802 | })); |
| 803 | /* *INDENT-ON* */ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 804 | } |
| 805 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 806 | static void |
| 807 | send_ip_details (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 808 | vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6, |
| 809 | u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 810 | { |
| 811 | vl_api_ip_details_t *mp; |
| 812 | |
| 813 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 814 | clib_memset (mp, 0, sizeof (*mp)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 815 | mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS); |
| 816 | |
| 817 | mp->sw_if_index = ntohl (sw_if_index); |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 818 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 819 | mp->context = context; |
| 820 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 821 | vl_api_send_msg (reg, (u8 *) mp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static void |
| 825 | send_ip_address_details (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 826 | vl_api_registration_t * reg, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 827 | const fib_prefix_t * pfx, |
| 828 | u32 sw_if_index, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 829 | { |
| 830 | vl_api_ip_address_details_t *mp; |
| 831 | |
| 832 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 833 | clib_memset (mp, 0, sizeof (*mp)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 834 | mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS); |
| 835 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 836 | ip_prefix_encode (pfx, &mp->prefix); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 837 | mp->context = context; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 838 | mp->sw_if_index = htonl (sw_if_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 839 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 840 | vl_api_send_msg (reg, (u8 *) mp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | static void |
| 844 | vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp) |
| 845 | { |
| 846 | vpe_api_main_t *am = &vpe_api_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 847 | vl_api_registration_t *reg; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 848 | ip6_main_t *im6 = &ip6_main; |
| 849 | ip4_main_t *im4 = &ip4_main; |
| 850 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 851 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 852 | ip_interface_address_t *ia = 0; |
| 853 | u32 sw_if_index = ~0; |
| 854 | int rv __attribute__ ((unused)) = 0; |
| 855 | |
| 856 | VALIDATE_SW_IF_INDEX (mp); |
| 857 | |
| 858 | sw_if_index = ntohl (mp->sw_if_index); |
| 859 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 860 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 861 | if (!reg) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 862 | return; |
| 863 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 864 | if (mp->is_ipv6) |
| 865 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 866 | /* *INDENT-OFF* */ |
Neale Ranns | 4f2db7d | 2018-05-17 09:38:13 -0700 | [diff] [blame] | 867 | /* Do not send subnet details of the IP-interface for |
| 868 | * unnumbered interfaces. otherwise listening clients |
| 869 | * will be confused that the subnet is applied on more |
| 870 | * than one interface */ |
| 871 | foreach_ip_interface_address (lm6, ia, sw_if_index, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 872 | ({ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 873 | fib_prefix_t pfx = { |
| 874 | .fp_addr.ip6 = *(ip6_address_t *)ip_interface_address_get_address (lm6, ia), |
| 875 | .fp_len = ia->address_length, |
| 876 | .fp_proto = FIB_PROTOCOL_IP6, |
| 877 | }; |
| 878 | send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 879 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 880 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 881 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 882 | else |
| 883 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 884 | /* *INDENT-OFF* */ |
Neale Ranns | 4f2db7d | 2018-05-17 09:38:13 -0700 | [diff] [blame] | 885 | foreach_ip_interface_address (lm4, ia, sw_if_index, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 886 | ({ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 887 | fib_prefix_t pfx = { |
| 888 | .fp_addr.ip4 = *(ip4_address_t *)ip_interface_address_get_address (lm4, ia), |
| 889 | .fp_len = ia->address_length, |
| 890 | .fp_proto = FIB_PROTOCOL_IP4, |
| 891 | }; |
| 892 | |
| 893 | send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 894 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 895 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 896 | } |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 897 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 898 | BAD_SW_IF_INDEX_LABEL; |
| 899 | } |
| 900 | |
| 901 | static void |
Neale Ranns | 9e2f915 | 2018-05-18 02:27:10 -0700 | [diff] [blame] | 902 | send_ip_unnumbered_details (vpe_api_main_t * am, |
| 903 | vl_api_registration_t * reg, |
| 904 | u32 sw_if_index, u32 ip_sw_if_index, u32 context) |
| 905 | { |
| 906 | vl_api_ip_unnumbered_details_t *mp; |
| 907 | |
| 908 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 909 | clib_memset (mp, 0, sizeof (*mp)); |
Neale Ranns | 9e2f915 | 2018-05-18 02:27:10 -0700 | [diff] [blame] | 910 | mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS); |
| 911 | |
| 912 | mp->context = context; |
| 913 | mp->sw_if_index = htonl (sw_if_index); |
| 914 | mp->ip_sw_if_index = htonl (ip_sw_if_index); |
| 915 | |
| 916 | vl_api_send_msg (reg, (u8 *) mp); |
| 917 | } |
| 918 | |
| 919 | static void |
| 920 | vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp) |
| 921 | { |
| 922 | vnet_main_t *vnm = vnet_get_main (); |
| 923 | vnet_interface_main_t *im = &vnm->interface_main; |
| 924 | int rv __attribute__ ((unused)) = 0; |
| 925 | vpe_api_main_t *am = &vpe_api_main; |
| 926 | vl_api_registration_t *reg; |
| 927 | vnet_sw_interface_t *si; |
| 928 | u32 sw_if_index; |
| 929 | |
| 930 | sw_if_index = ntohl (mp->sw_if_index); |
| 931 | |
| 932 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 933 | if (!reg) |
| 934 | return; |
| 935 | |
| 936 | if (~0 != sw_if_index) |
| 937 | { |
| 938 | VALIDATE_SW_IF_INDEX (mp); |
| 939 | |
| 940 | si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index)); |
| 941 | |
Neale Ranns | ac3e72c | 2019-10-06 01:04:26 -0700 | [diff] [blame] | 942 | if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) |
Neale Ranns | 9e2f915 | 2018-05-18 02:27:10 -0700 | [diff] [blame] | 943 | { |
| 944 | send_ip_unnumbered_details (am, reg, |
| 945 | sw_if_index, |
| 946 | si->unnumbered_sw_if_index, |
| 947 | mp->context); |
| 948 | } |
| 949 | } |
| 950 | else |
| 951 | { |
| 952 | /* *INDENT-OFF* */ |
| 953 | pool_foreach (si, im->sw_interfaces, |
| 954 | ({ |
| 955 | if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) |
| 956 | { |
| 957 | send_ip_unnumbered_details(am, reg, |
| 958 | si->sw_if_index, |
| 959 | si->unnumbered_sw_if_index, |
| 960 | mp->context); |
| 961 | } |
| 962 | })); |
| 963 | /* *INDENT-ON* */ |
| 964 | } |
| 965 | |
| 966 | BAD_SW_IF_INDEX_LABEL; |
| 967 | } |
| 968 | |
| 969 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 970 | vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp) |
| 971 | { |
| 972 | vpe_api_main_t *am = &vpe_api_main; |
| 973 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 974 | //vlib_main_t *vm = vlib_get_main (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 975 | vnet_interface_main_t *im = &vnm->interface_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 976 | vl_api_registration_t *reg; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 977 | vnet_sw_interface_t *si, *sorted_sis; |
| 978 | u32 sw_if_index = ~0; |
| 979 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 980 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 981 | if (!reg) |
| 982 | return; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 983 | |
| 984 | /* Gather interfaces. */ |
| 985 | sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
| 986 | _vec_len (sorted_sis) = 0; |
| 987 | /* *INDENT-OFF* */ |
| 988 | pool_foreach (si, im->sw_interfaces, |
| 989 | ({ |
| 990 | vec_add1 (sorted_sis, si[0]); |
| 991 | })); |
| 992 | /* *INDENT-ON* */ |
| 993 | |
| 994 | vec_foreach (si, sorted_sis) |
| 995 | { |
| 996 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) |
| 997 | { |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 998 | /* if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) */ |
| 999 | /* { */ |
| 1000 | /* continue; */ |
| 1001 | /* } */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1002 | sw_if_index = si->sw_if_index; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1003 | 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] | 1004 | } |
| 1005 | } |
Matthew Smith | 6d5f659 | 2019-09-18 13:51:46 -0500 | [diff] [blame] | 1006 | |
| 1007 | vec_free (sorted_sis); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | static void |
| 1011 | set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1012 | { |
| 1013 | vl_api_set_ip_flow_hash_reply_t *rmp; |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1014 | int rv; |
| 1015 | u32 table_id; |
| 1016 | flow_hash_config_t flow_hash_config = 0; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1017 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1018 | table_id = ntohl (mp->vrf_id); |
| 1019 | |
| 1020 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1021 | foreach_flow_hash_bit; |
| 1022 | #undef _ |
| 1023 | |
| 1024 | rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1025 | |
| 1026 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1027 | } |
| 1028 | |
| 1029 | static void |
| 1030 | set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1031 | { |
| 1032 | vl_api_set_ip_flow_hash_reply_t *rmp; |
| 1033 | int rv; |
| 1034 | u32 table_id; |
| 1035 | flow_hash_config_t flow_hash_config = 0; |
| 1036 | |
| 1037 | table_id = ntohl (mp->vrf_id); |
| 1038 | |
| 1039 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1040 | foreach_flow_hash_bit; |
| 1041 | #undef _ |
| 1042 | |
| 1043 | rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config); |
| 1044 | |
| 1045 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1046 | } |
| 1047 | |
| 1048 | |
| 1049 | static void |
| 1050 | vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp) |
| 1051 | { |
| 1052 | if (mp->is_ipv6 == 0) |
| 1053 | set_ip4_flow_hash (mp); |
| 1054 | else |
| 1055 | set_ip6_flow_hash (mp); |
| 1056 | } |
| 1057 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1058 | void |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1059 | vl_mfib_signal_send_one (vl_api_registration_t * reg, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1060 | u32 context, const mfib_signal_t * mfs) |
| 1061 | { |
| 1062 | vl_api_mfib_signal_details_t *mp; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1063 | const mfib_prefix_t *prefix; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1064 | mfib_table_t *mfib; |
| 1065 | mfib_itf_t *mfi; |
| 1066 | |
| 1067 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1068 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1069 | clib_memset (mp, 0, sizeof (*mp)); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1070 | mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS); |
| 1071 | mp->context = context; |
| 1072 | |
| 1073 | mfi = mfib_itf_get (mfs->mfs_itf); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1074 | prefix = mfib_entry_get_prefix (mfs->mfs_entry); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1075 | mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry), |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1076 | prefix->fp_proto); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1077 | mp->table_id = ntohl (mfib->mft_table_id); |
| 1078 | mp->sw_if_index = ntohl (mfi->mfi_sw_if_index); |
| 1079 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1080 | ip_mprefix_encode (prefix, &mp->prefix); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1081 | |
| 1082 | if (0 != mfs->mfs_buffer_len) |
| 1083 | { |
| 1084 | mp->ip_packet_len = ntohs (mfs->mfs_buffer_len); |
| 1085 | |
| 1086 | memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len); |
| 1087 | } |
| 1088 | else |
| 1089 | { |
| 1090 | mp->ip_packet_len = 0; |
| 1091 | } |
| 1092 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1093 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | static void |
| 1097 | vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp) |
| 1098 | { |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1099 | vl_api_registration_t *reg; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1100 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1101 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1102 | if (!reg) |
| 1103 | return; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1104 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1105 | 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] | 1106 | ; |
| 1107 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1108 | |
Florin Coras | 595992c | 2017-11-06 17:17:08 -0800 | [diff] [blame] | 1109 | static void |
| 1110 | vl_api_ip_container_proxy_add_del_t_handler |
| 1111 | (vl_api_ip_container_proxy_add_del_t * mp) |
| 1112 | { |
| 1113 | vl_api_ip_container_proxy_add_del_reply_t *rmp; |
| 1114 | vnet_ip_container_proxy_args_t args; |
| 1115 | int rv = 0; |
| 1116 | clib_error_t *error; |
| 1117 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1118 | clib_memset (&args, 0, sizeof (args)); |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1119 | |
| 1120 | ip_prefix_decode (&mp->pfx, &args.prefix); |
| 1121 | |
Florin Coras | 595992c | 2017-11-06 17:17:08 -0800 | [diff] [blame] | 1122 | args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index); |
| 1123 | args.is_add = mp->is_add; |
| 1124 | if ((error = vnet_ip_container_proxy_add_del (&args))) |
| 1125 | { |
| 1126 | rv = clib_error_get_code (error); |
| 1127 | clib_error_report (error); |
| 1128 | } |
| 1129 | |
| 1130 | REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY); |
| 1131 | } |
| 1132 | |
Matus Fabian | 75b9f45 | 2018-10-02 23:27:21 -0700 | [diff] [blame] | 1133 | typedef struct ip_container_proxy_walk_ctx_t_ |
| 1134 | { |
| 1135 | vl_api_registration_t *reg; |
| 1136 | u32 context; |
| 1137 | } ip_container_proxy_walk_ctx_t; |
| 1138 | |
| 1139 | static int |
| 1140 | ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index, |
| 1141 | void *args) |
| 1142 | { |
| 1143 | vl_api_ip_container_proxy_details_t *mp; |
| 1144 | ip_container_proxy_walk_ctx_t *ctx = args; |
| 1145 | |
| 1146 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1147 | if (!mp) |
| 1148 | return 1; |
| 1149 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1150 | clib_memset (mp, 0, sizeof (*mp)); |
Matus Fabian | 75b9f45 | 2018-10-02 23:27:21 -0700 | [diff] [blame] | 1151 | mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS); |
| 1152 | mp->context = ctx->context; |
| 1153 | |
| 1154 | mp->sw_if_index = ntohl (sw_if_index); |
| 1155 | ip_prefix_encode (pfx, &mp->prefix); |
| 1156 | |
| 1157 | vl_api_send_msg (ctx->reg, (u8 *) mp); |
| 1158 | |
| 1159 | return 1; |
| 1160 | } |
| 1161 | |
| 1162 | static void |
| 1163 | vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t * |
| 1164 | mp) |
| 1165 | { |
| 1166 | vl_api_registration_t *reg; |
| 1167 | |
| 1168 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1169 | if (!reg) |
| 1170 | return; |
| 1171 | |
| 1172 | ip_container_proxy_walk_ctx_t ctx = { |
| 1173 | .context = mp->context, |
| 1174 | .reg = reg, |
| 1175 | }; |
| 1176 | |
| 1177 | ip_container_proxy_walk (ip_container_proxy_send_details, &ctx); |
| 1178 | } |
| 1179 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1180 | static void |
| 1181 | vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp) |
| 1182 | { |
| 1183 | int rv = 0; |
| 1184 | vl_api_ioam_enable_reply_t *rmp; |
| 1185 | clib_error_t *error; |
| 1186 | |
| 1187 | /* Ignoring the profile id as currently a single profile |
| 1188 | * is supported */ |
| 1189 | error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable, |
| 1190 | mp->seqno, mp->analyse); |
| 1191 | if (error) |
| 1192 | { |
| 1193 | clib_error_report (error); |
| 1194 | rv = clib_error_get_code (error); |
| 1195 | } |
| 1196 | |
| 1197 | REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY); |
| 1198 | } |
| 1199 | |
| 1200 | static void |
| 1201 | vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp) |
| 1202 | { |
| 1203 | int rv = 0; |
| 1204 | vl_api_ioam_disable_reply_t *rmp; |
| 1205 | clib_error_t *error; |
| 1206 | |
| 1207 | error = clear_ioam_rewrite_fn (); |
| 1208 | if (error) |
| 1209 | { |
| 1210 | clib_error_report (error); |
| 1211 | rv = clib_error_get_code (error); |
| 1212 | } |
| 1213 | |
| 1214 | REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY); |
| 1215 | } |
| 1216 | |
| 1217 | static void |
| 1218 | vl_api_ip_source_and_port_range_check_add_del_t_handler |
| 1219 | (vl_api_ip_source_and_port_range_check_add_del_t * mp) |
| 1220 | { |
| 1221 | vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp; |
| 1222 | int rv = 0; |
| 1223 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1224 | u8 is_add = mp->is_add; |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1225 | fib_prefix_t pfx; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1226 | u16 *low_ports = 0; |
| 1227 | u16 *high_ports = 0; |
| 1228 | u32 vrf_id; |
| 1229 | u16 tmp_low, tmp_high; |
| 1230 | u8 num_ranges; |
| 1231 | int i; |
| 1232 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1233 | ip_prefix_decode (&mp->prefix, &pfx); |
| 1234 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1235 | // Validate port range |
| 1236 | num_ranges = mp->number_of_ranges; |
| 1237 | if (num_ranges > 32) |
| 1238 | { // This is size of array in VPE.API |
| 1239 | rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY; |
| 1240 | goto reply; |
| 1241 | } |
| 1242 | |
| 1243 | vec_reset_length (low_ports); |
| 1244 | vec_reset_length (high_ports); |
| 1245 | |
| 1246 | for (i = 0; i < num_ranges; i++) |
| 1247 | { |
| 1248 | tmp_low = mp->low_ports[i]; |
| 1249 | tmp_high = mp->high_ports[i]; |
| 1250 | // If tmp_low <= tmp_high then only need to check tmp_low = 0 |
| 1251 | // If tmp_low <= tmp_high then only need to check tmp_high > 65535 |
| 1252 | if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535) |
| 1253 | { |
| 1254 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1255 | goto reply; |
| 1256 | } |
| 1257 | vec_add1 (low_ports, tmp_low); |
| 1258 | vec_add1 (high_ports, tmp_high + 1); |
| 1259 | } |
| 1260 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1261 | vrf_id = ntohl (mp->vrf_id); |
| 1262 | |
| 1263 | if (vrf_id < 1) |
| 1264 | { |
| 1265 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1266 | goto reply; |
| 1267 | } |
| 1268 | |
| 1269 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1270 | if (FIB_PROTOCOL_IP6 == pfx.fp_proto) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1271 | { |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1272 | rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6, |
| 1273 | pfx.fp_len, |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1274 | vrf_id, |
| 1275 | low_ports, |
| 1276 | high_ports, is_add); |
| 1277 | } |
| 1278 | else |
| 1279 | { |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1280 | rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4, |
| 1281 | pfx.fp_len, |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1282 | vrf_id, |
| 1283 | low_ports, |
| 1284 | high_ports, is_add); |
| 1285 | } |
| 1286 | |
| 1287 | reply: |
| 1288 | vec_free (low_ports); |
| 1289 | vec_free (high_ports); |
| 1290 | REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY); |
| 1291 | } |
| 1292 | |
| 1293 | static void |
| 1294 | vl_api_ip_source_and_port_range_check_interface_add_del_t_handler |
| 1295 | (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp) |
| 1296 | { |
| 1297 | vlib_main_t *vm = vlib_get_main (); |
| 1298 | vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp; |
| 1299 | ip4_main_t *im = &ip4_main; |
| 1300 | int rv; |
| 1301 | u32 sw_if_index; |
| 1302 | u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; |
| 1303 | u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; |
| 1304 | uword *p = 0; |
| 1305 | int i; |
| 1306 | |
| 1307 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] = |
| 1308 | ntohl (mp->tcp_out_vrf_id); |
| 1309 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] = |
| 1310 | ntohl (mp->udp_out_vrf_id); |
| 1311 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] = |
| 1312 | ntohl (mp->tcp_in_vrf_id); |
| 1313 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] = |
| 1314 | ntohl (mp->udp_in_vrf_id); |
| 1315 | |
| 1316 | |
| 1317 | for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++) |
| 1318 | { |
| 1319 | if (vrf_id[i] != 0 && vrf_id[i] != ~0) |
| 1320 | { |
| 1321 | p = hash_get (im->fib_index_by_table_id, vrf_id[i]); |
| 1322 | |
| 1323 | if (p == 0) |
| 1324 | { |
| 1325 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1326 | goto reply; |
| 1327 | } |
| 1328 | |
| 1329 | fib_index[i] = p[0]; |
| 1330 | } |
| 1331 | else |
| 1332 | fib_index[i] = ~0; |
| 1333 | } |
| 1334 | sw_if_index = ntohl (mp->sw_if_index); |
| 1335 | |
| 1336 | VALIDATE_SW_IF_INDEX (mp); |
| 1337 | |
| 1338 | rv = |
| 1339 | set_ip_source_and_port_range_check (vm, fib_index, sw_if_index, |
| 1340 | mp->is_add); |
| 1341 | |
| 1342 | BAD_SW_IF_INDEX_LABEL; |
| 1343 | reply: |
| 1344 | |
| 1345 | REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY); |
| 1346 | } |
| 1347 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1348 | static void |
| 1349 | vl_api_sw_interface_ip6_set_link_local_address_t_handler |
| 1350 | (vl_api_sw_interface_ip6_set_link_local_address_t * mp) |
| 1351 | { |
| 1352 | vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp; |
| 1353 | ip6_address_t ip; |
| 1354 | int rv; |
| 1355 | |
| 1356 | VALIDATE_SW_IF_INDEX (mp); |
| 1357 | |
| 1358 | ip6_address_decode (mp->ip, &ip); |
| 1359 | |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 1360 | rv = ip6_link_set_local_address (ntohl (mp->sw_if_index), &ip); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1361 | |
| 1362 | BAD_SW_IF_INDEX_LABEL; |
| 1363 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY); |
| 1364 | } |
| 1365 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1366 | static void |
| 1367 | 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] | 1368 | { |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1369 | vl_api_ip_table_replace_begin_reply_t *rmp; |
| 1370 | fib_protocol_t fproto; |
| 1371 | u32 fib_index; |
| 1372 | int rv = 0; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1373 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1374 | fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 1375 | fib_index = fib_table_find (fproto, ntohl (mp->table.table_id)); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1376 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1377 | if (INDEX_INVALID == fib_index) |
| 1378 | rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 1379 | else |
| 1380 | { |
| 1381 | fib_table_mark (fib_index, fproto, FIB_SOURCE_API); |
| 1382 | mfib_table_mark (mfib_table_find (fproto, ntohl (mp->table.table_id)), |
| 1383 | fproto, MFIB_SOURCE_API); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1384 | } |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1385 | REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | static void |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1389 | 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] | 1390 | { |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1391 | vl_api_ip_table_replace_end_reply_t *rmp; |
| 1392 | fib_protocol_t fproto; |
| 1393 | u32 fib_index; |
| 1394 | int rv = 0; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1395 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1396 | fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 1397 | fib_index = fib_table_find (fproto, ntohl (mp->table.table_id)); |
| 1398 | |
| 1399 | if (INDEX_INVALID == fib_index) |
| 1400 | rv = VNET_API_ERROR_NO_SUCH_FIB; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1401 | else |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1402 | { |
| 1403 | fib_table_sweep (fib_index, fproto, FIB_SOURCE_API); |
| 1404 | mfib_table_sweep (mfib_table_find |
| 1405 | (fproto, ntohl (mp->table.table_id)), fproto, |
| 1406 | MFIB_SOURCE_API); |
| 1407 | } |
| 1408 | REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY); |
| 1409 | } |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1410 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 1411 | static void |
| 1412 | vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp) |
| 1413 | { |
| 1414 | vl_api_ip_table_flush_reply_t *rmp; |
| 1415 | fib_protocol_t fproto; |
| 1416 | u32 fib_index; |
| 1417 | int rv = 0; |
| 1418 | |
| 1419 | fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 1420 | fib_index = fib_table_find (fproto, ntohl (mp->table.table_id)); |
| 1421 | |
| 1422 | if (INDEX_INVALID == fib_index) |
| 1423 | rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 1424 | else |
| 1425 | { |
| 1426 | vnet_main_t *vnm = vnet_get_main (); |
| 1427 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1428 | vnet_sw_interface_t *si; |
| 1429 | |
| 1430 | /* Shut down interfaces in this FIB / clean out intfc routes */ |
| 1431 | /* *INDENT-OFF* */ |
| 1432 | pool_foreach (si, im->sw_interfaces, |
| 1433 | ({ |
| 1434 | if (fib_index == fib_table_get_index_for_sw_if_index (fproto, |
| 1435 | si->sw_if_index)) |
| 1436 | { |
| 1437 | u32 flags = si->flags; |
| 1438 | flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP; |
| 1439 | vnet_sw_interface_set_flags (vnm, si->sw_if_index, flags); |
| 1440 | } |
| 1441 | })); |
| 1442 | /* *INDENT-ON* */ |
| 1443 | |
| 1444 | fib_table_flush (fib_index, fproto, FIB_SOURCE_API); |
| 1445 | mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)), |
| 1446 | fproto, MFIB_SOURCE_API); |
| 1447 | } |
| 1448 | |
| 1449 | REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1450 | } |
| 1451 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1452 | void |
| 1453 | vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp) |
| 1454 | { |
| 1455 | vl_api_ip_reassembly_set_reply_t *rmp; |
| 1456 | int rv = 0; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1457 | 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] | 1458 | { |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1459 | case IP_REASS_TYPE_FULL: |
| 1460 | if (mp->is_ip6) |
| 1461 | { |
| 1462 | rv = ip6_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms), |
| 1463 | clib_net_to_host_u32 |
| 1464 | (mp->max_reassemblies), |
| 1465 | clib_net_to_host_u32 |
| 1466 | (mp->max_reassembly_length), |
| 1467 | clib_net_to_host_u32 |
| 1468 | (mp->expire_walk_interval_ms)); |
| 1469 | } |
| 1470 | else |
| 1471 | { |
| 1472 | rv = ip4_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms), |
| 1473 | clib_net_to_host_u32 |
| 1474 | (mp->max_reassemblies), |
| 1475 | clib_net_to_host_u32 |
| 1476 | (mp->max_reassembly_length), |
| 1477 | clib_net_to_host_u32 |
| 1478 | (mp->expire_walk_interval_ms)); |
| 1479 | } |
| 1480 | break; |
| 1481 | case IP_REASS_TYPE_SHALLOW_VIRTUAL: |
| 1482 | if (mp->is_ip6) |
| 1483 | { |
| 1484 | rv = |
| 1485 | ip6_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms), |
| 1486 | clib_net_to_host_u32 (mp->max_reassemblies), |
| 1487 | clib_net_to_host_u32 |
| 1488 | (mp->max_reassembly_length), |
| 1489 | clib_net_to_host_u32 |
| 1490 | (mp->expire_walk_interval_ms)); |
| 1491 | } |
| 1492 | else |
| 1493 | { |
| 1494 | rv = ip4_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms), |
| 1495 | clib_net_to_host_u32 (mp->max_reassemblies), |
| 1496 | clib_net_to_host_u32 |
| 1497 | (mp->max_reassembly_length), |
| 1498 | clib_net_to_host_u32 |
| 1499 | (mp->expire_walk_interval_ms)); |
| 1500 | } |
| 1501 | break; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY); |
| 1505 | } |
| 1506 | |
| 1507 | void |
| 1508 | vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp) |
| 1509 | { |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 1510 | vl_api_registration_t *rp; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1511 | |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 1512 | rp = vl_api_client_index_to_registration (mp->client_index); |
| 1513 | if (rp == 0) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1514 | return; |
| 1515 | |
| 1516 | 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] | 1517 | clib_memset (rmp, 0, sizeof (*rmp)); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1518 | rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY); |
| 1519 | rmp->context = mp->context; |
| 1520 | rmp->retval = 0; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1521 | u32 timeout_ms; |
| 1522 | u32 max_reassemblies; |
| 1523 | u32 max_reassembly_length; |
| 1524 | u32 expire_walk_interval_ms; |
| 1525 | 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] | 1526 | { |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1527 | case IP_REASS_TYPE_FULL: |
| 1528 | if (mp->is_ip6) |
| 1529 | { |
| 1530 | rmp->is_ip6 = 1; |
| 1531 | ip6_full_reass_get (&timeout_ms, &max_reassemblies, |
| 1532 | &max_reassembly_length, |
| 1533 | &expire_walk_interval_ms); |
| 1534 | } |
| 1535 | else |
| 1536 | { |
| 1537 | rmp->is_ip6 = 0; |
| 1538 | ip4_full_reass_get (&timeout_ms, &max_reassemblies, |
| 1539 | &max_reassembly_length, |
| 1540 | &expire_walk_interval_ms); |
| 1541 | } |
| 1542 | break; |
| 1543 | case IP_REASS_TYPE_SHALLOW_VIRTUAL: |
| 1544 | if (mp->is_ip6) |
| 1545 | { |
| 1546 | rmp->is_ip6 = 1; |
| 1547 | ip6_sv_reass_get (&timeout_ms, &max_reassemblies, |
| 1548 | &max_reassembly_length, &expire_walk_interval_ms); |
| 1549 | } |
| 1550 | else |
| 1551 | { |
| 1552 | rmp->is_ip6 = 0; |
| 1553 | ip4_sv_reass_get (&timeout_ms, &max_reassemblies, |
| 1554 | &max_reassembly_length, &expire_walk_interval_ms); |
| 1555 | } |
| 1556 | break; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1557 | } |
Matthew Smith | b3174df | 2019-12-03 12:41:53 -0600 | [diff] [blame] | 1558 | rmp->timeout_ms = clib_host_to_net_u32 (timeout_ms); |
| 1559 | rmp->max_reassemblies = clib_host_to_net_u32 (max_reassemblies); |
| 1560 | rmp->max_reassembly_length = clib_host_to_net_u32 (max_reassembly_length); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1561 | rmp->expire_walk_interval_ms = |
Matthew Smith | b3174df | 2019-12-03 12:41:53 -0600 | [diff] [blame] | 1562 | clib_host_to_net_u32 (expire_walk_interval_ms); |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 1563 | vl_api_send_msg (rp, (u8 *) rmp); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1564 | } |
| 1565 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1566 | void |
| 1567 | vl_api_ip_reassembly_enable_disable_t_handler |
| 1568 | (vl_api_ip_reassembly_enable_disable_t * mp) |
| 1569 | { |
| 1570 | vl_api_ip_reassembly_enable_disable_reply_t *rmp; |
| 1571 | int rv = 0; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1572 | 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] | 1573 | { |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1574 | case IP_REASS_TYPE_FULL: |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1575 | rv = |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1576 | ip4_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index), |
| 1577 | mp->enable_ip4); |
| 1578 | if (0 == rv) |
| 1579 | rv = |
| 1580 | ip6_full_reass_enable_disable (clib_net_to_host_u32 |
| 1581 | (mp->sw_if_index), mp->enable_ip6); |
| 1582 | break; |
| 1583 | case IP_REASS_TYPE_SHALLOW_VIRTUAL: |
| 1584 | rv = |
| 1585 | ip4_sv_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index), |
| 1586 | mp->enable_ip4); |
| 1587 | if (0 == rv) |
| 1588 | { |
| 1589 | rv = |
| 1590 | ip6_sv_reass_enable_disable (clib_net_to_host_u32 |
| 1591 | (mp->sw_if_index), mp->enable_ip6); |
| 1592 | } |
| 1593 | break; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1594 | } |
| 1595 | |
Chore | e7f61d1 | 2018-11-28 10:27:58 +0330 | [diff] [blame] | 1596 | REPLY_MACRO (VL_API_IP_REASSEMBLY_ENABLE_DISABLE_REPLY); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1597 | } |
| 1598 | |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1599 | typedef struct ip_punt_redirect_walk_ctx_t_ |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1600 | { |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1601 | vl_api_registration_t *reg; |
| 1602 | u32 context; |
| 1603 | } ip_punt_redirect_walk_ctx_t; |
| 1604 | |
| 1605 | static walk_rc_t |
| 1606 | send_ip_punt_redirect_details (u32 rx_sw_if_index, |
| 1607 | const ip_punt_redirect_rx_t * ipr, void *arg) |
| 1608 | { |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1609 | ip_punt_redirect_walk_ctx_t *ctx = arg; |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1610 | vl_api_ip_punt_redirect_details_t *mp; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1611 | fib_path_encode_ctx_t path_ctx = { |
| 1612 | .rpaths = NULL, |
| 1613 | }; |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1614 | |
| 1615 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1616 | if (!mp) |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1617 | return (WALK_STOP);; |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1618 | |
| 1619 | clib_memset (mp, 0, sizeof (*mp)); |
| 1620 | mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS); |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1621 | mp->context = ctx->context; |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1622 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1623 | 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] | 1624 | |
| 1625 | mp->punt.rx_sw_if_index = htonl (rx_sw_if_index); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1626 | 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] | 1627 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1628 | ip_address_encode (&path_ctx.rpaths[0].frp_addr, |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1629 | fib_proto_to_ip46 (ipr->fproto), &mp->punt.nh); |
| 1630 | |
| 1631 | vl_api_send_msg (ctx->reg, (u8 *) mp); |
| 1632 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1633 | vec_free (path_ctx.rpaths); |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1634 | |
| 1635 | return (WALK_CONTINUE); |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static void |
| 1639 | vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp) |
| 1640 | { |
| 1641 | vl_api_registration_t *reg; |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 1642 | fib_protocol_t fproto = FIB_PROTOCOL_IP4; |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1643 | |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1644 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1645 | if (!reg) |
| 1646 | return; |
| 1647 | |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 1648 | if (mp->is_ipv6 == 1) |
| 1649 | fproto = FIB_PROTOCOL_IP6; |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1650 | |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1651 | ip_punt_redirect_walk_ctx_t ctx = { |
| 1652 | .reg = reg, |
| 1653 | .context = mp->context, |
| 1654 | }; |
| 1655 | |
| 1656 | if (~0 != mp->sw_if_index) |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1657 | { |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1658 | u32 rx_sw_if_index; |
| 1659 | index_t pri; |
| 1660 | |
| 1661 | rx_sw_if_index = ntohl (mp->sw_if_index); |
| 1662 | pri = ip_punt_redirect_find (fproto, rx_sw_if_index); |
| 1663 | |
| 1664 | if (INDEX_INVALID == pri) |
| 1665 | return; |
| 1666 | |
| 1667 | send_ip_punt_redirect_details (rx_sw_if_index, |
| 1668 | ip_punt_redirect_get (pri), &ctx); |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1669 | } |
| 1670 | else |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 1671 | ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx); |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1674 | #define vl_msg_name_crc_list |
| 1675 | #include <vnet/ip/ip.api.h> |
| 1676 | #undef vl_msg_name_crc_list |
| 1677 | |
| 1678 | static void |
| 1679 | setup_message_id_table (api_main_t * am) |
| 1680 | { |
| 1681 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1682 | foreach_vl_msg_name_crc_ip; |
| 1683 | #undef _ |
| 1684 | } |
| 1685 | |
| 1686 | static clib_error_t * |
| 1687 | ip_api_hookup (vlib_main_t * vm) |
| 1688 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1689 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1690 | |
| 1691 | #define _(N,n) \ |
| 1692 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1693 | vl_api_##n##_t_handler, \ |
| 1694 | vl_noop_handler, \ |
| 1695 | vl_api_##n##_t_endian, \ |
| 1696 | vl_api_##n##_t_print, \ |
| 1697 | sizeof(vl_api_##n##_t), 1); |
| 1698 | foreach_ip_api_msg; |
| 1699 | #undef _ |
| 1700 | |
| 1701 | /* |
Neale Ranns | 6a231a1 | 2018-10-17 06:38:00 +0000 | [diff] [blame] | 1702 | * Mark the route add/del API as MP safe |
| 1703 | */ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1704 | am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1; |
| 1705 | am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL_REPLY] = 1; |
Neale Ranns | 6a231a1 | 2018-10-17 06:38:00 +0000 | [diff] [blame] | 1706 | |
| 1707 | /* |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1708 | * Set up the (msg_name, crc, message-id) table |
| 1709 | */ |
| 1710 | setup_message_id_table (am); |
| 1711 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1712 | return 0; |
| 1713 | } |
| 1714 | |
| 1715 | VLIB_API_INIT_FUNCTION (ip_api_hookup); |
| 1716 | |
| 1717 | /* |
| 1718 | * fd.io coding-style-patch-verification: ON |
| 1719 | * |
| 1720 | * Local Variables: |
| 1721 | * eval: (c-set-style "gnu") |
| 1722 | * End: |
| 1723 | */ |