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