diff options
| author | liuwentan <[email protected]> | 2022-08-18 16:26:00 +0800 |
|---|---|---|
| committer | liuwentan <[email protected]> | 2022-08-31 22:04:05 +0800 |
| commit | 90b359ed40368f552ae251daaa82a75ff2b86f3e (patch) | |
| tree | 10a08333fc75b23dacb507885fbd3f7536b63fc2 /src/packet_io/packet_io_internal.h | |
| parent | 90542cec2d50836b2bba8db39900bff9742b9667 (diff) | |
[PACKET_IO]format api style
Diffstat (limited to 'src/packet_io/packet_io_internal.h')
| -rw-r--r-- | src/packet_io/packet_io_internal.h | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/src/packet_io/packet_io_internal.h b/src/packet_io/packet_io_internal.h new file mode 100644 index 0000000..e52dd7c --- /dev/null +++ b/src/packet_io/packet_io_internal.h @@ -0,0 +1,155 @@ +/* +********************************************************************************************** +* File: packet_io_internal.h +* Description: packet_io internal api +* Authors: Liu WenTan <[email protected]> +* Date: 2022-07-15 +* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +*********************************************************************************************** +*/ + +#ifndef _PACKET_IO_INTERNAL_H_ +#define _PACKET_IO_INTERNAL_H_ + +#ifdef __cpluscplus +extern "C" +{ +#endif + +#include <limits.h> +#include <sys/queue.h> + +#include "packet_io_util.h" + +#define DEV_MAX_CNT 64 + +/** + * note: + * 1. packet_io_XXX function is supported by packet_io.h + * 2. pio_XXX function is supported by pio_pcap_live.h/pio_pcap_file.h/pio_marsio.h + */ + +struct pio_instance_operations { + ssize_t (*create)(struct packet_io_instance *pinst); + + void (*destroy)(struct packet_io_instance *pinst); +}; + +struct packet_io_instance { + /* packet_io instance name */ + char inst_name[NAME_MAX]; + + /* packet_io run mode of the instance */ + enum packet_io_run_mode mode; + + /* device handle set in this instance */ + TAILQ_HEAD(pio_device_queue, packet_io_device) device_queue_head; + + /* device's exactly count */ + uint32_t dev_cnt; + + /* instance operations */ + struct pio_instance_operations *inst_ops; + + union + { + struct pio_pcap_file_instance_context *pcap_file_inst_ctx; + struct pio_pcap_live_instance_context *pcap_live_inst_ctx; + struct pio_marsio_instance_context *marsio_inst_ctx; + } entity; +}; + +struct pio_device_operations { + ssize_t (*open)(struct packet_io_device *pdev); + + ssize_t (*close)(struct packet_io_device *pdev); + + ssize_t (*recv)(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, size_t nr_pkts); + + ssize_t (*send)(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, size_t nr_pkts); + + void (*pkt_free)(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, size_t nr_pkts); + + char *(*buff_ctrlzone)(struct stellar_packet *p, size_t *ctrlzone_len); + + char *(*buff_mtod)(struct stellar_packet *p, size_t *data_len); +}; + +struct packet_io_device { + /* device name */ + char dev_name[NAME_MAX]; + + /* device operations */ + struct pio_device_operations *dev_ops; + + /* number of receive queue */ + uint16_t rxq_num; + + /* number of send queue */ + uint16_t txq_num; + + /* packet io device context */ + union { + struct pio_pcap_file_device_context *pcap_file_dev_ctx; + struct pio_pcap_live_device_context *pcap_live_dev_ctx; + struct pio_marsio_device_context *marsio_dev_ctx; + } entity; + + /* packet_io instance which the device belongs to */ + struct packet_io_instance *ppio_inst; + + TAILQ_ENTRY(packet_io_device) next; +}; + +struct pio_marsio_config { + /* marsio ctrlzone id */ + int mr_ctrlzone_id; + + const char *libmarsio_path; +}; + +struct pio_pcap_config { + char path[PATH_MAX]; + /* bpf filter string, such as "tcp and port 25"*/ + char bpf_string[STR_MAX_LEN]; + + /* delete after the pcap file is processed */ + int should_delete; + + //time_t delay; + + /* snapshot length */ + int snaplen; + + /* promiscuous value */ + int promisc; +}; + +struct pio_common_config { + /* packet_io run mode */ + enum packet_io_run_mode mode; + + /* worker thread num */ + int thread_num; + + /* device name list */ + char dev_name[DEV_MAX_CNT][NAME_MAX]; + + /* device counts */ + uint32_t dev_cnt; +}; + +/* store packet_io configuration */ +struct packet_io_config { + struct pio_common_config common; + struct pio_pcap_config pcap; + struct pio_marsio_config marsio; +}; + +extern struct packet_io_config g_packet_io_config; + +#ifdef __cpluscplus +} +#endif + +#endif /* _PACKET_IO_INTERNAL_H_ */
\ No newline at end of file |
