2023-02-10 14:22:40 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <MESA/MESA_prof_load.h>
|
|
|
|
|
|
|
|
|
|
#include "sce.h"
|
|
|
|
|
#include "log.h"
|
2023-02-21 09:58:31 +08:00
|
|
|
#include "global_metrics.h"
|
2023-02-10 14:22:40 +08:00
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
* session_ctx
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
struct session_ctx *session_ctx_new()
|
|
|
|
|
{
|
|
|
|
|
struct session_ctx *ctx = (struct session_ctx *)calloc(1, sizeof(struct session_ctx));
|
|
|
|
|
assert(ctx != NULL);
|
|
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void session_ctx_free(struct session_ctx *ctx)
|
|
|
|
|
{
|
|
|
|
|
if (ctx)
|
|
|
|
|
{
|
|
|
|
|
if (ctx->first_ctrl_pkt.addr_string)
|
|
|
|
|
{
|
|
|
|
|
free(ctx->first_ctrl_pkt.addr_string);
|
|
|
|
|
ctx->first_ctrl_pkt.addr_string = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ctx->first_ctrl_pkt.header_data)
|
|
|
|
|
{
|
|
|
|
|
free(ctx->first_ctrl_pkt.header_data);
|
|
|
|
|
ctx->first_ctrl_pkt.header_data = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ctx->chaining)
|
|
|
|
|
{
|
|
|
|
|
selected_chaining_destory(ctx->chaining);
|
|
|
|
|
ctx->chaining = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(ctx);
|
|
|
|
|
ctx = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
* sce_ctx
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
struct sce_ctx *sce_ctx_create(const char *profile)
|
|
|
|
|
{
|
|
|
|
|
struct sce_ctx *ctx = (struct sce_ctx *)calloc(1, sizeof(struct sce_ctx));
|
|
|
|
|
|
|
|
|
|
MESA_load_profile_int_def(profile, "system", "firewall_sids", (int *)&(ctx->firewall_sids), 1001);
|
|
|
|
|
MESA_load_profile_int_def(profile, "system", "nr_worker_threads", (int *)&(ctx->nr_worker_threads), 8);
|
|
|
|
|
ctx->nr_worker_threads = MIN(ctx->nr_worker_threads, (int)(sizeof(ctx->work_threads) / sizeof(ctx->work_threads[0])));
|
|
|
|
|
|
|
|
|
|
ctx->io = packet_io_create(profile, ctx->nr_worker_threads);
|
|
|
|
|
if (ctx->io == NULL)
|
|
|
|
|
{
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 09:58:31 +08:00
|
|
|
ctx->metrics = global_metrics_create(profile);
|
2023-02-10 14:22:40 +08:00
|
|
|
if (ctx->metrics == NULL)
|
|
|
|
|
{
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx->enforcer = policy_enforcer_create("SCE", profile, ctx->nr_worker_threads, NULL);
|
|
|
|
|
if (ctx->enforcer == NULL)
|
|
|
|
|
{
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 09:58:31 +08:00
|
|
|
if (policy_enforcer_register(ctx->enforcer) == -1)
|
|
|
|
|
{
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 14:22:40 +08:00
|
|
|
return ctx;
|
|
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
|
sce_ctx_destory(ctx);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sce_ctx_destory(struct sce_ctx *ctx)
|
|
|
|
|
{
|
|
|
|
|
if (ctx)
|
|
|
|
|
{
|
|
|
|
|
policy_enforcer_destory(ctx->enforcer);
|
|
|
|
|
global_metrics_destory(ctx->metrics);
|
|
|
|
|
packet_io_destory(ctx->io);
|
|
|
|
|
|
|
|
|
|
free(ctx);
|
|
|
|
|
ctx = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|