ikev2: add support for custom ipsec-over-udp port
[vpp.git] / src / plugins / dns / dns.c
index 5c51a44..bdf1496 100644 (file)
 #include <stdbool.h>
 
 /* define message IDs */
-#include <dns/dns_msg_enum.h>
-
-/* define message structures */
-#define vl_typedefs
-#include <dns/dns_all_api_h.h>
-#undef vl_typedefs
-
-/* define generated endian-swappers */
-#define vl_endianfun
-#include <dns/dns_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 <dns/dns_all_api_h.h>
-#undef vl_printfun
-
-/* Get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <dns/dns_all_api_h.h>
-#undef vl_api_version
+#include <dns/dns.api_enum.h>
+#include <dns/dns.api_types.h>
 
 #define REPLY_MSG_ID_BASE dm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
 /* Macro to finish up custom dump fns */
+#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define FINISH                                  \
     vec_add1 (s, 0);                            \
     vl_print (handle, (char *)s);               \
@@ -816,6 +797,8 @@ dns_add_static_entry (dns_main_t * dm, u8 * name, u8 * dns_reply_data)
 
   /* Note: consumes the name vector */
   ep->name = name;
+  /* make sure it NULL-terminated as hash_set_mem will use strlen() */
+  vec_terminate_c_string (ep->name);
   hash_set_mem (dm->cache_entry_by_name, ep->name, ep - dm->entries);
   ep->flags = DNS_CACHE_ENTRY_FLAG_VALID | DNS_CACHE_ENTRY_FLAG_STATIC;
   ep->dns_response = dns_reply_data;
@@ -1576,25 +1559,6 @@ vl_api_dns_resolve_ip_t_handler (vl_api_dns_resolve_ip_t * mp)
   dns_cache_unlock (dm);
 }
 
-#define vl_msg_name_crc_list
-#include <dns/dns_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-static void
-setup_message_id_table (dns_main_t * dm)
-{
-#define _(id,n,crc) \
-  vl_msg_api_add_msg_name_crc (dm->api_main, #n "_" #crc, dm->msg_id_base + id);
-  foreach_vl_msg_name_crc_dns;
-#undef _
-}
-
-#define foreach_dns_plugin_api_msg                      \
-_(DNS_ENABLE_DISABLE, dns_enable_disable)               \
-_(DNS_NAME_SERVER_ADD_DEL, dns_name_server_add_del)     \
-_(DNS_RESOLVE_NAME, dns_resolve_name)                  \
-_(DNS_RESOLVE_IP, dns_resolve_ip)
-
 static clib_error_t *
 dns_config_fn (vlib_main_t * vm, unformat_input_t * input)
 {
@@ -2793,7 +2757,7 @@ vnet_send_dns4_reply (dns_main_t * dm, dns_pending_request_t * pr,
   u8 *reply;
   vl_api_dns_resolve_name_reply_t _rnr, *rnr = &_rnr;
   vl_api_dns_resolve_ip_reply_t _rir, *rir = &_rir;
-  u32 ttl, tmp;
+  u32 ttl = 64, tmp;
   u32 qp_offset;
   dns_query_t *qp;
   dns_rr_t *rr;
@@ -3081,62 +3045,21 @@ static void *vl_api_dns_resolve_ip_t_print
   FINISH;
 }
 
-static void
-dns_custom_dump_configure (dns_main_t * dm)
-{
-#define _(n,f) dm->api_main->msg_print_handlers \
-  [VL_API_##n + dm->msg_id_base]                \
-    = (void *) vl_api_##f##_t_print;
-  foreach_dns_plugin_api_msg;
-#undef _
-}
-
-/* Set up the API message handling tables */
-static clib_error_t *
-dns_plugin_api_hookup (vlib_main_t * vm)
-{
-  dns_main_t *dmp = &dns_main;
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + dmp->msg_id_base),    \
-                           #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_dns_plugin_api_msg;
-#undef _
-
-  return 0;
-}
-
+#include <dns/dns.api.c>
 static clib_error_t *
 dns_init (vlib_main_t * vm)
 {
   dns_main_t *dm = &dns_main;
-  u8 *name;
 
   dm->vlib_main = vm;
   dm->vnet_main = vnet_get_main ();
   dm->name_cache_size = 1000;
   dm->max_ttl_in_seconds = 86400;
   dm->random_seed = 0xDEADDABE;
-  dm->api_main = &api_main;
-
-  name = format (0, "dns_%08x%c", api_version, 0);
+  dm->api_main = vlibapi_get_main ();
 
   /* Ask for a correctly-sized block of API message decode slots */
-  dm->msg_id_base = vl_msg_api_get_msg_ids
-    ((char *) name, VL_MSG_FIRST_AVAILABLE);
-
-  (void) dns_plugin_api_hookup (vm);
-
-  /* Add our API messages to the global name_crc hash table */
-  setup_message_id_table (dm);
-
-  dns_custom_dump_configure (dm);
-
-  vec_free (name);
+  dm->msg_id_base = setup_message_id_table ();
 
   return 0;
 }