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