blob: 5b87f7cc86a8f83934b4d3ce46d5a76126505a33 [file] [log] [blame]
Dave Barachb5e8a772016-12-06 12:04:42 -05001/*
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 Ranns37029302018-08-10 05:30:06 -070026#include <vnet/ethernet/ethernet_types_api.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050027#include <vnet/ip/ip.h>
Neale Ranns37029302018-08-10 05:30:06 -070028#include <vnet/ip/ip_types_api.h>
Pavel Kotucek609e1212018-11-27 09:59:44 +010029#include <vnet/ip/ip_punt_drop.h>
Neale Ranns097fa662018-05-01 05:17:55 -070030#include <vnet/ip/ip_types_api.h>
Neale Ranns8f5fef22020-12-21 08:29:34 +000031#include <vnet/ip/ip_path_mtu.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050032#include <vnet/fib/fib_table.h>
33#include <vnet/fib/fib_api.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050034#include <vnet/ethernet/arp_packet.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080035#include <vnet/mfib/ip6_mfib.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000036#include <vnet/mfib/ip4_mfib.h>
37#include <vnet/mfib/mfib_signal.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080038#include <vnet/mfib/mfib_entry.h>
Neale Ranns097fa662018-05-01 05:17:55 -070039#include <vnet/mfib/mfib_api.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080040#include <vnet/ip/ip_source_and_port_range_check.h>
Neale Ranns92207752019-06-03 13:21:40 +000041#include <vnet/fib/fib_path_list.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080042#include <vnet/ip/ip6_hop_by_hop.h>
Neale Rannscbe25aa2019-09-30 10:53:31 +000043#include <vnet/ip/ip6_link.h>
Klement Sekerade34c352019-06-25 11:19:22 +000044#include <vnet/ip/reass/ip4_sv_reass.h>
Klement Sekera896c8962019-06-24 11:52:49 +000045#include <vnet/ip/reass/ip4_full_reass.h>
Klement Sekerade34c352019-06-25 11:19:22 +000046#include <vnet/ip/reass/ip6_sv_reass.h>
Klement Sekera896c8962019-06-24 11:52:49 +000047#include <vnet/ip/reass/ip6_full_reass.h>
Steven Luongc3ed1c92020-07-27 10:06:58 -070048#include <vnet/ip/ip_table.h>
Neale Rannse4031132020-10-26 13:00:06 +000049#include <vnet/ip/ip_container_proxy.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050050
51#include <vnet/vnet_msg_enum.h>
52
53#define vl_typedefs /* define message structures */
54#include <vnet/vnet_all_api_h.h>
55#undef vl_typedefs
56
57#define vl_endianfun /* define message structures */
58#include <vnet/vnet_all_api_h.h>
59#undef vl_endianfun
60
61/* instantiate all the print functions we know about */
62#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
63#define vl_printfun
64#include <vnet/vnet_all_api_h.h>
65#undef vl_printfun
66
67#include <vlibapi/api_helper_macros.h>
68
Ole Troan33a58172019-09-04 09:12:29 +020069#include <vnet/format_fns.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080070
Benoît Ganne58a19152021-01-18 19:24:34 +010071#define foreach_ip_api_msg \
72 _ (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable) \
73 _ (IP_TABLE_DUMP, ip_table_dump) \
74 _ (IP_ROUTE_DUMP, ip_route_dump) \
75 _ (IP_MTABLE_DUMP, ip_mtable_dump) \
76 _ (IP_MROUTE_DUMP, ip_mroute_dump) \
77 _ (IP_MROUTE_ADD_DEL, ip_mroute_add_del) \
78 _ (MFIB_SIGNAL_DUMP, mfib_signal_dump) \
79 _ (IP_ADDRESS_DUMP, ip_address_dump) \
80 _ (IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \
81 _ (IP_DUMP, ip_dump) \
82 _ (IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin) \
83 _ (IP_TABLE_REPLACE_END, ip_table_replace_end) \
84 _ (IP_TABLE_FLUSH, ip_table_flush) \
85 _ (IP_ROUTE_ADD_DEL, ip_route_add_del) \
86 _ (IP_ROUTE_LOOKUP, ip_route_lookup) \
87 _ (IP_TABLE_ADD_DEL, ip_table_add_del) \
88 _ (IP_PUNT_POLICE, ip_punt_police) \
89 _ (IP_PUNT_REDIRECT, ip_punt_redirect) \
90 _ (SET_IP_FLOW_HASH, set_ip_flow_hash) \
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +000091 _ (SET_IP_FLOW_HASH_V2, set_ip_flow_hash_v2) \
Neale Ranns3d5f08a2021-01-22 16:12:38 +000092 _ (SET_IP_FLOW_HASH_ROUTER_ID, set_ip_flow_hash_router_id) \
Benoît Ganne58a19152021-01-18 19:24:34 +010093 _ (IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \
94 _ (IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \
95 _ (IOAM_ENABLE, ioam_enable) \
96 _ (IOAM_DISABLE, ioam_disable) \
97 _ (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
98 ip_source_and_port_range_check_add_del) \
99 _ (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
100 ip_source_and_port_range_check_interface_add_del) \
101 _ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
102 sw_interface_ip6_set_link_local_address) \
103 _ (SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS, \
104 sw_interface_ip6_get_link_local_address) \
105 _ (IP_REASSEMBLY_SET, ip_reassembly_set) \
106 _ (IP_REASSEMBLY_GET, ip_reassembly_get) \
107 _ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
Neale Ranns8f5fef22020-12-21 08:29:34 +0000108 _ (IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump) \
109 _ (IP_PATH_MTU_UPDATE, ip_path_mtu_update) \
110 _ (IP_PATH_MTU_REPLACE_BEGIN, ip_path_mtu_replace_begin) \
111 _ (IP_PATH_MTU_REPLACE_END, ip_path_mtu_replace_end) \
112 _ (IP_PATH_MTU_GET, ip_path_mtu_get)
Pavel Kotucek609e1212018-11-27 09:59:44 +0100113
Dave Barachb5e8a772016-12-06 12:04:42 -0500114static void
Neale Rannscbe25aa2019-09-30 10:53:31 +0000115 vl_api_sw_interface_ip6_enable_disable_t_handler
116 (vl_api_sw_interface_ip6_enable_disable_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500117{
Neale Rannscbe25aa2019-09-30 10:53:31 +0000118 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
119 int rv = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500120
Neale Rannscbe25aa2019-09-30 10:53:31 +0000121 VALIDATE_SW_IF_INDEX (mp);
Neale Ranns37029302018-08-10 05:30:06 -0700122
Neale Rannscbe25aa2019-09-30 10:53:31 +0000123 rv = ((mp->enable == 1) ?
Neale Rannsec40a7d2020-04-23 07:36:12 +0000124 ip6_link_enable (ntohl (mp->sw_if_index), NULL) :
Neale Rannscbe25aa2019-09-30 10:53:31 +0000125 ip6_link_disable (ntohl (mp->sw_if_index)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500126
Neale Rannscbe25aa2019-09-30 10:53:31 +0000127 BAD_SW_IF_INDEX_LABEL;
Dave Barachb5e8a772016-12-06 12:04:42 -0500128
Neale Rannscbe25aa2019-09-30 10:53:31 +0000129 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
Dave Barachb5e8a772016-12-06 12:04:42 -0500130}
131
Dave Barachb5e8a772016-12-06 12:04:42 -0500132static void
Neale Ranns097fa662018-05-01 05:17:55 -0700133send_ip_table_details (vpe_api_main_t * am,
134 vl_api_registration_t * reg,
135 u32 context, const fib_table_t * table)
Dave Barachb5e8a772016-12-06 12:04:42 -0500136{
Neale Ranns097fa662018-05-01 05:17:55 -0700137 vl_api_ip_table_details_t *mp;
Dave Barachb5e8a772016-12-06 12:04:42 -0500138
Neale Ranns097fa662018-05-01 05:17:55 -0700139 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500140 if (!mp)
141 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400142 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700143 mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500144 mp->context = context;
145
Neale Ranns097fa662018-05-01 05:17:55 -0700146 mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6);
147 mp->table.table_id = htonl (table->ft_table_id);
148 memcpy (mp->table.name, table->ft_desc,
149 clib_min (vec_len (table->ft_desc), sizeof (mp->table.name)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500150
Florin Coras6c4dae22018-01-09 06:39:23 -0800151 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500152}
153
Neale Ranns097fa662018-05-01 05:17:55 -0700154static void
155vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp)
156{
157 vpe_api_main_t *am = &vpe_api_main;
158 vl_api_registration_t *reg;
159 fib_table_t *fib_table;
160
161 reg = vl_api_client_index_to_registration (mp->client_index);
162 if (!reg)
163 return;
164
165 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100166 pool_foreach (fib_table, ip4_main.fibs)
167 {
Neale Ranns097fa662018-05-01 05:17:55 -0700168 send_ip_table_details(am, reg, mp->context, fib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100169 }
170 pool_foreach (fib_table, ip6_main.fibs)
171 {
Neale Ranns097fa662018-05-01 05:17:55 -0700172 /* don't send link locals */
173 if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
174 continue;
175 send_ip_table_details(am, reg, mp->context, fib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100176 }
Neale Ranns097fa662018-05-01 05:17:55 -0700177 /* *INDENT-ON* */
178}
179
Neale Rannsa3af3372017-03-28 03:49:52 -0700180typedef struct vl_api_ip_fib_dump_walk_ctx_t_
181{
182 fib_node_index_t *feis;
183} vl_api_ip_fib_dump_walk_ctx_t;
184
Neale Ranns89541992017-04-06 04:41:02 -0700185static fib_table_walk_rc_t
Neale Rannsa3af3372017-03-28 03:49:52 -0700186vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg)
187{
188 vl_api_ip_fib_dump_walk_ctx_t *ctx = arg;
189
190 vec_add1 (ctx->feis, fei);
191
Neale Ranns89541992017-04-06 04:41:02 -0700192 return (FIB_TABLE_WALK_CONTINUE);
Neale Rannsa3af3372017-03-28 03:49:52 -0700193}
194
Dave Barachb5e8a772016-12-06 12:04:42 -0500195static void
Neale Ranns097fa662018-05-01 05:17:55 -0700196send_ip_route_details (vpe_api_main_t * am,
197 vl_api_registration_t * reg,
198 u32 context, fib_node_index_t fib_entry_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500199{
Neale Ranns097fa662018-05-01 05:17:55 -0700200 fib_route_path_t *rpaths, *rpath;
201 vl_api_ip_route_details_t *mp;
Neale Rannsc5d43172018-07-30 08:04:40 -0700202 const fib_prefix_t *pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -0500203 vl_api_fib_path_t *fp;
204 int path_count;
205
Neale Ranns097fa662018-05-01 05:17:55 -0700206 rpaths = NULL;
207 pfx = fib_entry_get_prefix (fib_entry_index);
208 rpaths = fib_entry_encode (fib_entry_index);
209
210 path_count = vec_len (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500211 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
212 if (!mp)
213 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400214 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700215 mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500216 mp->context = context;
217
Neale Ranns097fa662018-05-01 05:17:55 -0700218 ip_prefix_encode (pfx, &mp->route.prefix);
219 mp->route.table_id =
220 htonl (fib_table_get_table_id
221 (fib_entry_get_fib_index (fib_entry_index), pfx->fp_proto));
222 mp->route.n_paths = path_count;
223 mp->route.stats_index =
224 htonl (fib_table_entry_get_stats_index
225 (fib_entry_get_fib_index (fib_entry_index), pfx));
Dave Barachb5e8a772016-12-06 12:04:42 -0500226
Neale Ranns097fa662018-05-01 05:17:55 -0700227 fp = mp->route.paths;
228 vec_foreach (rpath, rpaths)
Dave Barachb5e8a772016-12-06 12:04:42 -0500229 {
Neale Ranns097fa662018-05-01 05:17:55 -0700230 fib_api_path_encode (rpath, fp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500231 fp++;
232 }
233
Florin Coras6c4dae22018-01-09 06:39:23 -0800234 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns9db6ada2019-11-08 12:42:31 +0000235 vec_free (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500236}
237
Dave Barachd7cb1b52016-12-09 09:52:16 -0500238typedef struct apt_ip6_fib_show_ctx_t_
239{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500240 fib_node_index_t *entries;
Dave Barachb5e8a772016-12-06 12:04:42 -0500241} api_ip6_fib_show_ctx_t;
242
Dave Barachb5e8a772016-12-06 12:04:42 -0500243static void
Neale Ranns097fa662018-05-01 05:17:55 -0700244vl_api_ip_route_dump_t_handler (vl_api_ip_route_dump_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500245{
246 vpe_api_main_t *am = &vpe_api_main;
Dave Barachb5e8a772016-12-06 12:04:42 -0500247 fib_node_index_t *fib_entry_index;
Florin Coras6c4dae22018-01-09 06:39:23 -0800248 vl_api_registration_t *reg;
Neale Ranns097fa662018-05-01 05:17:55 -0700249 fib_protocol_t fproto;
250 u32 fib_index;
Dave Barachb5e8a772016-12-06 12:04:42 -0500251
Florin Coras6c4dae22018-01-09 06:39:23 -0800252 reg = vl_api_client_index_to_registration (mp->client_index);
253 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500254 return;
255
Neale Ranns097fa662018-05-01 05:17:55 -0700256 vl_api_ip_fib_dump_walk_ctx_t ctx = {
257 .feis = NULL,
258 };
Neale Ranns81458422018-03-12 06:59:36 -0700259
Neale Ranns097fa662018-05-01 05:17:55 -0700260 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
261 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
262
263 if (INDEX_INVALID == fib_index)
264 return;
265
266 fib_table_walk (fib_index, fproto, vl_api_ip_fib_dump_walk, &ctx);
267
268 vec_foreach (fib_entry_index, ctx.feis)
269 {
270 send_ip_route_details (am, reg, mp->context, *fib_entry_index);
271 }
272
273 vec_free (ctx.feis);
Dave Barachb5e8a772016-12-06 12:04:42 -0500274}
275
276static void
Neale Ranns097fa662018-05-01 05:17:55 -0700277send_ip_mtable_details (vl_api_registration_t * reg,
278 u32 context, const mfib_table_t * mfib_table)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800279{
Neale Ranns097fa662018-05-01 05:17:55 -0700280 vl_api_ip_mtable_details_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800281
Neale Ranns097fa662018-05-01 05:17:55 -0700282 mp = vl_msg_api_alloc (sizeof (*mp));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800283 if (!mp)
284 return;
Neale Ranns097fa662018-05-01 05:17:55 -0700285 memset (mp, 0, sizeof (*mp));
286 mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800287 mp->context = context;
288
Neale Ranns097fa662018-05-01 05:17:55 -0700289 mp->table.table_id = htonl (mfib_table->mft_table_id);
290 mp->table.is_ip6 = (FIB_PROTOCOL_IP6 == mfib_table->mft_proto);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800291
Florin Coras6c4dae22018-01-09 06:39:23 -0800292 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800293}
294
Neale Ranns5a8123b2017-01-26 01:18:23 -0800295static void
Neale Ranns097fa662018-05-01 05:17:55 -0700296vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800297{
Florin Coras6c4dae22018-01-09 06:39:23 -0800298 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800299 mfib_table_t *mfib_table;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800300
Florin Coras6c4dae22018-01-09 06:39:23 -0800301 reg = vl_api_client_index_to_registration (mp->client_index);
302 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800303 return;
304
Neale Ranns5a8123b2017-01-26 01:18:23 -0800305 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100306 pool_foreach (mfib_table, ip4_main.mfibs)
307 {
Neale Ranns097fa662018-05-01 05:17:55 -0700308 send_ip_mtable_details (reg, mp->context, mfib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100309 }
310 pool_foreach (mfib_table, ip6_main.mfibs)
311 {
Neale Ranns097fa662018-05-01 05:17:55 -0700312 send_ip_mtable_details (reg, mp->context, mfib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100313 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800314 /* *INDENT-ON* */
Neale Ranns5a8123b2017-01-26 01:18:23 -0800315}
316
Neale Ranns097fa662018-05-01 05:17:55 -0700317typedef struct vl_api_ip_mfib_dump_ctx_t_
Neale Ranns5a8123b2017-01-26 01:18:23 -0800318{
319 fib_node_index_t *entries;
Neale Ranns097fa662018-05-01 05:17:55 -0700320} vl_api_ip_mfib_dump_ctx_t;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800321
Neale Ranns9db6ada2019-11-08 12:42:31 +0000322static walk_rc_t
Neale Ranns097fa662018-05-01 05:17:55 -0700323mfib_route_dump_walk (fib_node_index_t fei, void *arg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800324{
Neale Ranns097fa662018-05-01 05:17:55 -0700325 vl_api_ip_mfib_dump_ctx_t *ctx = arg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800326
327 vec_add1 (ctx->entries, fei);
328
Neale Ranns9db6ada2019-11-08 12:42:31 +0000329 return (WALK_CONTINUE);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800330}
331
332static void
Neale Ranns097fa662018-05-01 05:17:55 -0700333send_ip_mroute_details (vpe_api_main_t * am,
334 vl_api_registration_t * reg,
335 u32 context, fib_node_index_t mfib_entry_index)
336{
337 fib_route_path_t *rpaths, *rpath;
338 vl_api_ip_mroute_details_t *mp;
339 const mfib_prefix_t *pfx;
340 vl_api_mfib_path_t *fp;
Matthew Smitha2bbeb82020-09-17 16:33:10 -0500341 u8 path_count;
Neale Ranns097fa662018-05-01 05:17:55 -0700342
343 rpaths = NULL;
344 pfx = mfib_entry_get_prefix (mfib_entry_index);
345 rpaths = mfib_entry_encode (mfib_entry_index);
346
347 path_count = vec_len (rpaths);
348 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
349 if (!mp)
350 return;
351 clib_memset (mp, 0, sizeof (*mp));
352 mp->_vl_msg_id = ntohs (VL_API_IP_MROUTE_DETAILS);
353 mp->context = context;
354
355 ip_mprefix_encode (pfx, &mp->route.prefix);
356 mp->route.table_id =
357 htonl (mfib_table_get_table_id
358 (mfib_entry_get_fib_index (mfib_entry_index), pfx->fp_proto));
Matthew Smitha2bbeb82020-09-17 16:33:10 -0500359 mp->route.n_paths = path_count;
Neale Ranns097fa662018-05-01 05:17:55 -0700360 fp = mp->route.paths;
361 vec_foreach (rpath, rpaths)
362 {
363 mfib_api_path_encode (rpath, fp);
364 fp++;
365 }
366
367 vl_api_send_msg (reg, (u8 *) mp);
368 vec_free (rpaths);
369}
370
371static void
372vl_api_ip_mroute_dump_t_handler (vl_api_ip_mroute_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800373{
374 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800375 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800376 fib_node_index_t *mfeip;
Neale Ranns097fa662018-05-01 05:17:55 -0700377 fib_protocol_t fproto;
378 u32 fib_index;
379
380 vl_api_ip_mfib_dump_ctx_t ctx = {
Neale Ranns5a8123b2017-01-26 01:18:23 -0800381 .entries = NULL,
382 };
383
Florin Coras6c4dae22018-01-09 06:39:23 -0800384 reg = vl_api_client_index_to_registration (mp->client_index);
385 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800386 return;
387
Neale Ranns097fa662018-05-01 05:17:55 -0700388 fproto = fib_ip_proto (mp->table.is_ip6);
389 fib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800390
Neale Ranns097fa662018-05-01 05:17:55 -0700391 if (INDEX_INVALID == fib_index)
392 return;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800393
Neale Ranns097fa662018-05-01 05:17:55 -0700394 mfib_table_walk (fib_index, fproto, mfib_route_dump_walk, &ctx);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800395
Neale Ranns097fa662018-05-01 05:17:55 -0700396 vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800397
Neale Ranns097fa662018-05-01 05:17:55 -0700398 vec_foreach (mfeip, ctx.entries)
399 {
400 send_ip_mroute_details (am, reg, mp->context, *mfeip);
401 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800402
403 vec_free (ctx.entries);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800404}
405
406static void
Neale Rannsd91c1db2017-07-31 02:30:50 -0700407vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp,
408 vlib_main_t * vm)
409{
410 vl_api_ip_punt_police_reply_t *rmp;
411 int rv = 0;
412
413 if (mp->is_ip6)
414 ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
415 else
416 ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
417
418 REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY);
419}
420
421static void
422vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp,
423 vlib_main_t * vm)
424{
425 vl_api_ip_punt_redirect_reply_t *rmp;
426 int rv = 0;
Pavel Kotucek609e1212018-11-27 09:59:44 +0100427 ip46_type_t ipv;
428 ip46_address_t nh;
Neale Rannsd91c1db2017-07-31 02:30:50 -0700429
Pavel Kotucek609e1212018-11-27 09:59:44 +0100430 if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index)))
431 goto bad_sw_if_index;
432
433 ipv = ip_address_decode (&mp->punt.nh, &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700434 if (mp->is_add)
435 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100436 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700437 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100438 ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
439 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700440 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100441 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700442 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100443 ip4_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
444 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700445 }
446 }
447 else
448 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100449 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700450 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100451 ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700452 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100453 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700454 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100455 ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700456 }
457 }
458
Pavel Kotucek609e1212018-11-27 09:59:44 +0100459 BAD_SW_IF_INDEX_LABEL;
460
Neale Rannsd91c1db2017-07-31 02:30:50 -0700461 REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY);
462}
463
Steven Luongc3ed1c92020-07-27 10:06:58 -0700464static clib_error_t *
465call_elf_section_ip_table_callbacks (vnet_main_t * vnm, u32 table_id,
466 u32 flags,
467 _vnet_ip_table_function_list_elt_t **
468 elts)
469{
470 _vnet_ip_table_function_list_elt_t *elt;
471 vnet_ip_table_function_priority_t prio;
472 clib_error_t *error = 0;
473
474 for (prio = VNET_IP_TABLE_FUNC_PRIORITY_LOW;
475 prio <= VNET_IP_TABLE_FUNC_PRIORITY_HIGH; prio++)
476 {
477 elt = elts[prio];
478
479 while (elt)
480 {
481 error = elt->fp (vnm, table_id, flags);
482 if (error)
483 return error;
484 elt = elt->next_ip_table_function;
485 }
486 }
487 return error;
488}
489
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700490void
Neale Ranns15002542017-09-10 04:39:11 -0700491ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api)
492{
493 u32 fib_index, mfib_index;
Steven Luongc3ed1c92020-07-27 10:06:58 -0700494 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns15002542017-09-10 04:39:11 -0700495
496 /*
497 * ignore action on the default table - this is always present
498 * and cannot be added nor deleted from the API
499 */
500 if (0 != table_id)
501 {
502 /*
503 * The API holds only one lock on the table.
504 * i.e. it can be added many times via the API but needs to be
505 * deleted only once.
506 * The FIB index for unicast and multicast is not necessarily the
507 * same, since internal VPP systesm (like LISP and SR) create
508 * their own unicast tables.
509 */
510 fib_index = fib_table_find (fproto, table_id);
511 mfib_index = mfib_table_find (fproto, table_id);
512
Steven Luongc3ed1c92020-07-27 10:06:58 -0700513 if ((~0 != fib_index) || (~0 != mfib_index))
514 call_elf_section_ip_table_callbacks (vnm, table_id, 0 /* is_add */ ,
515 vnm->ip_table_add_del_functions);
516
Neale Ranns15002542017-09-10 04:39:11 -0700517 if (~0 != fib_index)
518 {
519 fib_table_unlock (fib_index, fproto,
520 (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI));
521 }
522 if (~0 != mfib_index)
523 {
524 mfib_table_unlock (mfib_index, fproto,
525 (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI));
526 }
527 }
528}
529
530void
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700531vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
532{
533 vl_api_ip_table_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700534 fib_protocol_t fproto = (mp->table.is_ip6 ?
535 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
536 u32 table_id = ntohl (mp->table.table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700537 int rv = 0;
538
Neale Ranns15002542017-09-10 04:39:11 -0700539 if (mp->is_add)
540 {
Neale Ranns097fa662018-05-01 05:17:55 -0700541 ip_table_create (fproto, table_id, 1, mp->table.name);
Neale Ranns15002542017-09-10 04:39:11 -0700542 }
543 else
544 {
545 ip_table_delete (fproto, table_id, 1);
546 }
547
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700548 REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY);
549}
550
Dave Barachb5e8a772016-12-06 12:04:42 -0500551static int
Neale Ranns097fa662018-05-01 05:17:55 -0700552ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp, u32 * stats_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500553{
Neale Ranns097fa662018-05-01 05:17:55 -0700554 fib_route_path_t *rpaths = NULL, *rpath;
555 fib_entry_flag_t entry_flags;
556 vl_api_fib_path_t *apath;
557 fib_prefix_t pfx;
558 u32 fib_index;
559 int rv, ii;
Dave Barachb5e8a772016-12-06 12:04:42 -0500560
Neale Ranns097fa662018-05-01 05:17:55 -0700561 entry_flags = FIB_ENTRY_FLAG_NONE;
562 ip_prefix_decode (&mp->route.prefix, &pfx);
Dave Barachb5e8a772016-12-06 12:04:42 -0500563
Neale Ranns097fa662018-05-01 05:17:55 -0700564 rv = fib_api_table_id_decode (pfx.fp_proto,
565 ntohl (mp->route.table_id), &fib_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500566 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700567 goto out;
Dave Barachb5e8a772016-12-06 12:04:42 -0500568
Neale Rannsc2ac2352019-07-02 14:33:29 +0000569 if (0 != mp->route.n_paths)
570 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns097fa662018-05-01 05:17:55 -0700571
572 for (ii = 0; ii < mp->route.n_paths; ii++)
573 {
574 apath = &mp->route.paths[ii];
575 rpath = &rpaths[ii];
576
577 rv = fib_api_path_decode (apath, rpath);
578
579 if ((rpath->frp_flags & FIB_ROUTE_PATH_LOCAL) &&
580 (~0 == rpath->frp_sw_if_index))
581 entry_flags |= (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL);
582
583 if (0 != rv)
584 goto out;
585 }
586
Neale Rannsc2ac2352019-07-02 14:33:29 +0000587 rv = fib_api_route_add_del (mp->is_add,
588 mp->is_multipath,
589 fib_index, &pfx, entry_flags, rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700590
591 if (mp->is_add && 0 == rv)
592 *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx);
593
Neale Ranns097fa662018-05-01 05:17:55 -0700594out:
595 vec_free (rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700596
597 return (rv);
Dave Barachb5e8a772016-12-06 12:04:42 -0500598}
599
600void
Neale Ranns097fa662018-05-01 05:17:55 -0700601vl_api_ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500602{
Neale Ranns097fa662018-05-01 05:17:55 -0700603 vl_api_ip_route_add_del_reply_t *rmp;
604 u32 stats_index = ~0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500605 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -0500606
Neale Ranns097fa662018-05-01 05:17:55 -0700607 rv = ip_route_add_del_t_handler (mp, &stats_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500608
Neale Ranns008dbe12018-09-07 09:32:36 -0700609 /* *INDENT-OFF* */
Neale Ranns097fa662018-05-01 05:17:55 -0700610 REPLY_MACRO2 (VL_API_IP_ROUTE_ADD_DEL_REPLY,
Neale Ranns008dbe12018-09-07 09:32:36 -0700611 ({
612 rmp->stats_index = htonl (stats_index);
613 }))
614 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500615}
616
Neale Ranns15002542017-09-10 04:39:11 -0700617void
Christian Hoppsf5d38e02020-05-04 10:28:03 -0400618vl_api_ip_route_lookup_t_handler (vl_api_ip_route_lookup_t * mp)
619{
620 vl_api_ip_route_lookup_reply_t *rmp = NULL;
621 fib_route_path_t *rpaths = NULL, *rpath;
622 const fib_prefix_t *pfx = NULL;
623 fib_prefix_t lookup;
624 vl_api_fib_path_t *fp;
625 fib_node_index_t fib_entry_index;
626 u32 fib_index;
627 int npaths = 0;
628 int rv;
629
630 ip_prefix_decode (&mp->prefix, &lookup);
631 rv = fib_api_table_id_decode (lookup.fp_proto, ntohl (mp->table_id),
632 &fib_index);
633 if (PREDICT_TRUE (!rv))
634 {
635 if (mp->exact)
636 fib_entry_index = fib_table_lookup_exact_match (fib_index, &lookup);
637 else
638 fib_entry_index = fib_table_lookup (fib_index, &lookup);
639 if (fib_entry_index == FIB_NODE_INDEX_INVALID)
640 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
641 else
642 {
643 pfx = fib_entry_get_prefix (fib_entry_index);
644 rpaths = fib_entry_encode (fib_entry_index);
645 npaths = vec_len (rpaths);
646 }
647 }
648
649 /* *INDENT-OFF* */
650 REPLY_MACRO3_ZERO(VL_API_IP_ROUTE_LOOKUP_REPLY,
651 npaths * sizeof (*fp),
652 ({
653 if (!rv)
654 {
655 ip_prefix_encode (pfx, &rmp->route.prefix);
656 rmp->route.table_id = mp->table_id;
657 rmp->route.n_paths = npaths;
658 rmp->route.stats_index = fib_table_entry_get_stats_index (fib_index, pfx);
659 rmp->route.stats_index = htonl (rmp->route.stats_index);
660
661 fp = rmp->route.paths;
662 vec_foreach (rpath, rpaths)
663 {
664 fib_api_path_encode (rpath, fp);
665 fp++;
666 }
667 }
668 }));
669 /* *INDENT-ON* */
670 vec_free (rpaths);
671}
672
673void
Neale Ranns2297af02017-09-12 09:45:04 -0700674ip_table_create (fib_protocol_t fproto,
675 u32 table_id, u8 is_api, const u8 * name)
Neale Ranns15002542017-09-10 04:39:11 -0700676{
677 u32 fib_index, mfib_index;
Steven Luongc3ed1c92020-07-27 10:06:58 -0700678 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns15002542017-09-10 04:39:11 -0700679
680 /*
681 * ignore action on the default table - this is always present
682 * and cannot be added nor deleted from the API
683 */
684 if (0 != table_id)
685 {
686 /*
687 * The API holds only one lock on the table.
688 * i.e. it can be added many times via the API but needs to be
689 * deleted only once.
690 * The FIB index for unicast and multicast is not necessarily the
691 * same, since internal VPP systesm (like LISP and SR) create
692 * their own unicast tables.
693 */
694 fib_index = fib_table_find (fproto, table_id);
695 mfib_index = mfib_table_find (fproto, table_id);
696
697 if (~0 == fib_index)
698 {
Neale Ranns2297af02017-09-12 09:45:04 -0700699 fib_table_find_or_create_and_lock_w_name (fproto, table_id,
700 (is_api ?
701 FIB_SOURCE_API :
702 FIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700703 }
704 if (~0 == mfib_index)
705 {
Neale Ranns2297af02017-09-12 09:45:04 -0700706 mfib_table_find_or_create_and_lock_w_name (fproto, table_id,
707 (is_api ?
708 MFIB_SOURCE_API :
709 MFIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700710 }
Steven Luongc3ed1c92020-07-27 10:06:58 -0700711
712 if ((~0 == fib_index) || (~0 == mfib_index))
713 call_elf_section_ip_table_callbacks (vnm, table_id, 1 /* is_add */ ,
714 vnm->ip_table_add_del_functions);
Neale Ranns15002542017-09-10 04:39:11 -0700715 }
716}
717
Neale Ranns097fa662018-05-01 05:17:55 -0700718static u32
Neale Ranns32e1c012016-11-22 17:07:28 +0000719mroute_add_del_handler (u8 is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700720 u8 is_multipath,
Neale Ranns32e1c012016-11-22 17:07:28 +0000721 u32 fib_index,
722 const mfib_prefix_t * prefix,
723 u32 entry_flags,
Neale Ranns097fa662018-05-01 05:17:55 -0700724 u32 rpf_id, fib_route_path_t * rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +0000725{
Neale Ranns097fa662018-05-01 05:17:55 -0700726 u32 mfib_entry_index = ~0;
Neale Ranns28c142e2018-09-07 09:37:07 -0700727
Neale Ranns097fa662018-05-01 05:17:55 -0700728 if (0 == vec_len (rpaths))
Neale Ranns32e1c012016-11-22 17:07:28 +0000729 {
Neale Ranns28c142e2018-09-07 09:37:07 -0700730 mfib_entry_index = mfib_table_entry_update (fib_index, prefix,
731 MFIB_SOURCE_API,
732 rpf_id, entry_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +0000733 }
734 else
735 {
Neale Ranns097fa662018-05-01 05:17:55 -0700736 if (is_add)
737 {
738 mfib_entry_index =
739 mfib_table_entry_paths_update (fib_index, prefix,
740 MFIB_SOURCE_API, rpaths);
741 }
742 else
743 {
744 mfib_table_entry_paths_remove (fib_index, prefix,
745 MFIB_SOURCE_API, rpaths);
746 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000747 }
748
Neale Ranns28c142e2018-09-07 09:37:07 -0700749 return (mfib_entry_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000750}
751
752static int
Neale Ranns28c142e2018-09-07 09:37:07 -0700753api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp,
754 u32 * stats_index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000755{
Neale Ranns097fa662018-05-01 05:17:55 -0700756 fib_route_path_t *rpath, *rpaths = NULL;
Neale Ranns28c142e2018-09-07 09:37:07 -0700757 fib_node_index_t mfib_entry_index;
Neale Ranns990f6942020-10-20 07:20:17 +0000758 mfib_entry_flags_t eflags;
Neale Ranns097fa662018-05-01 05:17:55 -0700759 mfib_prefix_t pfx;
Neale Ranns32e1c012016-11-22 17:07:28 +0000760 u32 fib_index;
761 int rv;
Neale Ranns097fa662018-05-01 05:17:55 -0700762 u16 ii;
Neale Ranns32e1c012016-11-22 17:07:28 +0000763
Neale Ranns097fa662018-05-01 05:17:55 -0700764 ip_mprefix_decode (&mp->route.prefix, &pfx);
Neale Ranns32e1c012016-11-22 17:07:28 +0000765
Neale Ranns097fa662018-05-01 05:17:55 -0700766 rv = mfib_api_table_id_decode (pfx.fp_proto,
767 ntohl (mp->route.table_id), &fib_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000768 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700769 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000770
Neale Ranns097fa662018-05-01 05:17:55 -0700771 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns32e1c012016-11-22 17:07:28 +0000772
Neale Ranns097fa662018-05-01 05:17:55 -0700773 for (ii = 0; ii < mp->route.n_paths; ii++)
Neale Ranns32e1c012016-11-22 17:07:28 +0000774 {
Neale Ranns097fa662018-05-01 05:17:55 -0700775 rpath = &rpaths[ii];
776
777 rv = mfib_api_path_decode (&mp->route.paths[ii], rpath);
778
779 if (0 != rv)
780 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000781 }
782
Neale Ranns990f6942020-10-20 07:20:17 +0000783 eflags = mfib_api_path_entry_flags_decode (mp->route.entry_flags);
Neale Ranns28c142e2018-09-07 09:37:07 -0700784 mfib_entry_index = mroute_add_del_handler (mp->is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700785 mp->is_add,
Neale Ranns28c142e2018-09-07 09:37:07 -0700786 fib_index, &pfx,
Neale Ranns990f6942020-10-20 07:20:17 +0000787 eflags,
Neale Ranns097fa662018-05-01 05:17:55 -0700788 ntohl (mp->route.rpf_id),
789 rpaths);
Neale Ranns28c142e2018-09-07 09:37:07 -0700790
791 if (~0 != mfib_entry_index)
792 *stats_index = mfib_entry_get_stats_index (mfib_entry_index);
793
Neale Ranns097fa662018-05-01 05:17:55 -0700794out:
Neale Ranns28c142e2018-09-07 09:37:07 -0700795 return (rv);
Neale Ranns32e1c012016-11-22 17:07:28 +0000796}
797
798void
799vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp)
800{
801 vl_api_ip_mroute_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700802 u32 stats_index = ~0;
Neale Ranns32e1c012016-11-22 17:07:28 +0000803 int rv;
Neale Ranns32e1c012016-11-22 17:07:28 +0000804
Neale Ranns28c142e2018-09-07 09:37:07 -0700805 rv = api_mroute_add_del_t_handler (mp, &stats_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000806
Neale Ranns28c142e2018-09-07 09:37:07 -0700807 /* *INDENT-OFF* */
808 REPLY_MACRO2 (VL_API_IP_MROUTE_ADD_DEL_REPLY,
809 ({
810 rmp->stats_index = htonl (stats_index);
811 }));
812 /* *INDENT-ON* */
Neale Ranns32e1c012016-11-22 17:07:28 +0000813}
814
Dave Barachb5e8a772016-12-06 12:04:42 -0500815static void
816send_ip_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800817 vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6,
818 u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500819{
820 vl_api_ip_details_t *mp;
821
822 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400823 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500824 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
825
826 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger466f0d42017-02-09 12:17:50 -0600827 mp->is_ipv6 = is_ipv6;
Dave Barachb5e8a772016-12-06 12:04:42 -0500828 mp->context = context;
829
Florin Coras6c4dae22018-01-09 06:39:23 -0800830 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500831}
832
833static void
834send_ip_address_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800835 vl_api_registration_t * reg,
Neale Ranns097fa662018-05-01 05:17:55 -0700836 const fib_prefix_t * pfx,
837 u32 sw_if_index, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500838{
839 vl_api_ip_address_details_t *mp;
840
841 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400842 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500843 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
844
Neale Ranns097fa662018-05-01 05:17:55 -0700845 ip_prefix_encode (pfx, &mp->prefix);
Dave Barachb5e8a772016-12-06 12:04:42 -0500846 mp->context = context;
Jon Loeliger466f0d42017-02-09 12:17:50 -0600847 mp->sw_if_index = htonl (sw_if_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500848
Florin Coras6c4dae22018-01-09 06:39:23 -0800849 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500850}
851
852static void
853vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
854{
855 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800856 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500857 ip6_main_t *im6 = &ip6_main;
858 ip4_main_t *im4 = &ip4_main;
859 ip_lookup_main_t *lm6 = &im6->lookup_main;
860 ip_lookup_main_t *lm4 = &im4->lookup_main;
861 ip_interface_address_t *ia = 0;
862 u32 sw_if_index = ~0;
863 int rv __attribute__ ((unused)) = 0;
864
865 VALIDATE_SW_IF_INDEX (mp);
866
867 sw_if_index = ntohl (mp->sw_if_index);
868
Florin Coras6c4dae22018-01-09 06:39:23 -0800869 reg = vl_api_client_index_to_registration (mp->client_index);
870 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500871 return;
872
Dave Barachb5e8a772016-12-06 12:04:42 -0500873 if (mp->is_ipv6)
874 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500875 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700876 /* Do not send subnet details of the IP-interface for
877 * unnumbered interfaces. otherwise listening clients
878 * will be confused that the subnet is applied on more
879 * than one interface */
880 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500881 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700882 fib_prefix_t pfx = {
883 .fp_addr.ip6 = *(ip6_address_t *)ip_interface_address_get_address (lm6, ia),
884 .fp_len = ia->address_length,
885 .fp_proto = FIB_PROTOCOL_IP6,
886 };
887 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500888 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500889 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500890 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500891 else
892 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500893 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700894 foreach_ip_interface_address (lm4, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500895 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700896 fib_prefix_t pfx = {
897 .fp_addr.ip4 = *(ip4_address_t *)ip_interface_address_get_address (lm4, ia),
898 .fp_len = ia->address_length,
899 .fp_proto = FIB_PROTOCOL_IP4,
900 };
901
902 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500903 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500904 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500905 }
Neale Ranns008dbe12018-09-07 09:32:36 -0700906
Dave Barachb5e8a772016-12-06 12:04:42 -0500907 BAD_SW_IF_INDEX_LABEL;
908}
909
910static void
Neale Ranns9e2f9152018-05-18 02:27:10 -0700911send_ip_unnumbered_details (vpe_api_main_t * am,
912 vl_api_registration_t * reg,
913 u32 sw_if_index, u32 ip_sw_if_index, u32 context)
914{
915 vl_api_ip_unnumbered_details_t *mp;
916
917 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400918 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns9e2f9152018-05-18 02:27:10 -0700919 mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
920
921 mp->context = context;
922 mp->sw_if_index = htonl (sw_if_index);
923 mp->ip_sw_if_index = htonl (ip_sw_if_index);
924
925 vl_api_send_msg (reg, (u8 *) mp);
926}
927
928static void
929vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
930{
931 vnet_main_t *vnm = vnet_get_main ();
932 vnet_interface_main_t *im = &vnm->interface_main;
933 int rv __attribute__ ((unused)) = 0;
934 vpe_api_main_t *am = &vpe_api_main;
935 vl_api_registration_t *reg;
936 vnet_sw_interface_t *si;
937 u32 sw_if_index;
938
939 sw_if_index = ntohl (mp->sw_if_index);
940
941 reg = vl_api_client_index_to_registration (mp->client_index);
942 if (!reg)
943 return;
944
945 if (~0 != sw_if_index)
946 {
947 VALIDATE_SW_IF_INDEX (mp);
948
949 si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
950
Neale Rannsac3e72c2019-10-06 01:04:26 -0700951 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
Neale Ranns9e2f9152018-05-18 02:27:10 -0700952 {
953 send_ip_unnumbered_details (am, reg,
954 sw_if_index,
955 si->unnumbered_sw_if_index,
956 mp->context);
957 }
958 }
959 else
960 {
961 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100962 pool_foreach (si, im->sw_interfaces)
963 {
Neale Ranns9e2f9152018-05-18 02:27:10 -0700964 if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
965 {
966 send_ip_unnumbered_details(am, reg,
967 si->sw_if_index,
968 si->unnumbered_sw_if_index,
969 mp->context);
970 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100971 }
Neale Ranns9e2f9152018-05-18 02:27:10 -0700972 /* *INDENT-ON* */
973 }
974
975 BAD_SW_IF_INDEX_LABEL;
976}
977
978static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500979vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
980{
981 vpe_api_main_t *am = &vpe_api_main;
982 vnet_main_t *vnm = vnet_get_main ();
Neale Rannscbe25aa2019-09-30 10:53:31 +0000983 //vlib_main_t *vm = vlib_get_main ();
Dave Barachb5e8a772016-12-06 12:04:42 -0500984 vnet_interface_main_t *im = &vnm->interface_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800985 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500986 vnet_sw_interface_t *si, *sorted_sis;
987 u32 sw_if_index = ~0;
988
Florin Coras6c4dae22018-01-09 06:39:23 -0800989 reg = vl_api_client_index_to_registration (mp->client_index);
990 if (!reg)
991 return;
Dave Barachb5e8a772016-12-06 12:04:42 -0500992
993 /* Gather interfaces. */
994 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
995 _vec_len (sorted_sis) = 0;
996 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100997 pool_foreach (si, im->sw_interfaces)
998 {
Dave Barachb5e8a772016-12-06 12:04:42 -0500999 vec_add1 (sorted_sis, si[0]);
Damjan Marionb2c31b62020-12-13 21:47:40 +01001000 }
Dave Barachb5e8a772016-12-06 12:04:42 -05001001 /* *INDENT-ON* */
1002
1003 vec_foreach (si, sorted_sis)
1004 {
1005 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1006 {
Neale Rannscbe25aa2019-09-30 10:53:31 +00001007 /* if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) */
1008 /* { */
1009 /* continue; */
1010 /* } */
Dave Barachb5e8a772016-12-06 12:04:42 -05001011 sw_if_index = si->sw_if_index;
Florin Coras6c4dae22018-01-09 06:39:23 -08001012 send_ip_details (am, reg, sw_if_index, mp->is_ipv6, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -05001013 }
1014 }
Matthew Smith6d5f6592019-09-18 13:51:46 -05001015
1016 vec_free (sorted_sis);
Dave Barachb5e8a772016-12-06 12:04:42 -05001017}
1018
1019static void
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001020vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t *mp)
Dave Barachb5e8a772016-12-06 12:04:42 -05001021{
1022 vl_api_set_ip_flow_hash_reply_t *rmp;
Neale Ranns227038a2017-04-21 01:07:59 -07001023 int rv;
1024 u32 table_id;
1025 flow_hash_config_t flow_hash_config = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -05001026
Neale Ranns227038a2017-04-21 01:07:59 -07001027 table_id = ntohl (mp->vrf_id);
1028
1029#define _(a,b) if (mp->a) flow_hash_config |= b;
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001030 foreach_flow_hash_bit_v1;
Neale Ranns227038a2017-04-21 01:07:59 -07001031#undef _
1032
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001033 rv = ip_flow_hash_set ((mp->is_ipv6 ? AF_IP6 : AF_IP4), table_id,
1034 flow_hash_config);
Dave Barachb5e8a772016-12-06 12:04:42 -05001035
1036 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1037}
1038
1039static void
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001040vl_api_set_ip_flow_hash_v2_t_handler (vl_api_set_ip_flow_hash_v2_t *mp)
Dave Barachb5e8a772016-12-06 12:04:42 -05001041{
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001042 vl_api_set_ip_flow_hash_v2_reply_t *rmp;
1043 ip_address_family_t af;
Dave Barachb5e8a772016-12-06 12:04:42 -05001044 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -05001045
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001046 rv = ip_address_family_decode (mp->af, &af);
Dave Barachb5e8a772016-12-06 12:04:42 -05001047
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001048 if (!rv)
1049 rv = ip_flow_hash_set (af, htonl (mp->table_id),
1050 htonl (mp->flow_hash_config));
Dave Barachb5e8a772016-12-06 12:04:42 -05001051
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001052 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_V2_REPLY);
Dave Barachb5e8a772016-12-06 12:04:42 -05001053}
1054
Neale Ranns3d5f08a2021-01-22 16:12:38 +00001055static void
1056vl_api_set_ip_flow_hash_router_id_t_handler (
1057 vl_api_set_ip_flow_hash_router_id_t *mp)
1058{
1059 vl_api_set_ip_flow_hash_router_id_reply_t *rmp;
1060 int rv = 0;
1061
1062 ip_flow_hash_router_id_set (ntohl (mp->router_id));
1063
1064 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_ROUTER_ID_REPLY);
1065}
1066
Neale Ranns32e1c012016-11-22 17:07:28 +00001067void
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001068vl_mfib_signal_send_one (vl_api_registration_t * reg,
Neale Ranns32e1c012016-11-22 17:07:28 +00001069 u32 context, const mfib_signal_t * mfs)
1070{
1071 vl_api_mfib_signal_details_t *mp;
Neale Ranns9e829a82018-12-17 05:50:32 -08001072 const mfib_prefix_t *prefix;
Neale Ranns32e1c012016-11-22 17:07:28 +00001073 mfib_table_t *mfib;
1074 mfib_itf_t *mfi;
1075
1076 mp = vl_msg_api_alloc (sizeof (*mp));
1077
Dave Barachb7b92992018-10-17 10:38:51 -04001078 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns32e1c012016-11-22 17:07:28 +00001079 mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS);
1080 mp->context = context;
1081
1082 mfi = mfib_itf_get (mfs->mfs_itf);
Neale Ranns9e829a82018-12-17 05:50:32 -08001083 prefix = mfib_entry_get_prefix (mfs->mfs_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +00001084 mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry),
Neale Ranns9e829a82018-12-17 05:50:32 -08001085 prefix->fp_proto);
Neale Ranns32e1c012016-11-22 17:07:28 +00001086 mp->table_id = ntohl (mfib->mft_table_id);
1087 mp->sw_if_index = ntohl (mfi->mfi_sw_if_index);
1088
Neale Ranns097fa662018-05-01 05:17:55 -07001089 ip_mprefix_encode (prefix, &mp->prefix);
Neale Ranns32e1c012016-11-22 17:07:28 +00001090
1091 if (0 != mfs->mfs_buffer_len)
1092 {
1093 mp->ip_packet_len = ntohs (mfs->mfs_buffer_len);
1094
1095 memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len);
1096 }
1097 else
1098 {
1099 mp->ip_packet_len = 0;
1100 }
1101
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001102 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00001103}
1104
1105static void
1106vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
1107{
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001108 vl_api_registration_t *reg;
Neale Ranns32e1c012016-11-22 17:07:28 +00001109
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001110 reg = vl_api_client_index_to_registration (mp->client_index);
1111 if (!reg)
1112 return;
Neale Ranns32e1c012016-11-22 17:07:28 +00001113
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001114 while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
Neale Ranns32e1c012016-11-22 17:07:28 +00001115 ;
1116}
Dave Barachb5e8a772016-12-06 12:04:42 -05001117
Florin Coras595992c2017-11-06 17:17:08 -08001118static void
1119 vl_api_ip_container_proxy_add_del_t_handler
1120 (vl_api_ip_container_proxy_add_del_t * mp)
1121{
1122 vl_api_ip_container_proxy_add_del_reply_t *rmp;
1123 vnet_ip_container_proxy_args_t args;
1124 int rv = 0;
1125 clib_error_t *error;
1126
Dave Barachb7b92992018-10-17 10:38:51 -04001127 clib_memset (&args, 0, sizeof (args));
Neale Ranns37029302018-08-10 05:30:06 -07001128
1129 ip_prefix_decode (&mp->pfx, &args.prefix);
1130
Florin Coras595992c2017-11-06 17:17:08 -08001131 args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1132 args.is_add = mp->is_add;
1133 if ((error = vnet_ip_container_proxy_add_del (&args)))
1134 {
1135 rv = clib_error_get_code (error);
1136 clib_error_report (error);
1137 }
1138
1139 REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
1140}
1141
Neale Ranns8f5fef22020-12-21 08:29:34 +00001142typedef struct ip_walk_ctx_t_
Matus Fabian75b9f452018-10-02 23:27:21 -07001143{
1144 vl_api_registration_t *reg;
1145 u32 context;
Neale Ranns8f5fef22020-12-21 08:29:34 +00001146} ip_walk_ctx_t;
Matus Fabian75b9f452018-10-02 23:27:21 -07001147
1148static int
1149ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
1150 void *args)
1151{
1152 vl_api_ip_container_proxy_details_t *mp;
Neale Ranns8f5fef22020-12-21 08:29:34 +00001153 ip_walk_ctx_t *ctx = args;
Matus Fabian75b9f452018-10-02 23:27:21 -07001154
1155 mp = vl_msg_api_alloc (sizeof (*mp));
1156 if (!mp)
1157 return 1;
1158
Dave Barachb7b92992018-10-17 10:38:51 -04001159 clib_memset (mp, 0, sizeof (*mp));
Matus Fabian75b9f452018-10-02 23:27:21 -07001160 mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
1161 mp->context = ctx->context;
1162
1163 mp->sw_if_index = ntohl (sw_if_index);
1164 ip_prefix_encode (pfx, &mp->prefix);
1165
1166 vl_api_send_msg (ctx->reg, (u8 *) mp);
1167
1168 return 1;
1169}
1170
1171static void
1172vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t *
1173 mp)
1174{
1175 vl_api_registration_t *reg;
1176
1177 reg = vl_api_client_index_to_registration (mp->client_index);
1178 if (!reg)
1179 return;
1180
Neale Ranns8f5fef22020-12-21 08:29:34 +00001181 ip_walk_ctx_t ctx = {
Matus Fabian75b9f452018-10-02 23:27:21 -07001182 .context = mp->context,
1183 .reg = reg,
1184 };
1185
1186 ip_container_proxy_walk (ip_container_proxy_send_details, &ctx);
1187}
1188
Neale Rannsb8d44812017-11-10 06:53:54 -08001189static void
1190vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1191{
1192 int rv = 0;
1193 vl_api_ioam_enable_reply_t *rmp;
1194 clib_error_t *error;
1195
1196 /* Ignoring the profile id as currently a single profile
1197 * is supported */
1198 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1199 mp->seqno, mp->analyse);
1200 if (error)
1201 {
1202 clib_error_report (error);
1203 rv = clib_error_get_code (error);
1204 }
1205
1206 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1207}
1208
1209static void
1210vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1211{
1212 int rv = 0;
1213 vl_api_ioam_disable_reply_t *rmp;
1214 clib_error_t *error;
1215
1216 error = clear_ioam_rewrite_fn ();
1217 if (error)
1218 {
1219 clib_error_report (error);
1220 rv = clib_error_get_code (error);
1221 }
1222
1223 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1224}
1225
1226static void
1227 vl_api_ip_source_and_port_range_check_add_del_t_handler
1228 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1229{
1230 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1231 int rv = 0;
1232
Neale Rannsb8d44812017-11-10 06:53:54 -08001233 u8 is_add = mp->is_add;
Neale Ranns37029302018-08-10 05:30:06 -07001234 fib_prefix_t pfx;
Neale Rannsb8d44812017-11-10 06:53:54 -08001235 u16 *low_ports = 0;
1236 u16 *high_ports = 0;
1237 u32 vrf_id;
1238 u16 tmp_low, tmp_high;
1239 u8 num_ranges;
1240 int i;
1241
Neale Ranns37029302018-08-10 05:30:06 -07001242 ip_prefix_decode (&mp->prefix, &pfx);
1243
Neale Rannsb8d44812017-11-10 06:53:54 -08001244 // Validate port range
1245 num_ranges = mp->number_of_ranges;
1246 if (num_ranges > 32)
1247 { // This is size of array in VPE.API
1248 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1249 goto reply;
1250 }
1251
1252 vec_reset_length (low_ports);
1253 vec_reset_length (high_ports);
1254
1255 for (i = 0; i < num_ranges; i++)
1256 {
1257 tmp_low = mp->low_ports[i];
1258 tmp_high = mp->high_ports[i];
1259 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1260 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1261 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1262 {
1263 rv = VNET_API_ERROR_INVALID_VALUE;
1264 goto reply;
1265 }
1266 vec_add1 (low_ports, tmp_low);
1267 vec_add1 (high_ports, tmp_high + 1);
1268 }
1269
Neale Rannsb8d44812017-11-10 06:53:54 -08001270 vrf_id = ntohl (mp->vrf_id);
1271
1272 if (vrf_id < 1)
1273 {
1274 rv = VNET_API_ERROR_INVALID_VALUE;
1275 goto reply;
1276 }
1277
1278
Neale Ranns37029302018-08-10 05:30:06 -07001279 if (FIB_PROTOCOL_IP6 == pfx.fp_proto)
Neale Rannsb8d44812017-11-10 06:53:54 -08001280 {
Neale Ranns37029302018-08-10 05:30:06 -07001281 rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6,
1282 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001283 vrf_id,
1284 low_ports,
1285 high_ports, is_add);
1286 }
1287 else
1288 {
Neale Ranns37029302018-08-10 05:30:06 -07001289 rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4,
1290 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001291 vrf_id,
1292 low_ports,
1293 high_ports, is_add);
1294 }
1295
1296reply:
1297 vec_free (low_ports);
1298 vec_free (high_ports);
1299 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1300}
1301
1302static void
1303 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1304 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
1305{
1306 vlib_main_t *vm = vlib_get_main ();
1307 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
1308 ip4_main_t *im = &ip4_main;
1309 int rv;
1310 u32 sw_if_index;
1311 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1312 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1313 uword *p = 0;
1314 int i;
1315
1316 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
1317 ntohl (mp->tcp_out_vrf_id);
1318 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
1319 ntohl (mp->udp_out_vrf_id);
1320 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
1321 ntohl (mp->tcp_in_vrf_id);
1322 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
1323 ntohl (mp->udp_in_vrf_id);
1324
1325
1326 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
1327 {
1328 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
1329 {
1330 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
1331
1332 if (p == 0)
1333 {
1334 rv = VNET_API_ERROR_INVALID_VALUE;
1335 goto reply;
1336 }
1337
1338 fib_index[i] = p[0];
1339 }
1340 else
1341 fib_index[i] = ~0;
1342 }
1343 sw_if_index = ntohl (mp->sw_if_index);
1344
1345 VALIDATE_SW_IF_INDEX (mp);
1346
1347 rv =
1348 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
1349 mp->is_add);
1350
1351 BAD_SW_IF_INDEX_LABEL;
1352reply:
1353
1354 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
1355}
1356
Neale Rannscbe25aa2019-09-30 10:53:31 +00001357static void
1358 vl_api_sw_interface_ip6_set_link_local_address_t_handler
1359 (vl_api_sw_interface_ip6_set_link_local_address_t * mp)
1360{
1361 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
1362 ip6_address_t ip;
1363 int rv;
1364
1365 VALIDATE_SW_IF_INDEX (mp);
1366
1367 ip6_address_decode (mp->ip, &ip);
1368
Neale Rannsec40a7d2020-04-23 07:36:12 +00001369 rv = ip6_link_set_local_address (ntohl (mp->sw_if_index), &ip);
Neale Rannscbe25aa2019-09-30 10:53:31 +00001370
1371 BAD_SW_IF_INDEX_LABEL;
1372 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
1373}
1374
Neale Ranns9db6ada2019-11-08 12:42:31 +00001375static void
Benoît Ganne58a19152021-01-18 19:24:34 +01001376vl_api_sw_interface_ip6_get_link_local_address_t_handler (
1377 vl_api_sw_interface_ip6_get_link_local_address_t *mp)
1378{
1379 vl_api_sw_interface_ip6_get_link_local_address_reply_t *rmp;
1380 const ip6_address_t *ip = NULL;
1381 int rv = 0;
1382
1383 VALIDATE_SW_IF_INDEX (mp);
1384
1385 ip = ip6_get_link_local_address (ntohl (mp->sw_if_index));
1386 if (NULL == ip)
1387 rv = VNET_API_ERROR_IP6_NOT_ENABLED;
1388
1389 BAD_SW_IF_INDEX_LABEL;
1390 /* clang-format off */
1391 REPLY_MACRO2 (VL_API_SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS_REPLY,
1392 ({
1393 if (!rv)
1394 ip6_address_encode (ip, rmp->ip);
1395 }))
1396 /* clang-format on */
1397}
1398
1399static void
Neale Ranns9db6ada2019-11-08 12:42:31 +00001400vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp)
Neale Rannsb8d44812017-11-10 06:53:54 -08001401{
Neale Ranns9db6ada2019-11-08 12:42:31 +00001402 vl_api_ip_table_replace_begin_reply_t *rmp;
1403 fib_protocol_t fproto;
1404 u32 fib_index;
1405 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -08001406
Neale Ranns9db6ada2019-11-08 12:42:31 +00001407 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1408 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
Neale Rannsb8d44812017-11-10 06:53:54 -08001409
Neale Ranns9db6ada2019-11-08 12:42:31 +00001410 if (INDEX_INVALID == fib_index)
1411 rv = VNET_API_ERROR_NO_SUCH_FIB;
1412 else
1413 {
1414 fib_table_mark (fib_index, fproto, FIB_SOURCE_API);
1415 mfib_table_mark (mfib_table_find (fproto, ntohl (mp->table.table_id)),
1416 fproto, MFIB_SOURCE_API);
Neale Rannsb8d44812017-11-10 06:53:54 -08001417 }
Neale Ranns9db6ada2019-11-08 12:42:31 +00001418 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY);
Neale Rannsb8d44812017-11-10 06:53:54 -08001419}
1420
1421static void
Neale Ranns9db6ada2019-11-08 12:42:31 +00001422vl_api_ip_table_replace_end_t_handler (vl_api_ip_table_replace_end_t * mp)
Neale Rannsb8d44812017-11-10 06:53:54 -08001423{
Neale Ranns9db6ada2019-11-08 12:42:31 +00001424 vl_api_ip_table_replace_end_reply_t *rmp;
1425 fib_protocol_t fproto;
1426 u32 fib_index;
1427 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -08001428
Neale Ranns9db6ada2019-11-08 12:42:31 +00001429 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1430 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1431
1432 if (INDEX_INVALID == fib_index)
1433 rv = VNET_API_ERROR_NO_SUCH_FIB;
Neale Rannsb8d44812017-11-10 06:53:54 -08001434 else
Neale Ranns9db6ada2019-11-08 12:42:31 +00001435 {
1436 fib_table_sweep (fib_index, fproto, FIB_SOURCE_API);
1437 mfib_table_sweep (mfib_table_find
1438 (fproto, ntohl (mp->table.table_id)), fproto,
1439 MFIB_SOURCE_API);
1440 }
1441 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY);
1442}
Neale Rannsb8d44812017-11-10 06:53:54 -08001443
Neale Ranns9db6ada2019-11-08 12:42:31 +00001444static void
1445vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
1446{
1447 vl_api_ip_table_flush_reply_t *rmp;
1448 fib_protocol_t fproto;
1449 u32 fib_index;
1450 int rv = 0;
1451
1452 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1453 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1454
1455 if (INDEX_INVALID == fib_index)
1456 rv = VNET_API_ERROR_NO_SUCH_FIB;
1457 else
1458 {
1459 vnet_main_t *vnm = vnet_get_main ();
1460 vnet_interface_main_t *im = &vnm->interface_main;
1461 vnet_sw_interface_t *si;
1462
1463 /* Shut down interfaces in this FIB / clean out intfc routes */
1464 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +01001465 pool_foreach (si, im->sw_interfaces)
1466 {
Neale Ranns9db6ada2019-11-08 12:42:31 +00001467 if (fib_index == fib_table_get_index_for_sw_if_index (fproto,
1468 si->sw_if_index))
1469 {
1470 u32 flags = si->flags;
1471 flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
1472 vnet_sw_interface_set_flags (vnm, si->sw_if_index, flags);
1473 }
Damjan Marionb2c31b62020-12-13 21:47:40 +01001474 }
Neale Ranns9db6ada2019-11-08 12:42:31 +00001475 /* *INDENT-ON* */
1476
1477 fib_table_flush (fib_index, fproto, FIB_SOURCE_API);
1478 mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)),
1479 fproto, MFIB_SOURCE_API);
1480 }
1481
1482 REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY);
Neale Rannsb8d44812017-11-10 06:53:54 -08001483}
1484
Klement Sekera75e7d132017-09-20 08:26:30 +02001485void
1486vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
1487{
1488 vl_api_ip_reassembly_set_reply_t *rmp;
1489 int rv = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001490 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera75e7d132017-09-20 08:26:30 +02001491 {
Klement Sekerade34c352019-06-25 11:19:22 +00001492 case IP_REASS_TYPE_FULL:
1493 if (mp->is_ip6)
1494 {
1495 rv = ip6_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1496 clib_net_to_host_u32
1497 (mp->max_reassemblies),
1498 clib_net_to_host_u32
1499 (mp->max_reassembly_length),
1500 clib_net_to_host_u32
1501 (mp->expire_walk_interval_ms));
1502 }
1503 else
1504 {
1505 rv = ip4_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1506 clib_net_to_host_u32
1507 (mp->max_reassemblies),
1508 clib_net_to_host_u32
1509 (mp->max_reassembly_length),
1510 clib_net_to_host_u32
1511 (mp->expire_walk_interval_ms));
1512 }
1513 break;
1514 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1515 if (mp->is_ip6)
1516 {
1517 rv =
1518 ip6_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1519 clib_net_to_host_u32 (mp->max_reassemblies),
1520 clib_net_to_host_u32
1521 (mp->max_reassembly_length),
1522 clib_net_to_host_u32
1523 (mp->expire_walk_interval_ms));
1524 }
1525 else
1526 {
1527 rv = ip4_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1528 clib_net_to_host_u32 (mp->max_reassemblies),
1529 clib_net_to_host_u32
1530 (mp->max_reassembly_length),
1531 clib_net_to_host_u32
1532 (mp->expire_walk_interval_ms));
1533 }
1534 break;
Klement Sekera75e7d132017-09-20 08:26:30 +02001535 }
1536
1537 REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
1538}
1539
1540void
1541vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
1542{
Ole Troan2e1c8962019-04-10 09:44:23 +02001543 vl_api_registration_t *rp;
Klement Sekera75e7d132017-09-20 08:26:30 +02001544
Ole Troan2e1c8962019-04-10 09:44:23 +02001545 rp = vl_api_client_index_to_registration (mp->client_index);
1546 if (rp == 0)
Klement Sekera75e7d132017-09-20 08:26:30 +02001547 return;
1548
1549 vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001550 clib_memset (rmp, 0, sizeof (*rmp));
Klement Sekera75e7d132017-09-20 08:26:30 +02001551 rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
1552 rmp->context = mp->context;
1553 rmp->retval = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001554 u32 timeout_ms;
1555 u32 max_reassemblies;
1556 u32 max_reassembly_length;
1557 u32 expire_walk_interval_ms;
1558 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera75e7d132017-09-20 08:26:30 +02001559 {
Klement Sekerade34c352019-06-25 11:19:22 +00001560 case IP_REASS_TYPE_FULL:
1561 if (mp->is_ip6)
1562 {
1563 rmp->is_ip6 = 1;
1564 ip6_full_reass_get (&timeout_ms, &max_reassemblies,
1565 &max_reassembly_length,
1566 &expire_walk_interval_ms);
1567 }
1568 else
1569 {
1570 rmp->is_ip6 = 0;
1571 ip4_full_reass_get (&timeout_ms, &max_reassemblies,
1572 &max_reassembly_length,
1573 &expire_walk_interval_ms);
1574 }
1575 break;
1576 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1577 if (mp->is_ip6)
1578 {
1579 rmp->is_ip6 = 1;
1580 ip6_sv_reass_get (&timeout_ms, &max_reassemblies,
1581 &max_reassembly_length, &expire_walk_interval_ms);
1582 }
1583 else
1584 {
1585 rmp->is_ip6 = 0;
1586 ip4_sv_reass_get (&timeout_ms, &max_reassemblies,
1587 &max_reassembly_length, &expire_walk_interval_ms);
1588 }
1589 break;
Klement Sekera75e7d132017-09-20 08:26:30 +02001590 }
Matthew Smithb3174df2019-12-03 12:41:53 -06001591 rmp->timeout_ms = clib_host_to_net_u32 (timeout_ms);
1592 rmp->max_reassemblies = clib_host_to_net_u32 (max_reassemblies);
1593 rmp->max_reassembly_length = clib_host_to_net_u32 (max_reassembly_length);
Klement Sekera75e7d132017-09-20 08:26:30 +02001594 rmp->expire_walk_interval_ms =
Matthew Smithb3174df2019-12-03 12:41:53 -06001595 clib_host_to_net_u32 (expire_walk_interval_ms);
Ole Troan2e1c8962019-04-10 09:44:23 +02001596 vl_api_send_msg (rp, (u8 *) rmp);
Klement Sekera75e7d132017-09-20 08:26:30 +02001597}
1598
Klement Sekera4c533132018-02-22 11:41:12 +01001599void
1600 vl_api_ip_reassembly_enable_disable_t_handler
1601 (vl_api_ip_reassembly_enable_disable_t * mp)
1602{
1603 vl_api_ip_reassembly_enable_disable_reply_t *rmp;
1604 int rv = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001605 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera4c533132018-02-22 11:41:12 +01001606 {
Klement Sekerade34c352019-06-25 11:19:22 +00001607 case IP_REASS_TYPE_FULL:
Klement Sekera896c8962019-06-24 11:52:49 +00001608 rv =
Klement Sekerade34c352019-06-25 11:19:22 +00001609 ip4_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
1610 mp->enable_ip4);
1611 if (0 == rv)
1612 rv =
1613 ip6_full_reass_enable_disable (clib_net_to_host_u32
1614 (mp->sw_if_index), mp->enable_ip6);
1615 break;
1616 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1617 rv =
1618 ip4_sv_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
1619 mp->enable_ip4);
1620 if (0 == rv)
1621 {
1622 rv =
1623 ip6_sv_reass_enable_disable (clib_net_to_host_u32
1624 (mp->sw_if_index), mp->enable_ip6);
1625 }
1626 break;
Klement Sekera4c533132018-02-22 11:41:12 +01001627 }
1628
Choree7f61d12018-11-28 10:27:58 +03301629 REPLY_MACRO (VL_API_IP_REASSEMBLY_ENABLE_DISABLE_REPLY);
Klement Sekera4c533132018-02-22 11:41:12 +01001630}
1631
Neale Ranns92207752019-06-03 13:21:40 +00001632static walk_rc_t
1633send_ip_punt_redirect_details (u32 rx_sw_if_index,
1634 const ip_punt_redirect_rx_t * ipr, void *arg)
1635{
Pavel Kotucek609e1212018-11-27 09:59:44 +01001636 vl_api_ip_punt_redirect_details_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07001637 fib_path_encode_ctx_t path_ctx = {
1638 .rpaths = NULL,
1639 };
Neale Ranns8f5fef22020-12-21 08:29:34 +00001640 ip_walk_ctx_t *ctx = arg;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001641
1642 mp = vl_msg_api_alloc (sizeof (*mp));
1643 if (!mp)
Neale Ranns92207752019-06-03 13:21:40 +00001644 return (WALK_STOP);;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001645
1646 clib_memset (mp, 0, sizeof (*mp));
1647 mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
Neale Ranns92207752019-06-03 13:21:40 +00001648 mp->context = ctx->context;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001649
Neale Ranns097fa662018-05-01 05:17:55 -07001650 fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &path_ctx);
Neale Ranns92207752019-06-03 13:21:40 +00001651
1652 mp->punt.rx_sw_if_index = htonl (rx_sw_if_index);
Neale Ranns097fa662018-05-01 05:17:55 -07001653 mp->punt.tx_sw_if_index = htonl (path_ctx.rpaths[0].frp_sw_if_index);
Neale Ranns92207752019-06-03 13:21:40 +00001654
Neale Ranns097fa662018-05-01 05:17:55 -07001655 ip_address_encode (&path_ctx.rpaths[0].frp_addr,
Neale Ranns92207752019-06-03 13:21:40 +00001656 fib_proto_to_ip46 (ipr->fproto), &mp->punt.nh);
1657
1658 vl_api_send_msg (ctx->reg, (u8 *) mp);
1659
Neale Ranns097fa662018-05-01 05:17:55 -07001660 vec_free (path_ctx.rpaths);
Neale Ranns92207752019-06-03 13:21:40 +00001661
1662 return (WALK_CONTINUE);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001663}
1664
1665static void
1666vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp)
1667{
1668 vl_api_registration_t *reg;
Dave Barach77841402020-04-29 17:04:10 -04001669 fib_protocol_t fproto = FIB_PROTOCOL_IP4;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001670
Pavel Kotucek609e1212018-11-27 09:59:44 +01001671 reg = vl_api_client_index_to_registration (mp->client_index);
1672 if (!reg)
1673 return;
1674
Dave Barach77841402020-04-29 17:04:10 -04001675 if (mp->is_ipv6 == 1)
1676 fproto = FIB_PROTOCOL_IP6;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001677
Neale Ranns8f5fef22020-12-21 08:29:34 +00001678 ip_walk_ctx_t ctx = {
Neale Ranns92207752019-06-03 13:21:40 +00001679 .reg = reg,
1680 .context = mp->context,
1681 };
1682
1683 if (~0 != mp->sw_if_index)
Pavel Kotucek609e1212018-11-27 09:59:44 +01001684 {
Neale Ranns92207752019-06-03 13:21:40 +00001685 u32 rx_sw_if_index;
1686 index_t pri;
1687
1688 rx_sw_if_index = ntohl (mp->sw_if_index);
1689 pri = ip_punt_redirect_find (fproto, rx_sw_if_index);
1690
1691 if (INDEX_INVALID == pri)
1692 return;
1693
1694 send_ip_punt_redirect_details (rx_sw_if_index,
1695 ip_punt_redirect_get (pri), &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001696 }
1697 else
Neale Ranns92207752019-06-03 13:21:40 +00001698 ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001699}
1700
Neale Ranns8f5fef22020-12-21 08:29:34 +00001701void
1702vl_api_ip_path_mtu_update_t_handler (vl_api_ip_path_mtu_update_t *mp)
1703{
1704 vl_api_ip_path_mtu_update_reply_t *rmp;
1705 ip_address_t nh;
1706 int rv = 0;
1707
1708 ip_address_decode2 (&mp->pmtu.nh, &nh);
1709
1710 rv = ip_path_mtu_update (&nh, ntohl (mp->pmtu.table_id),
1711 ntohs (mp->pmtu.path_mtu));
1712
1713 REPLY_MACRO (VL_API_IP_PATH_MTU_UPDATE_REPLY);
1714}
1715
1716void
1717vl_api_ip_path_mtu_replace_begin_t_handler (
1718 vl_api_ip_path_mtu_replace_begin_t *mp)
1719{
1720 vl_api_ip_path_mtu_replace_begin_reply_t *rmp;
1721 int rv;
1722
1723 rv = ip_path_mtu_replace_begin ();
1724
1725 REPLY_MACRO (VL_API_IP_PATH_MTU_REPLACE_BEGIN_REPLY);
1726}
1727
1728void
1729vl_api_ip_path_mtu_replace_end_t_handler (vl_api_ip_path_mtu_replace_end_t *mp)
1730{
1731 vl_api_ip_path_mtu_replace_end_reply_t *rmp;
1732 int rv;
1733
1734 rv = ip_path_mtu_replace_end ();
1735
1736 REPLY_MACRO (VL_API_IP_PATH_MTU_REPLACE_END_REPLY);
1737}
1738
1739static void
1740send_ip_path_mtu_details (index_t ipti, vl_api_registration_t *rp, u32 context)
1741{
1742 vl_api_ip_path_mtu_details_t *rmp;
1743 ip_address_t ip;
1744 ip_pmtu_t *ipt;
1745
1746 ipt = ip_path_mtu_get (ipti);
1747
1748 REPLY_MACRO_DETAILS4 (VL_API_IP_PATH_MTU_DETAILS, rp, context, ({
1749 ip_pmtu_get_ip (ipt, &ip);
1750 ip_address_encode2 (&ip, &rmp->pmtu.nh);
1751 rmp->pmtu.table_id =
1752 htonl (ip_pmtu_get_table_id (ipt));
1753 rmp->pmtu.path_mtu = htons (ipt->ipt_cfg_pmtu);
1754 }));
1755}
1756
1757static void
1758vl_api_ip_path_mtu_get_t_handler (vl_api_ip_path_mtu_get_t *mp)
1759{
1760 vl_api_ip_path_mtu_get_reply_t *rmp;
1761 i32 rv = 0;
1762
1763 REPLY_AND_DETAILS_MACRO (
1764 VL_API_IP_PATH_MTU_GET_REPLY, ip_pmtu_pool,
1765 ({ send_ip_path_mtu_details (cursor, rp, mp->context); }));
1766}
1767
Dave Barachb5e8a772016-12-06 12:04:42 -05001768#define vl_msg_name_crc_list
1769#include <vnet/ip/ip.api.h>
1770#undef vl_msg_name_crc_list
1771
1772static void
1773setup_message_id_table (api_main_t * am)
1774{
1775#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1776 foreach_vl_msg_name_crc_ip;
1777#undef _
1778}
1779
1780static clib_error_t *
1781ip_api_hookup (vlib_main_t * vm)
1782{
Dave Barach39d69112019-11-27 11:42:13 -05001783 api_main_t *am = vlibapi_get_main ();
Dave Barachb5e8a772016-12-06 12:04:42 -05001784
1785#define _(N,n) \
1786 vl_msg_api_set_handlers(VL_API_##N, #n, \
1787 vl_api_##n##_t_handler, \
1788 vl_noop_handler, \
1789 vl_api_##n##_t_endian, \
1790 vl_api_##n##_t_print, \
1791 sizeof(vl_api_##n##_t), 1);
1792 foreach_ip_api_msg;
1793#undef _
1794
1795 /*
Neale Ranns6a231a12018-10-17 06:38:00 +00001796 * Mark the route add/del API as MP safe
1797 */
Neale Ranns097fa662018-05-01 05:17:55 -07001798 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1;
1799 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL_REPLY] = 1;
Neale Ranns6a231a12018-10-17 06:38:00 +00001800
1801 /*
Dave Barachb5e8a772016-12-06 12:04:42 -05001802 * Set up the (msg_name, crc, message-id) table
1803 */
1804 setup_message_id_table (am);
1805
Dave Barachb5e8a772016-12-06 12:04:42 -05001806 return 0;
1807}
1808
1809VLIB_API_INIT_FUNCTION (ip_api_hookup);
1810
1811/*
1812 * fd.io coding-style-patch-verification: ON
1813 *
1814 * Local Variables:
1815 * eval: (c-set-style "gnu")
1816 * End:
1817 */