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