summaryrefslogtreecommitdiff
path: root/src/packet_io/packet_io_internal.h
blob: 9fdef43d2328db6e58543d35a2cb9df844ecc54c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
**********************************************************************************************
*	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;

    /* 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_ */