aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHongjun Ni <hongjun.ni@intel.com>2019-03-12 03:32:38 +0000
committerGerrit Code Review <gerrit@fd.io>2019-03-12 03:32:38 +0000
commitf8118bf32a5e5276f796c3f03095c2ee1a41423a (patch)
treea50670a48ad91be53f31814b3f4a4737d5776e82
parent10d169e7883d78a61a2db923559c79f4621fc886 (diff)
parent1024a9ca19fc49172d3220f7219a369f692d2fe9 (diff)
Merge "scvpp - init NAT"
-rw-r--r--src/scvpp/src/CMakeLists.txt2
-rw-r--r--src/scvpp/src/sc_vpp_nat.c321
-rw-r--r--src/scvpp/src/sc_vpp_nat.h61
3 files changed, 384 insertions, 0 deletions
diff --git a/src/scvpp/src/CMakeLists.txt b/src/scvpp/src/CMakeLists.txt
index af4a945..6869a4b 100644
--- a/src/scvpp/src/CMakeLists.txt
+++ b/src/scvpp/src/CMakeLists.txt
@@ -21,6 +21,7 @@ set(SCVPP_SOURCES
sc_vpp_interface.c
sc_vpp_ip.c
sc_vpp_v3po.c
+ sc_vpp_nat.c
)
# scvpp public headers
@@ -29,6 +30,7 @@ set(SCVPP_HEADERS
sc_vpp_interface.h
sc_vpp_ip.h
sc_vpp_v3po.h
+ sc_vpp_nat.h
)
set(CMAKE_C_FLAGS " -g -O0 -fpic -fPIC -std=gnu99 -Wl,-rpath-link=/usr/lib")
diff --git a/src/scvpp/src/sc_vpp_nat.c b/src/scvpp/src/sc_vpp_nat.c
new file mode 100644
index 0000000..1944684
--- /dev/null
+++ b/src/scvpp/src/sc_vpp_nat.c
@@ -0,0 +1,321 @@
+/*
+ * 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 "sc_vpp_comm.h"
+#include "sc_vpp_nat.h"
+
+#include <assert.h>
+#include <stdbool.h>
+
+
+DEFINE_VAPI_MSG_IDS_NAT_API_JSON
+
+static vapi_error_e
+nat44_interface_dump_cb(
+ __attribute__((unused)) struct vapi_ctx_s *ctx,
+ void *callback_ctx,
+ __attribute__((unused)) vapi_error_e rv,
+ bool is_last,
+ vapi_payload_nat44_interface_details *reply)
+{
+ vapi_payload_nat44_interface_details *dctx = callback_ctx;
+ assert(dctx);
+
+ if (is_last)
+ {
+ assert(NULL == reply);
+ }
+ else
+ {
+ //TODO: Use LOG message for scvpp
+// SC_LOG_DBG("NAT Interface dump entry: [%u]: %u\n", reply->sw_if_index,
+// reply->is_inside);
+ *dctx = *reply;
+ }
+
+ return VAPI_OK;
+}
+
+static vapi_error_e
+bin_api_nat44_interface_dump(vapi_payload_nat44_interface_details *reply)
+{
+ vapi_error_e rv;
+ vapi_msg_nat44_interface_dump *mp;
+
+ ARG_CHECK(VAPI_EINVAL, reply);
+
+ mp = vapi_alloc_nat44_interface_dump(g_vapi_ctx_instance);
+ assert(NULL != mp);
+
+ VAPI_CALL(vapi_nat44_interface_dump(g_vapi_ctx_instance, mp,
+ nat44_interface_dump_cb, reply));
+
+ return rv;
+}
+
+VAPI_RETVAL_CB(nat44_add_del_interface_addr);
+
+static vapi_error_e
+bin_api_nat44_add_del_interface_addr(
+ const vapi_payload_nat44_add_del_interface_addr *msg)
+{
+ vapi_error_e rv;
+ vapi_msg_nat44_add_del_interface_addr *mp;
+
+ ARG_CHECK(VAPI_EINVAL, msg);
+
+ mp = vapi_alloc_nat44_add_del_interface_addr(g_vapi_ctx_instance);
+ assert(NULL != mp);
+
+ mp->payload = *msg;
+
+ VAPI_CALL(vapi_nat44_add_del_interface_addr(g_vapi_ctx_instance, mp,
+ nat44_add_del_interface_addr_cb,
+ NULL));
+
+ return rv;
+}
+
+VAPI_RETVAL_CB(nat44_add_del_address_range);
+
+static vapi_error_e
+bin_api_nat44_add_del_addr_range(
+ const vapi_payload_nat44_add_del_address_range *range)
+{
+ vapi_error_e rv;
+ vapi_msg_nat44_add_del_address_range *mp;
+
+ ARG_CHECK(VAPI_EINVAL, range);
+
+ mp = vapi_alloc_nat44_add_del_address_range(g_vapi_ctx_instance);
+
+ assert(NULL != mp);
+
+ mp->payload = *range;
+
+ VAPI_CALL(vapi_nat44_add_del_address_range(g_vapi_ctx_instance, mp,
+ nat44_add_del_address_range_cb,
+ NULL));
+
+ return rv;
+}
+
+VAPI_RETVAL_CB(nat44_add_del_static_mapping);
+
+static vapi_error_e
+bin_api_nat44_add_del_static_mapping(
+ const vapi_payload_nat44_add_del_static_mapping *msg)
+{
+ vapi_error_e rv;
+ vapi_msg_nat44_add_del_static_mapping *mp;
+
+ ARG_CHECK(VAPI_EINVAL, msg);
+
+ mp = vapi_alloc_nat44_add_del_static_mapping(g_vapi_ctx_instance);
+
+ assert(NULL != mp);
+
+ mp->payload = *msg;
+
+ VAPI_CALL(vapi_nat44_add_del_static_mapping(g_vapi_ctx_instance, mp,
+ nat44_add_del_static_mapping_cb,
+ NULL));
+
+ return rv;
+}
+
+static vapi_error_e nat44_static_mapping_dump_cb(
+ __attribute__((unused)) struct vapi_ctx_s *ctx,
+ void *callback_ctx,
+ __attribute__((unused)) vapi_error_e rv,
+ bool is_last,
+ vapi_payload_nat44_static_mapping_details *reply)
+{
+ vapi_payload_nat44_static_mapping_details *dctx = callback_ctx;
+ assert(dctx);
+
+ if (is_last)
+ {
+ assert(NULL == reply);
+ }
+ else
+ {
+ *dctx = *reply;
+ }
+
+ return VAPI_OK;
+}
+
+static vapi_error_e
+bin_api_nat44_static_mapping_dump(
+ vapi_payload_nat44_static_mapping_details *reply)
+{
+ vapi_error_e rv;
+ vapi_msg_nat44_static_mapping_dump *msg;
+
+ ARG_CHECK(VAPI_EINVAL, reply);
+
+ msg = vapi_alloc_nat44_static_mapping_dump(g_vapi_ctx_instance);
+ assert(NULL != msg);
+
+ VAPI_CALL(vapi_nat44_static_mapping_dump(g_vapi_ctx_instance, msg,
+ nat44_static_mapping_dump_cb,
+ reply));
+
+ return rv;
+}
+
+VAPI_RETVAL_CB(nat44_forwarding_enable_disable);
+
+static vapi_error_e bin_api_nat44_forwarding_enable_disable(
+ const vapi_payload_nat44_forwarding_enable_disable *msg)
+{
+ vapi_error_e rv;
+ vapi_msg_nat44_forwarding_enable_disable *mp;
+
+ ARG_CHECK(VAPI_EINVAL, msg);
+
+ mp = vapi_alloc_nat44_forwarding_enable_disable(g_vapi_ctx_instance);
+ assert(NULL != mp);
+
+ mp->payload = *msg;
+
+ VAPI_CALL(vapi_nat44_forwarding_enable_disable(
+ g_vapi_ctx_instance, mp, nat44_forwarding_enable_disable_cb, NULL));
+
+ return rv;
+}
+
+VAPI_RETVAL_CB(nat_set_workers);
+
+static vapi_error_e
+bin_api_nat_set_workers(const vapi_payload_nat_set_workers *msg)
+{
+ vapi_error_e rv;
+ vapi_msg_nat_set_workers *mp;
+
+ ARG_CHECK(VAPI_EINVAL, msg);
+
+ mp = vapi_alloc_nat_set_workers(g_vapi_ctx_instance);
+ assert(NULL != mp);
+
+ mp->payload = *msg;
+
+ VAPI_CALL(vapi_nat_set_workers(g_vapi_ctx_instance, mp, nat_set_workers_cb,
+ NULL));
+
+ return rv;
+}
+
+int nat44_interface_dump(nat44_interface_details_t *reply)
+{
+ vapi_error_e rc;
+
+ 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;
+ }
+
+ return 0;
+}
+
+int nat44_add_del_interface_addr(const nat44_add_del_interface_addr_t *msg)
+{
+ vapi_error_e rc;
+
+ 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;
+ }
+
+ return 0;
+}
+
+int nat44_add_del_addr_range(const nat44_add_del_address_range_t *range)
+{
+ vapi_error_e rc;
+
+ 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;
+ }
+
+ return 0;
+}
+
+int nat44_add_del_static_mapping(const nat44_add_del_static_mapping_t *msg)
+{
+ vapi_error_e rc;
+
+ 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;
+ }
+
+ return 0;
+}
+
+int nat44_static_mapping_dump(nat44_static_mapping_details_t *reply)
+{
+ vapi_error_e rc;
+
+ 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;
+ }
+
+ return 0;
+}
+
+int nat44_forwarding_enable_disable(
+ const nat44_forwarding_enable_disable_t *msg)
+{
+ vapi_error_e rc;
+
+ 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;
+ }
+
+ return 0;
+}
+
+int nat_set_workers(const nat_set_workers_t *msg)
+{
+ vapi_error_e rc;
+
+ 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;
+ }
+
+ return 0;
+}
+
diff --git a/src/scvpp/src/sc_vpp_nat.h b/src/scvpp/src/sc_vpp_nat.h
new file mode 100644
index 0000000..40e727e
--- /dev/null
+++ b/src/scvpp/src/sc_vpp_nat.h
@@ -0,0 +1,61 @@
+/*
+ * 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__ */
+