This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar-2022/src/packet_io/pcap_file_mode/pio_pcap_file.h
2022-08-31 22:04:56 +08:00

151 lines
3.6 KiB
C

/*
**********************************************************************************************
* File: pcap_file.h
* Description: pcap file runmode api
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-07-15
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
***********************************************************************************************
*/
#ifndef _PIO_PCAP_FILE_H_
#define _PIO_PCAP_FILE_H_
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
#include <dirent.h>
#include <pcap/pcap.h>
#include <sys/queue.h>
#include "packet_io_util.h"
struct pio_pcap_file_instance_context {
};
struct pending_file {
char file_name[NAME_MAX];
struct timespec modified_time;
TAILQ_ENTRY(pending_file) next;
};
struct safe_pending_file_queue {
TAILQ_HEAD(pending_file_queue, pending_file) file_queue_head;
pthread_mutex_t queue_mutex;
};
struct pcap_file_shared_info {
/* bpf filter string, such as "tcp and port 25"*/
char bpf_string[STR_MAX_LEN];
/* if delete when pcapfile is processed */
int should_delete;
/* the timestamp of the last process */
struct timespec last_processed_ts;
/* counters */
uint64_t pkts;
uint64_t bytes;
uint64_t files;
/* processing completed flags */
uint8_t done;
};
struct pcap_plain_file_info {
char file_name[NAME_MAX];
pcap_t *pcap_handle;
pthread_mutex_t handle_mutex;
int data_link;
struct bpf_program filter;
/* get the first packet timestamp */
const u_char *first_pkt_data;
struct pcap_pkthdr *first_pkt_hdr;
struct timeval first_pkt_ts;
struct pcap_file_shared_info *shared;
};
struct pcap_file_directory_info {
char dir_name[NAME_MAX];
DIR *directory;
struct pcap_plain_file_info *current_file[VIRTUAL_QUEUE_MAX_NUM];
time_t delay;
struct pcap_file_shared_info *shared;
struct pending_file *pending_file[VIRTUAL_QUEUE_MAX_NUM];
};
/**
* @brief pio_pcap_file_device_context - pcap file device context
*/
struct pio_pcap_file_device_context {
union {
struct pcap_file_directory_info *dir;
struct pcap_plain_file_info *file;
} entity;
bool is_dir;
/* rx pio packet queue */
struct pio_packet_queue pkt_queues[VIRTUAL_QUEUE_MAX_NUM];
struct pcap_file_shared_info shared;
/* point to packet_io device it belongs to */
struct packet_io_device *pdev;
};
/**
* @brief
*
* @param pinst
* @return int
*/
ssize_t pio_pcap_file_instance_create(struct packet_io_instance *pinst);
/**
* @brief
*
* @param pinst
*/
void pio_pcap_file_instance_destroy(struct packet_io_instance *pinst);
/**
* @brief open pcap_file device
*
* @param pdev: pcap_file device's pointer which support following params
* pdev->dev_name: the name of pcap file
* pdev->rxq_num: number of the packet receiving queues for the device
* pdev->txq_num: number of the packet sending queues for the device
*/
ssize_t pio_pcap_file_device_open(struct packet_io_device *pdev);
/**
* @brief close pcap_live device
*/
ssize_t pio_pcap_file_device_close(struct packet_io_device *pdev);
ssize_t pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, size_t nr_pkts);
void pio_pcap_file_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, size_t nr_pkts);
char *pio_pcap_file_device_buff_ctrlzone(struct stellar_packet *p, size_t *ctrlzone_len);
char *pio_pcap_file_device_buff_mtod(struct stellar_packet *p, size_t *data_len);
#ifdef __cpluscplus
}
#endif
#endif /* _PIO_PCAP_FILE_H_ */