summaryrefslogtreecommitdiff
path: root/platform/src/sce.cpp
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2023-11-23 16:52:06 +0800
committerluwenpeng <[email protected]>2023-11-24 11:37:24 +0800
commitbda50d79af1f7c59f5ab71fdefff06e3e3397be2 (patch)
tree8eec56e3276271a192c2f73c1e2831aa5c02e22f /platform/src/sce.cpp
parentcbac7fea291ded728a630227e196e17543f4646d (diff)
perf: 删除无效代码;修改变量命名;减少内存分配
Diffstat (limited to 'platform/src/sce.cpp')
-rw-r--r--platform/src/sce.cpp90
1 files changed, 20 insertions, 70 deletions
diff --git a/platform/src/sce.cpp b/platform/src/sce.cpp
index 9b870ef..26f7f92 100644
--- a/platform/src/sce.cpp
+++ b/platform/src/sce.cpp
@@ -9,14 +9,7 @@
* Struct Metadata
******************************************************************************/
-struct metadata *metadata_new()
-{
- struct metadata *meta = (struct metadata *)calloc(1, sizeof(struct metadata));
-
- return meta;
-}
-
-int metadata_is_empty(struct metadata *meta)
+int metadata_isempty(struct metadata *meta)
{
if (meta->write_ref == 0)
{
@@ -28,7 +21,7 @@ int metadata_is_empty(struct metadata *meta)
}
}
-void metadata_shallow_copy(struct metadata *dst, struct metadata *src)
+void metadata_copy(struct metadata *dst, struct metadata *src)
{
dst->write_ref++;
dst->session_id = src->session_id;
@@ -36,7 +29,7 @@ void metadata_shallow_copy(struct metadata *dst, struct metadata *src)
dst->raw_data = NULL;
dst->raw_len = 0;
dst->l7offset = src->l7offset;
- dst->is_e2i_dir = src->is_e2i_dir;
+ dst->direction = src->direction;
dst->is_ctrl_pkt = src->is_ctrl_pkt;
dst->is_decrypted = src->is_decrypted;
@@ -44,28 +37,16 @@ void metadata_shallow_copy(struct metadata *dst, struct metadata *src)
route_ctx_copy(&dst->route_ctx, &src->route_ctx);
}
-void metadata_deep_copy(struct metadata *dst, struct metadata *src)
+char *memdup(const char *src, int len)
{
- metadata_shallow_copy(dst, src);
-
- dst->raw_data = (char *)calloc(src->raw_len + 1, sizeof(char));
- memcpy(dst->raw_data, src->raw_data, src->raw_len);
- dst->raw_len = src->raw_len;
-}
-
-void metadata_free(struct metadata *meta)
-{
- if (meta)
+ if (src == NULL || len == 0)
{
- if (meta->raw_data)
- {
- free(meta->raw_data);
- meta->raw_data = NULL;
- }
-
- free(meta);
- meta = NULL;
+ return NULL;
}
+
+ char *dst = (char *)calloc(len + 1, sizeof(char));
+ memcpy(dst, src, len);
+ return dst;
}
/******************************************************************************
@@ -78,13 +59,6 @@ struct session_ctx *session_ctx_new()
assert(session_ctx != NULL);
mutable_array_init(&session_ctx->rule_ids);
-
- session_ctx->decrypted_meta_i2e = metadata_new();
- session_ctx->decrypted_meta_e2i = metadata_new();
- session_ctx->raw_meta_i2e = metadata_new();
- session_ctx->raw_meta_e2i = metadata_new();
- session_ctx->ctrl_meta = metadata_new();
-
return session_ctx;
}
@@ -98,46 +72,22 @@ void session_ctx_free(struct session_ctx *session_ctx)
session_ctx->session_addr = NULL;
}
- if (session_ctx->decrypted_meta_i2e)
- {
- metadata_free(session_ctx->decrypted_meta_i2e);
- session_ctx->decrypted_meta_i2e = NULL;
- }
-
- if (session_ctx->decrypted_meta_e2i)
- {
- metadata_free(session_ctx->decrypted_meta_e2i);
- session_ctx->decrypted_meta_e2i = NULL;
- }
-
- if (session_ctx->raw_meta_i2e)
- {
- metadata_free(session_ctx->raw_meta_i2e);
- session_ctx->raw_meta_i2e = NULL;
- }
-
- if (session_ctx->raw_meta_e2i)
- {
- metadata_free(session_ctx->raw_meta_e2i);
- session_ctx->raw_meta_e2i = NULL;
- }
-
- if (session_ctx->ctrl_meta)
+ if (session_ctx->ctrl_packet_header_data)
{
- metadata_free(session_ctx->ctrl_meta);
- session_ctx->ctrl_meta = NULL;
+ free(session_ctx->ctrl_packet_header_data);
+ session_ctx->ctrl_packet_header_data = NULL;
}
- if (session_ctx->chainings.chaining_raw)
+ if (session_ctx->chaining_raw)
{
- selected_chaining_destory(session_ctx->chainings.chaining_raw);
- session_ctx->chainings.chaining_raw = NULL;
+ selected_chaining_destory(session_ctx->chaining_raw);
+ session_ctx->chaining_raw = NULL;
}
- if (session_ctx->chainings.chaining_decrypted)
+ if (session_ctx->chaining_decrypted)
{
- selected_chaining_destory(session_ctx->chainings.chaining_decrypted);
- session_ctx->chainings.chaining_decrypted = NULL;
+ selected_chaining_destory(session_ctx->chaining_decrypted);
+ session_ctx->chaining_decrypted = NULL;
}
free(session_ctx);
@@ -175,7 +125,7 @@ struct sce_ctx *sce_ctx_create(const char *profile)
goto error_out;
}
- sce_ctx->enforcer = policy_enforcer_create("SCE", profile, sce_ctx->nr_worker_threads, NULL);
+ sce_ctx->enforcer = policy_enforcer_create("SCE", profile, sce_ctx->nr_worker_threads);
if (sce_ctx->enforcer == NULL)
{
goto error_out;