blob: 6da6ac34d483e87f887d5533a08b57206fba7ee5 [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>
John Lo7f358b32018-04-28 01:19:24 -040028#include <vnet/ip/ip_neighbor.h>
Neale Ranns37029302018-08-10 05:30:06 -070029#include <vnet/ip/ip_types_api.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050030#include <vnet/ip/ip6_neighbor.h>
Pavel Kotucek609e1212018-11-27 09:59:44 +010031#include <vnet/ip/ip_punt_drop.h>
Neale Ranns097fa662018-05-01 05:17:55 -070032#include <vnet/ip/ip_types_api.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050033#include <vnet/fib/fib_table.h>
34#include <vnet/fib/fib_api.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050035#include <vnet/ethernet/arp_packet.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080036#include <vnet/mfib/ip6_mfib.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000037#include <vnet/mfib/ip4_mfib.h>
38#include <vnet/mfib/mfib_signal.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080039#include <vnet/mfib/mfib_entry.h>
Neale Ranns097fa662018-05-01 05:17:55 -070040#include <vnet/mfib/mfib_api.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080041#include <vnet/ip/ip_source_and_port_range_check.h>
42#include <vnet/fib/ip4_fib.h>
43#include <vnet/fib/ip6_fib.h>
Neale Ranns92207752019-06-03 13:21:40 +000044#include <vnet/fib/fib_path_list.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080045#include <vnet/ip/ip6_hop_by_hop.h>
Klement Sekerade34c352019-06-25 11:19:22 +000046#include <vnet/ip/reass/ip4_sv_reass.h>
Klement Sekera896c8962019-06-24 11:52:49 +000047#include <vnet/ip/reass/ip4_full_reass.h>
Klement Sekerade34c352019-06-25 11:19:22 +000048#include <vnet/ip/reass/ip6_sv_reass.h>
Klement Sekera896c8962019-06-24 11:52:49 +000049#include <vnet/ip/reass/ip6_full_reass.h>
Neale Ranns0053de62018-05-22 08:40:52 -070050#include <vnet/ethernet/arp.h>
Matus Fabian75b9f452018-10-02 23:27:21 -070051#include <vnet/ip/ip_types_api.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050052
53#include <vnet/vnet_msg_enum.h>
54
55#define vl_typedefs /* define message structures */
56#include <vnet/vnet_all_api_h.h>
57#undef vl_typedefs
58
59#define vl_endianfun /* define message structures */
60#include <vnet/vnet_all_api_h.h>
61#undef vl_endianfun
62
63/* instantiate all the print functions we know about */
64#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
65#define vl_printfun
66#include <vnet/vnet_all_api_h.h>
67#undef vl_printfun
68
69#include <vlibapi/api_helper_macros.h>
70
Ole Troan33a58172019-09-04 09:12:29 +020071#include <vnet/format_fns.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080072
Dave Barachb5e8a772016-12-06 12:04:42 -050073#define foreach_ip_api_msg \
Neale Ranns097fa662018-05-01 05:17:55 -070074_(IP_TABLE_DUMP, ip_table_dump) \
75_(IP_ROUTE_DUMP, ip_route_dump) \
76_(IP_MTABLE_DUMP, ip_mtable_dump) \
77_(IP_MROUTE_DUMP, ip_mroute_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050078_(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \
Neale Ranns32e1c012016-11-22 17:07:28 +000079_(IP_MROUTE_ADD_DEL, ip_mroute_add_del) \
Neale Ranns5a8123b2017-01-26 01:18:23 -080080_(MFIB_SIGNAL_DUMP, mfib_signal_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050081_(IP_ADDRESS_DUMP, ip_address_dump) \
Neale Ranns9e2f9152018-05-18 02:27:10 -070082_(IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050083_(IP_DUMP, ip_dump) \
84_(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
Neale Rannsb8d44812017-11-10 06:53:54 -080085_(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
John Loc7b43042018-04-13 16:46:22 -040086_(IP_PROBE_NEIGHBOR, ip_probe_neighbor) \
John Lo7f358b32018-04-28 01:19:24 -040087_(IP_SCAN_NEIGHBOR_ENABLE_DISABLE, ip_scan_neighbor_enable_disable) \
Neale Rannsb8d44812017-11-10 06:53:54 -080088_(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
89_(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010090_(WANT_IP6_RA_EVENTS, want_ip6_ra_events) \
Neale Rannsb8d44812017-11-10 06:53:54 -080091_(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
Neale Ranns0053de62018-05-22 08:40:52 -070092_(PROXY_ARP_DUMP, proxy_arp_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -080093_(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
Neale Ranns0053de62018-05-22 08:40:52 -070094 _(PROXY_ARP_INTFC_DUMP, proxy_arp_intfc_dump) \
Neale Ranns9db6ada2019-11-08 12:42:31 +000095_(IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin) \
96_(IP_TABLE_REPLACE_END, ip_table_replace_end) \
97_(IP_TABLE_FLUSH, ip_table_flush) \
Neale Ranns097fa662018-05-01 05:17:55 -070098_(IP_ROUTE_ADD_DEL, ip_route_add_del) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070099_(IP_TABLE_ADD_DEL, ip_table_add_del) \
Neale Rannsd91c1db2017-07-31 02:30:50 -0700100_(IP_PUNT_POLICE, ip_punt_police) \
101_(IP_PUNT_REDIRECT, ip_punt_redirect) \
Dave Barachb5e8a772016-12-06 12:04:42 -0500102_(SET_IP_FLOW_HASH,set_ip_flow_hash) \
103_(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
104_(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
Neale Ranns3f844d02017-02-18 00:03:54 -0800105_(IP6ND_PROXY_ADD_DEL, ip6nd_proxy_add_del) \
106_(IP6ND_PROXY_DUMP, ip6nd_proxy_dump) \
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100107_(IP6ND_SEND_ROUTER_SOLICITATION, ip6nd_send_router_solicitation) \
Dave Barachb5e8a772016-12-06 12:04:42 -0500108_(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
Neale Rannsb8d44812017-11-10 06:53:54 -0800109_(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \
Matus Fabian75b9f452018-10-02 23:27:21 -0700110_(IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -0800111_(IOAM_ENABLE, ioam_enable) \
112_(IOAM_DISABLE, ioam_disable) \
113_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
114 ip_source_and_port_range_check_add_del) \
115_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
Klement Sekera75e7d132017-09-20 08:26:30 +0200116 ip_source_and_port_range_check_interface_add_del) \
Chore3460b012018-11-28 10:53:11 +0330117_(IP_SOURCE_CHECK_INTERFACE_ADD_DEL, \
118 ip_source_check_interface_add_del) \
Klement Sekera75e7d132017-09-20 08:26:30 +0200119_(IP_REASSEMBLY_SET, ip_reassembly_set) \
Klement Sekera4c533132018-02-22 11:41:12 +0100120_(IP_REASSEMBLY_GET, ip_reassembly_get) \
Pavel Kotucek609e1212018-11-27 09:59:44 +0100121_(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
122_(IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
123
Dave Barachb5e8a772016-12-06 12:04:42 -0500124
Neale Ranns37029302018-08-10 05:30:06 -0700125static vl_api_ip_neighbor_flags_t
126ip_neighbor_flags_encode (ip_neighbor_flags_t f)
127{
128 vl_api_ip_neighbor_flags_t v = IP_API_NEIGHBOR_FLAG_NONE;
129
130 if (f & IP_NEIGHBOR_FLAG_STATIC)
131 v |= IP_API_NEIGHBOR_FLAG_STATIC;
132 if (f & IP_NEIGHBOR_FLAG_NO_FIB_ENTRY)
133 v |= IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY;
134
135 return (clib_host_to_net_u32 (v));
136}
137
Dave Barachb5e8a772016-12-06 12:04:42 -0500138static void
Jon Loeligeraf8dfbf2017-11-08 13:07:39 -0600139send_ip_neighbor_details (u32 sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700140 const ip46_address_t * ip_address,
141 const mac_address_t * mac,
142 ip_neighbor_flags_t flags,
143 vl_api_registration_t * reg, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500144{
145 vl_api_ip_neighbor_details_t *mp;
146
147 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400148 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500149 mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS);
150 mp->context = context;
Neale Ranns37029302018-08-10 05:30:06 -0700151 mp->neighbor.sw_if_index = htonl (sw_if_index);
152 mp->neighbor.flags = ip_neighbor_flags_encode (flags);
153
154 ip_address_encode (ip_address, IP46_TYPE_ANY, &mp->neighbor.ip_address);
155 mac_address_encode (mac, mp->neighbor.mac_address);
Dave Barachb5e8a772016-12-06 12:04:42 -0500156
Florin Coras6c4dae22018-01-09 06:39:23 -0800157 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500158}
159
160static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500161vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp)
162{
Florin Coras6c4dae22018-01-09 06:39:23 -0800163 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500164
Florin Coras6c4dae22018-01-09 06:39:23 -0800165 reg = vl_api_client_index_to_registration (mp->client_index);
166 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500167 return;
168
169 u32 sw_if_index = ntohl (mp->sw_if_index);
170
171 if (mp->is_ipv6)
172 {
173 ip6_neighbor_t *n, *ns;
174
175 ns = ip6_neighbors_entries (sw_if_index);
176 /* *INDENT-OFF* */
177 vec_foreach (n, ns)
178 {
Neale Ranns37029302018-08-10 05:30:06 -0700179 ip46_address_t nh = {
180 .ip6 = {
181 .as_u64[0] = n->key.ip6_address.as_u64[0],
182 .as_u64[1] = n->key.ip6_address.as_u64[1],
183 },
184 };
185 send_ip_neighbor_details (n->key.sw_if_index, &nh,
186 &n->mac, n->flags,
187 reg, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500188 }
189 /* *INDENT-ON* */
190 vec_free (ns);
191 }
192 else
193 {
194 ethernet_arp_ip4_entry_t *n, *ns;
195
196 ns = ip4_neighbor_entries (sw_if_index);
197 /* *INDENT-OFF* */
198 vec_foreach (n, ns)
199 {
Neale Ranns37029302018-08-10 05:30:06 -0700200 ip46_address_t nh = {
201 .ip4 = {
202 .as_u32 = n->ip4_address.as_u32,
203 },
204 };
205
206 send_ip_neighbor_details (n->sw_if_index, &nh,
207 &n->mac, n->flags,
208 reg, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500209 }
210 /* *INDENT-ON* */
211 vec_free (ns);
212 }
213}
214
Dave Barachb5e8a772016-12-06 12:04:42 -0500215static void
Neale Ranns097fa662018-05-01 05:17:55 -0700216send_ip_table_details (vpe_api_main_t * am,
217 vl_api_registration_t * reg,
218 u32 context, const fib_table_t * table)
Dave Barachb5e8a772016-12-06 12:04:42 -0500219{
Neale Ranns097fa662018-05-01 05:17:55 -0700220 vl_api_ip_table_details_t *mp;
Dave Barachb5e8a772016-12-06 12:04:42 -0500221
Neale Ranns097fa662018-05-01 05:17:55 -0700222 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500223 if (!mp)
224 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400225 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700226 mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500227 mp->context = context;
228
Neale Ranns097fa662018-05-01 05:17:55 -0700229 mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6);
230 mp->table.table_id = htonl (table->ft_table_id);
231 memcpy (mp->table.name, table->ft_desc,
232 clib_min (vec_len (table->ft_desc), sizeof (mp->table.name)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500233
Florin Coras6c4dae22018-01-09 06:39:23 -0800234 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500235}
236
Neale Ranns097fa662018-05-01 05:17:55 -0700237static void
238vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp)
239{
240 vpe_api_main_t *am = &vpe_api_main;
241 vl_api_registration_t *reg;
242 fib_table_t *fib_table;
243
244 reg = vl_api_client_index_to_registration (mp->client_index);
245 if (!reg)
246 return;
247
248 /* *INDENT-OFF* */
249 pool_foreach (fib_table, ip4_main.fibs,
250 ({
251 send_ip_table_details(am, reg, mp->context, fib_table);
252 }));
253 pool_foreach (fib_table, ip6_main.fibs,
254 ({
255 /* don't send link locals */
256 if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
257 continue;
258 send_ip_table_details(am, reg, mp->context, fib_table);
259 }));
260 /* *INDENT-ON* */
261}
262
Neale Rannsa3af3372017-03-28 03:49:52 -0700263typedef struct vl_api_ip_fib_dump_walk_ctx_t_
264{
265 fib_node_index_t *feis;
266} vl_api_ip_fib_dump_walk_ctx_t;
267
Neale Ranns89541992017-04-06 04:41:02 -0700268static fib_table_walk_rc_t
Neale Rannsa3af3372017-03-28 03:49:52 -0700269vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg)
270{
271 vl_api_ip_fib_dump_walk_ctx_t *ctx = arg;
272
273 vec_add1 (ctx->feis, fei);
274
Neale Ranns89541992017-04-06 04:41:02 -0700275 return (FIB_TABLE_WALK_CONTINUE);
Neale Rannsa3af3372017-03-28 03:49:52 -0700276}
277
Dave Barachb5e8a772016-12-06 12:04:42 -0500278static void
Neale Ranns097fa662018-05-01 05:17:55 -0700279send_ip_route_details (vpe_api_main_t * am,
280 vl_api_registration_t * reg,
281 u32 context, fib_node_index_t fib_entry_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500282{
Neale Ranns097fa662018-05-01 05:17:55 -0700283 fib_route_path_t *rpaths, *rpath;
284 vl_api_ip_route_details_t *mp;
Neale Rannsc5d43172018-07-30 08:04:40 -0700285 const fib_prefix_t *pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -0500286 vl_api_fib_path_t *fp;
287 int path_count;
288
Neale Ranns097fa662018-05-01 05:17:55 -0700289 rpaths = NULL;
290 pfx = fib_entry_get_prefix (fib_entry_index);
291 rpaths = fib_entry_encode (fib_entry_index);
292
293 path_count = vec_len (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500294 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
295 if (!mp)
296 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400297 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700298 mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500299 mp->context = context;
300
Neale Ranns097fa662018-05-01 05:17:55 -0700301 ip_prefix_encode (pfx, &mp->route.prefix);
302 mp->route.table_id =
303 htonl (fib_table_get_table_id
304 (fib_entry_get_fib_index (fib_entry_index), pfx->fp_proto));
305 mp->route.n_paths = path_count;
306 mp->route.stats_index =
307 htonl (fib_table_entry_get_stats_index
308 (fib_entry_get_fib_index (fib_entry_index), pfx));
Dave Barachb5e8a772016-12-06 12:04:42 -0500309
Neale Ranns097fa662018-05-01 05:17:55 -0700310 fp = mp->route.paths;
311 vec_foreach (rpath, rpaths)
Dave Barachb5e8a772016-12-06 12:04:42 -0500312 {
Neale Ranns097fa662018-05-01 05:17:55 -0700313 fib_api_path_encode (rpath, fp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500314 fp++;
315 }
316
Florin Coras6c4dae22018-01-09 06:39:23 -0800317 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns9db6ada2019-11-08 12:42:31 +0000318 vec_free (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500319}
320
Dave Barachd7cb1b52016-12-09 09:52:16 -0500321typedef struct apt_ip6_fib_show_ctx_t_
322{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500323 fib_node_index_t *entries;
Dave Barachb5e8a772016-12-06 12:04:42 -0500324} api_ip6_fib_show_ctx_t;
325
Dave Barachb5e8a772016-12-06 12:04:42 -0500326static void
Neale Ranns097fa662018-05-01 05:17:55 -0700327vl_api_ip_route_dump_t_handler (vl_api_ip_route_dump_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500328{
329 vpe_api_main_t *am = &vpe_api_main;
Dave Barachb5e8a772016-12-06 12:04:42 -0500330 fib_node_index_t *fib_entry_index;
Florin Coras6c4dae22018-01-09 06:39:23 -0800331 vl_api_registration_t *reg;
Neale Ranns097fa662018-05-01 05:17:55 -0700332 fib_protocol_t fproto;
333 u32 fib_index;
Dave Barachb5e8a772016-12-06 12:04:42 -0500334
Florin Coras6c4dae22018-01-09 06:39:23 -0800335 reg = vl_api_client_index_to_registration (mp->client_index);
336 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500337 return;
338
Neale Ranns097fa662018-05-01 05:17:55 -0700339 vl_api_ip_fib_dump_walk_ctx_t ctx = {
340 .feis = NULL,
341 };
Neale Ranns81458422018-03-12 06:59:36 -0700342
Neale Ranns097fa662018-05-01 05:17:55 -0700343 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
344 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
345
346 if (INDEX_INVALID == fib_index)
347 return;
348
349 fib_table_walk (fib_index, fproto, vl_api_ip_fib_dump_walk, &ctx);
350
351 vec_foreach (fib_entry_index, ctx.feis)
352 {
353 send_ip_route_details (am, reg, mp->context, *fib_entry_index);
354 }
355
356 vec_free (ctx.feis);
Dave Barachb5e8a772016-12-06 12:04:42 -0500357}
358
359static void
Neale Ranns097fa662018-05-01 05:17:55 -0700360send_ip_mtable_details (vl_api_registration_t * reg,
361 u32 context, const mfib_table_t * mfib_table)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800362{
Neale Ranns097fa662018-05-01 05:17:55 -0700363 vl_api_ip_mtable_details_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800364
Neale Ranns097fa662018-05-01 05:17:55 -0700365 mp = vl_msg_api_alloc (sizeof (*mp));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800366 if (!mp)
367 return;
Neale Ranns097fa662018-05-01 05:17:55 -0700368 memset (mp, 0, sizeof (*mp));
369 mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800370 mp->context = context;
371
Neale Ranns097fa662018-05-01 05:17:55 -0700372 mp->table.table_id = htonl (mfib_table->mft_table_id);
373 mp->table.is_ip6 = (FIB_PROTOCOL_IP6 == mfib_table->mft_proto);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800374
Florin Coras6c4dae22018-01-09 06:39:23 -0800375 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800376}
377
Neale Ranns5a8123b2017-01-26 01:18:23 -0800378static void
Neale Ranns097fa662018-05-01 05:17:55 -0700379vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800380{
Florin Coras6c4dae22018-01-09 06:39:23 -0800381 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800382 mfib_table_t *mfib_table;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800383
Florin Coras6c4dae22018-01-09 06:39:23 -0800384 reg = vl_api_client_index_to_registration (mp->client_index);
385 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800386 return;
387
Neale Ranns5a8123b2017-01-26 01:18:23 -0800388 /* *INDENT-OFF* */
Neale Ranns097fa662018-05-01 05:17:55 -0700389 pool_foreach (mfib_table, ip4_main.mfibs,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800390 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700391 send_ip_mtable_details (reg, mp->context, mfib_table);
392 }));
393 pool_foreach (mfib_table, ip6_main.mfibs,
394 ({
395 send_ip_mtable_details (reg, mp->context, mfib_table);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800396 }));
397 /* *INDENT-ON* */
Neale Ranns5a8123b2017-01-26 01:18:23 -0800398}
399
Neale Ranns097fa662018-05-01 05:17:55 -0700400typedef struct vl_api_ip_mfib_dump_ctx_t_
Neale Ranns5a8123b2017-01-26 01:18:23 -0800401{
402 fib_node_index_t *entries;
Neale Ranns097fa662018-05-01 05:17:55 -0700403} vl_api_ip_mfib_dump_ctx_t;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800404
Neale Ranns9db6ada2019-11-08 12:42:31 +0000405static walk_rc_t
Neale Ranns097fa662018-05-01 05:17:55 -0700406mfib_route_dump_walk (fib_node_index_t fei, void *arg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800407{
Neale Ranns097fa662018-05-01 05:17:55 -0700408 vl_api_ip_mfib_dump_ctx_t *ctx = arg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800409
410 vec_add1 (ctx->entries, fei);
411
Neale Ranns9db6ada2019-11-08 12:42:31 +0000412 return (WALK_CONTINUE);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800413}
414
415static void
Neale Ranns097fa662018-05-01 05:17:55 -0700416send_ip_mroute_details (vpe_api_main_t * am,
417 vl_api_registration_t * reg,
418 u32 context, fib_node_index_t mfib_entry_index)
419{
420 fib_route_path_t *rpaths, *rpath;
421 vl_api_ip_mroute_details_t *mp;
422 const mfib_prefix_t *pfx;
423 vl_api_mfib_path_t *fp;
424 int path_count;
425
426 rpaths = NULL;
427 pfx = mfib_entry_get_prefix (mfib_entry_index);
428 rpaths = mfib_entry_encode (mfib_entry_index);
429
430 path_count = vec_len (rpaths);
431 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
432 if (!mp)
433 return;
434 clib_memset (mp, 0, sizeof (*mp));
435 mp->_vl_msg_id = ntohs (VL_API_IP_MROUTE_DETAILS);
436 mp->context = context;
437
438 ip_mprefix_encode (pfx, &mp->route.prefix);
439 mp->route.table_id =
440 htonl (mfib_table_get_table_id
441 (mfib_entry_get_fib_index (mfib_entry_index), pfx->fp_proto));
442 mp->route.n_paths = htonl (path_count);
443 fp = mp->route.paths;
444 vec_foreach (rpath, rpaths)
445 {
446 mfib_api_path_encode (rpath, fp);
447 fp++;
448 }
449
450 vl_api_send_msg (reg, (u8 *) mp);
451 vec_free (rpaths);
452}
453
454static void
455vl_api_ip_mroute_dump_t_handler (vl_api_ip_mroute_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800456{
457 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800458 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800459 fib_node_index_t *mfeip;
Neale Ranns097fa662018-05-01 05:17:55 -0700460 fib_protocol_t fproto;
461 u32 fib_index;
462
463 vl_api_ip_mfib_dump_ctx_t ctx = {
Neale Ranns5a8123b2017-01-26 01:18:23 -0800464 .entries = NULL,
465 };
466
Florin Coras6c4dae22018-01-09 06:39:23 -0800467 reg = vl_api_client_index_to_registration (mp->client_index);
468 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800469 return;
470
Neale Ranns097fa662018-05-01 05:17:55 -0700471 fproto = fib_ip_proto (mp->table.is_ip6);
472 fib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800473
Neale Ranns097fa662018-05-01 05:17:55 -0700474 if (INDEX_INVALID == fib_index)
475 return;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800476
Neale Ranns097fa662018-05-01 05:17:55 -0700477 mfib_table_walk (fib_index, fproto, mfib_route_dump_walk, &ctx);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800478
Neale Ranns097fa662018-05-01 05:17:55 -0700479 vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800480
Neale Ranns097fa662018-05-01 05:17:55 -0700481 vec_foreach (mfeip, ctx.entries)
482 {
483 send_ip_mroute_details (am, reg, mp->context, *mfeip);
484 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800485
486 vec_free (ctx.entries);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800487}
488
489static void
Neale Rannsd91c1db2017-07-31 02:30:50 -0700490vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp,
491 vlib_main_t * vm)
492{
493 vl_api_ip_punt_police_reply_t *rmp;
494 int rv = 0;
495
496 if (mp->is_ip6)
497 ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
498 else
499 ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
500
501 REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY);
502}
503
504static void
505vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp,
506 vlib_main_t * vm)
507{
508 vl_api_ip_punt_redirect_reply_t *rmp;
509 int rv = 0;
Pavel Kotucek609e1212018-11-27 09:59:44 +0100510 ip46_type_t ipv;
511 ip46_address_t nh;
Neale Rannsd91c1db2017-07-31 02:30:50 -0700512
Pavel Kotucek609e1212018-11-27 09:59:44 +0100513 if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index)))
514 goto bad_sw_if_index;
515
516 ipv = ip_address_decode (&mp->punt.nh, &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700517 if (mp->is_add)
518 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100519 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700520 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100521 ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
522 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700523 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100524 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700525 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100526 ip4_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
527 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700528 }
529 }
530 else
531 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100532 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700533 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100534 ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700535 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100536 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700537 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100538 ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700539 }
540 }
541
Pavel Kotucek609e1212018-11-27 09:59:44 +0100542 BAD_SW_IF_INDEX_LABEL;
543
Neale Rannsd91c1db2017-07-31 02:30:50 -0700544 REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY);
545}
546
Neale Ranns37029302018-08-10 05:30:06 -0700547static ip_neighbor_flags_t
548ip_neighbor_flags_decode (vl_api_ip_neighbor_flags_t v)
549{
550 ip_neighbor_flags_t f = IP_NEIGHBOR_FLAG_NONE;
551
552 v = clib_net_to_host_u32 (v);
553
554 if (v & IP_API_NEIGHBOR_FLAG_STATIC)
555 f |= IP_NEIGHBOR_FLAG_STATIC;
556 if (v & IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY)
557 f |= IP_NEIGHBOR_FLAG_NO_FIB_ENTRY;
558
559 return (f);
560}
561
Neale Rannsd91c1db2017-07-31 02:30:50 -0700562static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500563vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
564 vlib_main_t * vm)
565{
566 vl_api_ip_neighbor_add_del_reply_t *rmp;
Neale Ranns0bdd3192018-09-07 11:04:52 -0700567 ip_neighbor_flags_t flags;
Neale Ranns14260392018-09-28 05:00:57 -0700568 u32 stats_index = ~0;
Neale Ranns37029302018-08-10 05:30:06 -0700569 ip46_address_t ip;
570 mac_address_t mac;
571 ip46_type_t type;
Neale Ranns097fa662018-05-01 05:17:55 -0700572 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -0500573
Neale Ranns37029302018-08-10 05:30:06 -0700574 VALIDATE_SW_IF_INDEX ((&mp->neighbor));
Dave Barachb5e8a772016-12-06 12:04:42 -0500575
Neale Ranns37029302018-08-10 05:30:06 -0700576 flags = ip_neighbor_flags_decode (mp->neighbor.flags);
577 type = ip_address_decode (&mp->neighbor.ip_address, &ip);
578 mac_address_decode (mp->neighbor.mac_address, &mac);
Neale Ranns0bdd3192018-09-07 11:04:52 -0700579
Neale Ranns37029302018-08-10 05:30:06 -0700580 /*
581 * there's no validation here of the ND/ARP entry being added.
582 * The expectation is that the FIB will ensure that nothing bad
583 * will come of adding bogus entries.
584 */
Neale Ranns0bdd3192018-09-07 11:04:52 -0700585 if (mp->is_add)
Neale Ranns37029302018-08-10 05:30:06 -0700586 rv = ip_neighbor_add (&ip, type, &mac,
587 ntohl (mp->neighbor.sw_if_index),
588 flags, &stats_index);
Neale Ranns0bdd3192018-09-07 11:04:52 -0700589 else
Neale Ranns37029302018-08-10 05:30:06 -0700590 rv = ip_neighbor_del (&ip, type, ntohl (mp->neighbor.sw_if_index));
Dave Barachb5e8a772016-12-06 12:04:42 -0500591
Neale Ranns8edad032017-10-09 05:26:13 -0700592 BAD_SW_IF_INDEX_LABEL;
Neale Ranns14260392018-09-28 05:00:57 -0700593
594 /* *INDENT-OFF* */
595 REPLY_MACRO2 (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY,
596 ({
597 rmp->stats_index = htonl (stats_index);
598 }));
599 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500600}
601
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700602void
Neale Ranns15002542017-09-10 04:39:11 -0700603ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api)
604{
605 u32 fib_index, mfib_index;
606
607 /*
608 * ignore action on the default table - this is always present
609 * and cannot be added nor deleted from the API
610 */
611 if (0 != table_id)
612 {
613 /*
614 * The API holds only one lock on the table.
615 * i.e. it can be added many times via the API but needs to be
616 * deleted only once.
617 * The FIB index for unicast and multicast is not necessarily the
618 * same, since internal VPP systesm (like LISP and SR) create
619 * their own unicast tables.
620 */
621 fib_index = fib_table_find (fproto, table_id);
622 mfib_index = mfib_table_find (fproto, table_id);
623
624 if (~0 != fib_index)
625 {
626 fib_table_unlock (fib_index, fproto,
627 (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI));
628 }
629 if (~0 != mfib_index)
630 {
631 mfib_table_unlock (mfib_index, fproto,
632 (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI));
633 }
634 }
635}
636
637void
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700638vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
639{
640 vl_api_ip_table_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700641 fib_protocol_t fproto = (mp->table.is_ip6 ?
642 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
643 u32 table_id = ntohl (mp->table.table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700644 int rv = 0;
645
Neale Ranns15002542017-09-10 04:39:11 -0700646 if (mp->is_add)
647 {
Neale Ranns097fa662018-05-01 05:17:55 -0700648 ip_table_create (fproto, table_id, 1, mp->table.name);
Neale Ranns15002542017-09-10 04:39:11 -0700649 }
650 else
651 {
652 ip_table_delete (fproto, table_id, 1);
653 }
654
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700655 REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY);
656}
657
Dave Barachb5e8a772016-12-06 12:04:42 -0500658static int
Neale Ranns097fa662018-05-01 05:17:55 -0700659ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp, u32 * stats_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500660{
Neale Ranns097fa662018-05-01 05:17:55 -0700661 fib_route_path_t *rpaths = NULL, *rpath;
662 fib_entry_flag_t entry_flags;
663 vl_api_fib_path_t *apath;
664 fib_prefix_t pfx;
665 u32 fib_index;
666 int rv, ii;
Dave Barachb5e8a772016-12-06 12:04:42 -0500667
Neale Ranns097fa662018-05-01 05:17:55 -0700668 entry_flags = FIB_ENTRY_FLAG_NONE;
669 ip_prefix_decode (&mp->route.prefix, &pfx);
Dave Barachb5e8a772016-12-06 12:04:42 -0500670
Neale Ranns097fa662018-05-01 05:17:55 -0700671 rv = fib_api_table_id_decode (pfx.fp_proto,
672 ntohl (mp->route.table_id), &fib_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500673 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700674 goto out;
Dave Barachb5e8a772016-12-06 12:04:42 -0500675
Neale Rannsc2ac2352019-07-02 14:33:29 +0000676 if (0 != mp->route.n_paths)
677 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns097fa662018-05-01 05:17:55 -0700678
679 for (ii = 0; ii < mp->route.n_paths; ii++)
680 {
681 apath = &mp->route.paths[ii];
682 rpath = &rpaths[ii];
683
684 rv = fib_api_path_decode (apath, rpath);
685
686 if ((rpath->frp_flags & FIB_ROUTE_PATH_LOCAL) &&
687 (~0 == rpath->frp_sw_if_index))
688 entry_flags |= (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL);
689
690 if (0 != rv)
691 goto out;
692 }
693
Neale Rannsc2ac2352019-07-02 14:33:29 +0000694 rv = fib_api_route_add_del (mp->is_add,
695 mp->is_multipath,
696 fib_index, &pfx, entry_flags, rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700697
698 if (mp->is_add && 0 == rv)
699 *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx);
700
Neale Ranns097fa662018-05-01 05:17:55 -0700701out:
702 vec_free (rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700703
704 return (rv);
Dave Barachb5e8a772016-12-06 12:04:42 -0500705}
706
707void
Neale Ranns097fa662018-05-01 05:17:55 -0700708vl_api_ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500709{
Neale Ranns097fa662018-05-01 05:17:55 -0700710 vl_api_ip_route_add_del_reply_t *rmp;
711 u32 stats_index = ~0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500712 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -0500713
Neale Ranns097fa662018-05-01 05:17:55 -0700714 rv = ip_route_add_del_t_handler (mp, &stats_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500715
Neale Ranns008dbe12018-09-07 09:32:36 -0700716 /* *INDENT-OFF* */
Neale Ranns097fa662018-05-01 05:17:55 -0700717 REPLY_MACRO2 (VL_API_IP_ROUTE_ADD_DEL_REPLY,
Neale Ranns008dbe12018-09-07 09:32:36 -0700718 ({
719 rmp->stats_index = htonl (stats_index);
720 }))
721 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500722}
723
Neale Ranns15002542017-09-10 04:39:11 -0700724void
Neale Ranns2297af02017-09-12 09:45:04 -0700725ip_table_create (fib_protocol_t fproto,
726 u32 table_id, u8 is_api, const u8 * name)
Neale Ranns15002542017-09-10 04:39:11 -0700727{
728 u32 fib_index, mfib_index;
729
730 /*
731 * ignore action on the default table - this is always present
732 * and cannot be added nor deleted from the API
733 */
734 if (0 != table_id)
735 {
736 /*
737 * The API holds only one lock on the table.
738 * i.e. it can be added many times via the API but needs to be
739 * deleted only once.
740 * The FIB index for unicast and multicast is not necessarily the
741 * same, since internal VPP systesm (like LISP and SR) create
742 * their own unicast tables.
743 */
744 fib_index = fib_table_find (fproto, table_id);
745 mfib_index = mfib_table_find (fproto, table_id);
746
747 if (~0 == fib_index)
748 {
Neale Ranns2297af02017-09-12 09:45:04 -0700749 fib_table_find_or_create_and_lock_w_name (fproto, table_id,
750 (is_api ?
751 FIB_SOURCE_API :
752 FIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700753 }
754 if (~0 == mfib_index)
755 {
Neale Ranns2297af02017-09-12 09:45:04 -0700756 mfib_table_find_or_create_and_lock_w_name (fproto, table_id,
757 (is_api ?
758 MFIB_SOURCE_API :
759 MFIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700760 }
761 }
762}
763
Neale Ranns097fa662018-05-01 05:17:55 -0700764static u32
Neale Ranns32e1c012016-11-22 17:07:28 +0000765mroute_add_del_handler (u8 is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700766 u8 is_multipath,
Neale Ranns32e1c012016-11-22 17:07:28 +0000767 u32 fib_index,
768 const mfib_prefix_t * prefix,
769 u32 entry_flags,
Neale Ranns097fa662018-05-01 05:17:55 -0700770 u32 rpf_id, fib_route_path_t * rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +0000771{
Neale Ranns097fa662018-05-01 05:17:55 -0700772 u32 mfib_entry_index = ~0;
Neale Ranns28c142e2018-09-07 09:37:07 -0700773
Neale Ranns097fa662018-05-01 05:17:55 -0700774 if (0 == vec_len (rpaths))
Neale Ranns32e1c012016-11-22 17:07:28 +0000775 {
Neale Ranns28c142e2018-09-07 09:37:07 -0700776 mfib_entry_index = mfib_table_entry_update (fib_index, prefix,
777 MFIB_SOURCE_API,
778 rpf_id, entry_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +0000779 }
780 else
781 {
Neale Ranns097fa662018-05-01 05:17:55 -0700782 if (is_add)
783 {
784 mfib_entry_index =
785 mfib_table_entry_paths_update (fib_index, prefix,
786 MFIB_SOURCE_API, rpaths);
787 }
788 else
789 {
790 mfib_table_entry_paths_remove (fib_index, prefix,
791 MFIB_SOURCE_API, rpaths);
792 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000793 }
794
Neale Ranns28c142e2018-09-07 09:37:07 -0700795 return (mfib_entry_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000796}
797
798static int
Neale Ranns28c142e2018-09-07 09:37:07 -0700799api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp,
800 u32 * stats_index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000801{
Neale Ranns097fa662018-05-01 05:17:55 -0700802 fib_route_path_t *rpath, *rpaths = NULL;
Neale Ranns28c142e2018-09-07 09:37:07 -0700803 fib_node_index_t mfib_entry_index;
Neale Ranns097fa662018-05-01 05:17:55 -0700804 mfib_prefix_t pfx;
Neale Ranns32e1c012016-11-22 17:07:28 +0000805 u32 fib_index;
806 int rv;
Neale Ranns097fa662018-05-01 05:17:55 -0700807 u16 ii;
Neale Ranns32e1c012016-11-22 17:07:28 +0000808
Neale Ranns097fa662018-05-01 05:17:55 -0700809 ip_mprefix_decode (&mp->route.prefix, &pfx);
Neale Ranns32e1c012016-11-22 17:07:28 +0000810
Neale Ranns097fa662018-05-01 05:17:55 -0700811 rv = mfib_api_table_id_decode (pfx.fp_proto,
812 ntohl (mp->route.table_id), &fib_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000813 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700814 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000815
Neale Ranns097fa662018-05-01 05:17:55 -0700816 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns32e1c012016-11-22 17:07:28 +0000817
Neale Ranns097fa662018-05-01 05:17:55 -0700818 for (ii = 0; ii < mp->route.n_paths; ii++)
Neale Ranns32e1c012016-11-22 17:07:28 +0000819 {
Neale Ranns097fa662018-05-01 05:17:55 -0700820 rpath = &rpaths[ii];
821
822 rv = mfib_api_path_decode (&mp->route.paths[ii], rpath);
823
824 if (0 != rv)
825 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000826 }
827
Neale Ranns28c142e2018-09-07 09:37:07 -0700828 mfib_entry_index = mroute_add_del_handler (mp->is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700829 mp->is_add,
Neale Ranns28c142e2018-09-07 09:37:07 -0700830 fib_index, &pfx,
Neale Ranns097fa662018-05-01 05:17:55 -0700831 ntohl (mp->route.entry_flags),
832 ntohl (mp->route.rpf_id),
833 rpaths);
Neale Ranns28c142e2018-09-07 09:37:07 -0700834
835 if (~0 != mfib_entry_index)
836 *stats_index = mfib_entry_get_stats_index (mfib_entry_index);
837
Neale Ranns097fa662018-05-01 05:17:55 -0700838out:
Neale Ranns28c142e2018-09-07 09:37:07 -0700839 return (rv);
Neale Ranns32e1c012016-11-22 17:07:28 +0000840}
841
842void
843vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp)
844{
845 vl_api_ip_mroute_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700846 u32 stats_index = ~0;
Neale Ranns32e1c012016-11-22 17:07:28 +0000847 int rv;
Neale Ranns32e1c012016-11-22 17:07:28 +0000848
Neale Ranns28c142e2018-09-07 09:37:07 -0700849 rv = api_mroute_add_del_t_handler (mp, &stats_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000850
Neale Ranns28c142e2018-09-07 09:37:07 -0700851 /* *INDENT-OFF* */
852 REPLY_MACRO2 (VL_API_IP_MROUTE_ADD_DEL_REPLY,
853 ({
854 rmp->stats_index = htonl (stats_index);
855 }));
856 /* *INDENT-ON* */
Neale Ranns32e1c012016-11-22 17:07:28 +0000857}
858
Dave Barachb5e8a772016-12-06 12:04:42 -0500859static void
860send_ip_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800861 vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6,
862 u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500863{
864 vl_api_ip_details_t *mp;
865
866 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400867 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500868 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
869
870 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger466f0d42017-02-09 12:17:50 -0600871 mp->is_ipv6 = is_ipv6;
Dave Barachb5e8a772016-12-06 12:04:42 -0500872 mp->context = context;
873
Florin Coras6c4dae22018-01-09 06:39:23 -0800874 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500875}
876
877static void
878send_ip_address_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800879 vl_api_registration_t * reg,
Neale Ranns097fa662018-05-01 05:17:55 -0700880 const fib_prefix_t * pfx,
881 u32 sw_if_index, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500882{
883 vl_api_ip_address_details_t *mp;
884
885 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400886 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500887 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
888
Neale Ranns097fa662018-05-01 05:17:55 -0700889 ip_prefix_encode (pfx, &mp->prefix);
Dave Barachb5e8a772016-12-06 12:04:42 -0500890 mp->context = context;
Jon Loeliger466f0d42017-02-09 12:17:50 -0600891 mp->sw_if_index = htonl (sw_if_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500892
Florin Coras6c4dae22018-01-09 06:39:23 -0800893 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500894}
895
896static void
897vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
898{
899 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800900 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500901 ip6_main_t *im6 = &ip6_main;
902 ip4_main_t *im4 = &ip4_main;
903 ip_lookup_main_t *lm6 = &im6->lookup_main;
904 ip_lookup_main_t *lm4 = &im4->lookup_main;
905 ip_interface_address_t *ia = 0;
906 u32 sw_if_index = ~0;
907 int rv __attribute__ ((unused)) = 0;
908
909 VALIDATE_SW_IF_INDEX (mp);
910
911 sw_if_index = ntohl (mp->sw_if_index);
912
Florin Coras6c4dae22018-01-09 06:39:23 -0800913 reg = vl_api_client_index_to_registration (mp->client_index);
914 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500915 return;
916
Dave Barachb5e8a772016-12-06 12:04:42 -0500917 if (mp->is_ipv6)
918 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500919 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700920 /* Do not send subnet details of the IP-interface for
921 * unnumbered interfaces. otherwise listening clients
922 * will be confused that the subnet is applied on more
923 * than one interface */
924 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500925 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700926 fib_prefix_t pfx = {
927 .fp_addr.ip6 = *(ip6_address_t *)ip_interface_address_get_address (lm6, ia),
928 .fp_len = ia->address_length,
929 .fp_proto = FIB_PROTOCOL_IP6,
930 };
931 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500932 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500933 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500934 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500935 else
936 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500937 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700938 foreach_ip_interface_address (lm4, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500939 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700940 fib_prefix_t pfx = {
941 .fp_addr.ip4 = *(ip4_address_t *)ip_interface_address_get_address (lm4, ia),
942 .fp_len = ia->address_length,
943 .fp_proto = FIB_PROTOCOL_IP4,
944 };
945
946 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500947 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500948 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500949 }
Neale Ranns008dbe12018-09-07 09:32:36 -0700950
Dave Barachb5e8a772016-12-06 12:04:42 -0500951 BAD_SW_IF_INDEX_LABEL;
952}
953
954static void
Neale Ranns9e2f9152018-05-18 02:27:10 -0700955send_ip_unnumbered_details (vpe_api_main_t * am,
956 vl_api_registration_t * reg,
957 u32 sw_if_index, u32 ip_sw_if_index, u32 context)
958{
959 vl_api_ip_unnumbered_details_t *mp;
960
961 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400962 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns9e2f9152018-05-18 02:27:10 -0700963 mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
964
965 mp->context = context;
966 mp->sw_if_index = htonl (sw_if_index);
967 mp->ip_sw_if_index = htonl (ip_sw_if_index);
968
969 vl_api_send_msg (reg, (u8 *) mp);
970}
971
972static void
973vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
974{
975 vnet_main_t *vnm = vnet_get_main ();
976 vnet_interface_main_t *im = &vnm->interface_main;
977 int rv __attribute__ ((unused)) = 0;
978 vpe_api_main_t *am = &vpe_api_main;
979 vl_api_registration_t *reg;
980 vnet_sw_interface_t *si;
981 u32 sw_if_index;
982
983 sw_if_index = ntohl (mp->sw_if_index);
984
985 reg = vl_api_client_index_to_registration (mp->client_index);
986 if (!reg)
987 return;
988
989 if (~0 != sw_if_index)
990 {
991 VALIDATE_SW_IF_INDEX (mp);
992
993 si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
994
Neale Rannsac3e72c2019-10-06 01:04:26 -0700995 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
Neale Ranns9e2f9152018-05-18 02:27:10 -0700996 {
997 send_ip_unnumbered_details (am, reg,
998 sw_if_index,
999 si->unnumbered_sw_if_index,
1000 mp->context);
1001 }
1002 }
1003 else
1004 {
1005 /* *INDENT-OFF* */
1006 pool_foreach (si, im->sw_interfaces,
1007 ({
1008 if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1009 {
1010 send_ip_unnumbered_details(am, reg,
1011 si->sw_if_index,
1012 si->unnumbered_sw_if_index,
1013 mp->context);
1014 }
1015 }));
1016 /* *INDENT-ON* */
1017 }
1018
1019 BAD_SW_IF_INDEX_LABEL;
1020}
1021
1022static void
Dave Barachb5e8a772016-12-06 12:04:42 -05001023vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
1024{
1025 vpe_api_main_t *am = &vpe_api_main;
1026 vnet_main_t *vnm = vnet_get_main ();
1027 vlib_main_t *vm = vlib_get_main ();
1028 vnet_interface_main_t *im = &vnm->interface_main;
Florin Coras6c4dae22018-01-09 06:39:23 -08001029 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -05001030 vnet_sw_interface_t *si, *sorted_sis;
1031 u32 sw_if_index = ~0;
1032
Florin Coras6c4dae22018-01-09 06:39:23 -08001033 reg = vl_api_client_index_to_registration (mp->client_index);
1034 if (!reg)
1035 return;
Dave Barachb5e8a772016-12-06 12:04:42 -05001036
1037 /* Gather interfaces. */
1038 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1039 _vec_len (sorted_sis) = 0;
1040 /* *INDENT-OFF* */
1041 pool_foreach (si, im->sw_interfaces,
1042 ({
1043 vec_add1 (sorted_sis, si[0]);
1044 }));
1045 /* *INDENT-ON* */
1046
1047 vec_foreach (si, sorted_sis)
1048 {
1049 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1050 {
1051 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
1052 {
1053 continue;
1054 }
1055 sw_if_index = si->sw_if_index;
Florin Coras6c4dae22018-01-09 06:39:23 -08001056 send_ip_details (am, reg, sw_if_index, mp->is_ipv6, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -05001057 }
1058 }
Matthew Smith6d5f6592019-09-18 13:51:46 -05001059
1060 vec_free (sorted_sis);
Dave Barachb5e8a772016-12-06 12:04:42 -05001061}
1062
1063static void
1064set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
1065{
1066 vl_api_set_ip_flow_hash_reply_t *rmp;
Neale Ranns227038a2017-04-21 01:07:59 -07001067 int rv;
1068 u32 table_id;
1069 flow_hash_config_t flow_hash_config = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -05001070
Neale Ranns227038a2017-04-21 01:07:59 -07001071 table_id = ntohl (mp->vrf_id);
1072
1073#define _(a,b) if (mp->a) flow_hash_config |= b;
1074 foreach_flow_hash_bit;
1075#undef _
1076
1077 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
Dave Barachb5e8a772016-12-06 12:04:42 -05001078
1079 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1080}
1081
1082static void
1083set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
1084{
1085 vl_api_set_ip_flow_hash_reply_t *rmp;
1086 int rv;
1087 u32 table_id;
1088 flow_hash_config_t flow_hash_config = 0;
1089
1090 table_id = ntohl (mp->vrf_id);
1091
1092#define _(a,b) if (mp->a) flow_hash_config |= b;
1093 foreach_flow_hash_bit;
1094#undef _
1095
1096 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
1097
1098 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1099}
1100
1101
1102static void
1103vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
1104{
1105 if (mp->is_ipv6 == 0)
1106 set_ip4_flow_hash (mp);
1107 else
1108 set_ip6_flow_hash (mp);
1109}
1110
1111static void
1112 vl_api_sw_interface_ip6nd_ra_config_t_handler
1113 (vl_api_sw_interface_ip6nd_ra_config_t * mp)
1114{
1115 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
1116 vlib_main_t *vm = vlib_get_main ();
1117 int rv = 0;
1118 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
1119 default_router;
1120
1121 is_no = mp->is_no == 1;
1122 suppress = mp->suppress == 1;
1123 managed = mp->managed == 1;
1124 other = mp->other == 1;
1125 ll_option = mp->ll_option == 1;
1126 send_unicast = mp->send_unicast == 1;
1127 cease = mp->cease == 1;
1128 default_router = mp->default_router == 1;
1129
1130 VALIDATE_SW_IF_INDEX (mp);
1131
1132 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
1133 suppress, managed, other,
1134 ll_option, send_unicast, cease,
1135 default_router, ntohl (mp->lifetime),
1136 ntohl (mp->initial_count),
1137 ntohl (mp->initial_interval),
1138 ntohl (mp->max_interval),
1139 ntohl (mp->min_interval), is_no);
1140
1141 BAD_SW_IF_INDEX_LABEL;
1142
1143 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
1144}
1145
1146static void
1147 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
1148 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp)
1149{
1150 vlib_main_t *vm = vlib_get_main ();
1151 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07001152 fib_prefix_t pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -05001153 int rv = 0;
1154 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
1155
1156 VALIDATE_SW_IF_INDEX (mp);
1157
Neale Ranns37029302018-08-10 05:30:06 -07001158 ip_prefix_decode (&mp->prefix, &pfx);
Dave Barachb5e8a772016-12-06 12:04:42 -05001159 is_no = mp->is_no == 1;
1160 use_default = mp->use_default == 1;
1161 no_advertise = mp->no_advertise == 1;
1162 off_link = mp->off_link == 1;
1163 no_autoconfig = mp->no_autoconfig == 1;
1164 no_onlink = mp->no_onlink == 1;
1165
1166 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
Neale Ranns37029302018-08-10 05:30:06 -07001167 &pfx.fp_addr.ip6,
1168 pfx.fp_len, use_default,
Dave Barachb5e8a772016-12-06 12:04:42 -05001169 ntohl (mp->val_lifetime),
1170 ntohl (mp->pref_lifetime), no_advertise,
1171 off_link, no_autoconfig, no_onlink, is_no);
1172
1173 BAD_SW_IF_INDEX_LABEL;
1174 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
1175}
1176
1177static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001178send_ip6nd_proxy_details (vl_api_registration_t * reg,
Neale Ranns3f844d02017-02-18 00:03:54 -08001179 u32 context,
1180 const ip46_address_t * addr, u32 sw_if_index)
1181{
1182 vl_api_ip6nd_proxy_details_t *mp;
1183
1184 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04001185 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns3f844d02017-02-18 00:03:54 -08001186 mp->_vl_msg_id = ntohs (VL_API_IP6ND_PROXY_DETAILS);
1187 mp->context = context;
1188 mp->sw_if_index = htonl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07001189
1190 ip6_address_encode (&addr->ip6, mp->ip);
Neale Ranns3f844d02017-02-18 00:03:54 -08001191
Florin Coras6c4dae22018-01-09 06:39:23 -08001192 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns3f844d02017-02-18 00:03:54 -08001193}
1194
Neale Ranns3f844d02017-02-18 00:03:54 -08001195typedef struct api_ip6nd_proxy_fib_table_walk_ctx_t_
1196{
1197 u32 *indices;
1198} api_ip6nd_proxy_fib_table_walk_ctx_t;
1199
Neale Ranns89541992017-04-06 04:41:02 -07001200static fib_table_walk_rc_t
Neale Ranns3f844d02017-02-18 00:03:54 -08001201api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg)
1202{
1203 api_ip6nd_proxy_fib_table_walk_ctx_t *ctx = arg;
1204
1205 if (fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND_PROXY))
1206 {
1207 vec_add1 (ctx->indices, fei);
1208 }
1209
Neale Ranns89541992017-04-06 04:41:02 -07001210 return (FIB_TABLE_WALK_CONTINUE);
Neale Ranns3f844d02017-02-18 00:03:54 -08001211}
1212
1213static void
1214vl_api_ip6nd_proxy_dump_t_handler (vl_api_ip6nd_proxy_dump_t * mp)
1215{
1216 ip6_main_t *im6 = &ip6_main;
1217 fib_table_t *fib_table;
1218 api_ip6nd_proxy_fib_table_walk_ctx_t ctx = {
1219 .indices = NULL,
1220 };
1221 fib_node_index_t *feip;
Neale Rannsc5d43172018-07-30 08:04:40 -07001222 const fib_prefix_t *pfx;
Florin Coras6c4dae22018-01-09 06:39:23 -08001223 vl_api_registration_t *reg;
Neale Ranns3f844d02017-02-18 00:03:54 -08001224
Florin Coras6c4dae22018-01-09 06:39:23 -08001225 reg = vl_api_client_index_to_registration (mp->client_index);
1226 if (!reg)
1227 return;
Neale Ranns3f844d02017-02-18 00:03:54 -08001228
1229 /* *INDENT-OFF* */
1230 pool_foreach (fib_table, im6->fibs,
1231 ({
1232 fib_table_walk(fib_table->ft_index,
1233 FIB_PROTOCOL_IP6,
1234 api_ip6nd_proxy_fib_table_walk,
1235 &ctx);
1236 }));
1237 /* *INDENT-ON* */
1238
1239 vec_sort_with_function (ctx.indices, fib_entry_cmp_for_sort);
1240
1241 vec_foreach (feip, ctx.indices)
1242 {
Neale Rannsc5d43172018-07-30 08:04:40 -07001243 pfx = fib_entry_get_prefix (*feip);
Neale Ranns3f844d02017-02-18 00:03:54 -08001244
Florin Coras6c4dae22018-01-09 06:39:23 -08001245 send_ip6nd_proxy_details (reg,
Neale Ranns3f844d02017-02-18 00:03:54 -08001246 mp->context,
Neale Rannsc5d43172018-07-30 08:04:40 -07001247 &pfx->fp_addr,
Neale Ranns3f844d02017-02-18 00:03:54 -08001248 fib_entry_get_resolving_interface (*feip));
1249 }
1250
1251 vec_free (ctx.indices);
1252}
1253
1254static void
1255vl_api_ip6nd_proxy_add_del_t_handler (vl_api_ip6nd_proxy_add_del_t * mp)
1256{
1257 vl_api_ip6nd_proxy_add_del_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07001258 ip6_address_t ip6;
Neale Ranns3f844d02017-02-18 00:03:54 -08001259 int rv = 0;
1260
1261 VALIDATE_SW_IF_INDEX (mp);
1262
Neale Ranns37029302018-08-10 05:30:06 -07001263 ip6_address_decode (mp->ip, &ip6);
1264 rv = ip6_neighbor_proxy_add_del (ntohl (mp->sw_if_index), &ip6, mp->is_del);
Neale Ranns3f844d02017-02-18 00:03:54 -08001265
1266 BAD_SW_IF_INDEX_LABEL;
1267 REPLY_MACRO (VL_API_IP6ND_PROXY_ADD_DEL_REPLY);
1268}
1269
1270static void
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001271 vl_api_ip6nd_send_router_solicitation_t_handler
1272 (vl_api_ip6nd_send_router_solicitation_t * mp)
1273{
1274 vl_api_ip6nd_send_router_solicitation_reply_t *rmp;
1275 icmp6_send_router_solicitation_params_t params;
1276 vlib_main_t *vm = vlib_get_main ();
1277 int rv = 0;
1278
1279 VALIDATE_SW_IF_INDEX (mp);
1280
1281 BAD_SW_IF_INDEX_LABEL;
1282 REPLY_MACRO (VL_API_IP6ND_SEND_ROUTER_SOLICITATION_REPLY);
1283
1284 if (rv != 0)
1285 return;
1286
1287 params.irt = ntohl (mp->irt);
1288 params.mrt = ntohl (mp->mrt);
1289 params.mrc = ntohl (mp->mrc);
1290 params.mrd = ntohl (mp->mrd);
1291
1292 icmp6_send_router_solicitation (vm, ntohl (mp->sw_if_index), mp->stop,
1293 &params);
1294}
1295
1296static void
Dave Barachb5e8a772016-12-06 12:04:42 -05001297 vl_api_sw_interface_ip6_enable_disable_t_handler
1298 (vl_api_sw_interface_ip6_enable_disable_t * mp)
1299{
1300 vlib_main_t *vm = vlib_get_main ();
1301 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
1302 vnet_main_t *vnm = vnet_get_main ();
1303 int rv = 0;
1304 clib_error_t *error;
1305
1306 vnm->api_errno = 0;
1307
1308 VALIDATE_SW_IF_INDEX (mp);
1309
1310 error =
1311 (mp->enable == 1) ? enable_ip6_interface (vm,
1312 ntohl (mp->sw_if_index)) :
1313 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
1314
1315 if (error)
1316 {
1317 clib_error_report (error);
1318 rv = VNET_API_ERROR_UNSPECIFIED;
1319 }
1320 else
1321 {
1322 rv = vnm->api_errno;
1323 }
1324
1325 BAD_SW_IF_INDEX_LABEL;
1326
1327 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
1328}
1329
Neale Ranns32e1c012016-11-22 17:07:28 +00001330void
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001331vl_mfib_signal_send_one (vl_api_registration_t * reg,
Neale Ranns32e1c012016-11-22 17:07:28 +00001332 u32 context, const mfib_signal_t * mfs)
1333{
1334 vl_api_mfib_signal_details_t *mp;
Neale Ranns9e829a82018-12-17 05:50:32 -08001335 const mfib_prefix_t *prefix;
Neale Ranns32e1c012016-11-22 17:07:28 +00001336 mfib_table_t *mfib;
1337 mfib_itf_t *mfi;
1338
1339 mp = vl_msg_api_alloc (sizeof (*mp));
1340
Dave Barachb7b92992018-10-17 10:38:51 -04001341 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns32e1c012016-11-22 17:07:28 +00001342 mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS);
1343 mp->context = context;
1344
1345 mfi = mfib_itf_get (mfs->mfs_itf);
Neale Ranns9e829a82018-12-17 05:50:32 -08001346 prefix = mfib_entry_get_prefix (mfs->mfs_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +00001347 mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry),
Neale Ranns9e829a82018-12-17 05:50:32 -08001348 prefix->fp_proto);
Neale Ranns32e1c012016-11-22 17:07:28 +00001349 mp->table_id = ntohl (mfib->mft_table_id);
1350 mp->sw_if_index = ntohl (mfi->mfi_sw_if_index);
1351
Neale Ranns097fa662018-05-01 05:17:55 -07001352 ip_mprefix_encode (prefix, &mp->prefix);
Neale Ranns32e1c012016-11-22 17:07:28 +00001353
1354 if (0 != mfs->mfs_buffer_len)
1355 {
1356 mp->ip_packet_len = ntohs (mfs->mfs_buffer_len);
1357
1358 memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len);
1359 }
1360 else
1361 {
1362 mp->ip_packet_len = 0;
1363 }
1364
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001365 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00001366}
1367
1368static void
1369vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
1370{
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001371 vl_api_registration_t *reg;
Neale Ranns32e1c012016-11-22 17:07:28 +00001372
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001373 reg = vl_api_client_index_to_registration (mp->client_index);
1374 if (!reg)
1375 return;
Neale Ranns32e1c012016-11-22 17:07:28 +00001376
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001377 while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
Neale Ranns32e1c012016-11-22 17:07:28 +00001378 ;
1379}
Dave Barachb5e8a772016-12-06 12:04:42 -05001380
Florin Coras595992c2017-11-06 17:17:08 -08001381static void
1382 vl_api_ip_container_proxy_add_del_t_handler
1383 (vl_api_ip_container_proxy_add_del_t * mp)
1384{
1385 vl_api_ip_container_proxy_add_del_reply_t *rmp;
1386 vnet_ip_container_proxy_args_t args;
1387 int rv = 0;
1388 clib_error_t *error;
1389
Dave Barachb7b92992018-10-17 10:38:51 -04001390 clib_memset (&args, 0, sizeof (args));
Neale Ranns37029302018-08-10 05:30:06 -07001391
1392 ip_prefix_decode (&mp->pfx, &args.prefix);
1393
Florin Coras595992c2017-11-06 17:17:08 -08001394 args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1395 args.is_add = mp->is_add;
1396 if ((error = vnet_ip_container_proxy_add_del (&args)))
1397 {
1398 rv = clib_error_get_code (error);
1399 clib_error_report (error);
1400 }
1401
1402 REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
1403}
1404
Matus Fabian75b9f452018-10-02 23:27:21 -07001405typedef struct ip_container_proxy_walk_ctx_t_
1406{
1407 vl_api_registration_t *reg;
1408 u32 context;
1409} ip_container_proxy_walk_ctx_t;
1410
1411static int
1412ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
1413 void *args)
1414{
1415 vl_api_ip_container_proxy_details_t *mp;
1416 ip_container_proxy_walk_ctx_t *ctx = args;
1417
1418 mp = vl_msg_api_alloc (sizeof (*mp));
1419 if (!mp)
1420 return 1;
1421
Dave Barachb7b92992018-10-17 10:38:51 -04001422 clib_memset (mp, 0, sizeof (*mp));
Matus Fabian75b9f452018-10-02 23:27:21 -07001423 mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
1424 mp->context = ctx->context;
1425
1426 mp->sw_if_index = ntohl (sw_if_index);
1427 ip_prefix_encode (pfx, &mp->prefix);
1428
1429 vl_api_send_msg (ctx->reg, (u8 *) mp);
1430
1431 return 1;
1432}
1433
1434static void
1435vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t *
1436 mp)
1437{
1438 vl_api_registration_t *reg;
1439
1440 reg = vl_api_client_index_to_registration (mp->client_index);
1441 if (!reg)
1442 return;
1443
1444 ip_container_proxy_walk_ctx_t ctx = {
1445 .context = mp->context,
1446 .reg = reg,
1447 };
1448
1449 ip_container_proxy_walk (ip_container_proxy_send_details, &ctx);
1450}
1451
Neale Rannsb8d44812017-11-10 06:53:54 -08001452static void
1453vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1454{
1455 int rv = 0;
1456 vl_api_ioam_enable_reply_t *rmp;
1457 clib_error_t *error;
1458
1459 /* Ignoring the profile id as currently a single profile
1460 * is supported */
1461 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1462 mp->seqno, mp->analyse);
1463 if (error)
1464 {
1465 clib_error_report (error);
1466 rv = clib_error_get_code (error);
1467 }
1468
1469 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1470}
1471
1472static void
1473vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1474{
1475 int rv = 0;
1476 vl_api_ioam_disable_reply_t *rmp;
1477 clib_error_t *error;
1478
1479 error = clear_ioam_rewrite_fn ();
1480 if (error)
1481 {
1482 clib_error_report (error);
1483 rv = clib_error_get_code (error);
1484 }
1485
1486 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1487}
1488
1489static void
1490 vl_api_ip_source_and_port_range_check_add_del_t_handler
1491 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1492{
1493 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1494 int rv = 0;
1495
Neale Rannsb8d44812017-11-10 06:53:54 -08001496 u8 is_add = mp->is_add;
Neale Ranns37029302018-08-10 05:30:06 -07001497 fib_prefix_t pfx;
Neale Rannsb8d44812017-11-10 06:53:54 -08001498 u16 *low_ports = 0;
1499 u16 *high_ports = 0;
1500 u32 vrf_id;
1501 u16 tmp_low, tmp_high;
1502 u8 num_ranges;
1503 int i;
1504
Neale Ranns37029302018-08-10 05:30:06 -07001505 ip_prefix_decode (&mp->prefix, &pfx);
1506
Neale Rannsb8d44812017-11-10 06:53:54 -08001507 // Validate port range
1508 num_ranges = mp->number_of_ranges;
1509 if (num_ranges > 32)
1510 { // This is size of array in VPE.API
1511 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1512 goto reply;
1513 }
1514
1515 vec_reset_length (low_ports);
1516 vec_reset_length (high_ports);
1517
1518 for (i = 0; i < num_ranges; i++)
1519 {
1520 tmp_low = mp->low_ports[i];
1521 tmp_high = mp->high_ports[i];
1522 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1523 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1524 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1525 {
1526 rv = VNET_API_ERROR_INVALID_VALUE;
1527 goto reply;
1528 }
1529 vec_add1 (low_ports, tmp_low);
1530 vec_add1 (high_ports, tmp_high + 1);
1531 }
1532
Neale Rannsb8d44812017-11-10 06:53:54 -08001533 vrf_id = ntohl (mp->vrf_id);
1534
1535 if (vrf_id < 1)
1536 {
1537 rv = VNET_API_ERROR_INVALID_VALUE;
1538 goto reply;
1539 }
1540
1541
Neale Ranns37029302018-08-10 05:30:06 -07001542 if (FIB_PROTOCOL_IP6 == pfx.fp_proto)
Neale Rannsb8d44812017-11-10 06:53:54 -08001543 {
Neale Ranns37029302018-08-10 05:30:06 -07001544 rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6,
1545 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001546 vrf_id,
1547 low_ports,
1548 high_ports, is_add);
1549 }
1550 else
1551 {
Neale Ranns37029302018-08-10 05:30:06 -07001552 rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4,
1553 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001554 vrf_id,
1555 low_ports,
1556 high_ports, is_add);
1557 }
1558
1559reply:
1560 vec_free (low_ports);
1561 vec_free (high_ports);
1562 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1563}
1564
1565static void
1566 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1567 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
1568{
1569 vlib_main_t *vm = vlib_get_main ();
1570 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
1571 ip4_main_t *im = &ip4_main;
1572 int rv;
1573 u32 sw_if_index;
1574 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1575 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1576 uword *p = 0;
1577 int i;
1578
1579 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
1580 ntohl (mp->tcp_out_vrf_id);
1581 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
1582 ntohl (mp->udp_out_vrf_id);
1583 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
1584 ntohl (mp->tcp_in_vrf_id);
1585 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
1586 ntohl (mp->udp_in_vrf_id);
1587
1588
1589 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
1590 {
1591 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
1592 {
1593 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
1594
1595 if (p == 0)
1596 {
1597 rv = VNET_API_ERROR_INVALID_VALUE;
1598 goto reply;
1599 }
1600
1601 fib_index[i] = p[0];
1602 }
1603 else
1604 fib_index[i] = ~0;
1605 }
1606 sw_if_index = ntohl (mp->sw_if_index);
1607
1608 VALIDATE_SW_IF_INDEX (mp);
1609
1610 rv =
1611 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
1612 mp->is_add);
1613
1614 BAD_SW_IF_INDEX_LABEL;
1615reply:
1616
1617 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
1618}
1619
Chore3460b012018-11-28 10:53:11 +03301620typedef union
1621{
1622 u32 fib_index;
1623} ip4_source_check_config_t;
1624
1625static void
1626 vl_api_ip_source_check_interface_add_del_t_handler
1627 (vl_api_ip_source_check_interface_add_del_t * mp)
1628{
1629 vl_api_ip_source_check_interface_add_del_reply_t *rmp;
1630 int rv;
1631 u32 sw_if_index = ntohl (mp->sw_if_index);
1632 u8 is_add = mp->is_add;
1633 char *feature_name =
1634 mp->loose ? "ip4-source-check-via-any" : "ip4-source-check-via-rx";
1635
1636 ip4_source_check_config_t config;
1637
1638 VALIDATE_SW_IF_INDEX (mp);
1639
1640 config.fib_index =
1641 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index);
1642 rv =
1643 vnet_feature_enable_disable ("ip4-unicast", feature_name, sw_if_index,
1644 is_add, &config, sizeof (config));
1645 BAD_SW_IF_INDEX_LABEL;
1646
1647 REPLY_MACRO (VL_API_IP_SOURCE_CHECK_INTERFACE_ADD_DEL_REPLY);
1648}
1649
Neale Rannsb8d44812017-11-10 06:53:54 -08001650#define IP4_ARP_EVENT 3
1651#define IP6_ND_EVENT 4
1652
Neale Rannsb8d44812017-11-10 06:53:54 -08001653static vlib_node_registration_t ip_resolver_process_node;
1654
Neale Ranns37029302018-08-10 05:30:06 -07001655static int
1656arp_change_delete_callback (u32 pool_index,
1657 const mac_address_t * mac,
1658 u32 sw_if_index, const ip4_address_t * address)
1659{
1660 vpe_api_main_t *am = &vpe_api_main;
1661
1662 if (pool_is_free_index (am->arp_events, pool_index))
1663 return 1;
1664
1665 pool_put_index (am->arp_events, pool_index);
1666 return 0;
1667}
1668
Neale Rannsb8d44812017-11-10 06:53:54 -08001669static void
1670handle_ip4_arp_event (u32 pool_index)
1671{
1672 vpe_api_main_t *vam = &vpe_api_main;
1673 vnet_main_t *vnm = vam->vnet_main;
1674 vlib_main_t *vm = vam->vlib_main;
1675 vl_api_ip4_arp_event_t *event;
1676 vl_api_ip4_arp_event_t *mp;
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001677 vl_api_registration_t *reg;
Neale Rannsb8d44812017-11-10 06:53:54 -08001678
1679 /* Client can cancel, die, etc. */
1680 if (pool_is_free_index (vam->arp_events, pool_index))
1681 return;
1682
1683 event = pool_elt_at_index (vam->arp_events, pool_index);
1684
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001685 reg = vl_api_client_index_to_registration (event->client_index);
1686 if (!reg)
Neale Rannsb8d44812017-11-10 06:53:54 -08001687 {
1688 (void) vnet_add_del_ip4_arp_change_event
1689 (vnm, arp_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07001690 event->pid, event->ip,
Neale Rannsb8d44812017-11-10 06:53:54 -08001691 ip_resolver_process_node.index, IP4_ARP_EVENT,
1692 ~0 /* pool index, notused */ , 0 /* is_add */ );
1693 return;
1694 }
1695
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001696 if (vl_api_can_send_msg (reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08001697 {
1698 mp = vl_msg_api_alloc (sizeof (*mp));
1699 clib_memcpy (mp, event, sizeof (*mp));
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001700 vl_api_send_msg (reg, (u8 *) mp);
Neale Rannsb8d44812017-11-10 06:53:54 -08001701 }
1702 else
1703 {
1704 static f64 last_time;
1705 /*
1706 * Throttle syslog msgs.
1707 * It's pretty tempting to just revoke the registration...
1708 */
1709 if (vlib_time_now (vm) > last_time + 10.0)
1710 {
1711 clib_warning ("arp event for %U to pid %d: queue stuffed!",
Neale Ranns37029302018-08-10 05:30:06 -07001712 format_ip4_address, event->ip, event->pid);
Neale Rannsb8d44812017-11-10 06:53:54 -08001713 last_time = vlib_time_now (vm);
1714 }
1715 }
1716}
1717
Neale Ranns37029302018-08-10 05:30:06 -07001718static int
1719nd_change_delete_callback (u32 pool_index,
1720 const mac_address_t * mac,
1721 u32 sw_if_index, const ip6_address_t * addr)
1722{
1723 vpe_api_main_t *am = &vpe_api_main;
1724
1725 if (pool_is_free_index (am->nd_events, pool_index))
1726 return 1;
1727
1728 pool_put_index (am->nd_events, pool_index);
1729 return 0;
1730}
1731
Neale Rannsf12dad62018-06-04 18:41:24 -07001732static void
Neale Rannsb8d44812017-11-10 06:53:54 -08001733handle_ip6_nd_event (u32 pool_index)
1734{
1735 vpe_api_main_t *vam = &vpe_api_main;
1736 vnet_main_t *vnm = vam->vnet_main;
1737 vlib_main_t *vm = vam->vlib_main;
1738 vl_api_ip6_nd_event_t *event;
1739 vl_api_ip6_nd_event_t *mp;
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001740 vl_api_registration_t *reg;
Neale Rannsb8d44812017-11-10 06:53:54 -08001741
1742 /* Client can cancel, die, etc. */
1743 if (pool_is_free_index (vam->nd_events, pool_index))
1744 return;
1745
1746 event = pool_elt_at_index (vam->nd_events, pool_index);
1747
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001748 reg = vl_api_client_index_to_registration (event->client_index);
1749 if (!reg)
Neale Rannsb8d44812017-11-10 06:53:54 -08001750 {
1751 (void) vnet_add_del_ip6_nd_change_event
1752 (vnm, nd_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07001753 event->pid, event->ip,
Neale Rannsb8d44812017-11-10 06:53:54 -08001754 ip_resolver_process_node.index, IP6_ND_EVENT,
1755 ~0 /* pool index, notused */ , 0 /* is_add */ );
1756 return;
1757 }
1758
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001759 if (vl_api_can_send_msg (reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08001760 {
1761 mp = vl_msg_api_alloc (sizeof (*mp));
1762 clib_memcpy (mp, event, sizeof (*mp));
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001763 vl_api_send_msg (reg, (u8 *) mp);
Neale Rannsb8d44812017-11-10 06:53:54 -08001764 }
1765 else
1766 {
1767 static f64 last_time;
1768 /*
1769 * Throttle syslog msgs.
1770 * It's pretty tempting to just revoke the registration...
1771 */
1772 if (vlib_time_now (vm) > last_time + 10.0)
1773 {
1774 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
Neale Ranns37029302018-08-10 05:30:06 -07001775 format_ip6_address, event->ip, event->pid);
Neale Rannsb8d44812017-11-10 06:53:54 -08001776 last_time = vlib_time_now (vm);
1777 }
1778 }
1779}
1780
1781static uword
1782resolver_process (vlib_main_t * vm,
1783 vlib_node_runtime_t * rt, vlib_frame_t * f)
1784{
1785 volatile f64 timeout = 100.0;
1786 volatile uword *event_data = 0;
1787
1788 while (1)
1789 {
1790 vlib_process_wait_for_event_or_clock (vm, timeout);
1791
1792 uword event_type =
1793 vlib_process_get_events (vm, (uword **) & event_data);
1794
1795 int i;
1796 switch (event_type)
1797 {
1798 case IP4_ARP_EVENT:
1799 for (i = 0; i < vec_len (event_data); i++)
1800 handle_ip4_arp_event (event_data[i]);
1801 break;
1802
1803 case IP6_ND_EVENT:
1804 for (i = 0; i < vec_len (event_data); i++)
1805 handle_ip6_nd_event (event_data[i]);
1806 break;
1807
1808 case ~0: /* timeout */
1809 break;
1810 }
1811
1812 vec_reset_length (event_data);
1813 }
1814 return 0; /* or not */
1815}
1816
1817/* *INDENT-OFF* */
1818VLIB_REGISTER_NODE (ip_resolver_process_node,static) = {
1819 .function = resolver_process,
1820 .type = VLIB_NODE_TYPE_PROCESS,
1821 .name = "ip-route-resolver-process",
1822};
1823/* *INDENT-ON* */
1824
1825static int
Neale Ranns37029302018-08-10 05:30:06 -07001826nd_change_data_callback (u32 pool_index, const mac_address_t * new_mac,
1827 u32 sw_if_index, const ip6_address_t * address)
Neale Rannsb8d44812017-11-10 06:53:54 -08001828{
1829 vpe_api_main_t *am = &vpe_api_main;
1830 vl_api_ip6_nd_event_t *event;
1831
1832 if (pool_is_free_index (am->nd_events, pool_index))
1833 return 1;
1834
1835 event = pool_elt_at_index (am->nd_events, pool_index);
Neale Ranns37029302018-08-10 05:30:06 -07001836 if (ethernet_mac_address_equal (event->mac, new_mac->bytes) &&
Neale Rannsb8d44812017-11-10 06:53:54 -08001837 sw_if_index == ntohl (event->sw_if_index))
1838 {
1839 return 1;
1840 }
1841
Neale Ranns37029302018-08-10 05:30:06 -07001842 mac_address_encode (new_mac, event->mac);
Neale Rannsb8d44812017-11-10 06:53:54 -08001843 event->sw_if_index = htonl (sw_if_index);
1844 return 0;
1845}
1846
Neale Rannsb8d44812017-11-10 06:53:54 -08001847static vlib_node_registration_t wc_arp_process_node;
1848
1849enum
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001850{ WC_ARP_REPORT, WC_ND_REPORT, RA_REPORT, REPORT_MAX };
Neale Rannsb8d44812017-11-10 06:53:54 -08001851
1852static uword
1853wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1854{
Jim Thompsonf324dec2019-04-08 03:22:21 -05001855 /* These cross the longjmp boundary (vlib_process_wait_for_event)
Neale Rannsb8d44812017-11-10 06:53:54 -08001856 * and need to be volatile - to prevent them from being optimized into
1857 * a register - which could change during suspension */
1858
1859 volatile wc_arp_report_t arp_prev = { 0 };
1860 volatile wc_nd_report_t nd_prev = { 0 };
1861 volatile f64 last_arp = vlib_time_now (vm);
1862 volatile f64 last_nd = vlib_time_now (vm);
1863
1864 while (1)
1865 {
1866 vlib_process_wait_for_event (vm);
1867 uword event_type = WC_ARP_REPORT;
1868 void *event_data = vlib_process_get_event_data (vm, &event_type);
1869
1870 f64 now = vlib_time_now (vm);
1871 int i;
1872 if (event_type == WC_ARP_REPORT)
1873 {
1874 wc_arp_report_t *arp_events = event_data;
1875 for (i = 0; i < vec_len (arp_events); i++)
1876 {
Neale Ranns37029302018-08-10 05:30:06 -07001877 /* discard dup event - cast away volatile */
1878 if (arp_prev.ip.as_u32 == arp_events[i].ip.as_u32 &&
1879 mac_address_equal ((const mac_address_t *) &arp_prev.mac,
1880 &arp_events[i].mac) &&
Neale Rannsb8d44812017-11-10 06:53:54 -08001881 arp_prev.sw_if_index == arp_events[i].sw_if_index &&
1882 (now - last_arp) < 10.0)
1883 {
1884 continue;
1885 }
1886 arp_prev = arp_events[i];
1887 last_arp = now;
1888 vpe_client_registration_t *reg;
1889 /* *INDENT-OFF* */
1890 pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations,
1891 ({
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001892 vl_api_registration_t *vl_reg;
1893 vl_reg = vl_api_client_index_to_registration (reg->client_index);
Chris Luke30684ac2018-03-29 12:56:58 -07001894 ASSERT (vl_reg != NULL);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001895 if (reg && vl_api_can_send_msg (vl_reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08001896 {
1897 vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event);
Dave Barachb7b92992018-10-17 10:38:51 -04001898 clib_memset (event, 0, sizeof *event);
Neale Rannsb8d44812017-11-10 06:53:54 -08001899 event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
1900 event->client_index = reg->client_index;
1901 event->pid = reg->client_pid;
1902 event->mac_ip = 1;
Neale Ranns37029302018-08-10 05:30:06 -07001903 ip4_address_encode(&arp_events[i].ip, event->ip);
Neale Rannsb8d44812017-11-10 06:53:54 -08001904 event->sw_if_index = htonl(arp_events[i].sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07001905 mac_address_encode(&arp_events[i].mac, event->mac);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001906 vl_api_send_msg (vl_reg, (u8 *) event);
Neale Rannsb8d44812017-11-10 06:53:54 -08001907 }
1908 }));
1909 /* *INDENT-ON* */
1910 }
1911 }
1912 else if (event_type == WC_ND_REPORT)
1913 {
1914 wc_nd_report_t *nd_events = event_data;
1915 for (i = 0; i < vec_len (nd_events); i++)
1916 {
Neale Ranns37029302018-08-10 05:30:06 -07001917 /* discard dup event - cast away volatile */
1918 if (ip6_address_is_equal ((const ip6_address_t *) &nd_prev.ip6,
1919 &nd_events[i].ip6)
1920 && mac_address_equal ((const mac_address_t *) &nd_prev.mac,
1921 &nd_events[i].mac)
Neale Rannsb8d44812017-11-10 06:53:54 -08001922 && nd_prev.sw_if_index == nd_events[i].sw_if_index
1923 && (now - last_nd) < 10.0)
1924 {
1925 continue;
1926 }
1927 nd_prev = nd_events[i];
1928 last_nd = now;
1929 vpe_client_registration_t *reg;
1930 /* *INDENT-OFF* */
1931 pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations,
1932 ({
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001933 vl_api_registration_t *vl_reg;
1934 vl_reg = vl_api_client_index_to_registration (reg->client_index);
1935 if (vl_reg && vl_api_can_send_msg (vl_reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08001936 {
1937 vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event);
Dave Barachb7b92992018-10-17 10:38:51 -04001938 clib_memset (event, 0, sizeof *event);
Neale Rannsb8d44812017-11-10 06:53:54 -08001939 event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT);
1940 event->client_index = reg->client_index;
1941 event->pid = reg->client_pid;
1942 event->mac_ip = 1;
Neale Ranns37029302018-08-10 05:30:06 -07001943 ip6_address_encode(&nd_events[i].ip6, event->ip);
Neale Rannsb8d44812017-11-10 06:53:54 -08001944 event->sw_if_index = htonl(nd_events[i].sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07001945 mac_address_encode(&nd_events[i].mac, event->mac);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001946 vl_api_send_msg (vl_reg, (u8 *) event);
Neale Rannsb8d44812017-11-10 06:53:54 -08001947 }
1948 }));
1949 /* *INDENT-ON* */
1950 }
1951 }
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001952 else if (event_type == RA_REPORT)
1953 {
1954 ra_report_t *ra_events = event_data;
1955 for (i = 0; i < vec_len (ra_events); i++)
1956 {
Juraj Sloboda52574522018-05-03 10:03:50 +02001957 ip6_neighbor_public_main_t *npm = &ip6_neighbor_public_main;
1958 call_ip6_neighbor_callbacks (&ra_events[i],
1959 npm->ra_report_functions);
1960
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001961 vpe_client_registration_t *reg;
1962 /* *INDENT-OFF* */
1963 pool_foreach(reg, vpe_api_main.ip6_ra_events_registrations,
1964 ({
1965 vl_api_registration_t *vl_reg;
1966 vl_reg =
1967 vl_api_client_index_to_registration (reg->client_index);
1968 if (vl_reg && vl_api_can_send_msg (vl_reg))
1969 {
1970 u32 event_size =
1971 sizeof (vl_api_ip6_ra_event_t) +
1972 vec_len (ra_events[i].prefixes) *
1973 sizeof (vl_api_ip6_ra_prefix_info_t);
1974 vl_api_ip6_ra_event_t *event =
1975 vl_msg_api_alloc (event_size);
Dave Barachb7b92992018-10-17 10:38:51 -04001976 clib_memset (event, 0, event_size);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001977 event->_vl_msg_id = htons (VL_API_IP6_RA_EVENT);
1978 event->client_index = reg->client_index;
1979 event->pid = reg->client_pid;
1980
1981 event->sw_if_index = clib_host_to_net_u32 (ra_events[i].sw_if_index);
1982
Neale Ranns37029302018-08-10 05:30:06 -07001983 ip6_address_encode (&ra_events[i].router_address,
1984 event->router_addr);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001985
1986 event->current_hop_limit = ra_events[i].current_hop_limit;
1987 event->flags = ra_events[i].flags;
1988 event->router_lifetime_in_sec =
1989 clib_host_to_net_u16 (ra_events
1990 [i].router_lifetime_in_sec);
1991 event->neighbor_reachable_time_in_msec =
1992 clib_host_to_net_u32 (ra_events
1993 [i].neighbor_reachable_time_in_msec);
1994 event->time_in_msec_between_retransmitted_neighbor_solicitations
1995 =
1996 clib_host_to_net_u32 (ra_events
1997 [i].time_in_msec_between_retransmitted_neighbor_solicitations);
1998
1999 event->n_prefixes =
2000 clib_host_to_net_u32 (vec_len (ra_events[i].prefixes));
2001 vl_api_ip6_ra_prefix_info_t *prefix =
2002 (typeof (prefix)) event->prefixes;
2003 u32 j;
2004 for (j = 0; j < vec_len (ra_events[i].prefixes); j++)
2005 {
2006 ra_report_prefix_info_t *info =
2007 &ra_events[i].prefixes[j];
Neale Ranns37029302018-08-10 05:30:06 -07002008 ip_prefix_encode(&info->prefix, &prefix->prefix);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002009 prefix->flags = info->flags;
2010 prefix->valid_time =
2011 clib_host_to_net_u32 (info->valid_time);
2012 prefix->preferred_time =
2013 clib_host_to_net_u32 (info->preferred_time);
2014 prefix++;
2015 }
2016
2017 vl_api_send_msg (vl_reg, (u8 *) event);
2018 }
2019 }));
Juraj Slobodad7f58cc2018-07-27 11:23:14 +02002020 /* *INDENT-ON* */
2021 vec_free (ra_events[i].prefixes);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002022 }
2023 }
Neale Rannsb8d44812017-11-10 06:53:54 -08002024 vlib_process_put_event_data (vm, event_data);
2025 }
2026
2027 return 0;
2028}
2029
2030/* *INDENT-OFF* */
2031VLIB_REGISTER_NODE (wc_arp_process_node,static) = {
2032 .function = wc_arp_process,
2033 .type = VLIB_NODE_TYPE_PROCESS,
2034 .name = "wildcard-ip4-arp-publisher-process",
2035};
2036/* *INDENT-ON* */
2037
2038static int
Neale Ranns37029302018-08-10 05:30:06 -07002039arp_change_data_callback (u32 pool_index,
2040 const mac_address_t * mac,
2041 u32 sw_if_index, const ip4_address_t * address)
Neale Rannsb8d44812017-11-10 06:53:54 -08002042{
2043 vpe_api_main_t *am = &vpe_api_main;
2044 vl_api_ip4_arp_event_t *event;
2045
2046 if (pool_is_free_index (am->arp_events, pool_index))
2047 return 1;
2048
2049 event = pool_elt_at_index (am->arp_events, pool_index);
Neale Ranns37029302018-08-10 05:30:06 -07002050 if (ethernet_mac_address_equal (event->mac, mac->bytes) &&
Neale Rannsb8d44812017-11-10 06:53:54 -08002051 sw_if_index == ntohl (event->sw_if_index))
2052 {
2053 return 1;
2054 }
2055
Neale Ranns37029302018-08-10 05:30:06 -07002056 mac_address_encode (mac, event->mac);
Neale Rannsb8d44812017-11-10 06:53:54 -08002057 event->sw_if_index = htonl (sw_if_index);
2058 return 0;
2059}
2060
2061static void
2062vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
2063{
2064 vpe_api_main_t *am = &vpe_api_main;
2065 vnet_main_t *vnm = vnet_get_main ();
2066 vl_api_want_ip4_arp_events_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07002067 ip4_address_t ip;
Neale Rannsb8d44812017-11-10 06:53:54 -08002068 int rv = 0;
2069
Neale Ranns37029302018-08-10 05:30:06 -07002070 ip4_address_decode (mp->ip, &ip);
2071
2072 if (ip.as_u32 == 0)
Neale Rannsb8d44812017-11-10 06:53:54 -08002073 {
2074 uword *p =
2075 hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index);
2076 vpe_client_registration_t *rp;
2077 if (p)
2078 {
2079 if (mp->enable_disable)
2080 {
2081 clib_warning ("pid %d: already enabled...", mp->pid);
2082 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2083 goto reply;
2084 }
2085 else
2086 {
2087 rp =
2088 pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
2089 pool_put (am->wc_ip4_arp_events_registrations, rp);
2090 hash_unset (am->wc_ip4_arp_events_registration_hash,
2091 mp->client_index);
2092 if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002093 wc_arp_set_publisher_node (~0, REPORT_MAX);
Neale Rannsb8d44812017-11-10 06:53:54 -08002094 goto reply;
2095 }
2096 }
2097 if (mp->enable_disable == 0)
2098 {
2099 clib_warning ("pid %d: already disabled...", mp->pid);
2100 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2101 goto reply;
2102 }
2103 pool_get (am->wc_ip4_arp_events_registrations, rp);
2104 rp->client_index = mp->client_index;
2105 rp->client_pid = mp->pid;
2106 hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index,
2107 rp - am->wc_ip4_arp_events_registrations);
2108 wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT);
2109 goto reply;
2110 }
2111
2112 if (mp->enable_disable)
2113 {
2114 vl_api_ip4_arp_event_t *event;
2115 pool_get (am->arp_events, event);
2116 rv = vnet_add_del_ip4_arp_change_event
2117 (vnm, arp_change_data_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002118 mp->pid, mp->ip /* addr, in net byte order */ ,
Neale Rannsb8d44812017-11-10 06:53:54 -08002119 ip_resolver_process_node.index,
2120 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
2121
2122 if (rv)
2123 {
2124 pool_put (am->arp_events, event);
2125 goto reply;
2126 }
Dave Barachb7b92992018-10-17 10:38:51 -04002127 clib_memset (event, 0, sizeof (*event));
Neale Rannsb8d44812017-11-10 06:53:54 -08002128
2129 /* Python API expects events to have no context */
2130 event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
2131 event->client_index = mp->client_index;
Neale Ranns37029302018-08-10 05:30:06 -07002132 memcpy (event->ip, mp->ip, 4);
Neale Rannsb8d44812017-11-10 06:53:54 -08002133 event->pid = mp->pid;
Neale Ranns37029302018-08-10 05:30:06 -07002134 if (ip.as_u32 == 0)
Neale Rannsb8d44812017-11-10 06:53:54 -08002135 event->mac_ip = 1;
2136 }
2137 else
2138 {
2139 rv = vnet_add_del_ip4_arp_change_event
2140 (vnm, arp_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002141 mp->pid, mp->ip /* addr, in net byte order */ ,
Neale Rannsb8d44812017-11-10 06:53:54 -08002142 ip_resolver_process_node.index,
2143 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
2144 }
2145reply:
2146 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
2147}
2148
Neale Rannsf12dad62018-06-04 18:41:24 -07002149static clib_error_t *
2150want_ip4_arp_events_reaper (u32 client_index)
2151{
2152 vpe_client_registration_t *rp;
2153 vl_api_ip4_arp_event_t *event;
2154 u32 *to_delete, *event_id;
2155 vpe_api_main_t *am;
2156 vnet_main_t *vnm;
2157 uword *p;
2158
2159 am = &vpe_api_main;
2160 vnm = vnet_get_main ();
2161 to_delete = NULL;
2162
2163 /* clear out all of its pending resolutions */
2164 /* *INDENT-OFF* */
2165 pool_foreach(event, am->arp_events,
2166 ({
2167 if (event->client_index == client_index)
2168 {
2169 vec_add1(to_delete, event - am->arp_events);
2170 }
2171 }));
2172 /* *INDENT-ON* */
2173
2174 vec_foreach (event_id, to_delete)
2175 {
2176 event = pool_elt_at_index (am->arp_events, *event_id);
2177 vnet_add_del_ip4_arp_change_event
2178 (vnm, arp_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002179 event->pid, event->ip,
Neale Rannsf12dad62018-06-04 18:41:24 -07002180 ip_resolver_process_node.index, IP4_ARP_EVENT,
2181 ~0 /* pool index, notused */ , 0 /* is_add */ );
2182 }
2183 vec_free (to_delete);
2184
2185 /* remove from the registration hash */
2186 p = hash_get (am->wc_ip4_arp_events_registration_hash, client_index);
2187
2188 if (p)
2189 {
2190 rp = pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
2191 pool_put (am->wc_ip4_arp_events_registrations, rp);
2192 hash_unset (am->wc_ip4_arp_events_registration_hash, client_index);
2193 if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
2194 wc_arp_set_publisher_node (~0, REPORT_MAX);
2195 }
2196 return (NULL);
2197}
2198
2199VL_MSG_API_REAPER_FUNCTION (want_ip4_arp_events_reaper);
2200
Neale Rannsb8d44812017-11-10 06:53:54 -08002201static void
2202vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
2203{
2204 vpe_api_main_t *am = &vpe_api_main;
2205 vnet_main_t *vnm = vnet_get_main ();
2206 vl_api_want_ip6_nd_events_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07002207 ip6_address_t ip6;
Neale Rannsb8d44812017-11-10 06:53:54 -08002208 int rv = 0;
2209
Neale Ranns37029302018-08-10 05:30:06 -07002210 ip6_address_decode (mp->ip, &ip6);
2211
2212 if (ip6_address_is_zero (&ip6))
Neale Rannsb8d44812017-11-10 06:53:54 -08002213 {
2214 uword *p =
2215 hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index);
2216 vpe_client_registration_t *rp;
2217 if (p)
2218 {
2219 if (mp->enable_disable)
2220 {
2221 clib_warning ("pid %d: already enabled...", mp->pid);
2222 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2223 goto reply;
2224 }
2225 else
2226 {
2227 rp =
2228 pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
2229 pool_put (am->wc_ip6_nd_events_registrations, rp);
2230 hash_unset (am->wc_ip6_nd_events_registration_hash,
2231 mp->client_index);
2232 if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002233 wc_nd_set_publisher_node (~0, REPORT_MAX);
Neale Rannsb8d44812017-11-10 06:53:54 -08002234 goto reply;
2235 }
2236 }
2237 if (mp->enable_disable == 0)
2238 {
2239 clib_warning ("pid %d: already disabled...", mp->pid);
2240 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2241 goto reply;
2242 }
2243 pool_get (am->wc_ip6_nd_events_registrations, rp);
2244 rp->client_index = mp->client_index;
2245 rp->client_pid = mp->pid;
2246 hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index,
2247 rp - am->wc_ip6_nd_events_registrations);
2248 wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT);
2249 goto reply;
2250 }
2251
2252 if (mp->enable_disable)
2253 {
2254 vl_api_ip6_nd_event_t *event;
2255 pool_get (am->nd_events, event);
2256
2257 rv = vnet_add_del_ip6_nd_change_event
2258 (vnm, nd_change_data_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002259 mp->pid, &ip6,
Neale Rannsb8d44812017-11-10 06:53:54 -08002260 ip_resolver_process_node.index,
2261 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
2262
2263 if (rv)
2264 {
2265 pool_put (am->nd_events, event);
2266 goto reply;
2267 }
Dave Barachb7b92992018-10-17 10:38:51 -04002268 clib_memset (event, 0, sizeof (*event));
Neale Rannsb8d44812017-11-10 06:53:54 -08002269
2270 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
2271 event->client_index = mp->client_index;
Neale Ranns37029302018-08-10 05:30:06 -07002272 ip6_address_encode (&ip6, event->ip);
Neale Rannsb8d44812017-11-10 06:53:54 -08002273 event->pid = mp->pid;
2274 }
2275 else
2276 {
2277 rv = vnet_add_del_ip6_nd_change_event
2278 (vnm, nd_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002279 mp->pid, &ip6 /* addr, in net byte order */ ,
Neale Rannsb8d44812017-11-10 06:53:54 -08002280 ip_resolver_process_node.index,
2281 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
2282 }
2283reply:
2284 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
2285}
2286
Neale Rannsf12dad62018-06-04 18:41:24 -07002287static clib_error_t *
2288want_ip6_nd_events_reaper (u32 client_index)
2289{
2290
2291 vpe_client_registration_t *rp;
2292 vl_api_ip6_nd_event_t *event;
2293 u32 *to_delete, *event_id;
2294 vpe_api_main_t *am;
2295 vnet_main_t *vnm;
2296 uword *p;
2297
2298 am = &vpe_api_main;
2299 vnm = vnet_get_main ();
2300 to_delete = NULL;
2301
2302 /* clear out all of its pending resolutions */
2303 /* *INDENT-OFF* */
2304 pool_foreach(event, am->nd_events,
2305 ({
2306 if (event->client_index == client_index)
2307 {
2308 vec_add1(to_delete, event - am->nd_events);
2309 }
2310 }));
2311 /* *INDENT-ON* */
2312
2313 vec_foreach (event_id, to_delete)
2314 {
2315 event = pool_elt_at_index (am->nd_events, *event_id);
2316 vnet_add_del_ip6_nd_change_event
2317 (vnm, nd_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002318 event->pid, event->ip,
Neale Rannsf12dad62018-06-04 18:41:24 -07002319 ip_resolver_process_node.index, IP6_ND_EVENT,
2320 ~0 /* pool index, notused */ , 0 /* is_add */ );
2321 }
2322 vec_free (to_delete);
2323
2324 /* remove from the registration hash */
2325 p = hash_get (am->wc_ip6_nd_events_registration_hash, client_index);
2326
2327 if (p)
2328 {
2329 rp = pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
2330 pool_put (am->wc_ip6_nd_events_registrations, rp);
2331 hash_unset (am->wc_ip6_nd_events_registration_hash, client_index);
2332 if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
2333 wc_nd_set_publisher_node (~0, REPORT_MAX);
2334 }
2335 return (NULL);
2336}
2337
2338VL_MSG_API_REAPER_FUNCTION (want_ip6_nd_events_reaper);
2339
Neale Rannsb8d44812017-11-10 06:53:54 -08002340static void
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002341vl_api_want_ip6_ra_events_t_handler (vl_api_want_ip6_ra_events_t * mp)
2342{
2343 vpe_api_main_t *am = &vpe_api_main;
2344 vl_api_want_ip6_ra_events_reply_t *rmp;
2345 int rv = 0;
2346
2347 uword *p = hash_get (am->ip6_ra_events_registration_hash, mp->client_index);
2348 vpe_client_registration_t *rp;
2349 if (p)
2350 {
2351 if (mp->enable_disable)
2352 {
2353 clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
2354 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2355 goto reply;
2356 }
2357 else
2358 {
2359 rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
2360 pool_put (am->ip6_ra_events_registrations, rp);
2361 hash_unset (am->ip6_ra_events_registration_hash, mp->client_index);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002362 goto reply;
2363 }
2364 }
2365 if (mp->enable_disable == 0)
2366 {
2367 clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
2368 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2369 goto reply;
2370 }
2371 pool_get (am->ip6_ra_events_registrations, rp);
2372 rp->client_index = mp->client_index;
2373 rp->client_pid = ntohl (mp->pid);
2374 hash_set (am->ip6_ra_events_registration_hash, rp->client_index,
2375 rp - am->ip6_ra_events_registrations);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002376
2377reply:
2378 REPLY_MACRO (VL_API_WANT_IP6_RA_EVENTS_REPLY);
2379}
2380
Neale Rannsf12dad62018-06-04 18:41:24 -07002381static clib_error_t *
2382want_ip6_ra_events_reaper (u32 client_index)
2383{
2384 vpe_api_main_t *am = &vpe_api_main;
2385 vpe_client_registration_t *rp;
2386 uword *p;
2387
2388 p = hash_get (am->ip6_ra_events_registration_hash, client_index);
2389
2390 if (p)
2391 {
2392 rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
2393 pool_put (am->ip6_ra_events_registrations, rp);
2394 hash_unset (am->ip6_ra_events_registration_hash, client_index);
2395 }
2396 return (NULL);
2397}
2398
2399VL_MSG_API_REAPER_FUNCTION (want_ip6_ra_events_reaper);
2400
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002401static void
Neale Rannsb8d44812017-11-10 06:53:54 -08002402vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2403{
2404 vl_api_proxy_arp_add_del_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07002405 ip4_address_t lo, hi;
Neale Rannsb8d44812017-11-10 06:53:54 -08002406 u32 fib_index;
2407 int rv;
Neale Rannsb8d44812017-11-10 06:53:54 -08002408
Neale Ranns37029302018-08-10 05:30:06 -07002409 fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->proxy.table_id));
Neale Rannsb8d44812017-11-10 06:53:54 -08002410
Neale Ranns37029302018-08-10 05:30:06 -07002411 if (~0 == fib_index)
Neale Rannsb8d44812017-11-10 06:53:54 -08002412 {
2413 rv = VNET_API_ERROR_NO_SUCH_FIB;
2414 goto out;
2415 }
2416
Neale Ranns37029302018-08-10 05:30:06 -07002417 ip4_address_decode (mp->proxy.low, &lo);
2418 ip4_address_decode (mp->proxy.hi, &hi);
Neale Rannsb8d44812017-11-10 06:53:54 -08002419
Neale Ranns37029302018-08-10 05:30:06 -07002420 rv = vnet_proxy_arp_add_del (&lo, &hi, fib_index, mp->is_add == 0);
Neale Rannsb8d44812017-11-10 06:53:54 -08002421
2422out:
Neale Rannsb8d44812017-11-10 06:53:54 -08002423 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2424}
2425
Neale Ranns0053de62018-05-22 08:40:52 -07002426typedef struct proxy_arp_walk_ctx_t_
2427{
2428 vl_api_registration_t *reg;
2429 u32 context;
2430} proxy_arp_walk_ctx_t;
2431
2432static walk_rc_t
2433send_proxy_arp_details (const ip4_address_t * lo_addr,
2434 const ip4_address_t * hi_addr,
2435 u32 fib_index, void *data)
2436{
2437 vl_api_proxy_arp_details_t *mp;
2438 proxy_arp_walk_ctx_t *ctx;
2439
2440 ctx = data;
2441
2442 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04002443 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns0053de62018-05-22 08:40:52 -07002444 mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_DETAILS);
2445 mp->context = ctx->context;
Neale Ranns37029302018-08-10 05:30:06 -07002446 mp->proxy.table_id = htonl (fib_index);
2447
2448 ip4_address_encode (lo_addr, mp->proxy.low);
2449 ip4_address_encode (hi_addr, mp->proxy.hi);
Neale Ranns0053de62018-05-22 08:40:52 -07002450
2451 vl_api_send_msg (ctx->reg, (u8 *) mp);
2452
2453 return (WALK_CONTINUE);
2454}
2455
2456static void
2457vl_api_proxy_arp_dump_t_handler (vl_api_proxy_arp_dump_t * mp)
2458{
2459 vl_api_registration_t *reg;
2460
2461 reg = vl_api_client_index_to_registration (mp->client_index);
2462 if (!reg)
2463 return;
2464
2465 proxy_arp_walk_ctx_t wctx = {
2466 .reg = reg,
2467 .context = mp->context,
2468 };
2469
2470 proxy_arp_walk (send_proxy_arp_details, &wctx);
2471}
2472
2473static walk_rc_t
Neale Ranns57e53bb2019-05-29 13:58:43 +00002474send_proxy_arp_intfc_details (u32 sw_if_index, void *data)
Neale Ranns0053de62018-05-22 08:40:52 -07002475{
2476 vl_api_proxy_arp_intfc_details_t *mp;
2477 proxy_arp_walk_ctx_t *ctx;
2478
Neale Ranns0053de62018-05-22 08:40:52 -07002479 ctx = data;
2480
2481 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04002482 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns0053de62018-05-22 08:40:52 -07002483 mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_INTFC_DETAILS);
2484 mp->context = ctx->context;
Neale Ranns57e53bb2019-05-29 13:58:43 +00002485 mp->sw_if_index = htonl (sw_if_index);
Neale Ranns0053de62018-05-22 08:40:52 -07002486
2487 vl_api_send_msg (ctx->reg, (u8 *) mp);
2488
2489 return (WALK_CONTINUE);
2490}
2491
2492static void
2493vl_api_proxy_arp_intfc_dump_t_handler (vl_api_proxy_arp_intfc_dump_t * mp)
2494{
2495 vl_api_registration_t *reg;
2496
2497 reg = vl_api_client_index_to_registration (mp->client_index);
2498 if (!reg)
2499 return;
2500
2501 proxy_arp_walk_ctx_t wctx = {
2502 .reg = reg,
2503 .context = mp->context,
2504 };
2505
Neale Ranns57e53bb2019-05-29 13:58:43 +00002506 proxy_arp_intfc_walk (send_proxy_arp_intfc_details, &wctx);
Neale Ranns0053de62018-05-22 08:40:52 -07002507}
2508
Neale Rannsb8d44812017-11-10 06:53:54 -08002509static void
2510 vl_api_proxy_arp_intfc_enable_disable_t_handler
2511 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2512{
2513 int rv = 0;
2514 vnet_main_t *vnm = vnet_get_main ();
2515 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2516
2517 VALIDATE_SW_IF_INDEX (mp);
2518
Neale Ranns57e53bb2019-05-29 13:58:43 +00002519 rv = vnet_proxy_arp_enable_disable (vnm,
2520 ntohl (mp->sw_if_index),
2521 mp->enable_disable);
Neale Rannsb8d44812017-11-10 06:53:54 -08002522
2523 BAD_SW_IF_INDEX_LABEL;
2524
2525 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2526}
2527
John Loc7b43042018-04-13 16:46:22 -04002528static void
2529vl_api_ip_probe_neighbor_t_handler (vl_api_ip_probe_neighbor_t * mp)
2530{
2531 int rv = 0;
2532 vlib_main_t *vm = vlib_get_main ();
2533 vl_api_ip_probe_neighbor_reply_t *rmp;
2534 clib_error_t *error;
Neale Ranns37029302018-08-10 05:30:06 -07002535 ip46_address_t dst;
2536 ip46_type_t itype;
John Loc7b43042018-04-13 16:46:22 -04002537
2538 VALIDATE_SW_IF_INDEX (mp);
2539
2540 u32 sw_if_index = ntohl (mp->sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07002541 itype = ip_address_decode (&mp->dst, &dst);
John Loc7b43042018-04-13 16:46:22 -04002542
Neale Ranns37029302018-08-10 05:30:06 -07002543 if (IP46_TYPE_IP6 == itype)
2544 error = ip6_probe_neighbor (vm, &dst.ip6, sw_if_index, 0);
John Loc7b43042018-04-13 16:46:22 -04002545 else
Neale Ranns37029302018-08-10 05:30:06 -07002546 error = ip4_probe_neighbor (vm, &dst.ip4, sw_if_index, 0);
John Loc7b43042018-04-13 16:46:22 -04002547
2548 if (error)
2549 {
2550 clib_error_report (error);
2551 rv = clib_error_get_code (error);
2552 }
2553
2554 BAD_SW_IF_INDEX_LABEL;
2555
Ole Troanedfe2c02019-07-30 15:38:13 +02002556 REPLY_MACRO (VL_API_IP_PROBE_NEIGHBOR_REPLY);
John Loc7b43042018-04-13 16:46:22 -04002557}
2558
John Lo7f358b32018-04-28 01:19:24 -04002559static void
2560 vl_api_ip_scan_neighbor_enable_disable_t_handler
2561 (vl_api_ip_scan_neighbor_enable_disable_t * mp)
2562{
2563 int rv = 0;
2564 vl_api_ip_scan_neighbor_enable_disable_reply_t *rmp;
2565 ip_neighbor_scan_arg_t arg;
2566
2567 arg.mode = mp->mode;
2568 arg.scan_interval = mp->scan_interval;
2569 arg.max_proc_time = mp->max_proc_time;
2570 arg.max_update = mp->max_update;
2571 arg.scan_int_delay = mp->scan_int_delay;
2572 arg.stale_threshold = mp->stale_threshold;
2573 ip_neighbor_scan_enable_disable (&arg);
2574
2575 REPLY_MACRO (VL_API_IP_SCAN_NEIGHBOR_ENABLE_DISABLE_REPLY);
2576}
2577
Neale Ranns9db6ada2019-11-08 12:42:31 +00002578static void
2579vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp)
Neale Rannsb8d44812017-11-10 06:53:54 -08002580{
Neale Ranns9db6ada2019-11-08 12:42:31 +00002581 vl_api_ip_table_replace_begin_reply_t *rmp;
2582 fib_protocol_t fproto;
2583 u32 fib_index;
2584 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -08002585
Neale Ranns9db6ada2019-11-08 12:42:31 +00002586 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
2587 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
Neale Rannsb8d44812017-11-10 06:53:54 -08002588
Neale Ranns9db6ada2019-11-08 12:42:31 +00002589 if (INDEX_INVALID == fib_index)
2590 rv = VNET_API_ERROR_NO_SUCH_FIB;
2591 else
2592 {
2593 fib_table_mark (fib_index, fproto, FIB_SOURCE_API);
2594 mfib_table_mark (mfib_table_find (fproto, ntohl (mp->table.table_id)),
2595 fproto, MFIB_SOURCE_API);
Neale Rannsb8d44812017-11-10 06:53:54 -08002596 }
Neale Ranns9db6ada2019-11-08 12:42:31 +00002597 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY);
Neale Rannsb8d44812017-11-10 06:53:54 -08002598}
2599
2600static void
Neale Ranns9db6ada2019-11-08 12:42:31 +00002601vl_api_ip_table_replace_end_t_handler (vl_api_ip_table_replace_end_t * mp)
Neale Rannsb8d44812017-11-10 06:53:54 -08002602{
Neale Ranns9db6ada2019-11-08 12:42:31 +00002603 vl_api_ip_table_replace_end_reply_t *rmp;
2604 fib_protocol_t fproto;
2605 u32 fib_index;
2606 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -08002607
Neale Ranns9db6ada2019-11-08 12:42:31 +00002608 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
2609 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
2610
2611 if (INDEX_INVALID == fib_index)
2612 rv = VNET_API_ERROR_NO_SUCH_FIB;
Neale Rannsb8d44812017-11-10 06:53:54 -08002613 else
Neale Ranns9db6ada2019-11-08 12:42:31 +00002614 {
2615 fib_table_sweep (fib_index, fproto, FIB_SOURCE_API);
2616 mfib_table_sweep (mfib_table_find
2617 (fproto, ntohl (mp->table.table_id)), fproto,
2618 MFIB_SOURCE_API);
2619 }
2620 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY);
2621}
Neale Rannsb8d44812017-11-10 06:53:54 -08002622
Neale Ranns9db6ada2019-11-08 12:42:31 +00002623static void
2624vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
2625{
2626 vl_api_ip_table_flush_reply_t *rmp;
2627 fib_protocol_t fproto;
2628 u32 fib_index;
2629 int rv = 0;
2630
2631 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
2632 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
2633
2634 if (INDEX_INVALID == fib_index)
2635 rv = VNET_API_ERROR_NO_SUCH_FIB;
2636 else
2637 {
2638 vnet_main_t *vnm = vnet_get_main ();
2639 vnet_interface_main_t *im = &vnm->interface_main;
2640 vnet_sw_interface_t *si;
2641
2642 /* Shut down interfaces in this FIB / clean out intfc routes */
2643 /* *INDENT-OFF* */
2644 pool_foreach (si, im->sw_interfaces,
2645 ({
2646 if (fib_index == fib_table_get_index_for_sw_if_index (fproto,
2647 si->sw_if_index))
2648 {
2649 u32 flags = si->flags;
2650 flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
2651 vnet_sw_interface_set_flags (vnm, si->sw_if_index, flags);
2652 }
2653 }));
2654 /* *INDENT-ON* */
2655
2656 fib_table_flush (fib_index, fproto, FIB_SOURCE_API);
2657 mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)),
2658 fproto, MFIB_SOURCE_API);
2659 }
2660
2661 REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY);
Neale Rannsb8d44812017-11-10 06:53:54 -08002662}
2663
2664static void
2665vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2666{
2667 int rv;
2668 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2669 vnet_main_t *vnm = vnet_get_main ();
2670 clib_error_t *error;
2671
2672 vnm->api_errno = 0;
2673
2674 if (mp->is_ipv6)
2675 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2676 else
2677 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2678
2679 if (error)
2680 {
2681 clib_error_report (error);
2682 rv = VNET_API_ERROR_UNSPECIFIED;
2683 }
2684 else
2685 {
2686 rv = vnm->api_errno;
2687 }
2688
2689 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2690}
2691
Klement Sekera75e7d132017-09-20 08:26:30 +02002692void
2693vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
2694{
2695 vl_api_ip_reassembly_set_reply_t *rmp;
2696 int rv = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00002697 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera75e7d132017-09-20 08:26:30 +02002698 {
Klement Sekerade34c352019-06-25 11:19:22 +00002699 case IP_REASS_TYPE_FULL:
2700 if (mp->is_ip6)
2701 {
2702 rv = ip6_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
2703 clib_net_to_host_u32
2704 (mp->max_reassemblies),
2705 clib_net_to_host_u32
2706 (mp->max_reassembly_length),
2707 clib_net_to_host_u32
2708 (mp->expire_walk_interval_ms));
2709 }
2710 else
2711 {
2712 rv = ip4_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
2713 clib_net_to_host_u32
2714 (mp->max_reassemblies),
2715 clib_net_to_host_u32
2716 (mp->max_reassembly_length),
2717 clib_net_to_host_u32
2718 (mp->expire_walk_interval_ms));
2719 }
2720 break;
2721 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
2722 if (mp->is_ip6)
2723 {
2724 rv =
2725 ip6_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
2726 clib_net_to_host_u32 (mp->max_reassemblies),
2727 clib_net_to_host_u32
2728 (mp->max_reassembly_length),
2729 clib_net_to_host_u32
2730 (mp->expire_walk_interval_ms));
2731 }
2732 else
2733 {
2734 rv = ip4_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
2735 clib_net_to_host_u32 (mp->max_reassemblies),
2736 clib_net_to_host_u32
2737 (mp->max_reassembly_length),
2738 clib_net_to_host_u32
2739 (mp->expire_walk_interval_ms));
2740 }
2741 break;
Klement Sekera75e7d132017-09-20 08:26:30 +02002742 }
2743
2744 REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
2745}
2746
2747void
2748vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
2749{
Ole Troan2e1c8962019-04-10 09:44:23 +02002750 vl_api_registration_t *rp;
Klement Sekera75e7d132017-09-20 08:26:30 +02002751
Ole Troan2e1c8962019-04-10 09:44:23 +02002752 rp = vl_api_client_index_to_registration (mp->client_index);
2753 if (rp == 0)
Klement Sekera75e7d132017-09-20 08:26:30 +02002754 return;
2755
2756 vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04002757 clib_memset (rmp, 0, sizeof (*rmp));
Klement Sekera75e7d132017-09-20 08:26:30 +02002758 rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
2759 rmp->context = mp->context;
2760 rmp->retval = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00002761 u32 timeout_ms;
2762 u32 max_reassemblies;
2763 u32 max_reassembly_length;
2764 u32 expire_walk_interval_ms;
2765 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera75e7d132017-09-20 08:26:30 +02002766 {
Klement Sekerade34c352019-06-25 11:19:22 +00002767 case IP_REASS_TYPE_FULL:
2768 if (mp->is_ip6)
2769 {
2770 rmp->is_ip6 = 1;
2771 ip6_full_reass_get (&timeout_ms, &max_reassemblies,
2772 &max_reassembly_length,
2773 &expire_walk_interval_ms);
2774 }
2775 else
2776 {
2777 rmp->is_ip6 = 0;
2778 ip4_full_reass_get (&timeout_ms, &max_reassemblies,
2779 &max_reassembly_length,
2780 &expire_walk_interval_ms);
2781 }
2782 break;
2783 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
2784 if (mp->is_ip6)
2785 {
2786 rmp->is_ip6 = 1;
2787 ip6_sv_reass_get (&timeout_ms, &max_reassemblies,
2788 &max_reassembly_length, &expire_walk_interval_ms);
2789 }
2790 else
2791 {
2792 rmp->is_ip6 = 0;
2793 ip4_sv_reass_get (&timeout_ms, &max_reassemblies,
2794 &max_reassembly_length, &expire_walk_interval_ms);
2795 }
2796 break;
Klement Sekera75e7d132017-09-20 08:26:30 +02002797 }
Matthew Smithb3174df2019-12-03 12:41:53 -06002798 rmp->timeout_ms = clib_host_to_net_u32 (timeout_ms);
2799 rmp->max_reassemblies = clib_host_to_net_u32 (max_reassemblies);
2800 rmp->max_reassembly_length = clib_host_to_net_u32 (max_reassembly_length);
Klement Sekera75e7d132017-09-20 08:26:30 +02002801 rmp->expire_walk_interval_ms =
Matthew Smithb3174df2019-12-03 12:41:53 -06002802 clib_host_to_net_u32 (expire_walk_interval_ms);
Ole Troan2e1c8962019-04-10 09:44:23 +02002803 vl_api_send_msg (rp, (u8 *) rmp);
Klement Sekera75e7d132017-09-20 08:26:30 +02002804}
2805
Klement Sekera4c533132018-02-22 11:41:12 +01002806void
2807 vl_api_ip_reassembly_enable_disable_t_handler
2808 (vl_api_ip_reassembly_enable_disable_t * mp)
2809{
2810 vl_api_ip_reassembly_enable_disable_reply_t *rmp;
2811 int rv = 0;
Klement Sekerade34c352019-06-25 11:19:22 +00002812 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
Klement Sekera4c533132018-02-22 11:41:12 +01002813 {
Klement Sekerade34c352019-06-25 11:19:22 +00002814 case IP_REASS_TYPE_FULL:
Klement Sekera896c8962019-06-24 11:52:49 +00002815 rv =
Klement Sekerade34c352019-06-25 11:19:22 +00002816 ip4_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
2817 mp->enable_ip4);
2818 if (0 == rv)
2819 rv =
2820 ip6_full_reass_enable_disable (clib_net_to_host_u32
2821 (mp->sw_if_index), mp->enable_ip6);
2822 break;
2823 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
2824 rv =
2825 ip4_sv_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
2826 mp->enable_ip4);
2827 if (0 == rv)
2828 {
2829 rv =
2830 ip6_sv_reass_enable_disable (clib_net_to_host_u32
2831 (mp->sw_if_index), mp->enable_ip6);
2832 }
2833 break;
Klement Sekera4c533132018-02-22 11:41:12 +01002834 }
2835
Choree7f61d12018-11-28 10:27:58 +03302836 REPLY_MACRO (VL_API_IP_REASSEMBLY_ENABLE_DISABLE_REPLY);
Klement Sekera4c533132018-02-22 11:41:12 +01002837}
2838
Neale Ranns92207752019-06-03 13:21:40 +00002839typedef struct ip_punt_redirect_walk_ctx_t_
Pavel Kotucek609e1212018-11-27 09:59:44 +01002840{
Neale Ranns92207752019-06-03 13:21:40 +00002841 vl_api_registration_t *reg;
2842 u32 context;
2843} ip_punt_redirect_walk_ctx_t;
2844
2845static walk_rc_t
2846send_ip_punt_redirect_details (u32 rx_sw_if_index,
2847 const ip_punt_redirect_rx_t * ipr, void *arg)
2848{
Neale Ranns92207752019-06-03 13:21:40 +00002849 ip_punt_redirect_walk_ctx_t *ctx = arg;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002850 vl_api_ip_punt_redirect_details_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07002851 fib_path_encode_ctx_t path_ctx = {
2852 .rpaths = NULL,
2853 };
Pavel Kotucek609e1212018-11-27 09:59:44 +01002854
2855 mp = vl_msg_api_alloc (sizeof (*mp));
2856 if (!mp)
Neale Ranns92207752019-06-03 13:21:40 +00002857 return (WALK_STOP);;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002858
2859 clib_memset (mp, 0, sizeof (*mp));
2860 mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
Neale Ranns92207752019-06-03 13:21:40 +00002861 mp->context = ctx->context;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002862
Neale Ranns097fa662018-05-01 05:17:55 -07002863 fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &path_ctx);
Neale Ranns92207752019-06-03 13:21:40 +00002864
2865 mp->punt.rx_sw_if_index = htonl (rx_sw_if_index);
Neale Ranns097fa662018-05-01 05:17:55 -07002866 mp->punt.tx_sw_if_index = htonl (path_ctx.rpaths[0].frp_sw_if_index);
Neale Ranns92207752019-06-03 13:21:40 +00002867
Neale Ranns097fa662018-05-01 05:17:55 -07002868 ip_address_encode (&path_ctx.rpaths[0].frp_addr,
Neale Ranns92207752019-06-03 13:21:40 +00002869 fib_proto_to_ip46 (ipr->fproto), &mp->punt.nh);
2870
2871 vl_api_send_msg (ctx->reg, (u8 *) mp);
2872
Neale Ranns097fa662018-05-01 05:17:55 -07002873 vec_free (path_ctx.rpaths);
Neale Ranns92207752019-06-03 13:21:40 +00002874
2875 return (WALK_CONTINUE);
Pavel Kotucek609e1212018-11-27 09:59:44 +01002876}
2877
2878static void
2879vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp)
2880{
2881 vl_api_registration_t *reg;
Neale Ranns92207752019-06-03 13:21:40 +00002882 fib_protocol_t fproto;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002883
Pavel Kotucek609e1212018-11-27 09:59:44 +01002884 reg = vl_api_client_index_to_registration (mp->client_index);
2885 if (!reg)
2886 return;
2887
Neale Ranns92207752019-06-03 13:21:40 +00002888 fproto = mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002889
Neale Ranns92207752019-06-03 13:21:40 +00002890 ip_punt_redirect_walk_ctx_t ctx = {
2891 .reg = reg,
2892 .context = mp->context,
2893 };
2894
2895 if (~0 != mp->sw_if_index)
Pavel Kotucek609e1212018-11-27 09:59:44 +01002896 {
Neale Ranns92207752019-06-03 13:21:40 +00002897 u32 rx_sw_if_index;
2898 index_t pri;
2899
2900 rx_sw_if_index = ntohl (mp->sw_if_index);
2901 pri = ip_punt_redirect_find (fproto, rx_sw_if_index);
2902
2903 if (INDEX_INVALID == pri)
2904 return;
2905
2906 send_ip_punt_redirect_details (rx_sw_if_index,
2907 ip_punt_redirect_get (pri), &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01002908 }
2909 else
Neale Ranns92207752019-06-03 13:21:40 +00002910 ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01002911}
2912
Dave Barachb5e8a772016-12-06 12:04:42 -05002913#define vl_msg_name_crc_list
2914#include <vnet/ip/ip.api.h>
2915#undef vl_msg_name_crc_list
2916
2917static void
2918setup_message_id_table (api_main_t * am)
2919{
2920#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2921 foreach_vl_msg_name_crc_ip;
2922#undef _
2923}
2924
2925static clib_error_t *
2926ip_api_hookup (vlib_main_t * vm)
2927{
Dave Barach39d69112019-11-27 11:42:13 -05002928 api_main_t *am = vlibapi_get_main ();
Dave Barachb5e8a772016-12-06 12:04:42 -05002929
2930#define _(N,n) \
2931 vl_msg_api_set_handlers(VL_API_##N, #n, \
2932 vl_api_##n##_t_handler, \
2933 vl_noop_handler, \
2934 vl_api_##n##_t_endian, \
2935 vl_api_##n##_t_print, \
2936 sizeof(vl_api_##n##_t), 1);
2937 foreach_ip_api_msg;
2938#undef _
2939
2940 /*
Neale Ranns6a231a12018-10-17 06:38:00 +00002941 * Mark the route add/del API as MP safe
2942 */
Neale Ranns097fa662018-05-01 05:17:55 -07002943 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1;
2944 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL_REPLY] = 1;
Neale Ranns6a231a12018-10-17 06:38:00 +00002945
2946 /*
Dave Barachb5e8a772016-12-06 12:04:42 -05002947 * Set up the (msg_name, crc, message-id) table
2948 */
2949 setup_message_id_table (am);
2950
Juraj Sloboda52574522018-05-03 10:03:50 +02002951 ra_set_publisher_node (wc_arp_process_node.index, RA_REPORT);
2952
Dave Barachb5e8a772016-12-06 12:04:42 -05002953 return 0;
2954}
2955
2956VLIB_API_INIT_FUNCTION (ip_api_hookup);
2957
2958/*
2959 * fd.io coding-style-patch-verification: ON
2960 *
2961 * Local Variables:
2962 * eval: (c-set-style "gnu")
2963 * End:
2964 */