#include #include #include "sce.h" #include "log.h" #include "global_metrics.h" /****************************************************************************** * 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", "enable_debug", (int *)&(ctx->enable_debug), 0); 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); MESA_load_profile_int_def(profile, "system", "enable_cpu_affinity", (int *)&ctx->enable_cpu_affinity, 0); MESA_load_profile_uint_range(profile, "system", "cpu_affinity_mask", MAX_THREAD_NUM, (unsigned int *)ctx->cpu_affinity_mask); ctx->nr_worker_threads = MIN(ctx->nr_worker_threads, MAX_THREAD_NUM); ctx->io = packet_io_create(profile, ctx->nr_worker_threads); if (ctx->io == NULL) { goto error_out; } ctx->metrics = global_metrics_create(profile); 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; } if (policy_enforcer_register(ctx->enforcer) == -1) { goto error_out; } 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; } }