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