[PACKET_IO]unallocated memory related bugfix for marsio mode
This commit is contained in:
@@ -9,17 +9,114 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "pio_pcap_file.h"
|
||||
#include "../packet_io.h"
|
||||
#include "../../sdk/include/utils.h"
|
||||
#include "../../sdk/include/util_errors.h"
|
||||
#include "../../sdk/include/logger.h"
|
||||
|
||||
int pio_pcap_file_device_open(struct packet_io_device *pdev, const char *path, uint32_t nr_rxq, uint32_t nr_txq)
|
||||
{
|
||||
/*
|
||||
* @brief validate path is a valid plain file or directory
|
||||
*
|
||||
* @retval failed (-1) successful (0),
|
||||
* if success, dir == nullptr <---> means path is plain file
|
||||
* dir != nullptr <---> means path is directory
|
||||
**/
|
||||
static int validate_directory_or_file(const char *path, DIR **dir) {
|
||||
DIR *temp_dir = nullptr;
|
||||
int ret = -1;
|
||||
|
||||
temp_dir = opendir(path);
|
||||
if (nullptr == temp_dir) {
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
log_error(ST_ERR_FOPEN, "%s: Permission denied", path);
|
||||
break;
|
||||
case EBADF:
|
||||
log_error(ST_ERR_FOPEN, "%s: invalid file descriptor", path);
|
||||
break;
|
||||
case ENOTDIR:
|
||||
log_info("%s: is a plain file, not directory", path);
|
||||
ret = 0;
|
||||
break;
|
||||
default:
|
||||
log_error(ST_ERR_FOPEN, "%s: errno:%d", path, errno);
|
||||
}
|
||||
} else {
|
||||
*dir = temp_dir;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int pcap_plain_file_init(struct pio_pcap_file_device_context *pfile_dev_ctx) {
|
||||
struct pcap_plain_file_info *pfile_info = CALLOC(struct pcap_plain_file_info, 1);
|
||||
if (nullptr == pfile_info) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pio_pcap_file_device_close(const struct packet_io_device *pdev)
|
||||
static int pcap_directory_file_init(struct pio_pcap_file_device_context *pfile_dev_ctx) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pcap_file_shared_init(struct pio_pcap_file_device_context *pfile_dev_ctx) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pio_pcap_file_device_open(struct packet_io_device *pdev, const char *path, uint32_t nr_rxq, uint32_t nr_txq)
|
||||
{
|
||||
int status = -1;
|
||||
DIR *directory = nullptr;
|
||||
|
||||
|
||||
status = pcap_file_shared_init(pdev->entity.pcap_file_dev_ctx);
|
||||
if (status < 0) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "pcap file shared init failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (validate_directory_or_file(path, &directory) != 0) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "invalid path:%s (not plain file or directory)", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nullptr == directory) {
|
||||
/* plain file */
|
||||
status = pcap_plain_file_init(pdev->entity.pcap_file_dev_ctx);
|
||||
if (status < 0) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "pcap plain file init failed.");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* directory */
|
||||
status = pcap_directory_file_init(pdev->entity.pcap_file_dev_ctx);
|
||||
if (status < 0) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "pcap directory file init failed.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pio_pcap_file_device_close(struct packet_io_device *pdev)
|
||||
{
|
||||
if (nullptr == pdev) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "invalid pdev pointer so close pcap file device failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TODO: */
|
||||
//pcap_close(pdev->entity.pcap_file_dev->pcap_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -41,7 +138,7 @@ void pio_pcap_file_device_pkt_free(struct packet_io_device *pdev, uint32_t qid,
|
||||
|
||||
}
|
||||
|
||||
int pio_pcap_file_instance_create(struct packet_io_instance *pinst, int wrk_thread_num)
|
||||
int pio_pcap_file_instance_create(struct packet_io_instance *pinst, __unused int wrk_thread_num)
|
||||
{
|
||||
|
||||
return 0;
|
||||
@@ -49,5 +146,8 @@ int pio_pcap_file_instance_create(struct packet_io_instance *pinst, int wrk_thre
|
||||
|
||||
void pio_pcap_file_instance_destroy(struct packet_io_instance *pinst)
|
||||
{
|
||||
|
||||
for (uint32_t i = 0; i < pinst->dev_cnt; i++) {
|
||||
pio_pcap_file_device_close(pinst->devices[i]);
|
||||
FREE(pinst->devices[i]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user