Merge branch develop-0.0

This commit is contained in:
liuwentan
2022-08-11 09:38:38 +08:00
87 changed files with 9132 additions and 522 deletions

View File

@@ -93,7 +93,7 @@ static int init_pcap_file(struct pcap_plain_file_info *pfile_info)
return -1;
}
pthread_mutex_init(&pfile_info->handle_mutex, NULL);
pthread_mutex_init(&pfile_info->handle_mutex, nullptr);
if (pfile_info->shared != nullptr && pfile_info->shared->bpf_string != nullptr) {
if (pcap_compile(pfile_info->pcap_handle, &pfile_info->filter,
@@ -133,9 +133,14 @@ static int pcap_plain_file_init(struct pio_pcap_file_device_context *pfile_dev_c
}
/* TODO: get conf and assign pfile_info */
strncpy(pfile_info->file_name, file_name, strlen(file_name));
int ret = strncpy_safe(pfile_info->file_name, file_name, sizeof(pfile_info->file_name));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "pcap plain file name copy failed.");
return -1;
}
pfile_info->shared = &pfile_dev_ctx->shared;
int ret = init_pcap_file(pfile_info);
ret = init_pcap_file(pfile_info);
if (ret < 0) {
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "init_pcap_file failed.");
FREE(pfile_info);
@@ -161,7 +166,12 @@ static int pcap_directory_file_init(struct pio_pcap_file_device_context *pfile_d
}
/* TODO: get conf and assign pdir_info */
strncpy(pdir_info->dir_name, dir_name, strlen(dir_name));
int ret = strncpy_safe(pdir_info->dir_name, dir_name, sizeof(pdir_info->dir_name));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "pcap directory name copy failed.");
return -1;
}
//pdir_info->delay = 30;
pdir_info->shared = &pfile_dev_ctx->shared;
pdir_info->directory = directory;
@@ -182,8 +192,13 @@ static int pcap_file_shared_init(struct pio_pcap_file_device_context *pfile_dev_
/* TODO: get conf and assign pfile_dev_ctx->shared */
if ((g_engine_instance.config.packet_io.mode == PACKET_IO_RUN_MODE_PCAP_FILE) &&
g_engine_instance.config.packet_io.bpf_string != nullptr) {
strncpy(pfile_dev_ctx->shared.bpf_string, g_engine_instance.config.packet_io.bpf_string,
strlen(g_engine_instance.config.packet_io.bpf_string));
memset(pfile_dev_ctx->shared.bpf_string, 0, sizeof(pfile_dev_ctx->shared.bpf_string));
int ret = strncpy_safe(pfile_dev_ctx->shared.bpf_string, g_engine_instance.config.packet_io.bpf_string,
sizeof(pfile_dev_ctx->shared.bpf_string));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "pcap file bpf string copy failed.");
return -1;
}
}
pfile_dev_ctx->shared.should_delete = g_engine_instance.config.packet_io.should_delete;
@@ -315,7 +330,7 @@ void pcap_file_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_hdr, u_c
return;
}
uint32_t nr_rxq = pfile_dev_ctx->pio_dev->rxq_num;
//uint32_t nr_rxq = pfile_dev_ctx->pio_dev->rxq_num;
/*
hash to specific queue id and enqueue
hash_id = decode_packet(p) % nr_rxq;
@@ -328,7 +343,7 @@ void pcap_file_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_hdr, u_c
}
static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t rxq_id,
struct packet **pkts, int nr_pkts)
struct stellar_packet **pkts, int nr_pkts)
{
if (pfile_dev_ctx->entity.file->first_pkt_hdr != nullptr) {
pthread_mutex_lock(&pfile_dev_ctx->entity.file->handle_mutex);
@@ -361,7 +376,7 @@ static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx
pthread_mutex_lock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
do {
p = pio_packet_dequeue(&pfile_dev_ctx->pkt_queues[rxq_id]);
pkts[i] = (struct packet *)p;
pkts[i] = (struct stellar_packet *)p;
i++;
} while (p != nullptr && (i < nr_pkts));
pthread_mutex_unlock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
@@ -401,7 +416,7 @@ find_pending_file_to_add(struct pio_pcap_file_device_context *pfile_dev_ctx, str
{
char abs_path[PATH_MAX] = {0};
snprintf(abs_path, PATH_MAX, "%s/%s", pfile_dev_ctx->entity.dir->dir_name, dir->d_name);
snprintf(abs_path, sizeof(abs_path), "%s/%s", pfile_dev_ctx->entity.dir->dir_name, dir->d_name);
struct timespec temp_time;
memset(&temp_time, 0, sizeof(struct timespec));
@@ -420,7 +435,12 @@ find_pending_file_to_add(struct pio_pcap_file_device_context *pfile_dev_ctx, str
}
struct pending_file *file_to_add = CALLOC(struct pending_file, 1);
strncpy(file_to_add->file_name, abs_path, strlen(abs_path));
int ret = strncpy_safe(file_to_add->file_name, abs_path, sizeof(file_to_add->file_name));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "file_to_add file name copy failed.");
return nullptr;
}
copy_timespec(&temp_time, &file_to_add->modified_time);
log_info("found \"%s\" at %" PRIuMAX, file_to_add->file_name,
(uintmax_t)timespec_to_millisecond(&file_to_add->modified_time));
@@ -499,7 +519,7 @@ static int pcap_directory_collect_pending_files(struct pio_pcap_file_device_cont
}
static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t rxq_id,
struct packet **pkts, int nr_pkts)
struct stellar_packet **pkts, int nr_pkts)
{
int res = -1;
struct timespec deadline;
@@ -535,7 +555,14 @@ static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_de
return -1;
}
strncpy(pfile_info->file_name, current_file->file_name, strlen(current_file->file_name));
res = strncpy_safe(pfile_info->file_name, current_file->file_name, sizeof(pfile_info->file_name));
if (res < 0) {
log_error(ST_ERR_STR_COPY, "pfile_info file name copy failed.");
FREE(current_file);
FREE(pfile_info);
return -1;
}
pfile_info->shared = &pfile_dev_ctx->shared;
if (init_pcap_file(pfile_info) < 0) {
@@ -576,13 +603,7 @@ static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_de
return res;
}
static int pcap_file_exit(int status, struct timespec *last_processed)
{
return 0;
}
int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts)
int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts)
{
struct pio_pcap_file_device_context *pfile_dev_ctx = pdev->entity.pcap_file_dev_ctx;
if (nullptr == pfile_dev_ctx) {
@@ -599,14 +620,12 @@ int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id,
res = pcap_directory_dispatch(pfile_dev_ctx, rxq_id, pkts, nr_pkts);
}
//pcap_file_exit(status, &pfile_dev_ctx->shared.last_processed_ts);
return res;
}
void pio_pcap_file_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint32_t qid, struct packet **pkts, int nr_pkts)
void pio_pcap_file_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint32_t qid, struct stellar_packet **pkts, int nr_pkts)
{
for (uint32_t i = 0; i < nr_pkts; i++) {
for (int i = 0; i < nr_pkts; i++) {
struct pio_packet *p = (struct pio_packet *)pkts[i];
FREE(p);
}
@@ -642,26 +661,26 @@ void pio_pcap_file_instance_destroy(struct packet_io_instance *pinst)
}
}
void *pio_pcap_file_device_buff_ctrlzone(struct packet *p)
void *pio_pcap_file_device_buff_ctrlzone(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return pkt->pkt_hdr;
}
char *pio_pcap_file_device_buff_mtod(struct packet *p)
char *pio_pcap_file_device_buff_mtod(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (char *)pkt->pkt_payload;
}
uint32_t pio_pcap_file_device_buff_buflen(struct packet *p)
uint32_t pio_pcap_file_device_buff_buflen(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (pkt->pkt_len + CUSTOM_ZONE_LEN);
}
uint32_t pio_pcap_file_device_buff_datalen(struct packet *p)
uint32_t pio_pcap_file_device_buff_datalen(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (pkt->pkt_len);
}
}