blob: 3e04b9f740ce8c98f216df3b0abf7f03d61b37b5 [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 Sekera896c8962019-06-24 11:52:49 +000046#include <vnet/ip/reass/ip4_full_reass.h>
47#include <vnet/ip/reass/ip6_full_reass.h>
Neale Ranns0053de62018-05-22 08:40:52 -070048#include <vnet/ethernet/arp.h>
Matus Fabian75b9f452018-10-02 23:27:21 -070049#include <vnet/ip/ip_types_api.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050050
51#include <vnet/vnet_msg_enum.h>
52
53#define vl_typedefs /* define message structures */
54#include <vnet/vnet_all_api_h.h>
55#undef vl_typedefs
56
57#define vl_endianfun /* define message structures */
58#include <vnet/vnet_all_api_h.h>
59#undef vl_endianfun
60
61/* instantiate all the print functions we know about */
62#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
63#define vl_printfun
64#include <vnet/vnet_all_api_h.h>
65#undef vl_printfun
66
67#include <vlibapi/api_helper_macros.h>
68
Ole Troan33a58172019-09-04 09:12:29 +020069#include <vnet/format_fns.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080070
Dave Barachb5e8a772016-12-06 12:04:42 -050071#define foreach_ip_api_msg \
Neale Ranns097fa662018-05-01 05:17:55 -070072_(IP_TABLE_DUMP, ip_table_dump) \
73_(IP_ROUTE_DUMP, ip_route_dump) \
74_(IP_MTABLE_DUMP, ip_mtable_dump) \
75_(IP_MROUTE_DUMP, ip_mroute_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050076_(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \
Neale Ranns32e1c012016-11-22 17:07:28 +000077_(IP_MROUTE_ADD_DEL, ip_mroute_add_del) \
Neale Ranns5a8123b2017-01-26 01:18:23 -080078_(MFIB_SIGNAL_DUMP, mfib_signal_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050079_(IP_ADDRESS_DUMP, ip_address_dump) \
Neale Ranns9e2f9152018-05-18 02:27:10 -070080_(IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050081_(IP_DUMP, ip_dump) \
82_(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
Neale Rannsb8d44812017-11-10 06:53:54 -080083_(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
John Loc7b43042018-04-13 16:46:22 -040084_(IP_PROBE_NEIGHBOR, ip_probe_neighbor) \
John Lo7f358b32018-04-28 01:19:24 -040085_(IP_SCAN_NEIGHBOR_ENABLE_DISABLE, ip_scan_neighbor_enable_disable) \
Neale Rannsb8d44812017-11-10 06:53:54 -080086_(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
87_(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010088_(WANT_IP6_RA_EVENTS, want_ip6_ra_events) \
Neale Rannsb8d44812017-11-10 06:53:54 -080089_(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
Neale Ranns0053de62018-05-22 08:40:52 -070090_(PROXY_ARP_DUMP, proxy_arp_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -080091_(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
Neale Ranns0053de62018-05-22 08:40:52 -070092 _(PROXY_ARP_INTFC_DUMP, proxy_arp_intfc_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -080093_(RESET_FIB, reset_fib) \
Neale Ranns097fa662018-05-01 05:17:55 -070094_(IP_ROUTE_ADD_DEL, ip_route_add_del) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070095_(IP_TABLE_ADD_DEL, ip_table_add_del) \
Neale Rannsd91c1db2017-07-31 02:30:50 -070096_(IP_PUNT_POLICE, ip_punt_police) \
97_(IP_PUNT_REDIRECT, ip_punt_redirect) \
Dave Barachb5e8a772016-12-06 12:04:42 -050098_(SET_IP_FLOW_HASH,set_ip_flow_hash) \
99_(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
100_(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
Neale Ranns3f844d02017-02-18 00:03:54 -0800101_(IP6ND_PROXY_ADD_DEL, ip6nd_proxy_add_del) \
102_(IP6ND_PROXY_DUMP, ip6nd_proxy_dump) \
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100103_(IP6ND_SEND_ROUTER_SOLICITATION, ip6nd_send_router_solicitation) \
Dave Barachb5e8a772016-12-06 12:04:42 -0500104_(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
Neale Rannsb8d44812017-11-10 06:53:54 -0800105_(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \
Matus Fabian75b9f452018-10-02 23:27:21 -0700106_(IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -0800107_(IOAM_ENABLE, ioam_enable) \
108_(IOAM_DISABLE, ioam_disable) \
109_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
110 ip_source_and_port_range_check_add_del) \
111_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
Klement Sekera75e7d132017-09-20 08:26:30 +0200112 ip_source_and_port_range_check_interface_add_del) \
Chore3460b012018-11-28 10:53:11 +0330113_(IP_SOURCE_CHECK_INTERFACE_ADD_DEL, \
114 ip_source_check_interface_add_del) \
Klement Sekera75e7d132017-09-20 08:26:30 +0200115_(IP_REASSEMBLY_SET, ip_reassembly_set) \
Klement Sekera4c533132018-02-22 11:41:12 +0100116_(IP_REASSEMBLY_GET, ip_reassembly_get) \
Pavel Kotucek609e1212018-11-27 09:59:44 +0100117_(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
118_(IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
119
Dave Barachb5e8a772016-12-06 12:04:42 -0500120
Neale Ranns37029302018-08-10 05:30:06 -0700121static vl_api_ip_neighbor_flags_t
122ip_neighbor_flags_encode (ip_neighbor_flags_t f)
123{
124 vl_api_ip_neighbor_flags_t v = IP_API_NEIGHBOR_FLAG_NONE;
125
126 if (f & IP_NEIGHBOR_FLAG_STATIC)
127 v |= IP_API_NEIGHBOR_FLAG_STATIC;
128 if (f & IP_NEIGHBOR_FLAG_NO_FIB_ENTRY)
129 v |= IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY;
130
131 return (clib_host_to_net_u32 (v));
132}
133
Dave Barachb5e8a772016-12-06 12:04:42 -0500134static void
Jon Loeligeraf8dfbf2017-11-08 13:07:39 -0600135send_ip_neighbor_details (u32 sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700136 const ip46_address_t * ip_address,
137 const mac_address_t * mac,
138 ip_neighbor_flags_t flags,
139 vl_api_registration_t * reg, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500140{
141 vl_api_ip_neighbor_details_t *mp;
142
143 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400144 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500145 mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS);
146 mp->context = context;
Neale Ranns37029302018-08-10 05:30:06 -0700147 mp->neighbor.sw_if_index = htonl (sw_if_index);
148 mp->neighbor.flags = ip_neighbor_flags_encode (flags);
149
150 ip_address_encode (ip_address, IP46_TYPE_ANY, &mp->neighbor.ip_address);
151 mac_address_encode (mac, mp->neighbor.mac_address);
Dave Barachb5e8a772016-12-06 12:04:42 -0500152
Florin Coras6c4dae22018-01-09 06:39:23 -0800153 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500154}
155
156static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500157vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp)
158{
Florin Coras6c4dae22018-01-09 06:39:23 -0800159 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500160
Florin Coras6c4dae22018-01-09 06:39:23 -0800161 reg = vl_api_client_index_to_registration (mp->client_index);
162 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500163 return;
164
165 u32 sw_if_index = ntohl (mp->sw_if_index);
166
167 if (mp->is_ipv6)
168 {
169 ip6_neighbor_t *n, *ns;
170
171 ns = ip6_neighbors_entries (sw_if_index);
172 /* *INDENT-OFF* */
173 vec_foreach (n, ns)
174 {
Neale Ranns37029302018-08-10 05:30:06 -0700175 ip46_address_t nh = {
176 .ip6 = {
177 .as_u64[0] = n->key.ip6_address.as_u64[0],
178 .as_u64[1] = n->key.ip6_address.as_u64[1],
179 },
180 };
181 send_ip_neighbor_details (n->key.sw_if_index, &nh,
182 &n->mac, n->flags,
183 reg, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500184 }
185 /* *INDENT-ON* */
186 vec_free (ns);
187 }
188 else
189 {
190 ethernet_arp_ip4_entry_t *n, *ns;
191
192 ns = ip4_neighbor_entries (sw_if_index);
193 /* *INDENT-OFF* */
194 vec_foreach (n, ns)
195 {
Neale Ranns37029302018-08-10 05:30:06 -0700196 ip46_address_t nh = {
197 .ip4 = {
198 .as_u32 = n->ip4_address.as_u32,
199 },
200 };
201
202 send_ip_neighbor_details (n->sw_if_index, &nh,
203 &n->mac, n->flags,
204 reg, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500205 }
206 /* *INDENT-ON* */
207 vec_free (ns);
208 }
209}
210
Dave Barachb5e8a772016-12-06 12:04:42 -0500211static void
Neale Ranns097fa662018-05-01 05:17:55 -0700212send_ip_table_details (vpe_api_main_t * am,
213 vl_api_registration_t * reg,
214 u32 context, const fib_table_t * table)
Dave Barachb5e8a772016-12-06 12:04:42 -0500215{
Neale Ranns097fa662018-05-01 05:17:55 -0700216 vl_api_ip_table_details_t *mp;
Dave Barachb5e8a772016-12-06 12:04:42 -0500217
Neale Ranns097fa662018-05-01 05:17:55 -0700218 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500219 if (!mp)
220 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400221 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700222 mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500223 mp->context = context;
224
Neale Ranns097fa662018-05-01 05:17:55 -0700225 mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6);
226 mp->table.table_id = htonl (table->ft_table_id);
227 memcpy (mp->table.name, table->ft_desc,
228 clib_min (vec_len (table->ft_desc), sizeof (mp->table.name)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500229
Florin Coras6c4dae22018-01-09 06:39:23 -0800230 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500231}
232
Neale Ranns097fa662018-05-01 05:17:55 -0700233static void
234vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp)
235{
236 vpe_api_main_t *am = &vpe_api_main;
237 vl_api_registration_t *reg;
238 fib_table_t *fib_table;
239
240 reg = vl_api_client_index_to_registration (mp->client_index);
241 if (!reg)
242 return;
243
244 /* *INDENT-OFF* */
245 pool_foreach (fib_table, ip4_main.fibs,
246 ({
247 send_ip_table_details(am, reg, mp->context, fib_table);
248 }));
249 pool_foreach (fib_table, ip6_main.fibs,
250 ({
251 /* don't send link locals */
252 if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
253 continue;
254 send_ip_table_details(am, reg, mp->context, fib_table);
255 }));
256 /* *INDENT-ON* */
257}
258
Neale Rannsa3af3372017-03-28 03:49:52 -0700259typedef struct vl_api_ip_fib_dump_walk_ctx_t_
260{
261 fib_node_index_t *feis;
262} vl_api_ip_fib_dump_walk_ctx_t;
263
Neale Ranns89541992017-04-06 04:41:02 -0700264static fib_table_walk_rc_t
Neale Rannsa3af3372017-03-28 03:49:52 -0700265vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg)
266{
267 vl_api_ip_fib_dump_walk_ctx_t *ctx = arg;
268
269 vec_add1 (ctx->feis, fei);
270
Neale Ranns89541992017-04-06 04:41:02 -0700271 return (FIB_TABLE_WALK_CONTINUE);
Neale Rannsa3af3372017-03-28 03:49:52 -0700272}
273
Dave Barachb5e8a772016-12-06 12:04:42 -0500274static void
Neale Ranns097fa662018-05-01 05:17:55 -0700275send_ip_route_details (vpe_api_main_t * am,
276 vl_api_registration_t * reg,
277 u32 context, fib_node_index_t fib_entry_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500278{
Neale Ranns097fa662018-05-01 05:17:55 -0700279 fib_route_path_t *rpaths, *rpath;
280 vl_api_ip_route_details_t *mp;
Neale Rannsc5d43172018-07-30 08:04:40 -0700281 const fib_prefix_t *pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -0500282 vl_api_fib_path_t *fp;
283 int path_count;
284
Neale Ranns097fa662018-05-01 05:17:55 -0700285 rpaths = NULL;
286 pfx = fib_entry_get_prefix (fib_entry_index);
287 rpaths = fib_entry_encode (fib_entry_index);
288
289 path_count = vec_len (rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500290 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
291 if (!mp)
292 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400293 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns097fa662018-05-01 05:17:55 -0700294 mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS);
Dave Barachb5e8a772016-12-06 12:04:42 -0500295 mp->context = context;
296
Neale Ranns097fa662018-05-01 05:17:55 -0700297 ip_prefix_encode (pfx, &mp->route.prefix);
298 mp->route.table_id =
299 htonl (fib_table_get_table_id
300 (fib_entry_get_fib_index (fib_entry_index), pfx->fp_proto));
301 mp->route.n_paths = path_count;
302 mp->route.stats_index =
303 htonl (fib_table_entry_get_stats_index
304 (fib_entry_get_fib_index (fib_entry_index), pfx));
Dave Barachb5e8a772016-12-06 12:04:42 -0500305
Neale Ranns097fa662018-05-01 05:17:55 -0700306 fp = mp->route.paths;
307 vec_foreach (rpath, rpaths)
Dave Barachb5e8a772016-12-06 12:04:42 -0500308 {
Neale Ranns097fa662018-05-01 05:17:55 -0700309 fib_api_path_encode (rpath, fp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500310 fp++;
311 }
312
Florin Coras6c4dae22018-01-09 06:39:23 -0800313 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500314}
315
Dave Barachd7cb1b52016-12-09 09:52:16 -0500316typedef struct apt_ip6_fib_show_ctx_t_
317{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500318 fib_node_index_t *entries;
Dave Barachb5e8a772016-12-06 12:04:42 -0500319} api_ip6_fib_show_ctx_t;
320
Dave Barachb5e8a772016-12-06 12:04:42 -0500321static void
Neale Ranns097fa662018-05-01 05:17:55 -0700322vl_api_ip_route_dump_t_handler (vl_api_ip_route_dump_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500323{
324 vpe_api_main_t *am = &vpe_api_main;
Dave Barachb5e8a772016-12-06 12:04:42 -0500325 fib_node_index_t *fib_entry_index;
Florin Coras6c4dae22018-01-09 06:39:23 -0800326 vl_api_registration_t *reg;
Neale Ranns097fa662018-05-01 05:17:55 -0700327 fib_protocol_t fproto;
328 u32 fib_index;
Dave Barachb5e8a772016-12-06 12:04:42 -0500329
Florin Coras6c4dae22018-01-09 06:39:23 -0800330 reg = vl_api_client_index_to_registration (mp->client_index);
331 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500332 return;
333
Neale Ranns097fa662018-05-01 05:17:55 -0700334 vl_api_ip_fib_dump_walk_ctx_t ctx = {
335 .feis = NULL,
336 };
Neale Ranns81458422018-03-12 06:59:36 -0700337
Neale Ranns097fa662018-05-01 05:17:55 -0700338 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
339 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
340
341 if (INDEX_INVALID == fib_index)
342 return;
343
344 fib_table_walk (fib_index, fproto, vl_api_ip_fib_dump_walk, &ctx);
345
346 vec_foreach (fib_entry_index, ctx.feis)
347 {
348 send_ip_route_details (am, reg, mp->context, *fib_entry_index);
349 }
350
351 vec_free (ctx.feis);
Dave Barachb5e8a772016-12-06 12:04:42 -0500352}
353
354static void
Neale Ranns097fa662018-05-01 05:17:55 -0700355send_ip_mtable_details (vl_api_registration_t * reg,
356 u32 context, const mfib_table_t * mfib_table)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800357{
Neale Ranns097fa662018-05-01 05:17:55 -0700358 vl_api_ip_mtable_details_t *mp;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800359
Neale Ranns097fa662018-05-01 05:17:55 -0700360 mp = vl_msg_api_alloc (sizeof (*mp));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800361 if (!mp)
362 return;
Neale Ranns097fa662018-05-01 05:17:55 -0700363 memset (mp, 0, sizeof (*mp));
364 mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800365 mp->context = context;
366
Neale Ranns097fa662018-05-01 05:17:55 -0700367 mp->table.table_id = htonl (mfib_table->mft_table_id);
368 mp->table.is_ip6 = (FIB_PROTOCOL_IP6 == mfib_table->mft_proto);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800369
Florin Coras6c4dae22018-01-09 06:39:23 -0800370 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800371}
372
Neale Ranns5a8123b2017-01-26 01:18:23 -0800373static void
Neale Ranns097fa662018-05-01 05:17:55 -0700374vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800375{
Florin Coras6c4dae22018-01-09 06:39:23 -0800376 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800377 mfib_table_t *mfib_table;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800378
Florin Coras6c4dae22018-01-09 06:39:23 -0800379 reg = vl_api_client_index_to_registration (mp->client_index);
380 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800381 return;
382
Neale Ranns5a8123b2017-01-26 01:18:23 -0800383 /* *INDENT-OFF* */
Neale Ranns097fa662018-05-01 05:17:55 -0700384 pool_foreach (mfib_table, ip4_main.mfibs,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800385 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700386 send_ip_mtable_details (reg, mp->context, mfib_table);
387 }));
388 pool_foreach (mfib_table, ip6_main.mfibs,
389 ({
390 send_ip_mtable_details (reg, mp->context, mfib_table);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800391 }));
392 /* *INDENT-ON* */
Neale Ranns5a8123b2017-01-26 01:18:23 -0800393}
394
Neale Ranns097fa662018-05-01 05:17:55 -0700395typedef struct vl_api_ip_mfib_dump_ctx_t_
Neale Ranns5a8123b2017-01-26 01:18:23 -0800396{
397 fib_node_index_t *entries;
Neale Ranns097fa662018-05-01 05:17:55 -0700398} vl_api_ip_mfib_dump_ctx_t;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800399
400static int
Neale Ranns097fa662018-05-01 05:17:55 -0700401mfib_route_dump_walk (fib_node_index_t fei, void *arg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800402{
Neale Ranns097fa662018-05-01 05:17:55 -0700403 vl_api_ip_mfib_dump_ctx_t *ctx = arg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800404
405 vec_add1 (ctx->entries, fei);
406
407 return (0);
408}
409
410static void
Neale Ranns097fa662018-05-01 05:17:55 -0700411send_ip_mroute_details (vpe_api_main_t * am,
412 vl_api_registration_t * reg,
413 u32 context, fib_node_index_t mfib_entry_index)
414{
415 fib_route_path_t *rpaths, *rpath;
416 vl_api_ip_mroute_details_t *mp;
417 const mfib_prefix_t *pfx;
418 vl_api_mfib_path_t *fp;
419 int path_count;
420
421 rpaths = NULL;
422 pfx = mfib_entry_get_prefix (mfib_entry_index);
423 rpaths = mfib_entry_encode (mfib_entry_index);
424
425 path_count = vec_len (rpaths);
426 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
427 if (!mp)
428 return;
429 clib_memset (mp, 0, sizeof (*mp));
430 mp->_vl_msg_id = ntohs (VL_API_IP_MROUTE_DETAILS);
431 mp->context = context;
432
433 ip_mprefix_encode (pfx, &mp->route.prefix);
434 mp->route.table_id =
435 htonl (mfib_table_get_table_id
436 (mfib_entry_get_fib_index (mfib_entry_index), pfx->fp_proto));
437 mp->route.n_paths = htonl (path_count);
438 fp = mp->route.paths;
439 vec_foreach (rpath, rpaths)
440 {
441 mfib_api_path_encode (rpath, fp);
442 fp++;
443 }
444
445 vl_api_send_msg (reg, (u8 *) mp);
446 vec_free (rpaths);
447}
448
449static void
450vl_api_ip_mroute_dump_t_handler (vl_api_ip_mroute_dump_t * mp)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800451{
452 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800453 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800454 fib_node_index_t *mfeip;
Neale Ranns097fa662018-05-01 05:17:55 -0700455 fib_protocol_t fproto;
456 u32 fib_index;
457
458 vl_api_ip_mfib_dump_ctx_t ctx = {
Neale Ranns5a8123b2017-01-26 01:18:23 -0800459 .entries = NULL,
460 };
461
Florin Coras6c4dae22018-01-09 06:39:23 -0800462 reg = vl_api_client_index_to_registration (mp->client_index);
463 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800464 return;
465
Neale Ranns097fa662018-05-01 05:17:55 -0700466 fproto = fib_ip_proto (mp->table.is_ip6);
467 fib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800468
Neale Ranns097fa662018-05-01 05:17:55 -0700469 if (INDEX_INVALID == fib_index)
470 return;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800471
Neale Ranns097fa662018-05-01 05:17:55 -0700472 mfib_table_walk (fib_index, fproto, mfib_route_dump_walk, &ctx);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800473
Neale Ranns097fa662018-05-01 05:17:55 -0700474 vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800475
Neale Ranns097fa662018-05-01 05:17:55 -0700476 vec_foreach (mfeip, ctx.entries)
477 {
478 send_ip_mroute_details (am, reg, mp->context, *mfeip);
479 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800480
481 vec_free (ctx.entries);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800482}
483
484static void
Neale Rannsd91c1db2017-07-31 02:30:50 -0700485vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp,
486 vlib_main_t * vm)
487{
488 vl_api_ip_punt_police_reply_t *rmp;
489 int rv = 0;
490
491 if (mp->is_ip6)
492 ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
493 else
494 ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
495
496 REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY);
497}
498
499static void
500vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp,
501 vlib_main_t * vm)
502{
503 vl_api_ip_punt_redirect_reply_t *rmp;
504 int rv = 0;
Pavel Kotucek609e1212018-11-27 09:59:44 +0100505 ip46_type_t ipv;
506 ip46_address_t nh;
Neale Rannsd91c1db2017-07-31 02:30:50 -0700507
Pavel Kotucek609e1212018-11-27 09:59:44 +0100508 if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index)))
509 goto bad_sw_if_index;
510
511 ipv = ip_address_decode (&mp->punt.nh, &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700512 if (mp->is_add)
513 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100514 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700515 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100516 ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
517 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700518 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100519 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700520 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100521 ip4_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 }
524 }
525 else
526 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100527 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700528 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100529 ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700530 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100531 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700532 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100533 ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700534 }
535 }
536
Pavel Kotucek609e1212018-11-27 09:59:44 +0100537 BAD_SW_IF_INDEX_LABEL;
538
Neale Rannsd91c1db2017-07-31 02:30:50 -0700539 REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY);
540}
541
Neale Ranns37029302018-08-10 05:30:06 -0700542static ip_neighbor_flags_t
543ip_neighbor_flags_decode (vl_api_ip_neighbor_flags_t v)
544{
545 ip_neighbor_flags_t f = IP_NEIGHBOR_FLAG_NONE;
546
547 v = clib_net_to_host_u32 (v);
548
549 if (v & IP_API_NEIGHBOR_FLAG_STATIC)
550 f |= IP_NEIGHBOR_FLAG_STATIC;
551 if (v & IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY)
552 f |= IP_NEIGHBOR_FLAG_NO_FIB_ENTRY;
553
554 return (f);
555}
556
Neale Rannsd91c1db2017-07-31 02:30:50 -0700557static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500558vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
559 vlib_main_t * vm)
560{
561 vl_api_ip_neighbor_add_del_reply_t *rmp;
Neale Ranns0bdd3192018-09-07 11:04:52 -0700562 ip_neighbor_flags_t flags;
Neale Ranns14260392018-09-28 05:00:57 -0700563 u32 stats_index = ~0;
Neale Ranns37029302018-08-10 05:30:06 -0700564 ip46_address_t ip;
565 mac_address_t mac;
566 ip46_type_t type;
Neale Ranns097fa662018-05-01 05:17:55 -0700567 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -0500568
Neale Ranns37029302018-08-10 05:30:06 -0700569 VALIDATE_SW_IF_INDEX ((&mp->neighbor));
Dave Barachb5e8a772016-12-06 12:04:42 -0500570
Neale Ranns37029302018-08-10 05:30:06 -0700571 flags = ip_neighbor_flags_decode (mp->neighbor.flags);
572 type = ip_address_decode (&mp->neighbor.ip_address, &ip);
573 mac_address_decode (mp->neighbor.mac_address, &mac);
Neale Ranns0bdd3192018-09-07 11:04:52 -0700574
Neale Ranns37029302018-08-10 05:30:06 -0700575 /*
576 * there's no validation here of the ND/ARP entry being added.
577 * The expectation is that the FIB will ensure that nothing bad
578 * will come of adding bogus entries.
579 */
Neale Ranns0bdd3192018-09-07 11:04:52 -0700580 if (mp->is_add)
Neale Ranns37029302018-08-10 05:30:06 -0700581 rv = ip_neighbor_add (&ip, type, &mac,
582 ntohl (mp->neighbor.sw_if_index),
583 flags, &stats_index);
Neale Ranns0bdd3192018-09-07 11:04:52 -0700584 else
Neale Ranns37029302018-08-10 05:30:06 -0700585 rv = ip_neighbor_del (&ip, type, ntohl (mp->neighbor.sw_if_index));
Dave Barachb5e8a772016-12-06 12:04:42 -0500586
Neale Ranns8edad032017-10-09 05:26:13 -0700587 BAD_SW_IF_INDEX_LABEL;
Neale Ranns14260392018-09-28 05:00:57 -0700588
589 /* *INDENT-OFF* */
590 REPLY_MACRO2 (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY,
591 ({
592 rmp->stats_index = htonl (stats_index);
593 }));
594 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500595}
596
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700597void
Neale Ranns15002542017-09-10 04:39:11 -0700598ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api)
599{
600 u32 fib_index, mfib_index;
601
602 /*
603 * ignore action on the default table - this is always present
604 * and cannot be added nor deleted from the API
605 */
606 if (0 != table_id)
607 {
608 /*
609 * The API holds only one lock on the table.
610 * i.e. it can be added many times via the API but needs to be
611 * deleted only once.
612 * The FIB index for unicast and multicast is not necessarily the
613 * same, since internal VPP systesm (like LISP and SR) create
614 * their own unicast tables.
615 */
616 fib_index = fib_table_find (fproto, table_id);
617 mfib_index = mfib_table_find (fproto, table_id);
618
619 if (~0 != fib_index)
620 {
621 fib_table_unlock (fib_index, fproto,
622 (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI));
623 }
624 if (~0 != mfib_index)
625 {
626 mfib_table_unlock (mfib_index, fproto,
627 (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI));
628 }
629 }
630}
631
632void
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700633vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
634{
635 vl_api_ip_table_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700636 fib_protocol_t fproto = (mp->table.is_ip6 ?
637 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
638 u32 table_id = ntohl (mp->table.table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700639 int rv = 0;
640
Neale Ranns15002542017-09-10 04:39:11 -0700641 if (mp->is_add)
642 {
Neale Ranns097fa662018-05-01 05:17:55 -0700643 ip_table_create (fproto, table_id, 1, mp->table.name);
Neale Ranns15002542017-09-10 04:39:11 -0700644 }
645 else
646 {
647 ip_table_delete (fproto, table_id, 1);
648 }
649
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700650 REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY);
651}
652
Dave Barachb5e8a772016-12-06 12:04:42 -0500653static int
Neale Ranns097fa662018-05-01 05:17:55 -0700654ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp, u32 * stats_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500655{
Neale Ranns097fa662018-05-01 05:17:55 -0700656 fib_route_path_t *rpaths = NULL, *rpath;
657 fib_entry_flag_t entry_flags;
658 vl_api_fib_path_t *apath;
659 fib_prefix_t pfx;
660 u32 fib_index;
661 int rv, ii;
Dave Barachb5e8a772016-12-06 12:04:42 -0500662
Neale Ranns097fa662018-05-01 05:17:55 -0700663 entry_flags = FIB_ENTRY_FLAG_NONE;
664 ip_prefix_decode (&mp->route.prefix, &pfx);
Dave Barachb5e8a772016-12-06 12:04:42 -0500665
Neale Ranns097fa662018-05-01 05:17:55 -0700666 rv = fib_api_table_id_decode (pfx.fp_proto,
667 ntohl (mp->route.table_id), &fib_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500668 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700669 goto out;
Dave Barachb5e8a772016-12-06 12:04:42 -0500670
Neale Rannsc2ac2352019-07-02 14:33:29 +0000671 if (0 != mp->route.n_paths)
672 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns097fa662018-05-01 05:17:55 -0700673
674 for (ii = 0; ii < mp->route.n_paths; ii++)
675 {
676 apath = &mp->route.paths[ii];
677 rpath = &rpaths[ii];
678
679 rv = fib_api_path_decode (apath, rpath);
680
681 if ((rpath->frp_flags & FIB_ROUTE_PATH_LOCAL) &&
682 (~0 == rpath->frp_sw_if_index))
683 entry_flags |= (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL);
684
685 if (0 != rv)
686 goto out;
687 }
688
Neale Rannsc2ac2352019-07-02 14:33:29 +0000689 rv = fib_api_route_add_del (mp->is_add,
690 mp->is_multipath,
691 fib_index, &pfx, entry_flags, rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700692
693 if (mp->is_add && 0 == rv)
694 *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx);
695
Neale Ranns097fa662018-05-01 05:17:55 -0700696out:
697 vec_free (rpaths);
Neale Ranns008dbe12018-09-07 09:32:36 -0700698
699 return (rv);
Dave Barachb5e8a772016-12-06 12:04:42 -0500700}
701
702void
Neale Ranns097fa662018-05-01 05:17:55 -0700703vl_api_ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp)
Dave Barachb5e8a772016-12-06 12:04:42 -0500704{
Neale Ranns097fa662018-05-01 05:17:55 -0700705 vl_api_ip_route_add_del_reply_t *rmp;
706 u32 stats_index = ~0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500707 int rv;
Dave Barachb5e8a772016-12-06 12:04:42 -0500708
Neale Ranns097fa662018-05-01 05:17:55 -0700709 rv = ip_route_add_del_t_handler (mp, &stats_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500710
Neale Ranns008dbe12018-09-07 09:32:36 -0700711 /* *INDENT-OFF* */
Neale Ranns097fa662018-05-01 05:17:55 -0700712 REPLY_MACRO2 (VL_API_IP_ROUTE_ADD_DEL_REPLY,
Neale Ranns008dbe12018-09-07 09:32:36 -0700713 ({
714 rmp->stats_index = htonl (stats_index);
715 }))
716 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500717}
718
Neale Ranns15002542017-09-10 04:39:11 -0700719void
Neale Ranns2297af02017-09-12 09:45:04 -0700720ip_table_create (fib_protocol_t fproto,
721 u32 table_id, u8 is_api, const u8 * name)
Neale Ranns15002542017-09-10 04:39:11 -0700722{
723 u32 fib_index, mfib_index;
724
725 /*
726 * ignore action on the default table - this is always present
727 * and cannot be added nor deleted from the API
728 */
729 if (0 != table_id)
730 {
731 /*
732 * The API holds only one lock on the table.
733 * i.e. it can be added many times via the API but needs to be
734 * deleted only once.
735 * The FIB index for unicast and multicast is not necessarily the
736 * same, since internal VPP systesm (like LISP and SR) create
737 * their own unicast tables.
738 */
739 fib_index = fib_table_find (fproto, table_id);
740 mfib_index = mfib_table_find (fproto, table_id);
741
742 if (~0 == fib_index)
743 {
Neale Ranns2297af02017-09-12 09:45:04 -0700744 fib_table_find_or_create_and_lock_w_name (fproto, table_id,
745 (is_api ?
746 FIB_SOURCE_API :
747 FIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700748 }
749 if (~0 == mfib_index)
750 {
Neale Ranns2297af02017-09-12 09:45:04 -0700751 mfib_table_find_or_create_and_lock_w_name (fproto, table_id,
752 (is_api ?
753 MFIB_SOURCE_API :
754 MFIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -0700755 }
756 }
757}
758
Neale Ranns097fa662018-05-01 05:17:55 -0700759static u32
Neale Ranns32e1c012016-11-22 17:07:28 +0000760mroute_add_del_handler (u8 is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700761 u8 is_multipath,
Neale Ranns32e1c012016-11-22 17:07:28 +0000762 u32 fib_index,
763 const mfib_prefix_t * prefix,
764 u32 entry_flags,
Neale Ranns097fa662018-05-01 05:17:55 -0700765 u32 rpf_id, fib_route_path_t * rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +0000766{
Neale Ranns097fa662018-05-01 05:17:55 -0700767 u32 mfib_entry_index = ~0;
Neale Ranns28c142e2018-09-07 09:37:07 -0700768
Neale Ranns097fa662018-05-01 05:17:55 -0700769 if (0 == vec_len (rpaths))
Neale Ranns32e1c012016-11-22 17:07:28 +0000770 {
Neale Ranns28c142e2018-09-07 09:37:07 -0700771 mfib_entry_index = mfib_table_entry_update (fib_index, prefix,
772 MFIB_SOURCE_API,
773 rpf_id, entry_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +0000774 }
775 else
776 {
Neale Ranns097fa662018-05-01 05:17:55 -0700777 if (is_add)
778 {
779 mfib_entry_index =
780 mfib_table_entry_paths_update (fib_index, prefix,
781 MFIB_SOURCE_API, rpaths);
782 }
783 else
784 {
785 mfib_table_entry_paths_remove (fib_index, prefix,
786 MFIB_SOURCE_API, rpaths);
787 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000788 }
789
Neale Ranns28c142e2018-09-07 09:37:07 -0700790 return (mfib_entry_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000791}
792
793static int
Neale Ranns28c142e2018-09-07 09:37:07 -0700794api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp,
795 u32 * stats_index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000796{
Neale Ranns097fa662018-05-01 05:17:55 -0700797 fib_route_path_t *rpath, *rpaths = NULL;
Neale Ranns28c142e2018-09-07 09:37:07 -0700798 fib_node_index_t mfib_entry_index;
Neale Ranns097fa662018-05-01 05:17:55 -0700799 mfib_prefix_t pfx;
Neale Ranns32e1c012016-11-22 17:07:28 +0000800 u32 fib_index;
801 int rv;
Neale Ranns097fa662018-05-01 05:17:55 -0700802 u16 ii;
Neale Ranns32e1c012016-11-22 17:07:28 +0000803
Neale Ranns097fa662018-05-01 05:17:55 -0700804 ip_mprefix_decode (&mp->route.prefix, &pfx);
Neale Ranns32e1c012016-11-22 17:07:28 +0000805
Neale Ranns097fa662018-05-01 05:17:55 -0700806 rv = mfib_api_table_id_decode (pfx.fp_proto,
807 ntohl (mp->route.table_id), &fib_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000808 if (0 != rv)
Neale Ranns097fa662018-05-01 05:17:55 -0700809 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000810
Neale Ranns097fa662018-05-01 05:17:55 -0700811 vec_validate (rpaths, mp->route.n_paths - 1);
Neale Ranns32e1c012016-11-22 17:07:28 +0000812
Neale Ranns097fa662018-05-01 05:17:55 -0700813 for (ii = 0; ii < mp->route.n_paths; ii++)
Neale Ranns32e1c012016-11-22 17:07:28 +0000814 {
Neale Ranns097fa662018-05-01 05:17:55 -0700815 rpath = &rpaths[ii];
816
817 rv = mfib_api_path_decode (&mp->route.paths[ii], rpath);
818
819 if (0 != rv)
820 goto out;
Neale Ranns32e1c012016-11-22 17:07:28 +0000821 }
822
Neale Ranns28c142e2018-09-07 09:37:07 -0700823 mfib_entry_index = mroute_add_del_handler (mp->is_add,
Neale Ranns097fa662018-05-01 05:17:55 -0700824 mp->is_add,
Neale Ranns28c142e2018-09-07 09:37:07 -0700825 fib_index, &pfx,
Neale Ranns097fa662018-05-01 05:17:55 -0700826 ntohl (mp->route.entry_flags),
827 ntohl (mp->route.rpf_id),
828 rpaths);
Neale Ranns28c142e2018-09-07 09:37:07 -0700829
830 if (~0 != mfib_entry_index)
831 *stats_index = mfib_entry_get_stats_index (mfib_entry_index);
832
Neale Ranns097fa662018-05-01 05:17:55 -0700833out:
Neale Ranns28c142e2018-09-07 09:37:07 -0700834 return (rv);
Neale Ranns32e1c012016-11-22 17:07:28 +0000835}
836
837void
838vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp)
839{
840 vl_api_ip_mroute_add_del_reply_t *rmp;
Neale Ranns097fa662018-05-01 05:17:55 -0700841 u32 stats_index = ~0;
Neale Ranns32e1c012016-11-22 17:07:28 +0000842 int rv;
Neale Ranns32e1c012016-11-22 17:07:28 +0000843
Neale Ranns28c142e2018-09-07 09:37:07 -0700844 rv = api_mroute_add_del_t_handler (mp, &stats_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000845
Neale Ranns28c142e2018-09-07 09:37:07 -0700846 /* *INDENT-OFF* */
847 REPLY_MACRO2 (VL_API_IP_MROUTE_ADD_DEL_REPLY,
848 ({
849 rmp->stats_index = htonl (stats_index);
850 }));
851 /* *INDENT-ON* */
Neale Ranns32e1c012016-11-22 17:07:28 +0000852}
853
Dave Barachb5e8a772016-12-06 12:04:42 -0500854static void
855send_ip_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800856 vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6,
857 u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500858{
859 vl_api_ip_details_t *mp;
860
861 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400862 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500863 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
864
865 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger466f0d42017-02-09 12:17:50 -0600866 mp->is_ipv6 = is_ipv6;
Dave Barachb5e8a772016-12-06 12:04:42 -0500867 mp->context = context;
868
Florin Coras6c4dae22018-01-09 06:39:23 -0800869 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500870}
871
872static void
873send_ip_address_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800874 vl_api_registration_t * reg,
Neale Ranns097fa662018-05-01 05:17:55 -0700875 const fib_prefix_t * pfx,
876 u32 sw_if_index, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500877{
878 vl_api_ip_address_details_t *mp;
879
880 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400881 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500882 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
883
Neale Ranns097fa662018-05-01 05:17:55 -0700884 ip_prefix_encode (pfx, &mp->prefix);
Dave Barachb5e8a772016-12-06 12:04:42 -0500885 mp->context = context;
Jon Loeliger466f0d42017-02-09 12:17:50 -0600886 mp->sw_if_index = htonl (sw_if_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500887
Florin Coras6c4dae22018-01-09 06:39:23 -0800888 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500889}
890
891static void
892vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
893{
894 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800895 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500896 ip6_main_t *im6 = &ip6_main;
897 ip4_main_t *im4 = &ip4_main;
898 ip_lookup_main_t *lm6 = &im6->lookup_main;
899 ip_lookup_main_t *lm4 = &im4->lookup_main;
900 ip_interface_address_t *ia = 0;
901 u32 sw_if_index = ~0;
902 int rv __attribute__ ((unused)) = 0;
903
904 VALIDATE_SW_IF_INDEX (mp);
905
906 sw_if_index = ntohl (mp->sw_if_index);
907
Florin Coras6c4dae22018-01-09 06:39:23 -0800908 reg = vl_api_client_index_to_registration (mp->client_index);
909 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500910 return;
911
Dave Barachb5e8a772016-12-06 12:04:42 -0500912 if (mp->is_ipv6)
913 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500914 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700915 /* Do not send subnet details of the IP-interface for
916 * unnumbered interfaces. otherwise listening clients
917 * will be confused that the subnet is applied on more
918 * than one interface */
919 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500920 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700921 fib_prefix_t pfx = {
922 .fp_addr.ip6 = *(ip6_address_t *)ip_interface_address_get_address (lm6, ia),
923 .fp_len = ia->address_length,
924 .fp_proto = FIB_PROTOCOL_IP6,
925 };
926 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500927 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500928 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500929 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500930 else
931 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500932 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -0700933 foreach_ip_interface_address (lm4, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -0500934 ({
Neale Ranns097fa662018-05-01 05:17:55 -0700935 fib_prefix_t pfx = {
936 .fp_addr.ip4 = *(ip4_address_t *)ip_interface_address_get_address (lm4, ia),
937 .fp_len = ia->address_length,
938 .fp_proto = FIB_PROTOCOL_IP4,
939 };
940
941 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500942 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500943 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500944 }
Neale Ranns008dbe12018-09-07 09:32:36 -0700945
Dave Barachb5e8a772016-12-06 12:04:42 -0500946 BAD_SW_IF_INDEX_LABEL;
947}
948
949static void
Neale Ranns9e2f9152018-05-18 02:27:10 -0700950send_ip_unnumbered_details (vpe_api_main_t * am,
951 vl_api_registration_t * reg,
952 u32 sw_if_index, u32 ip_sw_if_index, u32 context)
953{
954 vl_api_ip_unnumbered_details_t *mp;
955
956 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400957 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns9e2f9152018-05-18 02:27:10 -0700958 mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
959
960 mp->context = context;
961 mp->sw_if_index = htonl (sw_if_index);
962 mp->ip_sw_if_index = htonl (ip_sw_if_index);
963
964 vl_api_send_msg (reg, (u8 *) mp);
965}
966
967static void
968vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
969{
970 vnet_main_t *vnm = vnet_get_main ();
971 vnet_interface_main_t *im = &vnm->interface_main;
972 int rv __attribute__ ((unused)) = 0;
973 vpe_api_main_t *am = &vpe_api_main;
974 vl_api_registration_t *reg;
975 vnet_sw_interface_t *si;
976 u32 sw_if_index;
977
978 sw_if_index = ntohl (mp->sw_if_index);
979
980 reg = vl_api_client_index_to_registration (mp->client_index);
981 if (!reg)
982 return;
983
984 if (~0 != sw_if_index)
985 {
986 VALIDATE_SW_IF_INDEX (mp);
987
988 si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
989
990 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
991 {
992 send_ip_unnumbered_details (am, reg,
993 sw_if_index,
994 si->unnumbered_sw_if_index,
995 mp->context);
996 }
997 }
998 else
999 {
1000 /* *INDENT-OFF* */
1001 pool_foreach (si, im->sw_interfaces,
1002 ({
1003 if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1004 {
1005 send_ip_unnumbered_details(am, reg,
1006 si->sw_if_index,
1007 si->unnumbered_sw_if_index,
1008 mp->context);
1009 }
1010 }));
1011 /* *INDENT-ON* */
1012 }
1013
1014 BAD_SW_IF_INDEX_LABEL;
1015}
1016
1017static void
Dave Barachb5e8a772016-12-06 12:04:42 -05001018vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
1019{
1020 vpe_api_main_t *am = &vpe_api_main;
1021 vnet_main_t *vnm = vnet_get_main ();
1022 vlib_main_t *vm = vlib_get_main ();
1023 vnet_interface_main_t *im = &vnm->interface_main;
Florin Coras6c4dae22018-01-09 06:39:23 -08001024 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -05001025 vnet_sw_interface_t *si, *sorted_sis;
1026 u32 sw_if_index = ~0;
1027
Florin Coras6c4dae22018-01-09 06:39:23 -08001028 reg = vl_api_client_index_to_registration (mp->client_index);
1029 if (!reg)
1030 return;
Dave Barachb5e8a772016-12-06 12:04:42 -05001031
1032 /* Gather interfaces. */
1033 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1034 _vec_len (sorted_sis) = 0;
1035 /* *INDENT-OFF* */
1036 pool_foreach (si, im->sw_interfaces,
1037 ({
1038 vec_add1 (sorted_sis, si[0]);
1039 }));
1040 /* *INDENT-ON* */
1041
1042 vec_foreach (si, sorted_sis)
1043 {
1044 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1045 {
1046 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
1047 {
1048 continue;
1049 }
1050 sw_if_index = si->sw_if_index;
Florin Coras6c4dae22018-01-09 06:39:23 -08001051 send_ip_details (am, reg, sw_if_index, mp->is_ipv6, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -05001052 }
1053 }
Matthew Smith6d5f6592019-09-18 13:51:46 -05001054
1055 vec_free (sorted_sis);
Dave Barachb5e8a772016-12-06 12:04:42 -05001056}
1057
1058static void
1059set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
1060{
1061 vl_api_set_ip_flow_hash_reply_t *rmp;
Neale Ranns227038a2017-04-21 01:07:59 -07001062 int rv;
1063 u32 table_id;
1064 flow_hash_config_t flow_hash_config = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -05001065
Neale Ranns227038a2017-04-21 01:07:59 -07001066 table_id = ntohl (mp->vrf_id);
1067
1068#define _(a,b) if (mp->a) flow_hash_config |= b;
1069 foreach_flow_hash_bit;
1070#undef _
1071
1072 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
Dave Barachb5e8a772016-12-06 12:04:42 -05001073
1074 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1075}
1076
1077static void
1078set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
1079{
1080 vl_api_set_ip_flow_hash_reply_t *rmp;
1081 int rv;
1082 u32 table_id;
1083 flow_hash_config_t flow_hash_config = 0;
1084
1085 table_id = ntohl (mp->vrf_id);
1086
1087#define _(a,b) if (mp->a) flow_hash_config |= b;
1088 foreach_flow_hash_bit;
1089#undef _
1090
1091 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
1092
1093 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1094}
1095
1096
1097static void
1098vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
1099{
1100 if (mp->is_ipv6 == 0)
1101 set_ip4_flow_hash (mp);
1102 else
1103 set_ip6_flow_hash (mp);
1104}
1105
1106static void
1107 vl_api_sw_interface_ip6nd_ra_config_t_handler
1108 (vl_api_sw_interface_ip6nd_ra_config_t * mp)
1109{
1110 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
1111 vlib_main_t *vm = vlib_get_main ();
1112 int rv = 0;
1113 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
1114 default_router;
1115
1116 is_no = mp->is_no == 1;
1117 suppress = mp->suppress == 1;
1118 managed = mp->managed == 1;
1119 other = mp->other == 1;
1120 ll_option = mp->ll_option == 1;
1121 send_unicast = mp->send_unicast == 1;
1122 cease = mp->cease == 1;
1123 default_router = mp->default_router == 1;
1124
1125 VALIDATE_SW_IF_INDEX (mp);
1126
1127 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
1128 suppress, managed, other,
1129 ll_option, send_unicast, cease,
1130 default_router, ntohl (mp->lifetime),
1131 ntohl (mp->initial_count),
1132 ntohl (mp->initial_interval),
1133 ntohl (mp->max_interval),
1134 ntohl (mp->min_interval), is_no);
1135
1136 BAD_SW_IF_INDEX_LABEL;
1137
1138 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
1139}
1140
1141static void
1142 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
1143 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp)
1144{
1145 vlib_main_t *vm = vlib_get_main ();
1146 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07001147 fib_prefix_t pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -05001148 int rv = 0;
1149 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
1150
1151 VALIDATE_SW_IF_INDEX (mp);
1152
Neale Ranns37029302018-08-10 05:30:06 -07001153 ip_prefix_decode (&mp->prefix, &pfx);
Dave Barachb5e8a772016-12-06 12:04:42 -05001154 is_no = mp->is_no == 1;
1155 use_default = mp->use_default == 1;
1156 no_advertise = mp->no_advertise == 1;
1157 off_link = mp->off_link == 1;
1158 no_autoconfig = mp->no_autoconfig == 1;
1159 no_onlink = mp->no_onlink == 1;
1160
1161 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
Neale Ranns37029302018-08-10 05:30:06 -07001162 &pfx.fp_addr.ip6,
1163 pfx.fp_len, use_default,
Dave Barachb5e8a772016-12-06 12:04:42 -05001164 ntohl (mp->val_lifetime),
1165 ntohl (mp->pref_lifetime), no_advertise,
1166 off_link, no_autoconfig, no_onlink, is_no);
1167
1168 BAD_SW_IF_INDEX_LABEL;
1169 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
1170}
1171
1172static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001173send_ip6nd_proxy_details (vl_api_registration_t * reg,
Neale Ranns3f844d02017-02-18 00:03:54 -08001174 u32 context,
1175 const ip46_address_t * addr, u32 sw_if_index)
1176{
1177 vl_api_ip6nd_proxy_details_t *mp;
1178
1179 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04001180 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns3f844d02017-02-18 00:03:54 -08001181 mp->_vl_msg_id = ntohs (VL_API_IP6ND_PROXY_DETAILS);
1182 mp->context = context;
1183 mp->sw_if_index = htonl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07001184
1185 ip6_address_encode (&addr->ip6, mp->ip);
Neale Ranns3f844d02017-02-18 00:03:54 -08001186
Florin Coras6c4dae22018-01-09 06:39:23 -08001187 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns3f844d02017-02-18 00:03:54 -08001188}
1189
Neale Ranns3f844d02017-02-18 00:03:54 -08001190typedef struct api_ip6nd_proxy_fib_table_walk_ctx_t_
1191{
1192 u32 *indices;
1193} api_ip6nd_proxy_fib_table_walk_ctx_t;
1194
Neale Ranns89541992017-04-06 04:41:02 -07001195static fib_table_walk_rc_t
Neale Ranns3f844d02017-02-18 00:03:54 -08001196api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg)
1197{
1198 api_ip6nd_proxy_fib_table_walk_ctx_t *ctx = arg;
1199
1200 if (fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND_PROXY))
1201 {
1202 vec_add1 (ctx->indices, fei);
1203 }
1204
Neale Ranns89541992017-04-06 04:41:02 -07001205 return (FIB_TABLE_WALK_CONTINUE);
Neale Ranns3f844d02017-02-18 00:03:54 -08001206}
1207
1208static void
1209vl_api_ip6nd_proxy_dump_t_handler (vl_api_ip6nd_proxy_dump_t * mp)
1210{
1211 ip6_main_t *im6 = &ip6_main;
1212 fib_table_t *fib_table;
1213 api_ip6nd_proxy_fib_table_walk_ctx_t ctx = {
1214 .indices = NULL,
1215 };
1216 fib_node_index_t *feip;
Neale Rannsc5d43172018-07-30 08:04:40 -07001217 const fib_prefix_t *pfx;
Florin Coras6c4dae22018-01-09 06:39:23 -08001218 vl_api_registration_t *reg;
Neale Ranns3f844d02017-02-18 00:03:54 -08001219
Florin Coras6c4dae22018-01-09 06:39:23 -08001220 reg = vl_api_client_index_to_registration (mp->client_index);
1221 if (!reg)
1222 return;
Neale Ranns3f844d02017-02-18 00:03:54 -08001223
1224 /* *INDENT-OFF* */
1225 pool_foreach (fib_table, im6->fibs,
1226 ({
1227 fib_table_walk(fib_table->ft_index,
1228 FIB_PROTOCOL_IP6,
1229 api_ip6nd_proxy_fib_table_walk,
1230 &ctx);
1231 }));
1232 /* *INDENT-ON* */
1233
1234 vec_sort_with_function (ctx.indices, fib_entry_cmp_for_sort);
1235
1236 vec_foreach (feip, ctx.indices)
1237 {
Neale Rannsc5d43172018-07-30 08:04:40 -07001238 pfx = fib_entry_get_prefix (*feip);
Neale Ranns3f844d02017-02-18 00:03:54 -08001239
Florin Coras6c4dae22018-01-09 06:39:23 -08001240 send_ip6nd_proxy_details (reg,
Neale Ranns3f844d02017-02-18 00:03:54 -08001241 mp->context,
Neale Rannsc5d43172018-07-30 08:04:40 -07001242 &pfx->fp_addr,
Neale Ranns3f844d02017-02-18 00:03:54 -08001243 fib_entry_get_resolving_interface (*feip));
1244 }
1245
1246 vec_free (ctx.indices);
1247}
1248
1249static void
1250vl_api_ip6nd_proxy_add_del_t_handler (vl_api_ip6nd_proxy_add_del_t * mp)
1251{
1252 vl_api_ip6nd_proxy_add_del_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07001253 ip6_address_t ip6;
Neale Ranns3f844d02017-02-18 00:03:54 -08001254 int rv = 0;
1255
1256 VALIDATE_SW_IF_INDEX (mp);
1257
Neale Ranns37029302018-08-10 05:30:06 -07001258 ip6_address_decode (mp->ip, &ip6);
1259 rv = ip6_neighbor_proxy_add_del (ntohl (mp->sw_if_index), &ip6, mp->is_del);
Neale Ranns3f844d02017-02-18 00:03:54 -08001260
1261 BAD_SW_IF_INDEX_LABEL;
1262 REPLY_MACRO (VL_API_IP6ND_PROXY_ADD_DEL_REPLY);
1263}
1264
1265static void
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001266 vl_api_ip6nd_send_router_solicitation_t_handler
1267 (vl_api_ip6nd_send_router_solicitation_t * mp)
1268{
1269 vl_api_ip6nd_send_router_solicitation_reply_t *rmp;
1270 icmp6_send_router_solicitation_params_t params;
1271 vlib_main_t *vm = vlib_get_main ();
1272 int rv = 0;
1273
1274 VALIDATE_SW_IF_INDEX (mp);
1275
1276 BAD_SW_IF_INDEX_LABEL;
1277 REPLY_MACRO (VL_API_IP6ND_SEND_ROUTER_SOLICITATION_REPLY);
1278
1279 if (rv != 0)
1280 return;
1281
1282 params.irt = ntohl (mp->irt);
1283 params.mrt = ntohl (mp->mrt);
1284 params.mrc = ntohl (mp->mrc);
1285 params.mrd = ntohl (mp->mrd);
1286
1287 icmp6_send_router_solicitation (vm, ntohl (mp->sw_if_index), mp->stop,
1288 &params);
1289}
1290
1291static void
Dave Barachb5e8a772016-12-06 12:04:42 -05001292 vl_api_sw_interface_ip6_enable_disable_t_handler
1293 (vl_api_sw_interface_ip6_enable_disable_t * mp)
1294{
1295 vlib_main_t *vm = vlib_get_main ();
1296 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
1297 vnet_main_t *vnm = vnet_get_main ();
1298 int rv = 0;
1299 clib_error_t *error;
1300
1301 vnm->api_errno = 0;
1302
1303 VALIDATE_SW_IF_INDEX (mp);
1304
1305 error =
1306 (mp->enable == 1) ? enable_ip6_interface (vm,
1307 ntohl (mp->sw_if_index)) :
1308 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
1309
1310 if (error)
1311 {
1312 clib_error_report (error);
1313 rv = VNET_API_ERROR_UNSPECIFIED;
1314 }
1315 else
1316 {
1317 rv = vnm->api_errno;
1318 }
1319
1320 BAD_SW_IF_INDEX_LABEL;
1321
1322 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
1323}
1324
Neale Ranns32e1c012016-11-22 17:07:28 +00001325void
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001326vl_mfib_signal_send_one (vl_api_registration_t * reg,
Neale Ranns32e1c012016-11-22 17:07:28 +00001327 u32 context, const mfib_signal_t * mfs)
1328{
1329 vl_api_mfib_signal_details_t *mp;
Neale Ranns9e829a82018-12-17 05:50:32 -08001330 const mfib_prefix_t *prefix;
Neale Ranns32e1c012016-11-22 17:07:28 +00001331 mfib_table_t *mfib;
1332 mfib_itf_t *mfi;
1333
1334 mp = vl_msg_api_alloc (sizeof (*mp));
1335
Dave Barachb7b92992018-10-17 10:38:51 -04001336 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns32e1c012016-11-22 17:07:28 +00001337 mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS);
1338 mp->context = context;
1339
1340 mfi = mfib_itf_get (mfs->mfs_itf);
Neale Ranns9e829a82018-12-17 05:50:32 -08001341 prefix = mfib_entry_get_prefix (mfs->mfs_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +00001342 mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry),
Neale Ranns9e829a82018-12-17 05:50:32 -08001343 prefix->fp_proto);
Neale Ranns32e1c012016-11-22 17:07:28 +00001344 mp->table_id = ntohl (mfib->mft_table_id);
1345 mp->sw_if_index = ntohl (mfi->mfi_sw_if_index);
1346
Neale Ranns097fa662018-05-01 05:17:55 -07001347 ip_mprefix_encode (prefix, &mp->prefix);
Neale Ranns32e1c012016-11-22 17:07:28 +00001348
1349 if (0 != mfs->mfs_buffer_len)
1350 {
1351 mp->ip_packet_len = ntohs (mfs->mfs_buffer_len);
1352
1353 memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len);
1354 }
1355 else
1356 {
1357 mp->ip_packet_len = 0;
1358 }
1359
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001360 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00001361}
1362
1363static void
1364vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
1365{
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001366 vl_api_registration_t *reg;
Neale Ranns32e1c012016-11-22 17:07:28 +00001367
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001368 reg = vl_api_client_index_to_registration (mp->client_index);
1369 if (!reg)
1370 return;
Neale Ranns32e1c012016-11-22 17:07:28 +00001371
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001372 while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
Neale Ranns32e1c012016-11-22 17:07:28 +00001373 ;
1374}
Dave Barachb5e8a772016-12-06 12:04:42 -05001375
Florin Coras595992c2017-11-06 17:17:08 -08001376static void
1377 vl_api_ip_container_proxy_add_del_t_handler
1378 (vl_api_ip_container_proxy_add_del_t * mp)
1379{
1380 vl_api_ip_container_proxy_add_del_reply_t *rmp;
1381 vnet_ip_container_proxy_args_t args;
1382 int rv = 0;
1383 clib_error_t *error;
1384
Dave Barachb7b92992018-10-17 10:38:51 -04001385 clib_memset (&args, 0, sizeof (args));
Neale Ranns37029302018-08-10 05:30:06 -07001386
1387 ip_prefix_decode (&mp->pfx, &args.prefix);
1388
Florin Coras595992c2017-11-06 17:17:08 -08001389 args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1390 args.is_add = mp->is_add;
1391 if ((error = vnet_ip_container_proxy_add_del (&args)))
1392 {
1393 rv = clib_error_get_code (error);
1394 clib_error_report (error);
1395 }
1396
1397 REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
1398}
1399
Matus Fabian75b9f452018-10-02 23:27:21 -07001400typedef struct ip_container_proxy_walk_ctx_t_
1401{
1402 vl_api_registration_t *reg;
1403 u32 context;
1404} ip_container_proxy_walk_ctx_t;
1405
1406static int
1407ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
1408 void *args)
1409{
1410 vl_api_ip_container_proxy_details_t *mp;
1411 ip_container_proxy_walk_ctx_t *ctx = args;
1412
1413 mp = vl_msg_api_alloc (sizeof (*mp));
1414 if (!mp)
1415 return 1;
1416
Dave Barachb7b92992018-10-17 10:38:51 -04001417 clib_memset (mp, 0, sizeof (*mp));
Matus Fabian75b9f452018-10-02 23:27:21 -07001418 mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
1419 mp->context = ctx->context;
1420
1421 mp->sw_if_index = ntohl (sw_if_index);
1422 ip_prefix_encode (pfx, &mp->prefix);
1423
1424 vl_api_send_msg (ctx->reg, (u8 *) mp);
1425
1426 return 1;
1427}
1428
1429static void
1430vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t *
1431 mp)
1432{
1433 vl_api_registration_t *reg;
1434
1435 reg = vl_api_client_index_to_registration (mp->client_index);
1436 if (!reg)
1437 return;
1438
1439 ip_container_proxy_walk_ctx_t ctx = {
1440 .context = mp->context,
1441 .reg = reg,
1442 };
1443
1444 ip_container_proxy_walk (ip_container_proxy_send_details, &ctx);
1445}
1446
Neale Rannsb8d44812017-11-10 06:53:54 -08001447static void
1448vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1449{
1450 int rv = 0;
1451 vl_api_ioam_enable_reply_t *rmp;
1452 clib_error_t *error;
1453
1454 /* Ignoring the profile id as currently a single profile
1455 * is supported */
1456 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1457 mp->seqno, mp->analyse);
1458 if (error)
1459 {
1460 clib_error_report (error);
1461 rv = clib_error_get_code (error);
1462 }
1463
1464 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1465}
1466
1467static void
1468vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1469{
1470 int rv = 0;
1471 vl_api_ioam_disable_reply_t *rmp;
1472 clib_error_t *error;
1473
1474 error = clear_ioam_rewrite_fn ();
1475 if (error)
1476 {
1477 clib_error_report (error);
1478 rv = clib_error_get_code (error);
1479 }
1480
1481 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1482}
1483
1484static void
1485 vl_api_ip_source_and_port_range_check_add_del_t_handler
1486 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1487{
1488 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1489 int rv = 0;
1490
Neale Rannsb8d44812017-11-10 06:53:54 -08001491 u8 is_add = mp->is_add;
Neale Ranns37029302018-08-10 05:30:06 -07001492 fib_prefix_t pfx;
Neale Rannsb8d44812017-11-10 06:53:54 -08001493 u16 *low_ports = 0;
1494 u16 *high_ports = 0;
1495 u32 vrf_id;
1496 u16 tmp_low, tmp_high;
1497 u8 num_ranges;
1498 int i;
1499
Neale Ranns37029302018-08-10 05:30:06 -07001500 ip_prefix_decode (&mp->prefix, &pfx);
1501
Neale Rannsb8d44812017-11-10 06:53:54 -08001502 // Validate port range
1503 num_ranges = mp->number_of_ranges;
1504 if (num_ranges > 32)
1505 { // This is size of array in VPE.API
1506 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1507 goto reply;
1508 }
1509
1510 vec_reset_length (low_ports);
1511 vec_reset_length (high_ports);
1512
1513 for (i = 0; i < num_ranges; i++)
1514 {
1515 tmp_low = mp->low_ports[i];
1516 tmp_high = mp->high_ports[i];
1517 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1518 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1519 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1520 {
1521 rv = VNET_API_ERROR_INVALID_VALUE;
1522 goto reply;
1523 }
1524 vec_add1 (low_ports, tmp_low);
1525 vec_add1 (high_ports, tmp_high + 1);
1526 }
1527
Neale Rannsb8d44812017-11-10 06:53:54 -08001528 vrf_id = ntohl (mp->vrf_id);
1529
1530 if (vrf_id < 1)
1531 {
1532 rv = VNET_API_ERROR_INVALID_VALUE;
1533 goto reply;
1534 }
1535
1536
Neale Ranns37029302018-08-10 05:30:06 -07001537 if (FIB_PROTOCOL_IP6 == pfx.fp_proto)
Neale Rannsb8d44812017-11-10 06:53:54 -08001538 {
Neale Ranns37029302018-08-10 05:30:06 -07001539 rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6,
1540 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001541 vrf_id,
1542 low_ports,
1543 high_ports, is_add);
1544 }
1545 else
1546 {
Neale Ranns37029302018-08-10 05:30:06 -07001547 rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4,
1548 pfx.fp_len,
Neale Rannsb8d44812017-11-10 06:53:54 -08001549 vrf_id,
1550 low_ports,
1551 high_ports, is_add);
1552 }
1553
1554reply:
1555 vec_free (low_ports);
1556 vec_free (high_ports);
1557 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1558}
1559
1560static void
1561 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1562 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
1563{
1564 vlib_main_t *vm = vlib_get_main ();
1565 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
1566 ip4_main_t *im = &ip4_main;
1567 int rv;
1568 u32 sw_if_index;
1569 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1570 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1571 uword *p = 0;
1572 int i;
1573
1574 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
1575 ntohl (mp->tcp_out_vrf_id);
1576 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
1577 ntohl (mp->udp_out_vrf_id);
1578 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
1579 ntohl (mp->tcp_in_vrf_id);
1580 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
1581 ntohl (mp->udp_in_vrf_id);
1582
1583
1584 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
1585 {
1586 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
1587 {
1588 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
1589
1590 if (p == 0)
1591 {
1592 rv = VNET_API_ERROR_INVALID_VALUE;
1593 goto reply;
1594 }
1595
1596 fib_index[i] = p[0];
1597 }
1598 else
1599 fib_index[i] = ~0;
1600 }
1601 sw_if_index = ntohl (mp->sw_if_index);
1602
1603 VALIDATE_SW_IF_INDEX (mp);
1604
1605 rv =
1606 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
1607 mp->is_add);
1608
1609 BAD_SW_IF_INDEX_LABEL;
1610reply:
1611
1612 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
1613}
1614
Chore3460b012018-11-28 10:53:11 +03301615typedef union
1616{
1617 u32 fib_index;
1618} ip4_source_check_config_t;
1619
1620static void
1621 vl_api_ip_source_check_interface_add_del_t_handler
1622 (vl_api_ip_source_check_interface_add_del_t * mp)
1623{
1624 vl_api_ip_source_check_interface_add_del_reply_t *rmp;
1625 int rv;
1626 u32 sw_if_index = ntohl (mp->sw_if_index);
1627 u8 is_add = mp->is_add;
1628 char *feature_name =
1629 mp->loose ? "ip4-source-check-via-any" : "ip4-source-check-via-rx";
1630
1631 ip4_source_check_config_t config;
1632
1633 VALIDATE_SW_IF_INDEX (mp);
1634
1635 config.fib_index =
1636 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index);
1637 rv =
1638 vnet_feature_enable_disable ("ip4-unicast", feature_name, sw_if_index,
1639 is_add, &config, sizeof (config));
1640 BAD_SW_IF_INDEX_LABEL;
1641
1642 REPLY_MACRO (VL_API_IP_SOURCE_CHECK_INTERFACE_ADD_DEL_REPLY);
1643}
1644
Neale Rannsb8d44812017-11-10 06:53:54 -08001645#define IP4_ARP_EVENT 3
1646#define IP6_ND_EVENT 4
1647
Neale Rannsb8d44812017-11-10 06:53:54 -08001648static vlib_node_registration_t ip_resolver_process_node;
1649
Neale Ranns37029302018-08-10 05:30:06 -07001650static int
1651arp_change_delete_callback (u32 pool_index,
1652 const mac_address_t * mac,
1653 u32 sw_if_index, const ip4_address_t * address)
1654{
1655 vpe_api_main_t *am = &vpe_api_main;
1656
1657 if (pool_is_free_index (am->arp_events, pool_index))
1658 return 1;
1659
1660 pool_put_index (am->arp_events, pool_index);
1661 return 0;
1662}
1663
Neale Rannsb8d44812017-11-10 06:53:54 -08001664static void
1665handle_ip4_arp_event (u32 pool_index)
1666{
1667 vpe_api_main_t *vam = &vpe_api_main;
1668 vnet_main_t *vnm = vam->vnet_main;
1669 vlib_main_t *vm = vam->vlib_main;
1670 vl_api_ip4_arp_event_t *event;
1671 vl_api_ip4_arp_event_t *mp;
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001672 vl_api_registration_t *reg;
Neale Rannsb8d44812017-11-10 06:53:54 -08001673
1674 /* Client can cancel, die, etc. */
1675 if (pool_is_free_index (vam->arp_events, pool_index))
1676 return;
1677
1678 event = pool_elt_at_index (vam->arp_events, pool_index);
1679
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001680 reg = vl_api_client_index_to_registration (event->client_index);
1681 if (!reg)
Neale Rannsb8d44812017-11-10 06:53:54 -08001682 {
1683 (void) vnet_add_del_ip4_arp_change_event
1684 (vnm, arp_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07001685 event->pid, event->ip,
Neale Rannsb8d44812017-11-10 06:53:54 -08001686 ip_resolver_process_node.index, IP4_ARP_EVENT,
1687 ~0 /* pool index, notused */ , 0 /* is_add */ );
1688 return;
1689 }
1690
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001691 if (vl_api_can_send_msg (reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08001692 {
1693 mp = vl_msg_api_alloc (sizeof (*mp));
1694 clib_memcpy (mp, event, sizeof (*mp));
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001695 vl_api_send_msg (reg, (u8 *) mp);
Neale Rannsb8d44812017-11-10 06:53:54 -08001696 }
1697 else
1698 {
1699 static f64 last_time;
1700 /*
1701 * Throttle syslog msgs.
1702 * It's pretty tempting to just revoke the registration...
1703 */
1704 if (vlib_time_now (vm) > last_time + 10.0)
1705 {
1706 clib_warning ("arp event for %U to pid %d: queue stuffed!",
Neale Ranns37029302018-08-10 05:30:06 -07001707 format_ip4_address, event->ip, event->pid);
Neale Rannsb8d44812017-11-10 06:53:54 -08001708 last_time = vlib_time_now (vm);
1709 }
1710 }
1711}
1712
Neale Ranns37029302018-08-10 05:30:06 -07001713static int
1714nd_change_delete_callback (u32 pool_index,
1715 const mac_address_t * mac,
1716 u32 sw_if_index, const ip6_address_t * addr)
1717{
1718 vpe_api_main_t *am = &vpe_api_main;
1719
1720 if (pool_is_free_index (am->nd_events, pool_index))
1721 return 1;
1722
1723 pool_put_index (am->nd_events, pool_index);
1724 return 0;
1725}
1726
Neale Rannsf12dad62018-06-04 18:41:24 -07001727static void
Neale Rannsb8d44812017-11-10 06:53:54 -08001728handle_ip6_nd_event (u32 pool_index)
1729{
1730 vpe_api_main_t *vam = &vpe_api_main;
1731 vnet_main_t *vnm = vam->vnet_main;
1732 vlib_main_t *vm = vam->vlib_main;
1733 vl_api_ip6_nd_event_t *event;
1734 vl_api_ip6_nd_event_t *mp;
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001735 vl_api_registration_t *reg;
Neale Rannsb8d44812017-11-10 06:53:54 -08001736
1737 /* Client can cancel, die, etc. */
1738 if (pool_is_free_index (vam->nd_events, pool_index))
1739 return;
1740
1741 event = pool_elt_at_index (vam->nd_events, pool_index);
1742
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001743 reg = vl_api_client_index_to_registration (event->client_index);
1744 if (!reg)
Neale Rannsb8d44812017-11-10 06:53:54 -08001745 {
1746 (void) vnet_add_del_ip6_nd_change_event
1747 (vnm, nd_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07001748 event->pid, event->ip,
Neale Rannsb8d44812017-11-10 06:53:54 -08001749 ip_resolver_process_node.index, IP6_ND_EVENT,
1750 ~0 /* pool index, notused */ , 0 /* is_add */ );
1751 return;
1752 }
1753
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001754 if (vl_api_can_send_msg (reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08001755 {
1756 mp = vl_msg_api_alloc (sizeof (*mp));
1757 clib_memcpy (mp, event, sizeof (*mp));
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001758 vl_api_send_msg (reg, (u8 *) mp);
Neale Rannsb8d44812017-11-10 06:53:54 -08001759 }
1760 else
1761 {
1762 static f64 last_time;
1763 /*
1764 * Throttle syslog msgs.
1765 * It's pretty tempting to just revoke the registration...
1766 */
1767 if (vlib_time_now (vm) > last_time + 10.0)
1768 {
1769 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
Neale Ranns37029302018-08-10 05:30:06 -07001770 format_ip6_address, event->ip, event->pid);
Neale Rannsb8d44812017-11-10 06:53:54 -08001771 last_time = vlib_time_now (vm);
1772 }
1773 }
1774}
1775
1776static uword
1777resolver_process (vlib_main_t * vm,
1778 vlib_node_runtime_t * rt, vlib_frame_t * f)
1779{
1780 volatile f64 timeout = 100.0;
1781 volatile uword *event_data = 0;
1782
1783 while (1)
1784 {
1785 vlib_process_wait_for_event_or_clock (vm, timeout);
1786
1787 uword event_type =
1788 vlib_process_get_events (vm, (uword **) & event_data);
1789
1790 int i;
1791 switch (event_type)
1792 {
1793 case IP4_ARP_EVENT:
1794 for (i = 0; i < vec_len (event_data); i++)
1795 handle_ip4_arp_event (event_data[i]);
1796 break;
1797
1798 case IP6_ND_EVENT:
1799 for (i = 0; i < vec_len (event_data); i++)
1800 handle_ip6_nd_event (event_data[i]);
1801 break;
1802
1803 case ~0: /* timeout */
1804 break;
1805 }
1806
1807 vec_reset_length (event_data);
1808 }
1809 return 0; /* or not */
1810}
1811
1812/* *INDENT-OFF* */
1813VLIB_REGISTER_NODE (ip_resolver_process_node,static) = {
1814 .function = resolver_process,
1815 .type = VLIB_NODE_TYPE_PROCESS,
1816 .name = "ip-route-resolver-process",
1817};
1818/* *INDENT-ON* */
1819
1820static int
Neale Ranns37029302018-08-10 05:30:06 -07001821nd_change_data_callback (u32 pool_index, const mac_address_t * new_mac,
1822 u32 sw_if_index, const ip6_address_t * address)
Neale Rannsb8d44812017-11-10 06:53:54 -08001823{
1824 vpe_api_main_t *am = &vpe_api_main;
1825 vl_api_ip6_nd_event_t *event;
1826
1827 if (pool_is_free_index (am->nd_events, pool_index))
1828 return 1;
1829
1830 event = pool_elt_at_index (am->nd_events, pool_index);
Neale Ranns37029302018-08-10 05:30:06 -07001831 if (ethernet_mac_address_equal (event->mac, new_mac->bytes) &&
Neale Rannsb8d44812017-11-10 06:53:54 -08001832 sw_if_index == ntohl (event->sw_if_index))
1833 {
1834 return 1;
1835 }
1836
Neale Ranns37029302018-08-10 05:30:06 -07001837 mac_address_encode (new_mac, event->mac);
Neale Rannsb8d44812017-11-10 06:53:54 -08001838 event->sw_if_index = htonl (sw_if_index);
1839 return 0;
1840}
1841
Neale Rannsb8d44812017-11-10 06:53:54 -08001842static vlib_node_registration_t wc_arp_process_node;
1843
1844enum
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001845{ WC_ARP_REPORT, WC_ND_REPORT, RA_REPORT, REPORT_MAX };
Neale Rannsb8d44812017-11-10 06:53:54 -08001846
1847static uword
1848wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1849{
Jim Thompsonf324dec2019-04-08 03:22:21 -05001850 /* These cross the longjmp boundary (vlib_process_wait_for_event)
Neale Rannsb8d44812017-11-10 06:53:54 -08001851 * and need to be volatile - to prevent them from being optimized into
1852 * a register - which could change during suspension */
1853
1854 volatile wc_arp_report_t arp_prev = { 0 };
1855 volatile wc_nd_report_t nd_prev = { 0 };
1856 volatile f64 last_arp = vlib_time_now (vm);
1857 volatile f64 last_nd = vlib_time_now (vm);
1858
1859 while (1)
1860 {
1861 vlib_process_wait_for_event (vm);
1862 uword event_type = WC_ARP_REPORT;
1863 void *event_data = vlib_process_get_event_data (vm, &event_type);
1864
1865 f64 now = vlib_time_now (vm);
1866 int i;
1867 if (event_type == WC_ARP_REPORT)
1868 {
1869 wc_arp_report_t *arp_events = event_data;
1870 for (i = 0; i < vec_len (arp_events); i++)
1871 {
Neale Ranns37029302018-08-10 05:30:06 -07001872 /* discard dup event - cast away volatile */
1873 if (arp_prev.ip.as_u32 == arp_events[i].ip.as_u32 &&
1874 mac_address_equal ((const mac_address_t *) &arp_prev.mac,
1875 &arp_events[i].mac) &&
Neale Rannsb8d44812017-11-10 06:53:54 -08001876 arp_prev.sw_if_index == arp_events[i].sw_if_index &&
1877 (now - last_arp) < 10.0)
1878 {
1879 continue;
1880 }
1881 arp_prev = arp_events[i];
1882 last_arp = now;
1883 vpe_client_registration_t *reg;
1884 /* *INDENT-OFF* */
1885 pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations,
1886 ({
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001887 vl_api_registration_t *vl_reg;
1888 vl_reg = vl_api_client_index_to_registration (reg->client_index);
Chris Luke30684ac2018-03-29 12:56:58 -07001889 ASSERT (vl_reg != NULL);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001890 if (reg && vl_api_can_send_msg (vl_reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08001891 {
1892 vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event);
Dave Barachb7b92992018-10-17 10:38:51 -04001893 clib_memset (event, 0, sizeof *event);
Neale Rannsb8d44812017-11-10 06:53:54 -08001894 event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
1895 event->client_index = reg->client_index;
1896 event->pid = reg->client_pid;
1897 event->mac_ip = 1;
Neale Ranns37029302018-08-10 05:30:06 -07001898 ip4_address_encode(&arp_events[i].ip, event->ip);
Neale Rannsb8d44812017-11-10 06:53:54 -08001899 event->sw_if_index = htonl(arp_events[i].sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07001900 mac_address_encode(&arp_events[i].mac, event->mac);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001901 vl_api_send_msg (vl_reg, (u8 *) event);
Neale Rannsb8d44812017-11-10 06:53:54 -08001902 }
1903 }));
1904 /* *INDENT-ON* */
1905 }
1906 }
1907 else if (event_type == WC_ND_REPORT)
1908 {
1909 wc_nd_report_t *nd_events = event_data;
1910 for (i = 0; i < vec_len (nd_events); i++)
1911 {
Neale Ranns37029302018-08-10 05:30:06 -07001912 /* discard dup event - cast away volatile */
1913 if (ip6_address_is_equal ((const ip6_address_t *) &nd_prev.ip6,
1914 &nd_events[i].ip6)
1915 && mac_address_equal ((const mac_address_t *) &nd_prev.mac,
1916 &nd_events[i].mac)
Neale Rannsb8d44812017-11-10 06:53:54 -08001917 && nd_prev.sw_if_index == nd_events[i].sw_if_index
1918 && (now - last_nd) < 10.0)
1919 {
1920 continue;
1921 }
1922 nd_prev = nd_events[i];
1923 last_nd = now;
1924 vpe_client_registration_t *reg;
1925 /* *INDENT-OFF* */
1926 pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations,
1927 ({
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001928 vl_api_registration_t *vl_reg;
1929 vl_reg = vl_api_client_index_to_registration (reg->client_index);
1930 if (vl_reg && vl_api_can_send_msg (vl_reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08001931 {
1932 vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event);
Dave Barachb7b92992018-10-17 10:38:51 -04001933 clib_memset (event, 0, sizeof *event);
Neale Rannsb8d44812017-11-10 06:53:54 -08001934 event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT);
1935 event->client_index = reg->client_index;
1936 event->pid = reg->client_pid;
1937 event->mac_ip = 1;
Neale Ranns37029302018-08-10 05:30:06 -07001938 ip6_address_encode(&nd_events[i].ip6, event->ip);
Neale Rannsb8d44812017-11-10 06:53:54 -08001939 event->sw_if_index = htonl(nd_events[i].sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07001940 mac_address_encode(&nd_events[i].mac, event->mac);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001941 vl_api_send_msg (vl_reg, (u8 *) event);
Neale Rannsb8d44812017-11-10 06:53:54 -08001942 }
1943 }));
1944 /* *INDENT-ON* */
1945 }
1946 }
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001947 else if (event_type == RA_REPORT)
1948 {
1949 ra_report_t *ra_events = event_data;
1950 for (i = 0; i < vec_len (ra_events); i++)
1951 {
Juraj Sloboda52574522018-05-03 10:03:50 +02001952 ip6_neighbor_public_main_t *npm = &ip6_neighbor_public_main;
1953 call_ip6_neighbor_callbacks (&ra_events[i],
1954 npm->ra_report_functions);
1955
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001956 vpe_client_registration_t *reg;
1957 /* *INDENT-OFF* */
1958 pool_foreach(reg, vpe_api_main.ip6_ra_events_registrations,
1959 ({
1960 vl_api_registration_t *vl_reg;
1961 vl_reg =
1962 vl_api_client_index_to_registration (reg->client_index);
1963 if (vl_reg && vl_api_can_send_msg (vl_reg))
1964 {
1965 u32 event_size =
1966 sizeof (vl_api_ip6_ra_event_t) +
1967 vec_len (ra_events[i].prefixes) *
1968 sizeof (vl_api_ip6_ra_prefix_info_t);
1969 vl_api_ip6_ra_event_t *event =
1970 vl_msg_api_alloc (event_size);
Dave Barachb7b92992018-10-17 10:38:51 -04001971 clib_memset (event, 0, event_size);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001972 event->_vl_msg_id = htons (VL_API_IP6_RA_EVENT);
1973 event->client_index = reg->client_index;
1974 event->pid = reg->client_pid;
1975
1976 event->sw_if_index = clib_host_to_net_u32 (ra_events[i].sw_if_index);
1977
Neale Ranns37029302018-08-10 05:30:06 -07001978 ip6_address_encode (&ra_events[i].router_address,
1979 event->router_addr);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001980
1981 event->current_hop_limit = ra_events[i].current_hop_limit;
1982 event->flags = ra_events[i].flags;
1983 event->router_lifetime_in_sec =
1984 clib_host_to_net_u16 (ra_events
1985 [i].router_lifetime_in_sec);
1986 event->neighbor_reachable_time_in_msec =
1987 clib_host_to_net_u32 (ra_events
1988 [i].neighbor_reachable_time_in_msec);
1989 event->time_in_msec_between_retransmitted_neighbor_solicitations
1990 =
1991 clib_host_to_net_u32 (ra_events
1992 [i].time_in_msec_between_retransmitted_neighbor_solicitations);
1993
1994 event->n_prefixes =
1995 clib_host_to_net_u32 (vec_len (ra_events[i].prefixes));
1996 vl_api_ip6_ra_prefix_info_t *prefix =
1997 (typeof (prefix)) event->prefixes;
1998 u32 j;
1999 for (j = 0; j < vec_len (ra_events[i].prefixes); j++)
2000 {
2001 ra_report_prefix_info_t *info =
2002 &ra_events[i].prefixes[j];
Neale Ranns37029302018-08-10 05:30:06 -07002003 ip_prefix_encode(&info->prefix, &prefix->prefix);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002004 prefix->flags = info->flags;
2005 prefix->valid_time =
2006 clib_host_to_net_u32 (info->valid_time);
2007 prefix->preferred_time =
2008 clib_host_to_net_u32 (info->preferred_time);
2009 prefix++;
2010 }
2011
2012 vl_api_send_msg (vl_reg, (u8 *) event);
2013 }
2014 }));
Juraj Slobodad7f58cc2018-07-27 11:23:14 +02002015 /* *INDENT-ON* */
2016 vec_free (ra_events[i].prefixes);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002017 }
2018 }
Neale Rannsb8d44812017-11-10 06:53:54 -08002019 vlib_process_put_event_data (vm, event_data);
2020 }
2021
2022 return 0;
2023}
2024
2025/* *INDENT-OFF* */
2026VLIB_REGISTER_NODE (wc_arp_process_node,static) = {
2027 .function = wc_arp_process,
2028 .type = VLIB_NODE_TYPE_PROCESS,
2029 .name = "wildcard-ip4-arp-publisher-process",
2030};
2031/* *INDENT-ON* */
2032
2033static int
Neale Ranns37029302018-08-10 05:30:06 -07002034arp_change_data_callback (u32 pool_index,
2035 const mac_address_t * mac,
2036 u32 sw_if_index, const ip4_address_t * address)
Neale Rannsb8d44812017-11-10 06:53:54 -08002037{
2038 vpe_api_main_t *am = &vpe_api_main;
2039 vl_api_ip4_arp_event_t *event;
2040
2041 if (pool_is_free_index (am->arp_events, pool_index))
2042 return 1;
2043
2044 event = pool_elt_at_index (am->arp_events, pool_index);
Neale Ranns37029302018-08-10 05:30:06 -07002045 if (ethernet_mac_address_equal (event->mac, mac->bytes) &&
Neale Rannsb8d44812017-11-10 06:53:54 -08002046 sw_if_index == ntohl (event->sw_if_index))
2047 {
2048 return 1;
2049 }
2050
Neale Ranns37029302018-08-10 05:30:06 -07002051 mac_address_encode (mac, event->mac);
Neale Rannsb8d44812017-11-10 06:53:54 -08002052 event->sw_if_index = htonl (sw_if_index);
2053 return 0;
2054}
2055
2056static void
2057vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
2058{
2059 vpe_api_main_t *am = &vpe_api_main;
2060 vnet_main_t *vnm = vnet_get_main ();
2061 vl_api_want_ip4_arp_events_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07002062 ip4_address_t ip;
Neale Rannsb8d44812017-11-10 06:53:54 -08002063 int rv = 0;
2064
Neale Ranns37029302018-08-10 05:30:06 -07002065 ip4_address_decode (mp->ip, &ip);
2066
2067 if (ip.as_u32 == 0)
Neale Rannsb8d44812017-11-10 06:53:54 -08002068 {
2069 uword *p =
2070 hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index);
2071 vpe_client_registration_t *rp;
2072 if (p)
2073 {
2074 if (mp->enable_disable)
2075 {
2076 clib_warning ("pid %d: already enabled...", mp->pid);
2077 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2078 goto reply;
2079 }
2080 else
2081 {
2082 rp =
2083 pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
2084 pool_put (am->wc_ip4_arp_events_registrations, rp);
2085 hash_unset (am->wc_ip4_arp_events_registration_hash,
2086 mp->client_index);
2087 if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002088 wc_arp_set_publisher_node (~0, REPORT_MAX);
Neale Rannsb8d44812017-11-10 06:53:54 -08002089 goto reply;
2090 }
2091 }
2092 if (mp->enable_disable == 0)
2093 {
2094 clib_warning ("pid %d: already disabled...", mp->pid);
2095 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2096 goto reply;
2097 }
2098 pool_get (am->wc_ip4_arp_events_registrations, rp);
2099 rp->client_index = mp->client_index;
2100 rp->client_pid = mp->pid;
2101 hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index,
2102 rp - am->wc_ip4_arp_events_registrations);
2103 wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT);
2104 goto reply;
2105 }
2106
2107 if (mp->enable_disable)
2108 {
2109 vl_api_ip4_arp_event_t *event;
2110 pool_get (am->arp_events, event);
2111 rv = vnet_add_del_ip4_arp_change_event
2112 (vnm, arp_change_data_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002113 mp->pid, mp->ip /* addr, in net byte order */ ,
Neale Rannsb8d44812017-11-10 06:53:54 -08002114 ip_resolver_process_node.index,
2115 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
2116
2117 if (rv)
2118 {
2119 pool_put (am->arp_events, event);
2120 goto reply;
2121 }
Dave Barachb7b92992018-10-17 10:38:51 -04002122 clib_memset (event, 0, sizeof (*event));
Neale Rannsb8d44812017-11-10 06:53:54 -08002123
2124 /* Python API expects events to have no context */
2125 event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
2126 event->client_index = mp->client_index;
Neale Ranns37029302018-08-10 05:30:06 -07002127 memcpy (event->ip, mp->ip, 4);
Neale Rannsb8d44812017-11-10 06:53:54 -08002128 event->pid = mp->pid;
Neale Ranns37029302018-08-10 05:30:06 -07002129 if (ip.as_u32 == 0)
Neale Rannsb8d44812017-11-10 06:53:54 -08002130 event->mac_ip = 1;
2131 }
2132 else
2133 {
2134 rv = vnet_add_del_ip4_arp_change_event
2135 (vnm, arp_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002136 mp->pid, mp->ip /* addr, in net byte order */ ,
Neale Rannsb8d44812017-11-10 06:53:54 -08002137 ip_resolver_process_node.index,
2138 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
2139 }
2140reply:
2141 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
2142}
2143
Neale Rannsf12dad62018-06-04 18:41:24 -07002144static clib_error_t *
2145want_ip4_arp_events_reaper (u32 client_index)
2146{
2147 vpe_client_registration_t *rp;
2148 vl_api_ip4_arp_event_t *event;
2149 u32 *to_delete, *event_id;
2150 vpe_api_main_t *am;
2151 vnet_main_t *vnm;
2152 uword *p;
2153
2154 am = &vpe_api_main;
2155 vnm = vnet_get_main ();
2156 to_delete = NULL;
2157
2158 /* clear out all of its pending resolutions */
2159 /* *INDENT-OFF* */
2160 pool_foreach(event, am->arp_events,
2161 ({
2162 if (event->client_index == client_index)
2163 {
2164 vec_add1(to_delete, event - am->arp_events);
2165 }
2166 }));
2167 /* *INDENT-ON* */
2168
2169 vec_foreach (event_id, to_delete)
2170 {
2171 event = pool_elt_at_index (am->arp_events, *event_id);
2172 vnet_add_del_ip4_arp_change_event
2173 (vnm, arp_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002174 event->pid, event->ip,
Neale Rannsf12dad62018-06-04 18:41:24 -07002175 ip_resolver_process_node.index, IP4_ARP_EVENT,
2176 ~0 /* pool index, notused */ , 0 /* is_add */ );
2177 }
2178 vec_free (to_delete);
2179
2180 /* remove from the registration hash */
2181 p = hash_get (am->wc_ip4_arp_events_registration_hash, client_index);
2182
2183 if (p)
2184 {
2185 rp = pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
2186 pool_put (am->wc_ip4_arp_events_registrations, rp);
2187 hash_unset (am->wc_ip4_arp_events_registration_hash, client_index);
2188 if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
2189 wc_arp_set_publisher_node (~0, REPORT_MAX);
2190 }
2191 return (NULL);
2192}
2193
2194VL_MSG_API_REAPER_FUNCTION (want_ip4_arp_events_reaper);
2195
Neale Rannsb8d44812017-11-10 06:53:54 -08002196static void
2197vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
2198{
2199 vpe_api_main_t *am = &vpe_api_main;
2200 vnet_main_t *vnm = vnet_get_main ();
2201 vl_api_want_ip6_nd_events_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07002202 ip6_address_t ip6;
Neale Rannsb8d44812017-11-10 06:53:54 -08002203 int rv = 0;
2204
Neale Ranns37029302018-08-10 05:30:06 -07002205 ip6_address_decode (mp->ip, &ip6);
2206
2207 if (ip6_address_is_zero (&ip6))
Neale Rannsb8d44812017-11-10 06:53:54 -08002208 {
2209 uword *p =
2210 hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index);
2211 vpe_client_registration_t *rp;
2212 if (p)
2213 {
2214 if (mp->enable_disable)
2215 {
2216 clib_warning ("pid %d: already enabled...", mp->pid);
2217 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2218 goto reply;
2219 }
2220 else
2221 {
2222 rp =
2223 pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
2224 pool_put (am->wc_ip6_nd_events_registrations, rp);
2225 hash_unset (am->wc_ip6_nd_events_registration_hash,
2226 mp->client_index);
2227 if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002228 wc_nd_set_publisher_node (~0, REPORT_MAX);
Neale Rannsb8d44812017-11-10 06:53:54 -08002229 goto reply;
2230 }
2231 }
2232 if (mp->enable_disable == 0)
2233 {
2234 clib_warning ("pid %d: already disabled...", mp->pid);
2235 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2236 goto reply;
2237 }
2238 pool_get (am->wc_ip6_nd_events_registrations, rp);
2239 rp->client_index = mp->client_index;
2240 rp->client_pid = mp->pid;
2241 hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index,
2242 rp - am->wc_ip6_nd_events_registrations);
2243 wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT);
2244 goto reply;
2245 }
2246
2247 if (mp->enable_disable)
2248 {
2249 vl_api_ip6_nd_event_t *event;
2250 pool_get (am->nd_events, event);
2251
2252 rv = vnet_add_del_ip6_nd_change_event
2253 (vnm, nd_change_data_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002254 mp->pid, &ip6,
Neale Rannsb8d44812017-11-10 06:53:54 -08002255 ip_resolver_process_node.index,
2256 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
2257
2258 if (rv)
2259 {
2260 pool_put (am->nd_events, event);
2261 goto reply;
2262 }
Dave Barachb7b92992018-10-17 10:38:51 -04002263 clib_memset (event, 0, sizeof (*event));
Neale Rannsb8d44812017-11-10 06:53:54 -08002264
2265 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
2266 event->client_index = mp->client_index;
Neale Ranns37029302018-08-10 05:30:06 -07002267 ip6_address_encode (&ip6, event->ip);
Neale Rannsb8d44812017-11-10 06:53:54 -08002268 event->pid = mp->pid;
2269 }
2270 else
2271 {
2272 rv = vnet_add_del_ip6_nd_change_event
2273 (vnm, nd_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002274 mp->pid, &ip6 /* addr, in net byte order */ ,
Neale Rannsb8d44812017-11-10 06:53:54 -08002275 ip_resolver_process_node.index,
2276 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
2277 }
2278reply:
2279 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
2280}
2281
Neale Rannsf12dad62018-06-04 18:41:24 -07002282static clib_error_t *
2283want_ip6_nd_events_reaper (u32 client_index)
2284{
2285
2286 vpe_client_registration_t *rp;
2287 vl_api_ip6_nd_event_t *event;
2288 u32 *to_delete, *event_id;
2289 vpe_api_main_t *am;
2290 vnet_main_t *vnm;
2291 uword *p;
2292
2293 am = &vpe_api_main;
2294 vnm = vnet_get_main ();
2295 to_delete = NULL;
2296
2297 /* clear out all of its pending resolutions */
2298 /* *INDENT-OFF* */
2299 pool_foreach(event, am->nd_events,
2300 ({
2301 if (event->client_index == client_index)
2302 {
2303 vec_add1(to_delete, event - am->nd_events);
2304 }
2305 }));
2306 /* *INDENT-ON* */
2307
2308 vec_foreach (event_id, to_delete)
2309 {
2310 event = pool_elt_at_index (am->nd_events, *event_id);
2311 vnet_add_del_ip6_nd_change_event
2312 (vnm, nd_change_delete_callback,
Neale Ranns37029302018-08-10 05:30:06 -07002313 event->pid, event->ip,
Neale Rannsf12dad62018-06-04 18:41:24 -07002314 ip_resolver_process_node.index, IP6_ND_EVENT,
2315 ~0 /* pool index, notused */ , 0 /* is_add */ );
2316 }
2317 vec_free (to_delete);
2318
2319 /* remove from the registration hash */
2320 p = hash_get (am->wc_ip6_nd_events_registration_hash, client_index);
2321
2322 if (p)
2323 {
2324 rp = pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
2325 pool_put (am->wc_ip6_nd_events_registrations, rp);
2326 hash_unset (am->wc_ip6_nd_events_registration_hash, client_index);
2327 if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
2328 wc_nd_set_publisher_node (~0, REPORT_MAX);
2329 }
2330 return (NULL);
2331}
2332
2333VL_MSG_API_REAPER_FUNCTION (want_ip6_nd_events_reaper);
2334
Neale Rannsb8d44812017-11-10 06:53:54 -08002335static void
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002336vl_api_want_ip6_ra_events_t_handler (vl_api_want_ip6_ra_events_t * mp)
2337{
2338 vpe_api_main_t *am = &vpe_api_main;
2339 vl_api_want_ip6_ra_events_reply_t *rmp;
2340 int rv = 0;
2341
2342 uword *p = hash_get (am->ip6_ra_events_registration_hash, mp->client_index);
2343 vpe_client_registration_t *rp;
2344 if (p)
2345 {
2346 if (mp->enable_disable)
2347 {
2348 clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
2349 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2350 goto reply;
2351 }
2352 else
2353 {
2354 rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
2355 pool_put (am->ip6_ra_events_registrations, rp);
2356 hash_unset (am->ip6_ra_events_registration_hash, mp->client_index);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002357 goto reply;
2358 }
2359 }
2360 if (mp->enable_disable == 0)
2361 {
2362 clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
2363 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2364 goto reply;
2365 }
2366 pool_get (am->ip6_ra_events_registrations, rp);
2367 rp->client_index = mp->client_index;
2368 rp->client_pid = ntohl (mp->pid);
2369 hash_set (am->ip6_ra_events_registration_hash, rp->client_index,
2370 rp - am->ip6_ra_events_registrations);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002371
2372reply:
2373 REPLY_MACRO (VL_API_WANT_IP6_RA_EVENTS_REPLY);
2374}
2375
Neale Rannsf12dad62018-06-04 18:41:24 -07002376static clib_error_t *
2377want_ip6_ra_events_reaper (u32 client_index)
2378{
2379 vpe_api_main_t *am = &vpe_api_main;
2380 vpe_client_registration_t *rp;
2381 uword *p;
2382
2383 p = hash_get (am->ip6_ra_events_registration_hash, client_index);
2384
2385 if (p)
2386 {
2387 rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
2388 pool_put (am->ip6_ra_events_registrations, rp);
2389 hash_unset (am->ip6_ra_events_registration_hash, client_index);
2390 }
2391 return (NULL);
2392}
2393
2394VL_MSG_API_REAPER_FUNCTION (want_ip6_ra_events_reaper);
2395
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002396static void
Neale Rannsb8d44812017-11-10 06:53:54 -08002397vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2398{
2399 vl_api_proxy_arp_add_del_reply_t *rmp;
Neale Ranns37029302018-08-10 05:30:06 -07002400 ip4_address_t lo, hi;
Neale Rannsb8d44812017-11-10 06:53:54 -08002401 u32 fib_index;
2402 int rv;
Neale Rannsb8d44812017-11-10 06:53:54 -08002403
Neale Ranns37029302018-08-10 05:30:06 -07002404 fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->proxy.table_id));
Neale Rannsb8d44812017-11-10 06:53:54 -08002405
Neale Ranns37029302018-08-10 05:30:06 -07002406 if (~0 == fib_index)
Neale Rannsb8d44812017-11-10 06:53:54 -08002407 {
2408 rv = VNET_API_ERROR_NO_SUCH_FIB;
2409 goto out;
2410 }
2411
Neale Ranns37029302018-08-10 05:30:06 -07002412 ip4_address_decode (mp->proxy.low, &lo);
2413 ip4_address_decode (mp->proxy.hi, &hi);
Neale Rannsb8d44812017-11-10 06:53:54 -08002414
Neale Ranns37029302018-08-10 05:30:06 -07002415 rv = vnet_proxy_arp_add_del (&lo, &hi, fib_index, mp->is_add == 0);
Neale Rannsb8d44812017-11-10 06:53:54 -08002416
2417out:
Neale Rannsb8d44812017-11-10 06:53:54 -08002418 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2419}
2420
Neale Ranns0053de62018-05-22 08:40:52 -07002421typedef struct proxy_arp_walk_ctx_t_
2422{
2423 vl_api_registration_t *reg;
2424 u32 context;
2425} proxy_arp_walk_ctx_t;
2426
2427static walk_rc_t
2428send_proxy_arp_details (const ip4_address_t * lo_addr,
2429 const ip4_address_t * hi_addr,
2430 u32 fib_index, void *data)
2431{
2432 vl_api_proxy_arp_details_t *mp;
2433 proxy_arp_walk_ctx_t *ctx;
2434
2435 ctx = data;
2436
2437 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04002438 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns0053de62018-05-22 08:40:52 -07002439 mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_DETAILS);
2440 mp->context = ctx->context;
Neale Ranns37029302018-08-10 05:30:06 -07002441 mp->proxy.table_id = htonl (fib_index);
2442
2443 ip4_address_encode (lo_addr, mp->proxy.low);
2444 ip4_address_encode (hi_addr, mp->proxy.hi);
Neale Ranns0053de62018-05-22 08:40:52 -07002445
2446 vl_api_send_msg (ctx->reg, (u8 *) mp);
2447
2448 return (WALK_CONTINUE);
2449}
2450
2451static void
2452vl_api_proxy_arp_dump_t_handler (vl_api_proxy_arp_dump_t * mp)
2453{
2454 vl_api_registration_t *reg;
2455
2456 reg = vl_api_client_index_to_registration (mp->client_index);
2457 if (!reg)
2458 return;
2459
2460 proxy_arp_walk_ctx_t wctx = {
2461 .reg = reg,
2462 .context = mp->context,
2463 };
2464
2465 proxy_arp_walk (send_proxy_arp_details, &wctx);
2466}
2467
2468static walk_rc_t
Neale Ranns57e53bb2019-05-29 13:58:43 +00002469send_proxy_arp_intfc_details (u32 sw_if_index, void *data)
Neale Ranns0053de62018-05-22 08:40:52 -07002470{
2471 vl_api_proxy_arp_intfc_details_t *mp;
2472 proxy_arp_walk_ctx_t *ctx;
2473
Neale Ranns0053de62018-05-22 08:40:52 -07002474 ctx = data;
2475
2476 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04002477 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns0053de62018-05-22 08:40:52 -07002478 mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_INTFC_DETAILS);
2479 mp->context = ctx->context;
Neale Ranns57e53bb2019-05-29 13:58:43 +00002480 mp->sw_if_index = htonl (sw_if_index);
Neale Ranns0053de62018-05-22 08:40:52 -07002481
2482 vl_api_send_msg (ctx->reg, (u8 *) mp);
2483
2484 return (WALK_CONTINUE);
2485}
2486
2487static void
2488vl_api_proxy_arp_intfc_dump_t_handler (vl_api_proxy_arp_intfc_dump_t * mp)
2489{
2490 vl_api_registration_t *reg;
2491
2492 reg = vl_api_client_index_to_registration (mp->client_index);
2493 if (!reg)
2494 return;
2495
2496 proxy_arp_walk_ctx_t wctx = {
2497 .reg = reg,
2498 .context = mp->context,
2499 };
2500
Neale Ranns57e53bb2019-05-29 13:58:43 +00002501 proxy_arp_intfc_walk (send_proxy_arp_intfc_details, &wctx);
Neale Ranns0053de62018-05-22 08:40:52 -07002502}
2503
Neale Rannsb8d44812017-11-10 06:53:54 -08002504static void
2505 vl_api_proxy_arp_intfc_enable_disable_t_handler
2506 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2507{
2508 int rv = 0;
2509 vnet_main_t *vnm = vnet_get_main ();
2510 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2511
2512 VALIDATE_SW_IF_INDEX (mp);
2513
Neale Ranns57e53bb2019-05-29 13:58:43 +00002514 rv = vnet_proxy_arp_enable_disable (vnm,
2515 ntohl (mp->sw_if_index),
2516 mp->enable_disable);
Neale Rannsb8d44812017-11-10 06:53:54 -08002517
2518 BAD_SW_IF_INDEX_LABEL;
2519
2520 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2521}
2522
John Loc7b43042018-04-13 16:46:22 -04002523static void
2524vl_api_ip_probe_neighbor_t_handler (vl_api_ip_probe_neighbor_t * mp)
2525{
2526 int rv = 0;
2527 vlib_main_t *vm = vlib_get_main ();
2528 vl_api_ip_probe_neighbor_reply_t *rmp;
2529 clib_error_t *error;
Neale Ranns37029302018-08-10 05:30:06 -07002530 ip46_address_t dst;
2531 ip46_type_t itype;
John Loc7b43042018-04-13 16:46:22 -04002532
2533 VALIDATE_SW_IF_INDEX (mp);
2534
2535 u32 sw_if_index = ntohl (mp->sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -07002536 itype = ip_address_decode (&mp->dst, &dst);
John Loc7b43042018-04-13 16:46:22 -04002537
Neale Ranns37029302018-08-10 05:30:06 -07002538 if (IP46_TYPE_IP6 == itype)
2539 error = ip6_probe_neighbor (vm, &dst.ip6, sw_if_index, 0);
John Loc7b43042018-04-13 16:46:22 -04002540 else
Neale Ranns37029302018-08-10 05:30:06 -07002541 error = ip4_probe_neighbor (vm, &dst.ip4, sw_if_index, 0);
John Loc7b43042018-04-13 16:46:22 -04002542
2543 if (error)
2544 {
2545 clib_error_report (error);
2546 rv = clib_error_get_code (error);
2547 }
2548
2549 BAD_SW_IF_INDEX_LABEL;
2550
Ole Troanedfe2c02019-07-30 15:38:13 +02002551 REPLY_MACRO (VL_API_IP_PROBE_NEIGHBOR_REPLY);
John Loc7b43042018-04-13 16:46:22 -04002552}
2553
John Lo7f358b32018-04-28 01:19:24 -04002554static void
2555 vl_api_ip_scan_neighbor_enable_disable_t_handler
2556 (vl_api_ip_scan_neighbor_enable_disable_t * mp)
2557{
2558 int rv = 0;
2559 vl_api_ip_scan_neighbor_enable_disable_reply_t *rmp;
2560 ip_neighbor_scan_arg_t arg;
2561
2562 arg.mode = mp->mode;
2563 arg.scan_interval = mp->scan_interval;
2564 arg.max_proc_time = mp->max_proc_time;
2565 arg.max_update = mp->max_update;
2566 arg.scan_int_delay = mp->scan_int_delay;
2567 arg.stale_threshold = mp->stale_threshold;
2568 ip_neighbor_scan_enable_disable (&arg);
2569
2570 REPLY_MACRO (VL_API_IP_SCAN_NEIGHBOR_ENABLE_DISABLE_REPLY);
2571}
2572
Neale Rannsb8d44812017-11-10 06:53:54 -08002573static int
2574ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2575{
2576 vnet_main_t *vnm = vnet_get_main ();
2577 vnet_interface_main_t *im = &vnm->interface_main;
2578 ip4_main_t *im4 = &ip4_main;
2579 static u32 *sw_if_indices_to_shut;
Neale Rannsb8d44812017-11-10 06:53:54 -08002580 fib_table_t *fib_table;
2581 ip4_fib_t *fib;
2582 u32 sw_if_index;
2583 int i;
2584 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2585 u32 target_fib_id = ntohl (mp->vrf_id);
2586
Neale Rannsb8d44812017-11-10 06:53:54 -08002587 /* *INDENT-OFF* */
2588 pool_foreach (fib_table, im4->fibs,
2589 ({
2590 vnet_sw_interface_t * si;
2591
2592 fib = pool_elt_at_index (im4->v4_fibs, fib_table->ft_index);
2593
2594 if (fib->table_id != target_fib_id)
2595 continue;
2596
2597 /* remove any mpls encap/decap labels */
2598 mpls_fib_reset_labels (fib->table_id);
2599
2600 /* remove any proxy arps in this fib */
2601 vnet_proxy_arp_fib_reset (fib->table_id);
2602
2603 /* Set the flow hash for this fib to the default */
2604 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2605
2606 vec_reset_length (sw_if_indices_to_shut);
2607
2608 /* Shut down interfaces in this FIB / clean out intfc routes */
2609 pool_foreach (si, im->sw_interfaces,
2610 ({
2611 u32 sw_if_index = si->sw_if_index;
2612
2613 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2614 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2615 fib->index))
2616 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2617 }));
2618
2619 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2620 sw_if_index = sw_if_indices_to_shut[i];
2621
2622 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2623 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2624 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2625 }
2626
2627 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
2628
2629 rv = 0;
2630 break;
2631 })); /* pool_foreach (fib) */
2632 /* *INDENT-ON* */
2633
Neale Rannsb8d44812017-11-10 06:53:54 -08002634 return rv;
2635}
2636
2637static int
2638ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2639{
2640 vnet_main_t *vnm = vnet_get_main ();
2641 vnet_interface_main_t *im = &vnm->interface_main;
2642 ip6_main_t *im6 = &ip6_main;
Neale Rannsb8d44812017-11-10 06:53:54 -08002643 static u32 *sw_if_indices_to_shut;
2644 fib_table_t *fib_table;
2645 ip6_fib_t *fib;
2646 u32 sw_if_index;
2647 int i;
2648 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2649 u32 target_fib_id = ntohl (mp->vrf_id);
2650
Neale Rannsb8d44812017-11-10 06:53:54 -08002651 /* *INDENT-OFF* */
2652 pool_foreach (fib_table, im6->fibs,
2653 ({
2654 vnet_sw_interface_t * si;
2655
2656 fib = pool_elt_at_index (im6->v6_fibs, fib_table->ft_index);
2657
2658 if (fib->table_id != target_fib_id)
2659 continue;
2660
2661 vec_reset_length (sw_if_indices_to_shut);
2662
2663 /* Set the flow hash for this fib to the default */
2664 vnet_set_ip6_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2665
2666 /* Shut down interfaces in this FIB / clean out intfc routes */
2667 pool_foreach (si, im->sw_interfaces,
2668 ({
2669 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2670 fib->index)
2671 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2672 }));
2673
2674 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2675 sw_if_index = sw_if_indices_to_shut[i];
2676
2677 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2678 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2679 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2680 }
2681
2682 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
2683
2684 rv = 0;
2685 break;
2686 })); /* pool_foreach (fib) */
2687 /* *INDENT-ON* */
2688
Neale Rannsb8d44812017-11-10 06:53:54 -08002689 return rv;
2690}
2691
2692static void
2693vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2694{
2695 int rv;
2696 vl_api_reset_fib_reply_t *rmp;
2697
2698 if (mp->is_ipv6)
2699 rv = ip6_reset_fib_t_handler (mp);
2700 else
2701 rv = ip4_reset_fib_t_handler (mp);
2702
2703 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
2704}
2705
2706static void
2707vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
2708{
2709 int rv;
2710 vl_api_set_arp_neighbor_limit_reply_t *rmp;
2711 vnet_main_t *vnm = vnet_get_main ();
2712 clib_error_t *error;
2713
2714 vnm->api_errno = 0;
2715
2716 if (mp->is_ipv6)
2717 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
2718 else
2719 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
2720
2721 if (error)
2722 {
2723 clib_error_report (error);
2724 rv = VNET_API_ERROR_UNSPECIFIED;
2725 }
2726 else
2727 {
2728 rv = vnm->api_errno;
2729 }
2730
2731 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
2732}
2733
Klement Sekera75e7d132017-09-20 08:26:30 +02002734void
2735vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
2736{
2737 vl_api_ip_reassembly_set_reply_t *rmp;
2738 int rv = 0;
2739 if (mp->is_ip6)
2740 {
Klement Sekera896c8962019-06-24 11:52:49 +00002741 rv = ip6_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
2742 clib_net_to_host_u32 (mp->max_reassemblies),
2743 clib_net_to_host_u32
2744 (mp->max_reassembly_length),
2745 clib_net_to_host_u32
2746 (mp->expire_walk_interval_ms));
Klement Sekera75e7d132017-09-20 08:26:30 +02002747 }
2748 else
2749 {
Klement Sekera896c8962019-06-24 11:52:49 +00002750 rv = ip4_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
2751 clib_net_to_host_u32 (mp->max_reassemblies),
2752 clib_net_to_host_u32
2753 (mp->max_reassembly_length),
2754 clib_net_to_host_u32
2755 (mp->expire_walk_interval_ms));
Klement Sekera75e7d132017-09-20 08:26:30 +02002756 }
2757
2758 REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
2759}
2760
2761void
2762vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
2763{
Ole Troan2e1c8962019-04-10 09:44:23 +02002764 vl_api_registration_t *rp;
Klement Sekera75e7d132017-09-20 08:26:30 +02002765
Ole Troan2e1c8962019-04-10 09:44:23 +02002766 rp = vl_api_client_index_to_registration (mp->client_index);
2767 if (rp == 0)
Klement Sekera75e7d132017-09-20 08:26:30 +02002768 return;
2769
2770 vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04002771 clib_memset (rmp, 0, sizeof (*rmp));
Klement Sekera75e7d132017-09-20 08:26:30 +02002772 rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
2773 rmp->context = mp->context;
2774 rmp->retval = 0;
2775 if (mp->is_ip6)
2776 {
2777 rmp->is_ip6 = 1;
Klement Sekera896c8962019-06-24 11:52:49 +00002778 ip6_full_reass_get (&rmp->timeout_ms, &rmp->max_reassemblies,
2779 &rmp->max_reassembly_length,
2780 &rmp->expire_walk_interval_ms);
Klement Sekera75e7d132017-09-20 08:26:30 +02002781 }
2782 else
2783 {
2784 rmp->is_ip6 = 0;
Klement Sekera896c8962019-06-24 11:52:49 +00002785 ip4_full_reass_get (&rmp->timeout_ms, &rmp->max_reassemblies,
2786 &rmp->max_reassembly_length,
2787 &rmp->expire_walk_interval_ms);
Klement Sekera75e7d132017-09-20 08:26:30 +02002788 }
2789 rmp->timeout_ms = clib_host_to_net_u32 (rmp->timeout_ms);
2790 rmp->max_reassemblies = clib_host_to_net_u32 (rmp->max_reassemblies);
2791 rmp->expire_walk_interval_ms =
2792 clib_host_to_net_u32 (rmp->expire_walk_interval_ms);
Ole Troan2e1c8962019-04-10 09:44:23 +02002793 vl_api_send_msg (rp, (u8 *) rmp);
Klement Sekera75e7d132017-09-20 08:26:30 +02002794}
2795
Klement Sekera4c533132018-02-22 11:41:12 +01002796void
2797 vl_api_ip_reassembly_enable_disable_t_handler
2798 (vl_api_ip_reassembly_enable_disable_t * mp)
2799{
2800 vl_api_ip_reassembly_enable_disable_reply_t *rmp;
2801 int rv = 0;
Klement Sekera896c8962019-06-24 11:52:49 +00002802 rv = ip4_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
2803 mp->enable_ip4);
Klement Sekera4c533132018-02-22 11:41:12 +01002804 if (0 == rv)
2805 {
Klement Sekera896c8962019-06-24 11:52:49 +00002806 rv =
2807 ip6_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
2808 mp->enable_ip6);
Klement Sekera4c533132018-02-22 11:41:12 +01002809 }
2810
Choree7f61d12018-11-28 10:27:58 +03302811 REPLY_MACRO (VL_API_IP_REASSEMBLY_ENABLE_DISABLE_REPLY);
Klement Sekera4c533132018-02-22 11:41:12 +01002812}
2813
Neale Ranns92207752019-06-03 13:21:40 +00002814typedef struct ip_punt_redirect_walk_ctx_t_
Pavel Kotucek609e1212018-11-27 09:59:44 +01002815{
Neale Ranns92207752019-06-03 13:21:40 +00002816 vl_api_registration_t *reg;
2817 u32 context;
2818} ip_punt_redirect_walk_ctx_t;
2819
2820static walk_rc_t
2821send_ip_punt_redirect_details (u32 rx_sw_if_index,
2822 const ip_punt_redirect_rx_t * ipr, void *arg)
2823{
Neale Ranns92207752019-06-03 13:21:40 +00002824 ip_punt_redirect_walk_ctx_t *ctx = arg;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002825 vl_api_ip_punt_redirect_details_t *mp;
Neale Ranns097fa662018-05-01 05:17:55 -07002826 fib_path_encode_ctx_t path_ctx = {
2827 .rpaths = NULL,
2828 };
Pavel Kotucek609e1212018-11-27 09:59:44 +01002829
2830 mp = vl_msg_api_alloc (sizeof (*mp));
2831 if (!mp)
Neale Ranns92207752019-06-03 13:21:40 +00002832 return (WALK_STOP);;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002833
2834 clib_memset (mp, 0, sizeof (*mp));
2835 mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
Neale Ranns92207752019-06-03 13:21:40 +00002836 mp->context = ctx->context;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002837
Neale Ranns097fa662018-05-01 05:17:55 -07002838 fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &path_ctx);
Neale Ranns92207752019-06-03 13:21:40 +00002839
2840 mp->punt.rx_sw_if_index = htonl (rx_sw_if_index);
Neale Ranns097fa662018-05-01 05:17:55 -07002841 mp->punt.tx_sw_if_index = htonl (path_ctx.rpaths[0].frp_sw_if_index);
Neale Ranns92207752019-06-03 13:21:40 +00002842
Neale Ranns097fa662018-05-01 05:17:55 -07002843 ip_address_encode (&path_ctx.rpaths[0].frp_addr,
Neale Ranns92207752019-06-03 13:21:40 +00002844 fib_proto_to_ip46 (ipr->fproto), &mp->punt.nh);
2845
2846 vl_api_send_msg (ctx->reg, (u8 *) mp);
2847
Neale Ranns097fa662018-05-01 05:17:55 -07002848 vec_free (path_ctx.rpaths);
Neale Ranns92207752019-06-03 13:21:40 +00002849
2850 return (WALK_CONTINUE);
Pavel Kotucek609e1212018-11-27 09:59:44 +01002851}
2852
2853static void
2854vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp)
2855{
2856 vl_api_registration_t *reg;
Neale Ranns92207752019-06-03 13:21:40 +00002857 fib_protocol_t fproto;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002858
Pavel Kotucek609e1212018-11-27 09:59:44 +01002859 reg = vl_api_client_index_to_registration (mp->client_index);
2860 if (!reg)
2861 return;
2862
Neale Ranns92207752019-06-03 13:21:40 +00002863 fproto = mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4;
Pavel Kotucek609e1212018-11-27 09:59:44 +01002864
Neale Ranns92207752019-06-03 13:21:40 +00002865 ip_punt_redirect_walk_ctx_t ctx = {
2866 .reg = reg,
2867 .context = mp->context,
2868 };
2869
2870 if (~0 != mp->sw_if_index)
Pavel Kotucek609e1212018-11-27 09:59:44 +01002871 {
Neale Ranns92207752019-06-03 13:21:40 +00002872 u32 rx_sw_if_index;
2873 index_t pri;
2874
2875 rx_sw_if_index = ntohl (mp->sw_if_index);
2876 pri = ip_punt_redirect_find (fproto, rx_sw_if_index);
2877
2878 if (INDEX_INVALID == pri)
2879 return;
2880
2881 send_ip_punt_redirect_details (rx_sw_if_index,
2882 ip_punt_redirect_get (pri), &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01002883 }
2884 else
Neale Ranns92207752019-06-03 13:21:40 +00002885 ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx);
Pavel Kotucek609e1212018-11-27 09:59:44 +01002886}
2887
Dave Barachb5e8a772016-12-06 12:04:42 -05002888#define vl_msg_name_crc_list
2889#include <vnet/ip/ip.api.h>
2890#undef vl_msg_name_crc_list
2891
2892static void
2893setup_message_id_table (api_main_t * am)
2894{
2895#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2896 foreach_vl_msg_name_crc_ip;
2897#undef _
2898}
2899
2900static clib_error_t *
2901ip_api_hookup (vlib_main_t * vm)
2902{
2903 api_main_t *am = &api_main;
2904
2905#define _(N,n) \
2906 vl_msg_api_set_handlers(VL_API_##N, #n, \
2907 vl_api_##n##_t_handler, \
2908 vl_noop_handler, \
2909 vl_api_##n##_t_endian, \
2910 vl_api_##n##_t_print, \
2911 sizeof(vl_api_##n##_t), 1);
2912 foreach_ip_api_msg;
2913#undef _
2914
2915 /*
Neale Ranns6a231a12018-10-17 06:38:00 +00002916 * Mark the route add/del API as MP safe
2917 */
Neale Ranns097fa662018-05-01 05:17:55 -07002918 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1;
2919 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL_REPLY] = 1;
Neale Ranns6a231a12018-10-17 06:38:00 +00002920
2921 /*
Dave Barachb5e8a772016-12-06 12:04:42 -05002922 * Set up the (msg_name, crc, message-id) table
2923 */
2924 setup_message_id_table (am);
2925
Juraj Sloboda52574522018-05-03 10:03:50 +02002926 ra_set_publisher_node (wc_arp_process_node.index, RA_REPORT);
2927
Dave Barachb5e8a772016-12-06 12:04:42 -05002928 return 0;
2929}
2930
2931VLIB_API_INIT_FUNCTION (ip_api_hookup);
2932
2933/*
2934 * fd.io coding-style-patch-verification: ON
2935 *
2936 * Local Variables:
2937 * eval: (c-set-style "gnu")
2938 * End:
2939 */