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