refactor: rename packet_utils.cpp to packet.cpp

This commit is contained in:
luwenpeng
2024-08-16 16:31:25 +08:00
parent c298fdf289
commit a2d68bb853
20 changed files with 81 additions and 115 deletions

View File

@@ -7,7 +7,6 @@
#include "checksum.h" #include "checksum.h"
#include "crc32_hash.h" #include "crc32_hash.h"
#include "packet_private.h" #include "packet_private.h"
#include "packet_utils.h"
#include "packet_parser.h" #include "packet_parser.h"
#include "packet_helper.h" #include "packet_helper.h"
#include "ip_reassembly.h" #include "ip_reassembly.h"

View File

@@ -11,7 +11,6 @@ extern "C"
#include "ip_reassembly.h" #include "ip_reassembly.h"
#include "packet_private.h" #include "packet_private.h"
#include "packet_dump.h" #include "packet_dump.h"
#include "packet_utils.h"
#include "packet_parser.h" #include "packet_parser.h"
#include "packet_layer.h" #include "packet_layer.h"

View File

@@ -1,9 +1,9 @@
add_library(packet add_library(packet
packet.cpp
packet_parser.cpp packet_parser.cpp
packet_builder.cpp packet_builder.cpp
packet_filter.cpp packet_filter.cpp
packet_dump.cpp packet_dump.cpp
packet_utils.cpp
packet_ldbc.cpp packet_ldbc.cpp
packet_layer.cpp packet_layer.cpp
packet_tunnel.cpp packet_tunnel.cpp

View File

@@ -4,14 +4,33 @@
#include "tuple.h" #include "tuple.h"
#include "packet_helper.h" #include "packet_helper.h"
#include "packet_private.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 * 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) void packet_set_sids(struct packet *pkt, const struct sids *sids)
{ {
pkt->meta.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) if (pkt->meta.sids.used + sids->used > MAX_SIDS)
{ {
PACKET_UTILS_LOG_ERROR("sids overflow"); PACKET_LOG_ERROR("sids overflow");
return; return;
} }
else else

View File

@@ -4,7 +4,6 @@
#include "checksum.h" #include "checksum.h"
#include "packet_private.h" #include "packet_private.h"
#include "packet_helper.h" #include "packet_helper.h"
#include "packet_utils.h"
#include "packet_layer.h" #include "packet_layer.h"
#include "packet_parser.h" #include "packet_parser.h"
#include "packet_builder.h" #include "packet_builder.h"

View File

@@ -10,7 +10,6 @@
#include "packet_private.h" #include "packet_private.h"
#include "packet_dump.h" #include "packet_dump.h"
#include "packet_parser.h" #include "packet_parser.h"
#include "packet_utils.h"
#define PACKET_DUMP_LOG_ERROR(format, ...) LOG_ERROR("packet dump", format, ##__VA_ARGS__) #define PACKET_DUMP_LOG_ERROR(format, ...) LOG_ERROR("packet dump", format, ##__VA_ARGS__)

View File

@@ -1,6 +1,5 @@
#include "packet_private.h" #include "packet_private.h"
#include "packet_layer.h" #include "packet_layer.h"
#include "packet_utils.h"
int packet_get_layer_count(const struct packet *pkt) int packet_get_layer_count(const struct packet *pkt)
{ {

View File

@@ -1,8 +1,7 @@
#include "tuple.h" #include "tuple.h"
#include "uthash.h" #include "uthash.h"
#include "packet_ldbc.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 packet_ldbc_hash(const struct packet *pkt, enum load_balance ldbc, enum packet_direction direction)
{ {
uint64_t temp = 0; uint64_t temp = 0;

View File

@@ -58,25 +58,65 @@ struct packet
struct metadata meta; struct metadata meta;
}; };
inline void packet_set_route_ctx(struct packet *pkt, const struct route_ctx *ctx) /******************************************************************************
{ * metadata utils
pkt->meta.route_ctx = *ctx; ******************************************************************************/
}
inline const struct route_ctx *packet_get_route_ctx(const struct packet *pkt) 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);
return &pkt->meta.route_ctx;
}
inline void packet_set_origin_ctx(struct packet *pkt, void *ctx) void packet_set_origin_ctx(struct packet *pkt, void *ctx);
{ const void *packet_get_origin_ctx(const struct packet *pkt);
pkt->meta.origin_ctx = ctx;
}
inline const void *packet_get_origin_ctx(const struct packet *pkt) void packet_set_sids(struct packet *pkt, const struct sids *sids);
{ const struct sids *packet_get_sids(const struct packet *pkt);
return pkt->meta.origin_ctx;
} 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 #ifdef __cplusplus
} }

View File

@@ -2,7 +2,6 @@
#include "stellar/tunnel.h" #include "stellar/tunnel.h"
#include "packet_private.h" #include "packet_private.h"
#include "packet_utils.h"
#include "packet_layer.h" #include "packet_layer.h"
struct tunnel_detector struct tunnel_detector

View File

@@ -1,78 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
#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

View File

@@ -8,7 +8,6 @@
#include "packet_layer.h" #include "packet_layer.h"
#include "packet_parser.h" #include "packet_parser.h"
#include "packet_builder.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_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__) #define PRINT_RED(fmt, ...) printf("\033[0;31m" fmt "\033[0m\n", ##__VA_ARGS__)

View File

@@ -1,7 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "packet_private.h" #include "packet_private.h"
#include "packet_utils.h"
#include "packet_parser.h" #include "packet_parser.h"
/****************************************************************************** /******************************************************************************

View File

@@ -4,7 +4,6 @@
#include "tuple.h" #include "tuple.h"
#include "packet_private.h" #include "packet_private.h"
#include "packet_parser.h" #include "packet_parser.h"
#include "packet_utils.h"
#include "packet_layer.h" #include "packet_layer.h"
#include "packet_dump.h" #include "packet_dump.h"

View File

@@ -15,7 +15,6 @@
#include "dumpfile_io.h" #include "dumpfile_io.h"
#include "packet_private.h" #include "packet_private.h"
#include "packet_ldbc.h" #include "packet_ldbc.h"
#include "packet_utils.h"
#include "packet_parser.h" #include "packet_parser.h"
#include "packet_dump.h" #include "packet_dump.h"
#include "lock_free_queue.h" #include "lock_free_queue.h"

View File

@@ -8,7 +8,6 @@
#include "marsio.h" #include "marsio.h"
#include "marsio_io.h" #include "marsio_io.h"
#include "packet_private.h" #include "packet_private.h"
#include "packet_utils.h"
#include "packet_parser.h" #include "packet_parser.h"
#define PACKET_IO_LOG_ERROR(format, ...) LOG_ERROR("marsio", format, ##__VA_ARGS__) #define PACKET_IO_LOG_ERROR(format, ...) LOG_ERROR("marsio", format, ##__VA_ARGS__)

View File

@@ -7,7 +7,7 @@
#include "stellar/stellar_core.h" #include "stellar/stellar_core.h"
#include "session/session_utils.h" #include "session/session_utils.h"
#include "tuple/tuple.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}; UT_icd plugin_specs_icd = {sizeof(struct plugin_specific), NULL, NULL, NULL};

View File

@@ -6,7 +6,6 @@
#include "utils.h" #include "utils.h"
#include "packet_helper.h" #include "packet_helper.h"
#include "packet_layer.h" #include "packet_layer.h"
#include "packet_utils.h"
#include "packet_filter.h" #include "packet_filter.h"
#include "snowflake.h" #include "snowflake.h"
#include "session_def.h" #include "session_def.h"

View File

@@ -13,7 +13,6 @@
#include "utils.h" #include "utils.h"
#include "packet_io.h" #include "packet_io.h"
#include "packet_private.h" #include "packet_private.h"
#include "packet_utils.h"
#include "session_utils.h" #include "session_utils.h"
#include "snowflake.h" #include "snowflake.h"
#include "stellar_stat.h" #include "stellar_stat.h"

View File

@@ -6,7 +6,6 @@
#include "packet_layer.h" #include "packet_layer.h"
#include "packet_parser.h" #include "packet_parser.h"
#include "packet_dump.h" #include "packet_dump.h"
#include "packet_utils.h"
#define MAX_BUFF_SIZE 2048 #define MAX_BUFF_SIZE 2048
#define PRINT_GREEN(fmt, ...) printf("\033[0;32m" fmt "\033[0m\n", ##__VA_ARGS__) #define PRINT_GREEN(fmt, ...) printf("\033[0;32m" fmt "\033[0m\n", ##__VA_ARGS__)