将kni合并到tfe中
This commit is contained in:
115
common/src/tfe_acceptor_kni.cpp
Normal file
115
common/src/tfe_acceptor_kni.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
#include <assert.h>
|
||||
#include <MESA/MESA_prof_load.h>
|
||||
|
||||
#include "tfe_cmsg.h"
|
||||
#include "tfe_tap_rss.h"
|
||||
#include "tfe_acceptor_kni.h"
|
||||
#include "tfe_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->cmsg)
|
||||
{
|
||||
tfe_cmsg_destroy(ctx->cmsg);
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
ctx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* acceptor_ctx
|
||||
******************************************************************************/
|
||||
struct acceptor_ctx *acceptor_ctx_create(const char *profile)
|
||||
{
|
||||
int ret = 0;
|
||||
struct acceptor_ctx *ctx = ALLOC(struct acceptor_ctx, 1);
|
||||
|
||||
MESA_load_profile_int_def(profile, "system", "firewall_sids", (int *)&(ctx->firewall_sids), 1001);
|
||||
MESA_load_profile_int_def(profile, "system", "service_chaining_sids", (int *)&(ctx->sce_sids), 1002);
|
||||
MESA_load_profile_int_def(profile, "system", "nr_worker_threads", (int *)&(ctx->nr_worker_threads), 8);
|
||||
MESA_load_profile_uint_range(profile, "system", "cpu_affinity_mask", TFE_THREAD_MAX, (unsigned int *)ctx->cpu_affinity_mask);
|
||||
ctx->nr_worker_threads = MIN(ctx->nr_worker_threads, TFE_THREAD_MAX);
|
||||
|
||||
CPU_ZERO(&ctx->coremask);
|
||||
for (int i = 0; i < ctx->nr_worker_threads; i++)
|
||||
{
|
||||
int cpu_id = ctx->cpu_affinity_mask[i];
|
||||
CPU_SET(cpu_id, &ctx->coremask);
|
||||
}
|
||||
|
||||
ctx->io = packet_io_create(profile, ctx->nr_worker_threads, &ctx->coremask);
|
||||
if (ctx->io == NULL)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
ctx->config = tfe_tap_config_create(profile, ctx->nr_worker_threads);
|
||||
if (ctx->config == NULL)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
ctx->metrics = global_metrics_create();
|
||||
if (ctx->metrics == NULL)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
// ctx->enforcer = policy_enforcer_create("KNI", 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:
|
||||
acceptor_ctx_destory(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void acceptor_ctx_destory(struct acceptor_ctx * ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
packet_io_destory(ctx->io);
|
||||
tfe_tap_destory(ctx->config);
|
||||
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user