2024-09-14 15:20:59 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
2024-09-13 18:03:05 +08:00
|
|
|
#include "utils.h"
|
|
|
|
|
#include "stellar/mq.h"
|
|
|
|
|
#include "packet_private.h"
|
|
|
|
|
#include "packet_manager_private.h"
|
|
|
|
|
|
|
|
|
|
#define PACKET_MANAGER_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "packet manager", format, ##__VA_ARGS__)
|
2024-09-14 15:20:59 +08:00
|
|
|
#define PACKET_MANAGER_LOG_DEBUG(format, ...) STELLAR_LOG_DEBUG(__thread_local_logger, "packet manager", format, ##__VA_ARGS__)
|
2024-09-13 18:03:05 +08:00
|
|
|
#define PACKET_MANAGER_LOG_INFO(format, ...) STELLAR_LOG_WARN(__thread_local_logger, "packet manager", format, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
TAILQ_HEAD(packet_queue, packet);
|
|
|
|
|
|
|
|
|
|
struct packet_manager_config
|
|
|
|
|
{
|
|
|
|
|
uint16_t nr_worker_thread;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct packet_manager_schema
|
|
|
|
|
{
|
|
|
|
|
struct mq_schema *mq;
|
|
|
|
|
int topic_id[PACKET_STAGE_MAX];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct packet_manager_runtime
|
|
|
|
|
{
|
2024-09-14 18:38:37 +08:00
|
|
|
void *cb_args;
|
|
|
|
|
on_packet_claimed_callback *claimed_cb;
|
2024-09-18 14:23:01 +08:00
|
|
|
enum packet_stage stage;
|
2024-09-13 18:03:05 +08:00
|
|
|
struct mq_runtime *mq;
|
2024-09-18 14:23:01 +08:00
|
|
|
struct packet_queue queue[PACKET_QUEUE_MAX];
|
2024-09-14 18:38:37 +08:00
|
|
|
struct packet_manager_runtime_stat stat;
|
2024-09-13 18:03:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct packet_manager
|
|
|
|
|
{
|
|
|
|
|
struct packet_manager_config *cfg;
|
|
|
|
|
struct packet_manager_schema *schema;
|
|
|
|
|
struct packet_manager_runtime *runtime[MAX_THREAD_NUM];
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
* packet stage
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
const char *packet_stage_to_str(enum packet_stage stage)
|
|
|
|
|
{
|
|
|
|
|
switch (stage)
|
|
|
|
|
{
|
|
|
|
|
case PACKET_STAGE_PREROUTING:
|
|
|
|
|
return "prerouting";
|
|
|
|
|
case PACKET_STAGE_INPUT:
|
|
|
|
|
return "input";
|
|
|
|
|
case PACKET_STAGE_FORWARD:
|
|
|
|
|
return "forward";
|
|
|
|
|
case PACKET_STAGE_OUTPUT:
|
|
|
|
|
return "output";
|
|
|
|
|
case PACKET_STAGE_POSTROUTING:
|
|
|
|
|
return "postrouting";
|
|
|
|
|
default:
|
|
|
|
|
return "unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-13 18:03:05 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
* packet manager config
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void packet_manager_config_free(struct packet_manager_config *cfg)
|
|
|
|
|
{
|
|
|
|
|
if (cfg)
|
|
|
|
|
{
|
|
|
|
|
free(cfg);
|
|
|
|
|
cfg = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct packet_manager_config *packet_manager_config_new(const char *toml_file)
|
|
|
|
|
{
|
|
|
|
|
struct packet_manager_config *cfg = calloc(1, sizeof(struct packet_manager_config));
|
|
|
|
|
if (cfg == NULL)
|
|
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to allocate memory for packet_manager_config");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
uint64_t val = 0;
|
|
|
|
|
if (load_and_validate_toml_integer_config(toml_file, "packet_io.nr_worker_thread", &val, 1, MAX_THREAD_NUM) != 0)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to load packet_io.nr_worker_thread from %s", toml_file);
|
|
|
|
|
free(cfg);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-09-14 15:20:59 +08:00
|
|
|
cfg->nr_worker_thread = val;
|
2024-09-13 18:03:05 +08:00
|
|
|
|
|
|
|
|
return cfg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
* packet manager schema
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
static void on_packet_stage_dispatch(int topic_id, const void *msg, on_msg_cb_func *cb, void *cb_arg, void *dispatch_arg)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
2024-09-14 15:20:59 +08:00
|
|
|
assert(msg);
|
|
|
|
|
assert(dispatch_arg);
|
|
|
|
|
|
2024-09-13 18:03:05 +08:00
|
|
|
struct packet_manager_schema *schema = (struct packet_manager_schema *)dispatch_arg;
|
|
|
|
|
struct packet *pkt = (struct packet *)msg;
|
|
|
|
|
|
|
|
|
|
enum packet_stage stage = PACKET_STAGE_MAX;
|
|
|
|
|
for (int i = 0; i < PACKET_STAGE_MAX; i++)
|
|
|
|
|
{
|
|
|
|
|
if (schema->topic_id[i] == topic_id)
|
|
|
|
|
{
|
|
|
|
|
stage = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
((on_packet_stage_callback *)cb)(stage, pkt, cb_arg);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
static void packet_manager_schema_free(struct packet_manager_schema *pkt_mgr_schema)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
2024-09-14 15:20:59 +08:00
|
|
|
if (pkt_mgr_schema)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
2024-09-14 15:20:59 +08:00
|
|
|
if (pkt_mgr_schema->mq)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
|
|
|
|
for (int i = 0; i < PACKET_STAGE_MAX; i++)
|
|
|
|
|
{
|
2024-09-14 15:20:59 +08:00
|
|
|
if (pkt_mgr_schema->topic_id[i] >= 0)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
2024-09-14 15:20:59 +08:00
|
|
|
mq_schema_destroy_topic(pkt_mgr_schema->mq, pkt_mgr_schema->topic_id[i]);
|
2024-09-13 18:03:05 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
free(pkt_mgr_schema);
|
|
|
|
|
pkt_mgr_schema = NULL;
|
2024-09-13 18:03:05 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
static struct packet_manager_schema *packet_manager_schema_new(struct mq_schema *mq)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
2024-09-14 15:20:59 +08:00
|
|
|
struct packet_manager_schema *pkt_mgr_schema = calloc(1, sizeof(struct packet_manager_schema));
|
|
|
|
|
if (pkt_mgr_schema == NULL)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to allocate memory for packet_manager_schema");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
pkt_mgr_schema->mq = mq;
|
2024-09-13 18:03:05 +08:00
|
|
|
|
|
|
|
|
for (int i = 0; i < PACKET_STAGE_MAX; i++)
|
|
|
|
|
{
|
2024-09-14 15:20:59 +08:00
|
|
|
pkt_mgr_schema->topic_id[i] = mq_schema_create_topic(pkt_mgr_schema->mq, packet_stage_to_str(i), (on_msg_dispatch_cb_func *)on_packet_stage_dispatch, pkt_mgr_schema, NULL, NULL);
|
|
|
|
|
if (pkt_mgr_schema->topic_id[i] < 0)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
2024-09-14 15:20:59 +08:00
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to create topic %s", packet_stage_to_str(i));
|
2024-09-13 18:03:05 +08:00
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
return pkt_mgr_schema;
|
2024-09-13 18:03:05 +08:00
|
|
|
|
|
|
|
|
error_out:
|
2024-09-14 15:20:59 +08:00
|
|
|
packet_manager_schema_free(pkt_mgr_schema);
|
2024-09-13 18:03:05 +08:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
int packet_manager_schema_add_subscriber(struct packet_manager_schema *pkt_mgr_schema, enum packet_stage stage, on_packet_stage_callback cb, void *args)
|
|
|
|
|
{
|
|
|
|
|
return mq_schema_subscribe(pkt_mgr_schema->mq, pkt_mgr_schema->topic_id[stage], (on_msg_cb_func *)cb, args);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-13 18:03:05 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
* packet manager runtime
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void packet_manager_runtime_free(struct packet_manager_runtime *runtime)
|
|
|
|
|
{
|
|
|
|
|
if (runtime)
|
|
|
|
|
{
|
2024-09-18 14:23:01 +08:00
|
|
|
for (int i = 0; i < PACKET_QUEUE_MAX; i++)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
|
|
|
|
struct packet *pkt = NULL;
|
|
|
|
|
while ((pkt = TAILQ_FIRST(&runtime->queue[i])))
|
|
|
|
|
{
|
|
|
|
|
TAILQ_REMOVE(&runtime->queue[i], pkt, stage_tqe);
|
|
|
|
|
|
|
|
|
|
// TODO: free packet and free mbuff
|
|
|
|
|
packet_free(pkt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(runtime);
|
|
|
|
|
runtime = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 14:35:34 +08:00
|
|
|
static struct packet_manager_runtime *packet_manager_runtime_new()
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
|
|
|
|
struct packet_manager_runtime *runtime = calloc(1, sizeof(struct packet_manager_runtime));
|
|
|
|
|
if (runtime == NULL)
|
|
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to allocate memory for packet_manager_runtime");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 14:23:01 +08:00
|
|
|
for (int i = 0; i < PACKET_QUEUE_MAX; i++)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
|
|
|
|
TAILQ_INIT(&runtime->queue[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return runtime;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 18:38:37 +08:00
|
|
|
void packet_manager_runtime_print_stat(struct packet_manager_runtime *runtime)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
2024-09-18 14:35:34 +08:00
|
|
|
PACKET_MANAGER_LOG_DEBUG("runtime[%p] current stage: %s, pkts_ingress: %lu, pkts_egress: %lu",
|
|
|
|
|
runtime, packet_stage_to_str(runtime->stage),
|
|
|
|
|
runtime->stat.total.pkts_ingress, runtime->stat.total.pkts_egress);
|
2024-09-18 14:23:01 +08:00
|
|
|
for (int i = 0; i < PACKET_QUEUE_MAX; i++)
|
|
|
|
|
{
|
2024-09-18 14:35:34 +08:00
|
|
|
PACKET_MANAGER_LOG_DEBUG("runtime[%p] (%11s) queue stat => pkts_in: %lu, pkts_out: %lu, pkts_claim: %lu, pkts_schedule: %lu",
|
|
|
|
|
runtime,
|
2024-09-18 14:23:01 +08:00
|
|
|
packet_stage_to_str(i),
|
|
|
|
|
runtime->stat.queue[i].pkts_in,
|
|
|
|
|
runtime->stat.queue[i].pkts_out,
|
|
|
|
|
runtime->stat.queue[i].pkts_claim,
|
|
|
|
|
runtime->stat.queue[i].pkts_schedule);
|
|
|
|
|
}
|
2024-09-14 18:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct packet_manager_runtime_stat *packet_manager_runtime_get_stat(struct packet_manager_runtime *runtime)
|
|
|
|
|
{
|
|
|
|
|
return &runtime->stat;
|
2024-09-14 15:20:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void packet_manager_runtime_init(struct packet_manager_runtime *pkt_mgr_rt, struct mq_runtime *mq_rt)
|
|
|
|
|
{
|
|
|
|
|
pkt_mgr_rt->mq = mq_rt;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 14:35:34 +08:00
|
|
|
void packet_manager_runtime_ingress(struct packet_manager_runtime *pkt_mgr_rt, struct packet *pkt)
|
2024-09-14 15:20:59 +08:00
|
|
|
{
|
2024-09-18 14:35:34 +08:00
|
|
|
pkt_mgr_rt->stat.total.pkts_ingress++;
|
2024-09-18 14:23:01 +08:00
|
|
|
pkt_mgr_rt->stat.queue[PACKET_STAGE_PREROUTING].pkts_in++;
|
2024-09-14 15:20:59 +08:00
|
|
|
TAILQ_INSERT_TAIL(&pkt_mgr_rt->queue[PACKET_STAGE_PREROUTING], pkt, stage_tqe);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 14:35:34 +08:00
|
|
|
struct packet *packet_manager_runtime_egress(struct packet_manager_runtime *pkt_mgr_rt)
|
2024-09-14 15:20:59 +08:00
|
|
|
{
|
2024-09-18 14:23:01 +08:00
|
|
|
struct packet *pkt = TAILQ_FIRST(&pkt_mgr_rt->queue[PACKET_STAGE_MAX]);
|
2024-09-14 15:20:59 +08:00
|
|
|
if (pkt)
|
|
|
|
|
{
|
2024-09-18 14:35:34 +08:00
|
|
|
pkt_mgr_rt->stat.total.pkts_egress++;
|
2024-09-18 14:23:01 +08:00
|
|
|
pkt_mgr_rt->stat.queue[PACKET_STAGE_MAX].pkts_out++;
|
|
|
|
|
TAILQ_REMOVE(&pkt_mgr_rt->queue[PACKET_STAGE_MAX], pkt, stage_tqe);
|
2024-09-14 15:20:59 +08:00
|
|
|
}
|
|
|
|
|
return pkt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void packet_manager_runtime_dispatch(struct packet_manager_runtime *pkt_mgr_rt)
|
|
|
|
|
{
|
2024-09-13 18:03:05 +08:00
|
|
|
for (int i = 0; i < PACKET_STAGE_MAX; i++)
|
|
|
|
|
{
|
2024-09-18 14:23:01 +08:00
|
|
|
pkt_mgr_rt->stage = i;
|
2024-09-14 18:38:37 +08:00
|
|
|
packet_manager_runtime_print_stat(pkt_mgr_rt);
|
2024-09-14 15:20:59 +08:00
|
|
|
|
|
|
|
|
struct packet *pkt = NULL;
|
2024-09-18 14:23:01 +08:00
|
|
|
while ((pkt = TAILQ_FIRST(&pkt_mgr_rt->queue[pkt_mgr_rt->stage])))
|
2024-09-14 15:20:59 +08:00
|
|
|
{
|
2024-09-14 18:38:37 +08:00
|
|
|
packet_set_claim(pkt, false);
|
|
|
|
|
pkt_mgr_rt->claimed_cb = NULL;
|
|
|
|
|
pkt_mgr_rt->cb_args = NULL;
|
|
|
|
|
|
2024-09-18 14:23:01 +08:00
|
|
|
TAILQ_REMOVE(&pkt_mgr_rt->queue[pkt_mgr_rt->stage], pkt, stage_tqe);
|
|
|
|
|
pkt_mgr_rt->stat.queue[pkt_mgr_rt->stage].pkts_out++;
|
2024-09-14 15:20:59 +08:00
|
|
|
|
2024-09-18 14:23:01 +08:00
|
|
|
mq_runtime_publish_message(pkt_mgr_rt->mq, pkt_mgr_rt->stage, pkt);
|
2024-09-14 15:20:59 +08:00
|
|
|
mq_runtime_dispatch(pkt_mgr_rt->mq);
|
|
|
|
|
|
2024-09-14 18:38:37 +08:00
|
|
|
if (packet_is_claim(pkt))
|
2024-09-14 15:20:59 +08:00
|
|
|
{
|
2024-09-14 18:38:37 +08:00
|
|
|
if (pkt_mgr_rt->claimed_cb)
|
|
|
|
|
{
|
|
|
|
|
pkt_mgr_rt->claimed_cb(pkt, pkt_mgr_rt->cb_args);
|
|
|
|
|
}
|
2024-09-18 14:23:01 +08:00
|
|
|
packet_set_claim(pkt, false);
|
2024-09-14 15:20:59 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 14:23:01 +08:00
|
|
|
TAILQ_INSERT_TAIL(&pkt_mgr_rt->queue[pkt_mgr_rt->stage + 1], pkt, stage_tqe);
|
|
|
|
|
pkt_mgr_rt->stat.queue[pkt_mgr_rt->stage + 1].pkts_in++;
|
2024-09-14 15:20:59 +08:00
|
|
|
}
|
2024-09-13 18:03:05 +08:00
|
|
|
}
|
2024-09-18 14:23:01 +08:00
|
|
|
pkt_mgr_rt->stage = -1;
|
2024-09-13 18:03:05 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-14 18:38:37 +08:00
|
|
|
int packet_manager_runtime_claim_packet(struct packet_manager_runtime *pkt_mgr_rt, struct packet *pkt, on_packet_claimed_callback cb, void *args)
|
2024-09-14 15:20:59 +08:00
|
|
|
{
|
2024-09-14 18:38:37 +08:00
|
|
|
if (packet_is_claim(pkt))
|
|
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("packet is already claimed, cannot claim again");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pkt_mgr_rt->claimed_cb = cb;
|
|
|
|
|
pkt_mgr_rt->cb_args = args;
|
|
|
|
|
packet_set_claim(pkt, true);
|
2024-09-18 14:23:01 +08:00
|
|
|
pkt_mgr_rt->stat.queue[pkt_mgr_rt->stage].pkts_claim++;
|
2024-09-14 18:38:37 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
2024-09-14 15:20:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void packet_manager_runtime_schedule_packet(struct packet_manager_runtime *pkt_mgr_rt, struct packet *pkt, enum packet_stage stage)
|
|
|
|
|
{
|
2024-09-14 18:38:37 +08:00
|
|
|
if (stage >= PACKET_STAGE_MAX)
|
|
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("invalid stage %d", stage);
|
|
|
|
|
assert(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 14:23:01 +08:00
|
|
|
pkt_mgr_rt->stat.queue[stage].pkts_schedule++;
|
|
|
|
|
pkt_mgr_rt->stat.queue[stage].pkts_in++;
|
2024-09-14 15:20:59 +08:00
|
|
|
TAILQ_INSERT_TAIL(&pkt_mgr_rt->queue[stage], pkt, stage_tqe);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-13 18:03:05 +08:00
|
|
|
/******************************************************************************
|
2024-09-14 15:20:59 +08:00
|
|
|
* packet manager
|
2024-09-13 18:03:05 +08:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
struct packet_manager *packet_manager_new(struct mq_schema *mq, const char *toml_file)
|
2024-09-13 18:03:05 +08:00
|
|
|
{
|
|
|
|
|
struct packet_manager *pkt_mgr = calloc(1, sizeof(struct packet_manager));
|
|
|
|
|
if (pkt_mgr == NULL)
|
|
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to allocate memory for packet_manager");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pkt_mgr->cfg = packet_manager_config_new(toml_file);
|
|
|
|
|
if (pkt_mgr->cfg == NULL)
|
|
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to create packet_manager_config");
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
pkt_mgr->schema = packet_manager_schema_new(mq);
|
2024-09-13 18:03:05 +08:00
|
|
|
if (pkt_mgr->schema == NULL)
|
|
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to create packet_manager_schema");
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (uint16_t i = 0; i < pkt_mgr->cfg->nr_worker_thread; i++)
|
|
|
|
|
{
|
2024-09-18 14:35:34 +08:00
|
|
|
pkt_mgr->runtime[i] = packet_manager_runtime_new();
|
2024-09-13 18:03:05 +08:00
|
|
|
if (pkt_mgr->runtime[i] == NULL)
|
|
|
|
|
{
|
|
|
|
|
PACKET_MANAGER_LOG_ERROR("failed to create packet_manager_runtime");
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pkt_mgr;
|
|
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
|
packet_manager_free(pkt_mgr);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void packet_manager_free(struct packet_manager *pkt_mgr)
|
|
|
|
|
{
|
|
|
|
|
if (pkt_mgr)
|
|
|
|
|
{
|
|
|
|
|
for (uint16_t i = 0; i < pkt_mgr->cfg->nr_worker_thread; i++)
|
|
|
|
|
{
|
|
|
|
|
if (pkt_mgr->runtime[i])
|
|
|
|
|
{
|
|
|
|
|
packet_manager_runtime_free(pkt_mgr->runtime[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-14 15:20:59 +08:00
|
|
|
packet_manager_schema_free(pkt_mgr->schema);
|
|
|
|
|
packet_manager_config_free(pkt_mgr->cfg);
|
|
|
|
|
|
2024-09-13 18:03:05 +08:00
|
|
|
free(pkt_mgr);
|
|
|
|
|
pkt_mgr = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct packet_manager_schema *packet_manager_get_schema(struct packet_manager *pkt_mgr)
|
|
|
|
|
{
|
|
|
|
|
if (pkt_mgr)
|
|
|
|
|
{
|
|
|
|
|
return pkt_mgr->schema;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct packet_manager_runtime *packet_manager_get_runtime(struct packet_manager *pkt_mgr, uint16_t thr_idx)
|
|
|
|
|
{
|
|
|
|
|
if (pkt_mgr && thr_idx < pkt_mgr->cfg->nr_worker_thread)
|
|
|
|
|
{
|
|
|
|
|
return pkt_mgr->runtime[thr_idx];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|