summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-09-13 15:01:42 +0800
committeryangwei <[email protected]>2024-09-13 15:01:42 +0800
commita9bc2b4782a448c68f9529da628e6e552844f47f (patch)
tree7ff141ff7cbd08515b7cb72c379b20cfff5583fb
parentb33538ce63f4390bdaa14ebab641aeb6b98d7e58 (diff)
✨ feat(packet_io pcap): dumpfile模式下,插入polling时间片
-rw-r--r--src/packet_io/packet_io_pcap.c151
1 files changed, 78 insertions, 73 deletions
diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c
index a26fcf5..f5a6bf5 100644
--- a/src/packet_io/packet_io_pcap.c
+++ b/src/packet_io/packet_io_pcap.c
@@ -19,14 +19,14 @@ static int g_pcap_version_internal = 20210907;
#define PCAP_SNAPLEN_MAX (65535)
typedef struct{
- int raw_eth_fd; /* �����ڷ���Ethernetԭʼ���� */
+ int raw_eth_fd; /* �����ڷ���Ethernetԭʼ���� */
int thread_num;
struct sockaddr saddr_up;
struct sockaddr saddr_down;
UINT8 pcap_send_buf[SENDPACKET_BUF_LEN];
}pcap_send_handle;
-/* ����ģʽ, ���ڲ��Ԫ�黹������Ԫ��, TODO:�����󿪷�, �Ժ����֧����Ԫ�� */
+/* ����ģʽ, ���ڲ��Ԫ�黹������Ԫ��, TODO:�����󿪷�, �Ժ����֧����Ԫ�� */
typedef enum{
PCAP_DISTMODE_INNER_TUPLE2,
PCAP_DISTMODE_OUTER_TUPLE2,
@@ -49,7 +49,7 @@ static struct bpf_program g_pcap_bpf_filter_bin;
static int g_pcap_buf_queue_num = 10000;
static int g_pcap_cap_mode = CAP_MODEL_PCAP_ONLINE;
static int g_pcap_topology_mode = NET_CONN_PARALLEL;
-static int g_pcap_cap_level = CAP_LEVEL_MAC; /* ���Ⲷ����ʼλ��,Ĭ��MAC�� */
+static int g_pcap_cap_level = CAP_LEVEL_MAC; /* ���Ⲷ����ʼλ��,Ĭ��MAC�� */
static int g_pcap_work_thread_num = 1;
static pcap_t *pcap_up_handle; /* if in parallel mode, use this arg */
static pcap_t *pcap_down_handle;
@@ -57,10 +57,10 @@ static PACKET_IO_CB_T g_pcap_work_fun;
static PACKET_IO_EXIT_CB_T g_pcap_exit_cb_fun;
static volatile long pcap_app_drop_num[MAX_THREAD_NUM];
static volatile int get_pcap_lib_drop_flag = 0;
-static volatile long pcap_lib_drop_up_num = 0; /* ����ģʽĬ��ʹ�ô˱����洢 */
+static volatile long pcap_lib_drop_up_num = 0; /* ����ģʽĬ��ʹ�ô˱����洢 */
static volatile long pcap_lib_drop_down_num = 0;
-static struct mesa_ethernet_hdr *raw_pkt_hdr[MAX_THREAD_NUM]; /* ��¼ԭʼ��ͷָ��, ���ڷ�����ȡMAC��ַ�� */
-static unsigned char raw_pkt_route_dir[MAX_THREAD_NUM]; /* ��¼ԭʼ������, ���ڷ������ݰ� */
+static struct mesa_ethernet_hdr *raw_pkt_hdr[MAX_THREAD_NUM]; /* ��¼ԭʼ��ͷָ��, ���ڷ�����ȡMAC��ַ�� */
+static unsigned char raw_pkt_route_dir[MAX_THREAD_NUM]; /* ��¼ԭʼ������, ���ڷ������ݰ� */
static unsigned long long tot_up_rcv_pkt_num, tot_down_rcv_pkt_num;
static int pcap_device_up_mtu = 1500;
static int pcap_device_down_mtu = 1500;
@@ -75,17 +75,17 @@ extern void timestamp_record(enum timestamp_level level, const raw_pkt_t *raw_pk
extern void timestamp_record_lib(const raw_pkt_t *raw_pkt);
/*
- ע���������,
+ ע���������,
"set timestamp record minimum xxx",
- ����ʱ��С��xxxʱ����ʾ.
- ��ʱ��Ϊ���¼�������:
+ ����ʱ��С��xxxʱ����ʾ.
+ ��ʱ��Ϊ���¼�������:
- Ӳ��ʱ���--->��ײ��õ���-->IPv4�����-->befor_stream_process()->after_stream_process()
+ Ӳ��ʱ���--->��ײ��õ���-->IPv4�����-->befor_stream_process()->after_stream_process()
- �ֱ���__pkt_handle, ipv4_entry, stream_process()����ǰ���¼ʱ��:
+ �ֱ���__pkt_handle, ipv4_entry, stream_process()����ǰ���¼ʱ��:
"netdev--xxx---libentry---xxx---IPv4_entry---xxx---Before_call_plug---xxx---After_call_plug
- ����ÿ��ֻ��ӡʱ��ֵ, ��Ҫ��ʾ��,
+ ����ÿ��ֻ��ӡʱ��ֵ, ��Ҫ��ʾ��,
"0 -- 1 -- 4 -- 10 -- 20"
*/
@@ -118,7 +118,7 @@ typedef struct {
static pcap_work_thread_t work_thread_pool[MAX_THREAD_NUM];
-#if PROCESS_BAR_SW /* 2013-12-04 LiJia add, for ���������ʵʱ��ʾ */
+#if PROCESS_BAR_SW /* 2013-12-04 LiJia add, for ���������ʵʱ��ʾ */
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -132,7 +132,7 @@ static unsigned long dumpfile_read_size = 0;
static char process_bar[100][101];
static unsigned long PKTps = 500000;
static int dumpfile_according_timestamp = 0;
-static long long dumpfile_timestamp_diff_with_start = 0; /* ��ǰ��������ʱ�����յ���һ������ʱ����IJ�ֵ */
+static long long dumpfile_timestamp_diff_with_start = 0; /* ��ǰ��������ʱ�����յ���һ������ʱ����IJ�ֵ */
static long long __get_current_time_in_ms(void)
{
@@ -228,7 +228,7 @@ static const char* format_pretty_timeval(struct timeval start, struct timeval en
const char* beautify_size(long bytes) {
- static char beautify_size_result[100]; // Ϊ����ַ��������ڴ�
+ static char beautify_size_result[100]; // Ϊ����ַ��������ڴ�
if(bytes >= 1073741824) {
sprintf(beautify_size_result, "%.2f G", bytes / 1073741824.0);
} else if(bytes >= 1048576) {
@@ -272,7 +272,7 @@ static double process_bar_calc_byte_per_sec(void)
}
-/* ��������������, ����һ��ƽ��ֵ */
+/* ��������������, ����һ��ƽ��ֵ */
static double process_bar_calc_byte_per_sec_average(void)
{
double __pass_bpms = 0.0;
@@ -348,7 +348,7 @@ static void process_bar_print(int len)
strcpy(read_size_str, read_size_ptr);
total_size_ptr = beautify_size(dumpfile_total_size);
strcpy(total_size_str, total_size_ptr);
- /* �²�ʣ��ʱ�� */
+ /* �²�ʣ��ʱ�� */
bytes_per_sec = process_bar_calc_byte_per_sec_average();
if((percent < 99.0) && (bytes_per_sec > 100000.0) && (dumpfile_total_size-dumpfile_read_size > 100000)){
remain_time = ((double)(dumpfile_total_size-dumpfile_read_size)/bytes_per_sec);
@@ -376,7 +376,7 @@ static void process_bar_print(int len)
#if 0
- /* Ԥ���������ʱ�� */
+ /* Ԥ���������ʱ�� */
bytes_per_sec = process_bar_get_pps();
if(bytes_per_sec > 0){
printf("^_^ I guess, read file dumpfile over need time: \033[41m %fs \033[0m \n", (float)(dumpfile_total_size-dumpfile_read_size)/(float)bytes_per_sec);
@@ -423,9 +423,9 @@ inline void process_bar_print(int len)
/*
TODO,
- �˹���Ҫ�ٳ���һ��, �����ڲ�tcp�������, ��MTU�������ļ�����, ����д��!
- ����������������Э��, ��vxlan�ȵ�,
- ����֤������ݰ��ܱ���ַ���(����IP��Ƭ), ������֤���紫��Ŀɿ���.
+ �˹���Ҫ�ٳ���һ��, �����ڲ�tcp�������, ��MTU�������ļ�����, ����д��!
+ ����������������Э��, ��vxlan�ȵ�,
+ ����֤������ݰ��ܱ���ַ���(����IP��Ƭ), ������֤���紫��Ŀɿ���.
*/
static int sendpacket_tcp_offload(char *raw_data, int raw_datalen, int fd, const struct sockaddr *sa)
{
@@ -465,11 +465,11 @@ static int sendpacket_tcp_offload(char *raw_data, int raw_datalen, int fd, const
}
#endif
- fix_hdr_len = sizeof(struct sendpacket_ethernet_hdr) + raw_ip_hdr->ip_hl * 4 + raw_tcp_hdr->th_off * 4; /* �̶�ͷ������, ������ѡ�� */
+ fix_hdr_len = sizeof(struct sendpacket_ethernet_hdr) + raw_ip_hdr->ip_hl * 4 + raw_tcp_hdr->th_off * 4; /* �̶�ͷ������, ������ѡ�� */
memcpy(tmp_send_buf, raw_data, fix_hdr_len);
send_seq = ntohl(raw_tcp_hdr->th_seq);
- leftlen = ntohs(raw_ip_hdr->ip_len) - raw_ip_hdr->ip_hl * 4 - raw_tcp_hdr->th_off * 4; /* ʣ��Ĵ�TCP���ز��ֳ��� */
+ leftlen = ntohs(raw_ip_hdr->ip_len) - raw_ip_hdr->ip_hl * 4 - raw_tcp_hdr->th_off * 4; /* ʣ��Ĵ�TCP���ز��ֳ��� */
data = raw_data + fix_hdr_len;
send_ip_hdr = (struct sendpacket_ip_hdr *)(tmp_send_buf+ sizeof(struct sendpacket_ethernet_hdr));
send_tcp_hdr = (struct mesa_tcp_hdr *)(tmp_send_buf+ sizeof(struct sendpacket_ethernet_hdr) + send_ip_hdr->ip_hl*4);
@@ -478,12 +478,12 @@ static int sendpacket_tcp_offload(char *raw_data, int raw_datalen, int fd, const
retry_times = 0;
this_send_len = MIN(leftlen, TCP_TSO_SPLIT_MTU);
- memcpy(tmp_send_buf + fix_hdr_len, data, this_send_len); /* ��Ҫ����У���, �����޸�ԭʼ��, copy����ʱ������ */
+ memcpy(tmp_send_buf + fix_hdr_len, data, this_send_len); /* ��Ҫ����У���, �����޸�ԭʼ��, copy����ʱ������ */
send_ip_hdr->ip_len = htons(raw_ip_hdr->ip_hl * 4 + raw_tcp_hdr->th_off * 4 + this_send_len);
- send_tcp_hdr->th_seq = htonl(send_seq); /* ���TCP����, ��������, ACK���� */
+ send_tcp_hdr->th_seq = htonl(send_seq); /* ���TCP����, ��������, ACK���� */
/* NOTE:
- ע��, �˴�����ʹ�ù̶�����sizeof(struct sendpacket_tcp_hdr),
- ��Ϊʵ�ʰ�ͷ�п��ܰ���ѡ��, Ҫʹ��ԭʼ����ʵ�ʳ���: raw_tcp_hdr->th_off * 4.
+ ע��, �˴�����ʹ�ù̶�����sizeof(struct sendpacket_tcp_hdr),
+ ��Ϊʵ�ʰ�ͷ�п��ܰ���ѡ��, Ҫʹ��ԭʼ����ʵ�ʳ���: raw_tcp_hdr->th_off * 4.
*/
sendpacket_do_checksum((unsigned char *)send_ip_hdr, IPPROTO_TCP, raw_tcp_hdr->th_off*4 + this_send_len);
sendpacket_do_checksum((unsigned char *)send_ip_hdr, IPPROTO_IP, raw_ip_hdr->ip_hl * 4);
@@ -618,7 +618,7 @@ int pcap_dl_io_set_work_thread_num(int thread_num_max)
return 0;
}
-/* �˽ӿ����pagģʽ����rst, ���ݺ���־, pcapģʽ������ */
+/* �˽ӿ����pagģʽ����rst, ���ݺ���־, pcapģʽ������ */
int pcap_dl_io_set_send_type(int send_type)
{
return 0;
@@ -639,13 +639,13 @@ long pcap_dl_io_get_lib_drop_num(void)
void * pcap_dl_io_device_alias(unsigned int target_id, char *device_args)
{
- /* ����pcapģʽ��˵, �����豸���� eth1, eth2, etc. */
+ /* ����pcapģʽ��˵, �����豸���� eth1, eth2, etc. */
return (void *)sapp_strdup(device_args);
}
void pcap_dl_io_device_alias_free(unsigned int target_id, char *device_args)
{
- /* ����pcapģʽ��˵, �����豸���� eth1, eth2, etc. */
+ /* ����pcapģʽ��˵, �����豸���� eth1, eth2, etc. */
SAPP_GLOBAL_FREE(device_args);
}
@@ -677,7 +677,7 @@ void pcap_dl_io_free_sendbuf(void *phandle, int thread_num)
(void)phandle;
(void)thread_num;
- /* PCAPģʽ�����ͷ� */
+ /* PCAPģʽ�����ͷ� */
return;
}
@@ -736,9 +736,9 @@ int pcap_dl_io_raw_pkt_send(void *phandle, unsigned char *data,int datalen, void
strncpy(snd_addr.sa_data, snd_raw_args->dev_name, sizeof(snd_addr.sa_data));
snd_addr.sa_family = PF_INET;
-/* 2017-02-28 lijia add, for tcp offload sendback, ijЩ���߰����������, GRO, GSO�����Թز���, ���´���ģʽ������� */
- //TODO, �˴�����Ҫ�Ƶ�sapp���ϲ㷢���ӿ�, ������ô�ײ�Ľӿ���offload, ��Ϊ�������漰��marsioģʽ
- //���ݷ���������MTU�Զ��ж�, �Ƿ���Ҫoffload.
+/* 2017-02-28 lijia add, for tcp offload sendback, ijЩ���߰����������, GRO, GSO�����Թز���, ���´���ģʽ������� */
+ //TODO, �˴�����Ҫ�Ƶ�sapp���ϲ㷢���ӿ�, ������ô�ײ�Ľӿ���offload, ��Ϊ�������漰��marsioģʽ
+ //���ݷ���������MTU�Զ��ж�, �Ƿ���Ҫoffload.
#if 0
if(datalen > 1514){
if(sapp_global_single.cfg_send_tcp_offload_sw){
@@ -756,7 +756,7 @@ send_again:
ret = sendto(send_handle->raw_eth_fd, data, datalen, 0, (struct sockaddr *)&snd_addr, sizeof(struct sockaddr));
if(ret < 0){
if(EINTR == errno){
- goto send_again; /* ���жϻ򻺴������·���ʧ��, ���� */
+ goto send_again; /* ���жϻ򻺴������·���ʧ��, ���� */
}else if((EAGAIN == errno) || (ENOBUFS == errno)){
if(retry_times++ < 5){
goto send_again;
@@ -783,7 +783,7 @@ int pcap_dl_io_low_level_send(void *phandle, UINT8 *data,int datalen,
int ret;
struct sockaddr *snd_addr;
- /* 2018-07-26 lijia add, �����˲���Լ��������̷߳�������, ���DZ��뷢��������ethernet��, �ײ�mac�������޷���� */
+ /* 2018-07-26 lijia add, �����˲���Լ��������̷߳�������, ���DZ��뷢��������ethernet��, �ײ�mac�������޷���� */
if(thread_num >= g_pcap_work_thread_num){
sapp_runtime_log(30, "\033[1;31;40m send thread_seq is:%d, bigger than total thread num(%d) !\033[0m\n", thread_num, g_pcap_work_thread_num);
return -1;
@@ -806,7 +806,7 @@ int pcap_dl_io_low_level_send(void *phandle, UINT8 *data,int datalen,
}
//net_common_build_send_mac(data, raw_pkt_hdr[thread_num], eth_carry_layer_addr_type, dir_reverse,g_pcap_topology_mode);
- /* delete by lijia 2014-12-10, datalen�Ѿ�������mac��ַ���� */
+ /* delete by lijia 2014-12-10, datalen�Ѿ�������mac��ַ���� */
//datalen += sizeof(struct mesa_ethernet_hdr);
packet_io_hook_sendto(raw_pkt, dir, (char *)data, NULL);
@@ -898,9 +898,9 @@ static int pcap_forward_pkt(int thread_num, const unsigned char *data,int data_l
struct sockaddr *sock_addr;
if(NET_CONN_SERIAL_GDEV == g_pcap_topology_mode){
- /* �����豸ģʽ, �շ�ʹ��ͬһ������ */
+ /* �����豸ģʽ, �շ�ʹ��ͬһ������ */
sock_addr = &work_thread_pool[thread_num].sock_addr_up;
-#if 0 //2020-12-25 , v4.2�汾�� packet_io_hook_output_vxlan()�����Ѿ��޸��˸����ַ, �˴�ֱ��ת������.
+#if 0 //2020-12-25 , v4.2�汾�� packet_io_hook_output_vxlan()�����Ѿ��޸��˸����ַ, �˴�ֱ��ת������.
net_common_adjust_forward_mac((struct mesa_ethernet_hdr *)data, g_pcap_topology_mode);
#endif
}else{
@@ -936,7 +936,7 @@ static void pcap_clear_pkt_queue_left(int thread_index)
sapp_usleep(1);
}
- if(NET_CONN_SERIAL_2CARD == g_pcap_topology_mode){ /* ˫��������ģʽ */
+ if(NET_CONN_SERIAL_2CARD == g_pcap_topology_mode){ /* ˫��������ģʽ */
while(0 == g_pcap_io_stop_flag_down){
sapp_usleep(1);
}
@@ -952,7 +952,7 @@ static void pcap_clear_pkt_queue_left(int thread_index)
}
if(PCAP_OP_FLAG_PKT == pkt_queue_node.op_flag){
ret = (*g_pcap_work_fun)(&(pkt_queue_node.raw_pkt), pkt_queue_node.raw_pkt.route_dir, thread_index);
- /* ����ģʽ�ҷ���ֵΪPASS, ��Ҫת���� */
+ /* ����ģʽ�ҷ���ֵΪPASS, ��Ҫת���� */
if((g_pcap_topology_mode & __NET_CONN_SERIAL) && (PASS == ret)){
pcap_forward_pkt(thread_index, (unsigned char *)pkt_queue_node.raw_pkt.__lib_raw_pkt_data,
pkt_queue_node.raw_pkt.__lib_raw_pkt_len, pkt_queue_node.raw_pkt.route_dir);
@@ -975,7 +975,7 @@ static void *__pcap_work_thread(void *arg)
int ret;
int total_call_times = 0, rcv_pkt_tims = 0, polling_work_times = 0;
-#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 480) /* �汾�ж�, �ܶ��ϵͳ�޷����� */
+#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 480) /* �汾�ж�, �ܶ��ϵͳ�޷����� */
#ifdef _GNU_SOURCE
pthread_setname_np(pthread_self(), "sapp_pkt_process");
#endif
@@ -996,7 +996,7 @@ static void *__pcap_work_thread(void *arg)
}
/* for perf optimize
- Ƶ������stream_process_polling()�Ⱥ���, �˴����ں����ⲿ�ж�һ���Ƿ���Ҫ����.
+ Ƶ������stream_process_polling()�Ⱥ���, �˴����ں����ⲿ�ж�һ���Ƿ���Ҫ����.
*/
int polling_enabled = sapp_global_val->config.packet_io.polling_priority;
@@ -1037,11 +1037,15 @@ static void *__pcap_work_thread(void *arg)
total_call_times++;
if (total_call_times >= sapp_global_val->config.packet_io.polling_priority)
{
- /* ��������޴�, һֱ�а�ʱ, ÿ��polling_priority����ҲҪ����polling�ӿ� */
+
if (polling_enabled && (stream_process_polling(thread_num) & POLLING_STATE_WORK))
{
polling_work_times++;
}
+ if (polling_enabled && (polling_stream_timeout(thread_num) & POLLING_STATE_WORK))
+ {
+ polling_work_times++;
+ }
}
if (total_call_times >= 100)
{
@@ -1073,7 +1077,7 @@ static void *__pcap_work_thread(void *arg)
if (pkt_queue_node.raw_pkt.__lib_raw_pkt_len > 0 && pkt_queue_node.raw_pkt.__lib_raw_pkt_data != NULL)
{
ret = (*g_pcap_work_fun)(&(pkt_queue_node.raw_pkt), pkt_queue_node.raw_pkt.route_dir, thread_num);
- /* ����ģʽ�ҷ���ֵΪPASS, ��Ҫת���� */
+ /* ����ģʽ�ҷ���ֵΪPASS, ��Ҫת���� */
if ((g_pcap_topology_mode & __NET_CONN_SERIAL) && (PASS == ret))
{
pcap_forward_pkt(thread_num, (unsigned char *)pkt_queue_node.raw_pkt.__lib_raw_pkt_data,
@@ -1087,7 +1091,7 @@ static void *__pcap_work_thread(void *arg)
PCAP_FREE((void *)(pkt_queue_node.raw_pkt.__lib_raw_pkt_data));
}
- /* pcapʹ���첽ģʽ, ��������п��ܻ���δ���������ݰ� */
+ /* pcapʹ���첽ģʽ, ��������п��ܻ���δ���������ݰ� */
pcap_clear_pkt_queue_left(thread_num);
libsapp_destroy_env_per_thread(thread_num);
@@ -1126,7 +1130,7 @@ static int pcap_create_work_thread(void)
assert(0);
}
work_thread_pool[i].op_status = PCAP_OP_FLAG_PKT;
- /* ע��:�˴�����MESA_lqueue�Դ����̰߳�ȫ��, Ϊ��ʵ��__pcap_work_thread()��cond_wait����. */
+ /* ע��:�˴�����MESA_lqueue�Դ����̰߳�ȫ��, Ϊ��ʵ��__pcap_work_thread()��cond_wait����. */
work_thread_pool[i].pkt_queue = MESA_lqueue_create(0, g_pcap_buf_queue_num+1);
ret = pthread_create(&work_thread_pool[i].work_tid, NULL, __pcap_work_thread, &work_thread_pool[i].thread_num);
@@ -1195,7 +1199,7 @@ static unsigned int __pcap_dispatch_thread(const u_char *data)
}
if(res){
ipv6_hdr = (const struct ip6_hdr *)res;
- /* ֻʹ��IPv6��ַ��һ���� */
+ /* ֻʹ��IPv6��ַ��һ���� */
if(memcmp(&ipv6_hdr->ip6_src.s6_addr32[3], &ipv6_hdr->ip6_dst.s6_addr32[3], sizeof(int)) >= 0){
disp_arg1 = (unsigned char *)&ipv6_hdr->ip6_src;
disp_arg2 = (unsigned char *)&ipv6_hdr->ip6_dst;
@@ -1207,8 +1211,8 @@ static unsigned int __pcap_dispatch_thread(const u_char *data)
goto disp;
}
- /* ��IPv4, ��IPv6Э��, ��ʱ����0, �̶���һ���̴߳���.
- to do: ʶ�𾡿��ܶ����֪Э������, ����һ��hashֵ.
+ /* ��IPv4, ��IPv6Э��, ��ʱ����0, �̶���һ���̴߳���.
+ to do: ʶ�𾡿��ܶ����֪Э������, ����һ��hashֵ.
*/
return 0;
@@ -1315,7 +1319,7 @@ static int gen_route_dir_for_dumpfile_mode(const u_char *data)
}
/*
- todo, ����IP��ַһ����ô��? ����127.0.0.1����ͨ��, �ٱȶ˿�.
+ todo, ����IP��ַһ����ô��? ����127.0.0.1����ͨ��, �ٱȶ˿�.
*/
return route_dir;
@@ -1349,6 +1353,7 @@ static void __pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const
dumpfile_wait_according_timestamp(hdr);
}
+ __pcap_nodify_work_thread(PCAP_OP_FLAG_IDLE_POLLING);
}
#if 0
@@ -1366,7 +1371,7 @@ retry:
}else{
if(CAP_MODEL_PCAP_DUMPFILE == g_pcap_cap_mode){
sapp_usleep(1);
- goto retry; /* �ڶ���ģʽ��, ��֤��������������� */
+ goto retry; /* �ڶ���ģʽ��, ��֤��������������� */
}
pcap_app_drop_num[thread_num]++;
}
@@ -1388,17 +1393,17 @@ retry:
memcpy((void *)(pkt_queue_node.raw_pkt.__lib_raw_pkt_data), data, hdr->caplen);
//pkt_queue_node.raw_pkt.raw_pkt_len = hdr->len;
/* 2015-09-28 lijia modify,
- �˴�Ҫʹ��caplen, ��Ϊ��������û�м�-s0ѡ��, ʵ�ʲ��������۰�����һ��!
+ �˴�Ҫʹ��caplen, ��Ϊ��������û�м�-s0ѡ��, ʵ�ʲ��������۰�����һ��!
*/
pkt_queue_node.raw_pkt.__lib_raw_pkt_len = hdr->caplen;
- /* pcap��ͷ��timestamp������32bit��, ʹ�õ�����ֵ��� */
+ /* pcap��ͷ��timestamp������32bit��, ʹ�õ�����ֵ��� */
pkt_queue_node.raw_pkt.raw_pkt_ts.tv_sec = hdr->ts.tv_sec;
pkt_queue_node.raw_pkt.raw_pkt_ts.tv_usec = hdr->ts.tv_usec;
pkt_queue_node.raw_pkt.low_layer_type = (enum addr_type_t)g_pcap_cap_level;
pkt_queue_node.raw_pkt.magic_num = RAW_PKT_MAGIC_NUM; /* 2014-12-11 lijia add */
- pkt_queue_node.raw_pkt.hd_hash = 0; /* 2016-05-05 lijia add, pcapģʽ��֧��Ӳ��HASH */
- pkt_queue_node.raw_pkt.io_lib_pkt_reference = pkt_queue_node.raw_pkt.__lib_raw_pkt_data; /* ����dpdkģʽ, ���˱�����ֵ */
+ pkt_queue_node.raw_pkt.hd_hash = 0; /* 2016-05-05 lijia add, pcapģʽ��֧��Ӳ��HASH */
+ pkt_queue_node.raw_pkt.io_lib_pkt_reference = pkt_queue_node.raw_pkt.__lib_raw_pkt_data; /* ����dpdkģʽ, ���˱�����ֵ */
pkt_queue_node.raw_pkt.vlan_flipping_couple[0] = 0;
pkt_queue_node.raw_pkt.vlan_flipping_couple[1] = 0;
pkt_queue_node.raw_pkt.mac_flipping_enable = 0;
@@ -1408,7 +1413,7 @@ retry:
pkt_queue_node.raw_pkt.d_pkt = NULL;
if(CAP_MODEL_PCAP_DUMPFILE == g_pcap_cap_mode){
- /* ����ģʽ�±���û��routedir�ĸ���, Ϊ�˱��ڲ����ϲ�ҵ��, ʹ����ײ��ַ�Ƚ����һ��routedir */
+ /* ����ģʽ�±���û��routedir�ĸ���, Ϊ�˱��ڲ����ϲ�ҵ��, ʹ����ײ��ַ�Ƚ����һ��routedir */
pkt_queue_node.raw_pkt.route_dir = gen_route_dir_for_dumpfile_mode(data);
}else{
pkt_queue_node.raw_pkt.route_dir = *((unsigned char *)user);
@@ -1439,11 +1444,11 @@ retry:
{
MESA_sleep();
}
- goto retry; /* �ڶ���ģʽ��, ��֤���������������, Ҫ�������� */
+ goto retry; /* �ڶ���ģʽ��, ��֤���������������, Ҫ�������� */
}
else
{
- pcap_app_drop_num[thread_num]++; /* ����ģʽ��¼������ */
+ pcap_app_drop_num[thread_num]++; /* ����ģʽ��¼������ */
PCAP_FREE((void *)(pkt_queue_node.raw_pkt.__lib_raw_pkt_data));
}
}
@@ -1504,7 +1509,7 @@ static void wait_all_work_thread(void)
if(1 == update_packet_io_status_sw){
- sysinfo_output(); /* ���һ��дͳ����Ϣ, �رձ�־λ, ��Ϊ�����������, ��д��û������ */
+ sysinfo_output(); /* ���һ��дͳ����Ϣ, �رձ�־λ, ��Ϊ�����������, ��д��û������ */
update_packet_io_status_sw = 0;
}
@@ -1571,7 +1576,7 @@ static void pcap_io_dumpfile_list(void)
pcap_close(pcap_handle);
pcap_up_handle = NULL;
- dumpfile_timestamp_diff_with_start = 0; /* ÿ��pcap����ʱ�������һ��, ��������������ʱ��� */
+ dumpfile_timestamp_diff_with_start = 0; /* ÿ��pcap����ʱ�������һ��, ��������������ʱ��� */
}
pcap_file_num++;
dumpfile_list_total_pkt+=dumpfile_total_cnt;
@@ -1589,7 +1594,7 @@ static void pcap_io_dumpfile_list(void)
static void *pcap_io_thread(void *arg)
{
- long route_dir_arg = (long)arg; /* �ӹ�������precision��� */
+ long route_dir_arg = (long)arg; /* �ӹ�������precision��� */
unsigned char route_dir = (unsigned char)route_dir_arg;
pcap_t *handle;
int pcap_ret;
@@ -1597,7 +1602,7 @@ static void *pcap_io_thread(void *arg)
volatile int *stop_flag;
int exit_prog_flag = 0;
-#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 480) /* �汾�ж�, �ܶ��ϵͳ�޷����� */
+#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 480) /* �汾�ж�, �ܶ��ϵͳ�޷����� */
#ifdef _GNU_SOURCE
pthread_setname_np(pthread_self(), "sapp");
#endif
@@ -1669,7 +1674,7 @@ int pcap_dl_io_init(int argc, char *argv[])
printf("\033[41m Warning! 'PCAP_CAP_FROM_IP' is enable!. \033[0m\n");
#endif
- if(CAP_MODEL_PCAP_DUMPFILE == g_pcap_cap_mode) /* pcap���ض���ģʽ */
+ if(CAP_MODEL_PCAP_DUMPFILE == g_pcap_cap_mode) /* pcap���ض���ģʽ */
{
if(g_pcap_topology_mode & __NET_CONN_SERIAL){
printf("\033[1;31;40m[Error]cap_mode is %d, but topology is serial!\033[0m\n", g_pcap_cap_mode);
@@ -1679,7 +1684,7 @@ int pcap_dl_io_init(int argc, char *argv[])
process_bar_prt_init(sapp_global_val->config.packet_io.pcap_dumpfile_name);
#endif
if(sapp_get_cla_raw("dumpfile-list", &no_use) >= 0){
- ;//���б�ģʽ, ����˴���dumpfile�ļ�
+ ;//���б�ģʽ, ����˴���dumpfile�ļ�
}else{
time_t curtime;
char *str;
@@ -1698,9 +1703,9 @@ int pcap_dl_io_init(int argc, char *argv[])
pcap_set_filter(pcap_up_handle, g_pcap_cap_filter);
- //g_pcap_topology_model = NET_CONN_PARA_NOSEND; /* ���ض���ģʽ����������ģʽ��Ϊ���������� */
+ //g_pcap_topology_model = NET_CONN_PARA_NOSEND; /* ���ض���ģʽ����������ģʽ��Ϊ���������� */
}
- else /* ����ץ��ģʽ */
+ else /* ����ץ��ģʽ */
{
if((strncasecmp(sapp_global_val->config.packet_io.deployment_mode_str, "transparent", strlen("transparent")) == 0)
&& (strstr(sapp_global_val->config.packet_io.pcap_capture_direction, "out") != NULL)){
@@ -1728,9 +1733,9 @@ int pcap_dl_io_init(int argc, char *argv[])
if(pcap_device_up_mtu < 1500){
printf("\033[41m Warning! '%s' MTU is %d!. \033[0m\n", g_pcap_up_dev_name, pcap_device_up_mtu);
}
- pcap_device_up_mtu += sizeof(struct mesa_ethernet_hdr); /* MTU����ethernet�㳤��, ��pcap�����ǰ�����, ��Ҫ�������ͷ�� */
+ pcap_device_up_mtu += sizeof(struct mesa_ethernet_hdr); /* MTU����ethernet�㳤��, ��pcap�����ǰ�����, ��Ҫ�������ͷ�� */
- if(NET_CONN_SERIAL_2CARD == g_pcap_topology_mode) /* ˫��������ģʽ */
+ if(NET_CONN_SERIAL_2CARD == g_pcap_topology_mode) /* ˫��������ģʽ */
{
pcap_down_handle = pcap_open_live(g_pcap_down_dev_name, PCAP_SNAPLEN_MAX,1,1,pcap_errbuf);
if(NULL == pcap_down_handle)
@@ -1744,7 +1749,7 @@ int pcap_dl_io_init(int argc, char *argv[])
if(pcap_device_down_mtu < 1500){
printf("\033[41m Warning! '%s' MTU is %d!. \033[0m\n", g_pcap_down_dev_name, pcap_device_down_mtu);
}
- pcap_device_down_mtu += sizeof(struct mesa_ethernet_hdr); /* MTU����ethernet�㳤��, ��pcap�����ǰ�����, ��Ҫ�������ͷ�� */
+ pcap_device_down_mtu += sizeof(struct mesa_ethernet_hdr); /* MTU����ethernet�㳤��, ��pcap�����ǰ�����, ��Ҫ�������ͷ�� */
pcap_set_filter(pcap_down_handle, g_pcap_cap_filter);
pcap_setdirection(pcap_down_handle, PCAP_D_IN);
}
@@ -1764,7 +1769,7 @@ int pcap_dl_io_init(int argc, char *argv[])
}else{
if(strncasecmp(dumpfile_speed_mode, "timestamp", strlen("timestamp")) == 0){
dumpfile_according_timestamp = 1;
- dumpfile_timestamp_diff_with_start = 0;/* ��ʼ�����0, ��ȡ����һ����ʱ������pcap����ʱ�����ֵ */
+ dumpfile_timestamp_diff_with_start = 0;/* ��ʼ�����0, ��ȡ����һ����ʱ������pcap����ʱ�����ֵ */
}
}
#endif
@@ -1794,7 +1799,7 @@ void pcap_dl_io_run(void)
pthread_create(&g_pcap_io_pid_up, NULL, pcap_io_thread, (void *)dir_up);
pthread_detach(g_pcap_io_pid_up);
- if(NET_CONN_SERIAL_2CARD == g_pcap_topology_mode){ /* ˫��������ģʽ */
+ if(NET_CONN_SERIAL_2CARD == g_pcap_topology_mode){ /* ˫��������ģʽ */
pthread_create(&g_pcap_io_pid_down, NULL, pcap_io_thread, (void *)dir_down);
pthread_detach(g_pcap_io_pid_down);
}
@@ -1802,7 +1807,7 @@ void pcap_dl_io_run(void)
return;
}
-/* pcap ģʽ���ܱ�pcap_loop()����, ��Ҫ��������pcap_breakloop()�˳���ѭ��״̬ */
+/* pcap ģʽ���ܱ�pcap_loop()����, ��Ҫ��������pcap_breakloop()�˳���ѭ��״̬ */
void pcap_dl_io_stop(void)
{
char *no_use;