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