[PACKET_IO] add pio_packet structure for pcap_live/pcap_file mode

This commit is contained in:
liuwentan
2022-08-09 15:58:46 +08:00
parent 7442cb09d5
commit c2d5b9cdb7
17 changed files with 157 additions and 360 deletions

View File

@@ -287,7 +287,7 @@ int pio_pcap_file_device_close(struct packet_io_device *pdev)
for (uint32_t i = 0; i < PKT_QUEUE_MAX_NUM; i++) {
if (pdev->entity.pcap_file_dev_ctx->pkt_queues[i].len != 0) {
release_packet_queue(&pdev->entity.pcap_file_dev_ctx->pkt_queues[i]);
release_pio_packet_queue(&pdev->entity.pcap_file_dev_ctx->pkt_queues[i]);
}
}
@@ -299,12 +299,16 @@ 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 packet *p = CALLOC(struct packet, 1);
struct pio_packet *p = (struct pio_packet *)malloc(SIZE_OF_PIO_PACKET);
if (nullptr == p) {
return;
}
memset(p, 0, SIZE_OF_PIO_PACKET);
if (packet_copy_data(p, pkt, pkt_hdr->caplen)) {
p->pkt_hdr = p;
p->pkt_payload = (uint8_t *)p + CUSTOM_ZONE_LEN;
p->pkt_len = pkt_hdr->caplen;
if (packet_copy_data((uint8_t *)p->pkt_payload, (uint8_t *)pkt, pkt_hdr->caplen)) {
FREE(p);
return;
}
@@ -314,10 +318,10 @@ void pcap_file_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_hdr, u_c
hash_id = decode_packet(p) % nr_rxq;
packet_enqueue(&pfile_dev_ctx->pkt_queues[hash_id], p);
*/
/*
int rxq_id = 0;
pthread_mutex_lock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
packet_enqueue(&pfile_dev_ctx->pkt_queues[rxq_id], p);
pthread_mutex_unlock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q); */
pio_packet_enqueue(&pfile_dev_ctx->pkt_queues[rxq_id], p);
pthread_mutex_unlock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
}
static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t nr_rxq, uint32_t rxq_id,
@@ -349,12 +353,12 @@ static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx
//TODO: close pcap file
} else {
// success
struct packet *p = nullptr;
struct pio_packet *p = nullptr;
int i = 0;
pthread_mutex_lock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
do {
p = packet_dequeue(&pfile_dev_ctx->pkt_queues[rxq_id]);
pkts[i] = p;
p = pio_packet_dequeue(&pfile_dev_ctx->pkt_queues[rxq_id]);
pkts[i] = (struct packet *)p;
i++;
} while (p != nullptr && (i < nr_pkts));
pthread_mutex_unlock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
@@ -603,9 +607,12 @@ int pio_pcap_file_device_send(struct packet_io_device *pdev, uint32_t txq_id, st
return 0;
}
void pio_pcap_file_device_pkt_free(struct packet_io_device *pdev, 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 packet **pkts, int nr_pkts)
{
for (uint32_t i = 0; i < nr_pkts; i++) {
struct pio_packet *p = (struct pio_packet *)pkts[i];
FREE(p);
}
}
int pio_pcap_file_instance_create(struct packet_io_instance *pinst, __unused int wrk_thread_num)