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