2 *------------------------------------------------------------------
3 * ip_api.c - vnet ip api
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/ethernet/ethernet.h>
26 #include <vnet/ethernet/ethernet_types_api.h>
27 #include <vnet/ip/ip.h>
28 #include <vnet/ip/ip_types_api.h>
29 #include <vnet/ip/ip_punt_drop.h>
30 #include <vnet/ip/ip_types_api.h>
31 #include <vnet/fib/fib_table.h>
32 #include <vnet/fib/fib_api.h>
33 #include <vnet/ethernet/arp_packet.h>
34 #include <vnet/mfib/ip6_mfib.h>
35 #include <vnet/mfib/ip4_mfib.h>
36 #include <vnet/mfib/mfib_signal.h>
37 #include <vnet/mfib/mfib_entry.h>
38 #include <vnet/mfib/mfib_api.h>
39 #include <vnet/ip/ip_source_and_port_range_check.h>
40 #include <vnet/fib/fib_path_list.h>
41 #include <vnet/ip/ip6_hop_by_hop.h>
42 #include <vnet/ip/ip6_link.h>
43 #include <vnet/ip/reass/ip4_sv_reass.h>
44 #include <vnet/ip/reass/ip4_full_reass.h>
45 #include <vnet/ip/reass/ip6_sv_reass.h>
46 #include <vnet/ip/reass/ip6_full_reass.h>
47 #include <vnet/ip/ip_table.h>
48 #include <vnet/ip/ip_container_proxy.h>
50 #include <vnet/vnet_msg_enum.h>
52 #define vl_typedefs /* define message structures */
53 #include <vnet/vnet_all_api_h.h>
56 #define vl_endianfun /* define message structures */
57 #include <vnet/vnet_all_api_h.h>
60 /* instantiate all the print functions we know about */
61 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
63 #include <vnet/vnet_all_api_h.h>
66 #include <vlibapi/api_helper_macros.h>
68 #include <vnet/format_fns.h>
70 #define foreach_ip_api_msg \
71 _ (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable) \
72 _ (IP_TABLE_DUMP, ip_table_dump) \
73 _ (IP_ROUTE_DUMP, ip_route_dump) \
74 _ (IP_MTABLE_DUMP, ip_mtable_dump) \
75 _ (IP_MROUTE_DUMP, ip_mroute_dump) \
76 _ (IP_MROUTE_ADD_DEL, ip_mroute_add_del) \
77 _ (MFIB_SIGNAL_DUMP, mfib_signal_dump) \
78 _ (IP_ADDRESS_DUMP, ip_address_dump) \
79 _ (IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \
80 _ (IP_DUMP, ip_dump) \
81 _ (IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin) \
82 _ (IP_TABLE_REPLACE_END, ip_table_replace_end) \
83 _ (IP_TABLE_FLUSH, ip_table_flush) \
84 _ (IP_ROUTE_ADD_DEL, ip_route_add_del) \
85 _ (IP_ROUTE_LOOKUP, ip_route_lookup) \
86 _ (IP_TABLE_ADD_DEL, ip_table_add_del) \
87 _ (IP_PUNT_POLICE, ip_punt_police) \
88 _ (IP_PUNT_REDIRECT, ip_punt_redirect) \
89 _ (SET_IP_FLOW_HASH, set_ip_flow_hash) \
90 _ (IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \
91 _ (IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \
92 _ (IOAM_ENABLE, ioam_enable) \
93 _ (IOAM_DISABLE, ioam_disable) \
94 _ (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
95 ip_source_and_port_range_check_add_del) \
96 _ (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
97 ip_source_and_port_range_check_interface_add_del) \
98 _ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
99 sw_interface_ip6_set_link_local_address) \
100 _ (SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS, \
101 sw_interface_ip6_get_link_local_address) \
102 _ (IP_REASSEMBLY_SET, ip_reassembly_set) \
103 _ (IP_REASSEMBLY_GET, ip_reassembly_get) \
104 _ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
105 _ (IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)
108 vl_api_sw_interface_ip6_enable_disable_t_handler
109 (vl_api_sw_interface_ip6_enable_disable_t * mp)
111 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
114 VALIDATE_SW_IF_INDEX (mp);
116 rv = ((mp->enable == 1) ?
117 ip6_link_enable (ntohl (mp->sw_if_index), NULL) :
118 ip6_link_disable (ntohl (mp->sw_if_index)));
120 BAD_SW_IF_INDEX_LABEL;
122 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
126 send_ip_table_details (vpe_api_main_t * am,
127 vl_api_registration_t * reg,
128 u32 context, const fib_table_t * table)
130 vl_api_ip_table_details_t *mp;
132 mp = vl_msg_api_alloc (sizeof (*mp));
135 clib_memset (mp, 0, sizeof (*mp));
136 mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS);
137 mp->context = context;
139 mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6);
140 mp->table.table_id = htonl (table->ft_table_id);
141 memcpy (mp->table.name, table->ft_desc,
142 clib_min (vec_len (table->ft_desc), sizeof (mp->table.name)));
144 vl_api_send_msg (reg, (u8 *) mp);
148 vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp)
150 vpe_api_main_t *am = &vpe_api_main;
151 vl_api_registration_t *reg;
152 fib_table_t *fib_table;
154 reg = vl_api_client_index_to_registration (mp->client_index);
159 pool_foreach (fib_table, ip4_main.fibs)
161 send_ip_table_details(am, reg, mp->context, fib_table);
163 pool_foreach (fib_table, ip6_main.fibs)
165 /* don't send link locals */
166 if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
168 send_ip_table_details(am, reg, mp->context, fib_table);
173 typedef struct vl_api_ip_fib_dump_walk_ctx_t_
175 fib_node_index_t *feis;
176 } vl_api_ip_fib_dump_walk_ctx_t;
178 static fib_table_walk_rc_t
179 vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg)
181 vl_api_ip_fib_dump_walk_ctx_t *ctx = arg;
183 vec_add1 (ctx->feis, fei);
185 return (FIB_TABLE_WALK_CONTINUE);
189 send_ip_route_details (vpe_api_main_t * am,
190 vl_api_registration_t * reg,
191 u32 context, fib_node_index_t fib_entry_index)
193 fib_route_path_t *rpaths, *rpath;
194 vl_api_ip_route_details_t *mp;
195 const fib_prefix_t *pfx;
196 vl_api_fib_path_t *fp;
200 pfx = fib_entry_get_prefix (fib_entry_index);
201 rpaths = fib_entry_encode (fib_entry_index);
203 path_count = vec_len (rpaths);
204 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
207 clib_memset (mp, 0, sizeof (*mp));
208 mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS);
209 mp->context = context;
211 ip_prefix_encode (pfx, &mp->route.prefix);
213 htonl (fib_table_get_table_id
214 (fib_entry_get_fib_index (fib_entry_index), pfx->fp_proto));
215 mp->route.n_paths = path_count;
216 mp->route.stats_index =
217 htonl (fib_table_entry_get_stats_index
218 (fib_entry_get_fib_index (fib_entry_index), pfx));
220 fp = mp->route.paths;
221 vec_foreach (rpath, rpaths)
223 fib_api_path_encode (rpath, fp);
227 vl_api_send_msg (reg, (u8 *) mp);
231 typedef struct apt_ip6_fib_show_ctx_t_
233 fib_node_index_t *entries;
234 } api_ip6_fib_show_ctx_t;
237 vl_api_ip_route_dump_t_handler (vl_api_ip_route_dump_t * mp)
239 vpe_api_main_t *am = &vpe_api_main;
240 fib_node_index_t *fib_entry_index;
241 vl_api_registration_t *reg;
242 fib_protocol_t fproto;
245 reg = vl_api_client_index_to_registration (mp->client_index);
249 vl_api_ip_fib_dump_walk_ctx_t ctx = {
253 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
254 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
256 if (INDEX_INVALID == fib_index)
259 fib_table_walk (fib_index, fproto, vl_api_ip_fib_dump_walk, &ctx);
261 vec_foreach (fib_entry_index, ctx.feis)
263 send_ip_route_details (am, reg, mp->context, *fib_entry_index);
270 send_ip_mtable_details (vl_api_registration_t * reg,
271 u32 context, const mfib_table_t * mfib_table)
273 vl_api_ip_mtable_details_t *mp;
275 mp = vl_msg_api_alloc (sizeof (*mp));
278 memset (mp, 0, sizeof (*mp));
279 mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS);
280 mp->context = context;
282 mp->table.table_id = htonl (mfib_table->mft_table_id);
283 mp->table.is_ip6 = (FIB_PROTOCOL_IP6 == mfib_table->mft_proto);
285 vl_api_send_msg (reg, (u8 *) mp);
289 vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp)
291 vl_api_registration_t *reg;
292 mfib_table_t *mfib_table;
294 reg = vl_api_client_index_to_registration (mp->client_index);
299 pool_foreach (mfib_table, ip4_main.mfibs)
301 send_ip_mtable_details (reg, mp->context, mfib_table);
303 pool_foreach (mfib_table, ip6_main.mfibs)
305 send_ip_mtable_details (reg, mp->context, mfib_table);
310 typedef struct vl_api_ip_mfib_dump_ctx_t_
312 fib_node_index_t *entries;
313 } vl_api_ip_mfib_dump_ctx_t;
316 mfib_route_dump_walk (fib_node_index_t fei, void *arg)
318 vl_api_ip_mfib_dump_ctx_t *ctx = arg;
320 vec_add1 (ctx->entries, fei);
322 return (WALK_CONTINUE);
326 send_ip_mroute_details (vpe_api_main_t * am,
327 vl_api_registration_t * reg,
328 u32 context, fib_node_index_t mfib_entry_index)
330 fib_route_path_t *rpaths, *rpath;
331 vl_api_ip_mroute_details_t *mp;
332 const mfib_prefix_t *pfx;
333 vl_api_mfib_path_t *fp;
337 pfx = mfib_entry_get_prefix (mfib_entry_index);
338 rpaths = mfib_entry_encode (mfib_entry_index);
340 path_count = vec_len (rpaths);
341 mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
344 clib_memset (mp, 0, sizeof (*mp));
345 mp->_vl_msg_id = ntohs (VL_API_IP_MROUTE_DETAILS);
346 mp->context = context;
348 ip_mprefix_encode (pfx, &mp->route.prefix);
350 htonl (mfib_table_get_table_id
351 (mfib_entry_get_fib_index (mfib_entry_index), pfx->fp_proto));
352 mp->route.n_paths = path_count;
353 fp = mp->route.paths;
354 vec_foreach (rpath, rpaths)
356 mfib_api_path_encode (rpath, fp);
360 vl_api_send_msg (reg, (u8 *) mp);
365 vl_api_ip_mroute_dump_t_handler (vl_api_ip_mroute_dump_t * mp)
367 vpe_api_main_t *am = &vpe_api_main;
368 vl_api_registration_t *reg;
369 fib_node_index_t *mfeip;
370 fib_protocol_t fproto;
373 vl_api_ip_mfib_dump_ctx_t ctx = {
377 reg = vl_api_client_index_to_registration (mp->client_index);
381 fproto = fib_ip_proto (mp->table.is_ip6);
382 fib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
384 if (INDEX_INVALID == fib_index)
387 mfib_table_walk (fib_index, fproto, mfib_route_dump_walk, &ctx);
389 vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort);
391 vec_foreach (mfeip, ctx.entries)
393 send_ip_mroute_details (am, reg, mp->context, *mfeip);
396 vec_free (ctx.entries);
400 vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp,
403 vl_api_ip_punt_police_reply_t *rmp;
407 ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
409 ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index));
411 REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY);
415 vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp,
418 vl_api_ip_punt_redirect_reply_t *rmp;
423 if (!vnet_sw_if_index_is_api_valid (ntohl (mp->punt.tx_sw_if_index)))
424 goto bad_sw_if_index;
426 ipv = ip_address_decode (&mp->punt.nh, &nh);
429 if (ipv == IP46_TYPE_IP6)
431 ip6_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
432 ntohl (mp->punt.tx_sw_if_index), &nh);
434 else if (ipv == IP46_TYPE_IP4)
436 ip4_punt_redirect_add (ntohl (mp->punt.rx_sw_if_index),
437 ntohl (mp->punt.tx_sw_if_index), &nh);
442 if (ipv == IP46_TYPE_IP6)
444 ip6_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
446 else if (ipv == IP46_TYPE_IP4)
448 ip4_punt_redirect_del (ntohl (mp->punt.rx_sw_if_index));
452 BAD_SW_IF_INDEX_LABEL;
454 REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY);
457 static clib_error_t *
458 call_elf_section_ip_table_callbacks (vnet_main_t * vnm, u32 table_id,
460 _vnet_ip_table_function_list_elt_t **
463 _vnet_ip_table_function_list_elt_t *elt;
464 vnet_ip_table_function_priority_t prio;
465 clib_error_t *error = 0;
467 for (prio = VNET_IP_TABLE_FUNC_PRIORITY_LOW;
468 prio <= VNET_IP_TABLE_FUNC_PRIORITY_HIGH; prio++)
474 error = elt->fp (vnm, table_id, flags);
477 elt = elt->next_ip_table_function;
484 ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api)
486 u32 fib_index, mfib_index;
487 vnet_main_t *vnm = vnet_get_main ();
490 * ignore action on the default table - this is always present
491 * and cannot be added nor deleted from the API
496 * The API holds only one lock on the table.
497 * i.e. it can be added many times via the API but needs to be
499 * The FIB index for unicast and multicast is not necessarily the
500 * same, since internal VPP systesm (like LISP and SR) create
501 * their own unicast tables.
503 fib_index = fib_table_find (fproto, table_id);
504 mfib_index = mfib_table_find (fproto, table_id);
506 if ((~0 != fib_index) || (~0 != mfib_index))
507 call_elf_section_ip_table_callbacks (vnm, table_id, 0 /* is_add */ ,
508 vnm->ip_table_add_del_functions);
512 fib_table_unlock (fib_index, fproto,
513 (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI));
515 if (~0 != mfib_index)
517 mfib_table_unlock (mfib_index, fproto,
518 (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI));
524 vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
526 vl_api_ip_table_add_del_reply_t *rmp;
527 fib_protocol_t fproto = (mp->table.is_ip6 ?
528 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
529 u32 table_id = ntohl (mp->table.table_id);
534 ip_table_create (fproto, table_id, 1, mp->table.name);
538 ip_table_delete (fproto, table_id, 1);
541 REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY);
545 ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp, u32 * stats_index)
547 fib_route_path_t *rpaths = NULL, *rpath;
548 fib_entry_flag_t entry_flags;
549 vl_api_fib_path_t *apath;
554 entry_flags = FIB_ENTRY_FLAG_NONE;
555 ip_prefix_decode (&mp->route.prefix, &pfx);
557 rv = fib_api_table_id_decode (pfx.fp_proto,
558 ntohl (mp->route.table_id), &fib_index);
562 if (0 != mp->route.n_paths)
563 vec_validate (rpaths, mp->route.n_paths - 1);
565 for (ii = 0; ii < mp->route.n_paths; ii++)
567 apath = &mp->route.paths[ii];
570 rv = fib_api_path_decode (apath, rpath);
572 if ((rpath->frp_flags & FIB_ROUTE_PATH_LOCAL) &&
573 (~0 == rpath->frp_sw_if_index))
574 entry_flags |= (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL);
580 rv = fib_api_route_add_del (mp->is_add,
582 fib_index, &pfx, entry_flags, rpaths);
584 if (mp->is_add && 0 == rv)
585 *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx);
594 vl_api_ip_route_add_del_t_handler (vl_api_ip_route_add_del_t * mp)
596 vl_api_ip_route_add_del_reply_t *rmp;
597 u32 stats_index = ~0;
600 rv = ip_route_add_del_t_handler (mp, &stats_index);
603 REPLY_MACRO2 (VL_API_IP_ROUTE_ADD_DEL_REPLY,
605 rmp->stats_index = htonl (stats_index);
611 vl_api_ip_route_lookup_t_handler (vl_api_ip_route_lookup_t * mp)
613 vl_api_ip_route_lookup_reply_t *rmp = NULL;
614 fib_route_path_t *rpaths = NULL, *rpath;
615 const fib_prefix_t *pfx = NULL;
617 vl_api_fib_path_t *fp;
618 fib_node_index_t fib_entry_index;
623 ip_prefix_decode (&mp->prefix, &lookup);
624 rv = fib_api_table_id_decode (lookup.fp_proto, ntohl (mp->table_id),
626 if (PREDICT_TRUE (!rv))
629 fib_entry_index = fib_table_lookup_exact_match (fib_index, &lookup);
631 fib_entry_index = fib_table_lookup (fib_index, &lookup);
632 if (fib_entry_index == FIB_NODE_INDEX_INVALID)
633 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
636 pfx = fib_entry_get_prefix (fib_entry_index);
637 rpaths = fib_entry_encode (fib_entry_index);
638 npaths = vec_len (rpaths);
643 REPLY_MACRO3_ZERO(VL_API_IP_ROUTE_LOOKUP_REPLY,
644 npaths * sizeof (*fp),
648 ip_prefix_encode (pfx, &rmp->route.prefix);
649 rmp->route.table_id = mp->table_id;
650 rmp->route.n_paths = npaths;
651 rmp->route.stats_index = fib_table_entry_get_stats_index (fib_index, pfx);
652 rmp->route.stats_index = htonl (rmp->route.stats_index);
654 fp = rmp->route.paths;
655 vec_foreach (rpath, rpaths)
657 fib_api_path_encode (rpath, fp);
667 ip_table_create (fib_protocol_t fproto,
668 u32 table_id, u8 is_api, const u8 * name)
670 u32 fib_index, mfib_index;
671 vnet_main_t *vnm = vnet_get_main ();
674 * ignore action on the default table - this is always present
675 * and cannot be added nor deleted from the API
680 * The API holds only one lock on the table.
681 * i.e. it can be added many times via the API but needs to be
683 * The FIB index for unicast and multicast is not necessarily the
684 * same, since internal VPP systesm (like LISP and SR) create
685 * their own unicast tables.
687 fib_index = fib_table_find (fproto, table_id);
688 mfib_index = mfib_table_find (fproto, table_id);
692 fib_table_find_or_create_and_lock_w_name (fproto, table_id,
695 FIB_SOURCE_CLI), name);
697 if (~0 == mfib_index)
699 mfib_table_find_or_create_and_lock_w_name (fproto, table_id,
702 MFIB_SOURCE_CLI), name);
705 if ((~0 == fib_index) || (~0 == mfib_index))
706 call_elf_section_ip_table_callbacks (vnm, table_id, 1 /* is_add */ ,
707 vnm->ip_table_add_del_functions);
712 mroute_add_del_handler (u8 is_add,
715 const mfib_prefix_t * prefix,
717 u32 rpf_id, fib_route_path_t * rpaths)
719 u32 mfib_entry_index = ~0;
721 if (0 == vec_len (rpaths))
723 mfib_entry_index = mfib_table_entry_update (fib_index, prefix,
725 rpf_id, entry_flags);
732 mfib_table_entry_paths_update (fib_index, prefix,
733 MFIB_SOURCE_API, rpaths);
737 mfib_table_entry_paths_remove (fib_index, prefix,
738 MFIB_SOURCE_API, rpaths);
742 return (mfib_entry_index);
746 api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp,
749 fib_route_path_t *rpath, *rpaths = NULL;
750 fib_node_index_t mfib_entry_index;
751 mfib_entry_flags_t eflags;
757 ip_mprefix_decode (&mp->route.prefix, &pfx);
759 rv = mfib_api_table_id_decode (pfx.fp_proto,
760 ntohl (mp->route.table_id), &fib_index);
764 vec_validate (rpaths, mp->route.n_paths - 1);
766 for (ii = 0; ii < mp->route.n_paths; ii++)
770 rv = mfib_api_path_decode (&mp->route.paths[ii], rpath);
776 eflags = mfib_api_path_entry_flags_decode (mp->route.entry_flags);
777 mfib_entry_index = mroute_add_del_handler (mp->is_add,
781 ntohl (mp->route.rpf_id),
784 if (~0 != mfib_entry_index)
785 *stats_index = mfib_entry_get_stats_index (mfib_entry_index);
792 vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp)
794 vl_api_ip_mroute_add_del_reply_t *rmp;
795 u32 stats_index = ~0;
798 rv = api_mroute_add_del_t_handler (mp, &stats_index);
801 REPLY_MACRO2 (VL_API_IP_MROUTE_ADD_DEL_REPLY,
803 rmp->stats_index = htonl (stats_index);
809 send_ip_details (vpe_api_main_t * am,
810 vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6,
813 vl_api_ip_details_t *mp;
815 mp = vl_msg_api_alloc (sizeof (*mp));
816 clib_memset (mp, 0, sizeof (*mp));
817 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
819 mp->sw_if_index = ntohl (sw_if_index);
820 mp->is_ipv6 = is_ipv6;
821 mp->context = context;
823 vl_api_send_msg (reg, (u8 *) mp);
827 send_ip_address_details (vpe_api_main_t * am,
828 vl_api_registration_t * reg,
829 const fib_prefix_t * pfx,
830 u32 sw_if_index, u32 context)
832 vl_api_ip_address_details_t *mp;
834 mp = vl_msg_api_alloc (sizeof (*mp));
835 clib_memset (mp, 0, sizeof (*mp));
836 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
838 ip_prefix_encode (pfx, &mp->prefix);
839 mp->context = context;
840 mp->sw_if_index = htonl (sw_if_index);
842 vl_api_send_msg (reg, (u8 *) mp);
846 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
848 vpe_api_main_t *am = &vpe_api_main;
849 vl_api_registration_t *reg;
850 ip6_main_t *im6 = &ip6_main;
851 ip4_main_t *im4 = &ip4_main;
852 ip_lookup_main_t *lm6 = &im6->lookup_main;
853 ip_lookup_main_t *lm4 = &im4->lookup_main;
854 ip_interface_address_t *ia = 0;
855 u32 sw_if_index = ~0;
856 int rv __attribute__ ((unused)) = 0;
858 VALIDATE_SW_IF_INDEX (mp);
860 sw_if_index = ntohl (mp->sw_if_index);
862 reg = vl_api_client_index_to_registration (mp->client_index);
869 /* Do not send subnet details of the IP-interface for
870 * unnumbered interfaces. otherwise listening clients
871 * will be confused that the subnet is applied on more
872 * than one interface */
873 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
876 .fp_addr.ip6 = *(ip6_address_t *)ip_interface_address_get_address (lm6, ia),
877 .fp_len = ia->address_length,
878 .fp_proto = FIB_PROTOCOL_IP6,
880 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
887 foreach_ip_interface_address (lm4, ia, sw_if_index, 0,
890 .fp_addr.ip4 = *(ip4_address_t *)ip_interface_address_get_address (lm4, ia),
891 .fp_len = ia->address_length,
892 .fp_proto = FIB_PROTOCOL_IP4,
895 send_ip_address_details(am, reg, &pfx, sw_if_index, mp->context);
900 BAD_SW_IF_INDEX_LABEL;
904 send_ip_unnumbered_details (vpe_api_main_t * am,
905 vl_api_registration_t * reg,
906 u32 sw_if_index, u32 ip_sw_if_index, u32 context)
908 vl_api_ip_unnumbered_details_t *mp;
910 mp = vl_msg_api_alloc (sizeof (*mp));
911 clib_memset (mp, 0, sizeof (*mp));
912 mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
914 mp->context = context;
915 mp->sw_if_index = htonl (sw_if_index);
916 mp->ip_sw_if_index = htonl (ip_sw_if_index);
918 vl_api_send_msg (reg, (u8 *) mp);
922 vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
924 vnet_main_t *vnm = vnet_get_main ();
925 vnet_interface_main_t *im = &vnm->interface_main;
926 int rv __attribute__ ((unused)) = 0;
927 vpe_api_main_t *am = &vpe_api_main;
928 vl_api_registration_t *reg;
929 vnet_sw_interface_t *si;
932 sw_if_index = ntohl (mp->sw_if_index);
934 reg = vl_api_client_index_to_registration (mp->client_index);
938 if (~0 != sw_if_index)
940 VALIDATE_SW_IF_INDEX (mp);
942 si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
944 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
946 send_ip_unnumbered_details (am, reg,
948 si->unnumbered_sw_if_index,
955 pool_foreach (si, im->sw_interfaces)
957 if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
959 send_ip_unnumbered_details(am, reg,
961 si->unnumbered_sw_if_index,
968 BAD_SW_IF_INDEX_LABEL;
972 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
974 vpe_api_main_t *am = &vpe_api_main;
975 vnet_main_t *vnm = vnet_get_main ();
976 //vlib_main_t *vm = vlib_get_main ();
977 vnet_interface_main_t *im = &vnm->interface_main;
978 vl_api_registration_t *reg;
979 vnet_sw_interface_t *si, *sorted_sis;
980 u32 sw_if_index = ~0;
982 reg = vl_api_client_index_to_registration (mp->client_index);
986 /* Gather interfaces. */
987 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
988 _vec_len (sorted_sis) = 0;
990 pool_foreach (si, im->sw_interfaces)
992 vec_add1 (sorted_sis, si[0]);
996 vec_foreach (si, sorted_sis)
998 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
1000 /* if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) */
1004 sw_if_index = si->sw_if_index;
1005 send_ip_details (am, reg, sw_if_index, mp->is_ipv6, mp->context);
1009 vec_free (sorted_sis);
1013 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
1015 vl_api_set_ip_flow_hash_reply_t *rmp;
1018 flow_hash_config_t flow_hash_config = 0;
1020 table_id = ntohl (mp->vrf_id);
1022 #define _(a,b) if (mp->a) flow_hash_config |= b;
1023 foreach_flow_hash_bit;
1026 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
1028 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1032 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
1034 vl_api_set_ip_flow_hash_reply_t *rmp;
1037 flow_hash_config_t flow_hash_config = 0;
1039 table_id = ntohl (mp->vrf_id);
1041 #define _(a,b) if (mp->a) flow_hash_config |= b;
1042 foreach_flow_hash_bit;
1045 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
1047 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
1052 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
1054 if (mp->is_ipv6 == 0)
1055 set_ip4_flow_hash (mp);
1057 set_ip6_flow_hash (mp);
1061 vl_mfib_signal_send_one (vl_api_registration_t * reg,
1062 u32 context, const mfib_signal_t * mfs)
1064 vl_api_mfib_signal_details_t *mp;
1065 const mfib_prefix_t *prefix;
1069 mp = vl_msg_api_alloc (sizeof (*mp));
1071 clib_memset (mp, 0, sizeof (*mp));
1072 mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS);
1073 mp->context = context;
1075 mfi = mfib_itf_get (mfs->mfs_itf);
1076 prefix = mfib_entry_get_prefix (mfs->mfs_entry);
1077 mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry),
1079 mp->table_id = ntohl (mfib->mft_table_id);
1080 mp->sw_if_index = ntohl (mfi->mfi_sw_if_index);
1082 ip_mprefix_encode (prefix, &mp->prefix);
1084 if (0 != mfs->mfs_buffer_len)
1086 mp->ip_packet_len = ntohs (mfs->mfs_buffer_len);
1088 memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len);
1092 mp->ip_packet_len = 0;
1095 vl_api_send_msg (reg, (u8 *) mp);
1099 vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
1101 vl_api_registration_t *reg;
1103 reg = vl_api_client_index_to_registration (mp->client_index);
1107 while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
1112 vl_api_ip_container_proxy_add_del_t_handler
1113 (vl_api_ip_container_proxy_add_del_t * mp)
1115 vl_api_ip_container_proxy_add_del_reply_t *rmp;
1116 vnet_ip_container_proxy_args_t args;
1118 clib_error_t *error;
1120 clib_memset (&args, 0, sizeof (args));
1122 ip_prefix_decode (&mp->pfx, &args.prefix);
1124 args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
1125 args.is_add = mp->is_add;
1126 if ((error = vnet_ip_container_proxy_add_del (&args)))
1128 rv = clib_error_get_code (error);
1129 clib_error_report (error);
1132 REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
1135 typedef struct ip_container_proxy_walk_ctx_t_
1137 vl_api_registration_t *reg;
1139 } ip_container_proxy_walk_ctx_t;
1142 ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
1145 vl_api_ip_container_proxy_details_t *mp;
1146 ip_container_proxy_walk_ctx_t *ctx = args;
1148 mp = vl_msg_api_alloc (sizeof (*mp));
1152 clib_memset (mp, 0, sizeof (*mp));
1153 mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
1154 mp->context = ctx->context;
1156 mp->sw_if_index = ntohl (sw_if_index);
1157 ip_prefix_encode (pfx, &mp->prefix);
1159 vl_api_send_msg (ctx->reg, (u8 *) mp);
1165 vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t *
1168 vl_api_registration_t *reg;
1170 reg = vl_api_client_index_to_registration (mp->client_index);
1174 ip_container_proxy_walk_ctx_t ctx = {
1175 .context = mp->context,
1179 ip_container_proxy_walk (ip_container_proxy_send_details, &ctx);
1183 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1186 vl_api_ioam_enable_reply_t *rmp;
1187 clib_error_t *error;
1189 /* Ignoring the profile id as currently a single profile
1191 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1192 mp->seqno, mp->analyse);
1195 clib_error_report (error);
1196 rv = clib_error_get_code (error);
1199 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1203 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1206 vl_api_ioam_disable_reply_t *rmp;
1207 clib_error_t *error;
1209 error = clear_ioam_rewrite_fn ();
1212 clib_error_report (error);
1213 rv = clib_error_get_code (error);
1216 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1220 vl_api_ip_source_and_port_range_check_add_del_t_handler
1221 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1223 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1226 u8 is_add = mp->is_add;
1229 u16 *high_ports = 0;
1231 u16 tmp_low, tmp_high;
1235 ip_prefix_decode (&mp->prefix, &pfx);
1237 // Validate port range
1238 num_ranges = mp->number_of_ranges;
1239 if (num_ranges > 32)
1240 { // This is size of array in VPE.API
1241 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1245 vec_reset_length (low_ports);
1246 vec_reset_length (high_ports);
1248 for (i = 0; i < num_ranges; i++)
1250 tmp_low = mp->low_ports[i];
1251 tmp_high = mp->high_ports[i];
1252 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1253 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1254 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1256 rv = VNET_API_ERROR_INVALID_VALUE;
1259 vec_add1 (low_ports, tmp_low);
1260 vec_add1 (high_ports, tmp_high + 1);
1263 vrf_id = ntohl (mp->vrf_id);
1267 rv = VNET_API_ERROR_INVALID_VALUE;
1272 if (FIB_PROTOCOL_IP6 == pfx.fp_proto)
1274 rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6,
1278 high_ports, is_add);
1282 rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4,
1286 high_ports, is_add);
1290 vec_free (low_ports);
1291 vec_free (high_ports);
1292 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1296 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1297 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
1299 vlib_main_t *vm = vlib_get_main ();
1300 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
1301 ip4_main_t *im = &ip4_main;
1304 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1305 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1309 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
1310 ntohl (mp->tcp_out_vrf_id);
1311 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
1312 ntohl (mp->udp_out_vrf_id);
1313 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
1314 ntohl (mp->tcp_in_vrf_id);
1315 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
1316 ntohl (mp->udp_in_vrf_id);
1319 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
1321 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
1323 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
1327 rv = VNET_API_ERROR_INVALID_VALUE;
1331 fib_index[i] = p[0];
1336 sw_if_index = ntohl (mp->sw_if_index);
1338 VALIDATE_SW_IF_INDEX (mp);
1341 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
1344 BAD_SW_IF_INDEX_LABEL;
1347 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
1351 vl_api_sw_interface_ip6_set_link_local_address_t_handler
1352 (vl_api_sw_interface_ip6_set_link_local_address_t * mp)
1354 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
1358 VALIDATE_SW_IF_INDEX (mp);
1360 ip6_address_decode (mp->ip, &ip);
1362 rv = ip6_link_set_local_address (ntohl (mp->sw_if_index), &ip);
1364 BAD_SW_IF_INDEX_LABEL;
1365 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
1369 vl_api_sw_interface_ip6_get_link_local_address_t_handler (
1370 vl_api_sw_interface_ip6_get_link_local_address_t *mp)
1372 vl_api_sw_interface_ip6_get_link_local_address_reply_t *rmp;
1373 const ip6_address_t *ip = NULL;
1376 VALIDATE_SW_IF_INDEX (mp);
1378 ip = ip6_get_link_local_address (ntohl (mp->sw_if_index));
1380 rv = VNET_API_ERROR_IP6_NOT_ENABLED;
1382 BAD_SW_IF_INDEX_LABEL;
1383 /* clang-format off */
1384 REPLY_MACRO2 (VL_API_SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS_REPLY,
1387 ip6_address_encode (ip, rmp->ip);
1389 /* clang-format on */
1393 vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp)
1395 vl_api_ip_table_replace_begin_reply_t *rmp;
1396 fib_protocol_t fproto;
1400 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1401 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1403 if (INDEX_INVALID == fib_index)
1404 rv = VNET_API_ERROR_NO_SUCH_FIB;
1407 fib_table_mark (fib_index, fproto, FIB_SOURCE_API);
1408 mfib_table_mark (mfib_table_find (fproto, ntohl (mp->table.table_id)),
1409 fproto, MFIB_SOURCE_API);
1411 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY);
1415 vl_api_ip_table_replace_end_t_handler (vl_api_ip_table_replace_end_t * mp)
1417 vl_api_ip_table_replace_end_reply_t *rmp;
1418 fib_protocol_t fproto;
1422 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1423 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1425 if (INDEX_INVALID == fib_index)
1426 rv = VNET_API_ERROR_NO_SUCH_FIB;
1429 fib_table_sweep (fib_index, fproto, FIB_SOURCE_API);
1430 mfib_table_sweep (mfib_table_find
1431 (fproto, ntohl (mp->table.table_id)), fproto,
1434 REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY);
1438 vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
1440 vl_api_ip_table_flush_reply_t *rmp;
1441 fib_protocol_t fproto;
1445 fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
1446 fib_index = fib_table_find (fproto, ntohl (mp->table.table_id));
1448 if (INDEX_INVALID == fib_index)
1449 rv = VNET_API_ERROR_NO_SUCH_FIB;
1452 vnet_main_t *vnm = vnet_get_main ();
1453 vnet_interface_main_t *im = &vnm->interface_main;
1454 vnet_sw_interface_t *si;
1456 /* Shut down interfaces in this FIB / clean out intfc routes */
1458 pool_foreach (si, im->sw_interfaces)
1460 if (fib_index == fib_table_get_index_for_sw_if_index (fproto,
1463 u32 flags = si->flags;
1464 flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
1465 vnet_sw_interface_set_flags (vnm, si->sw_if_index, flags);
1470 fib_table_flush (fib_index, fproto, FIB_SOURCE_API);
1471 mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)),
1472 fproto, MFIB_SOURCE_API);
1475 REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY);
1479 vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
1481 vl_api_ip_reassembly_set_reply_t *rmp;
1483 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
1485 case IP_REASS_TYPE_FULL:
1488 rv = ip6_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1489 clib_net_to_host_u32
1490 (mp->max_reassemblies),
1491 clib_net_to_host_u32
1492 (mp->max_reassembly_length),
1493 clib_net_to_host_u32
1494 (mp->expire_walk_interval_ms));
1498 rv = ip4_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1499 clib_net_to_host_u32
1500 (mp->max_reassemblies),
1501 clib_net_to_host_u32
1502 (mp->max_reassembly_length),
1503 clib_net_to_host_u32
1504 (mp->expire_walk_interval_ms));
1507 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1511 ip6_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1512 clib_net_to_host_u32 (mp->max_reassemblies),
1513 clib_net_to_host_u32
1514 (mp->max_reassembly_length),
1515 clib_net_to_host_u32
1516 (mp->expire_walk_interval_ms));
1520 rv = ip4_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
1521 clib_net_to_host_u32 (mp->max_reassemblies),
1522 clib_net_to_host_u32
1523 (mp->max_reassembly_length),
1524 clib_net_to_host_u32
1525 (mp->expire_walk_interval_ms));
1530 REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
1534 vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
1536 vl_api_registration_t *rp;
1538 rp = vl_api_client_index_to_registration (mp->client_index);
1542 vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
1543 clib_memset (rmp, 0, sizeof (*rmp));
1544 rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
1545 rmp->context = mp->context;
1548 u32 max_reassemblies;
1549 u32 max_reassembly_length;
1550 u32 expire_walk_interval_ms;
1551 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
1553 case IP_REASS_TYPE_FULL:
1557 ip6_full_reass_get (&timeout_ms, &max_reassemblies,
1558 &max_reassembly_length,
1559 &expire_walk_interval_ms);
1564 ip4_full_reass_get (&timeout_ms, &max_reassemblies,
1565 &max_reassembly_length,
1566 &expire_walk_interval_ms);
1569 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1573 ip6_sv_reass_get (&timeout_ms, &max_reassemblies,
1574 &max_reassembly_length, &expire_walk_interval_ms);
1579 ip4_sv_reass_get (&timeout_ms, &max_reassemblies,
1580 &max_reassembly_length, &expire_walk_interval_ms);
1584 rmp->timeout_ms = clib_host_to_net_u32 (timeout_ms);
1585 rmp->max_reassemblies = clib_host_to_net_u32 (max_reassemblies);
1586 rmp->max_reassembly_length = clib_host_to_net_u32 (max_reassembly_length);
1587 rmp->expire_walk_interval_ms =
1588 clib_host_to_net_u32 (expire_walk_interval_ms);
1589 vl_api_send_msg (rp, (u8 *) rmp);
1593 vl_api_ip_reassembly_enable_disable_t_handler
1594 (vl_api_ip_reassembly_enable_disable_t * mp)
1596 vl_api_ip_reassembly_enable_disable_reply_t *rmp;
1598 switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type))
1600 case IP_REASS_TYPE_FULL:
1602 ip4_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
1606 ip6_full_reass_enable_disable (clib_net_to_host_u32
1607 (mp->sw_if_index), mp->enable_ip6);
1609 case IP_REASS_TYPE_SHALLOW_VIRTUAL:
1611 ip4_sv_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
1616 ip6_sv_reass_enable_disable (clib_net_to_host_u32
1617 (mp->sw_if_index), mp->enable_ip6);
1622 REPLY_MACRO (VL_API_IP_REASSEMBLY_ENABLE_DISABLE_REPLY);
1625 typedef struct ip_punt_redirect_walk_ctx_t_
1627 vl_api_registration_t *reg;
1629 } ip_punt_redirect_walk_ctx_t;
1632 send_ip_punt_redirect_details (u32 rx_sw_if_index,
1633 const ip_punt_redirect_rx_t * ipr, void *arg)
1635 ip_punt_redirect_walk_ctx_t *ctx = arg;
1636 vl_api_ip_punt_redirect_details_t *mp;
1637 fib_path_encode_ctx_t path_ctx = {
1641 mp = vl_msg_api_alloc (sizeof (*mp));
1643 return (WALK_STOP);;
1645 clib_memset (mp, 0, sizeof (*mp));
1646 mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
1647 mp->context = ctx->context;
1649 fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &path_ctx);
1651 mp->punt.rx_sw_if_index = htonl (rx_sw_if_index);
1652 mp->punt.tx_sw_if_index = htonl (path_ctx.rpaths[0].frp_sw_if_index);
1654 ip_address_encode (&path_ctx.rpaths[0].frp_addr,
1655 fib_proto_to_ip46 (ipr->fproto), &mp->punt.nh);
1657 vl_api_send_msg (ctx->reg, (u8 *) mp);
1659 vec_free (path_ctx.rpaths);
1661 return (WALK_CONTINUE);
1665 vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp)
1667 vl_api_registration_t *reg;
1668 fib_protocol_t fproto = FIB_PROTOCOL_IP4;
1670 reg = vl_api_client_index_to_registration (mp->client_index);
1674 if (mp->is_ipv6 == 1)
1675 fproto = FIB_PROTOCOL_IP6;
1677 ip_punt_redirect_walk_ctx_t ctx = {
1679 .context = mp->context,
1682 if (~0 != mp->sw_if_index)
1687 rx_sw_if_index = ntohl (mp->sw_if_index);
1688 pri = ip_punt_redirect_find (fproto, rx_sw_if_index);
1690 if (INDEX_INVALID == pri)
1693 send_ip_punt_redirect_details (rx_sw_if_index,
1694 ip_punt_redirect_get (pri), &ctx);
1697 ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx);
1700 #define vl_msg_name_crc_list
1701 #include <vnet/ip/ip.api.h>
1702 #undef vl_msg_name_crc_list
1705 setup_message_id_table (api_main_t * am)
1707 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1708 foreach_vl_msg_name_crc_ip;
1712 static clib_error_t *
1713 ip_api_hookup (vlib_main_t * vm)
1715 api_main_t *am = vlibapi_get_main ();
1718 vl_msg_api_set_handlers(VL_API_##N, #n, \
1719 vl_api_##n##_t_handler, \
1721 vl_api_##n##_t_endian, \
1722 vl_api_##n##_t_print, \
1723 sizeof(vl_api_##n##_t), 1);
1728 * Mark the route add/del API as MP safe
1730 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1;
1731 am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL_REPLY] = 1;
1734 * Set up the (msg_name, crc, message-id) table
1736 setup_message_id_table (am);
1741 VLIB_API_INIT_FUNCTION (ip_api_hookup);
1744 * fd.io coding-style-patch-verification: ON
1747 * eval: (c-set-style "gnu")