aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/stn
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-12-06 14:42:17 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-12-07 11:23:02 +0000
commit7929f9f5c612b22097d874001e93f5bb38e5ed4f (patch)
tree182a208e8633f40ec4205544ef08db956400ba24 /src/plugins/stn
parent277f03f0673b4be5db0f0eb8b3ed0e63855dbac7 (diff)
stn: use explicit types in api
Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: Ifba4ff0e0f61641ca3f5e7bb72086cb4f32f1909
Diffstat (limited to 'src/plugins/stn')
-rw-r--r--src/plugins/stn/stn.api17
-rw-r--r--src/plugins/stn/stn_api.c31
-rw-r--r--src/plugins/stn/stn_test.c4
3 files changed, 17 insertions, 35 deletions
diff --git a/src/plugins/stn/stn.api b/src/plugins/stn/stn.api
index a3753a9abf9..613d1804684 100644
--- a/src/plugins/stn/stn.api
+++ b/src/plugins/stn/stn.api
@@ -19,12 +19,13 @@
*
*/
-option version = "1.0.0";
+option version = "2.0.0";
+import "vnet/interface_types.api";
+import "vnet/ip/ip_types.api";
/** \brief Add/del STN rules
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
- @param is_ip4 - 1 if address type is IPv4
@param ip_address - STN rule IP address
@param sw_if_index - Interface index
@param is_add - 1 if add, 0 if delete
@@ -32,10 +33,9 @@ option version = "1.0.0";
autoreply manual_print define stn_add_del_rule {
u32 client_index;
u32 context;
- u8 is_ip4;
- u8 ip_address[16];
- u32 sw_if_index;
- u8 is_add;
+ vl_api_address_t ip_address;
+ vl_api_interface_index_t sw_if_index;
+ bool is_add;
};
/** \brief Dump STN rules
@@ -55,8 +55,7 @@ define stn_rules_dump {
*/
define stn_rules_details {
u32 context;
- u8 is_ip4;
- u8 ip_address[16];
- u32 sw_if_index;
+ vl_api_address_t ip_address;
+ vl_api_interface_index_t sw_if_index;
};
diff --git a/src/plugins/stn/stn_api.c b/src/plugins/stn/stn_api.c
index d9f3096b778..a22bbffd2fe 100644
--- a/src/plugins/stn/stn_api.c
+++ b/src/plugins/stn/stn_api.c
@@ -18,7 +18,8 @@
#include <plugins/stn/stn.h>
#include <vnet/ip/format.h>
-
+#include <vnet/format_fns.h>
+#include <vnet/ip/ip_types_api.h>
#include <vppinfra/byte_order.h>
/* define message IDs */
@@ -48,10 +49,7 @@ static void *vl_api_stn_add_del_rule_t_print
u8 *s;
s = format (0, "SCRIPT: stn_add_del_rule ");
- if (mp->is_ip4)
- s = format (s, "address %U ", format_ip4_address, mp->ip_address);
- else
- s = format (s, "address %U ", format_ip6_address, mp->ip_address);
+ s = format (s, "address %U ", format_ip46_address, mp->ip_address);
s = format (s, "sw_if_index %d is_add %d", mp->sw_if_index, mp->is_add);
FINISH;
@@ -64,15 +62,7 @@ vl_api_stn_add_del_rule_t_handler (vl_api_stn_add_del_rule_t * mp)
vl_api_stn_add_del_rule_reply_t *rmp;
int rv = 0;
- if (mp->is_ip4)
- {
- ip4_address_t a;
- memcpy (&a, mp->ip_address, sizeof (a));
- ip46_address_set_ip4 (&args.address, &a);
- }
- else
- memcpy (&args.address.ip6, mp->ip_address, sizeof (ip6_address_t));
-
+ ip_address_decode (&mp->ip_address, &args.address);
args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
args.del = !mp->is_add;
@@ -92,16 +82,9 @@ send_stn_rules_details (stn_rule_t * r, vl_api_registration_t * reg,
rmp->_vl_msg_id =
clib_host_to_net_u16 (VL_API_STN_RULES_DETAILS + stn_main.msg_id_base);
- if (ip46_address_is_ip4 (&r->address))
- {
- clib_memcpy (rmp->ip_address, &r->address.ip4, sizeof (ip4_address_t));
- rmp->is_ip4 = 1;
- }
- else
- {
- clib_memcpy (rmp->ip_address, &r->address.ip6, sizeof (ip6_address_t));
- }
-
+ ip_address_encode (&r->address,
+ ip46_address_is_ip4 (&r->address) ? IP46_TYPE_IP4 :
+ IP46_TYPE_IP6, &rmp->ip_address);
rmp->context = context;
rmp->sw_if_index = clib_host_to_net_u32 (r->sw_if_index);
diff --git a/src/plugins/stn/stn_test.c b/src/plugins/stn/stn_test.c
index c9bf5fe0309..c7514cf77c5 100644
--- a/src/plugins/stn/stn_test.c
+++ b/src/plugins/stn/stn_test.c
@@ -16,7 +16,7 @@
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vppinfra/error.h>
-
+#include <vnet/format_fns.h>
#include <stn/stn.h>
#define __plugin_msg_base stn_test_main.msg_id_base
@@ -81,7 +81,7 @@ vl_api_stn_rules_details_t_handler (vl_api_stn_rules_details_t * mp)
{
vat_main_t *vam = stn_test_main.vat_main;
fformat (vam->ofp, "addr: %U sw_if_index: %u\n",
- mp->is_ip4 ? format_ip4_address : format_ip6_address,
+ format_ip46_address,
mp->ip_address, clib_net_to_host_u32 (mp->sw_if_index));
}