diff --git a/include/stellar/packet.h b/include/stellar/packet.h index f3e5713..a540046 100644 --- a/include/stellar/packet.h +++ b/include/stellar/packet.h @@ -47,6 +47,10 @@ struct packet *craft_tcp_packet(const struct packet *origin_pkt, uint32_t tcp_se struct packet *craft_udp_packet(const struct packet *origin_pkt, const char *udp_payload, uint16_t udp_payload_len); struct packet *craft_packet_from_scratch(const struct layer larers[], uint16_t layer_count, const char *payload, uint16_t payload_len); +struct tcp_segment; +const char *tcp_segment_get_data(const struct tcp_segment *seg); +uint16_t tcp_segment_get_len(const struct tcp_segment *seg); + #ifdef __cplusplus } #endif diff --git a/include/stellar/session.h b/include/stellar/session.h index 3a74029..5a2567a 100644 --- a/include/stellar/session.h +++ b/include/stellar/session.h @@ -132,7 +132,6 @@ enum session_type session_get_type(const struct session *sess); enum session_state session_get_current_state(const struct session *sess); const struct packet *session_get0_current_packet(const struct session *sess); -const char *session_get0_current_payload(const struct session *sess, uint16_t *payload_len); enum closing_reason session_get_closing_reason(const struct session *sess); enum session_direction session_get_direction(const struct session *sess); diff --git a/src/packet_io/dumpfile_io.cpp b/src/packet_io/dumpfile_io.cpp index a9fc238..4525bf5 100644 --- a/src/packet_io/dumpfile_io.cpp +++ b/src/packet_io/dumpfile_io.cpp @@ -205,7 +205,7 @@ static void *dumpfile_thread(void *arg) ATOMIC_SET(&handle->io_thread_wait_exit, 1); } - PACKET_IO_LOG_STATE("dumpfile io thread waiting"); + PACKET_IO_LOG_STATE("dumpfile io thread waiting exit"); sleep(1); } diff --git a/src/session/session_utils.cpp b/src/session/session_utils.cpp index 2cbde33..22b970c 100644 --- a/src/session/session_utils.cpp +++ b/src/session/session_utils.cpp @@ -195,18 +195,6 @@ const struct packet *session_get0_current_packet(const struct session *sess) return sess->curr_pkt; } -const char *session_get0_current_payload(const struct session *sess, uint16_t *payload_len) -{ - const struct packet *pkt = session_get0_current_packet(sess); - if (pkt) - { - *payload_len = packet_get_payload_len(pkt); - return packet_get_payload(pkt); - } - *payload_len = 0; - return NULL; -} - int session_is_symmetric(const struct session *sess, unsigned char *flag) { int is_symmetric = 0; diff --git a/src/session/session_utils.h b/src/session/session_utils.h index 65143b9..d566a48 100644 --- a/src/session/session_utils.h +++ b/src/session/session_utils.h @@ -78,7 +78,6 @@ const struct packet *session_get_first_packet(const struct session *sess, enum f // session current packet void session_set_current_packet(struct session *sess, const struct packet *pkt); const struct packet *session_get0_current_packet(const struct session *sess); -const char *session_get0_current_payload(const struct session *sess, uint16_t *payload_len); // session symmetric int session_is_symmetric(const struct session *sess, unsigned char *flag); diff --git a/src/stellar/version.map b/src/stellar/version.map index ddb1b3d..3c3daf8 100644 --- a/src/stellar/version.map +++ b/src/stellar/version.map @@ -18,6 +18,9 @@ global: craft_udp_packet; craft_packet_from_scratch; + tcp_segment_get_data; + tcp_segment_get_len; + session_exdata_free; stellar_session_exdata_new_index; session_exdata_set; @@ -37,7 +40,6 @@ global: session_get_type; session_get_current_state; session_get0_current_packet; - session_get0_current_payload; session_get_closing_reason; session_get_direction; session_get_current_flow_direction; diff --git a/src/tcp_reassembly/tcp_reassembly.cpp b/src/tcp_reassembly/tcp_reassembly.cpp index 0cf3b3a..09de07c 100644 --- a/src/tcp_reassembly/tcp_reassembly.cpp +++ b/src/tcp_reassembly/tcp_reassembly.cpp @@ -251,4 +251,28 @@ uint32_t tcp_reassembly_get_recv_next(struct tcp_reassembly *assembler) } return assembler->recv_next; +} + +const char *tcp_segment_get_data(const struct tcp_segment *seg) +{ + if (seg == NULL) + { + return NULL; + } + else + { + return (const char *)seg->data; + } +} + +uint16_t tcp_segment_get_len(const struct tcp_segment *seg) +{ + if (seg == NULL) + { + return 0; + } + else + { + return seg->len; + } } \ No newline at end of file diff --git a/src/tcp_reassembly/tcp_reassembly.h b/src/tcp_reassembly/tcp_reassembly.h index 65a7a35..55d09a0 100644 --- a/src/tcp_reassembly/tcp_reassembly.h +++ b/src/tcp_reassembly/tcp_reassembly.h @@ -33,6 +33,9 @@ void tcp_reassembly_inc_recv_next(struct tcp_reassembly *assembler, uint32_t off void tcp_reassembly_set_recv_next(struct tcp_reassembly *assembler, uint32_t seq); uint32_t tcp_reassembly_get_recv_next(struct tcp_reassembly *assembler); +const char *tcp_segment_get_data(const struct tcp_segment *seg); +uint16_t tcp_segment_get_len(const struct tcp_segment *seg); + /* * The next routines deal with comparing 32 bit unsigned ints * and worry about wraparound (automatic with unsigned arithmetic). diff --git a/test/debug_plugin/debug_plugin.cpp b/test/debug_plugin/debug_plugin.cpp index f055191..fb9a081 100644 --- a/test/debug_plugin/debug_plugin.cpp +++ b/test/debug_plugin/debug_plugin.cpp @@ -9,13 +9,11 @@ #include #include -#include "log.h" #include "hexdump.h" #include "session_utils.h" -#include "tcp_reassembly.h" #include "packet_dump.h" #include "packet_parse.h" -#include "packet_utils.h" +#include "stellar/packet.h" #include "stellar/session_mq.h" // NOTE: packet hexdump or tcp segment hexdump may be too long, so we need direct output to fd, instead of using log_print @@ -131,15 +129,17 @@ static void on_sess_tcp_stream_msg(struct session *sess, int topic_id, const voi char buff[4096]; struct tcp_segment *seg = (struct tcp_segment *)msg; struct plugin_ctx *ctx = (struct plugin_ctx *)plugin_ctx; + const char *data = tcp_segment_get_data(seg); + uint16_t len = tcp_segment_get_len(seg); memset(buff, 0, sizeof(buff)); session_to_str(sess, 1, buff, sizeof(buff) - 1); log_print(ctx->fd, "debug plugin", "on TCP stream msg: %s", buff); - log_print(ctx->fd, "debug plugin", "rx TCP segment: len: %d, data: %p\n", seg->len, seg->data); + log_print(ctx->fd, "debug plugin", "rx TCP segment: len: %d, data: %p\n", len, data); pthread_spin_lock(&ctx->lock); - hexdump_to_fd(ctx->fd, (const char *)seg->data, seg->len); + hexdump_to_fd(ctx->fd, data, len); pthread_spin_unlock(&ctx->lock); }