aboutsummaryrefslogtreecommitdiffstats
path: root/src/dpi_api.c
diff options
context:
space:
mode:
authorHongjun Ni <hongjun.ni@intel.com>2019-09-09 19:03:46 +0800
committerHongjun Ni <hongjun.ni@intel.com>2019-09-09 19:03:46 +0800
commit2234c30a625ec2c38f7fb9d0c7e7ddd02a0f038f (patch)
tree087fbe5a528d96cdc548f36dd576c61d317b4a58 /src/dpi_api.c
parent3b09645d2b0259962d7f1e8a0adf76ab4b00fc1c (diff)
Add initial code
The inital code is from this patch: https://gerrit.fd.io/r/#/c/vpp/+/16580/ It is contributed by Intel and Travelping. Jerome Tollet, Ed Warnicke, Dave Barach, Damjan Marion from Cisco and other guys have gave lots of useful comments on it. The initial code is used for identifying layer-7 applications for HTTPS/TLS traffic - Below is the brief design info. - Provides a default APPID database for scan. - Dynamically create new SW mapping has been supported now. - Support TCP connection state tracking. - Support TCP segments reassembly on the fly, which handles out-of-order tcp segments and overlapping segments. It means that we do not need to reassembly segments first, then dedect applicaion, and then fragment segments again, which helps to improve performance. - Support Hyperscan Stream mode, which can scan rules straddling into different tcp segments. It means that if there is a rule "abcde", then "abc" can be in packet 1, and "de" can be in packet 2. - Configure static dpi flows with 5-tuple and VRF-aware, and supports both ipv4 and ipv6 flows. These flows will first try to HW offload to NIC based on DPDK rte_flow mechanism and vpp/vnet/flow infrastructure. If failed, then will create static SW flow mappings. Each flow configuration will create two HW or SW flow mappings, i.e. for forward and reverse traffic. And both flow mappings will be mapped to the same dpi flow. SW entry aging out mechanism will be added later. "dpi flow [add | del] " "[src-ip <ip-addr>] [dst-ip <ip-addr>] " "[src-port <port>] [dst-port <port>] " "[protocol <protocol>] [vrf-id <nn>]", "dpi set flow-offload hw <interface-name> rx <flow-id> [del]", "dpi set ip4 flow-bypass <interface> [del]", - When HW flow offload matched, packets will be redirected to DPI plugin with dpi flow_id in packet descriptor. If not, packets will be bypassed to DPI plugin from ip-input, and then lookup SW flow mapping table. - Then will detect layer 7 applications. This first patch only detect sub protocls within SSL/TLS. 1). Identify SSL/TLS certificate message and subsequent segments. 2). Scan SSL/TLS certificate message through hyperscan, and get application id if matched. 3). If maximum packets for this flow are checked and not found matched application, the detection will end up. Ticket: Type: feature Signed-off-by: Hongjun Ni <hongjun.ni@intel.com> Signed-off-by: Andreas Schultz <andreas.schultz@travelping.com> Signed-off-by: Mathias Gumz <mathias.gumz@travelping.com> Change-Id: I839cc70ddc80ea594d22a04e2cabf92a7b9c74e7
Diffstat (limited to 'src/dpi_api.c')
-rw-r--r--src/dpi_api.c160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/dpi_api.c b/src/dpi_api.c
new file mode 100644
index 0000000..540d1a2
--- /dev/null
+++ b/src/dpi_api.c
@@ -0,0 +1,160 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2018 Intel, Travelping 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.
+ *------------------------------------------------------------------
+*
+*/
+
+#include <vnet/interface.h>
+#include <vnet/api_errno.h>
+#include <vnet/feature/feature.h>
+#include <vnet/fib/fib_table.h>
+
+#include <vppinfra/byte_order.h>
+#include <vlibmemory/api.h>
+
+#include <dpi/dpi.h>
+
+
+#define vl_msg_id(n,h) n,
+typedef enum
+{
+#include <dpi/dpi.api.h>
+ /* We'll want to know how many messages IDs we need... */
+ VL_MSG_FIRST_AVAILABLE,
+} vl_msg_id_t;
+#undef vl_msg_id
+
+/* define message structures */
+#define vl_typedefs
+#include <dpi/dpi.api.h>
+#undef vl_typedefs
+
+/* define generated endian-swappers */
+#define vl_endianfun
+#include <dpi/dpi.api.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 <dpi/dpi.api.h>
+#undef vl_printfun
+
+/* Get the API version number */
+#define vl_api_version(n,v) static u32 api_version=(v);
+#include <dpi/dpi.api.h>
+#undef vl_api_version
+
+#define vl_msg_name_crc_list
+#include <dpi/dpi.api.h>
+#undef vl_msg_name_crc_list
+
+#define REPLY_MSG_ID_BASE dm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
+
+static void
+setup_message_id_table (dpi_main_t * dm, api_main_t * am)
+{
+#define _(id,n,crc) \
+ vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + dm->msg_id_base);
+ foreach_vl_msg_name_crc_dpi;
+#undef _
+}
+
+#define foreach_dpi_plugin_api_msg \
+_(DPI_FLOW_ADD_DEL, dpi_flow_add_del)
+
+
+/* API message handler */
+static void
+vl_api_dpi_flow_add_del_t_handler (vl_api_dpi_flow_add_del_t * mp)
+{
+ vl_api_dpi_flow_add_del_reply_t *rmp = NULL;
+ dpi_main_t *dm = &dpi_main;
+ int rv = 0;
+ u32 fib_index;
+ u32 flow_id = ~0;
+
+ fib_index = fib_table_find (fib_ip_proto (mp->is_ipv6), ntohl (mp->vrf_id));
+ if (fib_index == ~0)
+ {
+ rv = VNET_API_ERROR_NO_SUCH_FIB;
+ goto out;
+ }
+
+ dpi_add_del_flow_args_t a = {
+ .is_add = mp->is_add,
+ .is_ipv6 = mp->is_ipv6,
+ .src_ip = to_ip46 (mp->is_ipv6, mp->src_ip),
+ .dst_ip = to_ip46 (mp->is_ipv6, mp->dst_ip),
+ .src_port = ntohs (mp->src_port),
+ .dst_port = ntohs (mp->dst_port),
+ .protocol = mp->protocol,
+ .fib_index = fib_index,
+ };
+
+ /* Check src ip and dst ip are different */
+ if (ip46_address_cmp (&a.dst_ip, &a.src_ip) == 0)
+ {
+ rv = VNET_API_ERROR_SAME_SRC_DST;
+ goto out;
+ }
+
+ rv = dpi_flow_add_del (&a, &flow_id);
+
+out:
+ /* *INDENT-OFF* */
+ REPLY_MACRO2(VL_API_DPI_FLOW_ADD_DEL_REPLY,
+ ({
+ rmp->flow_id = htonl (flow_id);
+ }));
+ /* *INDENT-ON* */
+}
+
+static clib_error_t *
+dpi_api_hookup (vlib_main_t * vm)
+{
+ dpi_main_t *dm = &dpi_main;
+
+ u8 *name = format (0, "dpi_%08x%c", api_version, 0);
+ dm->msg_id_base = vl_msg_api_get_msg_ids
+ ((char *) name, VL_MSG_FIRST_AVAILABLE);
+
+#define _(N,n) \
+ vl_msg_api_set_handlers((VL_API_##N + dm->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_dpi_plugin_api_msg;
+#undef _
+
+ /* Add our API messages to the global name_crc hash table */
+ setup_message_id_table (dm, &api_main);
+
+ return 0;
+}
+
+VLIB_API_INIT_FUNCTION (dpi_api_hookup);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */