summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuxueli <[email protected]>2022-08-25 18:13:46 +0800
committerliuxueli <[email protected]>2022-08-25 19:17:23 +0800
commite3ea4d0729a524df7206e6c0b2a324e67db19723 (patch)
tree54df92c1b3d1c12e643781c8dc860151bffc30f0
parent9cfa120ae79cfd429f1b77eb8ccb6036651e7233 (diff)
update session manager interface definition; define ex_data interface; delete the event design
-rw-r--r--.gitignore21
-rw-r--r--sdk/example/custom_event_plugin.cpp2
-rw-r--r--sdk/include/event.h21
-rw-r--r--sdk/include/plugin.h4
-rw-r--r--sdk/include/session.h85
-rw-r--r--sdk/include/types.h318
-rw-r--r--src/main.cpp12
-rw-r--r--src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp2
-rw-r--r--src/protocol_decoder/http/http.cpp10
-rw-r--r--src/session_manager/CMakeLists.txt5
-rw-r--r--src/session_manager/parser/ethernet.cpp0
-rw-r--r--src/session_manager/session_ex_data.cpp30
-rw-r--r--src/session_manager/session_ex_data.h18
-rw-r--r--src/session_manager/session_internal_types.h62
-rw-r--r--src/session_manager/session_manager.cpp86
-rw-r--r--src/session_manager/session_manager.h54
-rw-r--r--src/session_manager/session_utils.cpp55
17 files changed, 618 insertions, 167 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d56b12e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,21 @@
+SI/
+*.log
+*.o
+*.so
+*.si4project/
+*.a
+*.o
+*.d
+*.bak
+.idea/
+bin/log/
+bin/sapp
+cmake-build-debug
+.vscode
+./build/
+version.txt
+GPATH
+GRTAGS
+GTAGS
+cmake-build*
+src/config/sapp.toml.hex.array.c
diff --git a/sdk/example/custom_event_plugin.cpp b/sdk/example/custom_event_plugin.cpp
index 00e0d43..6419eb9 100644
--- a/sdk/example/custom_event_plugin.cpp
+++ b/sdk/example/custom_event_plugin.cpp
@@ -74,7 +74,7 @@ extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *sess
if (event & SESSION_EVENT_ORDPKT)
{
- struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, ctx);
+ struct session_event_extras *info = (struct session_event_extras *)custom_decode(payload, len, ctx);
struct stellar_session *new_session = session_manager_session_derive(session, "CUSTOM");
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
diff --git a/sdk/include/event.h b/sdk/include/event.h
deleted file mode 100644
index 774c7d5..0000000
--- a/sdk/include/event.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#ifdef __cpluscplus
-extern "C"
-{
-#endif
-
-struct stellar_session_event_data;
-
-struct stellar_event
-{
- union
- {
- struct stellar_session_event_data *session_event_data;
- void *event_data;
- };
-};
-
-#ifdef __cpluscplus
-}
-#endif \ No newline at end of file
diff --git a/sdk/include/plugin.h b/sdk/include/plugin.h
index 33fe985..d506be6 100644
--- a/sdk/include/plugin.h
+++ b/sdk/include/plugin.h
@@ -12,7 +12,7 @@ extern "C"
typedef int plugin_init_callback(void);
typedef void plugin_exit_callback(void);
-typedef void plugin_event_callback(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx);
+typedef void plugin_event_callback(const struct stellar_session *session, enum session_state state, int thread_id, void **ctx);
/******************************************************************************
* Public API For Plugin
@@ -44,4 +44,4 @@ void pm_session_take_over(const struct stellar_session *session);
}
#endif
-#endif \ No newline at end of file
+#endif
diff --git a/sdk/include/session.h b/sdk/include/session.h
index c55d191..4911881 100644
--- a/sdk/include/session.h
+++ b/sdk/include/session.h
@@ -1,5 +1,5 @@
-#ifndef _SESSION_H
-#define _SESSION_H
+#ifndef _SESSION_H_
+#define _SESSION_H_
#ifdef __cpluscplus
extern "C"
@@ -7,18 +7,25 @@ extern "C"
#endif
#include "packet.h"
-#include "event.h"
#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
-struct stellar_session;
-enum stellar_session_type
+/* session direction definition */
+#define SESSION_DIR_C2S 0x01
+#define SESSION_DIR_S2C 0x02
+#define SESSION_DIR_DOUBLE 0x03
+
+enum session_type
{
SESSION_TYPE_CUSTOM,
- SESSION_TYPE_IP,
+ SESSION_TYPE_IPV4,
+ SESSION_TYPE_IPV6,
SESSION_TYPE_TCP,
SESSION_TYPE_UDP,
- SESSION_TYPE_ICMP,
+ SESSION_TYPE_ICMPV4,
+ SESSION_TYPE_ICMPV6,
SESSION_TYPE_PPTP,
SESSION_TYPE_L2TP,
SESSION_TYPE_SOCKS,
@@ -26,29 +33,67 @@ enum stellar_session_type
SESSION_TYPE_HTTP,
SESSION_TYPE_MAIL,
SESSION_TYPE_DNS,
+ SESSION_TYPE_OPENVPN,
+ SESSION_TYPE_HTTP_PROXY,
SESSION_TYPE_MAX,
};
-enum session_event_type
+//http decoder
+enum http_stage
+{
+ HTTP_STAGE_REQ_HDR=1<<1,
+ HTTP_STAGE_REQ_BODY_BEGIN=1<<2,
+ HTTP_STAGE_REQ_BODY_CONTINUE=1<<3,
+ HTTP_STAGE_REQ_BODY_END,
+ HTTP_STAGE_RESP_HDR,
+ HTTP_STAGE_RESP_BODY
+};
+
+//dns decoder
+enum dns_stage
{
- SESSION_EVENT_UNKNOWN = (0x00),
- SESSION_EVENT_OPENING = (0x01 << 1),
- SESSION_EVENT_RAWPKT = (0x01 << 2),
- SESSION_EVENT_ORDPKT = (0x01 << 3),
- SESSION_EVENT_META = (0x01 << 4),
- SESSION_EVENT_CLOSING = (0x01 << 5),
- SESSION_EVENT_ALL = (0x01 << 1 | 0x01 << 2 | 0x01 << 3 | 0x01 << 4 | 0x01 << 5),
+ DNS_STAGE_REQUEST,
+ DNS_STAGE_RESPONSE
};
-struct stellar_session_event_extras;
+enum session_state
+{
+ SESSION_STATE_OPENING,
+ SESSION_STATE_ACTIVE,
+ SESSION_STATE_CLOSING
+};
-void session_manager_trigger_event(struct stellar_session *s, enum session_event_type type, struct stellar_session_event_extras *info);
-struct stellar_session *session_manager_session_derive(const struct stellar_session *this_session, const char *session_name);
+struct stellar_session;
+struct stellar_session *session_derive(const struct stellar_session *this_session, const char *session_name);
+void session_close(const struct stellar_session *session);
-const char *stellar_session_get_name(const struct stellar_session *session);
+const char *session_get_name(const struct stellar_session *session);
+
+uint8_t session_get_direction(const struct stellar_session *session); // tcp or udp
+uint8_t session_get_current_direction(const struct stellar_session *session); // tcp or udp
+
+uint64_t session_get_createtime_ms(const struct stellar_session *session);
+uint64_t session_get_lasttime_ms(const struct stellar_session *session);
+enum session_type session_get_type(const struct stellar_session *session);
+struct stellar_packet *session_get_packet(struct stellar_session *session);
+enum session_state session_get_state(struct stellar_session *session);
+const char *session_get_payload(struct stellar_session *session);
+size_t session_get_payload_length(struct stellar_session *session);
+
+typedef void (*free_ex_data)(void *ex_data, void *cb_arg);
+static inline void directly_free(void *ex_data, void *cb_arg)
+{
+ free(ex_data);
+}
+
+int session_get_ex_data_index(struct stellar_session *session, const char *key);
+void *session_get_ex_data(struct stellar_session *session, int idx);
+void session_set_ex_data(struct stellar_session *session, int idx, void *ex_data, free_ex_data *free_cb, void *cb_arg);
+void session_del_ex_data(struct stellar_session *session, int idx, free_ex_data *free_cb, void *cb_arg);
+void session_trigger_ex_data_event(stellar_session *session, int idx, enum session_state state);
#ifdef __cpluscplus
}
#endif
-#endif \ No newline at end of file
+#endif
diff --git a/sdk/include/types.h b/sdk/include/types.h
new file mode 100644
index 0000000..4cfee97
--- /dev/null
+++ b/sdk/include/types.h
@@ -0,0 +1,318 @@
+#ifndef _TYPES_H_
+#define _TYPES_H_
+
+#ifdef __cpluscplus
+extern "C"
+{
+#endif
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+#include <linux/if_ether.h>
+
+enum addr_type
+{
+ ADDR_TYPE_UNKNOWN,
+ ADDR_TYPE_MAC,
+ ADDR_TYPE_ARP,
+ ADDR_TYPE_IPV4,
+ ADDR_TYPE_IPV6,
+ ADDR_TYPE_TCP,
+ ADDR_TYPE_UDP,
+ ADDR_TYPE_ICMPV4,
+ ADDR_TYPE_ICMPV6,
+ ADDR_TYPE_PPTP,
+ ADDR_TYPE_L2TP,
+ ADDR_TYPE_SOCKS,
+ ADDR_TYPE_GTPU,
+ ADDR_TYPE_PPPOE,
+ ADDR_TYPE_GRE,
+ ADDR_TYPE_VLAN,
+ ADDR_TYPE_MPLS,
+ ADDR_TYPE_PPP,
+ ADDR_TYPE_VXLAN,
+ ADDR_TYPE_MAX
+};
+
+
+struct layer_addr_mac
+{
+ struct ethhdr smac;
+ struct ethhdr dmac;
+};
+
+struct layer_addr_ipv4
+{
+ uint32_t saddr; /* network order */
+ uint32_t daddr; /* network order */
+};
+
+struct layer_addr_ipv6
+{
+ struct in6_addr saddr;
+ struct in6_addr daddr ;
+};
+
+struct layer_addr_tuple4
+{
+ struct layer_addr_ipv4 ipv4;
+ uint16_t source; /* network order */
+ uint16_t dest; /* network order */
+};
+
+struct layer_addr_tuple6
+{
+ struct layer_addr_ipv6 ipv6;
+ uint16_t source; /* network order */
+ uint16_t dest; /* network order */
+};
+
+/*
+* https://datatracker.ietf.org/doc/html/rfc2637
+* https://wwwdisc.chimica.unipd.it/luigino.feltre/pubblica/unix/winnt_doc/pppt/understanding_pptp.html#:~:text=Introduction-,Point%2Dto%2DPoint%20Tunneling%20Protocol%20(PPTP)%20is%20a,%2FIP%2Dbased%20data%20networks.
+*
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ |C|R|K|S|s|Recur|A| Flags | Ver | Protocol Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Key (HW) Payload Length | Key (LW) Call ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Sequence Number (Optional) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Acknowledgment Number (Optional) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+*/
+
+struct pptp_gre_header
+{
+ uint16_t checksum:1; /* Checksum Bit: Checksum field Present */
+ uint16_t routing:1; /* Routing Bit: Routing field Present */
+ uint16_t key:1; /* Key Bit: Key field Present */
+ uint16_t sequence:1; /* Sequence Bit: sequence present. Set to one (1) if a payload (data) packet is present. Set to zero (0) if payload is not present (GRE packet is an Acknowledgment only) */
+ uint16_t strict:1; /* Strict Bit: Strict source route present*/
+ uint16_t recursion:3; /* Recursion Bit: Recursion control */
+ uint16_t acknowledgment:1; /* Acknowledgment Bit: Acknowledgment sequence number present */
+ uint16_t flags:4; /* Must be set to zero */
+ uint16_t version:3; /* Must contain 1 (enhanced GRE) */
+};
+
+struct layer_addr_pptp
+{
+ uint16_t pac_call_id; /* callid, network order */
+ uint16_t pns_call_id; /* callid, network order */
+};
+
+/*
+* https://en.wikipedia.org/wiki/Layer_2_Tunneling_Protocol
+* The two endpoints of an L2TP tunnel are called the L2TP access concentrator (LAC) and the L2TP network server (LNS).
+* https://docs.huihoo.com/doxygen/linux/kernel/3.7/l2tp__core_8c_source.html
+* Do receive processing of L2TP data frames. We handle both L2TPv2
+ * and L2TPv3 data frames here.
+ *
+ * L2TPv2 Data Message Header
+ *
+ * 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |T|L|x|x|S|x|O|P|x|x|x|x| Ver | Length (opt) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Tunnel ID | Session ID |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Ns (opt) | Nr (opt) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Offset Size (opt) | Offset pad... (opt)
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * Data frames are marked by T=0. All other fields are the same as
+ * those in L2TP control frames.
+ *
+ * L2TPv3 Data Message Header
+ *
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | L2TP Session Header |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | L2-Specific Sublayer |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Tunnel Payload ...
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * L2TPv3 Session Header Over IP
+ *
+ * 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Session ID |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Cookie (optional, maximum 64 bits)...
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * L2TPv3 L2-Specific Sublayer Format
+ *
+ * 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |x|S|x|x|x|x|x|x| Sequence Number |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * Cookie value, sublayer format and offset (pad) are negotiated with
+ * the peer when the session is set up. Unlike L2TPv2, we do not need
+ * to parse the packet header to determine if optional fields are
+ * present.
+ *
+ * Caller must already have parsed the frame and determined that it is
+ * a data (not control) frame before coming here. Fields up to the
+ * session-id have already been parsed and ptr points to the data
+ * after the session-id.
+*/
+
+struct layer_ppp_header
+{
+ uint8_t address;
+ uint8_t control;
+ uint16_t protocol; /* network order */
+};
+
+struct layer_ppp_compress_header
+{
+ uint8_t protocol;
+};
+
+struct layer_addr_l2tp_v2
+{
+ uint16_t lac_tunnelid; /* network order */
+ uint16_t lns_tunnelid; /* network order */
+ uint16_t lac_sessionid; /* network order */
+ uint16_t lns_sessionid; /* network order */
+ uint8_t ppp_compress_hdr_enable;
+ union
+ {
+ struct layer_ppp_header ppp_hdr;
+ struct layer_ppp_compress_header ppp_compress_hdr;
+ };
+};
+
+struct layer_addr_l2tp_v3
+{
+ uint32_t sessionlid; /* network order */
+};
+
+struct l2tp_packet_type
+{
+ uint16_t type:1; /* */
+ uint16_t length:1; /* Lenght Bit: length field is not present */
+ uint16_t padding1:2;
+ uint16_t sequence:1; /* Sequence Bit: sequence(ns and nr) field is not present */
+ uint16_t padding2:1;
+ uint16_t offset:1; /* Offset Bit: Offset size filed is present */
+ uint16_t priority:1; /* Priority Bit */
+ uint16_t padding:4;
+ uint16_t version:4;
+};
+
+struct layer_addr_l2tp
+{
+ struct l2tp_packet_type l2tp_packet;
+ union
+ {
+ struct layer_addr_l2tp_v2 v2;
+ struct layer_addr_l2tp_v3 v3;
+ };
+};
+
+struct layer_addr_gtp
+{
+ uint32_t c2s_teid; /* network order */
+ uint32_t s2c_teid; /* network order */
+};
+
+#define VLAN_ID_MASK (0x0FFF)
+#define VLAN_TAG_LEN (4)
+#define MAX_VLAN_ADDR_LAYER (8)
+
+/* refer to https://en.wikipedia.org/wiki/IEEE_802.1Q */
+
+struct layer_addr_single_vlan
+{
+ uint8_t PCP; /* Priority code point */
+ uint8_t DEI; /* Drop eligible indicator */
+ uint16_t TPID; /* Tag protocol identifier, network order */
+ uint16_t VID; /* VLAN identifier, network order */
+};
+
+
+struct layer_addr_vlan
+{
+ uint8_t c2s_layer_num;
+ uint8_t s2c_layer_num;
+ struct layer_addr_single_vlan c2s_addr_array[MAX_VLAN_ADDR_LAYER];
+ struct layer_addr_single_vlan s2c_addr_array[MAX_VLAN_ADDR_LAYER];
+};
+
+#define MAX_MPLS_ADDR_LAYER 4
+/* refer to RFC3032 */
+struct layer_addr_single_mpls
+{
+ uint32_t label; /* network order */
+ uint8_t experimental;
+ uint8_t bottom;
+ uint8_t ttl;
+};
+
+struct layer_addr_mpls
+{
+ struct layer_addr_single_mpls c2s_addr_array[MAX_MPLS_ADDR_LAYER];
+ struct layer_addr_single_mpls s2c_addr_array[MAX_MPLS_ADDR_LAYER];
+ uint8_t c2s_layer_num; /* mpls layer number */
+ uint8_t s2c_layer_num; /* mpls layer number */
+ uint8_t c2s_ctrl_word_flag;
+ uint8_t s2c_ctrl_word_flag;
+ uint32_t c2s_ctrl_word; /* refer to RFC4623 */
+ uint32_t s2c_ctrl_word; /* refer to RFC4623 */
+};
+
+#if 0
+https://en.wikipedia.org/wiki/Generic_Routing_Encapsulation
+
+struct layer_addr_gre
+{
+ uint16_t call_id; /* network order */
+};
+#endif
+
+struct layer_addr_pppoe
+{
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ uint32_t ver:4;
+ uint32_t type:4;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ uint32_t type:4;
+ uint32_t ver:4;
+#endif
+ uint8_t code;
+ uint16_t session_id;
+};
+
+
+
+struct raw_ipfrag_list
+{
+ void *packet_frag; /* not ip header, the original header obtained from the underlying network card */
+ uint32_t packet_len;
+ int32_t packet_type; /* IPv4 or IPv6 */
+ struct raw_ipfrag_list *next;
+};
+
+#ifdef __cpluscplus
+}
+#endif
+
+#endif
+
diff --git a/src/main.cpp b/src/main.cpp
index 8d94824..5b55113 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -28,20 +28,20 @@ struct stellar_event_base_loop_arg
void *stellar_event_base_loop(void *arg)
{
struct stellar_packet *rx_pkt;
- struct stellar_event *event;
+ struct stellar_session *session;
struct stellar_event_base_loop_arg *thread_arg = (struct stellar_event_base_loop_arg *)arg;
while(1)
{
int fetch_num = packet_io_device_rx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
if(fetch_num > 0)
{
- event = session_manager_commit(thread_arg->session_mgr, rx_pkt);
- while(event)
+ session = session_manager_commit(thread_arg->session_mgr, rx_pkt, thread_arg->tid);
+ while(session)
{
- plugin_manager_dispatch(thread_arg->plug_mgr ,event);
- event = session_manager_fetch_event(thread_arg->session_mgr);
+ plugin_manager_dispatch(thread_arg->plug_mgr ,session);
+ session = session_manager_fetch_session(thread_arg->session_mgr, session, thread_arg->tid);
}
-
+
//clean session_manager event queue
packet_io_device_tx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
}
diff --git a/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp b/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp
index 178ea05..a6e9a8a 100644
--- a/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp
+++ b/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp
@@ -103,7 +103,7 @@ extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *sess
{
(*per_tcp_session_ctx)->flags = SESSION_EVENT_ORDPKT;
- struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, ctx);
+ struct session_event_extras *info = (struct session_event_extras *)custom_decode(payload, len, ctx);
struct stellar_session *new_session = session_manager_session_derive(session, "CUSTOM");
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
diff --git a/src/protocol_decoder/http/http.cpp b/src/protocol_decoder/http/http.cpp
index dc74ab0..02c691d 100644
--- a/src/protocol_decoder/http/http.cpp
+++ b/src/protocol_decoder/http/http.cpp
@@ -3,13 +3,9 @@
#include "sdk/include/session.h"
#include "sdk/include/http.h"
-void http_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
+void http_entry(const struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
{
- struct stellar_session_event_extras *info = NULL;
- struct stellar_session *new_session = session_manager_session_derive(session, "HTTP");
-
- session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
- session_manager_trigger_event(new_session, SESSION_EVENT_META, info);
+ struct stellar_session *new_session = session_derive(session, "HTTP");
}
struct http_decoder *http_session_get_decoder(const struct stellar_session *http_session)
@@ -28,4 +24,4 @@ void http_decoder_fetch_request_line(struct http_decoder *decoder, struct http_r
void http_decoder_fetch_status_line(struct http_decoder *decoder, struct http_status_line *status_line)
{
-} \ No newline at end of file
+}
diff --git a/src/session_manager/CMakeLists.txt b/src/session_manager/CMakeLists.txt
index b78722f..9b4583f 100644
--- a/src/session_manager/CMakeLists.txt
+++ b/src/session_manager/CMakeLists.txt
@@ -1,4 +1,7 @@
add_library(session_manager
session_manager.cpp
+ session_ex_data.cpp
+ session_utils.cpp
+ parser/ethernet.cpp
)
-target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}) \ No newline at end of file
+target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR})
diff --git a/src/session_manager/parser/ethernet.cpp b/src/session_manager/parser/ethernet.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/session_manager/parser/ethernet.cpp
diff --git a/src/session_manager/session_ex_data.cpp b/src/session_manager/session_ex_data.cpp
new file mode 100644
index 0000000..4b81ffd
--- /dev/null
+++ b/src/session_manager/session_ex_data.cpp
@@ -0,0 +1,30 @@
+#include <string.h>
+#include <stdlib.h>
+
+#include "session_ex_data.h"
+#include "sdk/include/session.h"
+
+int session_get_ex_data_index(struct stellar_session *session, const char *key)
+{
+ return 0;
+}
+
+void *session_get_ex_data(struct stellar_session *session, int idx)
+{
+ return nullptr;
+
+}
+void session_set_ex_data(struct stellar_session *session, int idx, void *ex_data, free_ex_data *free_cb, void *cb_arg)
+{
+
+}
+
+void session_del_ex_data(struct stellar_session *session, int idx, free_ex_data *free_cb, void *cb_arg)
+{
+
+}
+
+void session_trigger_ex_data_event(stellar_session *session, int idx, enum session_state state)
+{
+
+}
diff --git a/src/session_manager/session_ex_data.h b/src/session_manager/session_ex_data.h
new file mode 100644
index 0000000..b501bdc
--- /dev/null
+++ b/src/session_manager/session_ex_data.h
@@ -0,0 +1,18 @@
+#ifndef _SESSION_EX_DATA_H_
+#define _SESSION_EX_DATA_H_
+
+#ifdef __cpluscplus
+extern "C"
+{
+#endif
+
+
+
+
+
+#ifdef __cpluscplus
+}
+#endif
+
+#endif
+
diff --git a/src/session_manager/session_internal_types.h b/src/session_manager/session_internal_types.h
new file mode 100644
index 0000000..ec833b0
--- /dev/null
+++ b/src/session_manager/session_internal_types.h
@@ -0,0 +1,62 @@
+#ifndef _SESSION_INTERNAL_TYPES_H_
+#define _SESSION_INTERNAL_TYPES_H_
+
+#ifdef __cpluscplus
+extern "C"
+{
+#endif
+
+#include "sdk/include/types.h"
+#include "sdk/include/session.h"
+
+struct layer_addr
+{
+ enum addr_type type; /* definition in enum addr_type */
+ uint8_t addrlen;
+ //uint8_t pkttype; /* packet special features, definition in MACRO PKT_TYPE_xxx */
+ //uint8_t pktipfragtype; /* ip frag packetfeatures, definition in MACRO PKT_TYPE_xxx */
+ uint8_t padding[3]; /* pad for alignment */
+ union
+ {
+ struct layer_addr_mac *mac;
+ struct layer_addr_ipv4 *ipv4;
+ struct layer_addr_ipv6 *ipv6;
+ struct layer_addr_vlan *vlan;
+ //struct layer_addr_gre *gre;
+ struct layer_addr_tuple4 *tcp;
+ struct layer_addr_tuple6 *udp;
+ struct layer_addr_pppoe *pppoe;
+ struct layer_addr_l2tp *l2tp;
+ struct layer_addr_pptp *pptp;
+ struct layer_addr_gtp *gtp;
+ struct layer_addr_mpls *mpls;
+ void *paddr;
+ };
+};
+
+struct stellar_session
+{
+ const char *name;
+ uint8_t is_tunnel:1;
+ uint8_t padding:3;
+ uint8_t session_dir:2;
+ uint8_t current_dir:2;
+ uint8_t close_reason;
+ uint32_t hash_index;
+ uint64_t createtime; // struct timespec
+ uint64_t lastmtime; // struct timespec
+ enum session_type type;
+ struct layer_addr *addr;
+ void *ex_data; // array or list
+ struct session_manager *instance;
+ struct stellar_session *next;
+ struct stellar_session *prev;
+};
+
+
+#ifdef __cpluscplus
+}
+#endif
+
+#endif
+
diff --git a/src/session_manager/session_manager.cpp b/src/session_manager/session_manager.cpp
index 91e2405..dd2ef30 100644
--- a/src/session_manager/session_manager.cpp
+++ b/src/session_manager/session_manager.cpp
@@ -5,97 +5,45 @@
struct session_manager
{
+ int thread_num;
+ uint32_t tcp_timeout_s;
+ uint32_t tcp_table_max_size;
+ uint32_t tcp_reordered_num;
+ uint32_t udp_timeout_s;
+ uint32_t udp_table_max_size;
struct stellar_session **tcp_table;
- struct stellar_session **udp_table;
+ struct stellar_session **udp_table;
};
-struct session_manager *session_manager_init()
+void session_close(const struct stellar_session *session)
{
- return nullptr;
-}
-
-void session_manager_trigger_event(struct stellar_session *s, enum session_event_type type, struct stellar_session_event_extras *info)
-{
- return;
+
}
-struct stellar_session *session_manager_session_derive(const struct stellar_session *this_session, const char *session_name)
+struct stellar_session *session_derive(const struct stellar_session *this_session, const char *session_name)
{
return nullptr;
}
-struct stellar_event *session_manager_commit(struct session_manager *h, struct stellar_packet *p)
-{
- return nullptr;
-};
-
-struct stellar_event *session_manager_fetch_event(struct session_manager *h)
+struct session_manager *session_manager_create(int thread_num)
{
return nullptr;
}
-/******************************************************************************
- * stellar_event API For Plugin Manager
- ******************************************************************************/
-
-struct session_plugin_ctx *stellar_event_get_plugin_ctx(struct stellar_event *event)
-{
- return event->session_event_data->plugin_ctx;
-}
-
-void stellar_event_set_plugin_ctx(struct stellar_event *event, struct session_plugin_ctx *plugin_ctx)
-{
- event->session_event_data->plugin_ctx = plugin_ctx;
-}
-
-enum session_event_type stellar_event_get_type(struct stellar_event *event)
+void session_manager_destroy(struct session_manager *instance)
{
- return event->session_event_data->type;
+
}
-const char *stellar_event_get_session_name(struct stellar_event *event)
+struct stellar_session *session_manager_commit(struct session_manager *instance, struct stellar_packet *pkt, int thread_id)
{
- return event->session_event_data->s->name;
-}
-
-const struct stellar_session *stellar_event_get_session(struct stellar_event *event)
-{
- return event->session_event_data->s;
-}
-// TODO
-struct stellar_packet *stellar_event_get_packet(struct stellar_event *event)
-{
- return NULL;
-}
-
-// TODO
-const char *stellar_event_get_payload(struct stellar_event *event)
-{
- return NULL;
+ return nullptr;
}
-// TODO
-uint16_t stellar_event_get_payload_length(struct stellar_event *event)
+struct stellar_session *session_manager_fetch_session(struct session_manager *instance, struct stellar_session *session, int thread_id)
{
- return 0;
-}
-/******************************************************************************
- * stellar_session API For Plugin Manager
- ******************************************************************************/
-
-struct session_plugin_ctx *stellar_session_get_plugin_ctx(const struct stellar_session *session)
-{
- struct stellar_session_event_data *evdata = session->event_data;
- return evdata->plugin_ctx;
+ return nullptr;
}
-/******************************************************************************
- * stellar_session API For Plugin
- ******************************************************************************/
-
-const char *stellar_session_get_name(const struct stellar_session *session)
-{
- return session->name;
-} \ No newline at end of file
diff --git a/src/session_manager/session_manager.h b/src/session_manager/session_manager.h
index ec8ac60..f05d0b2 100644
--- a/src/session_manager/session_manager.h
+++ b/src/session_manager/session_manager.h
@@ -1,47 +1,23 @@
-#pragma once
+#ifndef _SESSION_MANAGER_H_
+#define _SESSION_MANAGER_H_
-#include "sdk/include/session.h"
-
-struct stellar_session_event_data
+#ifdef __cpluscplus
+extern "C"
{
- struct stellar_session *s;
- enum session_event_type type;
- long last_active;
- struct session_plugin_ctx *plugin_ctx;
-};
-
-struct session_manager;
-struct session_manager *session_manager_init();
-
-struct stellar_event *session_manager_commit(struct session_manager *session_mgr, struct stellar_packet *pkt);
-struct stellar_event *session_manager_fetch_event(struct session_manager *session_mgr);
+#endif
-struct stellar_session
-{
- stellar_session_type type;
- const char *name;
- void *addr;
- void *data;
- struct stellar_session_event_data *event_data;
-};
-
-/******************************************************************************
- * stellar_event API For Plugin Manager
- ******************************************************************************/
+#include "sdk/include/session.h"
-struct session_plugin_ctx *stellar_event_get_plugin_ctx(struct stellar_event *event);
-void stellar_event_set_plugin_ctx(struct stellar_event *event, struct session_plugin_ctx *plugin_ctx);
+struct session_manager;
+struct session_manager *session_manager_create(int thread_num);
+void session_manager_destroy(struct session_manager *instance);
-enum session_event_type stellar_event_get_type(struct stellar_event *event);
-const char *stellar_event_get_session_name(struct stellar_event *event);
-const struct stellar_session *stellar_event_get_session(struct stellar_event *event);
-struct stellar_packet *stellar_event_get_packet(struct stellar_event *event);
+struct stellar_session *session_manager_commit(struct session_manager *instance, struct stellar_packet *pkt, int thread_id);
+struct stellar_session *session_manager_fetch_session(struct session_manager *instance, struct stellar_session *session, int thread_id);
-const char *stellar_event_get_payload(struct stellar_event *event);
-uint16_t stellar_event_get_payload_length(struct stellar_event *event);
+#ifdef __cpluscplus
+}
+#endif
-/******************************************************************************
- * stellar_session API For Plugin Manager
- ******************************************************************************/
+#endif
-struct session_plugin_ctx *stellar_session_get_plugin_ctx(const struct stellar_session *session); \ No newline at end of file
diff --git a/src/session_manager/session_utils.cpp b/src/session_manager/session_utils.cpp
new file mode 100644
index 0000000..76f24f8
--- /dev/null
+++ b/src/session_manager/session_utils.cpp
@@ -0,0 +1,55 @@
+#include <stddef.h>
+
+#include "session_internal_types.h"
+
+
+const char *session_get_name(const struct stellar_session *session)
+{
+ return nullptr;
+}
+
+uint8_t session_get_direction(const struct stellar_session *session)
+{
+ return SESSION_DIR_DOUBLE;
+}
+
+uint8_t session_get_current_direction(const struct stellar_session *session)
+{
+ return SESSION_DIR_C2S;
+}
+
+uint64_t session_get_createtime_ms(const struct stellar_session *session)
+{
+ return 123456778;
+}
+
+uint64_t session_get_lasttime_ms(const struct stellar_session *session)
+{
+ return 123457890;
+}
+
+enum session_type session_get_type(const struct stellar_session *session)
+{
+ return SESSION_TYPE_TCP;
+}
+
+struct stellar_packet *session_get_packet(struct stellar_session *session)
+{
+ return nullptr;
+}
+
+enum session_state session_get_state(struct stellar_session *session)
+{
+ return SESSION_STATE_ACTIVE;
+}
+
+const char *session_get_payload(struct stellar_session *session)
+{
+ return nullptr;
+}
+
+size_t session_get_payload_length(struct stellar_session *session)
+{
+ return 0;
+}
+