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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
#ifndef _PACKET_IO_H_
#define _PACKET_IO_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <time.h>
#include <netinet/ip.h>
#include <sys/types.h>
#include <linux/limits.h>
#include "stream_manage.h"
#include "stream_internal.h"
#include "sysinfo.h"
#ifndef MULTITHREAD
#define MULTITHREAD (1)
#endif
#define RAW_PKT_BROKEN_TEST (0) /* ��ֹ�ϲ���������ԭʼ��, ���Ӽ����� */
#define SENDPACKET_BUF_LEN (2048)
extern int g_UseFilterCard; //add by lqy 20081110
extern int g_UseSendpktCard; //add by lqy 20090313
extern int g_UseFilterTag; //add by lqy 20090414
enum io_dir_t{
IO_DIR_UP = 0,
IO_DIR_DOWN = 1,
};
enum cap_level_t{
__CAP_LEVEL_UNKNOW = 0,
CAP_LEVEL_MAC = ADDR_TYPE_MAC,
CAP_LEVEL_IPV4 = __ADDR_TYPE_IP_PAIR_V4, /* �����IP��, Ĭ��ΪIPv4 */
CAP_LEVEL_IPV6 = __ADDR_TYPE_IP_PAIR_V6,
CAP_LEVEL_MAC_IN_MAC = ADDR_TYPE_MAC_IN_MAC,
};
enum cap_mode_t{
CAP_MODEL_PAG = 0,
CAP_MODEL_PCAP_ONLINE = 1,
CAP_MODEL_PCAP_DUMPFILE = 2,
CAP_MODEL_PFRING = 3,
CAP_MODEL_DPDK = 4,
CAP_MODEL_PPF = 5,
CAP_MODEL_NPACKET = 6,
CAP_MODEL_QNF = 7, /* for ��߿Ƽ�Zhuanyong���� */
CAP_MODEL_N95 = 8, /* to do: for xx9 UDP�½ӿ� */
CAP_MODEL_PCAP_DUMPLIST = 9, /* 2014-11-19 lijia add */
CAP_MODEL_TOPSEC = 10, /* 2015-09-29 lijia add, for trojan detect */
CAP_MODEL_IPFILE = 11,
CAP_MODEL_MARSIOV4 = 12, /* 2016-10-26 lijia add, for DPDK-marsio-V4.0 */
CAP_MODEL_AGENT_SMITH = 13, /* 2016-10-27 lijia add, for ��Դ���빲���ڴ� */
CAP_MODEL_DPDK_VXLAN = 14, /* 2016-11-01 lijia add, for DPDK-3.0, vxlan������� */
CAP_MODEL_MARSIOV4_VXLAN= 15, /* 2016-11-01 lijia add, for MARSIO-4.0, vxlan������� */
CAP_MODEL_PAG_MARSIO = 16, /* 2017-04-07 lijia add, for marsio compat pag */
CAP_MODEL_TUN = 17, /* 2020-02-20 lijia add, for tun mode */
__CAP_MODEL_MAX = 18,
};
enum send_packet_way{
SEND_WAY_PLATFORM = 1, /* �ϲ�Ӧ�÷�����ʽ,ʹ��ƽ̨����, ��ʱ������RST��ԭʼ����ʹ�� */
SEND_WAY_DLL = 2, /* �ϲ�Ӧ�÷�����ʽ,ʹ�õ�������̬�� */
};
enum send_packet_type{
SEND_TYPE_LINK_INJECT = 1, /* ������������, ������·ע��, ��RST, α����� */
SEND_TYPE_LOG = 2, /* ������������, �ش���־ */
SEND_TYPE_REDIRECT = 3, /* ������������, ���ݰ��ض���, ��ˮ��е�ԭʼ����ת�� */
SEND_TYPE_FEEDBACK = 4, /* ������������, ���ݻش�����, ��YSP�Ľ�Ŀ */
};
enum send_fake_packet_mode{
SEND_PKT_MODE_STACK_3_LAYER = 0, /* ��������ģʽ��Э��ջ���㷢��, ����ģʽ��Ĭ�Ϸ�ʽ */
SEND_PKT_MODE_STACK_2_LAYER_1_ROUTE = 1, /* ��������ģʽ��Э��ջ���㷢������һĿ��·��*/
SEND_PKT_MODE_STACK_2_LAYER_MUTI_ROUTE = 2, /* ��������ģʽ��Э��ջ���㷢�������Ŀ��·��*/
SEND_PKT_MODE_GDEV = 3, /* ��������ģʽ�� gdevע�� */
SEND_PKT_MODE_DEFAULT = 4, /* ��������ģʽ�� Ĭ�� */
};
typedef int (*PACKET_IO_CB_T)(const raw_pkt_t *p_raw_pkt,unsigned char dir,int thread_num);
typedef void (*PACKET_IO_EXIT_CB_T)(void);
typedef void (*PACKET_IO_EXIT_PER_THREAD_CB_T)(int thread_seq);
extern PACKET_IO_CB_T G_DEFAULT_PKT_CB;
#ifndef MAX_METADATA_LEN
#define MAX_METADATA_LEN 64
#endif
struct rawpkt_metadata
{
char data[MAX_METADATA_LEN];
unsigned int link_id;
unsigned int sz_data;
struct segment_id_list raw_sid_list;
};
/* ���в�����IJ�������ȫ��, ����Щ��������ȫ֧��, ��Ϊ�˼�����, һ��Ҫ��֤�д˷���, д���պ������� */
typedef struct{
int (*dl_io_set_cap_level)(int cap_level);
int (*dl_io_set_cap_mode)(int cap_mode);
int (*dl_io_set_topology_mode)(int topology_mode);
int (*dl_io_set_capdev_parallel)(const char *cap_dev);
int (*dl_io_set_capdev_serial)(const char *up_dev, const char *down_dev);
int (*dl_io_set_capture_filter)(const char *filter_rule);
int (*dl_io_set_cap_buf_queue)(int queue_num_max);
int (*dl_io_set_work_thread_num)(int thread_num_max);
long (*dl_io_get_app_drop_num)(int thread_num);
long (*dl_io_get_lib_drop_num)(void);
unsigned char * (*dl_io_get_sendbuf)(void *, int );
void (*dl_io_free_sendbuf)(void *, int thread_num);
void * (*dl_io_get_send_handle)(int thread_num);
int (*dl_io_low_level_send)(void *phandle, unsigned char *data,int datalen,
int eth_carry_layer_addr_type, int dir,int thread_num, const raw_pkt_t *raw_pkt); /* ����ethernet�� */
int (*dl_io_raw_pkt_send)(void *phandle, unsigned char *data,int datalen, void *arg, int thread_num,unsigned char, const raw_pkt_t *raw_pkt); /* ȫ��ԭʼ�� */
int (*dl_io_init)(int argc, char *argv[]);
void (*dl_io_run)(void);
int (*dl_io_register_cb)(PACKET_IO_CB_T fun);
int (*dl_io_register_exit_cb)(PACKET_IO_EXIT_CB_T exit_fun);
int (*dl_io_get_version)(void);
void * (*dl_io_device_alias)(unsigned int target_id, char *device_args);
int (*dl_io_send_only_thread_init)(void); /* 2020-06-01 lijia add, ������д����Ķ��������߳�, ��Ҫ���ô˽ӿڰ��ض�CPU������ */
void (*dl_io_free_send_handle)(int thread_seq, void *handle);
void (*dl_io_destroy)(void);
void (*dl_io_stop)(void);
void (*dl_io_device_alias_free)(unsigned int target_id, char *device_args);
int (*dl_io_smart_offload)(int device_index, unsigned char *pkt_ptr, int pkt_len, unsigned char dir, int thread_num);
int (*dl_io_forward_rawpkt)(const raw_pkt_t *raw_pkt, int thread_seq);
void (*dl_io_free_rawpkt)(const raw_pkt_t *raw_pkt, int thread_seq);
struct rawpkt_metadata *(*dl_io_get1_rawpkt_meta)(const raw_pkt_t *raw_pkt, int thread_seq);
void (*dl_io_free_rawpkt_meta)(struct rawpkt_metadata *, int thread_seq);
}dl_io_fun_list_t;
/* ���º����������, ������ȷ���������������� */
int packet_io_set_cap_mode(int cap_model);
int packet_io_set_topology_mode(int user_topology_mode);
int packet_io_init(int argc, char *argv[]);
void packet_io_run(void); /* not return until error, or use 'CAP_MODEL_PCAP_DUMPFILE' mode */
int packet_io_lib_load(int cap_mode);
int packet_io_set_topology_model(int topology_model);
int packet_io_set_capdev_parallel(const char *cap_dev);
int packet_io_set_capdev_serial(const char *up_dev, const char *down_dev);
/* ���º������Բ���ʽ����, ƽ̨����Ĭ��ֵ, ֻ��֤������������, ���������ý�Ϊ����,
������Ԥ�ڲ���, ���߳�����������д�С��.
*/
int packet_io_set_ipv6_module_enable(int op_switch);
int packet_io_set_capture_filter(const char *filter_rule);
int packet_io_set_cap_buf_queue(int queue_num_max);
int packet_io_set_work_thread_num(int thread_num_max);
long packet_io_get_app_drop_num(int thread_num);
unsigned long packet_io_get_send_pkt_num(int thread_num);
unsigned long packet_io_get_send_pkt_err(int thread_num);
unsigned long packet_io_get_send_pkt_byte(int thread_num);
long packet_io_get_lib_drop_num(void);
long packet_io_get_app_drop_num_tot(void);
int packet_io_register_cb(PACKET_IO_CB_T fun);
unsigned char *packet_io_get_sendbuf(int type, int thread_num);
void packet_io_free_sendbuf(int type, int thread_num);
int packet_io_set_send_dev(const char *send_dev);
int packet_io_set_gateway_mac(const char *gateway_mac);
int packet_io_send_only_thread_init(void);
extern void MESA_runtime_log(int level, char * module, char * fmt, ...);
extern int ipv4_entry(struct streaminfo_private*pfstream, const void *this_layer_data, int thread_num,
unsigned char routedir, const raw_pkt_t *raw_pkt, int);
extern int ipv6_entry(struct streaminfo_private *pfstream, const void *this_layer_data, int thread_num,
unsigned char routedir, const raw_pkt_t *raw_pkt, int);
int eth_entry(struct streaminfo_private *fstream, const void *this_layer_hdr,
int thread_num, unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_hdr);
int IEEE_8021_entry(struct streaminfo_private *pfstream,const void *this_layer_hdr,int thread_num,
unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr, unsigned short ethtype);
int arp_entry(struct streaminfo_private *fstream, const void *this_layer_hdr,
int thread_num, unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr);
extern int ppp_entry(struct streaminfo_private*pfstream, const void *this_layer_data, int thread_num,
unsigned char routedir, const raw_pkt_t *raw_pkt, int);
int pppoe_session_entry(struct streaminfo_private *pfstream, const void *this_layer_hdr,
int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt, int);
int gre_entry(struct streaminfo_private *fstream, const void *this_layer_hdr,
int thread_num, unsigned char dir, const raw_pkt_t *raw_pkt, int);
int mpls_uc_entry(struct streaminfo_private *pfstream,const void *this_layer_data,int thread_num,
unsigned char routedir, const raw_pkt_t *raw_pkt, int);
int mpls_empty_entry(struct streaminfo_private *pfstream,const void *this_layer_data,int thread_num,
unsigned char routedir, const raw_pkt_t *raw_pkt, int);
int teredo_entry(struct streaminfo_private *pfstream,void *this_layer_data,int thread_num,
unsigned char routedir, const raw_pkt_t *raw_packet, int offset_to_raw_pkt_hdr);
int gtp_entry(struct streaminfo_private *pfstream,void *this_layer_data,int thread_num,
unsigned char routedir, const raw_pkt_t *raw_packet, int offset_to_raw_pkt_hdr);
int icmp_entry(struct streaminfo_private *fstream, const void *this_layer_hdr,
int thread_num, unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr) ;
//int MESA_sendpacket_ethlayer(int thread_num,const char *data, int data_len, unsigned char compat_no_use);
int l2tpv2_entry(struct streaminfo_private *pfstream_pr,const void *this_layer_data,int thread_num,
unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr);
int mac_in_mac_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr,int thread_num,
unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr);
#ifdef __cplusplus
}
#endif
#endif
|