diff options
Diffstat (limited to 'src/scvpp/src')
-rw-r--r-- | src/scvpp/src/CMakeLists.txt | 57 | ||||
-rw-r--r-- | src/scvpp/src/comm.c (renamed from src/scvpp/src/sc_vpp_comm.c) | 22 | ||||
-rw-r--r-- | src/scvpp/src/interface.c | 176 | ||||
-rw-r--r-- | src/scvpp/src/ip.c (renamed from src/scvpp/src/sc_vpp_ip.c) | 185 | ||||
-rw-r--r-- | src/scvpp/src/nat.c (renamed from src/scvpp/src/sc_vpp_nat.c) | 133 | ||||
-rw-r--r-- | src/scvpp/src/sc_vpp_comm.h | 136 | ||||
-rw-r--r-- | src/scvpp/src/sc_vpp_interface.c | 252 | ||||
-rw-r--r-- | src/scvpp/src/sc_vpp_interface.h | 61 | ||||
-rw-r--r-- | src/scvpp/src/sc_vpp_ip.h | 36 | ||||
-rw-r--r-- | src/scvpp/src/sc_vpp_nat.h | 61 | ||||
-rw-r--r-- | src/scvpp/src/sc_vpp_v3po.h | 26 | ||||
-rw-r--r-- | src/scvpp/src/v3po.c (renamed from src/scvpp/src/sc_vpp_v3po.c) | 66 |
12 files changed, 384 insertions, 827 deletions
diff --git a/src/scvpp/src/CMakeLists.txt b/src/scvpp/src/CMakeLists.txt deleted file mode 100644 index 71a891f..0000000 --- a/src/scvpp/src/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright (c) 2018 Cisco and/or its affiliates. -# 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. -# - -# scvpp sources -set(SCVPP_SOURCES - sc_vpp_comm.c - sc_vpp_interface.c - sc_vpp_ip.c - sc_vpp_v3po.c - sc_vpp_nat.c -) - -# scvpp public headers -set(SCVPP_HEADERS - sc_vpp_comm.h - sc_vpp_interface.h - sc_vpp_ip.h - sc_vpp_v3po.h - sc_vpp_nat.h -) - -# Generate a compile_commands.json with compile options -set(CMAKE_EXPORT_COMPILE_COMMANDS 1) - -#set compiler and linker flags -set(RIGOROUS_C_FLAGS "-Wlogical-op -Wformat=2") -set(CMAKE_C_FLAGS "-Wall -Wextra -std=gnu99 ${RIGOROUS_C_FLAGS}") -set(CMAKE_C_FLAGS_DEBUG "-Wall -Wextra -std=gnu99 -g -O0 ${RIGOROUS_C_FLAGS}") -#NDEBUG to skip assert checks -set(CMAKE_C_FLAGS_RELEASE "-Wall -Wextra -std=gnu99 -DNDEBUG -O2 ${RIGOROUS_C_FLAGS}") - -# libraries to link with -set(LINK_LIBRARIES vlibmemoryclient vapiclient vppapiclient svm vppinfra pthread rt dl) - -# build instructions -add_library(scvpp SHARED ${SCVPP_SOURCES}) -add_library(scvpp_a ${SCVPP_SOURCES}) - -# linker instructions -target_link_libraries(scvpp ${LINK_LIBRARIES}) -target_link_libraries(scvpp_a ${LINK_LIBRARIES}) - -# install rules -install(TARGETS scvpp DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(FILES ${SCVPP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/src/scvpp/src/sc_vpp_comm.c b/src/scvpp/src/comm.c index cd0b035..a065b58 100644 --- a/src/scvpp/src/sc_vpp_comm.c +++ b/src/scvpp/src/comm.c @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "sc_vpp_comm.h" +#include <scvpp/comm.h> #include <assert.h> #include <string.h> @@ -24,21 +24,21 @@ #define MAX_OUTSTANDING_REQUESTS 4 #define RESPONSE_QUEUE_SIZE 2 -vapi_ctx_t g_vapi_ctx_instance = NULL; +vapi_ctx_t g_vapi_ctx = NULL; vapi_mode_e g_vapi_mode = VAPI_MODE_NONBLOCKING; int sc_connect_vpp() { - if (g_vapi_ctx_instance == NULL) + if (g_vapi_ctx == NULL) { - vapi_error_e rv = vapi_ctx_alloc(&g_vapi_ctx_instance); - rv = vapi_connect(g_vapi_ctx_instance, APP_NAME, NULL, + vapi_error_e rv = vapi_ctx_alloc(&g_vapi_ctx); + rv = vapi_connect(g_vapi_ctx, APP_NAME, NULL, MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE, VAPI_MODE_BLOCKING, true); if (rv != VAPI_OK) { - vapi_ctx_free(g_vapi_ctx_instance); - g_vapi_ctx_instance = NULL; + vapi_ctx_free(g_vapi_ctx); + g_vapi_ctx = NULL; return -1; } } @@ -48,11 +48,11 @@ int sc_connect_vpp() int sc_disconnect_vpp() { - if (NULL != g_vapi_ctx_instance) + if (NULL != g_vapi_ctx) { - vapi_disconnect(g_vapi_ctx_instance); - vapi_ctx_free(g_vapi_ctx_instance); - g_vapi_ctx_instance = NULL; + vapi_disconnect(g_vapi_ctx); + vapi_ctx_free(g_vapi_ctx); + g_vapi_ctx = NULL; } return 0; } diff --git a/src/scvpp/src/interface.c b/src/scvpp/src/interface.c new file mode 100644 index 0000000..53cea1c --- /dev/null +++ b/src/scvpp/src/interface.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2018 PANTHEON.tech. + * + * 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 <assert.h> +#include <stdbool.h> + +#include <scvpp/comm.h> +#include <scvpp/interface.h> + +// Use VAPI macros to define symbols +DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON + +static vapi_error_e +sw_interface_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, + vapi_error_e rv, bool is_last, + vapi_payload_sw_interface_details *reply) +{ + UNUSED(rv); UNUSED(ctx); UNUSED(is_last); + + vapi_payload_sw_interface_details *passed; + + ARG_CHECK2(VAPI_EINVAL, callback_ctx, reply); + + //copy + passed = (vapi_payload_sw_interface_details *) callback_ctx; + *passed = *reply; + + return VAPI_OK; +} + +static vapi_error_e +bin_api_sw_interface_dump(vapi_payload_sw_interface_details *details, + const char *iface_name) +{ + vapi_msg_sw_interface_dump *mp; + vapi_error_e rv; + + mp = vapi_alloc_sw_interface_dump(g_vapi_ctx); + assert(NULL != mp); + + /* Dump a specific interfaces */ + mp->payload.name_filter_valid = true; + strncpy((char *)mp->payload.name_filter, iface_name, VPP_INTFC_NAME_LEN); + + VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx, mp, + sw_interface_dump_cb, details)); + if (rv != VAPI_OK) + return -SCVPP_EINVAL; + + return rv; +} + +int get_interface_id(const char *if_name, uint32_t *sw_if_index) +{ + vapi_payload_sw_interface_details details = {0}; + vapi_error_e rv; + + ARG_CHECK2(-SCVPP_EINVAL, if_name, sw_if_index); + + rv = bin_api_sw_interface_dump(&details, if_name); + if (rv != VAPI_OK) + return -SCVPP_EINVAL; + + if (strncmp(if_name, (char*) details.interface_name, VPP_INTFC_NAME_LEN) + != 0) + return -SCVPP_NOT_FOUND; + + *sw_if_index = details.sw_if_index; + + return 0; +} + +/* + * dump only a specific interface + */ +int interface_dump_iface(sw_interface_dump_t *details, const char *iface_name) +{ + vapi_error_e rv; + + rv = bin_api_sw_interface_dump(details, iface_name); + if (rv != VAPI_OK) + return -SCVPP_EINVAL; + + if (strncmp(iface_name, (char*) details->interface_name, VPP_INTFC_NAME_LEN) + != 0) + return -SCVPP_NOT_FOUND; + + return SCVPP_OK; +} + +VAPI_DUMP_LIST_CB(sw_interface) + +struct elt* interface_dump_all() +{ + struct elt* stack = NULL; + vapi_msg_sw_interface_dump *mp; + vapi_error_e rv; + + mp = vapi_alloc_sw_interface_dump(g_vapi_ctx); + + /* Dump all */ + mp->payload.name_filter_valid = false; + memset(mp->payload.name_filter, 0, sizeof(mp->payload.name_filter)); + + VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx, mp, sw_interface_all_cb, + &stack)); + if (VAPI_OK != rv) + return NULL; + + return stack; +} + +VAPI_RETVAL_CB(sw_interface_set_flags); + +int interface_enable(const char *interface_name, const bool enable) +{ + vapi_msg_sw_interface_set_flags *mp; + uint32_t sw_if_index; + vapi_error_e rv; + int rc; + + ARG_CHECK(-SCVPP_EINVAL, interface_name); + + rc = get_interface_id(interface_name, &sw_if_index); + if (rc != 0) + return -SCVPP_NOT_FOUND; + + mp = vapi_alloc_sw_interface_set_flags(g_vapi_ctx); + assert(NULL != mp); + mp->payload.sw_if_index = sw_if_index; + mp->payload.admin_up_down = enable; + + VAPI_CALL(vapi_sw_interface_set_flags(g_vapi_ctx, mp, + sw_interface_set_flags_cb, NULL)); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; + + return 0; +} + +int get_interface_name(char *interface_name, uint32_t sw_if_index) +{ + struct elt *stack= NULL; + sw_interface_dump_t *dump; + int rc = -SCVPP_NOT_FOUND; + + stack = interface_dump_all(); + if (!stack) + return -SCVPP_NOT_FOUND; + + foreach_stack_elt(stack) { + dump = (sw_interface_dump_t *) data; + + if (dump->sw_if_index == sw_if_index) { + strncpy(interface_name, (char *)dump->interface_name, VPP_INTFC_NAME_LEN); + rc = SCVPP_OK; + } + + free(dump); + } + + return rc; +} diff --git a/src/scvpp/src/sc_vpp_ip.c b/src/scvpp/src/ip.c index 0dfd108..2dc991c 100644 --- a/src/scvpp/src/sc_vpp_ip.c +++ b/src/scvpp/src/ip.c @@ -14,12 +14,12 @@ * limitations under the License. */ -#include "sc_vpp_comm.h" -#include "sc_vpp_ip.h" - -#include "sc_vpp_interface.h" +#include <scvpp/comm.h> +#include <scvpp/ip.h> +#include <scvpp/interface.h> #include <assert.h> +#include <stdio.h> // Use VAPI macros to define symbols DEFINE_VAPI_MSG_IDS_IP_API_JSON @@ -36,7 +36,7 @@ bin_api_sw_interface_add_del_address(u32 sw_if_index, bool is_add, bool is_ipv6, ARG_CHECK(VAPI_EINVAL, ip_address); - mp = vapi_alloc_sw_interface_add_del_address(g_vapi_ctx_instance); + mp = vapi_alloc_sw_interface_add_del_address(g_vapi_ctx); assert(NULL != mp); mp->payload.sw_if_index = sw_if_index; @@ -44,10 +44,10 @@ bin_api_sw_interface_add_del_address(u32 sw_if_index, bool is_add, bool is_ipv6, mp->payload.is_ipv6 = is_ipv6; mp->payload.del_all = del_all; mp->payload.address_length = address_length; - if (sc_aton(ip_address, mp->payload.address, sizeof(mp->payload.address))) + if (sc_aton(ip_address, mp->payload.address, VPP_IP4_ADDRESS_LEN)) return VAPI_EINVAL; - VAPI_CALL(vapi_sw_interface_add_del_address(g_vapi_ctx_instance, mp, + VAPI_CALL(vapi_sw_interface_add_del_address(g_vapi_ctx, mp, sw_interface_add_del_address_cb, NULL)); return rv; @@ -59,38 +59,41 @@ static vapi_error_e bin_api_ip_add_del_route(vapi_payload_ip_add_del_route_reply * reply, const char* dst_address, uint8_t dst_address_length, const char* next_hop, uint8_t is_add, - uint32_t table_id, const char *interface_name) + uint32_t table_id, const char *next_interface) { - sw_interface_details_query_t query = {0}; vapi_msg_ip_add_del_route *mp; + uint32_t sw_if_index; + vapi_error_e rv ; + int rc; - ARG_CHECK4(VAPI_EINVAL, reply, dst_address, next_hop, interface_name); - - sw_interface_details_query_set_name(&query, interface_name); + ARG_CHECK2(VAPI_EINVAL, reply, dst_address); - if (!get_interface_id(&query)) + //Require interface or next hop IP or both + if (!next_interface && !next_hop) return VAPI_EINVAL; - mp = vapi_alloc_ip_add_del_route (g_vapi_ctx_instance, 1); + mp = vapi_alloc_ip_add_del_route(g_vapi_ctx, 1); assert(NULL != mp); - //ip route add 2.2.2.2/24 via 5.5.5.5 - //show ip fib table 0 2.2.2.0/24 detail + if (next_interface) { + rc = get_interface_id(next_interface, &sw_if_index); + if (rc < 0) + return VAPI_EINVAL; + } mp->payload.is_add = is_add; - mp->payload.dst_address_length = dst_address_length; mp->payload.table_id = table_id; - mp->payload.next_hop_sw_if_index = query.sw_interface_details.sw_if_index; - - if (sc_aton(dst_address, mp->payload.dst_address, - sizeof(mp->payload.dst_address))) - return VAPI_EINVAL; - if (sc_aton(next_hop, mp->payload.next_hop_address, - sizeof(mp->payload.next_hop_address))) - return VAPI_EINVAL; + mp->payload.is_ipv6 = false; + mp->payload.is_local = false; + sc_aton(dst_address, mp->payload.dst_address, VPP_IP4_ADDRESS_LEN); + mp->payload.dst_address_length = dst_address_length; + if (next_interface) //interface is not mandatory + mp->payload.next_hop_sw_if_index = sw_if_index; + if (next_hop) //next hop ip is not mandatory + sc_aton(next_hop, mp->payload.next_hop_address, VPP_IP4_ADDRESS_LEN); - vapi_error_e rv ; - VAPI_CALL(vapi_ip_add_del_route(g_vapi_ctx_instance, mp, ip_add_del_route_cb, reply)); + VAPI_CALL(vapi_ip_add_del_route(g_vapi_ctx, mp, + ip_add_del_route_cb, reply)); return rv; } @@ -100,12 +103,13 @@ ip_address_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, vapi_payload_ip_address_details *reply) { UNUSED(rv); + vapi_payload_ip_address_details *passed; + ARG_CHECK3(VAPI_EINVAL, ctx, callback_ctx, reply); //copy dump reply in callback context - if (!is_last && callback_ctx) { - vapi_payload_ip_address_details *passed = - (vapi_payload_ip_address_details *) callback_ctx; + if (!is_last) { + passed = (vapi_payload_ip_address_details *) callback_ctx; *passed = *reply; } @@ -119,11 +123,13 @@ bin_api_ip_address_dump(u32 sw_if_index, bool is_ipv6, vapi_msg_ip_address_dump *mp; vapi_error_e rv; - mp = vapi_alloc_ip_address_dump(g_vapi_ctx_instance); + mp = vapi_alloc_ip_address_dump(g_vapi_ctx); + assert(mp != NULL); + mp->payload.sw_if_index = sw_if_index; mp->payload.is_ipv6 = is_ipv6; - VAPI_CALL(vapi_ip_address_dump(g_vapi_ctx_instance, mp, ip_address_dump_cb, + VAPI_CALL(vapi_ip_address_dump(g_vapi_ctx, mp, ip_address_dump_cb, dctx)); if (rv != VAPI_OK) return rv; @@ -131,64 +137,112 @@ bin_api_ip_address_dump(u32 sw_if_index, bool is_ipv6, return VAPI_OK; } -/* - * @brief Dump IPv4/IPv6 address from an interface. - * @param interface_name Name of the interface to dump. - * @param ip_addr pointer where dump will store IP. - * @param prefix_len pointer where dump will store prefix - */ +///VAPI_DUMP_LIST_CB(ip_fib); can not be used because of path flexible array + +static vapi_error_e +ip_fib_all_cb(vapi_ctx_t ctx, void *caller_ctx, vapi_error_e rv, bool is_last, + vapi_payload_ip_fib_details *reply) +{ + UNUSED(ctx); UNUSED(rv); UNUSED(is_last); + struct elt **stackp; + ARG_CHECK2(VAPI_EINVAL, caller_ctx, reply); + + stackp = (struct elt**) caller_ctx; + push(stackp, reply, sizeof(*reply)+reply->count*sizeof(vapi_type_fib_path)); + + return VAPI_OK; +} + +struct elt* ipv4_fib_dump_all() +{ + struct elt *stack = NULL; + vapi_msg_ip_fib_dump *mp; + vapi_error_e rv; + + mp = vapi_alloc_ip_fib_dump(g_vapi_ctx); + assert(mp != NULL); + + VAPI_CALL(vapi_ip_fib_dump(g_vapi_ctx, mp, ip_fib_all_cb, &stack)); + if(VAPI_OK != rv) + return NULL; + + return stack; +} + +int ipv4_fib_dump_prefix(const char *prefix_xpath, fib_dump_t **reply) +{ + struct elt *stack = NULL; + char prefix[VPP_IP4_PREFIX_STRING_LEN]; + fib_dump_t *dump; + int rc = -SCVPP_NOT_FOUND; + + stack = ipv4_fib_dump_all(); + if (!stack) + return rc; + + foreach_stack_elt(stack) { + dump = (fib_dump_t *) data; + + if (rc == -SCVPP_NOT_FOUND) { + snprintf(prefix, VPP_IP4_PREFIX_STRING_LEN, "%s/%u", + sc_ntoa(dump->address), dump->address_length); + if (!strncmp(prefix_xpath, prefix, VPP_IP4_PREFIX_STRING_LEN)) { + *reply = dump; + rc = SCVPP_OK; + continue; + } + } + + free(dump); + } + + return rc; +} + int ipv46_address_dump(const char *interface_name, char *ip_addr, u8 *prefix_len, bool is_ipv6) { vapi_payload_ip_address_details dctx = {0}; - sw_interface_details_query_t query = {0}; + uint32_t sw_if_index; vapi_error_e rv; + int rc; - sw_interface_details_query_set_name(&query, interface_name); - - if (!get_interface_id(&query)) - return -EINVAL; + rc = get_interface_id(interface_name, &sw_if_index); + if (rc < 0) + return rc; - rv = bin_api_ip_address_dump(query.sw_interface_details.sw_if_index, is_ipv6, &dctx); + rv = bin_api_ip_address_dump(sw_if_index, is_ipv6, &dctx); if (rv != VAPI_OK) - return -EAGAIN; + return -SCVPP_EINVAL; strcpy(ip_addr, sc_ntoa(dctx.ip)); //IP string *prefix_len = dctx.prefix_length; //prefix length - return 0; + return SCVPP_OK; } -/** - * @brief Add or remove IPv4/IPv6 address to/from an interface. - */ int ipv46_config_add_remove(const char *if_name, const char *addr, uint8_t prefix, bool is_ipv6, bool add) { vapi_error_e rv; + uint32_t sw_if_index; int rc; ARG_CHECK2(-1, if_name, addr); - /* get interface index */ - sw_interface_details_query_t query = {0}; - sw_interface_details_query_set_name(&query, if_name); - rc = get_interface_id(&query); - if (!rc) - return -EINVAL; + rc = get_interface_id(if_name, &sw_if_index); + if (rc < 0) + return rc; /* add del addr */ - rv = bin_api_sw_interface_add_del_address(query.sw_interface_details.sw_if_index, - add, is_ipv6, 0, prefix, addr); + rv = bin_api_sw_interface_add_del_address(sw_if_index, add, is_ipv6, 0, + prefix, addr); if (rv != VAPI_OK) - return -EINVAL; + return -SCVPP_EINVAL; - return 0; + return SCVPP_OK; } -/* - * @brief Add or remove an IP route - */ int ipv46_config_add_del_route(const char* dst_address, u8 dst_address_length, const char* next_address, u8 is_add, u32 table_id, const char *interface) @@ -198,9 +252,8 @@ int ipv46_config_add_del_route(const char* dst_address, u8 dst_address_length, rv = bin_api_ip_add_del_route(&reply, dst_address, dst_address_length, next_address, is_add, table_id, interface); - if (VAPI_OK != rv || reply.retval > 0) { - return -EINVAL; - } + if (VAPI_OK != rv || reply.retval > 0) + return -SCVPP_EINVAL; - return 0; + return SCVPP_OK; } diff --git a/src/scvpp/src/sc_vpp_nat.c b/src/scvpp/src/nat.c index e4bf2b7..17ace64 100644 --- a/src/scvpp/src/sc_vpp_nat.c +++ b/src/scvpp/src/nat.c @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "sc_vpp_comm.h" -#include "sc_vpp_nat.h" +#include <scvpp/comm.h> +#include <scvpp/nat.h> #include <assert.h> #include <stdbool.h> @@ -28,8 +28,7 @@ nat44_interface_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, vapi_payload_nat44_interface_details *reply) { - UNUSED(ctx); - UNUSED(rv); + UNUSED(ctx); UNUSED(rv); vapi_payload_nat44_interface_details *dctx = callback_ctx; assert(dctx); @@ -56,10 +55,10 @@ bin_api_nat44_interface_dump(vapi_payload_nat44_interface_details *reply) ARG_CHECK(VAPI_EINVAL, reply); - mp = vapi_alloc_nat44_interface_dump(g_vapi_ctx_instance); + mp = vapi_alloc_nat44_interface_dump(g_vapi_ctx); assert(NULL != mp); - VAPI_CALL(vapi_nat44_interface_dump(g_vapi_ctx_instance, mp, + VAPI_CALL(vapi_nat44_interface_dump(g_vapi_ctx, mp, nat44_interface_dump_cb, reply)); return rv; @@ -76,12 +75,12 @@ bin_api_nat44_add_del_interface_addr( ARG_CHECK(VAPI_EINVAL, msg); - mp = vapi_alloc_nat44_add_del_interface_addr(g_vapi_ctx_instance); + mp = vapi_alloc_nat44_add_del_interface_addr(g_vapi_ctx); assert(NULL != mp); mp->payload = *msg; - VAPI_CALL(vapi_nat44_add_del_interface_addr(g_vapi_ctx_instance, mp, + VAPI_CALL(vapi_nat44_add_del_interface_addr(g_vapi_ctx, mp, nat44_add_del_interface_addr_cb, NULL)); @@ -99,13 +98,13 @@ bin_api_nat44_add_del_addr_range( ARG_CHECK(VAPI_EINVAL, range); - mp = vapi_alloc_nat44_add_del_address_range(g_vapi_ctx_instance); + mp = vapi_alloc_nat44_add_del_address_range(g_vapi_ctx); assert(NULL != mp); mp->payload = *range; - VAPI_CALL(vapi_nat44_add_del_address_range(g_vapi_ctx_instance, mp, + VAPI_CALL(vapi_nat44_add_del_address_range(g_vapi_ctx, mp, nat44_add_del_address_range_cb, NULL)); @@ -123,13 +122,12 @@ bin_api_nat44_add_del_static_mapping( ARG_CHECK(VAPI_EINVAL, msg); - mp = vapi_alloc_nat44_add_del_static_mapping(g_vapi_ctx_instance); - + mp = vapi_alloc_nat44_add_del_static_mapping(g_vapi_ctx); assert(NULL != mp); mp->payload = *msg; - VAPI_CALL(vapi_nat44_add_del_static_mapping(g_vapi_ctx_instance, mp, + VAPI_CALL(vapi_nat44_add_del_static_mapping(g_vapi_ctx, mp, nat44_add_del_static_mapping_cb, NULL)); @@ -140,8 +138,7 @@ static vapi_error_e nat44_static_mapping_dump_cb( struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last,vapi_payload_nat44_static_mapping_details *reply) { - UNUSED(rv); - UNUSED(ctx); + UNUSED(rv); UNUSED(ctx); vapi_payload_nat44_static_mapping_details *dctx = callback_ctx; assert(dctx); @@ -166,10 +163,10 @@ bin_api_nat44_static_mapping_dump( ARG_CHECK(VAPI_EINVAL, reply); - msg = vapi_alloc_nat44_static_mapping_dump(g_vapi_ctx_instance); + msg = vapi_alloc_nat44_static_mapping_dump(g_vapi_ctx); assert(NULL != msg); - VAPI_CALL(vapi_nat44_static_mapping_dump(g_vapi_ctx_instance, msg, + VAPI_CALL(vapi_nat44_static_mapping_dump(g_vapi_ctx, msg, nat44_static_mapping_dump_cb, reply)); @@ -186,13 +183,13 @@ static vapi_error_e bin_api_nat44_forwarding_enable_disable( ARG_CHECK(VAPI_EINVAL, msg); - mp = vapi_alloc_nat44_forwarding_enable_disable(g_vapi_ctx_instance); + mp = vapi_alloc_nat44_forwarding_enable_disable(g_vapi_ctx); assert(NULL != mp); mp->payload = *msg; VAPI_CALL(vapi_nat44_forwarding_enable_disable( - g_vapi_ctx_instance, mp, nat44_forwarding_enable_disable_cb, NULL)); + g_vapi_ctx, mp, nat44_forwarding_enable_disable_cb, NULL)); return rv; } @@ -207,113 +204,91 @@ bin_api_nat_set_workers(const vapi_payload_nat_set_workers *msg) ARG_CHECK(VAPI_EINVAL, msg); - mp = vapi_alloc_nat_set_workers(g_vapi_ctx_instance); + mp = vapi_alloc_nat_set_workers(g_vapi_ctx); assert(NULL != mp); mp->payload = *msg; - VAPI_CALL(vapi_nat_set_workers(g_vapi_ctx_instance, mp, nat_set_workers_cb, - NULL)); + VAPI_CALL(vapi_nat_set_workers(g_vapi_ctx, mp, nat_set_workers_cb, NULL)); return rv; } int nat44_interface_dump(nat44_interface_details_t *reply) { - vapi_error_e rc; + vapi_error_e rv; - rc = bin_api_nat44_interface_dump(reply); - if (VAPI_OK != rc) { - //TODO: Need implement log function -// ERROR("Error in nat44_interface_dump, error: %u", rc); - return -1; - } + rv = bin_api_nat44_interface_dump(reply); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; - return 0; + return SCVPP_OK; } int nat44_add_del_interface_addr(const nat44_add_del_interface_addr_t *msg) { - vapi_error_e rc; + vapi_error_e rv; - rc = bin_api_nat44_add_del_interface_addr(msg); - if (VAPI_OK != rc) { - //TODO: Need implement log function -// ERROR("Error in nat44_interface_dump, error: %u", rc); - return -1; - } + rv = bin_api_nat44_add_del_interface_addr(msg); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; - return 0; + return SCVPP_OK; } int nat44_add_del_addr_range(const nat44_add_del_address_range_t *range) { - vapi_error_e rc; + vapi_error_e rv; - rc = bin_api_nat44_add_del_addr_range(range); - if (VAPI_OK != rc) { - //TODO: Need implement log function -// ERROR("Error in nat44_interface_dump, error: %u", rc); - return -1; - } + rv = bin_api_nat44_add_del_addr_range(range); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; - return 0; + return SCVPP_OK; } int nat44_add_del_static_mapping(const nat44_add_del_static_mapping_t *msg) { - vapi_error_e rc; + vapi_error_e rv; - rc = bin_api_nat44_add_del_static_mapping(msg); - if (VAPI_OK != rc) { - //TODO: Need implement log function -// ERROR("Error in nat44_interface_dump, error: %u", rc); - return -1; - } + rv = bin_api_nat44_add_del_static_mapping(msg); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; - return 0; + return SCVPP_OK; } int nat44_static_mapping_dump(nat44_static_mapping_details_t *reply) { - vapi_error_e rc; + vapi_error_e rv; - rc = bin_api_nat44_static_mapping_dump(reply); - if (VAPI_OK != rc) { - //TODO: Need implement log function -// ERROR("Error in nat44_interface_dump, error: %u", rc); - return -1; - } + rv = bin_api_nat44_static_mapping_dump(reply); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; - return 0; + return SCVPP_OK; } -int nat44_forwarding_enable_disable( - const nat44_forwarding_enable_disable_t *msg) +int +nat44_forwarding_enable_disable(const nat44_forwarding_enable_disable_t *msg) { - vapi_error_e rc; + vapi_error_e rv; - rc = bin_api_nat44_forwarding_enable_disable(msg); - if (VAPI_OK != rc) { - //TODO: Need implement log function -// ERROR("Error in nat44_interface_dump, error: %u", rc); - return -1; - } + rv = bin_api_nat44_forwarding_enable_disable(msg); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; return 0; } int nat_set_workers(const nat_set_workers_t *msg) { - vapi_error_e rc; + vapi_error_e rv; - rc = bin_api_nat_set_workers(msg); - if (VAPI_OK != rc) { - //TODO: Need implement log function -// ERROR("Error in nat44_interface_dump, error: %u", rc); - return -1; - } + rv = bin_api_nat_set_workers(msg); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; - return 0; + return SCVPP_OK; } diff --git a/src/scvpp/src/sc_vpp_comm.h b/src/scvpp/src/sc_vpp_comm.h deleted file mode 100644 index eeeaaf9..0000000 --- a/src/scvpp/src/sc_vpp_comm.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2018 HUACHENTEL and/or its affiliates. - * Copyright (c) 2018 PANTHEON.tech - * 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 __SC_VPP_COMMM_H__ -#define __SC_VPP_COMMM_H__ - -#include <errno.h> - -#include <vapi/vapi.h> -#include <vapi/vapi_common.h> -#include <vapi/vpe.api.vapi.h> - -// Use VAPI macros to define symbols -DEFINE_VAPI_MSG_IDS_VPE_API_JSON; - -#define VPP_INTFC_NAME_LEN 64 -#define VPP_TAPV2_NAME_LEN VPP_INTFC_NAME_LEN -#define VPP_IP4_ADDRESS_LEN 4 -#define VPP_IP6_ADDRESS_LEN 16 -#define VPP_IP4_ADDRESS_STRING_LEN 16 -#define VPP_IP4_PREFIX_STRING_LEN 19 -#define VPP_IP4_HOST_PREFIX_LEN 32 -#define VPP_IP6_ADDRESS_STRING_LEN 46 -#define VPP_MAC_ADDRESS_LEN 8 -#define VPP_TAG_LEN VPP_INTFC_NAME_LEN -#define VPP_IKEV2_PROFILE_NAME_LEN VPP_INTFC_NAME_LEN -#define VPP_IKEV2_PSK_LEN VPP_INTFC_NAME_LEN -#define VPP_IKEV2_ID_LEN 32 - -/**********************************MACROS**********************************/ -#define ARG_CHECK(retval, arg) \ - do \ - { \ - if (NULL == (arg)) \ - { \ - return (retval); \ - } \ - } \ - while (0) - -#define ARG_CHECK2(retval, arg1, arg2) \ - ARG_CHECK(retval, arg1); \ - ARG_CHECK(retval, arg2) - -#define ARG_CHECK3(retval, arg1, arg2, arg3) \ - ARG_CHECK(retval, arg1); \ - ARG_CHECK(retval, arg2); \ - ARG_CHECK(retval, arg3) - -#define ARG_CHECK4(retval, arg1, arg2, arg3, arg4) \ - ARG_CHECK(retval, arg1); \ - ARG_CHECK(retval, arg2); \ - ARG_CHECK(retval, arg3); \ - ARG_CHECK(retval, arg4) - -/* Suppress compiler warning about unused variable. - * This must be used only for callback function else suppress your unused - * parameter in function prototype. */ -#define UNUSED(x) (void)x - -#define VAPI_RETVAL_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) \ -{ \ - UNUSED(ctx); UNUSED(caller_ctx); UNUSED(rv); UNUSED(is_last); \ - return reply->retval; \ -} - -#define VAPI_COPY_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) \ -{ \ - UNUSED(ctx); UNUSED(rv); UNUSED(is_last); \ - if (caller_ctx) \ - { \ - vapi_payload_##api_name##_reply * passed = (vapi_payload_##api_name##_reply *)caller_ctx; \ - *passed = *reply; \ - } \ - return VAPI_OK; \ -}\ - -#define VAPI_CALL_MODE(call_code, vapi_mode) \ - do \ - { \ - if (VAPI_MODE_BLOCKING == (vapi_mode)) \ - { \ - rv = call_code; \ - } \ - else \ - { \ - while (VAPI_EAGAIN == (rv = call_code)); \ - rv = vapi_dispatch (g_vapi_ctx_instance); \ - } \ - } \ - while (0) - -#define VAPI_CALL(call_code) VAPI_CALL_MODE(call_code, g_vapi_mode) - -int sc_aton(const char *cp, u8 * buf, size_t length); -char * sc_ntoa(const u8 * buf); - -/** - * @brief Function converts the u8 array from network byte order to host byte order. - * - * @param[in] host IPv4 address. - * @return host byte order value. - */ -uint32_t hardntohlu32(uint8_t host[4]); - -/* - * VPP - */ - -extern vapi_ctx_t g_vapi_ctx_instance; -extern vapi_mode_e g_vapi_mode; - -int sc_connect_vpp(); -int sc_disconnect_vpp(); -int sc_end_with(const char* str, const char* end); - -#endif //__SC_VPP_COMMM_H__ diff --git a/src/scvpp/src/sc_vpp_interface.c b/src/scvpp/src/sc_vpp_interface.c deleted file mode 100644 index bc5befc..0000000 --- a/src/scvpp/src/sc_vpp_interface.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (c) 2018 PANTHEON.tech. - * - * 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 <assert.h> -#include <stdbool.h> - -#include <vapi/l2.api.vapi.h> - -#include "sc_vpp_comm.h" -#include "sc_vpp_interface.h" - - -// Use VAPI macros to define symbols -DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON -DEFINE_VAPI_MSG_IDS_L2_API_JSON; - -void sw_interface_details_query_set_name(sw_interface_details_query_t * query, - const char * interface_name) -{ - assert(query && interface_name); - - memset(query, 0, sizeof(*query)); - - strncpy((char*) query->sw_interface_details.interface_name, interface_name, - sizeof(query->sw_interface_details.interface_name)); -} - -static vapi_error_e -sw_interface_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_sw_interface_details *reply) -{ - UNUSED(rv); UNUSED(ctx); UNUSED(is_last); - - vapi_payload_sw_interface_details *passed; - - ARG_CHECK(-EINVAL, callback_ctx); - - passed = (vapi_payload_sw_interface_details *) callback_ctx; - - //Interface is found if index of query equals index of reply - if (passed->sw_if_index != reply->sw_if_index) - return -EINVAL; - - //copy - *passed = *reply; - - return VAPI_OK; -} - -static vapi_error_e -bin_api_sw_interface_dump(vapi_payload_sw_interface_details *details) -{ - vapi_msg_sw_interface_dump *mp; - vapi_error_e rv; - - mp = vapi_alloc_sw_interface_dump(g_vapi_ctx_instance); - - mp->payload.name_filter_valid = 0; - memset(mp->payload.name_filter, 0, sizeof(mp->payload.name_filter)); - assert(NULL != mp); - - VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx_instance, mp, sw_interface_dump_cb, details)); - if (!rv) - return -EINVAL; - - return rv; -} - -static vapi_error_e -interface_dump_all_cb(struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_sw_interface_details * reply) -{ - UNUSED(ctx); UNUSED(rv); - dump_all_ctx *dctx = callback_ctx; - - if (is_last) - return VAPI_OK; - - if(dctx->capacity == 0 && dctx->intfcArray == NULL) { - dctx->capacity = 10; - dctx->intfcArray = (vpp_interface_t*)malloc( sizeof(vpp_interface_t)*dctx->capacity ); - } - if(dctx->num_ifs >= dctx->capacity-1) { - dctx->capacity += 10; - dctx->intfcArray = (vpp_interface_t*)realloc(dctx->intfcArray, sizeof(vpp_interface_t)*dctx->capacity ); - } - - vpp_interface_t * iface = &dctx->intfcArray[dctx->num_ifs]; - - iface->sw_if_index = reply->sw_if_index; - strncpy(iface->interface_name, (char*) reply->interface_name, - VPP_INTFC_NAME_LEN); - iface->l2_address_length = reply->l2_address_length; - memcpy(iface->l2_address, reply->l2_address, reply->l2_address_length ); - iface->link_speed = reply->link_speed; - - iface->link_mtu = reply->link_mtu; - iface->admin_up_down = reply->admin_up_down; - iface->link_up_down = reply->link_up_down; - - dctx->num_ifs += 1; - - return VAPI_OK; -} - -int interface_dump_all(dump_all_ctx * dctx) -{ - vapi_msg_sw_interface_dump *dump; - vapi_error_e rv; - - ARG_CHECK(-1, dctx); - - if(dctx == NULL) - return -1; - - dctx->intfcArray = NULL; - dctx->capacity = 0; - dctx->num_ifs = 0; - - dump = vapi_alloc_sw_interface_dump(g_vapi_ctx_instance); - - dump->payload.name_filter_valid = 0; - memset(dump->payload.name_filter, 0, sizeof(dump->payload.name_filter)); - while (VAPI_EAGAIN == - (rv = - vapi_sw_interface_dump(g_vapi_ctx_instance, dump, interface_dump_all_cb, - dctx))); - - return dctx->num_ifs; -} - -static vapi_error_e -get_interface_id_cb (struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_sw_interface_details * reply) -{ - UNUSED(ctx); UNUSED(rv); - - sw_interface_details_query_t *dctx = callback_ctx; - assert(dctx); - - if (!dctx->interface_found) - { - if (is_last) - { - assert(NULL == reply); - } - else - { - assert(NULL != reply); - - if (0 == strcmp((const char*)dctx->sw_interface_details.interface_name, - (const char*)reply->interface_name)) - { - dctx->interface_found = true; - dctx->sw_interface_details = *reply; - } - } - } - - return VAPI_OK; -} - -// return error code instead of boolean -int get_interface_id(sw_interface_details_query_t * sw_interface_details_query) -{ - vapi_error_e rv; - - ARG_CHECK(false, sw_interface_details_query); - - sw_interface_details_query->interface_found = false; - - vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx_instance); - assert(NULL != mp); - - mp->payload.name_filter_valid = true; - memcpy(mp->payload.name_filter, sw_interface_details_query->sw_interface_details.interface_name, - sizeof(mp->payload.name_filter)); - - VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx_instance, mp, get_interface_id_cb, sw_interface_details_query)); - if (VAPI_OK != rv) - return false; - - return sw_interface_details_query->interface_found; -} - -int get_interface_name(sw_interface_details_query_t *query) -{ - vapi_error_e rv; - - ARG_CHECK(-EINVAL, query); - - query->interface_found = false; - - rv = bin_api_sw_interface_dump(&query->sw_interface_details); - if (rv == VAPI_OK) - query->interface_found = true; - - return query->interface_found; -} - -VAPI_RETVAL_CB(sw_interface_set_flags); - -static vapi_error_e -bin_api_sw_interface_set_flags(uint32_t if_index, uint8_t up) -{ - vapi_msg_sw_interface_set_flags *mp = vapi_alloc_sw_interface_set_flags (g_vapi_ctx_instance); - assert(NULL != mp); - - mp->payload.sw_if_index = if_index; - mp->payload.admin_up_down = up; - - vapi_error_e rv; - VAPI_CALL(vapi_sw_interface_set_flags(g_vapi_ctx_instance, mp, sw_interface_set_flags_cb, NULL)); - - return rv; -} - -int interface_enable(const char *interface_name, const bool enable) -{ - ARG_CHECK(-1, interface_name); - - int rc = 0; - sw_interface_details_query_t query = {0}; - sw_interface_details_query_set_name(&query, interface_name); - - rc = get_interface_id(&query); - if (!rc) - return -1; - - rc = bin_api_sw_interface_set_flags(query.sw_interface_details.sw_if_index, - enable); - if (VAPI_OK != rc) - return -1; - - return 0; -} diff --git a/src/scvpp/src/sc_vpp_interface.h b/src/scvpp/src/sc_vpp_interface.h deleted file mode 100644 index 32b61bc..0000000 --- a/src/scvpp/src/sc_vpp_interface.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018 PANTHEON.tech. - * - * 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 __BAPI_INTERFACE_H__ -#define __BAPI_INTERFACE_H__ - -#include <vapi/interface.api.vapi.h> - -int interface_enable(const char *interface_name, const bool enable); - -//TODO remove the following structures ASAP -typedef struct { - bool interface_found; - vapi_payload_sw_interface_details sw_interface_details; -} sw_interface_details_query_t; - -typedef struct _vpp_interface_t -{ - u32 sw_if_index; - char interface_name[VPP_INTFC_NAME_LEN]; - u8 l2_address[VPP_MAC_ADDRESS_LEN]; - u32 l2_address_length; - u64 link_speed; - u16 link_mtu; - u8 admin_up_down; - u8 link_up_down; -} vpp_interface_t; - -typedef struct _dump_all_ctx -{ - int num_ifs; - int capacity; - vpp_interface_t * intfcArray; -} dump_all_ctx; - -/* return the number of interfaces or a negative error code */ -extern int interface_dump_all(dump_all_ctx * dctx); - -extern void sw_interface_details_query_set_name(sw_interface_details_query_t * query, - const char * interface_name); - -//input - sw_interface_details_query shall contain interface_name -extern int get_interface_id(sw_interface_details_query_t * sw_interface_details_query); - -//input - sw_interface_details_query shall contain sw_if_index -extern int get_interface_name(sw_interface_details_query_t * sw_interface_details_query); - -#endif /* __BAPI_INTERFACE_H__ */ diff --git a/src/scvpp/src/sc_vpp_ip.h b/src/scvpp/src/sc_vpp_ip.h deleted file mode 100644 index a9f19d4..0000000 --- a/src/scvpp/src/sc_vpp_ip.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2018 PANTHEON.tech. - * - * 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 __BAPI_IP_H__ -#define __BAPI_IP_H__ - -#include <vapi/interface.api.vapi.h> -#include <vapi/ip.api.vapi.h> - -/* If no IP has been found ip_addr will be "0.0.0.0" */ -extern int ipv46_address_dump(const char *interface_name, char *ip_addr, - u8 *prefix_len, bool is_ipv6); - -extern int ipv46_config_add_remove(const char *if_name, const char *addr, - uint8_t prefix, bool is_ipv6, bool add); - -extern int -ipv46_config_add_del_route(const char* dst_address, u8 dst_address_length, - const char* next_address, u8 is_add, u32 table_id, - const char *interface); - -#endif /* __BAPI_IP_H__ */ diff --git a/src/scvpp/src/sc_vpp_nat.h b/src/scvpp/src/sc_vpp_nat.h deleted file mode 100644 index 40e727e..0000000 --- a/src/scvpp/src/sc_vpp_nat.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018 PANTHEON.tech. - * - * 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 __BAPI_NAT_H__ -#define __BAPI_NAT_H__ - -#include <vapi/nat.api.vapi.h> - -typedef vapi_payload_nat44_interface_details nat44_interface_details_t; -typedef vapi_payload_nat44_add_del_interface_addr nat44_add_del_interface_addr_t; -typedef vapi_payload_nat44_add_del_address_range nat44_add_del_address_range_t; -typedef vapi_payload_nat44_add_del_static_mapping nat44_add_del_static_mapping_t; -typedef vapi_payload_nat44_static_mapping_details nat44_static_mapping_details_t; -typedef vapi_payload_nat44_forwarding_enable_disable nat44_forwarding_enable_disable_t; -typedef vapi_payload_nat_set_workers nat_set_workers_t; - - -//Wrapper function, if we want hide the VAPI return value -extern int nat44_interface_dump(nat44_interface_details_t *reply); -extern int nat44_add_del_interface_addr( - const nat44_add_del_interface_addr_t *msg); -extern int nat44_add_del_addr_range(const nat44_add_del_address_range_t *range); -extern int nat44_add_del_static_mapping( - const nat44_add_del_static_mapping_t *msg); -extern int nat44_static_mapping_dump(nat44_static_mapping_details_t *reply); -extern int nat44_forwarding_enable_disable( - const nat44_forwarding_enable_disable_t *msg); -extern int nat_set_workers(const nat_set_workers_t *msg); - - -// Alternative, if we don't want hide VAPI return value - -// extern vapi_error_e bin_api_nat44_interface_dump(nat44_interface_details_t *reply); -// extern vapi_error_e bin_api_nat44_add_del_interface_addr( -// const nat44_add_del_interface_addr_t *msg); -// extern vapi_error_e bin_api_nat44_add_del_addr_range( -// const nat44_add_del_address_range_t *range); -// extern vapi_error_e bin_api_nat44_add_del_static_mapping( -// const nat44_add_del_static_mapping_t *msg); -// extern vapi_error_e bin_api_nat44_static_mapping_dump( -// nat44_static_mapping_details_t *reply); -// extern vapi_error_e bin_api_nat44_forwarding_enable_disable( -// const nat44_forwarding_enable_disable_t *msg); -// extern vapi_error_e bin_api_nat_set_workers(const nat_set_workers_t *msg); - - -#endif /* __BAPI_NAT_H__ */ - diff --git a/src/scvpp/src/sc_vpp_v3po.h b/src/scvpp/src/sc_vpp_v3po.h deleted file mode 100644 index 9c13569..0000000 --- a/src/scvpp/src/sc_vpp_v3po.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * 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 _V3PO__INTERFACE_H__ -#define _V3PO__INTERFACE_H__ - -#include <vapi/tapv2.api.vapi.h> - -typedef vapi_payload_tap_create_v2 tapv2_create_t; - -int create_tapv2(tapv2_create_t *query); -int delete_tapv2(char *iface_name); - -#endif /* __V3PO_INTERFACE_H__ */ diff --git a/src/scvpp/src/sc_vpp_v3po.c b/src/scvpp/src/v3po.c index d312331..f0a41c5 100644 --- a/src/scvpp/src/sc_vpp_v3po.c +++ b/src/scvpp/src/v3po.c @@ -1,5 +1,7 @@ /* * Copyright (c) 2016 Cisco and/or its affiliates. + * Copyright (c) 2018 PANTHEON.tech. + * * 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: @@ -15,35 +17,18 @@ #include <assert.h> -#include "sc_vpp_comm.h" -#include "sc_vpp_v3po.h" -#include "sc_vpp_interface.h" +#include <scvpp/comm.h> +#include <scvpp/v3po.h> +#include <scvpp/interface.h> + +// Use VAPI macros to define symbols +DEFINE_VAPI_MSG_IDS_L2_API_JSON; +DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON /* * tap-v2 interfaces */ -DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON - -// Dump tapv2 - -//typedef struct __attribute__ ((__packed__)) { -// u32 sw_if_index; -// u32 id; -// u8 dev_name[64]; -// u16 tx_ring_sz; -// u16 rx_ring_sz; -// u8 host_mac_addr[6]; -// u8 host_if_name[64]; -// u8 host_namespace[64]; -// u8 host_bridge[64]; -// u8 host_ip4_addr[4]; -// u8 host_ip4_prefix_len; -// u8 host_ip6_addr[16]; -// u8 host_ip6_prefix_len; -// u32 tap_flags; -//} vapi_payload_sw_interface_tap_v2_details; - // Delete tapv2 VAPI_RETVAL_CB(tap_delete_v2); @@ -53,35 +38,33 @@ static vapi_error_e bin_api_delete_tapv2(u32 sw_if_index) vapi_msg_tap_delete_v2 *mp; vapi_error_e rv; - mp = vapi_alloc_tap_delete_v2(g_vapi_ctx_instance); + mp = vapi_alloc_tap_delete_v2(g_vapi_ctx); assert(NULL != mp); mp->payload.sw_if_index = sw_if_index; - VAPI_CALL(vapi_tap_delete_v2(g_vapi_ctx_instance, mp, tap_delete_v2_cb, - NULL)); + VAPI_CALL(vapi_tap_delete_v2(g_vapi_ctx, mp, tap_delete_v2_cb, NULL)); if (rv != VAPI_OK) - return -EAGAIN; + return -rv; - return rv; + return VAPI_OK; } int delete_tapv2(char *iface_name) { + uint32_t sw_if_index; + vapi_error_e rv; int rc; - sw_interface_details_query_t query = {0}; - sw_interface_details_query_set_name(&query, iface_name); + rc = get_interface_id(iface_name, &sw_if_index); + if (rc < 0) + return rc; - rc = get_interface_id(&query); - if (!rc) - return -1; + rv = bin_api_delete_tapv2(sw_if_index); + if (VAPI_OK != rv) + return -SCVPP_EINVAL; - rc = bin_api_delete_tapv2(query.sw_interface_details.sw_if_index); - if (VAPI_OK != rc) - return -1; - - return 0; + return SCVPP_OK; } // Create tapv2 @@ -93,13 +76,12 @@ int create_tapv2(tapv2_create_t *query) vapi_msg_tap_create_v2 *mp; vapi_error_e rv; - mp = vapi_alloc_tap_create_v2(g_vapi_ctx_instance); + mp = vapi_alloc_tap_create_v2(g_vapi_ctx); assert(NULL != mp); memcpy(&mp->payload, query, sizeof(tapv2_create_t)); - VAPI_CALL(vapi_tap_create_v2(g_vapi_ctx_instance, mp, tap_create_v2_cb, - NULL)); + VAPI_CALL(vapi_tap_create_v2(g_vapi_ctx, mp, tap_create_v2_cb, NULL)); if (rv != VAPI_OK) return -EAGAIN; |