aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjackiechen1985 <xiaobo.chen@tieto.com>2019-06-19 15:00:10 +0800
committerTianyi Wang <tianyi.wang@tieto.com>2019-07-01 02:59:14 +0000
commitf086b6eec410b18daba34e6a0dd64f46c076bbe7 (patch)
tree347f0cc60dce7c79c087f9856ddc393efda03a0d
parent9577e763933b61cc34f77e8b8f886e78c00176fc (diff)
SCVPP callback helper function enhancement:
- Combine VAPI_RETVAL_CB and VAPI_COPY_CB. Replace them with VAPI_REQUEST_CB; - Add VAPI_REQUEST_CB2 to process VPP Variable-Length reply structure; Change-Id: Ib66003a40d98e4e0b159ae74c9cb8dcd88c34099 Signed-off-by: jackiechen1985 <xiaobo.chen@tieto.com>
-rw-r--r--src/scvpp/inc/scvpp/comm.h34
-rw-r--r--src/scvpp/src/interface.c2
-rw-r--r--src/scvpp/src/ip.c4
-rw-r--r--src/scvpp/src/nat.c10
-rw-r--r--src/scvpp/src/v3po.c4
5 files changed, 30 insertions, 24 deletions
diff --git a/src/scvpp/inc/scvpp/comm.h b/src/scvpp/inc/scvpp/comm.h
index ed02d5d..687db5d 100644
--- a/src/scvpp/inc/scvpp/comm.h
+++ b/src/scvpp/inc/scvpp/comm.h
@@ -79,29 +79,35 @@ DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
* parameter in function prototype. */
#define UNUSED(x) (void)x
-#define VAPI_RETVAL_CB(api_name) \
+#define VAPI_REQUEST_CB(api_name) \
static vapi_error_e \
-api_name##_cb (vapi_ctx_t ctx, void *caller_ctx, vapi_error_e rv, bool is_last, \
- vapi_payload_##api_name##_reply * reply) \
+api_name##_cb (struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, \
+ bool is_last, vapi_payload_##api_name##_reply * reply) \
{ \
- UNUSED(ctx); UNUSED(caller_ctx); UNUSED(rv); UNUSED(is_last); \
+ UNUSED(ctx); UNUSED(rv); UNUSED(is_last); \
+ if (callback_ctx) { \
+ memcpy(callback_ctx, reply, sizeof(vapi_payload_##api_name##_reply)); \
+ } \
return reply->retval; \
}
-#define VAPI_COPY_CB(api_name) \
+#define VAPI_REQUEST_CB_EXTRA(api_name, member) \
static vapi_error_e \
-api_name##_cb (vapi_ctx_t ctx, void *caller_ctx, vapi_error_e rv, bool is_last, \
- vapi_payload_##api_name##_reply * reply) \
+api_name##_cb (struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, \
+ bool is_last, vapi_payload_##api_name##_reply * reply) \
{ \
UNUSED(ctx); UNUSED(rv); UNUSED(is_last); \
- vapi_payload_##api_name##_reply * passed; \
- if (caller_ctx) \
- { \
- passed = (vapi_payload_##api_name##_reply *)caller_ctx; \
- *passed = *reply; \
+ vapi_payload_##api_name##_reply **p = callback_ctx; \
+ int size = sizeof(vapi_payload_##api_name##_reply) + reply->member; \
+ if (p) { \
+ *p = malloc(size); \
+ if (!*p) { \
+ return VAPI_ENOMEM; \
+ } \
+ memcpy(*p, reply, size); \
} \
- return VAPI_OK; \
-}\
+ return reply->retval; \
+}
#define VAPI_CALL_MODE(call_code, vapi_mode) \
do \
diff --git a/src/scvpp/src/interface.c b/src/scvpp/src/interface.c
index 8f3b30b..3a30dc5 100644
--- a/src/scvpp/src/interface.c
+++ b/src/scvpp/src/interface.c
@@ -125,7 +125,7 @@ struct elt* interface_dump_all()
return stack;
}
-VAPI_RETVAL_CB(sw_interface_set_flags);
+VAPI_REQUEST_CB(sw_interface_set_flags);
int interface_enable(const char *interface_name, const bool enable)
{
diff --git a/src/scvpp/src/ip.c b/src/scvpp/src/ip.c
index 2dc991c..f2234f2 100644
--- a/src/scvpp/src/ip.c
+++ b/src/scvpp/src/ip.c
@@ -24,7 +24,7 @@
// Use VAPI macros to define symbols
DEFINE_VAPI_MSG_IDS_IP_API_JSON
-VAPI_RETVAL_CB(sw_interface_add_del_address);
+VAPI_REQUEST_CB(sw_interface_add_del_address);
static vapi_error_e
bin_api_sw_interface_add_del_address(u32 sw_if_index, bool is_add, bool is_ipv6,
@@ -53,7 +53,7 @@ bin_api_sw_interface_add_del_address(u32 sw_if_index, bool is_add, bool is_ipv6,
return rv;
}
-VAPI_COPY_CB(ip_add_del_route)
+VAPI_REQUEST_CB(ip_add_del_route)
static vapi_error_e
bin_api_ip_add_del_route(vapi_payload_ip_add_del_route_reply * reply,
diff --git a/src/scvpp/src/nat.c b/src/scvpp/src/nat.c
index 17ace64..1ff59f3 100644
--- a/src/scvpp/src/nat.c
+++ b/src/scvpp/src/nat.c
@@ -64,7 +64,7 @@ bin_api_nat44_interface_dump(vapi_payload_nat44_interface_details *reply)
return rv;
}
-VAPI_RETVAL_CB(nat44_add_del_interface_addr);
+VAPI_REQUEST_CB(nat44_add_del_interface_addr);
static vapi_error_e
bin_api_nat44_add_del_interface_addr(
@@ -87,7 +87,7 @@ bin_api_nat44_add_del_interface_addr(
return rv;
}
-VAPI_RETVAL_CB(nat44_add_del_address_range);
+VAPI_REQUEST_CB(nat44_add_del_address_range);
static vapi_error_e
bin_api_nat44_add_del_addr_range(
@@ -111,7 +111,7 @@ bin_api_nat44_add_del_addr_range(
return rv;
}
-VAPI_RETVAL_CB(nat44_add_del_static_mapping);
+VAPI_REQUEST_CB(nat44_add_del_static_mapping);
static vapi_error_e
bin_api_nat44_add_del_static_mapping(
@@ -173,7 +173,7 @@ bin_api_nat44_static_mapping_dump(
return rv;
}
-VAPI_RETVAL_CB(nat44_forwarding_enable_disable);
+VAPI_REQUEST_CB(nat44_forwarding_enable_disable);
static vapi_error_e bin_api_nat44_forwarding_enable_disable(
const vapi_payload_nat44_forwarding_enable_disable *msg)
@@ -194,7 +194,7 @@ static vapi_error_e bin_api_nat44_forwarding_enable_disable(
return rv;
}
-VAPI_RETVAL_CB(nat_set_workers);
+VAPI_REQUEST_CB(nat_set_workers);
static vapi_error_e
bin_api_nat_set_workers(const vapi_payload_nat_set_workers *msg)
diff --git a/src/scvpp/src/v3po.c b/src/scvpp/src/v3po.c
index f0a41c5..bdb15e1 100644
--- a/src/scvpp/src/v3po.c
+++ b/src/scvpp/src/v3po.c
@@ -31,7 +31,7 @@ DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON
// Delete tapv2
-VAPI_RETVAL_CB(tap_delete_v2);
+VAPI_REQUEST_CB(tap_delete_v2);
static vapi_error_e bin_api_delete_tapv2(u32 sw_if_index)
{
@@ -69,7 +69,7 @@ int delete_tapv2(char *iface_name)
// Create tapv2
-VAPI_RETVAL_CB(tap_create_v2);
+VAPI_REQUEST_CB(tap_create_v2);
int create_tapv2(tapv2_create_t *query)
{