ip: api cleanup
[vpp.git] / src / vnet / ip / ip_api.c
index 91b12e5..6f06e38 100644 (file)
 #include <vnet/ip/ip_table.h>
 #include <vnet/ip/ip_container_proxy.h>
 
-#include <vnet/vnet_msg_enum.h>
-
-#define vl_typedefs            /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun           /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define vl_printfun
-#include <vnet/vnet_all_api_h.h>
-#undef vl_printfun
-
-#include <vlibapi/api_helper_macros.h>
-
 #include <vnet/format_fns.h>
+#include <vnet/ip/ip.api_enum.h>
+#include <vnet/ip/ip.api_types.h>
 
-#define foreach_ip_api_msg                                                    \
-  _ (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable)        \
-  _ (IP_TABLE_DUMP, ip_table_dump)                                            \
-  _ (IP_ROUTE_DUMP, ip_route_dump)                                            \
-  _ (IP_ROUTE_V2_DUMP, ip_route_v2_dump)                                      \
-  _ (IP_MTABLE_DUMP, ip_mtable_dump)                                          \
-  _ (IP_MROUTE_DUMP, ip_mroute_dump)                                          \
-  _ (IP_MROUTE_ADD_DEL, ip_mroute_add_del)                                    \
-  _ (MFIB_SIGNAL_DUMP, mfib_signal_dump)                                      \
-  _ (IP_ADDRESS_DUMP, ip_address_dump)                                        \
-  _ (IP_UNNUMBERED_DUMP, ip_unnumbered_dump)                                  \
-  _ (IP_DUMP, ip_dump)                                                        \
-  _ (IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin)                          \
-  _ (IP_TABLE_REPLACE_END, ip_table_replace_end)                              \
-  _ (IP_TABLE_FLUSH, ip_table_flush)                                          \
-  _ (IP_ROUTE_ADD_DEL, ip_route_add_del)                                      \
-  _ (IP_ROUTE_ADD_DEL_V2, ip_route_add_del_v2)                                \
-  _ (IP_ROUTE_LOOKUP, ip_route_lookup)                                        \
-  _ (IP_ROUTE_LOOKUP_V2, ip_route_lookup_v2)                                  \
-  _ (IP_TABLE_ADD_DEL, ip_table_add_del)                                      \
-  _ (IP_PUNT_POLICE, ip_punt_police)                                          \
-  _ (IP_PUNT_REDIRECT, ip_punt_redirect)                                      \
-  _ (SET_IP_FLOW_HASH, set_ip_flow_hash)                                      \
-  _ (SET_IP_FLOW_HASH_V2, set_ip_flow_hash_v2)                                \
-  _ (SET_IP_FLOW_HASH_ROUTER_ID, set_ip_flow_hash_router_id)                  \
-  _ (IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del)                  \
-  _ (IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump)                        \
-  _ (IOAM_ENABLE, ioam_enable)                                                \
-  _ (IOAM_DISABLE, ioam_disable)                                              \
-  _ (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,                                  \
-     ip_source_and_port_range_check_add_del)                                  \
-  _ (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,                        \
-     ip_source_and_port_range_check_interface_add_del)                        \
-  _ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,                                 \
-     sw_interface_ip6_set_link_local_address)                                 \
-  _ (SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS,                                 \
-     sw_interface_ip6_get_link_local_address)                                 \
-  _ (IP_REASSEMBLY_SET, ip_reassembly_set)                                    \
-  _ (IP_REASSEMBLY_GET, ip_reassembly_get)                                    \
-  _ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable)              \
-  _ (IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump)                            \
-  _ (IP_PATH_MTU_UPDATE, ip_path_mtu_update)                                  \
-  _ (IP_PATH_MTU_REPLACE_BEGIN, ip_path_mtu_replace_begin)                    \
-  _ (IP_PATH_MTU_REPLACE_END, ip_path_mtu_replace_end)                        \
-  _ (IP_PATH_MTU_GET, ip_path_mtu_get)
+#define REPLY_MSG_ID_BASE ip4_main.msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 static void
   vl_api_sw_interface_ip6_enable_disable_t_handler
@@ -143,7 +84,7 @@ send_ip_table_details (vpe_api_main_t * am,
   if (!mp)
     return;
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_TABLE_DETAILS);
   mp->context = context;
 
   mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6);
@@ -215,7 +156,7 @@ send_ip_route_details (vpe_api_main_t * am,
   if (!mp)
     return;
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_ROUTE_DETAILS);
   mp->context = context;
 
   ip_prefix_encode (pfx, &mp->route.prefix);
@@ -257,7 +198,7 @@ send_ip_route_v2_details (vpe_api_main_t *am, vl_api_registration_t *reg,
   if (!mp)
     return;
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_V2_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_ROUTE_V2_DETAILS);
   mp->context = context;
 
   ip_prefix_encode (pfx, &mp->route.prefix);
@@ -366,7 +307,7 @@ send_ip_mtable_details (vl_api_registration_t * reg,
   if (!mp)
     return;
   memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_MTABLE_DETAILS);
   mp->context = context;
 
   mp->table.table_id = htonl (mfib_table->mft_table_id);
@@ -432,7 +373,7 @@ send_ip_mroute_details (vpe_api_main_t * am,
   if (!mp)
     return;
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_MROUTE_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_MROUTE_DETAILS);
   mp->context = context;
 
   ip_mprefix_encode (pfx, &mp->route.prefix);
@@ -1031,7 +972,7 @@ send_ip_details (vpe_api_main_t * am,
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_DETAILS);
 
   mp->sw_if_index = ntohl (sw_if_index);
   mp->is_ipv6 = is_ipv6;
@@ -1050,7 +991,7 @@ send_ip_address_details (vpe_api_main_t * am,
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_ADDRESS_DETAILS);
 
   ip_prefix_encode (pfx, &mp->prefix);
   mp->context = context;
@@ -1126,7 +1067,7 @@ send_ip_unnumbered_details (vpe_api_main_t * am,
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_UNNUMBERED_DETAILS);
 
   mp->context = context;
   mp->sw_if_index = htonl (sw_if_index);
@@ -1286,7 +1227,7 @@ vl_mfib_signal_send_one (vl_api_registration_t * reg,
   mp = vl_msg_api_alloc (sizeof (*mp));
 
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_MFIB_SIGNAL_DETAILS);
   mp->context = context;
 
   mfi = mfib_itf_get (mfs->mfs_itf);
@@ -1367,7 +1308,8 @@ ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index,
     return 1;
 
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_CONTAINER_PROXY_DETAILS);
+  mp->_vl_msg_id =
+    ntohs (REPLY_MSG_ID_BASE + VL_API_IP_CONTAINER_PROXY_DETAILS);
   mp->context = ctx->context;
 
   mp->sw_if_index = ntohl (sw_if_index);
@@ -1758,7 +1700,7 @@ vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
 
   vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
   clib_memset (rmp, 0, sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
+  rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_REASSEMBLY_GET_REPLY);
   rmp->context = mp->context;
   rmp->retval = 0;
   u32 timeout_ms;
@@ -1854,7 +1796,7 @@ send_ip_punt_redirect_details (u32 rx_sw_if_index,
     return (WALK_STOP);;
 
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IP_PUNT_REDIRECT_DETAILS);
   mp->context = ctx->context;
 
   fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &path_ctx);
@@ -1975,33 +1917,13 @@ vl_api_ip_path_mtu_get_t_handler (vl_api_ip_path_mtu_get_t *mp)
     ({ send_ip_path_mtu_details (cursor, rp, mp->context); }));
 }
 
-#define vl_msg_name_crc_list
-#include <vnet/ip/ip.api.h>
-#undef vl_msg_name_crc_list
-
-static void
-setup_message_id_table (api_main_t * am)
-{
-#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
-  foreach_vl_msg_name_crc_ip;
-#undef _
-}
+#include <vnet/ip/ip.api.c>
 
 static clib_error_t *
 ip_api_hookup (vlib_main_t * vm)
 {
   api_main_t *am = vlibapi_get_main ();
 
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers(VL_API_##N, #n,                     \
-                           vl_api_##n##_t_handler,              \
-                           vl_noop_handler,                     \
-                           vl_api_##n##_t_endian,               \
-                           vl_api_##n##_t_print,                \
-                           sizeof(vl_api_##n##_t), 1);
-  foreach_ip_api_msg;
-#undef _
-
   /*
    * Mark the route add/del API as MP safe
    */
@@ -2013,7 +1935,7 @@ ip_api_hookup (vlib_main_t * vm)
   /*
    * Set up the (msg_name, crc, message-id) table
    */
-  setup_message_id_table (am);
+  REPLY_MSG_ID_BASE = setup_message_id_table ();
 
   return 0;
 }