diff --git a/src/ip_reassembly/ip_reassembly.cpp b/src/ip_reassembly/ip_reassembly.cpp index d9275d9..24d1b63 100644 --- a/src/ip_reassembly/ip_reassembly.cpp +++ b/src/ip_reassembly/ip_reassembly.cpp @@ -7,7 +7,6 @@ #include "checksum.h" #include "crc32_hash.h" #include "packet_private.h" -#include "packet_utils.h" #include "packet_parser.h" #include "packet_helper.h" #include "ip_reassembly.h" diff --git a/src/ip_reassembly/test/gtest_utils.h b/src/ip_reassembly/test/gtest_utils.h index c426168..a7177d0 100644 --- a/src/ip_reassembly/test/gtest_utils.h +++ b/src/ip_reassembly/test/gtest_utils.h @@ -11,7 +11,6 @@ extern "C" #include "ip_reassembly.h" #include "packet_private.h" #include "packet_dump.h" -#include "packet_utils.h" #include "packet_parser.h" #include "packet_layer.h" diff --git a/src/packet/CMakeLists.txt b/src/packet/CMakeLists.txt index 4368964..ce1d71f 100644 --- a/src/packet/CMakeLists.txt +++ b/src/packet/CMakeLists.txt @@ -1,9 +1,9 @@ add_library(packet + packet.cpp packet_parser.cpp packet_builder.cpp packet_filter.cpp packet_dump.cpp - packet_utils.cpp packet_ldbc.cpp packet_layer.cpp packet_tunnel.cpp diff --git a/src/packet/packet_utils.cpp b/src/packet/packet.cpp similarity index 96% rename from src/packet/packet_utils.cpp rename to src/packet/packet.cpp index d9f8107..75583be 100644 --- a/src/packet/packet_utils.cpp +++ b/src/packet/packet.cpp @@ -4,14 +4,33 @@ #include "tuple.h" #include "packet_helper.h" #include "packet_private.h" -#include "packet_utils.h" -#define PACKET_UTILS_LOG_ERROR(format, ...) LOG_ERROR("packet utils", format, ##__VA_ARGS__) +#define PACKET_LOG_ERROR(format, ...) LOG_ERROR("packet", format, ##__VA_ARGS__) /****************************************************************************** * metadata utils ******************************************************************************/ +void packet_set_route_ctx(struct packet *pkt, const struct route_ctx *ctx) +{ + pkt->meta.route_ctx = *ctx; +} + +const struct route_ctx *packet_get_route_ctx(const struct packet *pkt) +{ + return &pkt->meta.route_ctx; +} + +void packet_set_origin_ctx(struct packet *pkt, void *ctx) +{ + pkt->meta.origin_ctx = ctx; +} + +const void *packet_get_origin_ctx(const struct packet *pkt) +{ + return pkt->meta.origin_ctx; +} + void packet_set_sids(struct packet *pkt, const struct sids *sids) { pkt->meta.sids = *sids; @@ -26,7 +45,7 @@ void packet_prepend_sids(struct packet *pkt, const struct sids *sids) { if (pkt->meta.sids.used + sids->used > MAX_SIDS) { - PACKET_UTILS_LOG_ERROR("sids overflow"); + PACKET_LOG_ERROR("sids overflow"); return; } else diff --git a/src/packet/packet_builder.cpp b/src/packet/packet_builder.cpp index ad10192..27be1ef 100644 --- a/src/packet/packet_builder.cpp +++ b/src/packet/packet_builder.cpp @@ -4,7 +4,6 @@ #include "checksum.h" #include "packet_private.h" #include "packet_helper.h" -#include "packet_utils.h" #include "packet_layer.h" #include "packet_parser.h" #include "packet_builder.h" diff --git a/src/packet/packet_dump.cpp b/src/packet/packet_dump.cpp index be3ca67..7abacd1 100644 --- a/src/packet/packet_dump.cpp +++ b/src/packet/packet_dump.cpp @@ -10,7 +10,6 @@ #include "packet_private.h" #include "packet_dump.h" #include "packet_parser.h" -#include "packet_utils.h" #define PACKET_DUMP_LOG_ERROR(format, ...) LOG_ERROR("packet dump", format, ##__VA_ARGS__) diff --git a/src/packet/packet_layer.cpp b/src/packet/packet_layer.cpp index d3b29f9..ac7a267 100644 --- a/src/packet/packet_layer.cpp +++ b/src/packet/packet_layer.cpp @@ -1,6 +1,5 @@ #include "packet_private.h" #include "packet_layer.h" -#include "packet_utils.h" int packet_get_layer_count(const struct packet *pkt) { diff --git a/src/packet/packet_ldbc.cpp b/src/packet/packet_ldbc.cpp index 0597a23..1e84953 100644 --- a/src/packet/packet_ldbc.cpp +++ b/src/packet/packet_ldbc.cpp @@ -1,8 +1,7 @@ #include "tuple.h" #include "uthash.h" #include "packet_ldbc.h" -#include "packet_utils.h" - +#include "packet_private.h" uint64_t packet_ldbc_hash(const struct packet *pkt, enum load_balance ldbc, enum packet_direction direction) { uint64_t temp = 0; diff --git a/src/packet/packet_private.h b/src/packet/packet_private.h index 774b67d..6cbf2c7 100644 --- a/src/packet/packet_private.h +++ b/src/packet/packet_private.h @@ -58,25 +58,65 @@ struct packet struct metadata meta; }; -inline void packet_set_route_ctx(struct packet *pkt, const struct route_ctx *ctx) -{ - pkt->meta.route_ctx = *ctx; -} +/****************************************************************************** + * metadata utils + ******************************************************************************/ -inline const struct route_ctx *packet_get_route_ctx(const struct packet *pkt) -{ - return &pkt->meta.route_ctx; -} +void packet_set_route_ctx(struct packet *pkt, const struct route_ctx *ctx); +const struct route_ctx *packet_get_route_ctx(const struct packet *pkt); -inline void packet_set_origin_ctx(struct packet *pkt, void *ctx) -{ - pkt->meta.origin_ctx = ctx; -} +void packet_set_origin_ctx(struct packet *pkt, void *ctx); +const void *packet_get_origin_ctx(const struct packet *pkt); -inline const void *packet_get_origin_ctx(const struct packet *pkt) -{ - return pkt->meta.origin_ctx; -} +void packet_set_sids(struct packet *pkt, const struct sids *sids); +const struct sids *packet_get_sids(const struct packet *pkt); + +void packet_set_session_id(struct packet *pkt, uint64_t id); +uint64_t packet_get_session_id(const struct packet *pkt); + +void packet_set_domain(struct packet *pkt, uint64_t domain); +uint64_t packet_get_domain(const struct packet *pkt); + +void packet_set_link_id(struct packet *pkt, uint16_t id); +uint16_t packet_get_link_id(const struct packet *pkt); + +void packet_set_ctrl(struct packet *pkt, uint8_t ctrl); +uint8_t packet_is_ctrl(const struct packet *pkt); + +void packet_set_direction(struct packet *pkt, enum packet_direction dir); + +void *packet_get_user_data(struct packet *pkt); +void packet_set_user_data(struct packet *pkt, void *data); + +/****************************************************************************** + * tuple uitls + ******************************************************************************/ + +// return 0: found +// return -1: not found +int packet_get_innermost_tuple2(const struct packet *pkt, struct tuple2 *tuple); +int packet_get_outermost_tuple2(const struct packet *pkt, struct tuple2 *tuple); + +// return 0: found +// return -1: not found +int packet_get_innermost_tuple4(const struct packet *pkt, struct tuple4 *tuple); +int packet_get_outermost_tuple4(const struct packet *pkt, struct tuple4 *tuple); + +// return 0: found +// return -1: not found +int packet_get_innermost_tuple6(const struct packet *pkt, struct tuple6 *tuple); +int packet_get_outermost_tuple6(const struct packet *pkt, struct tuple6 *tuple); + +/****************************************************************************** + * other uitls + ******************************************************************************/ + +struct packet *packet_new(uint16_t pkt_len); +struct packet *packet_dup(const struct packet *pkt); +void packet_free(struct packet *pkt); + +int packet_is_fragment(const struct packet *pkt); +void layer_convert(const struct raw_layer *in, struct layer *out); #ifdef __cplusplus } diff --git a/src/packet/packet_tunnel.cpp b/src/packet/packet_tunnel.cpp index 392ad46..c6edc21 100644 --- a/src/packet/packet_tunnel.cpp +++ b/src/packet/packet_tunnel.cpp @@ -2,7 +2,6 @@ #include "stellar/tunnel.h" #include "packet_private.h" -#include "packet_utils.h" #include "packet_layer.h" struct tunnel_detector diff --git a/src/packet/packet_utils.h b/src/packet/packet_utils.h deleted file mode 100644 index aa9315d..0000000 --- a/src/packet/packet_utils.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include -#include "stellar/packet.h" - -/****************************************************************************** - * metadata utils - ******************************************************************************/ - -void packet_set_sids(struct packet *pkt, const struct sids *sids); -const struct sids *packet_get_sids(const struct packet *pkt); -void packet_prepend_sids(struct packet *pkt, const struct sids *sids); - -void packet_set_session_id(struct packet *pkt, uint64_t id); -uint64_t packet_get_session_id(const struct packet *pkt); - -void packet_set_domain(struct packet *pkt, uint64_t domain); -uint64_t packet_get_domain(const struct packet *pkt); - -void packet_set_link_id(struct packet *pkt, uint16_t id); -uint16_t packet_get_link_id(const struct packet *pkt); - -void packet_set_ctrl(struct packet *pkt, uint8_t ctrl); -uint8_t packet_is_ctrl(const struct packet *pkt); - -void packet_set_direction(struct packet *pkt, enum packet_direction dir); -enum packet_direction packet_get_direction(const struct packet *pkt); - -void packet_set_action(struct packet *pkt, enum packet_action action); -enum packet_action packet_get_action(const struct packet *pkt); - -void *packet_get_user_data(struct packet *pkt); -void packet_set_user_data(struct packet *pkt, void *data); - -/****************************************************************************** - * tuple uitls - ******************************************************************************/ - -// return 0: found -// return -1: not found -int packet_get_innermost_tuple2(const struct packet *pkt, struct tuple2 *tuple); -int packet_get_outermost_tuple2(const struct packet *pkt, struct tuple2 *tuple); - -// return 0: found -// return -1: not found -int packet_get_innermost_tuple4(const struct packet *pkt, struct tuple4 *tuple); -int packet_get_outermost_tuple4(const struct packet *pkt, struct tuple4 *tuple); - -// return 0: found -// return -1: not found -int packet_get_innermost_tuple6(const struct packet *pkt, struct tuple6 *tuple); -int packet_get_outermost_tuple6(const struct packet *pkt, struct tuple6 *tuple); - -/****************************************************************************** - * other uitls - ******************************************************************************/ - -const char *packet_get_raw_data(const struct packet *pkt); -uint16_t packet_get_raw_len(const struct packet *pkt); - -const char *packet_get_payload(const struct packet *pkt); -uint16_t packet_get_payload_len(const struct packet *pkt); - -struct packet *packet_new(uint16_t pkt_len); -struct packet *packet_dup(const struct packet *pkt); -void packet_free(struct packet *pkt); - -int packet_is_fragment(const struct packet *pkt); -void layer_convert(const struct raw_layer *in, struct layer *out); - -#ifdef __cplusplus -} -#endif diff --git a/src/packet/test/gtest_packet_builder.cpp b/src/packet/test/gtest_packet_builder.cpp index 8e4f021..223f586 100644 --- a/src/packet/test/gtest_packet_builder.cpp +++ b/src/packet/test/gtest_packet_builder.cpp @@ -8,7 +8,6 @@ #include "packet_layer.h" #include "packet_parser.h" #include "packet_builder.h" -#include "packet_utils.h" #define PRINT_GREEN(fmt, ...) printf("\033[0;32m" fmt "\033[0m\n", ##__VA_ARGS__) #define PRINT_RED(fmt, ...) printf("\033[0;31m" fmt "\033[0m\n", ##__VA_ARGS__) diff --git a/src/packet/test/gtest_packet_frag.cpp b/src/packet/test/gtest_packet_frag.cpp index 8c3c7b1..222925b 100644 --- a/src/packet/test/gtest_packet_frag.cpp +++ b/src/packet/test/gtest_packet_frag.cpp @@ -1,7 +1,6 @@ #include #include "packet_private.h" -#include "packet_utils.h" #include "packet_parser.h" /****************************************************************************** diff --git a/src/packet/test/gtest_packet_parser.cpp b/src/packet/test/gtest_packet_parser.cpp index 80dd270..2bd3bb2 100644 --- a/src/packet/test/gtest_packet_parser.cpp +++ b/src/packet/test/gtest_packet_parser.cpp @@ -4,7 +4,6 @@ #include "tuple.h" #include "packet_private.h" #include "packet_parser.h" -#include "packet_utils.h" #include "packet_layer.h" #include "packet_dump.h" diff --git a/src/packet_io/dumpfile_io.cpp b/src/packet_io/dumpfile_io.cpp index 8189000..36d8925 100644 --- a/src/packet_io/dumpfile_io.cpp +++ b/src/packet_io/dumpfile_io.cpp @@ -15,7 +15,6 @@ #include "dumpfile_io.h" #include "packet_private.h" #include "packet_ldbc.h" -#include "packet_utils.h" #include "packet_parser.h" #include "packet_dump.h" #include "lock_free_queue.h" diff --git a/src/packet_io/marsio_io.cpp b/src/packet_io/marsio_io.cpp index 43a4284..9d21f5a 100644 --- a/src/packet_io/marsio_io.cpp +++ b/src/packet_io/marsio_io.cpp @@ -8,7 +8,6 @@ #include "marsio.h" #include "marsio_io.h" #include "packet_private.h" -#include "packet_utils.h" #include "packet_parser.h" #define PACKET_IO_LOG_ERROR(format, ...) LOG_ERROR("marsio", format, ##__VA_ARGS__) diff --git a/src/plugin/plugin_manager.cpp b/src/plugin/plugin_manager.cpp index 85728b0..c1dd859 100644 --- a/src/plugin/plugin_manager.cpp +++ b/src/plugin/plugin_manager.cpp @@ -7,7 +7,7 @@ #include "stellar/stellar_core.h" #include "session/session_utils.h" #include "tuple/tuple.h" -#include "packet/packet_utils.h" +#include "packet/packet_private.h" UT_icd plugin_specs_icd = {sizeof(struct plugin_specific), NULL, NULL, NULL}; diff --git a/src/session/session_manager.cpp b/src/session/session_manager.cpp index 70c9202..e56d113 100644 --- a/src/session/session_manager.cpp +++ b/src/session/session_manager.cpp @@ -6,7 +6,6 @@ #include "utils.h" #include "packet_helper.h" #include "packet_layer.h" -#include "packet_utils.h" #include "packet_filter.h" #include "snowflake.h" #include "session_def.h" diff --git a/src/stellar/stellar_core.cpp b/src/stellar/stellar_core.cpp index d1d5d9a..99c2c54 100644 --- a/src/stellar/stellar_core.cpp +++ b/src/stellar/stellar_core.cpp @@ -13,7 +13,6 @@ #include "utils.h" #include "packet_io.h" #include "packet_private.h" -#include "packet_utils.h" #include "session_utils.h" #include "snowflake.h" #include "stellar_stat.h" diff --git a/test/packet_tool/packet_tool.cpp b/test/packet_tool/packet_tool.cpp index 420cd45..c6b5982 100644 --- a/test/packet_tool/packet_tool.cpp +++ b/test/packet_tool/packet_tool.cpp @@ -6,7 +6,6 @@ #include "packet_layer.h" #include "packet_parser.h" #include "packet_dump.h" -#include "packet_utils.h" #define MAX_BUFF_SIZE 2048 #define PRINT_GREEN(fmt, ...) printf("\033[0;32m" fmt "\033[0m\n", ##__VA_ARGS__)