blob: 3bf404baadf3f746d57156ed303269f4792e4866 [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>
Dave Barachb5e8a772016-12-06 12:04:42 -050031#include <vnet/fib/fib_table.h>
32#include <vnet/fib/fib_api.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050033#include <vnet/ethernet/arp_packet.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080034#include <vnet/mfib/ip6_mfib.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000035#include <vnet/mfib/ip4_mfib.h>
36#include <vnet/mfib/mfib_signal.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080037#include <vnet/mfib/mfib_entry.h>
Neale Ranns097fa662018-05-01 05:17:55 -070038#include <vnet/mfib/mfib_api.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080039#include <vnet/ip/ip_source_and_port_range_check.h>
Neale Ranns92207752019-06-03 13:21:40 +000040#include <vnet/fib/fib_path_list.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080041#include <vnet/ip/ip6_hop_by_hop.h>
Neale Rannscbe25aa2019-09-30 10:53:31 +000042#include <vnet/ip/ip6_link.h>
Klement Sekerade34c352019-06-25 11:19:22 +000043#include <vnet/ip/reass/ip4_sv_reass.h>
Klement Sekera896c8962019-06-24 11:52:49 +000044#include <vnet/ip/reass/ip4_full_reass.h>
Klement Sekerade34c352019-06-25 11:19:22 +000045#include <vnet/ip/reass/ip6_sv_reass.h>
Klement Sekera896c8962019-06-24 11:52:49 +000046#include <vnet/ip/reass/ip6_full_reass.h>
Steven Luongc3ed1c92020-07-27 10:06:58 -070047#include <vnet/ip/ip_table.h>
Neale Rannse4031132020-10-26 13:00:06 +000048#include <vnet/ip/ip_container_proxy.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050049
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 Troan33a58172019-09-04 09:12:29 +020068#include <vnet/format_fns.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080069
Benoît Ganne58a19152021-01-18 19:24:34 +010070#define foreach_ip_api_msg \
71 _ (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable) \
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) \
76 _ (IP_MROUTE_ADD_DEL, ip_mroute_add_del) \
77 _ (MFIB_SIGNAL_DUMP, mfib_signal_dump) \
78 _ (IP_ADDRESS_DUMP, ip_address_dump) \
79 _ (IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \
80 _ (IP_DUMP, ip_dump) \
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) \
84 _ (IP_ROUTE_ADD_DEL, ip_route_add_del) \
85 _ (IP_ROUTE_LOOKUP, ip_route_lookup) \
86 _ (IP_TABLE_ADD_DEL, ip_table_add_del) \
87 _ (IP_PUNT_POLICE, ip_punt_police) \
88 _ (IP_PUNT_REDIRECT, ip_punt_redirect) \
89 _ (SET_IP_FLOW_HASH, set_ip_flow_hash) \
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +000090 _ (SET_IP_FLOW_HASH_V2, set_ip_flow_hash_v2) \
Neale Ranns3d5f08a2021-01-22 16:12:38 +000091 _ (SET_IP_FLOW_HASH_ROUTER_ID, set_ip_flow_hash_router_id) \
Benoît Ganne58a19152021-01-18 19:24:34 +010092 _ (IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \
93 _ (IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \
94 _ (IOAM_ENABLE, ioam_enable) \
95 _ (IOAM_DISABLE, ioam_disable) \
96 _ (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
97 ip_source_and_port_range_check_add_del) \
98 _ (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
99 ip_source_and_port_range_check_interface_add_del) \
100 _ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
101 sw_interface_ip6_set_link_local_address) \
102 _ (SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS, \
103 sw_interface_ip6_get_link_local_address) \
104 _ (IP_REASSEMBLY_SET, ip_reassembly_set) \
105 _ (IP_REASSEMBLY_GET, ip_reassembly_get) \
106 _ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
107 _ (IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
Pavel Kotucek609e1212018-11-27 09:59:44 +0100108
Dave Barachb5e8a772016-12-06 12:04:42 -0500109static void
Neale Rannscbe25aa2019-09-30 10:53:31 +0000110 vl_api_sw_interface_ip6_enable_disable_t_handler
111 (vl_api_sw_interface_ip6_enable_disable_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500112{
Neale Rannscbe25aa2019-09-30 10:53:31 +0000113 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
114 int rv = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500115
Neale Rannscbe25aa2019-09-30 10:53:31 +0000116 VALIDATE_SW_IF_INDEX (mp);
Neale Ranns37029302018-08-10 05:30:06 -0700117
Neale Rannscbe25aa2019-09-30 10:53:31 +0000118 rv = ((mp->enable == 1) ?
Neale Rannsec40a7d2020-04-23 07:36:12 +0000119 ip6_link_enable (ntohl (mp->sw_if_index), NULL) :
Neale Rannscbe25aa2019-09-30 10:53:31 +0000120 ip6_link_disable (ntohl (mp->sw_if_index)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500121
Neale Rannscbe25aa2019-09-30 10:53:31 +0000122 BAD_SW_IF_INDEX_LABEL;
Dave Barachb5e8a772016-12-06 12:04:42 -0500123
Neale Rannscbe25aa2019-09-30 10:53:31 +0000124 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
Dave Barachb5e8a772016-12-06 12:04:42 -0500125}
126
Dave Barachb5e8a772016-12-06 12:04:42 -0500127static void
Neale Ranns097fa662018-05-01 05:17:55 -0700128send_ip_table_details (vpe_api_main_t * am,
129 vl_api_registration_t * reg,
130 u32 context, const fib_table_t * table)
Dave Barachb5e8a772016-12-06 12:04:42 -0500131{
Neale Ranns097fa662018-05-01 05:17:55 -0700132 vl_api_ip_table_details_t *mp;
Dave Barachb5e8a772016-12-06 12:04:42 -0500133
Neale Ranns097fa662018-05-01 05:17:55 -0700134 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500135 if (!mp)
136 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400137 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700138 mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500139 mp->context = context;
140
Neale Ranns097fa662018-05-01 05:17:55 -0700141 mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6);
142 mp->table.table_id = htonl (table->ft_table_id);
143 memcpy (mp->table.name, table->ft_desc,
144 clib_min (vec_len (table->ft_desc), sizeof (mp->table.name)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500145
Florin Coras6c4dae22018-01-09 06:39:23 -0800146 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500147}
148
Neale Ranns097fa662018-05-01 05:17:55 -0700149static void
150vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp)
151{
152 vpe_api_main_t *am = &vpe_api_main;
153 vl_api_registration_t *reg;
154 fib_table_t *fib_table;
155
156 reg = vl_api_client_index_to_registration (mp->client_index);
157 if (!reg)
158 return;
159
160 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100161 pool_foreach (fib_table, ip4_main.fibs)
162 {
Neale Ranns097fa662018-05-01 05:17:55 -0700163 send_ip_table_details(am, reg, mp->context, fib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100164 }
165 pool_foreach (fib_table, ip6_main.fibs)
166 {
Neale Ranns097fa662018-05-01 05:17:55 -0700167 /* don't send link locals */
168 if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
169 continue;
170 send_ip_table_details(am, reg, mp->context, fib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100171 }
Neale Ranns097fa662018-05-01 05:17:55 -0700172 /* *INDENT-ON* */
173}
174
Neale Rannsa3af3372017-03-28 03:49:52 -0700175typedef struct vl_api_ip_fib_dump_walk_ctx_t_
176{
177 fib_node_index_t *feis;
178} vl_api_ip_fib_dump_walk_ctx_t;
179
Neale Ranns89541992017-04-06 04:41:02 -0700180static fib_table_walk_rc_t
Neale Rannsa3af3372017-03-28 03:49:52 -0700181vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg)
182{
183 vl_api_ip_fib_dump_walk_ctx_t *ctx = arg;
184
185 vec_add1 (ctx->feis, fei);
186
Neale Ranns89541992017-04-06 04:41:02 -0700187 return (FIB_TABLE_WALK_CONTINUE);
Neale Rannsa3af3372017-03-28 03:49:52 -0700188}
189
Dave Barachb5e8a772016-12-06 12:04:42 -0500190static void
Neale Ranns097fa662018-05-01 05:17:55 -0700191send_ip_route_details (vpe_api_main_t * am,
192 vl_api_registration_t * reg,
193 u32 context, fib_node_index_t fib_entry_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500194{
Neale Ranns097fa662018-05-01 05:17:55 -0700195 fib_route_path_t *rpaths, *rpath;
196 vl_api_ip_route_details_t *mp;
Neale Rannsc5d43172018-07-30 08:04:40 -0700197 const fib_prefix_t *pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -0500198 vl_api_fib_path_t *fp;
199 int path_count;
200
Neale Ranns097fa662018-05-01 05:17:55 -0700201 rpaths = NULL;
202 pfx = fib_entry_get_prefix (fib_entry_index);
203 rpaths = fib_entry_encode (fib_entry_index);
204
205 path_count = vec_len (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500206 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
207 if (!mp)
208 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400209 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700210 mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500211 mp->context = context;
212
Neale Ranns097fa662018-05-01 05:17:55 -0700213 ip_prefix_encode (pfx, &mp->route.prefix);
214 mp->route.table_id =
215 htonl (fib_table_get_table_id
216 (fib_entry_get_fib_index (fib_entry_index), pfx->fp_proto));
217 mp->route.n_paths = path_count;
218 mp->route.stats_index =
219 htonl (fib_table_entry_get_stats_index
220 (fib_entry_get_fib_index (fib_entry_index), pfx));
Dave Barachb5e8a772016-12-06 12:04:42 -0500221
Neale Ranns097fa662018-05-01 05:17:55 -0700222 fp = mp->route.paths;
223 vec_foreach (rpath, rpaths)
Dave Barachb5e8a772016-12-06 12:04:42 -0500224 {
Neale Ranns097fa662018-05-01 05:17:55 -0700225 fib_api_path_encode (rpath, fp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500226 fp++;
227 }
228
Florin Coras6c4dae22018-01-09 06:39:23 -0800229 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns9db6ada2019-11-08 12:42:31 +0000230 vec_free (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500231}
232
Dave Barachd7cb1b52016-12-09 09:52:16 -0500233typedef struct apt_ip6_fib_show_ctx_t_
234{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500235 fib_node_index_t *entries;
Dave Barachb5e8a772016-12-06 12:04:42 -0500236} api_ip6_fib_show_ctx_t;
237
Dave Barachb5e8a772016-12-06 12:04:42 -0500238static void
Neale Ranns097fa662018-05-01 05:17:55 -0700239vl_api_ip_route_dump_t_handler (vl_api_ip_route_dump_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500240{
241 vpe_api_main_t *am = &vpe_api_main;
Dave Barachb5e8a772016-12-06 12:04:42 -0500242 fib_node_index_t *fib_entry_index;
Florin Coras6c4dae22018-01-09 06:39:23 -0800243 vl_api_registration_t *reg;
Neale Ranns097fa662018-05-01 05:17:55 -0700244 fib_protocol_t fproto;
245 u32 fib_index;
Dave Barachb5e8a772016-12-06 12:04:42 -0500246
Florin Coras6c4dae22018-01-09 06:39:23 -0800247 reg = vl_api_client_index_to_registration (mp->client_index);
248 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500249 return;
250
Neale Ranns097fa662018-05-01 05:17:55 -0700251 vl_api_ip_fib_dump_walk_ctx_t ctx = {
252 .feis = NULL,
253 };
Neale Ranns81458422018-03-12 06:59:36 -0700254
Neale Ranns097fa662018-05-01 05:17:55 -0700255 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
256 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
257
258 if (INDEX_INVALID == fib_index)
259 return;
260
261 fib_table_walk (fib_index, fproto, vl_api_ip_fib_dump_walk, &ctx);
262
263 vec_foreach (fib_entry_index, ctx.feis)
264 {
265 send_ip_route_details (am, reg, mp->context, *fib_entry_index);
266 }
267
268 vec_free (ctx.feis);
Dave Barachb5e8a772016-12-06 12:04:42 -0500269}
270
271static void
Neale Ranns097fa662018-05-01 05:17:55 -0700272send_ip_mtable_details (vl_api_registration_t * reg,
273 u32 context, const mfib_table_t * mfib_table)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800274{
Neale Ranns097fa662018-05-01 05:17:55 -0700275 vl_api_ip_mtable_details_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800276
Neale Ranns097fa662018-05-01 05:17:55 -0700277 mp = vl_msg_api_alloc (sizeof (*mp));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800278 if (!mp)
279 return;
Neale Ranns097fa662018-05-01 05:17:55 -0700280 memset (mp, 0, sizeof (*mp));
281 mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800282 mp->context = context;
283
Neale Ranns097fa662018-05-01 05:17:55 -0700284 mp->table.table_id = htonl (mfib_table->mft_table_id);
285 mp->table.is_ip6 = (FIB_PROTOCOL_IP6 == mfib_table->mft_proto);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800286
Florin Coras6c4dae22018-01-09 06:39:23 -0800287 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800288}
289
Neale Ranns5a8123b2017-01-26 01:18:23 -0800290static void
Neale Ranns097fa662018-05-01 05:17:55 -0700291vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800292{
Florin Coras6c4dae22018-01-09 06:39:23 -0800293 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800294 mfib_table_t *mfib_table;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800295
Florin Coras6c4dae22018-01-09 06:39:23 -0800296 reg = vl_api_client_index_to_registration (mp->client_index);
297 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800298 return;
299
Neale Ranns5a8123b2017-01-26 01:18:23 -0800300 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100301 pool_foreach (mfib_table, ip4_main.mfibs)
302 {
Neale Ranns097fa662018-05-01 05:17:55 -0700303 send_ip_mtable_details (reg, mp->context, mfib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100304 }
305 pool_foreach (mfib_table, ip6_main.mfibs)
306 {
Neale Ranns097fa662018-05-01 05:17:55 -0700307 send_ip_mtable_details (reg, mp->context, mfib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100308 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800309 /* *INDENT-ON* */
Neale Ranns5a8123b2017-01-26 01:18:23 -0800310}
311
Neale Ranns097fa662018-05-01 05:17:55 -0700312typedef struct vl_api_ip_mfib_dump_ctx_t_
Neale Ranns5a8123b2017-01-26 01:18:23 -0800313{
314 fib_node_index_t *entries;
Neale Ranns097fa662018-05-01 05:17:55 -0700315} vl_api_ip_mfib_dump_ctx_t;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800316
Neale Ranns9db6ada2019-11-08 12:42:31 +0000317static walk_rc_t
Neale Ranns097fa662018-05-01 05:17:55 -0700318mfib_route_dump_walk (fib_node_index_t fei, void *arg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800319{
Neale Ranns097fa662018-05-01 05:17:55 -0700320 vl_api_ip_mfib_dump_ctx_t *ctx = arg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800321
322 vec_add1 (ctx->entries, fei);
323
Neale Ranns9db6ada2019-11-08 12:42:31 +0000324 return (WALK_CONTINUE);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800325}
326
327static void
Neale Ranns097fa662018-05-01 05:17:55 -0700328send_ip_mroute_details (vpe_api_main_t * am,
329 vl_api_registration_t * reg,
330 u32 context, fib_node_index_t mfib_entry_index)
331{
332 fib_route_path_t *rpaths, *rpath;
333 vl_api_ip_mroute_details_t *mp;
334 const mfib_prefix_t *pfx;
335 vl_api_mfib_path_t *fp;
Matthew Smitha2bbeb82020-09-17 16:33:10 -0500336 u8 path_count;
Neale Ranns097fa662018-05-01 05:17:55 -0700337
338 rpaths = NULL;
339 pfx = mfib_entry_get_prefix (mfib_entry_index);
340 rpaths = mfib_entry_encode (mfib_entry_index);
341
342 path_count = vec_len (rpaths);
343 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
344 if (!mp)
345 return;
346 clib_memset (mp, 0, sizeof (*mp));
347 mp->_vl_msg_id = ntohs (VL_API_IP_MROUTE_DETAILS);
348 mp->context = context;
349
350 ip_mprefix_encode (pfx, &mp->route.prefix);
351 mp->route.table_id =
352 htonl (mfib_table_get_table_id
353 (mfib_entry_get_fib_index (mfib_entry_index), pfx->fp_proto));
Matthew Smitha2bbeb82020-09-17 16:33:10 -0500354 mp->route.n_paths = path_count;
Neale Ranns097fa662018-05-01 05:17:55 -0700355 fp = mp->route.paths;
356 vec_foreach (rpath, rpaths)
357 {
358 mfib_api_path_encode (rpath, fp);
359 fp++;
360 }
361
362 vl_api_send_msg (reg, (u8 *) mp);
363 vec_free (rpaths);
364}
365
366static void
367vl_api_ip_mroute_dump_t_handler (vl_api_ip_mroute_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800368{
369 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800370 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800371 fib_node_index_t *mfeip;
Neale Ranns097fa662018-05-01 05:17:55 -0700372 fib_protocol_t fproto;
373 u32 fib_index;
374
375 vl_api_ip_mfib_dump_ctx_t ctx = {
Neale Ranns5a8123b2017-01-26 01:18:23 -0800376 .entries = NULL,
377 };
378
Florin Coras6c4dae22018-01-09 06:39:23 -0800379 reg = vl_api_client_index_to_registration (mp->client_index);
380 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800381 return;
382
Neale Ranns097fa662018-05-01 05:17:55 -0700383 fproto = fib_ip_proto (mp->table.is_ip6);
384 fib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800385
Neale Ranns097fa662018-05-01 05:17:55 -0700386 if (INDEX_INVALID == fib_index)
387 return;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800388
Neale Ranns097fa662018-05-01 05:17:55 -0700389 mfib_table_walk (fib_index, fproto, mfib_route_dump_walk, &ctx);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800390
Neale Ranns097fa662018-05-01 05:17:55 -0700391 vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800392
Neale Ranns097fa662018-05-01 05:17:55 -0700393 vec_foreach (mfeip, ctx.entries)
394 {
395 send_ip_mroute_details (am, reg, mp->context, *mfeip);
396 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800397
398 vec_free (ctx.entries);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800399}
400
401static void
Neale Rannsd91c1db2017-07-31 02:30:50 -0700402vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp,
403 vlib_main_t * vm)
404{
405 vl_api_ip_punt_police_reply_t *rmp;
406 int rv = 0;
407
408 if (mp->is_ip6)
409 ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
410 else
411 ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
412
413 REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY);
414}
415
416static void
417vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp,
418 vlib_main_t * vm)
419{
420 vl_api_ip_punt_redirect_reply_t *rmp;
421 int rv = 0;
Pavel Kotucek609e1212018-11-27 09:59:44 +0100422 ip46_type_t ipv;
423 ip46_address_t nh;
Neale Rannsd91c1db2017-07-31 02:30:50 -0700424
Pavel Kotucek609e1212018-11-27 09:59:44 +0100425 if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index)))
426 goto bad_sw_if_index;
427
428 ipv = ip_address_decode (&mp->punt.nh, &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700429 if (mp->is_add)
430 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100431 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700432 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100433 ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
434 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700435 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100436 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700437 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100438 ip4_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 }
441 }
442 else
443 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100444 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700445 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100446 ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700447 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100448 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700449 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100450 ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700451 }
452 }
453
Pavel Kotucek609e1212018-11-27 09:59:44 +0100454 BAD_SW_IF_INDEX_LABEL;
455
Neale Rannsd91c1db2017-07-31 02:30:50 -0700456 REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY);
457}
458
Steven Luongc3ed1c92020-07-27 10:06:58 -0700459static clib_error_t *
460call_elf_section_ip_table_callbacks (vnet_main_t * vnm, u32 table_id,
461 u32 flags,
462 _vnet_ip_table_function_list_elt_t **
463 elts)
464{
465 _vnet_ip_table_function_list_elt_t *elt;
466 vnet_ip_table_function_priority_t prio;
467 clib_error_t *error = 0;
468
469 for (prio = VNET_IP_TABLE_FUNC_PRIORITY_LOW;
470 prio <= VNET_IP_TABLE_FUNC_PRIORITY_HIGH; prio++)
471 {
472 elt = elts[prio];
473
474 while (elt)
475 {
476 error = elt->fp (vnm, table_id, flags);
477 if (error)
478 return error;
479 elt = elt->next_ip_table_function;
480 }
481 }
482 return error;
483}
484
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700485void
Neale Ranns15002542017-09-10 04:39:11 -0700486ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api)
487{
488 u32 fib_index, mfib_index;
Steven Luongc3ed1c92020-07-27 10:06:58 -0700489 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns15002542017-09-10 04:39:11 -0700490
491 /*
492 * ignore action on the default table - this is always present
493 * and cannot be added nor deleted from the API
494 */
495 if (0 != table_id)
496 {
497 /*
498 * The API holds only one lock on the table.
499 * i.e. it can be added many times via the API but needs to be
500 * deleted only once.
501 * The FIB index for unicast and multicast is not necessarily the
502 * same, since internal VPP systesm (like LISP and SR) create
503 * their own unicast tables.
504 */
505 fib_index = fib_table_find (fproto, table_id);
506 mfib_index = mfib_table_find (fproto, table_id);
507
Steven Luongc3ed1c92020-07-27 10:06:58 -0700508 if ((~0 != fib_index) || (~0 != mfib_index))
509 call_elf_section_ip_table_callbacks (vnm, table_id, 0 /* is_add */ ,
510 vnm->ip_table_add_del_functions);
511
Neale Ranns15002542017-09-10 04:39:11 -0700512 if (~0 != fib_index)
513 {
514 fib_table_unlock (fib_index, fproto,
515 (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI));
516 }
517 if (~0 != mfib_index)
518 {
519 mfib_table_unlock (mfib_index, fproto,
520 (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI));
521 }
522 }
523}
524
525void
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700526vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
527{
528 vl_api_ip_table_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700529 fib_protocol_t fproto = (mp->table.is_ip6 ?
530 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
531 u32 table_id = ntohl (mp->table.table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700532 int rv = 0;
533
Neale Ranns15002542017-09-10 04:39:11 -0700534 if (mp->is_add)
535 {
Neale Ranns097fa662018-05-01 05:17:55 -0700536 ip_table_create (fproto, table_id, 1, mp->table.name);
Neale Ranns15002542017-09-10 04:39:11 -0700537 }
538 else
539 {
540 ip_table_delete (fproto, table_id, 1);
541 }
542
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700543 REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY);
544}
545
Dave Barachb5e8a772016-12-06 12:04:42 -0500546static int
Neale Ranns097fa662018-05-01 05:17:55 -0700547ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp, u32 * stats_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500548{
Neale Ranns097fa662018-05-01 05:17:55 -0700549 fib_route_path_t *rpaths = NULL, *rpath;
550 fib_entry_flag_t entry_flags;
551 vl_api_fib_path_t *apath;
552 fib_prefix_t pfx;
553 u32 fib_index;
554 int rv, ii;
Dave Barachb5e8a772016-12-06 12:04:42 -0500555
Neale Ranns097fa662018-05-01 05:17:55 -0700556 entry_flags = FIB_ENTRY_FLAG_NONE;
557 ip_prefix_decode (&mp->route.prefix, &pfx);
Dave Barachb5e8a772016-12-06 12:04:42 -0500558
Neale Ranns097fa662018-05-01 05:17:55 -0700559 rv = fib_api_table_id_decode (pfx.fp_proto,
560 ntohl (mp->route.table_id), &fib_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500561 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700562 goto out;
Dave Barachb5e8a772016-12-06 12:04:42 -0500563
Neale Rannsc2ac2352019-07-02 14:33:29 +0000564 if (0 != mp->route.n_paths)
565 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns097fa662018-05-01 05:17:55 -0700566
567 for (ii = 0; ii < mp->route.n_paths; ii++)
568 {
569 apath = &mp->route.paths[ii];
570 rpath = &rpaths[ii];
571
572 rv = fib_api_path_decode (apath, rpath);
573
574 if ((rpath->frp_flags & FIB_ROUTE_PATH_LOCAL) &&
575 (~0 == rpath->frp_sw_if_index))
576 entry_flags |= (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL);
577
578 if (0 != rv)
579 goto out;
580 }
581
Neale Rannsc2ac2352019-07-02 14:33:29 +0000582 rv = fib_api_route_add_del (mp->is_add,
583 mp->is_multipath,
584 fib_index, &pfx, entry_flags, rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700585
586 if (mp->is_add && 0 == rv)
587 *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx);
588
Neale Ranns097fa662018-05-01 05:17:55 -0700589out:
590 vec_free (rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700591
592 return (rv);
Dave Barachb5e8a772016-12-06 12:04:42 -0500593}
594
595void
Neale Ranns097fa662018-05-01 05:17:55 -0700596vl_api_ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500597{
Neale Ranns097fa662018-05-01 05:17:55 -0700598 vl_api_ip_route_add_del_reply_t *rmp;
599 u32 stats_index = ~0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500600 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -0500601
Neale Ranns097fa662018-05-01 05:17:55 -0700602 rv = ip_route_add_del_t_handler (mp, &stats_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500603
Neale Ranns008dbe12018-09-07 09:32:36 -0700604 /* *INDENT-OFF* */
Neale Ranns097fa662018-05-01 05:17:55 -0700605 REPLY_MACRO2 (VL_API_IP_ROUTE_ADD_DEL_REPLY,
Neale Ranns008dbe12018-09-07 09:32:36 -0700606 ({
607 rmp->stats_index = htonl (stats_index);
608 }))
609 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500610}
611
Neale Ranns15002542017-09-10 04:39:11 -0700612void
Christian Hoppsf5d38e02020-05-04 10:28:03 -0400613vl_api_ip_route_lookup_t_handler (vl_api_ip_route_lookup_t * mp)
614{
615 vl_api_ip_route_lookup_reply_t *rmp = NULL;
616 fib_route_path_t *rpaths = NULL, *rpath;
617 const fib_prefix_t *pfx = NULL;
618 fib_prefix_t lookup;
619 vl_api_fib_path_t *fp;
620 fib_node_index_t fib_entry_index;
621 u32 fib_index;
622 int npaths = 0;
623 int rv;
624
625 ip_prefix_decode (&mp->prefix, &lookup);
626 rv = fib_api_table_id_decode (lookup.fp_proto, ntohl (mp->table_id),
627 &fib_index);
628 if (PREDICT_TRUE (!rv))
629 {
630 if (mp->exact)
631 fib_entry_index = fib_table_lookup_exact_match (fib_index, &lookup);
632 else
633 fib_entry_index = fib_table_lookup (fib_index, &lookup);
634 if (fib_entry_index == FIB_NODE_INDEX_INVALID)
635 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
636 else
637 {
638 pfx = fib_entry_get_prefix (fib_entry_index);
639 rpaths = fib_entry_encode (fib_entry_index);
640 npaths = vec_len (rpaths);
641 }
642 }
643
644 /* *INDENT-OFF* */
645 REPLY_MACRO3_ZERO(VL_API_IP_ROUTE_LOOKUP_REPLY,
646 npaths * sizeof (*fp),
647 ({
648 if (!rv)
649 {
650 ip_prefix_encode (pfx, &rmp->route.prefix);
651 rmp->route.table_id = mp->table_id;
652 rmp->route.n_paths = npaths;
653 rmp->route.stats_index = fib_table_entry_get_stats_index (fib_index, pfx);
654 rmp->route.stats_index = htonl (rmp->route.stats_index);
655
656 fp = rmp->route.paths;
657 vec_foreach (rpath, rpaths)
658 {
659 fib_api_path_encode (rpath, fp);
660 fp++;
661 }
662 }
663 }));
664 /* *INDENT-ON* */
665 vec_free (rpaths);
666}
667
668void
Neale Ranns2297af02017-09-12 09:45:04 -0700669ip_table_create (fib_protocol_t fproto,
670 u32 table_id, u8 is_api, const u8 * name)
Neale Ranns15002542017-09-10 04:39:11 -0700671{
672 u32 fib_index, mfib_index;
Steven Luongc3ed1c92020-07-27 10:06:58 -0700673 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns15002542017-09-10 04:39:11 -0700674
675 /*
676 * ignore action on the default table - this is always present
677 * and cannot be added nor deleted from the API
678 */
679 if (0 != table_id)
680 {
681 /*
682 * The API holds only one lock on the table.
683 * i.e. it can be added many times via the API but needs to be
684 * deleted only once.
685 * The FIB index for unicast and multicast is not necessarily the
686 * same, since internal VPP systesm (like LISP and SR) create
687 * their own unicast tables.
688 */
689 fib_index = fib_table_find (fproto, table_id);
690 mfib_index = mfib_table_find (fproto, table_id);
691
692 if (~0 == fib_index)
693 {
Neale Ranns2297af02017-09-12 09:45:04 -0700694 fib_table_find_or_create_and_lock_w_name (fproto, table_id,
695 (is_api ?
696 FIB_SOURCE_API :
697 FIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700698 }
699 if (~0 == mfib_index)
700 {
Neale Ranns2297af02017-09-12 09:45:04 -0700701 mfib_table_find_or_create_and_lock_w_name (fproto, table_id,
702 (is_api ?
703 MFIB_SOURCE_API :
704 MFIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700705 }
Steven Luongc3ed1c92020-07-27 10:06:58 -0700706
707 if ((~0 == fib_index) || (~0 == mfib_index))
708 call_elf_section_ip_table_callbacks (vnm, table_id, 1 /* is_add */ ,
709 vnm->ip_table_add_del_functions);
Neale Ranns15002542017-09-10 04:39:11 -0700710 }
711}
712
Neale Ranns097fa662018-05-01 05:17:55 -0700713static u32
Neale Ranns32e1c012016-11-22 17:07:28 +0000714mroute_add_del_handler (u8 is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700715 u8 is_multipath,
Neale Ranns32e1c012016-11-22 17:07:28 +0000716 u32 fib_index,
717 const mfib_prefix_t * prefix,
718 u32 entry_flags,
Neale Ranns097fa662018-05-01 05:17:55 -0700719 u32 rpf_id, fib_route_path_t * rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +0000720{
Neale Ranns097fa662018-05-01 05:17:55 -0700721 u32 mfib_entry_index = ~0;
Neale Ranns28c142e2018-09-07 09:37:07 -0700722
Neale Ranns097fa662018-05-01 05:17:55 -0700723 if (0 == vec_len (rpaths))
Neale Ranns32e1c012016-11-22 17:07:28 +0000724 {
Neale Ranns28c142e2018-09-07 09:37:07 -0700725 mfib_entry_index = mfib_table_entry_update (fib_index, prefix,
726 MFIB_SOURCE_API,
727 rpf_id, entry_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +0000728 }
729 else
730 {
Neale Ranns097fa662018-05-01 05:17:55 -0700731 if (is_add)
732 {
733 mfib_entry_index =
734 mfib_table_entry_paths_update (fib_index, prefix,
735 MFIB_SOURCE_API, rpaths);
736 }
737 else
738 {
739 mfib_table_entry_paths_remove (fib_index, prefix,
740 MFIB_SOURCE_API, rpaths);
741 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000742 }
743
Neale Ranns28c142e2018-09-07 09:37:07 -0700744 return (mfib_entry_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000745}
746
747static int
Neale Ranns28c142e2018-09-07 09:37:07 -0700748api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp,
749 u32 * stats_index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000750{
Neale Ranns097fa662018-05-01 05:17:55 -0700751 fib_route_path_t *rpath, *rpaths = NULL;
Neale Ranns28c142e2018-09-07 09:37:07 -0700752 fib_node_index_t mfib_entry_index;
Neale Ranns990f6942020-10-20 07:20:17 +0000753 mfib_entry_flags_t eflags;
Neale Ranns097fa662018-05-01 05:17:55 -0700754 mfib_prefix_t pfx;
Neale Ranns32e1c012016-11-22 17:07:28 +0000755 u32 fib_index;
756 int rv;
Neale Ranns097fa662018-05-01 05:17:55 -0700757 u16 ii;
Neale Ranns32e1c012016-11-22 17:07:28 +0000758
Neale Ranns097fa662018-05-01 05:17:55 -0700759 ip_mprefix_decode (&mp->route.prefix, &pfx);
Neale Ranns32e1c012016-11-22 17:07:28 +0000760
Neale Ranns097fa662018-05-01 05:17:55 -0700761 rv = mfib_api_table_id_decode (pfx.fp_proto,
762 ntohl (mp->route.table_id), &fib_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000763 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700764 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000765
Neale Ranns097fa662018-05-01 05:17:55 -0700766 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns32e1c012016-11-22 17:07:28 +0000767
Neale Ranns097fa662018-05-01 05:17:55 -0700768 for (ii = 0; ii < mp->route.n_paths; ii++)
Neale Ranns32e1c012016-11-22 17:07:28 +0000769 {
Neale Ranns097fa662018-05-01 05:17:55 -0700770 rpath = &rpaths[ii];
771
772 rv = mfib_api_path_decode (&mp->route.paths[ii], rpath);
773
774 if (0 != rv)
775 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000776 }
777
Neale Ranns990f6942020-10-20 07:20:17 +0000778 eflags = mfib_api_path_entry_flags_decode (mp->route.entry_flags);
Neale Ranns28c142e2018-09-07 09:37:07 -0700779 mfib_entry_index = mroute_add_del_handler (mp->is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700780 mp->is_add,
Neale Ranns28c142e2018-09-07 09:37:07 -0700781 fib_index, &pfx,
Neale Ranns990f6942020-10-20 07:20:17 +0000782 eflags,
Neale Ranns097fa662018-05-01 05:17:55 -0700783 ntohl (mp->route.rpf_id),
784 rpaths);
Neale Ranns28c142e2018-09-07 09:37:07 -0700785
786 if (~0 != mfib_entry_index)
787 *stats_index = mfib_entry_get_stats_index (mfib_entry_index);
788
Neale Ranns097fa662018-05-01 05:17:55 -0700789out:
Neale Ranns28c142e2018-09-07 09:37:07 -0700790 return (rv);
Neale Ranns32e1c012016-11-22 17:07:28 +0000791}
792
793void
794vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp)
795{
796 vl_api_ip_mroute_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700797 u32 stats_index = ~0;
Neale Ranns32e1c012016-11-22 17:07:28 +0000798 int rv;
Neale Ranns32e1c012016-11-22 17:07:28 +0000799
Neale Ranns28c142e2018-09-07 09:37:07 -0700800 rv = api_mroute_add_del_t_handler (mp, &stats_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000801
Neale Ranns28c142e2018-09-07 09:37:07 -0700802 /* *INDENT-OFF* */
803 REPLY_MACRO2 (VL_API_IP_MROUTE_ADD_DEL_REPLY,
804 ({
805 rmp->stats_index = htonl (stats_index);
806 }));
807 /* *INDENT-ON* */
Neale Ranns32e1c012016-11-22 17:07:28 +0000808}
809
Dave Barachb5e8a772016-12-06 12:04:42 -0500810static void
811send_ip_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800812 vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6,
813 u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500814{
815 vl_api_ip_details_t *mp;
816
817 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400818 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500819 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
820
821 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger466f0d42017-02-09 12:17:50 -0600822 mp->is_ipv6 = is_ipv6;
Dave Barachb5e8a772016-12-06 12:04:42 -0500823 mp->context = context;
824
Florin Coras6c4dae22018-01-09 06:39:23 -0800825 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500826}
827
828static void
829send_ip_address_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800830 vl_api_registration_t * reg,
Neale Ranns097fa662018-05-01 05:17:55 -0700831 const fib_prefix_t * pfx,
832 u32 sw_if_index, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500833{
834 vl_api_ip_address_details_t *mp;
835
836 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400837 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500838 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
839
Neale Ranns097fa662018-05-01 05:17:55 -0700840 ip_prefix_encode (pfx, &mp->prefix);
Dave Barachb5e8a772016-12-06 12:04:42 -0500841 mp->context = context;
Jon Loeliger466f0d42017-02-09 12:17:50 -0600842 mp->sw_if_index = htonl (sw_if_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500843
Florin Coras6c4dae22018-01-09 06:39:23 -0800844 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500845}
846
847static void
848vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
849{
850 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800851 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500852 ip6_main_t *im6 = &ip6_main;
853 ip4_main_t *im4 = &ip4_main;
854 ip_lookup_main_t *lm6 = &im6->lookup_main;
855 ip_lookup_main_t *lm4 = &im4->lookup_main;
856 ip_interface_address_t *ia = 0;
857 u32 sw_if_index = ~0;
858 int rv __attribute__ ((unused)) = 0;
859
860 VALIDATE_SW_IF_INDEX (mp);
861
862 sw_if_index = ntohl (mp->sw_if_index);
863
Florin Coras6c4dae22018-01-09 06:39:23 -0800864 reg = vl_api_client_index_to_registration (mp->client_index);
865 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500866 return;
867
Dave Barachb5e8a772016-12-06 12:04:42 -0500868 if (mp->is_ipv6)
869 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500870 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700871 /* Do not send subnet details of the IP-interface for
872 * unnumbered interfaces. otherwise listening clients
873 * will be confused that the subnet is applied on more
874 * than one interface */
875 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500876 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700877 fib_prefix_t pfx = {
878 .fp_addr.ip6 = *(ip6_address_t *)ip_interface_address_get_address (lm6, ia),
879 .fp_len = ia->address_length,
880 .fp_proto = FIB_PROTOCOL_IP6,
881 };
882 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500883 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500884 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500885 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500886 else
887 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500888 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700889 foreach_ip_interface_address (lm4, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500890 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700891 fib_prefix_t pfx = {
892 .fp_addr.ip4 = *(ip4_address_t *)ip_interface_address_get_address (lm4, ia),
893 .fp_len = ia->address_length,
894 .fp_proto = FIB_PROTOCOL_IP4,
895 };
896
897 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500898 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500899 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500900 }
Neale Ranns008dbe12018-09-07 09:32:36 -0700901
Dave Barachb5e8a772016-12-06 12:04:42 -0500902 BAD_SW_IF_INDEX_LABEL;
903}
904
905static void
Neale Ranns9e2f9152018-05-18 02:27:10 -0700906send_ip_unnumbered_details (vpe_api_main_t * am,
907 vl_api_registration_t * reg,
908 u32 sw_if_index, u32 ip_sw_if_index, u32 context)
909{
910 vl_api_ip_unnumbered_details_t *mp;
911
912 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400913 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns9e2f9152018-05-18 02:27:10 -0700914 mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
915
916 mp->context = context;
917 mp->sw_if_index = htonl (sw_if_index);
918 mp->ip_sw_if_index = htonl (ip_sw_if_index);
919
920 vl_api_send_msg (reg, (u8 *) mp);
921}
922
923static void
924vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
925{
926 vnet_main_t *vnm = vnet_get_main ();
927 vnet_interface_main_t *im = &vnm->interface_main;
928 int rv __attribute__ ((unused)) = 0;
929 vpe_api_main_t *am = &vpe_api_main;
930 vl_api_registration_t *reg;
931 vnet_sw_interface_t *si;
932 u32 sw_if_index;
933
934 sw_if_index = ntohl (mp->sw_if_index);
935
936 reg = vl_api_client_index_to_registration (mp->client_index);
937 if (!reg)
938 return;
939
940 if (~0 != sw_if_index)
941 {
942 VALIDATE_SW_IF_INDEX (mp);
943
944 si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
945
Neale Rannsac3e72c2019-10-06 01:04:26 -0700946 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
Neale Ranns9e2f9152018-05-18 02:27:10 -0700947 {
948 send_ip_unnumbered_details (am, reg,
949 sw_if_index,
950 si->unnumbered_sw_if_index,
951 mp->context);
952 }
953 }
954 else
955 {
956 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100957 pool_foreach (si, im->sw_interfaces)
958 {
Neale Ranns9e2f9152018-05-18 02:27:10 -0700959 if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
960 {
961 send_ip_unnumbered_details(am, reg,
962 si->sw_if_index,
963 si->unnumbered_sw_if_index,
964 mp->context);
965 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100966 }
Neale Ranns9e2f9152018-05-18 02:27:10 -0700967 /* *INDENT-ON* */
968 }
969
970 BAD_SW_IF_INDEX_LABEL;
971}
972
973static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500974vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
975{
976 vpe_api_main_t *am = &vpe_api_main;
977 vnet_main_t *vnm = vnet_get_main ();
Neale Rannscbe25aa2019-09-30 10:53:31 +0000978 //vlib_main_t *vm = vlib_get_main ();
Dave Barachb5e8a772016-12-06 12:04:42 -0500979 vnet_interface_main_t *im = &vnm->interface_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800980 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500981 vnet_sw_interface_t *si, *sorted_sis;
982 u32 sw_if_index = ~0;
983
Florin Coras6c4dae22018-01-09 06:39:23 -0800984 reg = vl_api_client_index_to_registration (mp->client_index);
985 if (!reg)
986 return;
Dave Barachb5e8a772016-12-06 12:04:42 -0500987
988 /* Gather interfaces. */
989 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
990 _vec_len (sorted_sis) = 0;
991 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100992 pool_foreach (si, im->sw_interfaces)
993 {
Dave Barachb5e8a772016-12-06 12:04:42 -0500994 vec_add1 (sorted_sis, si[0]);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100995 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500996 /* *INDENT-ON* */
997
998 vec_foreach (si, sorted_sis)
999 {
1000 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1001 {
Neale Rannscbe25aa2019-09-30 10:53:31 +00001002 /* if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) */
1003 /* { */
1004 /* continue; */
1005 /* } */
Dave Barachb5e8a772016-12-06 12:04:42 -05001006 sw_if_index = si->sw_if_index;
Florin Coras6c4dae22018-01-09 06:39:23 -08001007 send_ip_details (am, reg, sw_if_index, mp->is_ipv6, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -05001008 }
1009 }
Matthew Smith6d5f6592019-09-18 13:51:46 -05001010
1011 vec_free (sorted_sis);
Dave Barachb5e8a772016-12-06 12:04:42 -05001012}
1013
1014static void
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001015vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t *mp)
Dave Barachb5e8a772016-12-06 12:04:42 -05001016{
1017 vl_api_set_ip_flow_hash_reply_t *rmp;
Neale Ranns227038a2017-04-21 01:07:59 -07001018 int rv;
1019 u32 table_id;
1020 flow_hash_config_t flow_hash_config = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -05001021
Neale Ranns227038a2017-04-21 01:07:59 -07001022 table_id = ntohl (mp->vrf_id);
1023
1024#define _(a,b) if (mp->a) flow_hash_config |= b;
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001025 foreach_flow_hash_bit_v1;
Neale Ranns227038a2017-04-21 01:07:59 -07001026#undef _
1027
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001028 rv = ip_flow_hash_set ((mp->is_ipv6 ? AF_IP6 : AF_IP4), table_id,
1029 flow_hash_config);
Dave Barachb5e8a772016-12-06 12:04:42 -05001030
1031 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1032}
1033
1034static void
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001035vl_api_set_ip_flow_hash_v2_t_handler (vl_api_set_ip_flow_hash_v2_t *mp)
Dave Barachb5e8a772016-12-06 12:04:42 -05001036{
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001037 vl_api_set_ip_flow_hash_v2_reply_t *rmp;
1038 ip_address_family_t af;
Dave Barachb5e8a772016-12-06 12:04:42 -05001039 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -05001040
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001041 rv = ip_address_family_decode (mp->af, &af);
Dave Barachb5e8a772016-12-06 12:04:42 -05001042
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001043 if (!rv)
1044 rv = ip_flow_hash_set (af, htonl (mp->table_id),
1045 htonl (mp->flow_hash_config));
Dave Barachb5e8a772016-12-06 12:04:42 -05001046
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001047 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_V2_REPLY);
Dave Barachb5e8a772016-12-06 12:04:42 -05001048}
1049
Neale Ranns3d5f08a2021-01-22 16:12:38 +00001050static void
1051vl_api_set_ip_flow_hash_router_id_t_handler (
1052 vl_api_set_ip_flow_hash_router_id_t *mp)
1053{
1054 vl_api_set_ip_flow_hash_router_id_reply_t *rmp;
1055 int rv = 0;
1056
1057 ip_flow_hash_router_id_set (ntohl (mp->router_id));
1058
1059 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_ROUTER_ID_REPLY);
1060}
1061
Neale Ranns32e1c012016-11-22 17:07:28 +00001062void
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001063vl_mfib_signal_send_one (vl_api_registration_t * reg,
Neale Ranns32e1c012016-11-22 17:07:28 +00001064 u32 context, const mfib_signal_t * mfs)
1065{
1066 vl_api_mfib_signal_details_t *mp;
Neale Ranns9e829a82018-12-17 05:50:32 -08001067 const mfib_prefix_t *prefix;
Neale Ranns32e1c012016-11-22 17:07:28 +00001068 mfib_table_t *mfib;
1069 mfib_itf_t *mfi;
1070
1071 mp = vl_msg_api_alloc (sizeof (*mp));
1072
Dave Barachb7b92992018-10-17 10:38:51 -04001073 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns32e1c012016-11-22 17:07:28 +00001074 mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS);
1075 mp->context = context;
1076
1077 mfi = mfib_itf_get (mfs->mfs_itf);
Neale Ranns9e829a82018-12-17 05:50:32 -08001078 prefix = mfib_entry_get_prefix (mfs->mfs_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +00001079 mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry),
Neale Ranns9e829a82018-12-17 05:50:32 -08001080 prefix->fp_proto);
Neale Ranns32e1c012016-11-22 17:07:28 +00001081 mp->table_id = ntohl (mfib->mft_table_id);
1082 mp->sw_if_index = ntohl (mfi->mfi_sw_if_index);
1083
Neale Ranns097fa662018-05-01 05:17:55 -07001084 ip_mprefix_encode (prefix, &mp->prefix);
Neale Ranns32e1c012016-11-22 17:07:28 +00001085
1086 if (0 != mfs->mfs_buffer_len)
1087 {
1088 mp->ip_packet_len = ntohs (mfs->mfs_buffer_len);
1089
1090 memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len);
1091 }
1092 else
1093 {
1094 mp->ip_packet_len = 0;
1095 }
1096
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001097 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00001098}
1099
1100static void
1101vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
1102{
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001103 vl_api_registration_t *reg;
Neale Ranns32e1c012016-11-22 17:07:28 +00001104
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001105 reg = vl_api_client_index_to_registration (mp->client_index);
1106 if (!reg)
1107 return;
Neale Ranns32e1c012016-11-22 17:07:28 +00001108
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001109 while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
Neale Ranns32e1c012016-11-22 17:07:28 +00001110 ;
1111}
Dave Barachb5e8a772016-12-06 12:04:42 -05001112
Florin Coras595992c2017-11-06 17:17:08 -08001113static void
1114 vl_api_ip_container_proxy_add_del_t_handler
1115 (vl_api_ip_container_proxy_add_del_t * mp)
1116{
1117 vl_api_ip_container_proxy_add_del_reply_t *rmp;
1118 vnet_ip_container_proxy_args_t args;
1119 int rv = 0;
1120 clib_error_t *error;
1121
Dave Barachb7b92992018-10-17 10:38:51 -04001122 clib_memset (&args, 0, sizeof (args));
Neale Ranns37029302018-08-10 05:30:06 -07001123
1124 ip_prefix_decode (&mp->pfx, &args.prefix);
1125
Florin Coras595992c2017-11-06 17:17:08 -08001126 args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1127 args.is_add = mp->is_add;
1128 if ((error = vnet_ip_container_proxy_add_del (&args)))
1129 {
1130 rv = clib_error_get_code (error);
1131 clib_error_report (error);
1132 }
1133
1134 REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
1135}
1136
Matus Fabian75b9f452018-10-02 23:27:21 -07001137typedef struct ip_container_proxy_walk_ctx_t_
1138{
1139 vl_api_registration_t *reg;
1140 u32 context;
1141} ip_container_proxy_walk_ctx_t;
1142
1143static int
1144ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
1145 void *args)
1146{
1147 vl_api_ip_container_proxy_details_t *mp;
1148 ip_container_proxy_walk_ctx_t *ctx = args;
1149
1150 mp = vl_msg_api_alloc (sizeof (*mp));
1151 if (!mp)
1152 return 1;
1153
Dave Barachb7b92992018-10-17 10:38:51 -04001154 clib_memset (mp, 0, sizeof (*mp));
Matus Fabian75b9f452018-10-02 23:27:21 -07001155 mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
1156 mp->context = ctx->context;
1157
1158 mp->sw_if_index = ntohl (sw_if_index);
1159 ip_prefix_encode (pfx, &mp->prefix);
1160
1161 vl_api_send_msg (ctx->reg, (u8 *) mp);
1162
1163 return 1;
1164}
1165
1166static void
1167vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t *
1168 mp)
1169{
1170 vl_api_registration_t *reg;
1171
1172 reg = vl_api_client_index_to_registration (mp->client_index);
1173 if (!reg)
1174 return;
1175
1176 ip_container_proxy_walk_ctx_t ctx = {
1177 .context = mp->context,
1178 .reg = reg,
1179 };
1180
1181 ip_container_proxy_walk (ip_container_proxy_send_details, &ctx);
1182}
1183
Neale Rannsb8d44812017-11-10 06:53:54 -08001184static void
1185vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1186{
1187 int rv = 0;
1188 vl_api_ioam_enable_reply_t *rmp;
1189 clib_error_t *error;
1190
1191 /* Ignoring the profile id as currently a single profile
1192 * is supported */
1193 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1194 mp->seqno, mp->analyse);
1195 if (error)
1196 {
1197 clib_error_report (error);
1198 rv = clib_error_get_code (error);
1199 }
1200
1201 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1202}
1203
1204static void
1205vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1206{
1207 int rv = 0;
1208 vl_api_ioam_disable_reply_t *rmp;
1209 clib_error_t *error;
1210
1211 error = clear_ioam_rewrite_fn ();
1212 if (error)
1213 {
1214 clib_error_report (error);
1215 rv = clib_error_get_code (error);
1216 }
1217
1218 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1219}
1220
1221static void
1222 vl_api_ip_source_and_port_range_check_add_del_t_handler
1223 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1224{
1225 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1226 int rv = 0;
1227
Neale Rannsb8d44812017-11-10 06:53:54 -08001228 u8 is_add = mp->is_add;
Neale Ranns37029302018-08-10 05:30:06 -07001229 fib_prefix_t pfx;
Neale Rannsb8d44812017-11-10 06:53:54 -08001230 u16 *low_ports = 0;
1231 u16 *high_ports = 0;
1232 u32 vrf_id;
1233 u16 tmp_low, tmp_high;
1234 u8 num_ranges;
1235 int i;
1236
Neale Ranns37029302018-08-10 05:30:06 -07001237 ip_prefix_decode (&mp->prefix, &pfx);
1238
Neale Rannsb8d44812017-11-10 06:53:54 -08001239 // Validate port range
1240 num_ranges = mp->number_of_ranges;
1241 if (num_ranges > 32)
1242 { // This is size of array in VPE.API
1243 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1244 goto reply;
1245 }
1246
1247 vec_reset_length (low_ports);
1248 vec_reset_length (high_ports);
1249
1250 for (i = 0; i < num_ranges; i++)
1251 {
1252 tmp_low = mp->low_ports[i];
1253 tmp_high = mp->high_ports[i];
1254 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1255 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1256 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1257 {
1258 rv = VNET_API_ERROR_INVALID_VALUE;
1259 goto reply;
1260 }
1261 vec_add1 (low_ports, tmp_low);
1262 vec_add1 (high_ports, tmp_high + 1);
1263 }
1264
Neale Rannsb8d44812017-11-10 06:53:54 -08001265 vrf_id = ntohl (mp->vrf_id);
1266
1267 if (vrf_id < 1)
1268 {
1269 rv = VNET_API_ERROR_INVALID_VALUE;
1270 goto reply;
1271 }
1272
1273
Neale Ranns37029302018-08-10 05:30:06 -07001274 if (FIB_PROTOCOL_IP6 == pfx.fp_proto)
Neale Rannsb8d44812017-11-10 06:53:54 -08001275 {
Neale Ranns37029302018-08-10 05:30:06 -07001276 rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6,
1277 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001278 vrf_id,
1279 low_ports,
1280 high_ports, is_add);
1281 }
1282 else
1283 {
Neale Ranns37029302018-08-10 05:30:06 -07001284 rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4,
1285 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001286 vrf_id,
1287 low_ports,
1288 high_ports, is_add);
1289 }
1290
1291reply:
1292 vec_free (low_ports);
1293 vec_free (high_ports);
1294 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1295}
1296
1297static void
1298 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1299 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
1300{
1301 vlib_main_t *vm = vlib_get_main ();
1302 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
1303 ip4_main_t *im = &ip4_main;
1304 int rv;
1305 u32 sw_if_index;
1306 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1307 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1308 uword *p = 0;
1309 int i;
1310
1311 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
1312 ntohl (mp->tcp_out_vrf_id);
1313 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
1314 ntohl (mp->udp_out_vrf_id);
1315 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
1316 ntohl (mp->tcp_in_vrf_id);
1317 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
1318 ntohl (mp->udp_in_vrf_id);
1319
1320
1321 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
1322 {
1323 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
1324 {
1325 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
1326
1327 if (p == 0)
1328 {
1329 rv = VNET_API_ERROR_INVALID_VALUE;
1330 goto reply;
1331 }
1332
1333 fib_index[i] = p[0];
1334 }
1335 else
1336 fib_index[i] = ~0;
1337 }
1338 sw_if_index = ntohl (mp->sw_if_index);
1339
1340 VALIDATE_SW_IF_INDEX (mp);
1341
1342 rv =
1343 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
1344 mp->is_add);
1345
1346 BAD_SW_IF_INDEX_LABEL;
1347reply:
1348
1349 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
1350}
1351
Neale Rannscbe25aa2019-09-30 10:53:31 +00001352static void
1353 vl_api_sw_interface_ip6_set_link_local_address_t_handler
1354 (vl_api_sw_interface_ip6_set_link_local_address_t * mp)
1355{
1356 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
1357 ip6_address_t ip;
1358 int rv;
1359
1360 VALIDATE_SW_IF_INDEX (mp);
1361
1362 ip6_address_decode (mp->ip, &ip);
1363
Neale Rannsec40a7d2020-04-23 07:36:12 +00001364 rv = ip6_link_set_local_address (ntohl (mp->sw_if_index), &ip);
Neale Rannscbe25aa2019-09-30 10:53:31 +00001365
1366 BAD_SW_IF_INDEX_LABEL;
1367 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
1368}
1369
Neale Ranns9db6ada2019-11-08 12:42:31 +00001370static void
Benoît Ganne58a19152021-01-18 19:24:34 +01001371vl_api_sw_interface_ip6_get_link_local_address_t_handler (
1372 vl_api_sw_interface_ip6_get_link_local_address_t *mp)
1373{
1374 vl_api_sw_interface_ip6_get_link_local_address_reply_t *rmp;
1375 const ip6_address_t *ip = NULL;
1376 int rv = 0;
1377
1378 VALIDATE_SW_IF_INDEX (mp);
1379
1380 ip = ip6_get_link_local_address (ntohl (mp->sw_if_index));
1381 if (NULL == ip)
1382 rv = VNET_API_ERROR_IP6_NOT_ENABLED;
1383
1384 BAD_SW_IF_INDEX_LABEL;
1385 /* clang-format off */
1386 REPLY_MACRO2 (VL_API_SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS_REPLY,
1387 ({
1388 if (!rv)
1389 ip6_address_encode (ip, rmp->ip);
1390 }))
1391 /* clang-format on */
1392}
1393
1394static void
Neale Ranns9db6ada2019-11-08 12:42:31 +00001395vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp)
Neale Rannsb8d44812017-11-10 06:53:54 -08001396{
Neale Ranns9db6ada2019-11-08 12:42:31 +00001397 vl_api_ip_table_replace_begin_reply_t *rmp;
1398 fib_protocol_t fproto;
1399 u32 fib_index;
1400 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -08001401
Neale Ranns9db6ada2019-11-08 12:42:31 +00001402 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1403 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
Neale Rannsb8d44812017-11-10 06:53:54 -08001404
Neale Ranns9db6ada2019-11-08 12:42:31 +00001405 if (INDEX_INVALID == fib_index)
1406 rv = VNET_API_ERROR_NO_SUCH_FIB;
1407 else
1408 {
1409 fib_table_mark (fib_index, fproto, FIB_SOURCE_API);
1410 mfib_table_mark (mfib_table_find (fproto, ntohl (mp->table.table_id)),
1411 fproto, MFIB_SOURCE_API);
Neale Rannsb8d44812017-11-10 06:53:54 -08001412 }
Neale Ranns9db6ada2019-11-08 12:42:31 +00001413 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY);
Neale Rannsb8d44812017-11-10 06:53:54 -08001414}
1415
1416static void
Neale Ranns9db6ada2019-11-08 12:42:31 +00001417vl_api_ip_table_replace_end_t_handler (vl_api_ip_table_replace_end_t * mp)
Neale Rannsb8d44812017-11-10 06:53:54 -08001418{
Neale Ranns9db6ada2019-11-08 12:42:31 +00001419 vl_api_ip_table_replace_end_reply_t *rmp;
1420 fib_protocol_t fproto;
1421 u32 fib_index;
1422 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -08001423
Neale Ranns9db6ada2019-11-08 12:42:31 +00001424 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1425 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1426
1427 if (INDEX_INVALID == fib_index)
1428 rv = VNET_API_ERROR_NO_SUCH_FIB;
Neale Rannsb8d44812017-11-10 06:53:54 -08001429 else
Neale Ranns9db6ada2019-11-08 12:42:31 +00001430 {
1431 fib_table_sweep (fib_index, fproto, FIB_SOURCE_API);
1432 mfib_table_sweep (mfib_table_find
1433 (fproto, ntohl (mp->table.table_id)), fproto,
1434 MFIB_SOURCE_API);
1435 }
1436 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY);
1437}
Neale Rannsb8d44812017-11-10 06:53:54 -08001438
Neale Ranns9db6ada2019-11-08 12:42:31 +00001439static void
1440vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
1441{
1442 vl_api_ip_table_flush_reply_t *rmp;
1443 fib_protocol_t fproto;
1444 u32 fib_index;
1445 int rv = 0;
1446
1447 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1448 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1449
1450 if (INDEX_INVALID == fib_index)
1451 rv = VNET_API_ERROR_NO_SUCH_FIB;
1452 else
1453 {
1454 vnet_main_t *vnm = vnet_get_main ();
1455 vnet_interface_main_t *im = &vnm->interface_main;
1456 vnet_sw_interface_t *si;
1457
1458 /* Shut down interfaces in this FIB / clean out intfc routes */
1459 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +01001460 pool_foreach (si, im->sw_interfaces)
1461 {
Neale Ranns9db6ada2019-11-08 12:42:31 +00001462 if (fib_index == fib_table_get_index_for_sw_if_index (fproto,
1463 si->sw_if_index))
1464 {
1465 u32 flags = si->flags;
1466 flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
1467 vnet_sw_interface_set_flags (vnm, si->sw_if_index, flags);
1468 }
Damjan Marionb2c31b62020-12-13 21:47:40 +01001469 }
Neale Ranns9db6ada2019-11-08 12:42:31 +00001470 /* *INDENT-ON* */
1471
1472 fib_table_flush (fib_index, fproto, FIB_SOURCE_API);
1473 mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)),
1474 fproto, MFIB_SOURCE_API);
1475 }
1476
1477 REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY);
Neale Rannsb8d44812017-11-10 06:53:54 -08001478}
1479
Klement Sekera75e7d132017-09-20 08:26:30 +02001480void
1481vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
1482{
1483 vl_api_ip_reassembly_set_reply_t *rmp;
1484 int rv = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001485 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera75e7d132017-09-20 08:26:30 +02001486 {
Klement Sekerade34c352019-06-25 11:19:22 +00001487 case IP_REASS_TYPE_FULL:
1488 if (mp->is_ip6)
1489 {
1490 rv = ip6_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1491 clib_net_to_host_u32
1492 (mp->max_reassemblies),
1493 clib_net_to_host_u32
1494 (mp->max_reassembly_length),
1495 clib_net_to_host_u32
1496 (mp->expire_walk_interval_ms));
1497 }
1498 else
1499 {
1500 rv = ip4_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1501 clib_net_to_host_u32
1502 (mp->max_reassemblies),
1503 clib_net_to_host_u32
1504 (mp->max_reassembly_length),
1505 clib_net_to_host_u32
1506 (mp->expire_walk_interval_ms));
1507 }
1508 break;
1509 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1510 if (mp->is_ip6)
1511 {
1512 rv =
1513 ip6_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1514 clib_net_to_host_u32 (mp->max_reassemblies),
1515 clib_net_to_host_u32
1516 (mp->max_reassembly_length),
1517 clib_net_to_host_u32
1518 (mp->expire_walk_interval_ms));
1519 }
1520 else
1521 {
1522 rv = ip4_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1523 clib_net_to_host_u32 (mp->max_reassemblies),
1524 clib_net_to_host_u32
1525 (mp->max_reassembly_length),
1526 clib_net_to_host_u32
1527 (mp->expire_walk_interval_ms));
1528 }
1529 break;
Klement Sekera75e7d132017-09-20 08:26:30 +02001530 }
1531
1532 REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
1533}
1534
1535void
1536vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
1537{
Ole Troan2e1c8962019-04-10 09:44:23 +02001538 vl_api_registration_t *rp;
Klement Sekera75e7d132017-09-20 08:26:30 +02001539
Ole Troan2e1c8962019-04-10 09:44:23 +02001540 rp = vl_api_client_index_to_registration (mp->client_index);
1541 if (rp == 0)
Klement Sekera75e7d132017-09-20 08:26:30 +02001542 return;
1543
1544 vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001545 clib_memset (rmp, 0, sizeof (*rmp));
Klement Sekera75e7d132017-09-20 08:26:30 +02001546 rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
1547 rmp->context = mp->context;
1548 rmp->retval = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001549 u32 timeout_ms;
1550 u32 max_reassemblies;
1551 u32 max_reassembly_length;
1552 u32 expire_walk_interval_ms;
1553 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera75e7d132017-09-20 08:26:30 +02001554 {
Klement Sekerade34c352019-06-25 11:19:22 +00001555 case IP_REASS_TYPE_FULL:
1556 if (mp->is_ip6)
1557 {
1558 rmp->is_ip6 = 1;
1559 ip6_full_reass_get (&timeout_ms, &max_reassemblies,
1560 &max_reassembly_length,
1561 &expire_walk_interval_ms);
1562 }
1563 else
1564 {
1565 rmp->is_ip6 = 0;
1566 ip4_full_reass_get (&timeout_ms, &max_reassemblies,
1567 &max_reassembly_length,
1568 &expire_walk_interval_ms);
1569 }
1570 break;
1571 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1572 if (mp->is_ip6)
1573 {
1574 rmp->is_ip6 = 1;
1575 ip6_sv_reass_get (&timeout_ms, &max_reassemblies,
1576 &max_reassembly_length, &expire_walk_interval_ms);
1577 }
1578 else
1579 {
1580 rmp->is_ip6 = 0;
1581 ip4_sv_reass_get (&timeout_ms, &max_reassemblies,
1582 &max_reassembly_length, &expire_walk_interval_ms);
1583 }
1584 break;
Klement Sekera75e7d132017-09-20 08:26:30 +02001585 }
Matthew Smithb3174df2019-12-03 12:41:53 -06001586 rmp->timeout_ms = clib_host_to_net_u32 (timeout_ms);
1587 rmp->max_reassemblies = clib_host_to_net_u32 (max_reassemblies);
1588 rmp->max_reassembly_length = clib_host_to_net_u32 (max_reassembly_length);
Klement Sekera75e7d132017-09-20 08:26:30 +02001589 rmp->expire_walk_interval_ms =
Matthew Smithb3174df2019-12-03 12:41:53 -06001590 clib_host_to_net_u32 (expire_walk_interval_ms);
Ole Troan2e1c8962019-04-10 09:44:23 +02001591 vl_api_send_msg (rp, (u8 *) rmp);
Klement Sekera75e7d132017-09-20 08:26:30 +02001592}
1593
Klement Sekera4c533132018-02-22 11:41:12 +01001594void
1595 vl_api_ip_reassembly_enable_disable_t_handler
1596 (vl_api_ip_reassembly_enable_disable_t * mp)
1597{
1598 vl_api_ip_reassembly_enable_disable_reply_t *rmp;
1599 int rv = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001600 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera4c533132018-02-22 11:41:12 +01001601 {
Klement Sekerade34c352019-06-25 11:19:22 +00001602 case IP_REASS_TYPE_FULL:
Klement Sekera896c8962019-06-24 11:52:49 +00001603 rv =
Klement Sekerade34c352019-06-25 11:19:22 +00001604 ip4_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
1605 mp->enable_ip4);
1606 if (0 == rv)
1607 rv =
1608 ip6_full_reass_enable_disable (clib_net_to_host_u32
1609 (mp->sw_if_index), mp->enable_ip6);
1610 break;
1611 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1612 rv =
1613 ip4_sv_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
1614 mp->enable_ip4);
1615 if (0 == rv)
1616 {
1617 rv =
1618 ip6_sv_reass_enable_disable (clib_net_to_host_u32
1619 (mp->sw_if_index), mp->enable_ip6);
1620 }
1621 break;
Klement Sekera4c533132018-02-22 11:41:12 +01001622 }
1623
Choree7f61d12018-11-28 10:27:58 +03301624 REPLY_MACRO (VL_API_IP_REASSEMBLY_ENABLE_DISABLE_REPLY);
Klement Sekera4c533132018-02-22 11:41:12 +01001625}
1626
Neale Ranns92207752019-06-03 13:21:40 +00001627typedef struct ip_punt_redirect_walk_ctx_t_
Pavel Kotucek609e1212018-11-27 09:59:44 +01001628{
Neale Ranns92207752019-06-03 13:21:40 +00001629 vl_api_registration_t *reg;
1630 u32 context;
1631} ip_punt_redirect_walk_ctx_t;
1632
1633static walk_rc_t
1634send_ip_punt_redirect_details (u32 rx_sw_if_index,
1635 const ip_punt_redirect_rx_t * ipr, void *arg)
1636{
Neale Ranns92207752019-06-03 13:21:40 +00001637 ip_punt_redirect_walk_ctx_t *ctx = arg;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001638 vl_api_ip_punt_redirect_details_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07001639 fib_path_encode_ctx_t path_ctx = {
1640 .rpaths = NULL,
1641 };
Pavel Kotucek609e1212018-11-27 09:59:44 +01001642
1643 mp = vl_msg_api_alloc (sizeof (*mp));
1644 if (!mp)
Neale Ranns92207752019-06-03 13:21:40 +00001645 return (WALK_STOP);;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001646
1647 clib_memset (mp, 0, sizeof (*mp));
1648 mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
Neale Ranns92207752019-06-03 13:21:40 +00001649 mp->context = ctx->context;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001650
Neale Ranns097fa662018-05-01 05:17:55 -07001651 fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &path_ctx);
Neale Ranns92207752019-06-03 13:21:40 +00001652
1653 mp->punt.rx_sw_if_index = htonl (rx_sw_if_index);
Neale Ranns097fa662018-05-01 05:17:55 -07001654 mp->punt.tx_sw_if_index = htonl (path_ctx.rpaths[0].frp_sw_if_index);
Neale Ranns92207752019-06-03 13:21:40 +00001655
Neale Ranns097fa662018-05-01 05:17:55 -07001656 ip_address_encode (&path_ctx.rpaths[0].frp_addr,
Neale Ranns92207752019-06-03 13:21:40 +00001657 fib_proto_to_ip46 (ipr->fproto), &mp->punt.nh);
1658
1659 vl_api_send_msg (ctx->reg, (u8 *) mp);
1660
Neale Ranns097fa662018-05-01 05:17:55 -07001661 vec_free (path_ctx.rpaths);
Neale Ranns92207752019-06-03 13:21:40 +00001662
1663 return (WALK_CONTINUE);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001664}
1665
1666static void
1667vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp)
1668{
1669 vl_api_registration_t *reg;
Dave Barach77841402020-04-29 17:04:10 -04001670 fib_protocol_t fproto = FIB_PROTOCOL_IP4;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001671
Pavel Kotucek609e1212018-11-27 09:59:44 +01001672 reg = vl_api_client_index_to_registration (mp->client_index);
1673 if (!reg)
1674 return;
1675
Dave Barach77841402020-04-29 17:04:10 -04001676 if (mp->is_ipv6 == 1)
1677 fproto = FIB_PROTOCOL_IP6;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001678
Neale Ranns92207752019-06-03 13:21:40 +00001679 ip_punt_redirect_walk_ctx_t ctx = {
1680 .reg = reg,
1681 .context = mp->context,
1682 };
1683
1684 if (~0 != mp->sw_if_index)
Pavel Kotucek609e1212018-11-27 09:59:44 +01001685 {
Neale Ranns92207752019-06-03 13:21:40 +00001686 u32 rx_sw_if_index;
1687 index_t pri;
1688
1689 rx_sw_if_index = ntohl (mp->sw_if_index);
1690 pri = ip_punt_redirect_find (fproto, rx_sw_if_index);
1691
1692 if (INDEX_INVALID == pri)
1693 return;
1694
1695 send_ip_punt_redirect_details (rx_sw_if_index,
1696 ip_punt_redirect_get (pri), &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001697 }
1698 else
Neale Ranns92207752019-06-03 13:21:40 +00001699 ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001700}
1701
Dave Barachb5e8a772016-12-06 12:04:42 -05001702#define vl_msg_name_crc_list
1703#include <vnet/ip/ip.api.h>
1704#undef vl_msg_name_crc_list
1705
1706static void
1707setup_message_id_table (api_main_t * am)
1708{
1709#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1710 foreach_vl_msg_name_crc_ip;
1711#undef _
1712}
1713
1714static clib_error_t *
1715ip_api_hookup (vlib_main_t * vm)
1716{
Dave Barach39d69112019-11-27 11:42:13 -05001717 api_main_t *am = vlibapi_get_main ();
Dave Barachb5e8a772016-12-06 12:04:42 -05001718
1719#define _(N,n) \
1720 vl_msg_api_set_handlers(VL_API_##N, #n, \
1721 vl_api_##n##_t_handler, \
1722 vl_noop_handler, \
1723 vl_api_##n##_t_endian, \
1724 vl_api_##n##_t_print, \
1725 sizeof(vl_api_##n##_t), 1);
1726 foreach_ip_api_msg;
1727#undef _
1728
1729 /*
Neale Ranns6a231a12018-10-17 06:38:00 +00001730 * Mark the route add/del API as MP safe
1731 */
Neale Ranns097fa662018-05-01 05:17:55 -07001732 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1;
1733 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL_REPLY] = 1;
Neale Ranns6a231a12018-10-17 06:38:00 +00001734
1735 /*
Dave Barachb5e8a772016-12-06 12:04:42 -05001736 * Set up the (msg_name, crc, message-id) table
1737 */
1738 setup_message_id_table (am);
1739
Dave Barachb5e8a772016-12-06 12:04:42 -05001740 return 0;
1741}
1742
1743VLIB_API_INIT_FUNCTION (ip_api_hookup);
1744
1745/*
1746 * fd.io coding-style-patch-verification: ON
1747 *
1748 * Local Variables:
1749 * eval: (c-set-style "gnu")
1750 * End:
1751 */