blob: 37656f3232fea4bb4eda31394ff22b6ca48863f4 [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) \
Benoît Ganne58a19152021-01-18 19:24:34 +010091 _ (IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \
92 _ (IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \
93 _ (IOAM_ENABLE, ioam_enable) \
94 _ (IOAM_DISABLE, ioam_disable) \
95 _ (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
96 ip_source_and_port_range_check_add_del) \
97 _ (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
98 ip_source_and_port_range_check_interface_add_del) \
99 _ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
100 sw_interface_ip6_set_link_local_address) \
101 _ (SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS, \
102 sw_interface_ip6_get_link_local_address) \
103 _ (IP_REASSEMBLY_SET, ip_reassembly_set) \
104 _ (IP_REASSEMBLY_GET, ip_reassembly_get) \
105 _ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
106 _ (IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
Pavel Kotucek609e1212018-11-27 09:59:44 +0100107
Dave Barachb5e8a772016-12-06 12:04:42 -0500108static void
Neale Rannscbe25aa2019-09-30 10:53:31 +0000109 vl_api_sw_interface_ip6_enable_disable_t_handler
110 (vl_api_sw_interface_ip6_enable_disable_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500111{
Neale Rannscbe25aa2019-09-30 10:53:31 +0000112 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
113 int rv = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500114
Neale Rannscbe25aa2019-09-30 10:53:31 +0000115 VALIDATE_SW_IF_INDEX (mp);
Neale Ranns37029302018-08-10 05:30:06 -0700116
Neale Rannscbe25aa2019-09-30 10:53:31 +0000117 rv = ((mp->enable == 1) ?
Neale Rannsec40a7d2020-04-23 07:36:12 +0000118 ip6_link_enable (ntohl (mp->sw_if_index), NULL) :
Neale Rannscbe25aa2019-09-30 10:53:31 +0000119 ip6_link_disable (ntohl (mp->sw_if_index)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500120
Neale Rannscbe25aa2019-09-30 10:53:31 +0000121 BAD_SW_IF_INDEX_LABEL;
Dave Barachb5e8a772016-12-06 12:04:42 -0500122
Neale Rannscbe25aa2019-09-30 10:53:31 +0000123 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
Dave Barachb5e8a772016-12-06 12:04:42 -0500124}
125
Dave Barachb5e8a772016-12-06 12:04:42 -0500126static void
Neale Ranns097fa662018-05-01 05:17:55 -0700127send_ip_table_details (vpe_api_main_t * am,
128 vl_api_registration_t * reg,
129 u32 context, const fib_table_t * table)
Dave Barachb5e8a772016-12-06 12:04:42 -0500130{
Neale Ranns097fa662018-05-01 05:17:55 -0700131 vl_api_ip_table_details_t *mp;
Dave Barachb5e8a772016-12-06 12:04:42 -0500132
Neale Ranns097fa662018-05-01 05:17:55 -0700133 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500134 if (!mp)
135 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400136 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700137 mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500138 mp->context = context;
139
Neale Ranns097fa662018-05-01 05:17:55 -0700140 mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6);
141 mp->table.table_id = htonl (table->ft_table_id);
142 memcpy (mp->table.name, table->ft_desc,
143 clib_min (vec_len (table->ft_desc), sizeof (mp->table.name)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500144
Florin Coras6c4dae22018-01-09 06:39:23 -0800145 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500146}
147
Neale Ranns097fa662018-05-01 05:17:55 -0700148static void
149vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp)
150{
151 vpe_api_main_t *am = &vpe_api_main;
152 vl_api_registration_t *reg;
153 fib_table_t *fib_table;
154
155 reg = vl_api_client_index_to_registration (mp->client_index);
156 if (!reg)
157 return;
158
159 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100160 pool_foreach (fib_table, ip4_main.fibs)
161 {
Neale Ranns097fa662018-05-01 05:17:55 -0700162 send_ip_table_details(am, reg, mp->context, fib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100163 }
164 pool_foreach (fib_table, ip6_main.fibs)
165 {
Neale Ranns097fa662018-05-01 05:17:55 -0700166 /* don't send link locals */
167 if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
168 continue;
169 send_ip_table_details(am, reg, mp->context, fib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100170 }
Neale Ranns097fa662018-05-01 05:17:55 -0700171 /* *INDENT-ON* */
172}
173
Neale Rannsa3af3372017-03-28 03:49:52 -0700174typedef struct vl_api_ip_fib_dump_walk_ctx_t_
175{
176 fib_node_index_t *feis;
177} vl_api_ip_fib_dump_walk_ctx_t;
178
Neale Ranns89541992017-04-06 04:41:02 -0700179static fib_table_walk_rc_t
Neale Rannsa3af3372017-03-28 03:49:52 -0700180vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg)
181{
182 vl_api_ip_fib_dump_walk_ctx_t *ctx = arg;
183
184 vec_add1 (ctx->feis, fei);
185
Neale Ranns89541992017-04-06 04:41:02 -0700186 return (FIB_TABLE_WALK_CONTINUE);
Neale Rannsa3af3372017-03-28 03:49:52 -0700187}
188
Dave Barachb5e8a772016-12-06 12:04:42 -0500189static void
Neale Ranns097fa662018-05-01 05:17:55 -0700190send_ip_route_details (vpe_api_main_t * am,
191 vl_api_registration_t * reg,
192 u32 context, fib_node_index_t fib_entry_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500193{
Neale Ranns097fa662018-05-01 05:17:55 -0700194 fib_route_path_t *rpaths, *rpath;
195 vl_api_ip_route_details_t *mp;
Neale Rannsc5d43172018-07-30 08:04:40 -0700196 const fib_prefix_t *pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -0500197 vl_api_fib_path_t *fp;
198 int path_count;
199
Neale Ranns097fa662018-05-01 05:17:55 -0700200 rpaths = NULL;
201 pfx = fib_entry_get_prefix (fib_entry_index);
202 rpaths = fib_entry_encode (fib_entry_index);
203
204 path_count = vec_len (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500205 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
206 if (!mp)
207 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400208 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700209 mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500210 mp->context = context;
211
Neale Ranns097fa662018-05-01 05:17:55 -0700212 ip_prefix_encode (pfx, &mp->route.prefix);
213 mp->route.table_id =
214 htonl (fib_table_get_table_id
215 (fib_entry_get_fib_index (fib_entry_index), pfx->fp_proto));
216 mp->route.n_paths = path_count;
217 mp->route.stats_index =
218 htonl (fib_table_entry_get_stats_index
219 (fib_entry_get_fib_index (fib_entry_index), pfx));
Dave Barachb5e8a772016-12-06 12:04:42 -0500220
Neale Ranns097fa662018-05-01 05:17:55 -0700221 fp = mp->route.paths;
222 vec_foreach (rpath, rpaths)
Dave Barachb5e8a772016-12-06 12:04:42 -0500223 {
Neale Ranns097fa662018-05-01 05:17:55 -0700224 fib_api_path_encode (rpath, fp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500225 fp++;
226 }
227
Florin Coras6c4dae22018-01-09 06:39:23 -0800228 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns9db6ada2019-11-08 12:42:31 +0000229 vec_free (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500230}
231
Dave Barachd7cb1b52016-12-09 09:52:16 -0500232typedef struct apt_ip6_fib_show_ctx_t_
233{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500234 fib_node_index_t *entries;
Dave Barachb5e8a772016-12-06 12:04:42 -0500235} api_ip6_fib_show_ctx_t;
236
Dave Barachb5e8a772016-12-06 12:04:42 -0500237static void
Neale Ranns097fa662018-05-01 05:17:55 -0700238vl_api_ip_route_dump_t_handler (vl_api_ip_route_dump_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500239{
240 vpe_api_main_t *am = &vpe_api_main;
Dave Barachb5e8a772016-12-06 12:04:42 -0500241 fib_node_index_t *fib_entry_index;
Florin Coras6c4dae22018-01-09 06:39:23 -0800242 vl_api_registration_t *reg;
Neale Ranns097fa662018-05-01 05:17:55 -0700243 fib_protocol_t fproto;
244 u32 fib_index;
Dave Barachb5e8a772016-12-06 12:04:42 -0500245
Florin Coras6c4dae22018-01-09 06:39:23 -0800246 reg = vl_api_client_index_to_registration (mp->client_index);
247 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500248 return;
249
Neale Ranns097fa662018-05-01 05:17:55 -0700250 vl_api_ip_fib_dump_walk_ctx_t ctx = {
251 .feis = NULL,
252 };
Neale Ranns81458422018-03-12 06:59:36 -0700253
Neale Ranns097fa662018-05-01 05:17:55 -0700254 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
255 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
256
257 if (INDEX_INVALID == fib_index)
258 return;
259
260 fib_table_walk (fib_index, fproto, vl_api_ip_fib_dump_walk, &ctx);
261
262 vec_foreach (fib_entry_index, ctx.feis)
263 {
264 send_ip_route_details (am, reg, mp->context, *fib_entry_index);
265 }
266
267 vec_free (ctx.feis);
Dave Barachb5e8a772016-12-06 12:04:42 -0500268}
269
270static void
Neale Ranns097fa662018-05-01 05:17:55 -0700271send_ip_mtable_details (vl_api_registration_t * reg,
272 u32 context, const mfib_table_t * mfib_table)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800273{
Neale Ranns097fa662018-05-01 05:17:55 -0700274 vl_api_ip_mtable_details_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800275
Neale Ranns097fa662018-05-01 05:17:55 -0700276 mp = vl_msg_api_alloc (sizeof (*mp));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800277 if (!mp)
278 return;
Neale Ranns097fa662018-05-01 05:17:55 -0700279 memset (mp, 0, sizeof (*mp));
280 mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800281 mp->context = context;
282
Neale Ranns097fa662018-05-01 05:17:55 -0700283 mp->table.table_id = htonl (mfib_table->mft_table_id);
284 mp->table.is_ip6 = (FIB_PROTOCOL_IP6 == mfib_table->mft_proto);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800285
Florin Coras6c4dae22018-01-09 06:39:23 -0800286 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800287}
288
Neale Ranns5a8123b2017-01-26 01:18:23 -0800289static void
Neale Ranns097fa662018-05-01 05:17:55 -0700290vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800291{
Florin Coras6c4dae22018-01-09 06:39:23 -0800292 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800293 mfib_table_t *mfib_table;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800294
Florin Coras6c4dae22018-01-09 06:39:23 -0800295 reg = vl_api_client_index_to_registration (mp->client_index);
296 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800297 return;
298
Neale Ranns5a8123b2017-01-26 01:18:23 -0800299 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100300 pool_foreach (mfib_table, ip4_main.mfibs)
301 {
Neale Ranns097fa662018-05-01 05:17:55 -0700302 send_ip_mtable_details (reg, mp->context, mfib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100303 }
304 pool_foreach (mfib_table, ip6_main.mfibs)
305 {
Neale Ranns097fa662018-05-01 05:17:55 -0700306 send_ip_mtable_details (reg, mp->context, mfib_table);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100307 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800308 /* *INDENT-ON* */
Neale Ranns5a8123b2017-01-26 01:18:23 -0800309}
310
Neale Ranns097fa662018-05-01 05:17:55 -0700311typedef struct vl_api_ip_mfib_dump_ctx_t_
Neale Ranns5a8123b2017-01-26 01:18:23 -0800312{
313 fib_node_index_t *entries;
Neale Ranns097fa662018-05-01 05:17:55 -0700314} vl_api_ip_mfib_dump_ctx_t;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800315
Neale Ranns9db6ada2019-11-08 12:42:31 +0000316static walk_rc_t
Neale Ranns097fa662018-05-01 05:17:55 -0700317mfib_route_dump_walk (fib_node_index_t fei, void *arg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800318{
Neale Ranns097fa662018-05-01 05:17:55 -0700319 vl_api_ip_mfib_dump_ctx_t *ctx = arg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800320
321 vec_add1 (ctx->entries, fei);
322
Neale Ranns9db6ada2019-11-08 12:42:31 +0000323 return (WALK_CONTINUE);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800324}
325
326static void
Neale Ranns097fa662018-05-01 05:17:55 -0700327send_ip_mroute_details (vpe_api_main_t * am,
328 vl_api_registration_t * reg,
329 u32 context, fib_node_index_t mfib_entry_index)
330{
331 fib_route_path_t *rpaths, *rpath;
332 vl_api_ip_mroute_details_t *mp;
333 const mfib_prefix_t *pfx;
334 vl_api_mfib_path_t *fp;
Matthew Smitha2bbeb82020-09-17 16:33:10 -0500335 u8 path_count;
Neale Ranns097fa662018-05-01 05:17:55 -0700336
337 rpaths = NULL;
338 pfx = mfib_entry_get_prefix (mfib_entry_index);
339 rpaths = mfib_entry_encode (mfib_entry_index);
340
341 path_count = vec_len (rpaths);
342 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
343 if (!mp)
344 return;
345 clib_memset (mp, 0, sizeof (*mp));
346 mp->_vl_msg_id = ntohs (VL_API_IP_MROUTE_DETAILS);
347 mp->context = context;
348
349 ip_mprefix_encode (pfx, &mp->route.prefix);
350 mp->route.table_id =
351 htonl (mfib_table_get_table_id
352 (mfib_entry_get_fib_index (mfib_entry_index), pfx->fp_proto));
Matthew Smitha2bbeb82020-09-17 16:33:10 -0500353 mp->route.n_paths = path_count;
Neale Ranns097fa662018-05-01 05:17:55 -0700354 fp = mp->route.paths;
355 vec_foreach (rpath, rpaths)
356 {
357 mfib_api_path_encode (rpath, fp);
358 fp++;
359 }
360
361 vl_api_send_msg (reg, (u8 *) mp);
362 vec_free (rpaths);
363}
364
365static void
366vl_api_ip_mroute_dump_t_handler (vl_api_ip_mroute_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800367{
368 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800369 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800370 fib_node_index_t *mfeip;
Neale Ranns097fa662018-05-01 05:17:55 -0700371 fib_protocol_t fproto;
372 u32 fib_index;
373
374 vl_api_ip_mfib_dump_ctx_t ctx = {
Neale Ranns5a8123b2017-01-26 01:18:23 -0800375 .entries = NULL,
376 };
377
Florin Coras6c4dae22018-01-09 06:39:23 -0800378 reg = vl_api_client_index_to_registration (mp->client_index);
379 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800380 return;
381
Neale Ranns097fa662018-05-01 05:17:55 -0700382 fproto = fib_ip_proto (mp->table.is_ip6);
383 fib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800384
Neale Ranns097fa662018-05-01 05:17:55 -0700385 if (INDEX_INVALID == fib_index)
386 return;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800387
Neale Ranns097fa662018-05-01 05:17:55 -0700388 mfib_table_walk (fib_index, fproto, mfib_route_dump_walk, &ctx);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800389
Neale Ranns097fa662018-05-01 05:17:55 -0700390 vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800391
Neale Ranns097fa662018-05-01 05:17:55 -0700392 vec_foreach (mfeip, ctx.entries)
393 {
394 send_ip_mroute_details (am, reg, mp->context, *mfeip);
395 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800396
397 vec_free (ctx.entries);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800398}
399
400static void
Neale Rannsd91c1db2017-07-31 02:30:50 -0700401vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp,
402 vlib_main_t * vm)
403{
404 vl_api_ip_punt_police_reply_t *rmp;
405 int rv = 0;
406
407 if (mp->is_ip6)
408 ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
409 else
410 ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
411
412 REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY);
413}
414
415static void
416vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp,
417 vlib_main_t * vm)
418{
419 vl_api_ip_punt_redirect_reply_t *rmp;
420 int rv = 0;
Pavel Kotucek609e1212018-11-27 09:59:44 +0100421 ip46_type_t ipv;
422 ip46_address_t nh;
Neale Rannsd91c1db2017-07-31 02:30:50 -0700423
Pavel Kotucek609e1212018-11-27 09:59:44 +0100424 if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index)))
425 goto bad_sw_if_index;
426
427 ipv = ip_address_decode (&mp->punt.nh, &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700428 if (mp->is_add)
429 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100430 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700431 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100432 ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
433 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700434 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100435 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700436 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100437 ip4_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
438 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700439 }
440 }
441 else
442 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100443 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700444 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100445 ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700446 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100447 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700448 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100449 ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700450 }
451 }
452
Pavel Kotucek609e1212018-11-27 09:59:44 +0100453 BAD_SW_IF_INDEX_LABEL;
454
Neale Rannsd91c1db2017-07-31 02:30:50 -0700455 REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY);
456}
457
Steven Luongc3ed1c92020-07-27 10:06:58 -0700458static clib_error_t *
459call_elf_section_ip_table_callbacks (vnet_main_t * vnm, u32 table_id,
460 u32 flags,
461 _vnet_ip_table_function_list_elt_t **
462 elts)
463{
464 _vnet_ip_table_function_list_elt_t *elt;
465 vnet_ip_table_function_priority_t prio;
466 clib_error_t *error = 0;
467
468 for (prio = VNET_IP_TABLE_FUNC_PRIORITY_LOW;
469 prio <= VNET_IP_TABLE_FUNC_PRIORITY_HIGH; prio++)
470 {
471 elt = elts[prio];
472
473 while (elt)
474 {
475 error = elt->fp (vnm, table_id, flags);
476 if (error)
477 return error;
478 elt = elt->next_ip_table_function;
479 }
480 }
481 return error;
482}
483
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700484void
Neale Ranns15002542017-09-10 04:39:11 -0700485ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api)
486{
487 u32 fib_index, mfib_index;
Steven Luongc3ed1c92020-07-27 10:06:58 -0700488 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns15002542017-09-10 04:39:11 -0700489
490 /*
491 * ignore action on the default table - this is always present
492 * and cannot be added nor deleted from the API
493 */
494 if (0 != table_id)
495 {
496 /*
497 * The API holds only one lock on the table.
498 * i.e. it can be added many times via the API but needs to be
499 * deleted only once.
500 * The FIB index for unicast and multicast is not necessarily the
501 * same, since internal VPP systesm (like LISP and SR) create
502 * their own unicast tables.
503 */
504 fib_index = fib_table_find (fproto, table_id);
505 mfib_index = mfib_table_find (fproto, table_id);
506
Steven Luongc3ed1c92020-07-27 10:06:58 -0700507 if ((~0 != fib_index) || (~0 != mfib_index))
508 call_elf_section_ip_table_callbacks (vnm, table_id, 0 /* is_add */ ,
509 vnm->ip_table_add_del_functions);
510
Neale Ranns15002542017-09-10 04:39:11 -0700511 if (~0 != fib_index)
512 {
513 fib_table_unlock (fib_index, fproto,
514 (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI));
515 }
516 if (~0 != mfib_index)
517 {
518 mfib_table_unlock (mfib_index, fproto,
519 (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI));
520 }
521 }
522}
523
524void
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700525vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
526{
527 vl_api_ip_table_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700528 fib_protocol_t fproto = (mp->table.is_ip6 ?
529 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
530 u32 table_id = ntohl (mp->table.table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700531 int rv = 0;
532
Neale Ranns15002542017-09-10 04:39:11 -0700533 if (mp->is_add)
534 {
Neale Ranns097fa662018-05-01 05:17:55 -0700535 ip_table_create (fproto, table_id, 1, mp->table.name);
Neale Ranns15002542017-09-10 04:39:11 -0700536 }
537 else
538 {
539 ip_table_delete (fproto, table_id, 1);
540 }
541
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700542 REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY);
543}
544
Dave Barachb5e8a772016-12-06 12:04:42 -0500545static int
Neale Ranns097fa662018-05-01 05:17:55 -0700546ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp, u32 * stats_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500547{
Neale Ranns097fa662018-05-01 05:17:55 -0700548 fib_route_path_t *rpaths = NULL, *rpath;
549 fib_entry_flag_t entry_flags;
550 vl_api_fib_path_t *apath;
551 fib_prefix_t pfx;
552 u32 fib_index;
553 int rv, ii;
Dave Barachb5e8a772016-12-06 12:04:42 -0500554
Neale Ranns097fa662018-05-01 05:17:55 -0700555 entry_flags = FIB_ENTRY_FLAG_NONE;
556 ip_prefix_decode (&mp->route.prefix, &pfx);
Dave Barachb5e8a772016-12-06 12:04:42 -0500557
Neale Ranns097fa662018-05-01 05:17:55 -0700558 rv = fib_api_table_id_decode (pfx.fp_proto,
559 ntohl (mp->route.table_id), &fib_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500560 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700561 goto out;
Dave Barachb5e8a772016-12-06 12:04:42 -0500562
Neale Rannsc2ac2352019-07-02 14:33:29 +0000563 if (0 != mp->route.n_paths)
564 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns097fa662018-05-01 05:17:55 -0700565
566 for (ii = 0; ii < mp->route.n_paths; ii++)
567 {
568 apath = &mp->route.paths[ii];
569 rpath = &rpaths[ii];
570
571 rv = fib_api_path_decode (apath, rpath);
572
573 if ((rpath->frp_flags & FIB_ROUTE_PATH_LOCAL) &&
574 (~0 == rpath->frp_sw_if_index))
575 entry_flags |= (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL);
576
577 if (0 != rv)
578 goto out;
579 }
580
Neale Rannsc2ac2352019-07-02 14:33:29 +0000581 rv = fib_api_route_add_del (mp->is_add,
582 mp->is_multipath,
583 fib_index, &pfx, entry_flags, rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700584
585 if (mp->is_add && 0 == rv)
586 *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx);
587
Neale Ranns097fa662018-05-01 05:17:55 -0700588out:
589 vec_free (rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700590
591 return (rv);
Dave Barachb5e8a772016-12-06 12:04:42 -0500592}
593
594void
Neale Ranns097fa662018-05-01 05:17:55 -0700595vl_api_ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500596{
Neale Ranns097fa662018-05-01 05:17:55 -0700597 vl_api_ip_route_add_del_reply_t *rmp;
598 u32 stats_index = ~0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500599 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -0500600
Neale Ranns097fa662018-05-01 05:17:55 -0700601 rv = ip_route_add_del_t_handler (mp, &stats_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500602
Neale Ranns008dbe12018-09-07 09:32:36 -0700603 /* *INDENT-OFF* */
Neale Ranns097fa662018-05-01 05:17:55 -0700604 REPLY_MACRO2 (VL_API_IP_ROUTE_ADD_DEL_REPLY,
Neale Ranns008dbe12018-09-07 09:32:36 -0700605 ({
606 rmp->stats_index = htonl (stats_index);
607 }))
608 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500609}
610
Neale Ranns15002542017-09-10 04:39:11 -0700611void
Christian Hoppsf5d38e02020-05-04 10:28:03 -0400612vl_api_ip_route_lookup_t_handler (vl_api_ip_route_lookup_t * mp)
613{
614 vl_api_ip_route_lookup_reply_t *rmp = NULL;
615 fib_route_path_t *rpaths = NULL, *rpath;
616 const fib_prefix_t *pfx = NULL;
617 fib_prefix_t lookup;
618 vl_api_fib_path_t *fp;
619 fib_node_index_t fib_entry_index;
620 u32 fib_index;
621 int npaths = 0;
622 int rv;
623
624 ip_prefix_decode (&mp->prefix, &lookup);
625 rv = fib_api_table_id_decode (lookup.fp_proto, ntohl (mp->table_id),
626 &fib_index);
627 if (PREDICT_TRUE (!rv))
628 {
629 if (mp->exact)
630 fib_entry_index = fib_table_lookup_exact_match (fib_index, &lookup);
631 else
632 fib_entry_index = fib_table_lookup (fib_index, &lookup);
633 if (fib_entry_index == FIB_NODE_INDEX_INVALID)
634 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
635 else
636 {
637 pfx = fib_entry_get_prefix (fib_entry_index);
638 rpaths = fib_entry_encode (fib_entry_index);
639 npaths = vec_len (rpaths);
640 }
641 }
642
643 /* *INDENT-OFF* */
644 REPLY_MACRO3_ZERO(VL_API_IP_ROUTE_LOOKUP_REPLY,
645 npaths * sizeof (*fp),
646 ({
647 if (!rv)
648 {
649 ip_prefix_encode (pfx, &rmp->route.prefix);
650 rmp->route.table_id = mp->table_id;
651 rmp->route.n_paths = npaths;
652 rmp->route.stats_index = fib_table_entry_get_stats_index (fib_index, pfx);
653 rmp->route.stats_index = htonl (rmp->route.stats_index);
654
655 fp = rmp->route.paths;
656 vec_foreach (rpath, rpaths)
657 {
658 fib_api_path_encode (rpath, fp);
659 fp++;
660 }
661 }
662 }));
663 /* *INDENT-ON* */
664 vec_free (rpaths);
665}
666
667void
Neale Ranns2297af02017-09-12 09:45:04 -0700668ip_table_create (fib_protocol_t fproto,
669 u32 table_id, u8 is_api, const u8 * name)
Neale Ranns15002542017-09-10 04:39:11 -0700670{
671 u32 fib_index, mfib_index;
Steven Luongc3ed1c92020-07-27 10:06:58 -0700672 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns15002542017-09-10 04:39:11 -0700673
674 /*
675 * ignore action on the default table - this is always present
676 * and cannot be added nor deleted from the API
677 */
678 if (0 != table_id)
679 {
680 /*
681 * The API holds only one lock on the table.
682 * i.e. it can be added many times via the API but needs to be
683 * deleted only once.
684 * The FIB index for unicast and multicast is not necessarily the
685 * same, since internal VPP systesm (like LISP and SR) create
686 * their own unicast tables.
687 */
688 fib_index = fib_table_find (fproto, table_id);
689 mfib_index = mfib_table_find (fproto, table_id);
690
691 if (~0 == fib_index)
692 {
Neale Ranns2297af02017-09-12 09:45:04 -0700693 fib_table_find_or_create_and_lock_w_name (fproto, table_id,
694 (is_api ?
695 FIB_SOURCE_API :
696 FIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700697 }
698 if (~0 == mfib_index)
699 {
Neale Ranns2297af02017-09-12 09:45:04 -0700700 mfib_table_find_or_create_and_lock_w_name (fproto, table_id,
701 (is_api ?
702 MFIB_SOURCE_API :
703 MFIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700704 }
Steven Luongc3ed1c92020-07-27 10:06:58 -0700705
706 if ((~0 == fib_index) || (~0 == mfib_index))
707 call_elf_section_ip_table_callbacks (vnm, table_id, 1 /* is_add */ ,
708 vnm->ip_table_add_del_functions);
Neale Ranns15002542017-09-10 04:39:11 -0700709 }
710}
711
Neale Ranns097fa662018-05-01 05:17:55 -0700712static u32
Neale Ranns32e1c012016-11-22 17:07:28 +0000713mroute_add_del_handler (u8 is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700714 u8 is_multipath,
Neale Ranns32e1c012016-11-22 17:07:28 +0000715 u32 fib_index,
716 const mfib_prefix_t * prefix,
717 u32 entry_flags,
Neale Ranns097fa662018-05-01 05:17:55 -0700718 u32 rpf_id, fib_route_path_t * rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +0000719{
Neale Ranns097fa662018-05-01 05:17:55 -0700720 u32 mfib_entry_index = ~0;
Neale Ranns28c142e2018-09-07 09:37:07 -0700721
Neale Ranns097fa662018-05-01 05:17:55 -0700722 if (0 == vec_len (rpaths))
Neale Ranns32e1c012016-11-22 17:07:28 +0000723 {
Neale Ranns28c142e2018-09-07 09:37:07 -0700724 mfib_entry_index = mfib_table_entry_update (fib_index, prefix,
725 MFIB_SOURCE_API,
726 rpf_id, entry_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +0000727 }
728 else
729 {
Neale Ranns097fa662018-05-01 05:17:55 -0700730 if (is_add)
731 {
732 mfib_entry_index =
733 mfib_table_entry_paths_update (fib_index, prefix,
734 MFIB_SOURCE_API, rpaths);
735 }
736 else
737 {
738 mfib_table_entry_paths_remove (fib_index, prefix,
739 MFIB_SOURCE_API, rpaths);
740 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000741 }
742
Neale Ranns28c142e2018-09-07 09:37:07 -0700743 return (mfib_entry_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000744}
745
746static int
Neale Ranns28c142e2018-09-07 09:37:07 -0700747api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp,
748 u32 * stats_index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000749{
Neale Ranns097fa662018-05-01 05:17:55 -0700750 fib_route_path_t *rpath, *rpaths = NULL;
Neale Ranns28c142e2018-09-07 09:37:07 -0700751 fib_node_index_t mfib_entry_index;
Neale Ranns990f6942020-10-20 07:20:17 +0000752 mfib_entry_flags_t eflags;
Neale Ranns097fa662018-05-01 05:17:55 -0700753 mfib_prefix_t pfx;
Neale Ranns32e1c012016-11-22 17:07:28 +0000754 u32 fib_index;
755 int rv;
Neale Ranns097fa662018-05-01 05:17:55 -0700756 u16 ii;
Neale Ranns32e1c012016-11-22 17:07:28 +0000757
Neale Ranns097fa662018-05-01 05:17:55 -0700758 ip_mprefix_decode (&mp->route.prefix, &pfx);
Neale Ranns32e1c012016-11-22 17:07:28 +0000759
Neale Ranns097fa662018-05-01 05:17:55 -0700760 rv = mfib_api_table_id_decode (pfx.fp_proto,
761 ntohl (mp->route.table_id), &fib_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000762 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700763 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000764
Neale Ranns097fa662018-05-01 05:17:55 -0700765 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns32e1c012016-11-22 17:07:28 +0000766
Neale Ranns097fa662018-05-01 05:17:55 -0700767 for (ii = 0; ii < mp->route.n_paths; ii++)
Neale Ranns32e1c012016-11-22 17:07:28 +0000768 {
Neale Ranns097fa662018-05-01 05:17:55 -0700769 rpath = &rpaths[ii];
770
771 rv = mfib_api_path_decode (&mp->route.paths[ii], rpath);
772
773 if (0 != rv)
774 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000775 }
776
Neale Ranns990f6942020-10-20 07:20:17 +0000777 eflags = mfib_api_path_entry_flags_decode (mp->route.entry_flags);
Neale Ranns28c142e2018-09-07 09:37:07 -0700778 mfib_entry_index = mroute_add_del_handler (mp->is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700779 mp->is_add,
Neale Ranns28c142e2018-09-07 09:37:07 -0700780 fib_index, &pfx,
Neale Ranns990f6942020-10-20 07:20:17 +0000781 eflags,
Neale Ranns097fa662018-05-01 05:17:55 -0700782 ntohl (mp->route.rpf_id),
783 rpaths);
Neale Ranns28c142e2018-09-07 09:37:07 -0700784
785 if (~0 != mfib_entry_index)
786 *stats_index = mfib_entry_get_stats_index (mfib_entry_index);
787
Neale Ranns097fa662018-05-01 05:17:55 -0700788out:
Neale Ranns28c142e2018-09-07 09:37:07 -0700789 return (rv);
Neale Ranns32e1c012016-11-22 17:07:28 +0000790}
791
792void
793vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp)
794{
795 vl_api_ip_mroute_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700796 u32 stats_index = ~0;
Neale Ranns32e1c012016-11-22 17:07:28 +0000797 int rv;
Neale Ranns32e1c012016-11-22 17:07:28 +0000798
Neale Ranns28c142e2018-09-07 09:37:07 -0700799 rv = api_mroute_add_del_t_handler (mp, &stats_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000800
Neale Ranns28c142e2018-09-07 09:37:07 -0700801 /* *INDENT-OFF* */
802 REPLY_MACRO2 (VL_API_IP_MROUTE_ADD_DEL_REPLY,
803 ({
804 rmp->stats_index = htonl (stats_index);
805 }));
806 /* *INDENT-ON* */
Neale Ranns32e1c012016-11-22 17:07:28 +0000807}
808
Dave Barachb5e8a772016-12-06 12:04:42 -0500809static void
810send_ip_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800811 vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6,
812 u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500813{
814 vl_api_ip_details_t *mp;
815
816 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400817 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500818 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
819
820 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger466f0d42017-02-09 12:17:50 -0600821 mp->is_ipv6 = is_ipv6;
Dave Barachb5e8a772016-12-06 12:04:42 -0500822 mp->context = context;
823
Florin Coras6c4dae22018-01-09 06:39:23 -0800824 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500825}
826
827static void
828send_ip_address_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800829 vl_api_registration_t * reg,
Neale Ranns097fa662018-05-01 05:17:55 -0700830 const fib_prefix_t * pfx,
831 u32 sw_if_index, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500832{
833 vl_api_ip_address_details_t *mp;
834
835 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400836 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500837 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
838
Neale Ranns097fa662018-05-01 05:17:55 -0700839 ip_prefix_encode (pfx, &mp->prefix);
Dave Barachb5e8a772016-12-06 12:04:42 -0500840 mp->context = context;
Jon Loeliger466f0d42017-02-09 12:17:50 -0600841 mp->sw_if_index = htonl (sw_if_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500842
Florin Coras6c4dae22018-01-09 06:39:23 -0800843 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500844}
845
846static void
847vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
848{
849 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800850 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500851 ip6_main_t *im6 = &ip6_main;
852 ip4_main_t *im4 = &ip4_main;
853 ip_lookup_main_t *lm6 = &im6->lookup_main;
854 ip_lookup_main_t *lm4 = &im4->lookup_main;
855 ip_interface_address_t *ia = 0;
856 u32 sw_if_index = ~0;
857 int rv __attribute__ ((unused)) = 0;
858
859 VALIDATE_SW_IF_INDEX (mp);
860
861 sw_if_index = ntohl (mp->sw_if_index);
862
Florin Coras6c4dae22018-01-09 06:39:23 -0800863 reg = vl_api_client_index_to_registration (mp->client_index);
864 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500865 return;
866
Dave Barachb5e8a772016-12-06 12:04:42 -0500867 if (mp->is_ipv6)
868 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500869 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700870 /* Do not send subnet details of the IP-interface for
871 * unnumbered interfaces. otherwise listening clients
872 * will be confused that the subnet is applied on more
873 * than one interface */
874 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500875 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700876 fib_prefix_t pfx = {
877 .fp_addr.ip6 = *(ip6_address_t *)ip_interface_address_get_address (lm6, ia),
878 .fp_len = ia->address_length,
879 .fp_proto = FIB_PROTOCOL_IP6,
880 };
881 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500882 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500883 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500884 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500885 else
886 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500887 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700888 foreach_ip_interface_address (lm4, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500889 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700890 fib_prefix_t pfx = {
891 .fp_addr.ip4 = *(ip4_address_t *)ip_interface_address_get_address (lm4, ia),
892 .fp_len = ia->address_length,
893 .fp_proto = FIB_PROTOCOL_IP4,
894 };
895
896 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500897 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500898 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500899 }
Neale Ranns008dbe12018-09-07 09:32:36 -0700900
Dave Barachb5e8a772016-12-06 12:04:42 -0500901 BAD_SW_IF_INDEX_LABEL;
902}
903
904static void
Neale Ranns9e2f9152018-05-18 02:27:10 -0700905send_ip_unnumbered_details (vpe_api_main_t * am,
906 vl_api_registration_t * reg,
907 u32 sw_if_index, u32 ip_sw_if_index, u32 context)
908{
909 vl_api_ip_unnumbered_details_t *mp;
910
911 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400912 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns9e2f9152018-05-18 02:27:10 -0700913 mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
914
915 mp->context = context;
916 mp->sw_if_index = htonl (sw_if_index);
917 mp->ip_sw_if_index = htonl (ip_sw_if_index);
918
919 vl_api_send_msg (reg, (u8 *) mp);
920}
921
922static void
923vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
924{
925 vnet_main_t *vnm = vnet_get_main ();
926 vnet_interface_main_t *im = &vnm->interface_main;
927 int rv __attribute__ ((unused)) = 0;
928 vpe_api_main_t *am = &vpe_api_main;
929 vl_api_registration_t *reg;
930 vnet_sw_interface_t *si;
931 u32 sw_if_index;
932
933 sw_if_index = ntohl (mp->sw_if_index);
934
935 reg = vl_api_client_index_to_registration (mp->client_index);
936 if (!reg)
937 return;
938
939 if (~0 != sw_if_index)
940 {
941 VALIDATE_SW_IF_INDEX (mp);
942
943 si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
944
Neale Rannsac3e72c2019-10-06 01:04:26 -0700945 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
Neale Ranns9e2f9152018-05-18 02:27:10 -0700946 {
947 send_ip_unnumbered_details (am, reg,
948 sw_if_index,
949 si->unnumbered_sw_if_index,
950 mp->context);
951 }
952 }
953 else
954 {
955 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100956 pool_foreach (si, im->sw_interfaces)
957 {
Neale Ranns9e2f9152018-05-18 02:27:10 -0700958 if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
959 {
960 send_ip_unnumbered_details(am, reg,
961 si->sw_if_index,
962 si->unnumbered_sw_if_index,
963 mp->context);
964 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100965 }
Neale Ranns9e2f9152018-05-18 02:27:10 -0700966 /* *INDENT-ON* */
967 }
968
969 BAD_SW_IF_INDEX_LABEL;
970}
971
972static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500973vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
974{
975 vpe_api_main_t *am = &vpe_api_main;
976 vnet_main_t *vnm = vnet_get_main ();
Neale Rannscbe25aa2019-09-30 10:53:31 +0000977 //vlib_main_t *vm = vlib_get_main ();
Dave Barachb5e8a772016-12-06 12:04:42 -0500978 vnet_interface_main_t *im = &vnm->interface_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800979 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500980 vnet_sw_interface_t *si, *sorted_sis;
981 u32 sw_if_index = ~0;
982
Florin Coras6c4dae22018-01-09 06:39:23 -0800983 reg = vl_api_client_index_to_registration (mp->client_index);
984 if (!reg)
985 return;
Dave Barachb5e8a772016-12-06 12:04:42 -0500986
987 /* Gather interfaces. */
988 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
989 _vec_len (sorted_sis) = 0;
990 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100991 pool_foreach (si, im->sw_interfaces)
992 {
Dave Barachb5e8a772016-12-06 12:04:42 -0500993 vec_add1 (sorted_sis, si[0]);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100994 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500995 /* *INDENT-ON* */
996
997 vec_foreach (si, sorted_sis)
998 {
999 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1000 {
Neale Rannscbe25aa2019-09-30 10:53:31 +00001001 /* if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) */
1002 /* { */
1003 /* continue; */
1004 /* } */
Dave Barachb5e8a772016-12-06 12:04:42 -05001005 sw_if_index = si->sw_if_index;
Florin Coras6c4dae22018-01-09 06:39:23 -08001006 send_ip_details (am, reg, sw_if_index, mp->is_ipv6, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -05001007 }
1008 }
Matthew Smith6d5f6592019-09-18 13:51:46 -05001009
1010 vec_free (sorted_sis);
Dave Barachb5e8a772016-12-06 12:04:42 -05001011}
1012
1013static void
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001014vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t *mp)
Dave Barachb5e8a772016-12-06 12:04:42 -05001015{
1016 vl_api_set_ip_flow_hash_reply_t *rmp;
Neale Ranns227038a2017-04-21 01:07:59 -07001017 int rv;
1018 u32 table_id;
1019 flow_hash_config_t flow_hash_config = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -05001020
Neale Ranns227038a2017-04-21 01:07:59 -07001021 table_id = ntohl (mp->vrf_id);
1022
1023#define _(a,b) if (mp->a) flow_hash_config |= b;
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001024 foreach_flow_hash_bit_v1;
Neale Ranns227038a2017-04-21 01:07:59 -07001025#undef _
1026
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001027 rv = ip_flow_hash_set ((mp->is_ipv6 ? AF_IP6 : AF_IP4), table_id,
1028 flow_hash_config);
Dave Barachb5e8a772016-12-06 12:04:42 -05001029
1030 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1031}
1032
1033static void
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001034vl_api_set_ip_flow_hash_v2_t_handler (vl_api_set_ip_flow_hash_v2_t *mp)
Dave Barachb5e8a772016-12-06 12:04:42 -05001035{
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001036 vl_api_set_ip_flow_hash_v2_reply_t *rmp;
1037 ip_address_family_t af;
Dave Barachb5e8a772016-12-06 12:04:42 -05001038 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -05001039
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001040 rv = ip_address_family_decode (mp->af, &af);
Dave Barachb5e8a772016-12-06 12:04:42 -05001041
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001042 if (!rv)
1043 rv = ip_flow_hash_set (af, htonl (mp->table_id),
1044 htonl (mp->flow_hash_config));
Dave Barachb5e8a772016-12-06 12:04:42 -05001045
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00001046 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_V2_REPLY);
Dave Barachb5e8a772016-12-06 12:04:42 -05001047}
1048
Neale Ranns32e1c012016-11-22 17:07:28 +00001049void
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001050vl_mfib_signal_send_one (vl_api_registration_t * reg,
Neale Ranns32e1c012016-11-22 17:07:28 +00001051 u32 context, const mfib_signal_t * mfs)
1052{
1053 vl_api_mfib_signal_details_t *mp;
Neale Ranns9e829a82018-12-17 05:50:32 -08001054 const mfib_prefix_t *prefix;
Neale Ranns32e1c012016-11-22 17:07:28 +00001055 mfib_table_t *mfib;
1056 mfib_itf_t *mfi;
1057
1058 mp = vl_msg_api_alloc (sizeof (*mp));
1059
Dave Barachb7b92992018-10-17 10:38:51 -04001060 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns32e1c012016-11-22 17:07:28 +00001061 mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS);
1062 mp->context = context;
1063
1064 mfi = mfib_itf_get (mfs->mfs_itf);
Neale Ranns9e829a82018-12-17 05:50:32 -08001065 prefix = mfib_entry_get_prefix (mfs->mfs_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +00001066 mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry),
Neale Ranns9e829a82018-12-17 05:50:32 -08001067 prefix->fp_proto);
Neale Ranns32e1c012016-11-22 17:07:28 +00001068 mp->table_id = ntohl (mfib->mft_table_id);
1069 mp->sw_if_index = ntohl (mfi->mfi_sw_if_index);
1070
Neale Ranns097fa662018-05-01 05:17:55 -07001071 ip_mprefix_encode (prefix, &mp->prefix);
Neale Ranns32e1c012016-11-22 17:07:28 +00001072
1073 if (0 != mfs->mfs_buffer_len)
1074 {
1075 mp->ip_packet_len = ntohs (mfs->mfs_buffer_len);
1076
1077 memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len);
1078 }
1079 else
1080 {
1081 mp->ip_packet_len = 0;
1082 }
1083
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001084 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00001085}
1086
1087static void
1088vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
1089{
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001090 vl_api_registration_t *reg;
Neale Ranns32e1c012016-11-22 17:07:28 +00001091
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001092 reg = vl_api_client_index_to_registration (mp->client_index);
1093 if (!reg)
1094 return;
Neale Ranns32e1c012016-11-22 17:07:28 +00001095
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001096 while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
Neale Ranns32e1c012016-11-22 17:07:28 +00001097 ;
1098}
Dave Barachb5e8a772016-12-06 12:04:42 -05001099
Florin Coras595992c2017-11-06 17:17:08 -08001100static void
1101 vl_api_ip_container_proxy_add_del_t_handler
1102 (vl_api_ip_container_proxy_add_del_t * mp)
1103{
1104 vl_api_ip_container_proxy_add_del_reply_t *rmp;
1105 vnet_ip_container_proxy_args_t args;
1106 int rv = 0;
1107 clib_error_t *error;
1108
Dave Barachb7b92992018-10-17 10:38:51 -04001109 clib_memset (&args, 0, sizeof (args));
Neale Ranns37029302018-08-10 05:30:06 -07001110
1111 ip_prefix_decode (&mp->pfx, &args.prefix);
1112
Florin Coras595992c2017-11-06 17:17:08 -08001113 args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1114 args.is_add = mp->is_add;
1115 if ((error = vnet_ip_container_proxy_add_del (&args)))
1116 {
1117 rv = clib_error_get_code (error);
1118 clib_error_report (error);
1119 }
1120
1121 REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
1122}
1123
Matus Fabian75b9f452018-10-02 23:27:21 -07001124typedef struct ip_container_proxy_walk_ctx_t_
1125{
1126 vl_api_registration_t *reg;
1127 u32 context;
1128} ip_container_proxy_walk_ctx_t;
1129
1130static int
1131ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
1132 void *args)
1133{
1134 vl_api_ip_container_proxy_details_t *mp;
1135 ip_container_proxy_walk_ctx_t *ctx = args;
1136
1137 mp = vl_msg_api_alloc (sizeof (*mp));
1138 if (!mp)
1139 return 1;
1140
Dave Barachb7b92992018-10-17 10:38:51 -04001141 clib_memset (mp, 0, sizeof (*mp));
Matus Fabian75b9f452018-10-02 23:27:21 -07001142 mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
1143 mp->context = ctx->context;
1144
1145 mp->sw_if_index = ntohl (sw_if_index);
1146 ip_prefix_encode (pfx, &mp->prefix);
1147
1148 vl_api_send_msg (ctx->reg, (u8 *) mp);
1149
1150 return 1;
1151}
1152
1153static void
1154vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t *
1155 mp)
1156{
1157 vl_api_registration_t *reg;
1158
1159 reg = vl_api_client_index_to_registration (mp->client_index);
1160 if (!reg)
1161 return;
1162
1163 ip_container_proxy_walk_ctx_t ctx = {
1164 .context = mp->context,
1165 .reg = reg,
1166 };
1167
1168 ip_container_proxy_walk (ip_container_proxy_send_details, &ctx);
1169}
1170
Neale Rannsb8d44812017-11-10 06:53:54 -08001171static void
1172vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1173{
1174 int rv = 0;
1175 vl_api_ioam_enable_reply_t *rmp;
1176 clib_error_t *error;
1177
1178 /* Ignoring the profile id as currently a single profile
1179 * is supported */
1180 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1181 mp->seqno, mp->analyse);
1182 if (error)
1183 {
1184 clib_error_report (error);
1185 rv = clib_error_get_code (error);
1186 }
1187
1188 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1189}
1190
1191static void
1192vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1193{
1194 int rv = 0;
1195 vl_api_ioam_disable_reply_t *rmp;
1196 clib_error_t *error;
1197
1198 error = clear_ioam_rewrite_fn ();
1199 if (error)
1200 {
1201 clib_error_report (error);
1202 rv = clib_error_get_code (error);
1203 }
1204
1205 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1206}
1207
1208static void
1209 vl_api_ip_source_and_port_range_check_add_del_t_handler
1210 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1211{
1212 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1213 int rv = 0;
1214
Neale Rannsb8d44812017-11-10 06:53:54 -08001215 u8 is_add = mp->is_add;
Neale Ranns37029302018-08-10 05:30:06 -07001216 fib_prefix_t pfx;
Neale Rannsb8d44812017-11-10 06:53:54 -08001217 u16 *low_ports = 0;
1218 u16 *high_ports = 0;
1219 u32 vrf_id;
1220 u16 tmp_low, tmp_high;
1221 u8 num_ranges;
1222 int i;
1223
Neale Ranns37029302018-08-10 05:30:06 -07001224 ip_prefix_decode (&mp->prefix, &pfx);
1225
Neale Rannsb8d44812017-11-10 06:53:54 -08001226 // Validate port range
1227 num_ranges = mp->number_of_ranges;
1228 if (num_ranges > 32)
1229 { // This is size of array in VPE.API
1230 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1231 goto reply;
1232 }
1233
1234 vec_reset_length (low_ports);
1235 vec_reset_length (high_ports);
1236
1237 for (i = 0; i < num_ranges; i++)
1238 {
1239 tmp_low = mp->low_ports[i];
1240 tmp_high = mp->high_ports[i];
1241 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1242 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1243 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1244 {
1245 rv = VNET_API_ERROR_INVALID_VALUE;
1246 goto reply;
1247 }
1248 vec_add1 (low_ports, tmp_low);
1249 vec_add1 (high_ports, tmp_high + 1);
1250 }
1251
Neale Rannsb8d44812017-11-10 06:53:54 -08001252 vrf_id = ntohl (mp->vrf_id);
1253
1254 if (vrf_id < 1)
1255 {
1256 rv = VNET_API_ERROR_INVALID_VALUE;
1257 goto reply;
1258 }
1259
1260
Neale Ranns37029302018-08-10 05:30:06 -07001261 if (FIB_PROTOCOL_IP6 == pfx.fp_proto)
Neale Rannsb8d44812017-11-10 06:53:54 -08001262 {
Neale Ranns37029302018-08-10 05:30:06 -07001263 rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6,
1264 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001265 vrf_id,
1266 low_ports,
1267 high_ports, is_add);
1268 }
1269 else
1270 {
Neale Ranns37029302018-08-10 05:30:06 -07001271 rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4,
1272 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001273 vrf_id,
1274 low_ports,
1275 high_ports, is_add);
1276 }
1277
1278reply:
1279 vec_free (low_ports);
1280 vec_free (high_ports);
1281 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1282}
1283
1284static void
1285 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1286 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
1287{
1288 vlib_main_t *vm = vlib_get_main ();
1289 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
1290 ip4_main_t *im = &ip4_main;
1291 int rv;
1292 u32 sw_if_index;
1293 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1294 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1295 uword *p = 0;
1296 int i;
1297
1298 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
1299 ntohl (mp->tcp_out_vrf_id);
1300 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
1301 ntohl (mp->udp_out_vrf_id);
1302 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
1303 ntohl (mp->tcp_in_vrf_id);
1304 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
1305 ntohl (mp->udp_in_vrf_id);
1306
1307
1308 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
1309 {
1310 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
1311 {
1312 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
1313
1314 if (p == 0)
1315 {
1316 rv = VNET_API_ERROR_INVALID_VALUE;
1317 goto reply;
1318 }
1319
1320 fib_index[i] = p[0];
1321 }
1322 else
1323 fib_index[i] = ~0;
1324 }
1325 sw_if_index = ntohl (mp->sw_if_index);
1326
1327 VALIDATE_SW_IF_INDEX (mp);
1328
1329 rv =
1330 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
1331 mp->is_add);
1332
1333 BAD_SW_IF_INDEX_LABEL;
1334reply:
1335
1336 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
1337}
1338
Neale Rannscbe25aa2019-09-30 10:53:31 +00001339static void
1340 vl_api_sw_interface_ip6_set_link_local_address_t_handler
1341 (vl_api_sw_interface_ip6_set_link_local_address_t * mp)
1342{
1343 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
1344 ip6_address_t ip;
1345 int rv;
1346
1347 VALIDATE_SW_IF_INDEX (mp);
1348
1349 ip6_address_decode (mp->ip, &ip);
1350
Neale Rannsec40a7d2020-04-23 07:36:12 +00001351 rv = ip6_link_set_local_address (ntohl (mp->sw_if_index), &ip);
Neale Rannscbe25aa2019-09-30 10:53:31 +00001352
1353 BAD_SW_IF_INDEX_LABEL;
1354 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
1355}
1356
Neale Ranns9db6ada2019-11-08 12:42:31 +00001357static void
Benoît Ganne58a19152021-01-18 19:24:34 +01001358vl_api_sw_interface_ip6_get_link_local_address_t_handler (
1359 vl_api_sw_interface_ip6_get_link_local_address_t *mp)
1360{
1361 vl_api_sw_interface_ip6_get_link_local_address_reply_t *rmp;
1362 const ip6_address_t *ip = NULL;
1363 int rv = 0;
1364
1365 VALIDATE_SW_IF_INDEX (mp);
1366
1367 ip = ip6_get_link_local_address (ntohl (mp->sw_if_index));
1368 if (NULL == ip)
1369 rv = VNET_API_ERROR_IP6_NOT_ENABLED;
1370
1371 BAD_SW_IF_INDEX_LABEL;
1372 /* clang-format off */
1373 REPLY_MACRO2 (VL_API_SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS_REPLY,
1374 ({
1375 if (!rv)
1376 ip6_address_encode (ip, rmp->ip);
1377 }))
1378 /* clang-format on */
1379}
1380
1381static void
Neale Ranns9db6ada2019-11-08 12:42:31 +00001382vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp)
Neale Rannsb8d44812017-11-10 06:53:54 -08001383{
Neale Ranns9db6ada2019-11-08 12:42:31 +00001384 vl_api_ip_table_replace_begin_reply_t *rmp;
1385 fib_protocol_t fproto;
1386 u32 fib_index;
1387 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -08001388
Neale Ranns9db6ada2019-11-08 12:42:31 +00001389 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1390 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
Neale Rannsb8d44812017-11-10 06:53:54 -08001391
Neale Ranns9db6ada2019-11-08 12:42:31 +00001392 if (INDEX_INVALID == fib_index)
1393 rv = VNET_API_ERROR_NO_SUCH_FIB;
1394 else
1395 {
1396 fib_table_mark (fib_index, fproto, FIB_SOURCE_API);
1397 mfib_table_mark (mfib_table_find (fproto, ntohl (mp->table.table_id)),
1398 fproto, MFIB_SOURCE_API);
Neale Rannsb8d44812017-11-10 06:53:54 -08001399 }
Neale Ranns9db6ada2019-11-08 12:42:31 +00001400 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY);
Neale Rannsb8d44812017-11-10 06:53:54 -08001401}
1402
1403static void
Neale Ranns9db6ada2019-11-08 12:42:31 +00001404vl_api_ip_table_replace_end_t_handler (vl_api_ip_table_replace_end_t * mp)
Neale Rannsb8d44812017-11-10 06:53:54 -08001405{
Neale Ranns9db6ada2019-11-08 12:42:31 +00001406 vl_api_ip_table_replace_end_reply_t *rmp;
1407 fib_protocol_t fproto;
1408 u32 fib_index;
1409 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -08001410
Neale Ranns9db6ada2019-11-08 12:42:31 +00001411 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1412 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1413
1414 if (INDEX_INVALID == fib_index)
1415 rv = VNET_API_ERROR_NO_SUCH_FIB;
Neale Rannsb8d44812017-11-10 06:53:54 -08001416 else
Neale Ranns9db6ada2019-11-08 12:42:31 +00001417 {
1418 fib_table_sweep (fib_index, fproto, FIB_SOURCE_API);
1419 mfib_table_sweep (mfib_table_find
1420 (fproto, ntohl (mp->table.table_id)), fproto,
1421 MFIB_SOURCE_API);
1422 }
1423 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY);
1424}
Neale Rannsb8d44812017-11-10 06:53:54 -08001425
Neale Ranns9db6ada2019-11-08 12:42:31 +00001426static void
1427vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
1428{
1429 vl_api_ip_table_flush_reply_t *rmp;
1430 fib_protocol_t fproto;
1431 u32 fib_index;
1432 int rv = 0;
1433
1434 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1435 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1436
1437 if (INDEX_INVALID == fib_index)
1438 rv = VNET_API_ERROR_NO_SUCH_FIB;
1439 else
1440 {
1441 vnet_main_t *vnm = vnet_get_main ();
1442 vnet_interface_main_t *im = &vnm->interface_main;
1443 vnet_sw_interface_t *si;
1444
1445 /* Shut down interfaces in this FIB / clean out intfc routes */
1446 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +01001447 pool_foreach (si, im->sw_interfaces)
1448 {
Neale Ranns9db6ada2019-11-08 12:42:31 +00001449 if (fib_index == fib_table_get_index_for_sw_if_index (fproto,
1450 si->sw_if_index))
1451 {
1452 u32 flags = si->flags;
1453 flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
1454 vnet_sw_interface_set_flags (vnm, si->sw_if_index, flags);
1455 }
Damjan Marionb2c31b62020-12-13 21:47:40 +01001456 }
Neale Ranns9db6ada2019-11-08 12:42:31 +00001457 /* *INDENT-ON* */
1458
1459 fib_table_flush (fib_index, fproto, FIB_SOURCE_API);
1460 mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)),
1461 fproto, MFIB_SOURCE_API);
1462 }
1463
1464 REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY);
Neale Rannsb8d44812017-11-10 06:53:54 -08001465}
1466
Klement Sekera75e7d132017-09-20 08:26:30 +02001467void
1468vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
1469{
1470 vl_api_ip_reassembly_set_reply_t *rmp;
1471 int rv = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001472 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera75e7d132017-09-20 08:26:30 +02001473 {
Klement Sekerade34c352019-06-25 11:19:22 +00001474 case IP_REASS_TYPE_FULL:
1475 if (mp->is_ip6)
1476 {
1477 rv = ip6_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1478 clib_net_to_host_u32
1479 (mp->max_reassemblies),
1480 clib_net_to_host_u32
1481 (mp->max_reassembly_length),
1482 clib_net_to_host_u32
1483 (mp->expire_walk_interval_ms));
1484 }
1485 else
1486 {
1487 rv = ip4_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1488 clib_net_to_host_u32
1489 (mp->max_reassemblies),
1490 clib_net_to_host_u32
1491 (mp->max_reassembly_length),
1492 clib_net_to_host_u32
1493 (mp->expire_walk_interval_ms));
1494 }
1495 break;
1496 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1497 if (mp->is_ip6)
1498 {
1499 rv =
1500 ip6_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1501 clib_net_to_host_u32 (mp->max_reassemblies),
1502 clib_net_to_host_u32
1503 (mp->max_reassembly_length),
1504 clib_net_to_host_u32
1505 (mp->expire_walk_interval_ms));
1506 }
1507 else
1508 {
1509 rv = ip4_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1510 clib_net_to_host_u32 (mp->max_reassemblies),
1511 clib_net_to_host_u32
1512 (mp->max_reassembly_length),
1513 clib_net_to_host_u32
1514 (mp->expire_walk_interval_ms));
1515 }
1516 break;
Klement Sekera75e7d132017-09-20 08:26:30 +02001517 }
1518
1519 REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
1520}
1521
1522void
1523vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
1524{
Ole Troan2e1c8962019-04-10 09:44:23 +02001525 vl_api_registration_t *rp;
Klement Sekera75e7d132017-09-20 08:26:30 +02001526
Ole Troan2e1c8962019-04-10 09:44:23 +02001527 rp = vl_api_client_index_to_registration (mp->client_index);
1528 if (rp == 0)
Klement Sekera75e7d132017-09-20 08:26:30 +02001529 return;
1530
1531 vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001532 clib_memset (rmp, 0, sizeof (*rmp));
Klement Sekera75e7d132017-09-20 08:26:30 +02001533 rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
1534 rmp->context = mp->context;
1535 rmp->retval = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001536 u32 timeout_ms;
1537 u32 max_reassemblies;
1538 u32 max_reassembly_length;
1539 u32 expire_walk_interval_ms;
1540 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera75e7d132017-09-20 08:26:30 +02001541 {
Klement Sekerade34c352019-06-25 11:19:22 +00001542 case IP_REASS_TYPE_FULL:
1543 if (mp->is_ip6)
1544 {
1545 rmp->is_ip6 = 1;
1546 ip6_full_reass_get (&timeout_ms, &max_reassemblies,
1547 &max_reassembly_length,
1548 &expire_walk_interval_ms);
1549 }
1550 else
1551 {
1552 rmp->is_ip6 = 0;
1553 ip4_full_reass_get (&timeout_ms, &max_reassemblies,
1554 &max_reassembly_length,
1555 &expire_walk_interval_ms);
1556 }
1557 break;
1558 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1559 if (mp->is_ip6)
1560 {
1561 rmp->is_ip6 = 1;
1562 ip6_sv_reass_get (&timeout_ms, &max_reassemblies,
1563 &max_reassembly_length, &expire_walk_interval_ms);
1564 }
1565 else
1566 {
1567 rmp->is_ip6 = 0;
1568 ip4_sv_reass_get (&timeout_ms, &max_reassemblies,
1569 &max_reassembly_length, &expire_walk_interval_ms);
1570 }
1571 break;
Klement Sekera75e7d132017-09-20 08:26:30 +02001572 }
Matthew Smithb3174df2019-12-03 12:41:53 -06001573 rmp->timeout_ms = clib_host_to_net_u32 (timeout_ms);
1574 rmp->max_reassemblies = clib_host_to_net_u32 (max_reassemblies);
1575 rmp->max_reassembly_length = clib_host_to_net_u32 (max_reassembly_length);
Klement Sekera75e7d132017-09-20 08:26:30 +02001576 rmp->expire_walk_interval_ms =
Matthew Smithb3174df2019-12-03 12:41:53 -06001577 clib_host_to_net_u32 (expire_walk_interval_ms);
Ole Troan2e1c8962019-04-10 09:44:23 +02001578 vl_api_send_msg (rp, (u8 *) rmp);
Klement Sekera75e7d132017-09-20 08:26:30 +02001579}
1580
Klement Sekera4c533132018-02-22 11:41:12 +01001581void
1582 vl_api_ip_reassembly_enable_disable_t_handler
1583 (vl_api_ip_reassembly_enable_disable_t * mp)
1584{
1585 vl_api_ip_reassembly_enable_disable_reply_t *rmp;
1586 int rv = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00001587 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera4c533132018-02-22 11:41:12 +01001588 {
Klement Sekerade34c352019-06-25 11:19:22 +00001589 case IP_REASS_TYPE_FULL:
Klement Sekera896c8962019-06-24 11:52:49 +00001590 rv =
Klement Sekerade34c352019-06-25 11:19:22 +00001591 ip4_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
1592 mp->enable_ip4);
1593 if (0 == rv)
1594 rv =
1595 ip6_full_reass_enable_disable (clib_net_to_host_u32
1596 (mp->sw_if_index), mp->enable_ip6);
1597 break;
1598 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1599 rv =
1600 ip4_sv_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
1601 mp->enable_ip4);
1602 if (0 == rv)
1603 {
1604 rv =
1605 ip6_sv_reass_enable_disable (clib_net_to_host_u32
1606 (mp->sw_if_index), mp->enable_ip6);
1607 }
1608 break;
Klement Sekera4c533132018-02-22 11:41:12 +01001609 }
1610
Choree7f61d12018-11-28 10:27:58 +03301611 REPLY_MACRO (VL_API_IP_REASSEMBLY_ENABLE_DISABLE_REPLY);
Klement Sekera4c533132018-02-22 11:41:12 +01001612}
1613
Neale Ranns92207752019-06-03 13:21:40 +00001614typedef struct ip_punt_redirect_walk_ctx_t_
Pavel Kotucek609e1212018-11-27 09:59:44 +01001615{
Neale Ranns92207752019-06-03 13:21:40 +00001616 vl_api_registration_t *reg;
1617 u32 context;
1618} ip_punt_redirect_walk_ctx_t;
1619
1620static walk_rc_t
1621send_ip_punt_redirect_details (u32 rx_sw_if_index,
1622 const ip_punt_redirect_rx_t * ipr, void *arg)
1623{
Neale Ranns92207752019-06-03 13:21:40 +00001624 ip_punt_redirect_walk_ctx_t *ctx = arg;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001625 vl_api_ip_punt_redirect_details_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07001626 fib_path_encode_ctx_t path_ctx = {
1627 .rpaths = NULL,
1628 };
Pavel Kotucek609e1212018-11-27 09:59:44 +01001629
1630 mp = vl_msg_api_alloc (sizeof (*mp));
1631 if (!mp)
Neale Ranns92207752019-06-03 13:21:40 +00001632 return (WALK_STOP);;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001633
1634 clib_memset (mp, 0, sizeof (*mp));
1635 mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
Neale Ranns92207752019-06-03 13:21:40 +00001636 mp->context = ctx->context;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001637
Neale Ranns097fa662018-05-01 05:17:55 -07001638 fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &path_ctx);
Neale Ranns92207752019-06-03 13:21:40 +00001639
1640 mp->punt.rx_sw_if_index = htonl (rx_sw_if_index);
Neale Ranns097fa662018-05-01 05:17:55 -07001641 mp->punt.tx_sw_if_index = htonl (path_ctx.rpaths[0].frp_sw_if_index);
Neale Ranns92207752019-06-03 13:21:40 +00001642
Neale Ranns097fa662018-05-01 05:17:55 -07001643 ip_address_encode (&path_ctx.rpaths[0].frp_addr,
Neale Ranns92207752019-06-03 13:21:40 +00001644 fib_proto_to_ip46 (ipr->fproto), &mp->punt.nh);
1645
1646 vl_api_send_msg (ctx->reg, (u8 *) mp);
1647
Neale Ranns097fa662018-05-01 05:17:55 -07001648 vec_free (path_ctx.rpaths);
Neale Ranns92207752019-06-03 13:21:40 +00001649
1650 return (WALK_CONTINUE);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001651}
1652
1653static void
1654vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp)
1655{
1656 vl_api_registration_t *reg;
Dave Barach77841402020-04-29 17:04:10 -04001657 fib_protocol_t fproto = FIB_PROTOCOL_IP4;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001658
Pavel Kotucek609e1212018-11-27 09:59:44 +01001659 reg = vl_api_client_index_to_registration (mp->client_index);
1660 if (!reg)
1661 return;
1662
Dave Barach77841402020-04-29 17:04:10 -04001663 if (mp->is_ipv6 == 1)
1664 fproto = FIB_PROTOCOL_IP6;
Pavel Kotucek609e1212018-11-27 09:59:44 +01001665
Neale Ranns92207752019-06-03 13:21:40 +00001666 ip_punt_redirect_walk_ctx_t ctx = {
1667 .reg = reg,
1668 .context = mp->context,
1669 };
1670
1671 if (~0 != mp->sw_if_index)
Pavel Kotucek609e1212018-11-27 09:59:44 +01001672 {
Neale Ranns92207752019-06-03 13:21:40 +00001673 u32 rx_sw_if_index;
1674 index_t pri;
1675
1676 rx_sw_if_index = ntohl (mp->sw_if_index);
1677 pri = ip_punt_redirect_find (fproto, rx_sw_if_index);
1678
1679 if (INDEX_INVALID == pri)
1680 return;
1681
1682 send_ip_punt_redirect_details (rx_sw_if_index,
1683 ip_punt_redirect_get (pri), &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001684 }
1685 else
Neale Ranns92207752019-06-03 13:21:40 +00001686 ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01001687}
1688
Dave Barachb5e8a772016-12-06 12:04:42 -05001689#define vl_msg_name_crc_list
1690#include <vnet/ip/ip.api.h>
1691#undef vl_msg_name_crc_list
1692
1693static void
1694setup_message_id_table (api_main_t * am)
1695{
1696#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1697 foreach_vl_msg_name_crc_ip;
1698#undef _
1699}
1700
1701static clib_error_t *
1702ip_api_hookup (vlib_main_t * vm)
1703{
Dave Barach39d69112019-11-27 11:42:13 -05001704 api_main_t *am = vlibapi_get_main ();
Dave Barachb5e8a772016-12-06 12:04:42 -05001705
1706#define _(N,n) \
1707 vl_msg_api_set_handlers(VL_API_##N, #n, \
1708 vl_api_##n##_t_handler, \
1709 vl_noop_handler, \
1710 vl_api_##n##_t_endian, \
1711 vl_api_##n##_t_print, \
1712 sizeof(vl_api_##n##_t), 1);
1713 foreach_ip_api_msg;
1714#undef _
1715
1716 /*
Neale Ranns6a231a12018-10-17 06:38:00 +00001717 * Mark the route add/del API as MP safe
1718 */
Neale Ranns097fa662018-05-01 05:17:55 -07001719 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1;
1720 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL_REPLY] = 1;
Neale Ranns6a231a12018-10-17 06:38:00 +00001721
1722 /*
Dave Barachb5e8a772016-12-06 12:04:42 -05001723 * Set up the (msg_name, crc, message-id) table
1724 */
1725 setup_message_id_table (am);
1726
Dave Barachb5e8a772016-12-06 12:04:42 -05001727 return 0;
1728}
1729
1730VLIB_API_INIT_FUNCTION (ip_api_hookup);
1731
1732/*
1733 * fd.io coding-style-patch-verification: ON
1734 *
1735 * Local Variables:
1736 * eval: (c-set-style "gnu")
1737 * End:
1738 */