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