summaryrefslogtreecommitdiffstats
path: root/src/plugins/dns
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-09-27 09:07:51 +0200
committerNeale Ranns <nranns@cisco.com>2019-09-27 09:05:29 +0000
commitb922f16ba532d09f920776a04117e41f173dec8e (patch)
tree07456d2b44c86e39da92cc7805835450aaa2fa80 /src/plugins/dns
parent9f3d21170a3c408707e07e4f3ffbee2fd27c2b03 (diff)
dns: remove api boilerplate
Type: refactor Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: Ifffa86b45dd1f213ba974a296ab64202b672a6df
Diffstat (limited to 'src/plugins/dns')
-rw-r--r--src/plugins/dns/CMakeLists.txt2
-rw-r--r--src/plugins/dns/dns.api4
-rw-r--r--src/plugins/dns/dns.c89
-rw-r--r--src/plugins/dns/dns_all_api_h.h19
-rw-r--r--src/plugins/dns/dns_msg_enum.h31
-rw-r--r--src/plugins/dns/dns_test.c97
-rw-r--r--src/plugins/dns/resolver_process.c17
7 files changed, 14 insertions, 245 deletions
diff --git a/src/plugins/dns/CMakeLists.txt b/src/plugins/dns/CMakeLists.txt
index 5d1ac8628db..e9e3b432411 100644
--- a/src/plugins/dns/CMakeLists.txt
+++ b/src/plugins/dns/CMakeLists.txt
@@ -24,8 +24,6 @@ add_vpp_plugin(dns
dns.api
INSTALL_HEADERS
- dns_all_api_h.h
- dns_msg_enum.h
dns_packet.h
API_TEST_SOURCES
diff --git a/src/plugins/dns/dns.api b/src/plugins/dns/dns.api
index a4faec6bbb5..866ed8abae3 100644
--- a/src/plugins/dns/dns.api
+++ b/src/plugins/dns/dns.api
@@ -25,6 +25,7 @@ autoreply manual_print define dns_enable_disable {
u32 client_index;
u32 context;
u8 enable;
+ option vat_help = "[enable][disable]";
};
/** \brief add or delete an upstream name server
@@ -41,6 +42,7 @@ autoreply manual_print define dns_name_server_add_del {
u8 is_ip6;
u8 is_add;
u8 server_address[16];
+ option vat_help = "<ip-address> [del]";
};
/** \brief DNS name resolution request
@@ -53,6 +55,7 @@ manual_print define dns_resolve_name {
u32 client_index;
u32 context;
u8 name[256];
+ option vat_help = "<hostname>";
};
/** \brief DNS name resolution reply
@@ -86,6 +89,7 @@ manual_print define dns_resolve_ip {
u32 context;
u8 is_ip6;
u8 address[16];
+ option vat_help = "<ip4|ip6>";
};
/** \brief DNS ip->name resolution reply
diff --git a/src/plugins/dns/dns.c b/src/plugins/dns/dns.c
index 5c51a446d98..4a882ebddc1 100644
--- a/src/plugins/dns/dns.c
+++ b/src/plugins/dns/dns.c
@@ -25,33 +25,14 @@
#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); \
@@ -1576,25 +1557,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)
{
@@ -3081,40 +3043,11 @@ 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 ();
@@ -3123,20 +3056,8 @@ dns_init (vlib_main_t * vm)
dm->random_seed = 0xDEADDABE;
dm->api_main = &api_main;
- name = format (0, "dns_%08x%c", api_version, 0);
-
/* 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;
}
diff --git a/src/plugins/dns/dns_all_api_h.h b/src/plugins/dns/dns_all_api_h.h
deleted file mode 100644
index c226bcf18a4..00000000000
--- a/src/plugins/dns/dns_all_api_h.h
+++ /dev/null
@@ -1,19 +0,0 @@
-
-/*
- * dns_all_api_h.h - skeleton vpp engine plug-in api #include file
- *
- * Copyright (c) <current-year> <your-organization>
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/* Include the generated file, see BUILT_SOURCES in Makefile.am */
-#include <dns/dns.api.h>
diff --git a/src/plugins/dns/dns_msg_enum.h b/src/plugins/dns/dns_msg_enum.h
deleted file mode 100644
index bad374f7969..00000000000
--- a/src/plugins/dns/dns_msg_enum.h
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/*
- * dns_msg_enum.h - skeleton vpp engine plug-in message enumeration
- *
- * Copyright (c) <current-year> <your-organization>
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef included_dns_msg_enum_h
-#define included_dns_msg_enum_h
-
-#include <vppinfra/byte_order.h>
-
-#define vl_msg_id(n,h) n,
-typedef enum {
-#include <dns/dns_all_api_h.h>
- /* We'll want to know how many messages IDs we need... */
- VL_MSG_FIRST_AVAILABLE,
-} vl_msg_id_t;
-#undef vl_msg_id
-
-#endif /* included_dns_msg_enum_h */
diff --git a/src/plugins/dns/dns_test.c b/src/plugins/dns/dns_test.c
index 6b0b371dca1..9d5be8fcc1b 100644
--- a/src/plugins/dns/dns_test.c
+++ b/src/plugins/dns/dns_test.c
@@ -24,29 +24,8 @@
uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
/* Declare message IDs */
-#include <dns/dns_msg_enum.h>
-
-/* define message structures */
-#define vl_typedefs
-#include <dns/dns_all_api_h.h>
-#undef vl_typedefs
-
-/* declare message handlers for each api */
-
-#define vl_endianfun /* define message structures */
-#include <dns/dns_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...)
-#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>
typedef struct
{
@@ -60,26 +39,6 @@ dns_test_main_t dns_test_main;
#define __plugin_msg_base dns_test_main.msg_id_base
#include <vlibapi/vat_helper_macros.h>
-#define foreach_standard_reply_retval_handler \
-_(dns_enable_disable_reply) \
-_(dns_name_server_add_del_reply)
-
-#define _(n) \
- static void vl_api_##n##_t_handler \
- (vl_api_##n##_t * mp) \
- { \
- vat_main_t * vam = dns_test_main.vat_main; \
- i32 retval = (i32) clib_net_to_host_u32(mp->retval); \
- if (vam->async_mode) { \
- vam->async_errors += (retval < 0); \
- } else { \
- vam->retval = retval; \
- vam->result_ready = 1; \
- } \
- }
-foreach_standard_reply_retval_handler;
-#undef _
-
static void vl_api_dns_resolve_name_reply_t_handler
(vl_api_dns_resolve_name_reply_t * mp)
{
@@ -117,16 +76,6 @@ static void vl_api_dns_resolve_ip_reply_t_handler
}
}
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_vpe_api_reply_msg \
-_(DNS_ENABLE_DISABLE_REPLY, dns_enable_disable_reply) \
-_(DNS_NAME_SERVER_ADD_DEL_REPLY, dns_name_server_add_del_reply) \
-_(DNS_RESOLVE_NAME_REPLY, dns_resolve_name_reply) \
-_(DNS_RESOLVE_IP_REPLY, dns_resolve_ip_reply)
-
static int
api_dns_enable_disable (vat_main_t * vam)
{
@@ -158,18 +107,6 @@ api_dns_enable_disable (vat_main_t * vam)
return ret;
}
-/*
- * List of messages that the api test plugin sends,
- * and that the data plane plugin processes
- */
-#define foreach_vpe_api_msg \
-_(dns_enable_disable, "[enable][disable]") \
-_(dns_name_server_add_del, "<ip-address> [del]") \
-_(dns_resolve_name, "<hostname>") \
-_(dns_resolve_ip, "<ip4|ip6>") \
-_(dns_name_server_add_del, "<ip-address> [del]") \
-_(dns_resolve_name, "<hostname>")
-
static int
api_dns_resolve_name (vat_main_t * vam)
{
@@ -307,35 +244,7 @@ api_dns_name_server_add_del (vat_main_t * vam)
return ret;
}
-static void
-dns_api_hookup (vat_main_t * vam)
-{
- dns_test_main_t *dtmp = &dns_test_main;
- /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n) \
- vl_msg_api_set_handlers((VL_API_##N + dtmp->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_vpe_api_reply_msg;
-#undef _
-
- /* API messages we can send */
-#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
- foreach_vpe_api_msg;
-#undef _
-
- /* Help strings */
-#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
- foreach_vpe_api_msg;
-#undef _
-}
-
-VAT_PLUGIN_REGISTER (dns);
-
+#include <dns/dns.api_test.c>
/*
* fd.io coding-style-patch-verification: ON
diff --git a/src/plugins/dns/resolver_process.c b/src/plugins/dns/resolver_process.c
index 51fe9d76a08..71e5ba2ffab 100644
--- a/src/plugins/dns/resolver_process.c
+++ b/src/plugins/dns/resolver_process.c
@@ -21,21 +21,8 @@
#include <vnet/vnet.h>
/* define message IDs */
-#include <dns/dns_msg_enum.h>
-
-#define vl_typedefs /* define message structures */
-#include <dns/dns_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun /* define message structures */
-#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
+#include <dns/dns.api_enum.h>
+#include <dns/dns.api_types.h>
#include <vlibapi/api_helper_macros.h>