summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2024-04-22 20:01:15 +0800
committerluwenpeng <[email protected]>2024-04-23 14:38:58 +0800
commit74f0504d3d316ff52199c5bf76d5efa7fcbf9a5f (patch)
tree38d0b0004bbfffd813bb280b8098447bbb9f50b2
parent8a41a79f06f772723c2d01f46764f89a9576f6b7 (diff)
Update Stellar export header and add stellar_get_current_thread_index() function
-rw-r--r--include/stellar/packet.h (renamed from include/packet.h)6
-rw-r--r--include/stellar/session.h (renamed from include/session.h)6
-rw-r--r--include/stellar/stellar.h17
-rw-r--r--include/stellar/tuple.h (renamed from include/tuple.h)4
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/duplicated_packet_filter/duplicated_packet_filter.h2
-rw-r--r--src/duplicated_packet_filter/test/gtest_duplicated_packet_filter.cpp2
-rw-r--r--src/evicted_session_filter/evicted_session_filter.h2
-rw-r--r--src/id_generator/CMakeLists.txt2
-rw-r--r--src/id_generator/id_generator.cpp3
-rw-r--r--src/ip_reassembly/ip_reassembly.cpp2
-rw-r--r--src/ip_reassembly/ip_reassembly.h2
-rw-r--r--src/ip_reassembly/test/gtest_utils.h2
-rw-r--r--src/packet/packet.cpp2
-rw-r--r--src/packet/packet_priv.h (renamed from src/packet/packet_private.h)8
-rw-r--r--src/packet/packet_utils.cpp2
-rw-r--r--src/packet/test/gtest_packet.cpp2
-rw-r--r--src/packet/test/gtest_packet_frag.cpp2
-rw-r--r--src/packet_io/dumpfile_io.cpp4
-rw-r--r--src/packet_io/lock_free_queue.cpp3
-rw-r--r--src/packet_io/marsio_io.cpp4
-rw-r--r--src/packet_io/packet_io.h4
-rw-r--r--src/plugin/CMakeLists.txt2
-rw-r--r--src/plugin/plugin_manager.cpp5
-rw-r--r--src/plugin/plugin_manager.h2
-rw-r--r--src/session/session.cpp2
-rw-r--r--src/session/session_manager.cpp2
-rw-r--r--src/session/session_manager.h2
-rw-r--r--src/session/session_pool.h2
-rw-r--r--src/session/session_priv.h (renamed from src/session/session_private.h)10
-rw-r--r--src/session/session_table.h2
-rw-r--r--src/session/session_timer.h2
-rw-r--r--src/session/session_transition.h2
-rw-r--r--src/session/test/gtest_filter_tcp_dupkt.cpp2
-rw-r--r--src/session/test/gtest_overload_evict_tcp_sess.cpp4
-rw-r--r--src/session/test/gtest_overload_evict_udp_sess.cpp4
-rw-r--r--src/session/test/gtest_sess_mgr_tcp_reassembly.cpp2
-rw-r--r--src/session/test/gtest_session.cpp2
-rw-r--r--src/session/test/gtest_state_tcp_active_to_closing.cpp2
-rw-r--r--src/session/test/gtest_state_tcp_init_to_opening.cpp2
-rw-r--r--src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp2
-rw-r--r--src/session/test/gtest_state_tcp_opening_to_active.cpp2
-rw-r--r--src/session/test/gtest_state_tcp_opening_to_closing.cpp2
-rw-r--r--src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp2
-rw-r--r--src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp2
-rw-r--r--src/session/test/gtest_timeout_tcp_data.cpp2
-rw-r--r--src/session/test/gtest_timeout_tcp_handshake.cpp2
-rw-r--r--src/session/test/gtest_timeout_tcp_init.cpp2
-rw-r--r--src/session/test/gtest_timeout_udp_data.cpp2
-rw-r--r--src/stellar/CMakeLists.txt2
-rw-r--r--src/stellar/macro.h (renamed from src/stellar/stellar.h)17
-rw-r--r--src/stellar/stellar.cpp8
-rw-r--r--src/thread_idx/CMakeLists.txt4
-rw-r--r--src/thread_idx/thread_idx.cpp13
-rw-r--r--src/thread_idx/thread_idx.h17
-rw-r--r--src/timestamp/CMakeLists.txt1
-rw-r--r--src/timestamp/timestamp.cpp4
-rw-r--r--src/tuple/test/gtest_tuple.cpp2
-rw-r--r--src/tuple/tuple.cpp2
59 files changed, 134 insertions, 87 deletions
diff --git a/include/packet.h b/include/stellar/packet.h
index 0f8d8e8..439729d 100644
--- a/include/packet.h
+++ b/include/stellar/packet.h
@@ -1,12 +1,12 @@
-#ifndef _PACKET_H
-#define _PACKET_H
+#ifndef _PACKET_PUB_H
+#define _PACKET_PUB_H
#ifdef __cplusplus
extern "C"
{
#endif
-#include "tuple.h"
+#include "stellar/tuple.h"
enum layer_type
{
diff --git a/include/session.h b/include/stellar/session.h
index e557614..f0e46fd 100644
--- a/include/session.h
+++ b/include/stellar/session.h
@@ -1,5 +1,5 @@
-#ifndef _SESSION_H
-#define _SESSION_H
+#ifndef _SESSION_PUB_H
+#define _SESSION_PUB_H
#ifdef __cplusplus
extern "C"
@@ -8,7 +8,7 @@ extern "C"
#include <stdint.h>
-#include "packet.h"
+#include "stellar/packet.h"
enum session_state
{
diff --git a/include/stellar/stellar.h b/include/stellar/stellar.h
new file mode 100644
index 0000000..410583f
--- /dev/null
+++ b/include/stellar/stellar.h
@@ -0,0 +1,17 @@
+#ifndef _STELLAR_PUB_H
+#define _STELLAR_PUB_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+uint8_t stellar_get_current_thread_index();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/tuple.h b/include/stellar/tuple.h
index 73b8bcc..799977d 100644
--- a/include/tuple.h
+++ b/include/stellar/tuple.h
@@ -1,5 +1,5 @@
-#ifndef _TUPLE_H
-#define _TUPLE_H
+#ifndef _TUPLE_PUB_H
+#define _TUPLE_PUB_H
#ifdef __cplusplus
extern "C"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 90605b8..b951838 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,6 +4,7 @@ add_subdirectory(timestamp)
add_subdirectory(tuple)
add_subdirectory(packet)
add_subdirectory(packet_io)
+add_subdirectory(thread_idx)
add_subdirectory(id_generator)
add_subdirectory(ip_reassembly)
add_subdirectory(tcp_reassembly)
diff --git a/src/duplicated_packet_filter/duplicated_packet_filter.h b/src/duplicated_packet_filter/duplicated_packet_filter.h
index acc13ed..a1cd794 100644
--- a/src/duplicated_packet_filter/duplicated_packet_filter.h
+++ b/src/duplicated_packet_filter/duplicated_packet_filter.h
@@ -9,7 +9,7 @@ extern "C"
// Duplicated Packet Filter for IPv4 Packet
#include "log.h"
-#include "packet.h"
+#include "packet_priv.h"
#define DUPLICATED_PACKET_FILTER_LOG_ERROR(format, ...) LOG_ERROR("duplicated packet filter", format, ##__VA_ARGS__)
diff --git a/src/duplicated_packet_filter/test/gtest_duplicated_packet_filter.cpp b/src/duplicated_packet_filter/test/gtest_duplicated_packet_filter.cpp
index 3ae9c0d..d1b982a 100644
--- a/src/duplicated_packet_filter/test/gtest_duplicated_packet_filter.cpp
+++ b/src/duplicated_packet_filter/test/gtest_duplicated_packet_filter.cpp
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "duplicated_packet_filter.h"
-#include "packet_private.h"
+#include "packet_priv.h"
/******************************************************************************
* [Protocols in frame: eth:ethertype:ip:ipv6:tcp]
diff --git a/src/evicted_session_filter/evicted_session_filter.h b/src/evicted_session_filter/evicted_session_filter.h
index 262b77d..9c9ce38 100644
--- a/src/evicted_session_filter/evicted_session_filter.h
+++ b/src/evicted_session_filter/evicted_session_filter.h
@@ -7,7 +7,7 @@ extern "C"
#endif
#include "log.h"
-#include "tuple.h"
+#include "stellar/tuple.h"
#define EVICTED_SESSION_FILTER_LOG_ERROR(format, ...) LOG_ERROR("evicted session filter", format, ##__VA_ARGS__)
diff --git a/src/id_generator/CMakeLists.txt b/src/id_generator/CMakeLists.txt
index 6005108..834204f 100644
--- a/src/id_generator/CMakeLists.txt
+++ b/src/id_generator/CMakeLists.txt
@@ -1,4 +1,4 @@
add_library(id_generator id_generator.cpp)
target_include_directories(id_generator PUBLIC ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(id_generator PUBLIC ${CMAKE_SOURCE_DIR}/src/stellar)
-target_link_libraries(id_generator log) \ No newline at end of file
+target_link_libraries(id_generator log thread_idx) \ No newline at end of file
diff --git a/src/id_generator/id_generator.cpp b/src/id_generator/id_generator.cpp
index a293f1c..6739fc3 100644
--- a/src/id_generator/id_generator.cpp
+++ b/src/id_generator/id_generator.cpp
@@ -1,8 +1,9 @@
#include <time.h>
#include <string.h>
+#include "macro.h"
+#include "thread_idx.h"
#include "id_generator.h"
-#include "stellar.h"
struct id_generator
{
diff --git a/src/ip_reassembly/ip_reassembly.cpp b/src/ip_reassembly/ip_reassembly.cpp
index 55cc682..86c4e2a 100644
--- a/src/ip_reassembly/ip_reassembly.cpp
+++ b/src/ip_reassembly/ip_reassembly.cpp
@@ -3,7 +3,7 @@
#include <sys/queue.h>
#include <assert.h>
-#include "packet_private.h"
+#include "packet_priv.h"
#include "crc32_hash.h"
#include "checksum.h"
#include "ipv4_utils.h"
diff --git a/src/ip_reassembly/ip_reassembly.h b/src/ip_reassembly/ip_reassembly.h
index 9d50f4a..f9a7059 100644
--- a/src/ip_reassembly/ip_reassembly.h
+++ b/src/ip_reassembly/ip_reassembly.h
@@ -6,7 +6,7 @@ extern "C"
{
#endif
-#include "packet.h"
+#include "packet_priv.h"
#include "log.h"
#define IP_REASSEMBLE_DEBUG(format, ...) LOG_DEBUG("ip_reassembly", format, ##__VA_ARGS__)
diff --git a/src/ip_reassembly/test/gtest_utils.h b/src/ip_reassembly/test/gtest_utils.h
index 0e652f2..fb26b90 100644
--- a/src/ip_reassembly/test/gtest_utils.h
+++ b/src/ip_reassembly/test/gtest_utils.h
@@ -13,7 +13,7 @@ extern "C"
#include "ipv4_utils.h"
#include "ipv6_utils.h"
#include "ip_reassembly.h"
-#include "packet_private.h"
+#include "packet_priv.h"
static inline void packet_set_ipv4_src_addr(struct packet *pkt, uint32_t saddr)
{
diff --git a/src/packet/packet.cpp b/src/packet/packet.cpp
index 2984073..e2e6e9e 100644
--- a/src/packet/packet.cpp
+++ b/src/packet/packet.cpp
@@ -11,7 +11,7 @@
#include <linux/ppp_defs.h>
#include "uthash.h"
-#include "packet_private.h"
+#include "packet_priv.h"
#include "udp_utils.h"
#include "tcp_utils.h"
#include "ipv4_utils.h"
diff --git a/src/packet/packet_private.h b/src/packet/packet_priv.h
index df475a9..c7cc5b4 100644
--- a/src/packet/packet_private.h
+++ b/src/packet/packet_priv.h
@@ -1,5 +1,5 @@
-#ifndef _PACKET_PRIVATE_H
-#define _PACKET_PRIVATE_H
+#ifndef _PACKET_PRIV_H
+#define _PACKET_PRIV_H
#ifdef __cplusplus
extern "C"
@@ -10,8 +10,8 @@ extern "C"
#include <stdio.h>
#include "log.h"
-#include "tuple.h"
-#include "packet.h"
+#include "stellar/tuple.h"
+#include "stellar/packet.h"
#define PACKET_MAX_LAYERS 32
#define PACKET_LOG_ERROR(format, ...) LOG_ERROR("packet", format, ##__VA_ARGS__)
diff --git a/src/packet/packet_utils.cpp b/src/packet/packet_utils.cpp
index 2653437..87e7119 100644
--- a/src/packet/packet_utils.cpp
+++ b/src/packet/packet_utils.cpp
@@ -2,7 +2,7 @@
#include <assert.h>
#include <string.h>
-#include "packet_private.h"
+#include "packet_priv.h"
#include "marsio.h"
/******************************************************************************
diff --git a/src/packet/test/gtest_packet.cpp b/src/packet/test/gtest_packet.cpp
index a434197..c779e5a 100644
--- a/src/packet/test/gtest_packet.cpp
+++ b/src/packet/test/gtest_packet.cpp
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <arpa/inet.h>
-#include "packet_private.h"
+#include "packet_priv.h"
/******************************************************************************
* Pcap file: 1-ETH_VLAN_VLAN_IP4_IP4_UDP.pcap
diff --git a/src/packet/test/gtest_packet_frag.cpp b/src/packet/test/gtest_packet_frag.cpp
index a5db752..a2e39cb 100644
--- a/src/packet/test/gtest_packet_frag.cpp
+++ b/src/packet/test/gtest_packet_frag.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "packet_private.h"
+#include "packet_priv.h"
/******************************************************************************
* [Protocols in frame: eth:ethertype:ip:data]
diff --git a/src/packet_io/dumpfile_io.cpp b/src/packet_io/dumpfile_io.cpp
index ce7863b..b9e4aa2 100644
--- a/src/packet_io/dumpfile_io.cpp
+++ b/src/packet_io/dumpfile_io.cpp
@@ -5,9 +5,9 @@
#include <stdlib.h>
#include <assert.h>
-#include "stellar.h"
+#include "macro.h"
+#include "packet_priv.h"
#include "file_scan.h"
-#include "packet_private.h"
#include "lock_free_queue.h"
#include "dumpfile_io.h"
diff --git a/src/packet_io/lock_free_queue.cpp b/src/packet_io/lock_free_queue.cpp
index 45c4687..0fd036a 100644
--- a/src/packet_io/lock_free_queue.cpp
+++ b/src/packet_io/lock_free_queue.cpp
@@ -1,8 +1,9 @@
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
+#include <stdint.h>
-#include "stellar.h"
+#include "macro.h"
#include "lock_free_queue.h"
struct lock_free_queue
diff --git a/src/packet_io/marsio_io.cpp b/src/packet_io/marsio_io.cpp
index f6a923b..0d4355d 100644
--- a/src/packet_io/marsio_io.cpp
+++ b/src/packet_io/marsio_io.cpp
@@ -4,9 +4,9 @@
#include <string.h>
#include <netinet/ether.h>
-#include "stellar.h"
+#include "macro.h"
#include "marsio.h"
-#include "packet_private.h"
+#include "packet_priv.h"
#include "marsio_io.h"
struct marsio_io
diff --git a/src/packet_io/packet_io.h b/src/packet_io/packet_io.h
index 44e4dc2..2faec8c 100644
--- a/src/packet_io/packet_io.h
+++ b/src/packet_io/packet_io.h
@@ -7,8 +7,8 @@ extern "C"
#endif
#include "log.h"
-#include "packet.h"
-#include "stellar.h"
+#include "macro.h"
+#include "packet_priv.h"
#define PACKET_IO_LOG_STATE(format, ...) LOG_STATE("packet_io", format, ##__VA_ARGS__)
#define PACKET_IO_LOG_ERROR(format, ...) LOG_ERROR("packet_io", format, ##__VA_ARGS__)
diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt
index 5b996a7..c58b553 100644
--- a/src/plugin/CMakeLists.txt
+++ b/src/plugin/CMakeLists.txt
@@ -1,3 +1,3 @@
add_library(plugin_manager plugin_manager.cpp)
target_include_directories(plugin_manager PUBLIC ${CMAKE_CURRENT_LIST_DIR})
-target_link_libraries(plugin_manager session_manager) \ No newline at end of file
+target_link_libraries(plugin_manager session_manager thread_idx) \ No newline at end of file
diff --git a/src/plugin/plugin_manager.cpp b/src/plugin/plugin_manager.cpp
index 8966260..baec9dd 100644
--- a/src/plugin/plugin_manager.cpp
+++ b/src/plugin/plugin_manager.cpp
@@ -1,6 +1,7 @@
#include <assert.h>
#include "plugin_manager.h"
-#include "session_private.h"
+#include "session_priv.h"
+#include "thread_idx.h"
struct plugin_manager
{
@@ -42,7 +43,7 @@ void plugin_manager_dispatch_session(struct plugin_manager *mgr, struct session
struct tcp_segment *seg;
enum session_state state = session_get_state(sess);
enum session_type type = session_get_type(sess);
- PLUGIN_MANAGER_LOG_DEBUG("=> plugin dispatch session: %u %s %s %s", session_get_id(sess), session_get_tuple_str(sess), session_type_to_str(type), session_state_to_str(state));
+ PLUGIN_MANAGER_LOG_DEBUG("=> thread [%d] plugin dispatch session: %u %s %s %s", stellar_get_current_thread_index(), session_get_id(sess), session_get_tuple_str(sess), session_type_to_str(type), session_state_to_str(state));
// session_print(sess);
if (packet_is_ctrl(pkt))
diff --git a/src/plugin/plugin_manager.h b/src/plugin/plugin_manager.h
index d8b73e7..18eb038 100644
--- a/src/plugin/plugin_manager.h
+++ b/src/plugin/plugin_manager.h
@@ -6,7 +6,7 @@ extern "C"
{
#endif
-#include "session.h"
+#include "session_priv.h"
#define PLUGIN_MANAGER_LOG_ERROR(format, ...) LOG_ERROR("plugin manager", format, ##__VA_ARGS__)
#define PLUGIN_MANAGER_LOG_DEBUG(format, ...) LOG_DEBUG("plugin manager", format, ##__VA_ARGS__)
diff --git a/src/session/session.cpp b/src/session/session.cpp
index 3c149c7..3daa356 100644
--- a/src/session/session.cpp
+++ b/src/session/session.cpp
@@ -1,6 +1,6 @@
#include <assert.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "tcp_utils.h"
#include "tcp_reassembly.h"
diff --git a/src/session/session_manager.cpp b/src/session/session_manager.cpp
index 3c354d1..0dc3bbf 100644
--- a/src/session/session_manager.cpp
+++ b/src/session/session_manager.cpp
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <assert.h>
-#include "stellar.h"
+#include "macro.h"
#include "tcp_utils.h"
#include "udp_utils.h"
#include "id_generator.h"
diff --git a/src/session/session_manager.h b/src/session/session_manager.h
index dbcf0c5..1c5901a 100644
--- a/src/session/session_manager.h
+++ b/src/session/session_manager.h
@@ -6,7 +6,7 @@ extern "C"
{
#endif
-#include "session_private.h"
+#include "session_priv.h"
#include "log.h"
#define SESSION_LOG_ERROR(format, ...) LOG_ERROR("session", format, ##__VA_ARGS__)
diff --git a/src/session/session_pool.h b/src/session/session_pool.h
index bce323a..3344dad 100644
--- a/src/session/session_pool.h
+++ b/src/session/session_pool.h
@@ -6,7 +6,7 @@ extern "C"
{
#endif
-#include "session_private.h"
+#include "session_priv.h"
struct session_pool;
struct session_pool *session_pool_new(uint64_t count);
diff --git a/src/session/session_private.h b/src/session/session_priv.h
index 88701f2..aecf699 100644
--- a/src/session/session_private.h
+++ b/src/session/session_priv.h
@@ -1,5 +1,5 @@
-#ifndef _SESSION_PRIVATE_H
-#define _SESSION_PRIVATE_H
+#ifndef _SESSION_PRIV_H
+#define _SESSION_PRIV_H
#ifdef __cplusplus
extern "C"
@@ -7,11 +7,11 @@ extern "C"
#endif
#include "list.h"
-#include "tuple.h"
-#include "packet_private.h"
+#include "packet_priv.h"
#include "timeout.h"
#include "uthash.h"
-#include "session.h"
+#include "stellar/tuple.h"
+#include "stellar/session.h"
#include "tcp_reassembly.h"
#include "session_manager.h"
diff --git a/src/session/session_table.h b/src/session/session_table.h
index 6ccf1d1..da10178 100644
--- a/src/session/session_table.h
+++ b/src/session/session_table.h
@@ -6,7 +6,7 @@ extern "C"
{
#endif
-#include "session_private.h"
+#include "session_priv.h"
struct session_table;
struct session_table *session_table_new();
diff --git a/src/session/session_timer.h b/src/session/session_timer.h
index 725b25b..87368e2 100644
--- a/src/session/session_timer.h
+++ b/src/session/session_timer.h
@@ -6,7 +6,7 @@ extern "C"
{
#endif
-#include "session_private.h"
+#include "session_priv.h"
struct session_timer;
struct session_timer *session_timer_new(uint64_t now);
diff --git a/src/session/session_transition.h b/src/session/session_transition.h
index 84e35d1..afb004e 100644
--- a/src/session/session_transition.h
+++ b/src/session/session_transition.h
@@ -7,7 +7,7 @@ extern "C"
#endif
#include "log.h"
-#include "session_private.h"
+#include "session_priv.h"
#define SESSION_TRANSITION_LOG_INFO(format, ...) LOG_INFO("session transition", format, ##__VA_ARGS__)
diff --git a/src/session/test/gtest_filter_tcp_dupkt.cpp b/src/session/test/gtest_filter_tcp_dupkt.cpp
index 888c812..06e2db2 100644
--- a/src/session/test/gtest_filter_tcp_dupkt.cpp
+++ b/src/session/test/gtest_filter_tcp_dupkt.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "ipv4_utils.h"
diff --git a/src/session/test/gtest_overload_evict_tcp_sess.cpp b/src/session/test/gtest_overload_evict_tcp_sess.cpp
index 585aca5..d9bf0ed 100644
--- a/src/session/test/gtest_overload_evict_tcp_sess.cpp
+++ b/src/session/test/gtest_overload_evict_tcp_sess.cpp
@@ -1,9 +1,9 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
-#include "stellar.h"
+#include "macro.h"
#include "ipv4_utils.h"
#include "test_packets.h"
diff --git a/src/session/test/gtest_overload_evict_udp_sess.cpp b/src/session/test/gtest_overload_evict_udp_sess.cpp
index 25f122d..8d6d03e 100644
--- a/src/session/test/gtest_overload_evict_udp_sess.cpp
+++ b/src/session/test/gtest_overload_evict_udp_sess.cpp
@@ -1,9 +1,9 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
-#include "stellar.h"
+#include "macro.h"
#include "ipv4_utils.h"
#include "test_packets.h"
diff --git a/src/session/test/gtest_sess_mgr_tcp_reassembly.cpp b/src/session/test/gtest_sess_mgr_tcp_reassembly.cpp
index 68e6b39..93c3efd 100644
--- a/src/session/test/gtest_sess_mgr_tcp_reassembly.cpp
+++ b/src/session/test/gtest_sess_mgr_tcp_reassembly.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "ipv4_utils.h"
diff --git a/src/session/test/gtest_session.cpp b/src/session/test/gtest_session.cpp
index 54b1d3d..72430b0 100644
--- a/src/session/test/gtest_session.cpp
+++ b/src/session/test/gtest_session.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#define SESSION_KEY_IPV4_TCP(name) \
struct tuple6 name; \
diff --git a/src/session/test/gtest_state_tcp_active_to_closing.cpp b/src/session/test/gtest_state_tcp_active_to_closing.cpp
index 1c0ed61..580942c 100644
--- a/src/session/test/gtest_state_tcp_active_to_closing.cpp
+++ b/src/session/test/gtest_state_tcp_active_to_closing.cpp
@@ -1,7 +1,7 @@
// TCP state machine test: active -> closing
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "tcp_utils.h"
diff --git a/src/session/test/gtest_state_tcp_init_to_opening.cpp b/src/session/test/gtest_state_tcp_init_to_opening.cpp
index 062a546..5da6d6d 100644
--- a/src/session/test/gtest_state_tcp_init_to_opening.cpp
+++ b/src/session/test/gtest_state_tcp_init_to_opening.cpp
@@ -1,7 +1,7 @@
// TCP state machine test: init -> opening
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "ipv4_utils.h"
diff --git a/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp b/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp
index 5c9aff4..4a99436 100644
--- a/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp
+++ b/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp
@@ -1,7 +1,7 @@
// TCP state machine test: init -> opening -> active -> closing -> closed
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "test_packets.h"
diff --git a/src/session/test/gtest_state_tcp_opening_to_active.cpp b/src/session/test/gtest_state_tcp_opening_to_active.cpp
index c3d0038..588c422 100644
--- a/src/session/test/gtest_state_tcp_opening_to_active.cpp
+++ b/src/session/test/gtest_state_tcp_opening_to_active.cpp
@@ -1,7 +1,7 @@
// TCP state machine test: opening -> active
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "test_packets.h"
diff --git a/src/session/test/gtest_state_tcp_opening_to_closing.cpp b/src/session/test/gtest_state_tcp_opening_to_closing.cpp
index 413a41d..15adfe6 100644
--- a/src/session/test/gtest_state_tcp_opening_to_closing.cpp
+++ b/src/session/test/gtest_state_tcp_opening_to_closing.cpp
@@ -1,7 +1,7 @@
// TCP state machine test: opening -> closing
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "tcp_utils.h"
diff --git a/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp b/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp
index 78e2b41..d97bd8a 100644
--- a/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp
+++ b/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp
@@ -1,7 +1,7 @@
// UDP state machine test: init -> opening -> active -> closing
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "test_packets.h"
diff --git a/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp b/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp
index e5b586b..f2661c2 100644
--- a/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp
+++ b/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp
@@ -1,7 +1,7 @@
// UDP state machine test: init -> opening -> closing
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "test_packets.h"
diff --git a/src/session/test/gtest_timeout_tcp_data.cpp b/src/session/test/gtest_timeout_tcp_data.cpp
index 4972570..322b5e4 100644
--- a/src/session/test/gtest_timeout_tcp_data.cpp
+++ b/src/session/test/gtest_timeout_tcp_data.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "test_packets.h"
diff --git a/src/session/test/gtest_timeout_tcp_handshake.cpp b/src/session/test/gtest_timeout_tcp_handshake.cpp
index 75fc92e..c704773 100644
--- a/src/session/test/gtest_timeout_tcp_handshake.cpp
+++ b/src/session/test/gtest_timeout_tcp_handshake.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "ipv4_utils.h"
diff --git a/src/session/test/gtest_timeout_tcp_init.cpp b/src/session/test/gtest_timeout_tcp_init.cpp
index 46c4285..1d685fb 100644
--- a/src/session/test/gtest_timeout_tcp_init.cpp
+++ b/src/session/test/gtest_timeout_tcp_init.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "ipv4_utils.h"
diff --git a/src/session/test/gtest_timeout_udp_data.cpp b/src/session/test/gtest_timeout_udp_data.cpp
index d043c4b..81c4115 100644
--- a/src/session/test/gtest_timeout_udp_data.cpp
+++ b/src/session/test/gtest_timeout_udp_data.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "session_private.h"
+#include "session_priv.h"
#include "session_manager.h"
#include "test_packets.h"
diff --git a/src/stellar/CMakeLists.txt b/src/stellar/CMakeLists.txt
index 26bb828..579a963 100644
--- a/src/stellar/CMakeLists.txt
+++ b/src/stellar/CMakeLists.txt
@@ -1,5 +1,5 @@
add_executable(stellar config.cpp stat.cpp stellar.cpp)
-target_link_libraries(stellar timestamp plugin_manager session_manager ip_reassembly packet_io)
+target_link_libraries(stellar timestamp plugin_manager session_manager ip_reassembly packet_io thread_idx)
target_link_libraries(stellar pthread fieldstat4 toml)
install(TARGETS stellar RUNTIME DESTINATION bin COMPONENT Program) \ No newline at end of file
diff --git a/src/stellar/stellar.h b/src/stellar/macro.h
index b135ce9..8b545b4 100644
--- a/src/stellar/stellar.h
+++ b/src/stellar/macro.h
@@ -1,15 +1,13 @@
-#ifndef _STELLAR_H
-#define _STELLAR_H
+#ifndef _MACRO_H
+#define _MACRO_H
#ifdef __cplusplus
extern "C"
{
#endif
-#include <stdint.h>
-
-#define MAX_THREAD_NUM 256
#define RX_BURST_MAX 32
+#define MAX_THREAD_NUM 256 // limit by id_generator
#define ATOMIC_INC(x) __atomic_fetch_add(x, 1, __ATOMIC_RELAXED)
#define ATOMIC_DEC(x) __atomic_fetch_sub(x, 1, __ATOMIC_RELAXED)
@@ -23,16 +21,11 @@ extern "C"
#define unlikely(expr) __builtin_expect((expr), 0)
#ifdef STELLAR_GIT_VERSION
-static __attribute__((__used__)) const char *__stellar_version = STELLAR_GIT_VERSION;
+ static __attribute__((__used__)) const char *__stellar_version = STELLAR_GIT_VERSION;
#else
-static __attribute__((__used__)) const char *__stellar_version = "Unknown";
+ static __attribute__((__used__)) const char *__stellar_version = "Unknown";
#endif
-static inline uint8_t stellar_get_current_thread_index()
-{
- return 0;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/src/stellar/stellar.cpp b/src/stellar/stellar.cpp
index 92481de..ff80945 100644
--- a/src/stellar/stellar.cpp
+++ b/src/stellar/stellar.cpp
@@ -10,11 +10,11 @@
#include "logo.h"
#include "stat.h"
-#include "stellar.h"
#include "config.h"
-#include "packet_private.h"
+#include "packet_priv.h"
#include "packet_io.h"
#include "timestamp.h"
+#include "thread_idx.h"
#include "id_generator.h"
#include "ip_reassembly.h"
#include "session_manager.h"
@@ -159,7 +159,6 @@ static void *work_thread(void *arg)
{
int nr_recv;
uint64_t now = 0;
- uint16_t thr_idx = 0;
char thd_name[16] = {0};
void *plugin_ctx = NULL;
struct packet *pkt = NULL;
@@ -170,7 +169,8 @@ static void *work_thread(void *arg)
struct stellar_thread *thread = (struct stellar_thread *)arg;
struct ip_reassembly *ip_reass = thread->ip_mgr;
struct session_manager *sess_mgr = thread->sess_mgr;
- thr_idx = thread->idx;
+ uint16_t thr_idx = thread->idx;
+ stellar_set_current_thread_index(thr_idx);
snprintf(thd_name, sizeof(thd_name), "stellar:%d", thr_idx);
prctl(PR_SET_NAME, (unsigned long long)thd_name, NULL, NULL, NULL);
diff --git a/src/thread_idx/CMakeLists.txt b/src/thread_idx/CMakeLists.txt
new file mode 100644
index 0000000..a79bac4
--- /dev/null
+++ b/src/thread_idx/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_library(thread_idx thread_idx.cpp)
+target_include_directories(thread_idx PUBLIC ${CMAKE_CURRENT_LIST_DIR})
+target_include_directories(thread_idx PUBLIC ${CMAKE_SOURCE_DIR}/include)
+target_link_libraries(thread_idx)
diff --git a/src/thread_idx/thread_idx.cpp b/src/thread_idx/thread_idx.cpp
new file mode 100644
index 0000000..7756e6b
--- /dev/null
+++ b/src/thread_idx/thread_idx.cpp
@@ -0,0 +1,13 @@
+#include "thread_idx.h"
+
+static thread_local uint8_t __thread_id = 0;
+
+uint8_t stellar_get_current_thread_index()
+{
+ return __thread_id;
+}
+
+void stellar_set_current_thread_index(uint8_t idx)
+{
+ __thread_id = idx;
+}
diff --git a/src/thread_idx/thread_idx.h b/src/thread_idx/thread_idx.h
new file mode 100644
index 0000000..ebc5c6e
--- /dev/null
+++ b/src/thread_idx/thread_idx.h
@@ -0,0 +1,17 @@
+#ifndef _THREAD_IDX_H
+#define _THREAD_IDX_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "stellar/stellar.h"
+
+void stellar_set_current_thread_index(uint8_t idx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/timestamp/CMakeLists.txt b/src/timestamp/CMakeLists.txt
index fc59074..691002f 100644
--- a/src/timestamp/CMakeLists.txt
+++ b/src/timestamp/CMakeLists.txt
@@ -1,5 +1,6 @@
add_library(timestamp timestamp.cpp)
target_include_directories(timestamp PUBLIC ${CMAKE_CURRENT_LIST_DIR})
+target_include_directories(timestamp PUBLIC ${CMAKE_SOURCE_DIR}/src/stellar)
target_link_libraries(timestamp)
add_subdirectory(test) \ No newline at end of file
diff --git a/src/timestamp/timestamp.cpp b/src/timestamp/timestamp.cpp
index 72bd37c..3e90e48 100644
--- a/src/timestamp/timestamp.cpp
+++ b/src/timestamp/timestamp.cpp
@@ -1,5 +1,6 @@
#include <time.h>
+#include "macro.h"
#include "timestamp.h"
// 1 s = 1000 ms
@@ -23,9 +24,6 @@ struct timestamp
uint64_t ts_in_sec;
} g_timestamp;
-#define ATOMIC_SET(x, y) __atomic_store_n(x, y, __ATOMIC_RELAXED)
-#define ATOMIC_READ(x) __atomic_load_n(x, __ATOMIC_RELAXED)
-
void timestamp_update()
{
/*
diff --git a/src/tuple/test/gtest_tuple.cpp b/src/tuple/test/gtest_tuple.cpp
index 278a17d..415a435 100644
--- a/src/tuple/test/gtest_tuple.cpp
+++ b/src/tuple/test/gtest_tuple.cpp
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
-#include "tuple.h"
+#include "stellar/tuple.h"
TEST(TUPLE, TUPLE2)
{
diff --git a/src/tuple/tuple.cpp b/src/tuple/tuple.cpp
index cbd8af2..661d35f 100644
--- a/src/tuple/tuple.cpp
+++ b/src/tuple/tuple.cpp
@@ -1,7 +1,7 @@
#include <string.h>
#include <stdio.h>
-#include "tuple.h"
+#include "stellar/tuple.h"
#include "crc32_hash.h"
uint32_t tuple2_hash(const struct tuple2 *tuple)