[PACKET_IO]fix coredump for large packets

This commit is contained in:
liuwentan
2022-08-12 17:23:27 +08:00
parent 5c7c2a4052
commit 90542cec2d
6 changed files with 91 additions and 41 deletions

View File

@@ -106,7 +106,7 @@ static int init_pcap_file(struct pcap_plain_file_info *pfile_info)
if (pcap_setfilter(pfile_info->pcap_handle, &pfile_info->filter) < 0) {
log_error(ST_ERR_BPF, "could not set bpf filter %s for %s",
pcap_geterr(pfile_info->pcap_handle, pfile_info->file_name));
pcap_geterr(pfile_info->pcap_handle), pfile_info->file_name);
pcap_freecode(&pfile_info->filter);
return -1;
}
@@ -205,10 +205,9 @@ static int pcap_file_shared_init(struct pio_pcap_file_device_context *pfile_dev_
pfile_dev_ctx->shared.should_delete = g_engine_instance.config.packet_io.should_delete;
/* init pcap file device packet queue */
memset(pfile_dev_ctx->pkt_queues, 0, sizeof(pfile_dev_ctx->pkt_queues));
for (uint32_t i = 0; i < PKT_QUEUE_MAX_NUM; i++) {
pthread_mutex_init(&pfile_dev_ctx->pkt_queues[i].mutex_q, nullptr);
pio_packet_queue_init(&pfile_dev_ctx->pkt_queues[i]);
}
return 0;
@@ -317,15 +316,25 @@ int pio_pcap_file_device_close(struct packet_io_device *pdev)
void pcap_file_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_hdr, u_char *pkt)
{
struct pio_pcap_file_device_context *pfile_dev_ctx = (struct pio_pcap_file_device_context *)user;
struct pio_packet *p = (struct pio_packet *)malloc(SIZE_OF_PIO_PACKET);
uint32_t p_len = 0;
if (pkt_hdr->caplen < DEFAULT_MTU) {
p_len = COMMON_SIZE_OF_PIO_PACKET;
} else {
p_len = MAX_SIZE_OF_PIO_PACKET;
}
struct pio_packet *p = (struct pio_packet *)malloc(p_len);
if (nullptr == p) {
return;
}
memset(p, 0, SIZE_OF_PIO_PACKET);
memset(p, 0, p_len);
p->pkt_hdr = p;
p->pkt_payload = (uint8_t *)p + CUSTOM_ZONE_LEN;
p->pkt_len = pkt_hdr->caplen;
p->data_link = pfile_dev_ctx->entity.file->data_link;
if (packet_copy_data((uint8_t *)p->pkt_payload, (uint8_t *)pkt, pkt_hdr->caplen)) {
FREE(p);
return;