blob: 2f476a330ee81a86ae023bed54e277ceeb33f72e [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>
26#include <vnet/ip/ip.h>
John Lo7f358b32018-04-28 01:19:24 -040027#include <vnet/ip/ip_neighbor.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050028#include <vnet/ip/ip6_neighbor.h>
Pavel Kotucek609e1212018-11-27 09:59:44 +010029#include <vnet/ip/ip_punt_drop.h>
Dave Barachb5e8a772016-12-06 12:04:42 -050030#include <vnet/fib/fib_table.h>
31#include <vnet/fib/fib_api.h>
32#include <vnet/dpo/drop_dpo.h>
33#include <vnet/dpo/receive_dpo.h>
34#include <vnet/dpo/lookup_dpo.h>
35#include <vnet/dpo/classify_dpo.h>
36#include <vnet/dpo/ip_null_dpo.h>
37#include <vnet/ethernet/arp_packet.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080038#include <vnet/mfib/ip6_mfib.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000039#include <vnet/mfib/ip4_mfib.h>
40#include <vnet/mfib/mfib_signal.h>
Neale Ranns5a8123b2017-01-26 01:18:23 -080041#include <vnet/mfib/mfib_entry.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080042#include <vnet/ip/ip_source_and_port_range_check.h>
43#include <vnet/fib/ip4_fib.h>
44#include <vnet/fib/ip6_fib.h>
45#include <vnet/ip/ip6_hop_by_hop.h>
Klement Sekera75e7d132017-09-20 08:26:30 +020046#include <vnet/ip/ip4_reassembly.h>
47#include <vnet/ip/ip6_reassembly.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
Neale Ranns5a8123b2017-01-26 01:18:23 -080069
Dave Barachb5e8a772016-12-06 12:04:42 -050070#define foreach_ip_api_msg \
71_(IP_FIB_DUMP, ip_fib_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050072_(IP6_FIB_DUMP, ip6_fib_dump) \
Neale Ranns5a8123b2017-01-26 01:18:23 -080073_(IP_MFIB_DUMP, ip_mfib_dump) \
Neale Ranns5a8123b2017-01-26 01:18:23 -080074_(IP6_MFIB_DUMP, ip6_mfib_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050075_(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \
Neale Ranns32e1c012016-11-22 17:07:28 +000076_(IP_MROUTE_ADD_DEL, ip_mroute_add_del) \
Neale Ranns5a8123b2017-01-26 01:18:23 -080077_(MFIB_SIGNAL_DUMP, mfib_signal_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050078_(IP_ADDRESS_DUMP, ip_address_dump) \
Neale Ranns9e2f9152018-05-18 02:27:10 -070079_(IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \
Dave Barachb5e8a772016-12-06 12:04:42 -050080_(IP_DUMP, ip_dump) \
81_(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
Neale Rannsb8d44812017-11-10 06:53:54 -080082_(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
John Loc7b43042018-04-13 16:46:22 -040083_(IP_PROBE_NEIGHBOR, ip_probe_neighbor) \
John Lo7f358b32018-04-28 01:19:24 -040084_(IP_SCAN_NEIGHBOR_ENABLE_DISABLE, ip_scan_neighbor_enable_disable) \
Neale Rannsb8d44812017-11-10 06:53:54 -080085_(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
86_(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010087_(WANT_IP6_RA_EVENTS, want_ip6_ra_events) \
Neale Rannsb8d44812017-11-10 06:53:54 -080088_(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
Neale Ranns0053de62018-05-22 08:40:52 -070089_(PROXY_ARP_DUMP, proxy_arp_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -080090_(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
Neale Ranns0053de62018-05-22 08:40:52 -070091 _(PROXY_ARP_INTFC_DUMP, proxy_arp_intfc_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -080092_(RESET_FIB, reset_fib) \
Dave Barachb5e8a772016-12-06 12:04:42 -050093_(IP_ADD_DEL_ROUTE, ip_add_del_route) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070094_(IP_TABLE_ADD_DEL, ip_table_add_del) \
Neale Rannsd91c1db2017-07-31 02:30:50 -070095_(IP_PUNT_POLICE, ip_punt_police) \
96_(IP_PUNT_REDIRECT, ip_punt_redirect) \
Dave Barachb5e8a772016-12-06 12:04:42 -050097_(SET_IP_FLOW_HASH,set_ip_flow_hash) \
98_(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
99_(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
Neale Ranns3f844d02017-02-18 00:03:54 -0800100_(IP6ND_PROXY_ADD_DEL, ip6nd_proxy_add_del) \
101_(IP6ND_PROXY_DUMP, ip6nd_proxy_dump) \
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100102_(IP6ND_SEND_ROUTER_SOLICITATION, ip6nd_send_router_solicitation) \
Dave Barachb5e8a772016-12-06 12:04:42 -0500103_(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
Neale Rannsb8d44812017-11-10 06:53:54 -0800104_(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \
Matus Fabian75b9f452018-10-02 23:27:21 -0700105_(IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -0800106_(IOAM_ENABLE, ioam_enable) \
107_(IOAM_DISABLE, ioam_disable) \
108_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
109 ip_source_and_port_range_check_add_del) \
110_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
Klement Sekera75e7d132017-09-20 08:26:30 +0200111 ip_source_and_port_range_check_interface_add_del) \
112_(IP_REASSEMBLY_SET, ip_reassembly_set) \
Klement Sekera4c533132018-02-22 11:41:12 +0100113_(IP_REASSEMBLY_GET, ip_reassembly_get) \
Pavel Kotucek609e1212018-11-27 09:59:44 +0100114_(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
115_(IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
116
Dave Barachb5e8a772016-12-06 12:04:42 -0500117
118extern void stats_dslock_with_hint (int hint, int tag);
119extern void stats_dsunlock (void);
120
121static void
Jon Loeligeraf8dfbf2017-11-08 13:07:39 -0600122send_ip_neighbor_details (u32 sw_if_index,
123 u8 is_ipv6,
Dave Barachb5e8a772016-12-06 12:04:42 -0500124 u8 is_static,
125 u8 * mac_address,
Florin Coras6c4dae22018-01-09 06:39:23 -0800126 u8 * ip_address, vl_api_registration_t * reg,
127 u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500128{
129 vl_api_ip_neighbor_details_t *mp;
130
131 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400132 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500133 mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS);
134 mp->context = context;
Jon Loeligeraf8dfbf2017-11-08 13:07:39 -0600135 mp->sw_if_index = htonl (sw_if_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500136 mp->is_ipv6 = is_ipv6;
137 mp->is_static = is_static;
138 memcpy (mp->mac_address, mac_address, 6);
139 memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
140
Florin Coras6c4dae22018-01-09 06:39:23 -0800141 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500142}
143
144static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500145vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp)
146{
Florin Coras6c4dae22018-01-09 06:39:23 -0800147 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500148
Florin Coras6c4dae22018-01-09 06:39:23 -0800149 reg = vl_api_client_index_to_registration (mp->client_index);
150 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500151 return;
152
153 u32 sw_if_index = ntohl (mp->sw_if_index);
154
155 if (mp->is_ipv6)
156 {
157 ip6_neighbor_t *n, *ns;
158
159 ns = ip6_neighbors_entries (sw_if_index);
160 /* *INDENT-OFF* */
161 vec_foreach (n, ns)
162 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500163 send_ip_neighbor_details
Brant Lin285434a2018-06-13 06:01:58 -0400164 (n->key.sw_if_index, mp->is_ipv6,
Jon Loeligeraf8dfbf2017-11-08 13:07:39 -0600165 ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0),
Dave Barachd7cb1b52016-12-09 09:52:16 -0500166 (u8 *) n->link_layer_address,
167 (u8 *) & (n->key.ip6_address.as_u8),
Florin Coras6c4dae22018-01-09 06:39:23 -0800168 reg, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500169 }
170 /* *INDENT-ON* */
171 vec_free (ns);
172 }
173 else
174 {
175 ethernet_arp_ip4_entry_t *n, *ns;
176
177 ns = ip4_neighbor_entries (sw_if_index);
178 /* *INDENT-OFF* */
179 vec_foreach (n, ns)
180 {
Brant Lin285434a2018-06-13 06:01:58 -0400181 send_ip_neighbor_details (n->sw_if_index, mp->is_ipv6,
Dave Barachb5e8a772016-12-06 12:04:42 -0500182 ((n->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) ? 1 : 0),
183 (u8*) n->ethernet_address,
184 (u8*) & (n->ip4_address.as_u8),
Florin Coras6c4dae22018-01-09 06:39:23 -0800185 reg, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -0500186 }
187 /* *INDENT-ON* */
188 vec_free (ns);
189 }
190}
191
Dave Barachb5e8a772016-12-06 12:04:42 -0500192static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500193send_ip_fib_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800194 vl_api_registration_t * reg,
Neale Ranns2297af02017-09-12 09:45:04 -0700195 const fib_table_t * table,
196 const fib_prefix_t * pfx,
Dave Barachb5e8a772016-12-06 12:04:42 -0500197 fib_route_path_encode_t * api_rpaths, u32 context)
198{
199 vl_api_ip_fib_details_t *mp;
200 fib_route_path_encode_t *api_rpath;
201 vl_api_fib_path_t *fp;
202 int path_count;
203
204 path_count = vec_len (api_rpaths);
205 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
206 if (!mp)
207 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400208 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500209 mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS);
210 mp->context = context;
211
Neale Ranns2297af02017-09-12 09:45:04 -0700212 mp->table_id = htonl (table->ft_table_id);
213 memcpy (mp->table_name, table->ft_desc,
214 clib_min (vec_len (table->ft_desc), sizeof (mp->table_name)));
Dave Barachb5e8a772016-12-06 12:04:42 -0500215 mp->address_length = pfx->fp_len;
216 memcpy (mp->address, &pfx->fp_addr.ip4, sizeof (pfx->fp_addr.ip4));
Neale Ranns008dbe12018-09-07 09:32:36 -0700217 mp->stats_index =
218 htonl (fib_table_entry_get_stats_index (table->ft_index, pfx));
Dave Barachb5e8a772016-12-06 12:04:42 -0500219
220 mp->count = htonl (path_count);
221 fp = mp->path;
222 vec_foreach (api_rpath, api_rpaths)
223 {
Neale Ranns81458422018-03-12 06:59:36 -0700224 fib_api_path_encode (api_rpath, fp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500225 fp++;
226 }
227
Florin Coras6c4dae22018-01-09 06:39:23 -0800228 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500229}
230
Neale Rannsa3af3372017-03-28 03:49:52 -0700231typedef struct vl_api_ip_fib_dump_walk_ctx_t_
232{
233 fib_node_index_t *feis;
234} vl_api_ip_fib_dump_walk_ctx_t;
235
Neale Ranns89541992017-04-06 04:41:02 -0700236static fib_table_walk_rc_t
Neale Rannsa3af3372017-03-28 03:49:52 -0700237vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg)
238{
239 vl_api_ip_fib_dump_walk_ctx_t *ctx = arg;
240
241 vec_add1 (ctx->feis, fei);
242
Neale Ranns89541992017-04-06 04:41:02 -0700243 return (FIB_TABLE_WALK_CONTINUE);
Neale Rannsa3af3372017-03-28 03:49:52 -0700244}
245
Dave Barachb5e8a772016-12-06 12:04:42 -0500246static void
247vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp)
248{
249 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800250 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500251 ip4_main_t *im = &ip4_main;
252 fib_table_t *fib_table;
Neale Rannsa3af3372017-03-28 03:49:52 -0700253 fib_node_index_t *lfeip;
Neale Rannsc5d43172018-07-30 08:04:40 -0700254 const fib_prefix_t *pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -0500255 u32 fib_index;
256 fib_route_path_encode_t *api_rpaths;
Neale Rannsa3af3372017-03-28 03:49:52 -0700257 vl_api_ip_fib_dump_walk_ctx_t ctx = {
258 .feis = NULL,
259 };
Dave Barachb5e8a772016-12-06 12:04:42 -0500260
Florin Coras6c4dae22018-01-09 06:39:23 -0800261 reg = vl_api_client_index_to_registration (mp->client_index);
262 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500263 return;
264
265 /* *INDENT-OFF* */
266 pool_foreach (fib_table, im->fibs,
267 ({
Neale Rannsa3af3372017-03-28 03:49:52 -0700268 fib_table_walk(fib_table->ft_index,
269 FIB_PROTOCOL_IP4,
270 vl_api_ip_fib_dump_walk,
271 &ctx);
Dave Barachb5e8a772016-12-06 12:04:42 -0500272 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500273 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500274
Neale Rannsa3af3372017-03-28 03:49:52 -0700275 vec_sort_with_function (ctx.feis, fib_entry_cmp_for_sort);
Dave Barachb5e8a772016-12-06 12:04:42 -0500276
Neale Rannsa3af3372017-03-28 03:49:52 -0700277 vec_foreach (lfeip, ctx.feis)
Dave Barachb5e8a772016-12-06 12:04:42 -0500278 {
Neale Rannsc5d43172018-07-30 08:04:40 -0700279 pfx = fib_entry_get_prefix (*lfeip);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500280 fib_index = fib_entry_get_fib_index (*lfeip);
Neale Rannsc5d43172018-07-30 08:04:40 -0700281 fib_table = fib_table_get (fib_index, pfx->fp_proto);
Dave Barachb5e8a772016-12-06 12:04:42 -0500282 api_rpaths = NULL;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500283 fib_entry_encode (*lfeip, &api_rpaths);
Neale Rannsc5d43172018-07-30 08:04:40 -0700284 send_ip_fib_details (am, reg, fib_table, pfx, api_rpaths, mp->context);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500285 vec_free (api_rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500286 }
287
Neale Rannsa3af3372017-03-28 03:49:52 -0700288 vec_free (ctx.feis);
Dave Barachb5e8a772016-12-06 12:04:42 -0500289}
290
291static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500292send_ip6_fib_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800293 vl_api_registration_t * reg,
Neale Rannsa161a6d2017-11-14 08:10:41 -0800294 const fib_table_t * table,
295 const fib_prefix_t * pfx,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500296 fib_route_path_encode_t * api_rpaths, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -0500297{
298 vl_api_ip6_fib_details_t *mp;
299 fib_route_path_encode_t *api_rpath;
300 vl_api_fib_path_t *fp;
301 int path_count;
302
Dave Barachd7cb1b52016-12-09 09:52:16 -0500303 path_count = vec_len (api_rpaths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500304 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
305 if (!mp)
306 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400307 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -0500308 mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS);
309 mp->context = context;
310
Neale Rannsa161a6d2017-11-14 08:10:41 -0800311 mp->table_id = htonl (table->ft_table_id);
Dave Barachb5e8a772016-12-06 12:04:42 -0500312 mp->address_length = pfx->fp_len;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500313 memcpy (mp->address, &pfx->fp_addr.ip6, sizeof (pfx->fp_addr.ip6));
Neale Rannsa161a6d2017-11-14 08:10:41 -0800314 memcpy (mp->table_name, table->ft_desc,
315 clib_min (vec_len (table->ft_desc), sizeof (mp->table_name)));
Neale Ranns008dbe12018-09-07 09:32:36 -0700316 mp->stats_index =
317 htonl (fib_table_entry_get_stats_index (table->ft_index, pfx));
Dave Barachb5e8a772016-12-06 12:04:42 -0500318
319 mp->count = htonl (path_count);
320 fp = mp->path;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500321 vec_foreach (api_rpath, api_rpaths)
Dave Barachb5e8a772016-12-06 12:04:42 -0500322 {
Neale Ranns81458422018-03-12 06:59:36 -0700323 fib_api_path_encode (api_rpath, fp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500324 fp++;
325 }
326
Florin Coras6c4dae22018-01-09 06:39:23 -0800327 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -0500328}
329
Dave Barachd7cb1b52016-12-09 09:52:16 -0500330typedef struct apt_ip6_fib_show_ctx_t_
331{
332 u32 fib_index;
333 fib_node_index_t *entries;
Dave Barachb5e8a772016-12-06 12:04:42 -0500334} api_ip6_fib_show_ctx_t;
335
336static void
Dave Barachd7cb1b52016-12-09 09:52:16 -0500337api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp, void *arg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500338{
339 api_ip6_fib_show_ctx_t *ctx = arg;
340
341 if ((kvp->key[2] >> 32) == ctx->fib_index)
342 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500343 vec_add1 (ctx->entries, kvp->value);
Dave Barachb5e8a772016-12-06 12:04:42 -0500344 }
345}
346
347static void
Florin Coras6c4dae22018-01-09 06:39:23 -0800348api_ip6_fib_table_get_all (vl_api_registration_t * reg,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500349 vl_api_ip6_fib_dump_t * mp,
350 fib_table_t * fib_table)
Dave Barachb5e8a772016-12-06 12:04:42 -0500351{
352 vpe_api_main_t *am = &vpe_api_main;
353 ip6_main_t *im6 = &ip6_main;
Dave Barachb5e8a772016-12-06 12:04:42 -0500354 fib_node_index_t *fib_entry_index;
355 api_ip6_fib_show_ctx_t ctx = {
Neale Rannsa3af3372017-03-28 03:49:52 -0700356 .fib_index = fib_table->ft_index,
357 .entries = NULL,
Dave Barachb5e8a772016-12-06 12:04:42 -0500358 };
359 fib_route_path_encode_t *api_rpaths;
Neale Rannsc5d43172018-07-30 08:04:40 -0700360 const fib_prefix_t *pfx;
Dave Barachb5e8a772016-12-06 12:04:42 -0500361
Dave Barachd7cb1b52016-12-09 09:52:16 -0500362 BV (clib_bihash_foreach_key_value_pair)
363 ((BVT (clib_bihash) *) & im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].
364 ip6_hash, api_ip6_fib_table_put_entries, &ctx);
Dave Barachb5e8a772016-12-06 12:04:42 -0500365
Dave Barachd7cb1b52016-12-09 09:52:16 -0500366 vec_sort_with_function (ctx.entries, fib_entry_cmp_for_sort);
Dave Barachb5e8a772016-12-06 12:04:42 -0500367
Dave Barachd7cb1b52016-12-09 09:52:16 -0500368 vec_foreach (fib_entry_index, ctx.entries)
369 {
Neale Rannsc5d43172018-07-30 08:04:40 -0700370 pfx = fib_entry_get_prefix (*fib_entry_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500371 api_rpaths = NULL;
372 fib_entry_encode (*fib_entry_index, &api_rpaths);
Neale Rannsc5d43172018-07-30 08:04:40 -0700373 send_ip6_fib_details (am, reg, fib_table, pfx, api_rpaths, mp->context);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500374 vec_free (api_rpaths);
375 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500376
Dave Barachd7cb1b52016-12-09 09:52:16 -0500377 vec_free (ctx.entries);
Dave Barachb5e8a772016-12-06 12:04:42 -0500378}
379
380static void
381vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp)
382{
Florin Coras6c4dae22018-01-09 06:39:23 -0800383 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -0500384 ip6_main_t *im6 = &ip6_main;
385 fib_table_t *fib_table;
386
Florin Coras6c4dae22018-01-09 06:39:23 -0800387 reg = vl_api_client_index_to_registration (mp->client_index);
388 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -0500389 return;
390
391 /* *INDENT-OFF* */
392 pool_foreach (fib_table, im6->fibs,
393 ({
Neale Ranns81458422018-03-12 06:59:36 -0700394 /* don't send link locals */
395 if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
396 continue;
397
Florin Coras6c4dae22018-01-09 06:39:23 -0800398 api_ip6_fib_table_get_all(reg, mp, fib_table);
Dave Barachb5e8a772016-12-06 12:04:42 -0500399 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500400 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500401}
402
403static void
Florin Coras6c4dae22018-01-09 06:39:23 -0800404send_ip_mfib_details (vl_api_registration_t * reg,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800405 u32 context, u32 table_id, fib_node_index_t mfei)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800406{
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800407 fib_route_path_encode_t *api_rpath, *api_rpaths = NULL;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800408 vl_api_ip_mfib_details_t *mp;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800409 mfib_entry_t *mfib_entry;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800410 vl_api_fib_path_t *fp;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800411 mfib_prefix_t pfx;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800412 int path_count;
413
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800414 mfib_entry = mfib_entry_get (mfei);
415 mfib_entry_get_prefix (mfei, &pfx);
416 mfib_entry_encode (mfei, &api_rpaths);
417
Neale Ranns5a8123b2017-01-26 01:18:23 -0800418 path_count = vec_len (api_rpaths);
419 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
420 if (!mp)
421 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400422 clib_memset (mp, 0, sizeof (*mp));
Neale Rannsd792d9c2017-10-21 10:53:20 -0700423 mp->_vl_msg_id = ntohs (VL_API_IP_MFIB_DETAILS);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800424 mp->context = context;
425
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800426 mp->rpf_id = mfib_entry->mfe_rpf_id;
427 mp->entry_flags = mfib_entry->mfe_flags;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800428 mp->table_id = htonl (table_id);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800429 mp->address_length = pfx.fp_len;
430 memcpy (mp->grp_address, &pfx.fp_grp_addr.ip4,
431 sizeof (pfx.fp_grp_addr.ip4));
432 memcpy (mp->src_address, &pfx.fp_src_addr.ip4,
433 sizeof (pfx.fp_src_addr.ip4));
Neale Ranns5a8123b2017-01-26 01:18:23 -0800434
435 mp->count = htonl (path_count);
436 fp = mp->path;
437 vec_foreach (api_rpath, api_rpaths)
438 {
Neale Ranns81458422018-03-12 06:59:36 -0700439 fib_api_path_encode (api_rpath, fp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800440 fp++;
441 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800442 vec_free (api_rpaths);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800443
Florin Coras6c4dae22018-01-09 06:39:23 -0800444 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800445}
446
447typedef struct vl_api_ip_mfib_dump_ctc_t_
448{
449 fib_node_index_t *entries;
450} vl_api_ip_mfib_dump_ctc_t;
451
452static int
453vl_api_ip_mfib_table_dump_walk (fib_node_index_t fei, void *arg)
454{
455 vl_api_ip_mfib_dump_ctc_t *ctx = arg;
456
457 vec_add1 (ctx->entries, fei);
458
459 return (0);
460}
461
462static void
463vl_api_ip_mfib_dump_t_handler (vl_api_ip_mfib_dump_t * mp)
464{
Florin Coras6c4dae22018-01-09 06:39:23 -0800465 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800466 ip4_main_t *im = &ip4_main;
467 mfib_table_t *mfib_table;
468 fib_node_index_t *mfeip;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800469 vl_api_ip_mfib_dump_ctc_t ctx = {
470 .entries = NULL,
471 };
472
Florin Coras6c4dae22018-01-09 06:39:23 -0800473 reg = vl_api_client_index_to_registration (mp->client_index);
474 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800475 return;
476
Neale Ranns5a8123b2017-01-26 01:18:23 -0800477 /* *INDENT-OFF* */
478 pool_foreach (mfib_table, im->mfibs,
479 ({
480 ip4_mfib_table_walk(&mfib_table->v4,
481 vl_api_ip_mfib_table_dump_walk,
482 &ctx);
483
484 vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort);
485
486 vec_foreach (mfeip, ctx.entries)
487 {
Florin Coras6c4dae22018-01-09 06:39:23 -0800488 send_ip_mfib_details (reg, mp->context,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800489 mfib_table->mft_table_id,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800490 *mfeip);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800491 }
Neale Ranns5a8123b2017-01-26 01:18:23 -0800492 vec_reset_length (ctx.entries);
493
494 }));
495 /* *INDENT-ON* */
496
497 vec_free (ctx.entries);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800498}
499
500static void
Neale Ranns5a8123b2017-01-26 01:18:23 -0800501send_ip6_mfib_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800502 vl_api_registration_t * reg,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800503 u32 table_id,
504 mfib_prefix_t * pfx,
505 fib_route_path_encode_t * api_rpaths, u32 context)
506{
507 vl_api_ip6_mfib_details_t *mp;
508 fib_route_path_encode_t *api_rpath;
509 vl_api_fib_path_t *fp;
510 int path_count;
511
512 path_count = vec_len (api_rpaths);
513 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
514 if (!mp)
515 return;
Dave Barachb7b92992018-10-17 10:38:51 -0400516 clib_memset (mp, 0, sizeof (*mp));
Neale Rannsd792d9c2017-10-21 10:53:20 -0700517 mp->_vl_msg_id = ntohs (VL_API_IP6_MFIB_DETAILS);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800518 mp->context = context;
519
520 mp->table_id = htonl (table_id);
521 mp->address_length = pfx->fp_len;
522 memcpy (mp->grp_address, &pfx->fp_grp_addr.ip6,
523 sizeof (pfx->fp_grp_addr.ip6));
524 memcpy (mp->src_address, &pfx->fp_src_addr.ip6,
525 sizeof (pfx->fp_src_addr.ip6));
526
527 mp->count = htonl (path_count);
528 fp = mp->path;
529 vec_foreach (api_rpath, api_rpaths)
530 {
Neale Ranns81458422018-03-12 06:59:36 -0700531 fib_api_path_encode (api_rpath, fp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800532 fp++;
533 }
534
Florin Coras6c4dae22018-01-09 06:39:23 -0800535 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns5a8123b2017-01-26 01:18:23 -0800536}
537
538typedef struct vl_api_ip6_mfib_dump_ctc_t_
539{
540 fib_node_index_t *entries;
541} vl_api_ip6_mfib_dump_ctc_t;
542
543static int
544vl_api_ip6_mfib_table_dump_walk (fib_node_index_t fei, void *arg)
545{
546 vl_api_ip6_mfib_dump_ctc_t *ctx = arg;
547
548 vec_add1 (ctx->entries, fei);
549
550 return (0);
551}
552
553static void
554vl_api_ip6_mfib_dump_t_handler (vl_api_ip6_mfib_dump_t * mp)
555{
556 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800557 vl_api_registration_t *reg;
Neale Ranns5a8123b2017-01-26 01:18:23 -0800558 ip6_main_t *im = &ip6_main;
559 mfib_table_t *mfib_table;
560 fib_node_index_t *mfeip;
561 mfib_prefix_t pfx;
562 fib_route_path_encode_t *api_rpaths = NULL;
563 vl_api_ip6_mfib_dump_ctc_t ctx = {
564 .entries = NULL,
565 };
566
Florin Coras6c4dae22018-01-09 06:39:23 -0800567 reg = vl_api_client_index_to_registration (mp->client_index);
568 if (!reg)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800569 return;
570
571
572 /* *INDENT-OFF* */
573 pool_foreach (mfib_table, im->mfibs,
574 ({
575 ip6_mfib_table_walk(&mfib_table->v6,
576 vl_api_ip6_mfib_table_dump_walk,
577 &ctx);
578
579 vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort);
580
581 vec_foreach(mfeip, ctx.entries)
582 {
583 mfib_entry_get_prefix (*mfeip, &pfx);
584 mfib_entry_encode (*mfeip, &api_rpaths);
Florin Coras6c4dae22018-01-09 06:39:23 -0800585 send_ip6_mfib_details (am, reg,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800586 mfib_table->mft_table_id,
587 &pfx, api_rpaths,
588 mp->context);
589 }
590 vec_reset_length (api_rpaths);
591 vec_reset_length (ctx.entries);
592
593 }));
594 /* *INDENT-ON* */
595
596 vec_free (ctx.entries);
597 vec_free (api_rpaths);
598}
599
600static void
Neale Rannsd91c1db2017-07-31 02:30:50 -0700601vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp,
602 vlib_main_t * vm)
603{
604 vl_api_ip_punt_police_reply_t *rmp;
605 int rv = 0;
606
607 if (mp->is_ip6)
608 ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
609 else
610 ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
611
612 REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY);
613}
614
615static void
616vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp,
617 vlib_main_t * vm)
618{
619 vl_api_ip_punt_redirect_reply_t *rmp;
620 int rv = 0;
Pavel Kotucek609e1212018-11-27 09:59:44 +0100621 ip46_type_t ipv;
622 ip46_address_t nh;
Neale Rannsd91c1db2017-07-31 02:30:50 -0700623
Pavel Kotucek609e1212018-11-27 09:59:44 +0100624 if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index)))
625 goto bad_sw_if_index;
626
627 ipv = ip_address_decode (&mp->punt.nh, &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700628 if (mp->is_add)
629 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100630 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700631 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100632 ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
633 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700634 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100635 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700636 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100637 ip4_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
638 ntohl (mp->punt.tx_sw_if_index), &nh);
Neale Rannsd91c1db2017-07-31 02:30:50 -0700639 }
640 }
641 else
642 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100643 if (ipv == IP46_TYPE_IP6)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700644 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100645 ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700646 }
Pavel Kotucek609e1212018-11-27 09:59:44 +0100647 else if (ipv == IP46_TYPE_IP4)
Neale Rannsd91c1db2017-07-31 02:30:50 -0700648 {
Pavel Kotucek609e1212018-11-27 09:59:44 +0100649 ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
Neale Rannsd91c1db2017-07-31 02:30:50 -0700650 }
651 }
652
Pavel Kotucek609e1212018-11-27 09:59:44 +0100653 BAD_SW_IF_INDEX_LABEL;
654
Neale Rannsd91c1db2017-07-31 02:30:50 -0700655 REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY);
656}
657
658static void
Dave Barachb5e8a772016-12-06 12:04:42 -0500659vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
660 vlib_main_t * vm)
661{
Neale Ranns0bdd3192018-09-07 11:04:52 -0700662 ip46_address_t ip = ip46_address_initializer;
Dave Barachb5e8a772016-12-06 12:04:42 -0500663 vl_api_ip_neighbor_add_del_reply_t *rmp;
Neale Ranns0bdd3192018-09-07 11:04:52 -0700664 ip_neighbor_flags_t flags;
Neale Ranns14260392018-09-28 05:00:57 -0700665 u32 stats_index = ~0;
Dave Barachb5e8a772016-12-06 12:04:42 -0500666 int rv = 0;
667
668 VALIDATE_SW_IF_INDEX (mp);
669
670 stats_dslock_with_hint (1 /* release hint */ , 7 /* tag */ );
671
Neale Ranns0bdd3192018-09-07 11:04:52 -0700672 flags = IP_NEIGHBOR_FLAG_NODE;
673 if (mp->is_static)
674 flags |= IP_NEIGHBOR_FLAG_STATIC;
675 if (mp->is_no_adj_fib)
676 flags |= IP_NEIGHBOR_FLAG_NO_ADJ_FIB;
677
Dave Barachb5e8a772016-12-06 12:04:42 -0500678 if (mp->is_ipv6)
Neale Ranns0bdd3192018-09-07 11:04:52 -0700679 clib_memcpy (&ip.ip6, mp->dst_address, 16);
Dave Barachb5e8a772016-12-06 12:04:42 -0500680 else
Neale Ranns0bdd3192018-09-07 11:04:52 -0700681 clib_memcpy (&ip.ip4, mp->dst_address, 4);
Dave Barachb5e8a772016-12-06 12:04:42 -0500682
Neale Ranns0bdd3192018-09-07 11:04:52 -0700683 if (mp->is_add)
684 rv = ip_neighbor_add (&ip, mp->is_ipv6, mp->mac_address,
Neale Ranns14260392018-09-28 05:00:57 -0700685 ntohl (mp->sw_if_index), flags, &stats_index);
Neale Ranns0bdd3192018-09-07 11:04:52 -0700686 else
687 rv = ip_neighbor_del (&ip, mp->is_ipv6, ntohl (mp->sw_if_index));
Dave Barachb5e8a772016-12-06 12:04:42 -0500688
Dave Barachb5e8a772016-12-06 12:04:42 -0500689 stats_dsunlock ();
Neale Ranns8edad032017-10-09 05:26:13 -0700690
691 BAD_SW_IF_INDEX_LABEL;
Neale Ranns14260392018-09-28 05:00:57 -0700692
693 /* *INDENT-OFF* */
694 REPLY_MACRO2 (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY,
695 ({
696 rmp->stats_index = htonl (stats_index);
697 }));
698 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -0500699}
700
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700701void
Neale Ranns15002542017-09-10 04:39:11 -0700702ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api)
703{
704 u32 fib_index, mfib_index;
705
706 /*
707 * ignore action on the default table - this is always present
708 * and cannot be added nor deleted from the API
709 */
710 if (0 != table_id)
711 {
712 /*
713 * The API holds only one lock on the table.
714 * i.e. it can be added many times via the API but needs to be
715 * deleted only once.
716 * The FIB index for unicast and multicast is not necessarily the
717 * same, since internal VPP systesm (like LISP and SR) create
718 * their own unicast tables.
719 */
720 fib_index = fib_table_find (fproto, table_id);
721 mfib_index = mfib_table_find (fproto, table_id);
722
723 if (~0 != fib_index)
724 {
725 fib_table_unlock (fib_index, fproto,
726 (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI));
727 }
728 if (~0 != mfib_index)
729 {
730 mfib_table_unlock (mfib_index, fproto,
731 (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI));
732 }
733 }
734}
735
736void
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700737vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
738{
739 vl_api_ip_table_add_del_reply_t *rmp;
Neale Ranns15002542017-09-10 04:39:11 -0700740 fib_protocol_t fproto = (mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
741 u32 table_id = ntohl (mp->table_id);
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700742 int rv = 0;
743
Neale Ranns15002542017-09-10 04:39:11 -0700744 if (mp->is_add)
745 {
Neale Ranns2297af02017-09-12 09:45:04 -0700746 ip_table_create (fproto, table_id, 1, mp->name);
Neale Ranns15002542017-09-10 04:39:11 -0700747 }
748 else
749 {
750 ip_table_delete (fproto, table_id, 1);
751 }
752
Neale Ranns28ab9cc2017-08-14 07:18:42 -0700753 REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY);
754}
755
Dave Barachb5e8a772016-12-06 12:04:42 -0500756int
757add_del_route_t_handler (u8 is_multipath,
758 u8 is_add,
759 u8 is_drop,
760 u8 is_unreach,
761 u8 is_prohibit,
762 u8 is_local,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800763 u8 is_multicast,
Dave Barachb5e8a772016-12-06 12:04:42 -0500764 u8 is_classify,
765 u32 classify_table_index,
766 u8 is_resolve_host,
767 u8 is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800768 u8 is_interface_rx,
769 u8 is_rpf_id,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800770 u8 is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700771 u8 is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800772 u8 is_udp_encap,
Dave Barachb5e8a772016-12-06 12:04:42 -0500773 u32 fib_index,
774 const fib_prefix_t * prefix,
Neale Rannsda78f952017-05-24 09:15:43 -0700775 dpo_proto_t next_hop_proto,
Dave Barachb5e8a772016-12-06 12:04:42 -0500776 const ip46_address_t * next_hop,
Neale Ranns810086d2017-11-05 16:26:46 -0800777 u32 next_hop_id,
Dave Barachb5e8a772016-12-06 12:04:42 -0500778 u32 next_hop_sw_if_index,
779 u8 next_hop_fib_index,
Neale Ranns57b58602017-07-15 07:37:25 -0700780 u16 next_hop_weight,
781 u16 next_hop_preference,
Dave Barachb5e8a772016-12-06 12:04:42 -0500782 mpls_label_t next_hop_via_label,
Neale Ranns31ed7442018-02-23 05:29:09 -0800783 fib_mpls_label_t * next_hop_out_label_stack)
Dave Barachb5e8a772016-12-06 12:04:42 -0500784{
785 vnet_classify_main_t *cm = &vnet_classify_main;
786 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
787 fib_route_path_t path = {
Neale Rannsda78f952017-05-24 09:15:43 -0700788 .frp_proto = next_hop_proto,
Dave Barachb5e8a772016-12-06 12:04:42 -0500789 .frp_addr = (NULL == next_hop ? zero_addr : *next_hop),
790 .frp_sw_if_index = next_hop_sw_if_index,
791 .frp_fib_index = next_hop_fib_index,
792 .frp_weight = next_hop_weight,
Neale Ranns57b58602017-07-15 07:37:25 -0700793 .frp_preference = next_hop_preference,
Dave Barachb5e8a772016-12-06 12:04:42 -0500794 .frp_label_stack = next_hop_out_label_stack,
795 };
796 fib_route_path_t *paths = NULL;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800797 fib_entry_flag_t entry_flags = FIB_ENTRY_FLAG_NONE;
Dave Barachb5e8a772016-12-06 12:04:42 -0500798
Neale Rannscaac3502017-09-18 18:04:10 -0700799 /*
800 * the special INVALID label meams we are not recursing via a
801 * label. Exp-null value is never a valid via-label so that
802 * also means it's not a via-label and means clients that set
803 * it to 0 by default get the expected behaviour
804 */
805 if ((MPLS_LABEL_INVALID != next_hop_via_label) && (0 != next_hop_via_label))
Dave Barachb5e8a772016-12-06 12:04:42 -0500806 {
Neale Rannsda78f952017-05-24 09:15:43 -0700807 path.frp_proto = DPO_PROTO_MPLS;
Dave Barachb5e8a772016-12-06 12:04:42 -0500808 path.frp_local_label = next_hop_via_label;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800809 path.frp_eos = MPLS_NON_EOS;
Dave Barachb5e8a772016-12-06 12:04:42 -0500810 }
Neale Rannsf068c3e2018-01-03 04:18:48 -0800811 if (is_dvr)
812 path_flags |= FIB_ROUTE_PATH_DVR;
Dave Barachb5e8a772016-12-06 12:04:42 -0500813 if (is_resolve_host)
814 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
815 if (is_resolve_attached)
816 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800817 if (is_interface_rx)
818 path_flags |= FIB_ROUTE_PATH_INTF_RX;
819 if (is_rpf_id)
820 path_flags |= FIB_ROUTE_PATH_RPF_ID;
Neale Ranns054c03a2017-10-13 05:15:07 -0700821 if (is_source_lookup)
822 path_flags |= FIB_ROUTE_PATH_SOURCE_LOOKUP;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800823 if (is_multicast)
824 entry_flags |= FIB_ENTRY_FLAG_MULTICAST;
Neale Ranns810086d2017-11-05 16:26:46 -0800825 if (is_udp_encap)
826 {
827 path_flags |= FIB_ROUTE_PATH_UDP_ENCAP;
828 path.frp_udp_encap_id = next_hop_id;
829 }
Florin Coras79ae2d32017-12-16 08:31:06 -0800830 if (path.frp_sw_if_index == ~0 && ip46_address_is_zero (&path.frp_addr)
831 && path.frp_fib_index != ~0)
832 {
833 path_flags |= FIB_ROUTE_PATH_DEAG;
834 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500835
836 path.frp_flags = path_flags;
837
Dave Barachb5e8a772016-12-06 12:04:42 -0500838 stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ );
839
840 if (is_drop || is_local || is_classify || is_unreach || is_prohibit)
841 {
842 /*
843 * special route types that link directly to the adj
844 */
845 if (is_add)
846 {
847 dpo_id_t dpo = DPO_INVALID;
848 dpo_proto_t dproto;
849
850 dproto = fib_proto_to_dpo (prefix->fp_proto);
851
852 if (is_drop)
853 ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo);
854 else if (is_local)
855 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
856 else if (is_unreach)
857 ip_null_dpo_add_and_lock (dproto,
858 IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo);
859 else if (is_prohibit)
860 ip_null_dpo_add_and_lock (dproto,
861 IP_NULL_ACTION_SEND_ICMP_PROHIBIT,
862 &dpo);
863 else if (is_classify)
864 {
865 if (pool_is_free_index (cm->tables,
866 ntohl (classify_table_index)))
867 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500868 stats_dsunlock ();
Dave Barachb5e8a772016-12-06 12:04:42 -0500869 return VNET_API_ERROR_NO_SUCH_TABLE;
870 }
871
872 dpo_set (&dpo, DPO_CLASSIFY, dproto,
873 classify_dpo_create (dproto,
874 ntohl (classify_table_index)));
875 }
876 else
877 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500878 stats_dsunlock ();
Dave Barachb5e8a772016-12-06 12:04:42 -0500879 return VNET_API_ERROR_NO_SUCH_TABLE;
880 }
881
882 fib_table_entry_special_dpo_update (fib_index,
883 prefix,
884 FIB_SOURCE_API,
885 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
886 dpo_reset (&dpo);
887 }
888 else
889 {
890 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
891 }
892 }
Neale Ranns3b93be52018-09-07 01:48:54 -0700893 else if (is_multipath)
894 {
895 vec_add1 (paths, path);
896
897 if (is_add)
898 fib_table_entry_path_add2 (fib_index,
899 prefix,
900 FIB_SOURCE_API, entry_flags, paths);
901 else
902 fib_table_entry_path_remove2 (fib_index,
903 prefix, FIB_SOURCE_API, paths);
904
905 vec_free (paths);
906 }
Dave Barachb5e8a772016-12-06 12:04:42 -0500907 else
908 {
909 if (is_add)
910 {
911 vec_add1 (paths, path);
912 fib_table_entry_update (fib_index,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800913 prefix, FIB_SOURCE_API, entry_flags, paths);
Dave Barachb5e8a772016-12-06 12:04:42 -0500914 vec_free (paths);
915 }
916 else
917 {
918 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
919 }
920 }
921
Dave Barachd7cb1b52016-12-09 09:52:16 -0500922 stats_dsunlock ();
Dave Barachb5e8a772016-12-06 12:04:42 -0500923 return (0);
924}
925
926int
927add_del_route_check (fib_protocol_t table_proto,
928 u32 table_id,
929 u32 next_hop_sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -0700930 dpo_proto_t next_hop_table_proto,
Dave Barachb5e8a772016-12-06 12:04:42 -0500931 u32 next_hop_table_id,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800932 u8 is_rpf_id, u32 * fib_index, u32 * next_hop_fib_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500933{
934 vnet_main_t *vnm = vnet_get_main ();
935
936 *fib_index = fib_table_find (table_proto, ntohl (table_id));
937 if (~0 == *fib_index)
938 {
Neale Rannsb93078d2018-01-25 07:48:12 -0800939 /* No such VRF, and we weren't asked to create one */
940 return VNET_API_ERROR_NO_SUCH_FIB;
Dave Barachb5e8a772016-12-06 12:04:42 -0500941 }
942
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800943 if (!is_rpf_id && ~0 != ntohl (next_hop_sw_if_index))
Dave Barachb5e8a772016-12-06 12:04:42 -0500944 {
945 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
946 ntohl (next_hop_sw_if_index)))
947 {
948 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
949 }
950 }
951 else
952 {
Neale Rannsda78f952017-05-24 09:15:43 -0700953 fib_protocol_t fib_nh_proto;
954
955 if (next_hop_table_proto > DPO_PROTO_MPLS)
956 return (0);
957
958 fib_nh_proto = dpo_proto_to_fib (next_hop_table_proto);
959
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800960 if (is_rpf_id)
Neale Rannsda78f952017-05-24 09:15:43 -0700961 *next_hop_fib_index = mfib_table_find (fib_nh_proto,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800962 ntohl (next_hop_table_id));
963 else
Neale Rannsda78f952017-05-24 09:15:43 -0700964 *next_hop_fib_index = fib_table_find (fib_nh_proto,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800965 ntohl (next_hop_table_id));
Dave Barachb5e8a772016-12-06 12:04:42 -0500966
967 if (~0 == *next_hop_fib_index)
968 {
Neale Rannsb93078d2018-01-25 07:48:12 -0800969 /* No such VRF, and we weren't asked to create one */
970 return VNET_API_ERROR_NO_SUCH_FIB;
Dave Barachb5e8a772016-12-06 12:04:42 -0500971 }
972 }
973
974 return (0);
975}
976
977static int
Neale Ranns008dbe12018-09-07 09:32:36 -0700978ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp,
979 u32 * stats_index)
Dave Barachb5e8a772016-12-06 12:04:42 -0500980{
981 u32 fib_index, next_hop_fib_index;
Neale Ranns31ed7442018-02-23 05:29:09 -0800982 fib_mpls_label_t *label_stack = NULL;
Dave Barachb5e8a772016-12-06 12:04:42 -0500983 int rv, ii, n_labels;;
984
985 rv = add_del_route_check (FIB_PROTOCOL_IP4,
986 mp->table_id,
987 mp->next_hop_sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -0700988 DPO_PROTO_IP4,
Dave Barachb5e8a772016-12-06 12:04:42 -0500989 mp->next_hop_table_id,
Neale Ranns15002542017-09-10 04:39:11 -0700990 0, &fib_index, &next_hop_fib_index);
Dave Barachb5e8a772016-12-06 12:04:42 -0500991
992 if (0 != rv)
993 return (rv);
994
995 fib_prefix_t pfx = {
996 .fp_len = mp->dst_address_length,
997 .fp_proto = FIB_PROTOCOL_IP4,
998 };
999 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
1000
1001 ip46_address_t nh;
Dave Barachb7b92992018-10-17 10:38:51 -04001002 clib_memset (&nh, 0, sizeof (nh));
Dave Barachb5e8a772016-12-06 12:04:42 -05001003 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
1004
1005 n_labels = mp->next_hop_n_out_labels;
1006 if (n_labels == 0)
1007 ;
Dave Barachb5e8a772016-12-06 12:04:42 -05001008 else
1009 {
1010 vec_validate (label_stack, n_labels - 1);
1011 for (ii = 0; ii < n_labels; ii++)
Neale Ranns31ed7442018-02-23 05:29:09 -08001012 {
1013 label_stack[ii].fml_value =
1014 ntohl (mp->next_hop_out_label_stack[ii].label);
1015 label_stack[ii].fml_ttl = mp->next_hop_out_label_stack[ii].ttl;
1016 label_stack[ii].fml_exp = mp->next_hop_out_label_stack[ii].exp;
1017 label_stack[ii].fml_mode =
1018 (mp->next_hop_out_label_stack[ii].is_uniform ?
1019 FIB_MPLS_LSP_MODE_UNIFORM : FIB_MPLS_LSP_MODE_PIPE);
1020 }
Dave Barachb5e8a772016-12-06 12:04:42 -05001021 }
1022
Neale Ranns008dbe12018-09-07 09:32:36 -07001023 rv = add_del_route_t_handler (mp->is_multipath,
1024 mp->is_add,
1025 mp->is_drop,
1026 mp->is_unreach,
1027 mp->is_prohibit,
1028 mp->is_local, 0,
1029 mp->is_classify,
1030 mp->classify_table_index,
1031 mp->is_resolve_host,
1032 mp->is_resolve_attached, 0, 0,
1033 mp->is_dvr,
1034 mp->is_source_lookup,
1035 mp->is_udp_encap,
1036 fib_index, &pfx, DPO_PROTO_IP4,
1037 &nh,
1038 ntohl (mp->next_hop_id),
1039 ntohl (mp->next_hop_sw_if_index),
1040 next_hop_fib_index,
1041 mp->next_hop_weight,
1042 mp->next_hop_preference,
1043 ntohl (mp->next_hop_via_label), label_stack);
1044
1045 if (mp->is_add && 0 == rv)
1046 *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx);
1047
1048 return (rv);
Dave Barachb5e8a772016-12-06 12:04:42 -05001049}
1050
Juraj Sloboda0012fcc2018-05-17 12:05:27 +02001051static int
Neale Ranns008dbe12018-09-07 09:32:36 -07001052ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp,
1053 u32 * stats_index)
Dave Barachb5e8a772016-12-06 12:04:42 -05001054{
Neale Ranns31ed7442018-02-23 05:29:09 -08001055 fib_mpls_label_t *label_stack = NULL;
Dave Barachb5e8a772016-12-06 12:04:42 -05001056 u32 fib_index, next_hop_fib_index;
Dave Barachb5e8a772016-12-06 12:04:42 -05001057 int rv, ii, n_labels;;
1058
1059 rv = add_del_route_check (FIB_PROTOCOL_IP6,
1060 mp->table_id,
1061 mp->next_hop_sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001062 DPO_PROTO_IP6,
Dave Barachb5e8a772016-12-06 12:04:42 -05001063 mp->next_hop_table_id,
Neale Ranns15002542017-09-10 04:39:11 -07001064 0, &fib_index, &next_hop_fib_index);
Dave Barachb5e8a772016-12-06 12:04:42 -05001065
1066 if (0 != rv)
1067 return (rv);
1068
1069 fib_prefix_t pfx = {
1070 .fp_len = mp->dst_address_length,
1071 .fp_proto = FIB_PROTOCOL_IP6,
1072 };
1073 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
1074
1075 ip46_address_t nh;
Dave Barachb7b92992018-10-17 10:38:51 -04001076 clib_memset (&nh, 0, sizeof (nh));
Dave Barachb5e8a772016-12-06 12:04:42 -05001077 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
1078
1079 n_labels = mp->next_hop_n_out_labels;
1080 if (n_labels == 0)
1081 ;
Dave Barachb5e8a772016-12-06 12:04:42 -05001082 else
1083 {
1084 vec_validate (label_stack, n_labels - 1);
1085 for (ii = 0; ii < n_labels; ii++)
Neale Ranns31ed7442018-02-23 05:29:09 -08001086 {
1087 label_stack[ii].fml_value =
1088 ntohl (mp->next_hop_out_label_stack[ii].label);
1089 label_stack[ii].fml_ttl = mp->next_hop_out_label_stack[ii].ttl;
1090 label_stack[ii].fml_exp = mp->next_hop_out_label_stack[ii].exp;
1091 label_stack[ii].fml_mode =
1092 (mp->next_hop_out_label_stack[ii].is_uniform ?
1093 FIB_MPLS_LSP_MODE_UNIFORM : FIB_MPLS_LSP_MODE_PIPE);
1094 }
Dave Barachb5e8a772016-12-06 12:04:42 -05001095 }
1096
Neale Ranns008dbe12018-09-07 09:32:36 -07001097 rv = add_del_route_t_handler (mp->is_multipath,
1098 mp->is_add,
1099 mp->is_drop,
1100 mp->is_unreach,
1101 mp->is_prohibit,
1102 mp->is_local, 0,
1103 mp->is_classify,
1104 mp->classify_table_index,
1105 mp->is_resolve_host,
1106 mp->is_resolve_attached, 0, 0,
1107 mp->is_dvr,
1108 mp->is_source_lookup,
1109 mp->is_udp_encap,
1110 fib_index, &pfx, DPO_PROTO_IP6,
1111 &nh, ntohl (mp->next_hop_id),
1112 ntohl (mp->next_hop_sw_if_index),
1113 next_hop_fib_index,
1114 mp->next_hop_weight,
1115 mp->next_hop_preference,
1116 ntohl (mp->next_hop_via_label), label_stack);
1117
1118 if (mp->is_add && 0 == rv)
1119 *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx);
1120
1121 return (rv);
Dave Barachb5e8a772016-12-06 12:04:42 -05001122}
1123
1124void
1125vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1126{
1127 vl_api_ip_add_del_route_reply_t *rmp;
Neale Ranns008dbe12018-09-07 09:32:36 -07001128 u32 stats_index;
Dave Barachb5e8a772016-12-06 12:04:42 -05001129 int rv;
1130 vnet_main_t *vnm = vnet_get_main ();
1131
1132 vnm->api_errno = 0;
Neale Ranns008dbe12018-09-07 09:32:36 -07001133 stats_index = ~0;
Dave Barachb5e8a772016-12-06 12:04:42 -05001134
1135 if (mp->is_ipv6)
Neale Ranns008dbe12018-09-07 09:32:36 -07001136 rv = ip6_add_del_route_t_handler (mp, &stats_index);
Dave Barachb5e8a772016-12-06 12:04:42 -05001137 else
Neale Ranns008dbe12018-09-07 09:32:36 -07001138 rv = ip4_add_del_route_t_handler (mp, &stats_index);
Dave Barachb5e8a772016-12-06 12:04:42 -05001139
1140 rv = (rv == 0) ? vnm->api_errno : rv;
1141
Neale Ranns008dbe12018-09-07 09:32:36 -07001142 /* *INDENT-OFF* */
1143 REPLY_MACRO2 (VL_API_IP_ADD_DEL_ROUTE_REPLY,
1144 ({
1145 rmp->stats_index = htonl (stats_index);
1146 }))
1147 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -05001148}
1149
Neale Ranns15002542017-09-10 04:39:11 -07001150void
Neale Ranns2297af02017-09-12 09:45:04 -07001151ip_table_create (fib_protocol_t fproto,
1152 u32 table_id, u8 is_api, const u8 * name)
Neale Ranns15002542017-09-10 04:39:11 -07001153{
1154 u32 fib_index, mfib_index;
1155
1156 /*
1157 * ignore action on the default table - this is always present
1158 * and cannot be added nor deleted from the API
1159 */
1160 if (0 != table_id)
1161 {
1162 /*
1163 * The API holds only one lock on the table.
1164 * i.e. it can be added many times via the API but needs to be
1165 * deleted only once.
1166 * The FIB index for unicast and multicast is not necessarily the
1167 * same, since internal VPP systesm (like LISP and SR) create
1168 * their own unicast tables.
1169 */
1170 fib_index = fib_table_find (fproto, table_id);
1171 mfib_index = mfib_table_find (fproto, table_id);
1172
1173 if (~0 == fib_index)
1174 {
Neale Ranns2297af02017-09-12 09:45:04 -07001175 fib_table_find_or_create_and_lock_w_name (fproto, table_id,
1176 (is_api ?
1177 FIB_SOURCE_API :
1178 FIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -07001179 }
1180 if (~0 == mfib_index)
1181 {
Neale Ranns2297af02017-09-12 09:45:04 -07001182 mfib_table_find_or_create_and_lock_w_name (fproto, table_id,
1183 (is_api ?
1184 MFIB_SOURCE_API :
1185 MFIB_SOURCE_CLI), name);
Neale Ranns15002542017-09-10 04:39:11 -07001186 }
1187 }
1188}
1189
Neale Ranns32e1c012016-11-22 17:07:28 +00001190static int
1191add_del_mroute_check (fib_protocol_t table_proto,
1192 u32 table_id,
Neale Ranns15002542017-09-10 04:39:11 -07001193 u32 next_hop_sw_if_index, u8 is_local, u32 * fib_index)
Neale Ranns32e1c012016-11-22 17:07:28 +00001194{
1195 vnet_main_t *vnm = vnet_get_main ();
1196
1197 *fib_index = mfib_table_find (table_proto, ntohl (table_id));
1198 if (~0 == *fib_index)
1199 {
Neale Ranns15002542017-09-10 04:39:11 -07001200 /* No such table */
1201 return VNET_API_ERROR_NO_SUCH_FIB;
Neale Ranns32e1c012016-11-22 17:07:28 +00001202 }
1203
1204 if (~0 != ntohl (next_hop_sw_if_index))
1205 {
1206 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1207 ntohl (next_hop_sw_if_index)))
1208 {
1209 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1210 }
1211 }
1212
1213 return (0);
1214}
1215
Neale Ranns28c142e2018-09-07 09:37:07 -07001216static fib_node_index_t
Neale Ranns32e1c012016-11-22 17:07:28 +00001217mroute_add_del_handler (u8 is_add,
1218 u8 is_local,
1219 u32 fib_index,
1220 const mfib_prefix_t * prefix,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001221 dpo_proto_t nh_proto,
Neale Ranns32e1c012016-11-22 17:07:28 +00001222 u32 entry_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001223 fib_rpf_id_t rpf_id,
Neale Rannse821ab12017-06-01 07:45:05 -07001224 u32 next_hop_sw_if_index,
1225 ip46_address_t * nh, u32 itf_flags, u32 bier_imp)
Neale Ranns32e1c012016-11-22 17:07:28 +00001226{
Neale Ranns28c142e2018-09-07 09:37:07 -07001227 fib_node_index_t mfib_entry_index = ~0;
1228
Neale Ranns32e1c012016-11-22 17:07:28 +00001229 stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ );
1230
1231 fib_route_path_t path = {
1232 .frp_sw_if_index = next_hop_sw_if_index,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001233 .frp_proto = nh_proto,
Neale Rannse821ab12017-06-01 07:45:05 -07001234 .frp_addr = *nh,
Neale Ranns32e1c012016-11-22 17:07:28 +00001235 };
1236
1237 if (is_local)
1238 path.frp_flags |= FIB_ROUTE_PATH_LOCAL;
1239
Neale Rannsd792d9c2017-10-21 10:53:20 -07001240 if (DPO_PROTO_BIER == nh_proto)
1241 {
1242 path.frp_bier_imp = bier_imp;
1243 path.frp_flags = FIB_ROUTE_PATH_BIER_IMP;
1244 }
1245 else if (!is_local && ~0 == next_hop_sw_if_index)
Neale Ranns32e1c012016-11-22 17:07:28 +00001246 {
Neale Ranns28c142e2018-09-07 09:37:07 -07001247 mfib_entry_index = mfib_table_entry_update (fib_index, prefix,
1248 MFIB_SOURCE_API,
1249 rpf_id, entry_flags);
Neale Rannsd792d9c2017-10-21 10:53:20 -07001250 goto done;
1251 }
1252
1253 if (is_add)
1254 {
Neale Ranns28c142e2018-09-07 09:37:07 -07001255 mfib_entry_index = mfib_table_entry_path_update (fib_index, prefix,
1256 MFIB_SOURCE_API,
1257 &path, itf_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +00001258 }
1259 else
1260 {
Neale Rannsd792d9c2017-10-21 10:53:20 -07001261 mfib_table_entry_path_remove (fib_index, prefix,
1262 MFIB_SOURCE_API, &path);
Neale Ranns32e1c012016-11-22 17:07:28 +00001263 }
1264
Neale Rannsd792d9c2017-10-21 10:53:20 -07001265done:
Neale Ranns32e1c012016-11-22 17:07:28 +00001266 stats_dsunlock ();
Neale Ranns28c142e2018-09-07 09:37:07 -07001267 return (mfib_entry_index);
Neale Ranns32e1c012016-11-22 17:07:28 +00001268}
1269
1270static int
Neale Ranns28c142e2018-09-07 09:37:07 -07001271api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp,
1272 u32 * stats_index)
Neale Ranns32e1c012016-11-22 17:07:28 +00001273{
Neale Ranns28c142e2018-09-07 09:37:07 -07001274 fib_node_index_t mfib_entry_index;
Neale Ranns32e1c012016-11-22 17:07:28 +00001275 fib_protocol_t fproto;
Neale Rannsd792d9c2017-10-21 10:53:20 -07001276 dpo_proto_t nh_proto;
Neale Rannse821ab12017-06-01 07:45:05 -07001277 ip46_address_t nh;
Neale Ranns32e1c012016-11-22 17:07:28 +00001278 u32 fib_index;
1279 int rv;
1280
Neale Rannsd792d9c2017-10-21 10:53:20 -07001281 nh_proto = mp->next_hop_afi;
Neale Ranns32e1c012016-11-22 17:07:28 +00001282 fproto = (mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1283 rv = add_del_mroute_check (fproto,
1284 mp->table_id,
1285 mp->next_hop_sw_if_index,
Neale Ranns15002542017-09-10 04:39:11 -07001286 mp->is_local, &fib_index);
Neale Ranns32e1c012016-11-22 17:07:28 +00001287
1288 if (0 != rv)
1289 return (rv);
1290
1291 mfib_prefix_t pfx = {
1292 .fp_len = ntohs (mp->grp_address_length),
1293 .fp_proto = fproto,
1294 };
1295
1296 if (FIB_PROTOCOL_IP4 == fproto)
1297 {
1298 clib_memcpy (&pfx.fp_grp_addr.ip4, mp->grp_address,
1299 sizeof (pfx.fp_grp_addr.ip4));
1300 clib_memcpy (&pfx.fp_src_addr.ip4, mp->src_address,
1301 sizeof (pfx.fp_src_addr.ip4));
Dave Barachb7b92992018-10-17 10:38:51 -04001302 clib_memset (&nh.ip6, 0, sizeof (nh.ip6));
Neale Rannse821ab12017-06-01 07:45:05 -07001303 clib_memcpy (&nh.ip4, mp->nh_address, sizeof (nh.ip4));
Neale Ranns3e42ebe2018-10-04 08:36:56 -07001304 if (!ip46_address_is_zero (&pfx.fp_src_addr))
1305 pfx.fp_len = 64;
Neale Ranns32e1c012016-11-22 17:07:28 +00001306 }
1307 else
1308 {
1309 clib_memcpy (&pfx.fp_grp_addr.ip6, mp->grp_address,
1310 sizeof (pfx.fp_grp_addr.ip6));
1311 clib_memcpy (&pfx.fp_src_addr.ip6, mp->src_address,
1312 sizeof (pfx.fp_src_addr.ip6));
Neale Rannse821ab12017-06-01 07:45:05 -07001313 clib_memcpy (&nh.ip6, mp->nh_address, sizeof (nh.ip6));
Neale Ranns3e42ebe2018-10-04 08:36:56 -07001314 if (!ip46_address_is_zero (&pfx.fp_src_addr))
1315 pfx.fp_len = 256;
Neale Ranns32e1c012016-11-22 17:07:28 +00001316 }
1317
Neale Ranns28c142e2018-09-07 09:37:07 -07001318 mfib_entry_index = mroute_add_del_handler (mp->is_add,
1319 mp->is_local,
1320 fib_index, &pfx,
1321 nh_proto,
1322 ntohl (mp->entry_flags),
1323 ntohl (mp->rpf_id),
1324 ntohl (mp->next_hop_sw_if_index),
1325 &nh,
1326 ntohl (mp->itf_flags),
1327 ntohl (mp->bier_imp));
1328
1329 if (~0 != mfib_entry_index)
1330 *stats_index = mfib_entry_get_stats_index (mfib_entry_index);
1331
1332 return (rv);
Neale Ranns32e1c012016-11-22 17:07:28 +00001333}
1334
1335void
1336vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp)
1337{
1338 vl_api_ip_mroute_add_del_reply_t *rmp;
Neale Ranns28c142e2018-09-07 09:37:07 -07001339 vnet_main_t *vnm;
1340 u32 stats_index;
Neale Ranns32e1c012016-11-22 17:07:28 +00001341 int rv;
Neale Ranns32e1c012016-11-22 17:07:28 +00001342
Neale Ranns28c142e2018-09-07 09:37:07 -07001343 vnm = vnet_get_main ();
Neale Ranns32e1c012016-11-22 17:07:28 +00001344 vnm->api_errno = 0;
Neale Ranns28c142e2018-09-07 09:37:07 -07001345 stats_index = ~0;
Neale Ranns32e1c012016-11-22 17:07:28 +00001346
Neale Ranns28c142e2018-09-07 09:37:07 -07001347 rv = api_mroute_add_del_t_handler (mp, &stats_index);
Neale Ranns32e1c012016-11-22 17:07:28 +00001348
Neale Ranns28c142e2018-09-07 09:37:07 -07001349 /* *INDENT-OFF* */
1350 REPLY_MACRO2 (VL_API_IP_MROUTE_ADD_DEL_REPLY,
1351 ({
1352 rmp->stats_index = htonl (stats_index);
1353 }));
1354 /* *INDENT-ON* */
Neale Ranns32e1c012016-11-22 17:07:28 +00001355}
1356
Dave Barachb5e8a772016-12-06 12:04:42 -05001357static void
1358send_ip_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -08001359 vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6,
1360 u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -05001361{
1362 vl_api_ip_details_t *mp;
1363
1364 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04001365 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -05001366 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
1367
1368 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger466f0d42017-02-09 12:17:50 -06001369 mp->is_ipv6 = is_ipv6;
Dave Barachb5e8a772016-12-06 12:04:42 -05001370 mp->context = context;
1371
Florin Coras6c4dae22018-01-09 06:39:23 -08001372 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -05001373}
1374
1375static void
1376send_ip_address_details (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -08001377 vl_api_registration_t * reg,
Jon Loeliger466f0d42017-02-09 12:17:50 -06001378 u8 * ip, u16 prefix_length,
1379 u32 sw_if_index, u8 is_ipv6, u32 context)
Dave Barachb5e8a772016-12-06 12:04:42 -05001380{
1381 vl_api_ip_address_details_t *mp;
1382
1383 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04001384 clib_memset (mp, 0, sizeof (*mp));
Dave Barachb5e8a772016-12-06 12:04:42 -05001385 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
1386
1387 if (is_ipv6)
1388 {
1389 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
1390 }
1391 else
1392 {
1393 u32 *tp = (u32 *) mp->ip;
1394 *tp = *(u32 *) ip;
1395 }
1396 mp->prefix_length = prefix_length;
1397 mp->context = context;
Jon Loeliger466f0d42017-02-09 12:17:50 -06001398 mp->sw_if_index = htonl (sw_if_index);
1399 mp->is_ipv6 = is_ipv6;
Dave Barachb5e8a772016-12-06 12:04:42 -05001400
Florin Coras6c4dae22018-01-09 06:39:23 -08001401 vl_api_send_msg (reg, (u8 *) mp);
Dave Barachb5e8a772016-12-06 12:04:42 -05001402}
1403
1404static void
1405vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
1406{
1407 vpe_api_main_t *am = &vpe_api_main;
Florin Coras6c4dae22018-01-09 06:39:23 -08001408 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -05001409 ip6_address_t *r6;
1410 ip4_address_t *r4;
1411 ip6_main_t *im6 = &ip6_main;
1412 ip4_main_t *im4 = &ip4_main;
1413 ip_lookup_main_t *lm6 = &im6->lookup_main;
1414 ip_lookup_main_t *lm4 = &im4->lookup_main;
1415 ip_interface_address_t *ia = 0;
1416 u32 sw_if_index = ~0;
1417 int rv __attribute__ ((unused)) = 0;
1418
1419 VALIDATE_SW_IF_INDEX (mp);
1420
1421 sw_if_index = ntohl (mp->sw_if_index);
1422
Florin Coras6c4dae22018-01-09 06:39:23 -08001423 reg = vl_api_client_index_to_registration (mp->client_index);
1424 if (!reg)
Dave Barachb5e8a772016-12-06 12:04:42 -05001425 return;
1426
Dave Barachb5e8a772016-12-06 12:04:42 -05001427 if (mp->is_ipv6)
1428 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001429 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -07001430 /* Do not send subnet details of the IP-interface for
1431 * unnumbered interfaces. otherwise listening clients
1432 * will be confused that the subnet is applied on more
1433 * than one interface */
1434 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -05001435 ({
1436 r6 = ip_interface_address_get_address (lm6, ia);
1437 u16 prefix_length = ia->address_length;
Florin Coras6c4dae22018-01-09 06:39:23 -08001438 send_ip_address_details(am, reg, (u8*)r6, prefix_length,
Jon Loeliger466f0d42017-02-09 12:17:50 -06001439 sw_if_index, 1, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -05001440 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -05001441 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -05001442 }
Dave Barachb5e8a772016-12-06 12:04:42 -05001443 else
1444 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001445 /* *INDENT-OFF* */
Neale Ranns4f2db7d2018-05-17 09:38:13 -07001446 foreach_ip_interface_address (lm4, ia, sw_if_index, 0,
Dave Barachb5e8a772016-12-06 12:04:42 -05001447 ({
1448 r4 = ip_interface_address_get_address (lm4, ia);
1449 u16 prefix_length = ia->address_length;
Florin Coras6c4dae22018-01-09 06:39:23 -08001450 send_ip_address_details(am, reg, (u8*)r4, prefix_length,
Jon Loeliger466f0d42017-02-09 12:17:50 -06001451 sw_if_index, 0, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -05001452 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -05001453 /* *INDENT-ON* */
Dave Barachb5e8a772016-12-06 12:04:42 -05001454 }
Neale Ranns008dbe12018-09-07 09:32:36 -07001455
Dave Barachb5e8a772016-12-06 12:04:42 -05001456 BAD_SW_IF_INDEX_LABEL;
1457}
1458
1459static void
Neale Ranns9e2f9152018-05-18 02:27:10 -07001460send_ip_unnumbered_details (vpe_api_main_t * am,
1461 vl_api_registration_t * reg,
1462 u32 sw_if_index, u32 ip_sw_if_index, u32 context)
1463{
1464 vl_api_ip_unnumbered_details_t *mp;
1465
1466 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04001467 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns9e2f9152018-05-18 02:27:10 -07001468 mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
1469
1470 mp->context = context;
1471 mp->sw_if_index = htonl (sw_if_index);
1472 mp->ip_sw_if_index = htonl (ip_sw_if_index);
1473
1474 vl_api_send_msg (reg, (u8 *) mp);
1475}
1476
1477static void
1478vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
1479{
1480 vnet_main_t *vnm = vnet_get_main ();
1481 vnet_interface_main_t *im = &vnm->interface_main;
1482 int rv __attribute__ ((unused)) = 0;
1483 vpe_api_main_t *am = &vpe_api_main;
1484 vl_api_registration_t *reg;
1485 vnet_sw_interface_t *si;
1486 u32 sw_if_index;
1487
1488 sw_if_index = ntohl (mp->sw_if_index);
1489
1490 reg = vl_api_client_index_to_registration (mp->client_index);
1491 if (!reg)
1492 return;
1493
1494 if (~0 != sw_if_index)
1495 {
1496 VALIDATE_SW_IF_INDEX (mp);
1497
1498 si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
1499
1500 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1501 {
1502 send_ip_unnumbered_details (am, reg,
1503 sw_if_index,
1504 si->unnumbered_sw_if_index,
1505 mp->context);
1506 }
1507 }
1508 else
1509 {
1510 /* *INDENT-OFF* */
1511 pool_foreach (si, im->sw_interfaces,
1512 ({
1513 if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1514 {
1515 send_ip_unnumbered_details(am, reg,
1516 si->sw_if_index,
1517 si->unnumbered_sw_if_index,
1518 mp->context);
1519 }
1520 }));
1521 /* *INDENT-ON* */
1522 }
1523
1524 BAD_SW_IF_INDEX_LABEL;
1525}
1526
1527static void
Dave Barachb5e8a772016-12-06 12:04:42 -05001528vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
1529{
1530 vpe_api_main_t *am = &vpe_api_main;
1531 vnet_main_t *vnm = vnet_get_main ();
1532 vlib_main_t *vm = vlib_get_main ();
1533 vnet_interface_main_t *im = &vnm->interface_main;
Florin Coras6c4dae22018-01-09 06:39:23 -08001534 vl_api_registration_t *reg;
Dave Barachb5e8a772016-12-06 12:04:42 -05001535 vnet_sw_interface_t *si, *sorted_sis;
1536 u32 sw_if_index = ~0;
1537
Florin Coras6c4dae22018-01-09 06:39:23 -08001538 reg = vl_api_client_index_to_registration (mp->client_index);
1539 if (!reg)
1540 return;
Dave Barachb5e8a772016-12-06 12:04:42 -05001541
1542 /* Gather interfaces. */
1543 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1544 _vec_len (sorted_sis) = 0;
1545 /* *INDENT-OFF* */
1546 pool_foreach (si, im->sw_interfaces,
1547 ({
1548 vec_add1 (sorted_sis, si[0]);
1549 }));
1550 /* *INDENT-ON* */
1551
1552 vec_foreach (si, sorted_sis)
1553 {
1554 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1555 {
1556 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
1557 {
1558 continue;
1559 }
1560 sw_if_index = si->sw_if_index;
Florin Coras6c4dae22018-01-09 06:39:23 -08001561 send_ip_details (am, reg, sw_if_index, mp->is_ipv6, mp->context);
Dave Barachb5e8a772016-12-06 12:04:42 -05001562 }
1563 }
1564}
1565
1566static void
1567set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
1568{
1569 vl_api_set_ip_flow_hash_reply_t *rmp;
Neale Ranns227038a2017-04-21 01:07:59 -07001570 int rv;
1571 u32 table_id;
1572 flow_hash_config_t flow_hash_config = 0;
Dave Barachb5e8a772016-12-06 12:04:42 -05001573
Neale Ranns227038a2017-04-21 01:07:59 -07001574 table_id = ntohl (mp->vrf_id);
1575
1576#define _(a,b) if (mp->a) flow_hash_config |= b;
1577 foreach_flow_hash_bit;
1578#undef _
1579
1580 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
Dave Barachb5e8a772016-12-06 12:04:42 -05001581
1582 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1583}
1584
1585static void
1586set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
1587{
1588 vl_api_set_ip_flow_hash_reply_t *rmp;
1589 int rv;
1590 u32 table_id;
1591 flow_hash_config_t flow_hash_config = 0;
1592
1593 table_id = ntohl (mp->vrf_id);
1594
1595#define _(a,b) if (mp->a) flow_hash_config |= b;
1596 foreach_flow_hash_bit;
1597#undef _
1598
1599 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
1600
1601 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1602}
1603
1604
1605static void
1606vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
1607{
1608 if (mp->is_ipv6 == 0)
1609 set_ip4_flow_hash (mp);
1610 else
1611 set_ip6_flow_hash (mp);
1612}
1613
1614static void
1615 vl_api_sw_interface_ip6nd_ra_config_t_handler
1616 (vl_api_sw_interface_ip6nd_ra_config_t * mp)
1617{
1618 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
1619 vlib_main_t *vm = vlib_get_main ();
1620 int rv = 0;
1621 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
1622 default_router;
1623
1624 is_no = mp->is_no == 1;
1625 suppress = mp->suppress == 1;
1626 managed = mp->managed == 1;
1627 other = mp->other == 1;
1628 ll_option = mp->ll_option == 1;
1629 send_unicast = mp->send_unicast == 1;
1630 cease = mp->cease == 1;
1631 default_router = mp->default_router == 1;
1632
1633 VALIDATE_SW_IF_INDEX (mp);
1634
1635 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
1636 suppress, managed, other,
1637 ll_option, send_unicast, cease,
1638 default_router, ntohl (mp->lifetime),
1639 ntohl (mp->initial_count),
1640 ntohl (mp->initial_interval),
1641 ntohl (mp->max_interval),
1642 ntohl (mp->min_interval), is_no);
1643
1644 BAD_SW_IF_INDEX_LABEL;
1645
1646 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
1647}
1648
1649static void
1650 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
1651 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp)
1652{
1653 vlib_main_t *vm = vlib_get_main ();
1654 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
1655 int rv = 0;
1656 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
1657
1658 VALIDATE_SW_IF_INDEX (mp);
1659
1660 is_no = mp->is_no == 1;
1661 use_default = mp->use_default == 1;
1662 no_advertise = mp->no_advertise == 1;
1663 off_link = mp->off_link == 1;
1664 no_autoconfig = mp->no_autoconfig == 1;
1665 no_onlink = mp->no_onlink == 1;
1666
1667 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
1668 (ip6_address_t *) mp->address,
1669 mp->address_length, use_default,
1670 ntohl (mp->val_lifetime),
1671 ntohl (mp->pref_lifetime), no_advertise,
1672 off_link, no_autoconfig, no_onlink, is_no);
1673
1674 BAD_SW_IF_INDEX_LABEL;
1675 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
1676}
1677
1678static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001679send_ip6nd_proxy_details (vl_api_registration_t * reg,
Neale Ranns3f844d02017-02-18 00:03:54 -08001680 u32 context,
1681 const ip46_address_t * addr, u32 sw_if_index)
1682{
1683 vl_api_ip6nd_proxy_details_t *mp;
1684
1685 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04001686 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns3f844d02017-02-18 00:03:54 -08001687 mp->_vl_msg_id = ntohs (VL_API_IP6ND_PROXY_DETAILS);
1688 mp->context = context;
1689 mp->sw_if_index = htonl (sw_if_index);
1690 memcpy (mp->address, addr, 16);
1691
Florin Coras6c4dae22018-01-09 06:39:23 -08001692 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns3f844d02017-02-18 00:03:54 -08001693}
1694
Neale Ranns3f844d02017-02-18 00:03:54 -08001695typedef struct api_ip6nd_proxy_fib_table_walk_ctx_t_
1696{
1697 u32 *indices;
1698} api_ip6nd_proxy_fib_table_walk_ctx_t;
1699
Neale Ranns89541992017-04-06 04:41:02 -07001700static fib_table_walk_rc_t
Neale Ranns3f844d02017-02-18 00:03:54 -08001701api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg)
1702{
1703 api_ip6nd_proxy_fib_table_walk_ctx_t *ctx = arg;
1704
1705 if (fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND_PROXY))
1706 {
1707 vec_add1 (ctx->indices, fei);
1708 }
1709
Neale Ranns89541992017-04-06 04:41:02 -07001710 return (FIB_TABLE_WALK_CONTINUE);
Neale Ranns3f844d02017-02-18 00:03:54 -08001711}
1712
1713static void
1714vl_api_ip6nd_proxy_dump_t_handler (vl_api_ip6nd_proxy_dump_t * mp)
1715{
1716 ip6_main_t *im6 = &ip6_main;
1717 fib_table_t *fib_table;
1718 api_ip6nd_proxy_fib_table_walk_ctx_t ctx = {
1719 .indices = NULL,
1720 };
1721 fib_node_index_t *feip;
Neale Rannsc5d43172018-07-30 08:04:40 -07001722 const fib_prefix_t *pfx;
Florin Coras6c4dae22018-01-09 06:39:23 -08001723 vl_api_registration_t *reg;
Neale Ranns3f844d02017-02-18 00:03:54 -08001724
Florin Coras6c4dae22018-01-09 06:39:23 -08001725 reg = vl_api_client_index_to_registration (mp->client_index);
1726 if (!reg)
1727 return;
Neale Ranns3f844d02017-02-18 00:03:54 -08001728
1729 /* *INDENT-OFF* */
1730 pool_foreach (fib_table, im6->fibs,
1731 ({
1732 fib_table_walk(fib_table->ft_index,
1733 FIB_PROTOCOL_IP6,
1734 api_ip6nd_proxy_fib_table_walk,
1735 &ctx);
1736 }));
1737 /* *INDENT-ON* */
1738
1739 vec_sort_with_function (ctx.indices, fib_entry_cmp_for_sort);
1740
1741 vec_foreach (feip, ctx.indices)
1742 {
Neale Rannsc5d43172018-07-30 08:04:40 -07001743 pfx = fib_entry_get_prefix (*feip);
Neale Ranns3f844d02017-02-18 00:03:54 -08001744
Florin Coras6c4dae22018-01-09 06:39:23 -08001745 send_ip6nd_proxy_details (reg,
Neale Ranns3f844d02017-02-18 00:03:54 -08001746 mp->context,
Neale Rannsc5d43172018-07-30 08:04:40 -07001747 &pfx->fp_addr,
Neale Ranns3f844d02017-02-18 00:03:54 -08001748 fib_entry_get_resolving_interface (*feip));
1749 }
1750
1751 vec_free (ctx.indices);
1752}
1753
1754static void
1755vl_api_ip6nd_proxy_add_del_t_handler (vl_api_ip6nd_proxy_add_del_t * mp)
1756{
1757 vl_api_ip6nd_proxy_add_del_reply_t *rmp;
1758 int rv = 0;
1759
1760 VALIDATE_SW_IF_INDEX (mp);
1761
1762 rv = ip6_neighbor_proxy_add_del (ntohl (mp->sw_if_index),
1763 (ip6_address_t *) mp->address, mp->is_del);
1764
1765 BAD_SW_IF_INDEX_LABEL;
1766 REPLY_MACRO (VL_API_IP6ND_PROXY_ADD_DEL_REPLY);
1767}
1768
1769static void
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001770 vl_api_ip6nd_send_router_solicitation_t_handler
1771 (vl_api_ip6nd_send_router_solicitation_t * mp)
1772{
1773 vl_api_ip6nd_send_router_solicitation_reply_t *rmp;
1774 icmp6_send_router_solicitation_params_t params;
1775 vlib_main_t *vm = vlib_get_main ();
1776 int rv = 0;
1777
1778 VALIDATE_SW_IF_INDEX (mp);
1779
1780 BAD_SW_IF_INDEX_LABEL;
1781 REPLY_MACRO (VL_API_IP6ND_SEND_ROUTER_SOLICITATION_REPLY);
1782
1783 if (rv != 0)
1784 return;
1785
1786 params.irt = ntohl (mp->irt);
1787 params.mrt = ntohl (mp->mrt);
1788 params.mrc = ntohl (mp->mrc);
1789 params.mrd = ntohl (mp->mrd);
1790
1791 icmp6_send_router_solicitation (vm, ntohl (mp->sw_if_index), mp->stop,
1792 &params);
1793}
1794
1795static void
Dave Barachb5e8a772016-12-06 12:04:42 -05001796 vl_api_sw_interface_ip6_enable_disable_t_handler
1797 (vl_api_sw_interface_ip6_enable_disable_t * mp)
1798{
1799 vlib_main_t *vm = vlib_get_main ();
1800 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
1801 vnet_main_t *vnm = vnet_get_main ();
1802 int rv = 0;
1803 clib_error_t *error;
1804
1805 vnm->api_errno = 0;
1806
1807 VALIDATE_SW_IF_INDEX (mp);
1808
1809 error =
1810 (mp->enable == 1) ? enable_ip6_interface (vm,
1811 ntohl (mp->sw_if_index)) :
1812 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
1813
1814 if (error)
1815 {
1816 clib_error_report (error);
1817 rv = VNET_API_ERROR_UNSPECIFIED;
1818 }
1819 else
1820 {
1821 rv = vnm->api_errno;
1822 }
1823
1824 BAD_SW_IF_INDEX_LABEL;
1825
1826 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
1827}
1828
Neale Ranns32e1c012016-11-22 17:07:28 +00001829void
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001830vl_mfib_signal_send_one (vl_api_registration_t * reg,
Neale Ranns32e1c012016-11-22 17:07:28 +00001831 u32 context, const mfib_signal_t * mfs)
1832{
1833 vl_api_mfib_signal_details_t *mp;
1834 mfib_prefix_t prefix;
1835 mfib_table_t *mfib;
1836 mfib_itf_t *mfi;
1837
1838 mp = vl_msg_api_alloc (sizeof (*mp));
1839
Dave Barachb7b92992018-10-17 10:38:51 -04001840 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns32e1c012016-11-22 17:07:28 +00001841 mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS);
1842 mp->context = context;
1843
1844 mfi = mfib_itf_get (mfs->mfs_itf);
1845 mfib_entry_get_prefix (mfs->mfs_entry, &prefix);
1846 mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry),
1847 prefix.fp_proto);
1848 mp->table_id = ntohl (mfib->mft_table_id);
1849 mp->sw_if_index = ntohl (mfi->mfi_sw_if_index);
1850
1851 if (FIB_PROTOCOL_IP4 == prefix.fp_proto)
1852 {
1853 mp->grp_address_len = ntohs (prefix.fp_len);
1854
1855 memcpy (mp->grp_address, &prefix.fp_grp_addr.ip4, 4);
1856 if (prefix.fp_len > 32)
1857 {
1858 memcpy (mp->src_address, &prefix.fp_src_addr.ip4, 4);
1859 }
1860 }
1861 else
1862 {
1863 mp->grp_address_len = ntohs (prefix.fp_len);
1864
1865 ASSERT (0);
1866 }
1867
1868 if (0 != mfs->mfs_buffer_len)
1869 {
1870 mp->ip_packet_len = ntohs (mfs->mfs_buffer_len);
1871
1872 memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len);
1873 }
1874 else
1875 {
1876 mp->ip_packet_len = 0;
1877 }
1878
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001879 vl_api_send_msg (reg, (u8 *) mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00001880}
1881
1882static void
1883vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
1884{
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001885 vl_api_registration_t *reg;
Neale Ranns32e1c012016-11-22 17:07:28 +00001886
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001887 reg = vl_api_client_index_to_registration (mp->client_index);
1888 if (!reg)
1889 return;
Neale Ranns32e1c012016-11-22 17:07:28 +00001890
Florin Corasaf0ff5a2018-01-10 08:17:03 -08001891 while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
Neale Ranns32e1c012016-11-22 17:07:28 +00001892 ;
1893}
Dave Barachb5e8a772016-12-06 12:04:42 -05001894
Florin Coras595992c2017-11-06 17:17:08 -08001895static void
1896 vl_api_ip_container_proxy_add_del_t_handler
1897 (vl_api_ip_container_proxy_add_del_t * mp)
1898{
1899 vl_api_ip_container_proxy_add_del_reply_t *rmp;
1900 vnet_ip_container_proxy_args_t args;
1901 int rv = 0;
1902 clib_error_t *error;
1903
Dave Barachb7b92992018-10-17 10:38:51 -04001904 clib_memset (&args, 0, sizeof (args));
Florin Coras595992c2017-11-06 17:17:08 -08001905 ip_set (&args.prefix.fp_addr, mp->ip, mp->is_ip4);
1906 args.prefix.fp_len = mp->plen ? mp->plen : (mp->is_ip4 ? 32 : 128);
1907 args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1908 args.is_add = mp->is_add;
1909 if ((error = vnet_ip_container_proxy_add_del (&args)))
1910 {
1911 rv = clib_error_get_code (error);
1912 clib_error_report (error);
1913 }
1914
1915 REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
1916}
1917
Matus Fabian75b9f452018-10-02 23:27:21 -07001918typedef struct ip_container_proxy_walk_ctx_t_
1919{
1920 vl_api_registration_t *reg;
1921 u32 context;
1922} ip_container_proxy_walk_ctx_t;
1923
1924static int
1925ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
1926 void *args)
1927{
1928 vl_api_ip_container_proxy_details_t *mp;
1929 ip_container_proxy_walk_ctx_t *ctx = args;
1930
1931 mp = vl_msg_api_alloc (sizeof (*mp));
1932 if (!mp)
1933 return 1;
1934
Dave Barachb7b92992018-10-17 10:38:51 -04001935 clib_memset (mp, 0, sizeof (*mp));
Matus Fabian75b9f452018-10-02 23:27:21 -07001936 mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
1937 mp->context = ctx->context;
1938
1939 mp->sw_if_index = ntohl (sw_if_index);
1940 ip_prefix_encode (pfx, &mp->prefix);
1941
1942 vl_api_send_msg (ctx->reg, (u8 *) mp);
1943
1944 return 1;
1945}
1946
1947static void
1948vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t *
1949 mp)
1950{
1951 vl_api_registration_t *reg;
1952
1953 reg = vl_api_client_index_to_registration (mp->client_index);
1954 if (!reg)
1955 return;
1956
1957 ip_container_proxy_walk_ctx_t ctx = {
1958 .context = mp->context,
1959 .reg = reg,
1960 };
1961
1962 ip_container_proxy_walk (ip_container_proxy_send_details, &ctx);
1963}
1964
Neale Rannsb8d44812017-11-10 06:53:54 -08001965static void
1966vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1967{
1968 int rv = 0;
1969 vl_api_ioam_enable_reply_t *rmp;
1970 clib_error_t *error;
1971
1972 /* Ignoring the profile id as currently a single profile
1973 * is supported */
1974 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1975 mp->seqno, mp->analyse);
1976 if (error)
1977 {
1978 clib_error_report (error);
1979 rv = clib_error_get_code (error);
1980 }
1981
1982 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1983}
1984
1985static void
1986vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1987{
1988 int rv = 0;
1989 vl_api_ioam_disable_reply_t *rmp;
1990 clib_error_t *error;
1991
1992 error = clear_ioam_rewrite_fn ();
1993 if (error)
1994 {
1995 clib_error_report (error);
1996 rv = clib_error_get_code (error);
1997 }
1998
1999 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
2000}
2001
2002static void
2003 vl_api_ip_source_and_port_range_check_add_del_t_handler
2004 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
2005{
2006 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
2007 int rv = 0;
2008
2009 u8 is_ipv6 = mp->is_ipv6;
2010 u8 is_add = mp->is_add;
2011 u8 mask_length = mp->mask_length;
2012 ip4_address_t ip4_addr;
2013 ip6_address_t ip6_addr;
2014 u16 *low_ports = 0;
2015 u16 *high_ports = 0;
2016 u32 vrf_id;
2017 u16 tmp_low, tmp_high;
2018 u8 num_ranges;
2019 int i;
2020
2021 // Validate port range
2022 num_ranges = mp->number_of_ranges;
2023 if (num_ranges > 32)
2024 { // This is size of array in VPE.API
2025 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
2026 goto reply;
2027 }
2028
2029 vec_reset_length (low_ports);
2030 vec_reset_length (high_ports);
2031
2032 for (i = 0; i < num_ranges; i++)
2033 {
2034 tmp_low = mp->low_ports[i];
2035 tmp_high = mp->high_ports[i];
2036 // If tmp_low <= tmp_high then only need to check tmp_low = 0
2037 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
2038 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
2039 {
2040 rv = VNET_API_ERROR_INVALID_VALUE;
2041 goto reply;
2042 }
2043 vec_add1 (low_ports, tmp_low);
2044 vec_add1 (high_ports, tmp_high + 1);
2045 }
2046
2047 // Validate mask_length
2048 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
2049 {
2050 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
2051 goto reply;
2052 }
2053
2054 vrf_id = ntohl (mp->vrf_id);
2055
2056 if (vrf_id < 1)
2057 {
2058 rv = VNET_API_ERROR_INVALID_VALUE;
2059 goto reply;
2060 }
2061
2062
2063 if (is_ipv6)
2064 {
2065 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
2066 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
2067 mask_length,
2068 vrf_id,
2069 low_ports,
2070 high_ports, is_add);
2071 }
2072 else
2073 {
2074 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
2075 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
2076 mask_length,
2077 vrf_id,
2078 low_ports,
2079 high_ports, is_add);
2080 }
2081
2082reply:
2083 vec_free (low_ports);
2084 vec_free (high_ports);
2085 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
2086}
2087
2088static void
2089 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
2090 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
2091{
2092 vlib_main_t *vm = vlib_get_main ();
2093 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
2094 ip4_main_t *im = &ip4_main;
2095 int rv;
2096 u32 sw_if_index;
2097 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2098 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2099 uword *p = 0;
2100 int i;
2101
2102 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
2103 ntohl (mp->tcp_out_vrf_id);
2104 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
2105 ntohl (mp->udp_out_vrf_id);
2106 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
2107 ntohl (mp->tcp_in_vrf_id);
2108 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
2109 ntohl (mp->udp_in_vrf_id);
2110
2111
2112 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
2113 {
2114 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
2115 {
2116 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
2117
2118 if (p == 0)
2119 {
2120 rv = VNET_API_ERROR_INVALID_VALUE;
2121 goto reply;
2122 }
2123
2124 fib_index[i] = p[0];
2125 }
2126 else
2127 fib_index[i] = ~0;
2128 }
2129 sw_if_index = ntohl (mp->sw_if_index);
2130
2131 VALIDATE_SW_IF_INDEX (mp);
2132
2133 rv =
2134 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
2135 mp->is_add);
2136
2137 BAD_SW_IF_INDEX_LABEL;
2138reply:
2139
2140 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
2141}
2142
2143#define IP4_ARP_EVENT 3
2144#define IP6_ND_EVENT 4
2145
2146static int arp_change_delete_callback (u32 pool_index, u8 * notused);
2147static int nd_change_delete_callback (u32 pool_index, u8 * notused);
2148static vlib_node_registration_t ip_resolver_process_node;
2149
2150static void
2151handle_ip4_arp_event (u32 pool_index)
2152{
2153 vpe_api_main_t *vam = &vpe_api_main;
2154 vnet_main_t *vnm = vam->vnet_main;
2155 vlib_main_t *vm = vam->vlib_main;
2156 vl_api_ip4_arp_event_t *event;
2157 vl_api_ip4_arp_event_t *mp;
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002158 vl_api_registration_t *reg;
Neale Rannsb8d44812017-11-10 06:53:54 -08002159
2160 /* Client can cancel, die, etc. */
2161 if (pool_is_free_index (vam->arp_events, pool_index))
2162 return;
2163
2164 event = pool_elt_at_index (vam->arp_events, pool_index);
2165
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002166 reg = vl_api_client_index_to_registration (event->client_index);
2167 if (!reg)
Neale Rannsb8d44812017-11-10 06:53:54 -08002168 {
2169 (void) vnet_add_del_ip4_arp_change_event
2170 (vnm, arp_change_delete_callback,
2171 event->pid, &event->address,
2172 ip_resolver_process_node.index, IP4_ARP_EVENT,
2173 ~0 /* pool index, notused */ , 0 /* is_add */ );
2174 return;
2175 }
2176
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002177 if (vl_api_can_send_msg (reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08002178 {
2179 mp = vl_msg_api_alloc (sizeof (*mp));
2180 clib_memcpy (mp, event, sizeof (*mp));
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002181 vl_api_send_msg (reg, (u8 *) mp);
Neale Rannsb8d44812017-11-10 06:53:54 -08002182 }
2183 else
2184 {
2185 static f64 last_time;
2186 /*
2187 * Throttle syslog msgs.
2188 * It's pretty tempting to just revoke the registration...
2189 */
2190 if (vlib_time_now (vm) > last_time + 10.0)
2191 {
2192 clib_warning ("arp event for %U to pid %d: queue stuffed!",
2193 format_ip4_address, &event->address, event->pid);
2194 last_time = vlib_time_now (vm);
2195 }
2196 }
2197}
2198
Neale Rannsf12dad62018-06-04 18:41:24 -07002199static void
Neale Rannsb8d44812017-11-10 06:53:54 -08002200handle_ip6_nd_event (u32 pool_index)
2201{
2202 vpe_api_main_t *vam = &vpe_api_main;
2203 vnet_main_t *vnm = vam->vnet_main;
2204 vlib_main_t *vm = vam->vlib_main;
2205 vl_api_ip6_nd_event_t *event;
2206 vl_api_ip6_nd_event_t *mp;
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002207 vl_api_registration_t *reg;
Neale Rannsb8d44812017-11-10 06:53:54 -08002208
2209 /* Client can cancel, die, etc. */
2210 if (pool_is_free_index (vam->nd_events, pool_index))
2211 return;
2212
2213 event = pool_elt_at_index (vam->nd_events, pool_index);
2214
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002215 reg = vl_api_client_index_to_registration (event->client_index);
2216 if (!reg)
Neale Rannsb8d44812017-11-10 06:53:54 -08002217 {
2218 (void) vnet_add_del_ip6_nd_change_event
2219 (vnm, nd_change_delete_callback,
2220 event->pid, &event->address,
2221 ip_resolver_process_node.index, IP6_ND_EVENT,
2222 ~0 /* pool index, notused */ , 0 /* is_add */ );
2223 return;
2224 }
2225
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002226 if (vl_api_can_send_msg (reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08002227 {
2228 mp = vl_msg_api_alloc (sizeof (*mp));
2229 clib_memcpy (mp, event, sizeof (*mp));
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002230 vl_api_send_msg (reg, (u8 *) mp);
Neale Rannsb8d44812017-11-10 06:53:54 -08002231 }
2232 else
2233 {
2234 static f64 last_time;
2235 /*
2236 * Throttle syslog msgs.
2237 * It's pretty tempting to just revoke the registration...
2238 */
2239 if (vlib_time_now (vm) > last_time + 10.0)
2240 {
2241 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
2242 format_ip6_address, &event->address, event->pid);
2243 last_time = vlib_time_now (vm);
2244 }
2245 }
2246}
2247
2248static uword
2249resolver_process (vlib_main_t * vm,
2250 vlib_node_runtime_t * rt, vlib_frame_t * f)
2251{
2252 volatile f64 timeout = 100.0;
2253 volatile uword *event_data = 0;
2254
2255 while (1)
2256 {
2257 vlib_process_wait_for_event_or_clock (vm, timeout);
2258
2259 uword event_type =
2260 vlib_process_get_events (vm, (uword **) & event_data);
2261
2262 int i;
2263 switch (event_type)
2264 {
2265 case IP4_ARP_EVENT:
2266 for (i = 0; i < vec_len (event_data); i++)
2267 handle_ip4_arp_event (event_data[i]);
2268 break;
2269
2270 case IP6_ND_EVENT:
2271 for (i = 0; i < vec_len (event_data); i++)
2272 handle_ip6_nd_event (event_data[i]);
2273 break;
2274
2275 case ~0: /* timeout */
2276 break;
2277 }
2278
2279 vec_reset_length (event_data);
2280 }
2281 return 0; /* or not */
2282}
2283
2284/* *INDENT-OFF* */
2285VLIB_REGISTER_NODE (ip_resolver_process_node,static) = {
2286 .function = resolver_process,
2287 .type = VLIB_NODE_TYPE_PROCESS,
2288 .name = "ip-route-resolver-process",
2289};
2290/* *INDENT-ON* */
2291
2292static int
2293nd_change_data_callback (u32 pool_index, u8 * new_mac,
2294 u32 sw_if_index, ip6_address_t * address)
2295{
2296 vpe_api_main_t *am = &vpe_api_main;
2297 vl_api_ip6_nd_event_t *event;
2298
2299 if (pool_is_free_index (am->nd_events, pool_index))
2300 return 1;
2301
2302 event = pool_elt_at_index (am->nd_events, pool_index);
2303 if (eth_mac_equal (event->new_mac, new_mac) &&
2304 sw_if_index == ntohl (event->sw_if_index))
2305 {
2306 return 1;
2307 }
2308
2309 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
2310 event->sw_if_index = htonl (sw_if_index);
2311 return 0;
2312}
2313
2314static int
2315arp_change_delete_callback (u32 pool_index, u8 * notused)
2316{
2317 vpe_api_main_t *am = &vpe_api_main;
2318
2319 if (pool_is_free_index (am->arp_events, pool_index))
2320 return 1;
2321
2322 pool_put_index (am->arp_events, pool_index);
2323 return 0;
2324}
2325
2326static int
2327nd_change_delete_callback (u32 pool_index, u8 * notused)
2328{
2329 vpe_api_main_t *am = &vpe_api_main;
2330
2331 if (pool_is_free_index (am->nd_events, pool_index))
2332 return 1;
2333
2334 pool_put_index (am->nd_events, pool_index);
2335 return 0;
2336}
2337
2338static vlib_node_registration_t wc_arp_process_node;
2339
2340enum
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002341{ WC_ARP_REPORT, WC_ND_REPORT, RA_REPORT, REPORT_MAX };
Neale Rannsb8d44812017-11-10 06:53:54 -08002342
2343static uword
2344wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
2345{
2346 /* These cross the longjmp boundry (vlib_process_wait_for_event)
2347 * and need to be volatile - to prevent them from being optimized into
2348 * a register - which could change during suspension */
2349
2350 volatile wc_arp_report_t arp_prev = { 0 };
2351 volatile wc_nd_report_t nd_prev = { 0 };
2352 volatile f64 last_arp = vlib_time_now (vm);
2353 volatile f64 last_nd = vlib_time_now (vm);
2354
2355 while (1)
2356 {
2357 vlib_process_wait_for_event (vm);
2358 uword event_type = WC_ARP_REPORT;
2359 void *event_data = vlib_process_get_event_data (vm, &event_type);
2360
2361 f64 now = vlib_time_now (vm);
2362 int i;
2363 if (event_type == WC_ARP_REPORT)
2364 {
2365 wc_arp_report_t *arp_events = event_data;
2366 for (i = 0; i < vec_len (arp_events); i++)
2367 {
2368 /* discard dup event */
2369 if (arp_prev.ip4 == arp_events[i].ip4 &&
2370 eth_mac_equal ((u8 *) arp_prev.mac, arp_events[i].mac) &&
2371 arp_prev.sw_if_index == arp_events[i].sw_if_index &&
2372 (now - last_arp) < 10.0)
2373 {
2374 continue;
2375 }
2376 arp_prev = arp_events[i];
2377 last_arp = now;
2378 vpe_client_registration_t *reg;
2379 /* *INDENT-OFF* */
2380 pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations,
2381 ({
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002382 vl_api_registration_t *vl_reg;
2383 vl_reg = vl_api_client_index_to_registration (reg->client_index);
Chris Luke30684ac2018-03-29 12:56:58 -07002384 ASSERT (vl_reg != NULL);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002385 if (reg && vl_api_can_send_msg (vl_reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08002386 {
2387 vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event);
Dave Barachb7b92992018-10-17 10:38:51 -04002388 clib_memset (event, 0, sizeof *event);
Neale Rannsb8d44812017-11-10 06:53:54 -08002389 event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
2390 event->client_index = reg->client_index;
2391 event->pid = reg->client_pid;
2392 event->mac_ip = 1;
2393 event->address = arp_events[i].ip4;
2394 event->sw_if_index = htonl(arp_events[i].sw_if_index);
2395 memcpy(event->new_mac, arp_events[i].mac, sizeof event->new_mac);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002396 vl_api_send_msg (vl_reg, (u8 *) event);
Neale Rannsb8d44812017-11-10 06:53:54 -08002397 }
2398 }));
2399 /* *INDENT-ON* */
2400 }
2401 }
2402 else if (event_type == WC_ND_REPORT)
2403 {
2404 wc_nd_report_t *nd_events = event_data;
2405 for (i = 0; i < vec_len (nd_events); i++)
2406 {
2407 /* discard dup event */
2408 if (ip6_address_is_equal
2409 ((ip6_address_t *) & nd_prev.ip6, &nd_events[i].ip6)
2410 && eth_mac_equal ((u8 *) nd_prev.mac, nd_events[i].mac)
2411 && nd_prev.sw_if_index == nd_events[i].sw_if_index
2412 && (now - last_nd) < 10.0)
2413 {
2414 continue;
2415 }
2416 nd_prev = nd_events[i];
2417 last_nd = now;
2418 vpe_client_registration_t *reg;
2419 /* *INDENT-OFF* */
2420 pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations,
2421 ({
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002422 vl_api_registration_t *vl_reg;
2423 vl_reg = vl_api_client_index_to_registration (reg->client_index);
2424 if (vl_reg && vl_api_can_send_msg (vl_reg))
Neale Rannsb8d44812017-11-10 06:53:54 -08002425 {
2426 vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event);
Dave Barachb7b92992018-10-17 10:38:51 -04002427 clib_memset (event, 0, sizeof *event);
Neale Rannsb8d44812017-11-10 06:53:54 -08002428 event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT);
2429 event->client_index = reg->client_index;
2430 event->pid = reg->client_pid;
2431 event->mac_ip = 1;
2432 memcpy(event->address, nd_events[i].ip6.as_u8, sizeof event->address);
2433 event->sw_if_index = htonl(nd_events[i].sw_if_index);
2434 memcpy(event->new_mac, nd_events[i].mac, sizeof event->new_mac);
Florin Corasaf0ff5a2018-01-10 08:17:03 -08002435 vl_api_send_msg (vl_reg, (u8 *) event);
Neale Rannsb8d44812017-11-10 06:53:54 -08002436 }
2437 }));
2438 /* *INDENT-ON* */
2439 }
2440 }
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002441 else if (event_type == RA_REPORT)
2442 {
2443 ra_report_t *ra_events = event_data;
2444 for (i = 0; i < vec_len (ra_events); i++)
2445 {
Juraj Sloboda52574522018-05-03 10:03:50 +02002446 ip6_neighbor_public_main_t *npm = &ip6_neighbor_public_main;
2447 call_ip6_neighbor_callbacks (&ra_events[i],
2448 npm->ra_report_functions);
2449
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002450 vpe_client_registration_t *reg;
2451 /* *INDENT-OFF* */
2452 pool_foreach(reg, vpe_api_main.ip6_ra_events_registrations,
2453 ({
2454 vl_api_registration_t *vl_reg;
2455 vl_reg =
2456 vl_api_client_index_to_registration (reg->client_index);
2457 if (vl_reg && vl_api_can_send_msg (vl_reg))
2458 {
2459 u32 event_size =
2460 sizeof (vl_api_ip6_ra_event_t) +
2461 vec_len (ra_events[i].prefixes) *
2462 sizeof (vl_api_ip6_ra_prefix_info_t);
2463 vl_api_ip6_ra_event_t *event =
2464 vl_msg_api_alloc (event_size);
Dave Barachb7b92992018-10-17 10:38:51 -04002465 clib_memset (event, 0, event_size);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002466 event->_vl_msg_id = htons (VL_API_IP6_RA_EVENT);
2467 event->client_index = reg->client_index;
2468 event->pid = reg->client_pid;
2469
2470 event->sw_if_index = clib_host_to_net_u32 (ra_events[i].sw_if_index);
2471
2472 memcpy (event->router_address, ra_events[i].router_address, 16);
2473
2474 event->current_hop_limit = ra_events[i].current_hop_limit;
2475 event->flags = ra_events[i].flags;
2476 event->router_lifetime_in_sec =
2477 clib_host_to_net_u16 (ra_events
2478 [i].router_lifetime_in_sec);
2479 event->neighbor_reachable_time_in_msec =
2480 clib_host_to_net_u32 (ra_events
2481 [i].neighbor_reachable_time_in_msec);
2482 event->time_in_msec_between_retransmitted_neighbor_solicitations
2483 =
2484 clib_host_to_net_u32 (ra_events
2485 [i].time_in_msec_between_retransmitted_neighbor_solicitations);
2486
2487 event->n_prefixes =
2488 clib_host_to_net_u32 (vec_len (ra_events[i].prefixes));
2489 vl_api_ip6_ra_prefix_info_t *prefix =
2490 (typeof (prefix)) event->prefixes;
2491 u32 j;
2492 for (j = 0; j < vec_len (ra_events[i].prefixes); j++)
2493 {
2494 ra_report_prefix_info_t *info =
2495 &ra_events[i].prefixes[j];
2496 memcpy (prefix->dst_address, info->dst_address.as_u8,
2497 16);
2498 prefix->dst_address_length = info->dst_address_length;
2499 prefix->flags = info->flags;
2500 prefix->valid_time =
2501 clib_host_to_net_u32 (info->valid_time);
2502 prefix->preferred_time =
2503 clib_host_to_net_u32 (info->preferred_time);
2504 prefix++;
2505 }
2506
2507 vl_api_send_msg (vl_reg, (u8 *) event);
2508 }
2509 }));
Juraj Slobodad7f58cc2018-07-27 11:23:14 +02002510 /* *INDENT-ON* */
2511 vec_free (ra_events[i].prefixes);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002512 }
2513 }
Neale Rannsb8d44812017-11-10 06:53:54 -08002514 vlib_process_put_event_data (vm, event_data);
2515 }
2516
2517 return 0;
2518}
2519
2520/* *INDENT-OFF* */
2521VLIB_REGISTER_NODE (wc_arp_process_node,static) = {
2522 .function = wc_arp_process,
2523 .type = VLIB_NODE_TYPE_PROCESS,
2524 .name = "wildcard-ip4-arp-publisher-process",
2525};
2526/* *INDENT-ON* */
2527
2528static int
2529arp_change_data_callback (u32 pool_index, u8 * new_mac,
2530 u32 sw_if_index, u32 address)
2531{
2532 vpe_api_main_t *am = &vpe_api_main;
2533 vl_api_ip4_arp_event_t *event;
2534
2535 if (pool_is_free_index (am->arp_events, pool_index))
2536 return 1;
2537
2538 event = pool_elt_at_index (am->arp_events, pool_index);
2539 if (eth_mac_equal (event->new_mac, new_mac) &&
2540 sw_if_index == ntohl (event->sw_if_index))
2541 {
2542 return 1;
2543 }
2544
2545 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
2546 event->sw_if_index = htonl (sw_if_index);
2547 return 0;
2548}
2549
2550static void
2551vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
2552{
2553 vpe_api_main_t *am = &vpe_api_main;
2554 vnet_main_t *vnm = vnet_get_main ();
2555 vl_api_want_ip4_arp_events_reply_t *rmp;
2556 int rv = 0;
2557
2558 if (mp->address == 0)
2559 {
2560 uword *p =
2561 hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index);
2562 vpe_client_registration_t *rp;
2563 if (p)
2564 {
2565 if (mp->enable_disable)
2566 {
2567 clib_warning ("pid %d: already enabled...", mp->pid);
2568 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2569 goto reply;
2570 }
2571 else
2572 {
2573 rp =
2574 pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
2575 pool_put (am->wc_ip4_arp_events_registrations, rp);
2576 hash_unset (am->wc_ip4_arp_events_registration_hash,
2577 mp->client_index);
2578 if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002579 wc_arp_set_publisher_node (~0, REPORT_MAX);
Neale Rannsb8d44812017-11-10 06:53:54 -08002580 goto reply;
2581 }
2582 }
2583 if (mp->enable_disable == 0)
2584 {
2585 clib_warning ("pid %d: already disabled...", mp->pid);
2586 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2587 goto reply;
2588 }
2589 pool_get (am->wc_ip4_arp_events_registrations, rp);
2590 rp->client_index = mp->client_index;
2591 rp->client_pid = mp->pid;
2592 hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index,
2593 rp - am->wc_ip4_arp_events_registrations);
2594 wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT);
2595 goto reply;
2596 }
2597
2598 if (mp->enable_disable)
2599 {
2600 vl_api_ip4_arp_event_t *event;
2601 pool_get (am->arp_events, event);
2602 rv = vnet_add_del_ip4_arp_change_event
2603 (vnm, arp_change_data_callback,
2604 mp->pid, &mp->address /* addr, in net byte order */ ,
2605 ip_resolver_process_node.index,
2606 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
2607
2608 if (rv)
2609 {
2610 pool_put (am->arp_events, event);
2611 goto reply;
2612 }
Dave Barachb7b92992018-10-17 10:38:51 -04002613 clib_memset (event, 0, sizeof (*event));
Neale Rannsb8d44812017-11-10 06:53:54 -08002614
2615 /* Python API expects events to have no context */
2616 event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
2617 event->client_index = mp->client_index;
2618 event->address = mp->address;
2619 event->pid = mp->pid;
2620 if (mp->address == 0)
2621 event->mac_ip = 1;
2622 }
2623 else
2624 {
2625 rv = vnet_add_del_ip4_arp_change_event
2626 (vnm, arp_change_delete_callback,
2627 mp->pid, &mp->address /* addr, in net byte order */ ,
2628 ip_resolver_process_node.index,
2629 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
2630 }
2631reply:
2632 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
2633}
2634
Neale Rannsf12dad62018-06-04 18:41:24 -07002635static clib_error_t *
2636want_ip4_arp_events_reaper (u32 client_index)
2637{
2638 vpe_client_registration_t *rp;
2639 vl_api_ip4_arp_event_t *event;
2640 u32 *to_delete, *event_id;
2641 vpe_api_main_t *am;
2642 vnet_main_t *vnm;
2643 uword *p;
2644
2645 am = &vpe_api_main;
2646 vnm = vnet_get_main ();
2647 to_delete = NULL;
2648
2649 /* clear out all of its pending resolutions */
2650 /* *INDENT-OFF* */
2651 pool_foreach(event, am->arp_events,
2652 ({
2653 if (event->client_index == client_index)
2654 {
2655 vec_add1(to_delete, event - am->arp_events);
2656 }
2657 }));
2658 /* *INDENT-ON* */
2659
2660 vec_foreach (event_id, to_delete)
2661 {
2662 event = pool_elt_at_index (am->arp_events, *event_id);
2663 vnet_add_del_ip4_arp_change_event
2664 (vnm, arp_change_delete_callback,
2665 event->pid, &event->address,
2666 ip_resolver_process_node.index, IP4_ARP_EVENT,
2667 ~0 /* pool index, notused */ , 0 /* is_add */ );
2668 }
2669 vec_free (to_delete);
2670
2671 /* remove from the registration hash */
2672 p = hash_get (am->wc_ip4_arp_events_registration_hash, client_index);
2673
2674 if (p)
2675 {
2676 rp = pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
2677 pool_put (am->wc_ip4_arp_events_registrations, rp);
2678 hash_unset (am->wc_ip4_arp_events_registration_hash, client_index);
2679 if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
2680 wc_arp_set_publisher_node (~0, REPORT_MAX);
2681 }
2682 return (NULL);
2683}
2684
2685VL_MSG_API_REAPER_FUNCTION (want_ip4_arp_events_reaper);
2686
Neale Rannsb8d44812017-11-10 06:53:54 -08002687static void
2688vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
2689{
2690 vpe_api_main_t *am = &vpe_api_main;
2691 vnet_main_t *vnm = vnet_get_main ();
2692 vl_api_want_ip6_nd_events_reply_t *rmp;
2693 int rv = 0;
2694
2695 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
2696 {
2697 uword *p =
2698 hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index);
2699 vpe_client_registration_t *rp;
2700 if (p)
2701 {
2702 if (mp->enable_disable)
2703 {
2704 clib_warning ("pid %d: already enabled...", mp->pid);
2705 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2706 goto reply;
2707 }
2708 else
2709 {
2710 rp =
2711 pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
2712 pool_put (am->wc_ip6_nd_events_registrations, rp);
2713 hash_unset (am->wc_ip6_nd_events_registration_hash,
2714 mp->client_index);
2715 if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002716 wc_nd_set_publisher_node (~0, REPORT_MAX);
Neale Rannsb8d44812017-11-10 06:53:54 -08002717 goto reply;
2718 }
2719 }
2720 if (mp->enable_disable == 0)
2721 {
2722 clib_warning ("pid %d: already disabled...", mp->pid);
2723 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2724 goto reply;
2725 }
2726 pool_get (am->wc_ip6_nd_events_registrations, rp);
2727 rp->client_index = mp->client_index;
2728 rp->client_pid = mp->pid;
2729 hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index,
2730 rp - am->wc_ip6_nd_events_registrations);
2731 wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT);
2732 goto reply;
2733 }
2734
2735 if (mp->enable_disable)
2736 {
2737 vl_api_ip6_nd_event_t *event;
2738 pool_get (am->nd_events, event);
2739
2740 rv = vnet_add_del_ip6_nd_change_event
2741 (vnm, nd_change_data_callback,
2742 mp->pid, mp->address /* addr, in net byte order */ ,
2743 ip_resolver_process_node.index,
2744 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
2745
2746 if (rv)
2747 {
2748 pool_put (am->nd_events, event);
2749 goto reply;
2750 }
Dave Barachb7b92992018-10-17 10:38:51 -04002751 clib_memset (event, 0, sizeof (*event));
Neale Rannsb8d44812017-11-10 06:53:54 -08002752
2753 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
2754 event->client_index = mp->client_index;
2755 clib_memcpy (event->address, mp->address, sizeof event->address);
2756 event->pid = mp->pid;
2757 }
2758 else
2759 {
2760 rv = vnet_add_del_ip6_nd_change_event
2761 (vnm, nd_change_delete_callback,
2762 mp->pid, mp->address /* addr, in net byte order */ ,
2763 ip_resolver_process_node.index,
2764 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
2765 }
2766reply:
2767 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
2768}
2769
Neale Rannsf12dad62018-06-04 18:41:24 -07002770static clib_error_t *
2771want_ip6_nd_events_reaper (u32 client_index)
2772{
2773
2774 vpe_client_registration_t *rp;
2775 vl_api_ip6_nd_event_t *event;
2776 u32 *to_delete, *event_id;
2777 vpe_api_main_t *am;
2778 vnet_main_t *vnm;
2779 uword *p;
2780
2781 am = &vpe_api_main;
2782 vnm = vnet_get_main ();
2783 to_delete = NULL;
2784
2785 /* clear out all of its pending resolutions */
2786 /* *INDENT-OFF* */
2787 pool_foreach(event, am->nd_events,
2788 ({
2789 if (event->client_index == client_index)
2790 {
2791 vec_add1(to_delete, event - am->nd_events);
2792 }
2793 }));
2794 /* *INDENT-ON* */
2795
2796 vec_foreach (event_id, to_delete)
2797 {
2798 event = pool_elt_at_index (am->nd_events, *event_id);
2799 vnet_add_del_ip6_nd_change_event
2800 (vnm, nd_change_delete_callback,
2801 event->pid, &event->address,
2802 ip_resolver_process_node.index, IP6_ND_EVENT,
2803 ~0 /* pool index, notused */ , 0 /* is_add */ );
2804 }
2805 vec_free (to_delete);
2806
2807 /* remove from the registration hash */
2808 p = hash_get (am->wc_ip6_nd_events_registration_hash, client_index);
2809
2810 if (p)
2811 {
2812 rp = pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
2813 pool_put (am->wc_ip6_nd_events_registrations, rp);
2814 hash_unset (am->wc_ip6_nd_events_registration_hash, client_index);
2815 if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
2816 wc_nd_set_publisher_node (~0, REPORT_MAX);
2817 }
2818 return (NULL);
2819}
2820
2821VL_MSG_API_REAPER_FUNCTION (want_ip6_nd_events_reaper);
2822
Neale Rannsb8d44812017-11-10 06:53:54 -08002823static void
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002824vl_api_want_ip6_ra_events_t_handler (vl_api_want_ip6_ra_events_t * mp)
2825{
2826 vpe_api_main_t *am = &vpe_api_main;
2827 vl_api_want_ip6_ra_events_reply_t *rmp;
2828 int rv = 0;
2829
2830 uword *p = hash_get (am->ip6_ra_events_registration_hash, mp->client_index);
2831 vpe_client_registration_t *rp;
2832 if (p)
2833 {
2834 if (mp->enable_disable)
2835 {
2836 clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
2837 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2838 goto reply;
2839 }
2840 else
2841 {
2842 rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
2843 pool_put (am->ip6_ra_events_registrations, rp);
2844 hash_unset (am->ip6_ra_events_registration_hash, mp->client_index);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002845 goto reply;
2846 }
2847 }
2848 if (mp->enable_disable == 0)
2849 {
2850 clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
2851 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2852 goto reply;
2853 }
2854 pool_get (am->ip6_ra_events_registrations, rp);
2855 rp->client_index = mp->client_index;
2856 rp->client_pid = ntohl (mp->pid);
2857 hash_set (am->ip6_ra_events_registration_hash, rp->client_index,
2858 rp - am->ip6_ra_events_registrations);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002859
2860reply:
2861 REPLY_MACRO (VL_API_WANT_IP6_RA_EVENTS_REPLY);
2862}
2863
Neale Rannsf12dad62018-06-04 18:41:24 -07002864static clib_error_t *
2865want_ip6_ra_events_reaper (u32 client_index)
2866{
2867 vpe_api_main_t *am = &vpe_api_main;
2868 vpe_client_registration_t *rp;
2869 uword *p;
2870
2871 p = hash_get (am->ip6_ra_events_registration_hash, client_index);
2872
2873 if (p)
2874 {
2875 rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]);
2876 pool_put (am->ip6_ra_events_registrations, rp);
2877 hash_unset (am->ip6_ra_events_registration_hash, client_index);
2878 }
2879 return (NULL);
2880}
2881
2882VL_MSG_API_REAPER_FUNCTION (want_ip6_ra_events_reaper);
2883
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002884static void
Neale Rannsb8d44812017-11-10 06:53:54 -08002885vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2886{
2887 vl_api_proxy_arp_add_del_reply_t *rmp;
2888 u32 fib_index;
2889 int rv;
2890 ip4_main_t *im = &ip4_main;
Neale Rannsb8d44812017-11-10 06:53:54 -08002891 uword *p;
2892
Ole Troan3288ed72017-12-06 17:00:05 +01002893 stats_dslock_with_hint (1 /* release hint */ , 6 /* tag */ );
Neale Rannsb8d44812017-11-10 06:53:54 -08002894
Neale Ranns0053de62018-05-22 08:40:52 -07002895 p = hash_get (im->fib_index_by_table_id, ntohl (mp->proxy.vrf_id));
Neale Rannsb8d44812017-11-10 06:53:54 -08002896
2897 if (!p)
2898 {
2899 rv = VNET_API_ERROR_NO_SUCH_FIB;
2900 goto out;
2901 }
2902
2903 fib_index = p[0];
2904
Neale Ranns0053de62018-05-22 08:40:52 -07002905 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->proxy.low_address,
2906 (ip4_address_t *) mp->proxy.hi_address,
Neale Rannsb8d44812017-11-10 06:53:54 -08002907 fib_index, mp->is_add == 0);
2908
2909out:
Ole Troan3288ed72017-12-06 17:00:05 +01002910 stats_dsunlock ();
Neale Rannsb8d44812017-11-10 06:53:54 -08002911 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2912}
2913
Neale Ranns0053de62018-05-22 08:40:52 -07002914typedef struct proxy_arp_walk_ctx_t_
2915{
2916 vl_api_registration_t *reg;
2917 u32 context;
2918} proxy_arp_walk_ctx_t;
2919
2920static walk_rc_t
2921send_proxy_arp_details (const ip4_address_t * lo_addr,
2922 const ip4_address_t * hi_addr,
2923 u32 fib_index, void *data)
2924{
2925 vl_api_proxy_arp_details_t *mp;
2926 proxy_arp_walk_ctx_t *ctx;
2927
2928 ctx = data;
2929
2930 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04002931 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns0053de62018-05-22 08:40:52 -07002932 mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_DETAILS);
2933 mp->context = ctx->context;
2934 mp->proxy.vrf_id = htonl (fib_index);
2935 clib_memcpy (mp->proxy.low_address, lo_addr,
2936 sizeof (mp->proxy.low_address));
2937 clib_memcpy (mp->proxy.hi_address, hi_addr, sizeof (mp->proxy.hi_address));
2938
2939 vl_api_send_msg (ctx->reg, (u8 *) mp);
2940
2941 return (WALK_CONTINUE);
2942}
2943
2944static void
2945vl_api_proxy_arp_dump_t_handler (vl_api_proxy_arp_dump_t * mp)
2946{
2947 vl_api_registration_t *reg;
2948
2949 reg = vl_api_client_index_to_registration (mp->client_index);
2950 if (!reg)
2951 return;
2952
2953 proxy_arp_walk_ctx_t wctx = {
2954 .reg = reg,
2955 .context = mp->context,
2956 };
2957
2958 proxy_arp_walk (send_proxy_arp_details, &wctx);
2959}
2960
2961static walk_rc_t
2962send_proxy_arp_intfc_details (vnet_main_t * vnm,
2963 vnet_sw_interface_t * si, void *data)
2964{
2965 vl_api_proxy_arp_intfc_details_t *mp;
2966 proxy_arp_walk_ctx_t *ctx;
2967
2968 if (!(si->flags & VNET_SW_INTERFACE_FLAG_PROXY_ARP))
2969 return (WALK_CONTINUE);
2970
2971 ctx = data;
2972
2973 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -04002974 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns0053de62018-05-22 08:40:52 -07002975 mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_INTFC_DETAILS);
2976 mp->context = ctx->context;
2977 mp->sw_if_index = htonl (si->sw_if_index);
2978
2979 vl_api_send_msg (ctx->reg, (u8 *) mp);
2980
2981 return (WALK_CONTINUE);
2982}
2983
2984static void
2985vl_api_proxy_arp_intfc_dump_t_handler (vl_api_proxy_arp_intfc_dump_t * mp)
2986{
2987 vl_api_registration_t *reg;
2988
2989 reg = vl_api_client_index_to_registration (mp->client_index);
2990 if (!reg)
2991 return;
2992
2993 proxy_arp_walk_ctx_t wctx = {
2994 .reg = reg,
2995 .context = mp->context,
2996 };
2997
2998 vnet_sw_interface_walk (vnet_get_main (),
2999 send_proxy_arp_intfc_details, &wctx);
3000}
3001
Neale Rannsb8d44812017-11-10 06:53:54 -08003002static void
3003 vl_api_proxy_arp_intfc_enable_disable_t_handler
3004 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
3005{
3006 int rv = 0;
3007 vnet_main_t *vnm = vnet_get_main ();
3008 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
3009
3010 VALIDATE_SW_IF_INDEX (mp);
3011
3012 vnet_sw_interface_t *si =
3013 vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
3014
3015 ASSERT (si);
3016
3017 if (mp->enable_disable)
3018 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
3019 else
3020 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
3021
3022 BAD_SW_IF_INDEX_LABEL;
3023
3024 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
3025}
3026
John Loc7b43042018-04-13 16:46:22 -04003027static void
3028vl_api_ip_probe_neighbor_t_handler (vl_api_ip_probe_neighbor_t * mp)
3029{
3030 int rv = 0;
3031 vlib_main_t *vm = vlib_get_main ();
3032 vl_api_ip_probe_neighbor_reply_t *rmp;
3033 clib_error_t *error;
3034
3035 VALIDATE_SW_IF_INDEX (mp);
3036
3037 u32 sw_if_index = ntohl (mp->sw_if_index);
3038
3039 if (mp->is_ipv6)
3040 error = ip6_probe_neighbor (vm, (ip6_address_t *) mp->dst_address,
John Lo86376342018-06-11 20:14:49 -04003041 sw_if_index, 0);
John Loc7b43042018-04-13 16:46:22 -04003042 else
3043 error = ip4_probe_neighbor (vm, (ip4_address_t *) mp->dst_address,
John Lo86376342018-06-11 20:14:49 -04003044 sw_if_index, 0);
John Loc7b43042018-04-13 16:46:22 -04003045
3046 if (error)
3047 {
3048 clib_error_report (error);
3049 rv = clib_error_get_code (error);
3050 }
3051
3052 BAD_SW_IF_INDEX_LABEL;
3053
3054 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
3055}
3056
John Lo7f358b32018-04-28 01:19:24 -04003057static void
3058 vl_api_ip_scan_neighbor_enable_disable_t_handler
3059 (vl_api_ip_scan_neighbor_enable_disable_t * mp)
3060{
3061 int rv = 0;
3062 vl_api_ip_scan_neighbor_enable_disable_reply_t *rmp;
3063 ip_neighbor_scan_arg_t arg;
3064
3065 arg.mode = mp->mode;
3066 arg.scan_interval = mp->scan_interval;
3067 arg.max_proc_time = mp->max_proc_time;
3068 arg.max_update = mp->max_update;
3069 arg.scan_int_delay = mp->scan_int_delay;
3070 arg.stale_threshold = mp->stale_threshold;
3071 ip_neighbor_scan_enable_disable (&arg);
3072
3073 REPLY_MACRO (VL_API_IP_SCAN_NEIGHBOR_ENABLE_DISABLE_REPLY);
3074}
3075
Neale Rannsb8d44812017-11-10 06:53:54 -08003076static int
3077ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3078{
3079 vnet_main_t *vnm = vnet_get_main ();
3080 vnet_interface_main_t *im = &vnm->interface_main;
3081 ip4_main_t *im4 = &ip4_main;
3082 static u32 *sw_if_indices_to_shut;
Neale Rannsb8d44812017-11-10 06:53:54 -08003083 fib_table_t *fib_table;
3084 ip4_fib_t *fib;
3085 u32 sw_if_index;
3086 int i;
3087 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3088 u32 target_fib_id = ntohl (mp->vrf_id);
3089
Ole Troan3288ed72017-12-06 17:00:05 +01003090 stats_dslock_with_hint (1 /* release hint */ , 8 /* tag */ );
Neale Rannsb8d44812017-11-10 06:53:54 -08003091
3092 /* *INDENT-OFF* */
3093 pool_foreach (fib_table, im4->fibs,
3094 ({
3095 vnet_sw_interface_t * si;
3096
3097 fib = pool_elt_at_index (im4->v4_fibs, fib_table->ft_index);
3098
3099 if (fib->table_id != target_fib_id)
3100 continue;
3101
3102 /* remove any mpls encap/decap labels */
3103 mpls_fib_reset_labels (fib->table_id);
3104
3105 /* remove any proxy arps in this fib */
3106 vnet_proxy_arp_fib_reset (fib->table_id);
3107
3108 /* Set the flow hash for this fib to the default */
3109 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3110
3111 vec_reset_length (sw_if_indices_to_shut);
3112
3113 /* Shut down interfaces in this FIB / clean out intfc routes */
3114 pool_foreach (si, im->sw_interfaces,
3115 ({
3116 u32 sw_if_index = si->sw_if_index;
3117
3118 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
3119 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
3120 fib->index))
3121 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3122 }));
3123
3124 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3125 sw_if_index = sw_if_indices_to_shut[i];
3126
3127 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3128 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3129 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3130 }
3131
3132 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
3133
3134 rv = 0;
3135 break;
3136 })); /* pool_foreach (fib) */
3137 /* *INDENT-ON* */
3138
Ole Troan3288ed72017-12-06 17:00:05 +01003139 stats_dsunlock ();
Neale Rannsb8d44812017-11-10 06:53:54 -08003140 return rv;
3141}
3142
3143static int
3144ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3145{
3146 vnet_main_t *vnm = vnet_get_main ();
3147 vnet_interface_main_t *im = &vnm->interface_main;
3148 ip6_main_t *im6 = &ip6_main;
Neale Rannsb8d44812017-11-10 06:53:54 -08003149 static u32 *sw_if_indices_to_shut;
3150 fib_table_t *fib_table;
3151 ip6_fib_t *fib;
3152 u32 sw_if_index;
3153 int i;
3154 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3155 u32 target_fib_id = ntohl (mp->vrf_id);
3156
Ole Troan3288ed72017-12-06 17:00:05 +01003157 stats_dslock_with_hint (1 /* release hint */ , 9 /* tag */ );
Neale Rannsb8d44812017-11-10 06:53:54 -08003158
3159 /* *INDENT-OFF* */
3160 pool_foreach (fib_table, im6->fibs,
3161 ({
3162 vnet_sw_interface_t * si;
3163
3164 fib = pool_elt_at_index (im6->v6_fibs, fib_table->ft_index);
3165
3166 if (fib->table_id != target_fib_id)
3167 continue;
3168
3169 vec_reset_length (sw_if_indices_to_shut);
3170
3171 /* Set the flow hash for this fib to the default */
3172 vnet_set_ip6_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3173
3174 /* Shut down interfaces in this FIB / clean out intfc routes */
3175 pool_foreach (si, im->sw_interfaces,
3176 ({
3177 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3178 fib->index)
3179 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3180 }));
3181
3182 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3183 sw_if_index = sw_if_indices_to_shut[i];
3184
3185 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3186 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3187 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3188 }
3189
3190 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
3191
3192 rv = 0;
3193 break;
3194 })); /* pool_foreach (fib) */
3195 /* *INDENT-ON* */
3196
Ole Troan3288ed72017-12-06 17:00:05 +01003197 stats_dsunlock ();
Neale Rannsb8d44812017-11-10 06:53:54 -08003198 return rv;
3199}
3200
3201static void
3202vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3203{
3204 int rv;
3205 vl_api_reset_fib_reply_t *rmp;
3206
3207 if (mp->is_ipv6)
3208 rv = ip6_reset_fib_t_handler (mp);
3209 else
3210 rv = ip4_reset_fib_t_handler (mp);
3211
3212 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3213}
3214
3215static void
3216vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3217{
3218 int rv;
3219 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3220 vnet_main_t *vnm = vnet_get_main ();
3221 clib_error_t *error;
3222
3223 vnm->api_errno = 0;
3224
3225 if (mp->is_ipv6)
3226 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3227 else
3228 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3229
3230 if (error)
3231 {
3232 clib_error_report (error);
3233 rv = VNET_API_ERROR_UNSPECIFIED;
3234 }
3235 else
3236 {
3237 rv = vnm->api_errno;
3238 }
3239
3240 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3241}
3242
Klement Sekera75e7d132017-09-20 08:26:30 +02003243void
3244vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
3245{
3246 vl_api_ip_reassembly_set_reply_t *rmp;
3247 int rv = 0;
3248 if (mp->is_ip6)
3249 {
3250 rv = ip6_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
3251 clib_net_to_host_u32 (mp->max_reassemblies),
3252 clib_net_to_host_u32 (mp->expire_walk_interval_ms));
3253 }
3254 else
3255 {
3256 rv = ip4_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
3257 clib_net_to_host_u32 (mp->max_reassemblies),
3258 clib_net_to_host_u32 (mp->expire_walk_interval_ms));
3259 }
3260
3261 REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
3262}
3263
3264void
3265vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
3266{
3267 unix_shared_memory_queue_t *q;
3268
3269 q = vl_api_client_index_to_input_queue (mp->client_index);
3270
3271 if (q == 0)
3272 return;
3273
3274 vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04003275 clib_memset (rmp, 0, sizeof (*rmp));
Klement Sekera75e7d132017-09-20 08:26:30 +02003276 rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
3277 rmp->context = mp->context;
3278 rmp->retval = 0;
3279 if (mp->is_ip6)
3280 {
3281 rmp->is_ip6 = 1;
3282 ip6_reass_get (&rmp->timeout_ms, &rmp->max_reassemblies,
3283 &rmp->expire_walk_interval_ms);
3284 }
3285 else
3286 {
3287 rmp->is_ip6 = 0;
3288 ip4_reass_get (&rmp->timeout_ms, &rmp->max_reassemblies,
3289 &rmp->expire_walk_interval_ms);
3290 }
3291 rmp->timeout_ms = clib_host_to_net_u32 (rmp->timeout_ms);
3292 rmp->max_reassemblies = clib_host_to_net_u32 (rmp->max_reassemblies);
3293 rmp->expire_walk_interval_ms =
3294 clib_host_to_net_u32 (rmp->expire_walk_interval_ms);
3295 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3296}
3297
Klement Sekera4c533132018-02-22 11:41:12 +01003298void
3299 vl_api_ip_reassembly_enable_disable_t_handler
3300 (vl_api_ip_reassembly_enable_disable_t * mp)
3301{
3302 vl_api_ip_reassembly_enable_disable_reply_t *rmp;
3303 int rv = 0;
3304 rv = ip4_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
3305 mp->enable_ip4);
3306 if (0 == rv)
3307 {
3308 rv = ip6_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
3309 mp->enable_ip6);
3310 }
3311
3312 REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
3313}
3314
Pavel Kotucek609e1212018-11-27 09:59:44 +01003315void
3316send_ip_punt_redirect_details (vl_api_registration_t * reg,
3317 u32 context, u32 sw_if_index,
3318 ip_punt_redirect_rx_t * pr, u8 is_ipv6)
3319{
3320 vl_api_ip_punt_redirect_details_t *mp;
3321
3322 mp = vl_msg_api_alloc (sizeof (*mp));
3323 if (!mp)
3324 return;
3325
3326 clib_memset (mp, 0, sizeof (*mp));
3327 mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
3328 mp->context = context;
3329 mp->punt.rx_sw_if_index = htonl (sw_if_index);
3330 mp->punt.tx_sw_if_index = htonl (pr->tx_sw_if_index);
3331 if (is_ipv6)
3332 {
3333 ip_address_encode (&pr->nh, IP46_TYPE_IP6, &mp->punt.nh);
3334 }
3335 else
3336 {
3337 ip_address_encode (&pr->nh, IP46_TYPE_IP4, &mp->punt.nh);
3338 }
3339
3340 vl_api_send_msg (reg, (u8 *) mp);
3341}
3342
3343static void
3344vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp)
3345{
3346 vl_api_registration_t *reg;
3347 u32 sw_if_index;
3348 int rv __attribute__ ((unused)) = 0;
3349
3350 sw_if_index = ntohl (mp->sw_if_index);
3351 reg = vl_api_client_index_to_registration (mp->client_index);
3352 if (!reg)
3353 return;
3354
3355 if (~0 != sw_if_index)
3356 VALIDATE_SW_IF_INDEX (mp);
3357
3358 ip_punt_redirect_detail_t *pr, *prs;
3359 if (mp->is_ipv6)
3360 {
3361 prs = ip6_punt_redirect_entries (sw_if_index);
3362 /* *INDENT-OFF* */
3363 vec_foreach (pr, prs)
3364 {
3365 send_ip_punt_redirect_details (reg, mp->context, pr->rx_sw_if_index, &pr->punt_redirect, 1);
3366 }
3367 /* *INDENT-ON* */
3368 vec_free (prs);
3369 }
3370 else
3371 {
3372 prs = ip4_punt_redirect_entries (sw_if_index);
3373 /* *INDENT-OFF* */
3374 vec_foreach (pr, prs)
3375 {
3376 send_ip_punt_redirect_details (reg, mp->context, pr->rx_sw_if_index, &pr->punt_redirect, 0);
3377 }
3378 /* *INDENT-ON* */
3379 vec_free (prs);
3380 }
3381
3382 BAD_SW_IF_INDEX_LABEL;
3383}
3384
Dave Barachb5e8a772016-12-06 12:04:42 -05003385#define vl_msg_name_crc_list
3386#include <vnet/ip/ip.api.h>
3387#undef vl_msg_name_crc_list
3388
3389static void
3390setup_message_id_table (api_main_t * am)
3391{
3392#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
3393 foreach_vl_msg_name_crc_ip;
3394#undef _
3395}
3396
3397static clib_error_t *
3398ip_api_hookup (vlib_main_t * vm)
3399{
3400 api_main_t *am = &api_main;
3401
3402#define _(N,n) \
3403 vl_msg_api_set_handlers(VL_API_##N, #n, \
3404 vl_api_##n##_t_handler, \
3405 vl_noop_handler, \
3406 vl_api_##n##_t_endian, \
3407 vl_api_##n##_t_print, \
3408 sizeof(vl_api_##n##_t), 1);
3409 foreach_ip_api_msg;
3410#undef _
3411
3412 /*
Neale Ranns6a231a12018-10-17 06:38:00 +00003413 * Mark the route add/del API as MP safe
3414 */
3415 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
3416 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE_REPLY] = 1;
3417
3418 /*
Dave Barachb5e8a772016-12-06 12:04:42 -05003419 * Set up the (msg_name, crc, message-id) table
3420 */
3421 setup_message_id_table (am);
3422
Juraj Sloboda52574522018-05-03 10:03:50 +02003423 ra_set_publisher_node (wc_arp_process_node.index, RA_REPORT);
3424
Dave Barachb5e8a772016-12-06 12:04:42 -05003425 return 0;
3426}
3427
3428VLIB_API_INIT_FUNCTION (ip_api_hookup);
3429
3430/*
3431 * fd.io coding-style-patch-verification: ON
3432 *
3433 * Local Variables:
3434 * eval: (c-set-style "gnu")
3435 * End:
3436 */