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