diff options
| author | yangwei <[email protected]> | 2024-09-14 17:51:26 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-09-14 17:51:26 +0800 |
| commit | 1b14f987c03adb9ba57a35d715f94facc84cea2d (patch) | |
| tree | c968b6ac655dd8cfcc4d6ada05961781cbdc3508 | |
| parent | 3d484c89b13fca0ea53da3be24e70310b39d8b75 (diff) | |
🐞 fix(internal clock): 拆分为real和monotonic两个时间戳
| -rw-r--r-- | include/private/sapp_declaration.h | 8 | ||||
| -rw-r--r-- | include/private/stream_manage.h | 1 | ||||
| -rw-r--r-- | src/common/sapp_mem.c | 12 | ||||
| -rw-r--r-- | src/dealpkt/deal_ipv6.c | 67 | ||||
| -rw-r--r-- | src/dealpkt/deal_tcp.c | 65 | ||||
| -rw-r--r-- | src/dealpkt/deal_udp.c | 36 | ||||
| -rw-r--r-- | src/dealpkt/duplicate_pkt_distinguish.c | 38 | ||||
| -rw-r--r-- | src/dealpkt/g_device.c | 224 | ||||
| -rw-r--r-- | src/dealpkt/ip_reassembly.c | 68 | ||||
| -rw-r--r-- | src/dealpkt/plug_support.c | 6 | ||||
| -rw-r--r-- | src/dealpkt/stream_manage.c | 50 | ||||
| -rw-r--r-- | src/extensions/inline_keepalive.cpp | 116 | ||||
| -rw-r--r-- | src/extensions/sapp_assistant.cpp | 22 | ||||
| -rw-r--r-- | src/packet_io/cycle_pkt_dump_through_write_offset.c | 289 | ||||
| -rw-r--r-- | src/packet_io/packet_io_log.c | 26 | ||||
| -rw-r--r-- | src/plugin/src/plugin.c | 4 | ||||
| -rw-r--r-- | src/sapp_dev/sapp_init.c | 2 | ||||
| -rw-r--r-- | src/timer/sapp_timer.c | 56 | ||||
| -rw-r--r-- | test/test_app_sapp.c | 2 |
19 files changed, 365 insertions, 727 deletions
diff --git a/include/private/sapp_declaration.h b/include/private/sapp_declaration.h index 4d11b23..14c88a9 100644 --- a/include/private/sapp_declaration.h +++ b/include/private/sapp_declaration.h @@ -20,10 +20,11 @@ extern sapp_global_t *sapp_global_val; extern volatile time_t g_current_time; extern volatile long long g_current_time_ms; +extern volatile time_t g_monotonic_time; +extern volatile long long g_monotonic_time_ms; #define MAX_DEFALUT_TIMEOUT_S 86400 -/* ��Ƕ�ײ��̫��, ʹ�ü������ */ #define ABBR_SAPP_LOG_HANDLE sapp_global_val->individual_fixed.log_handle #define ABBR_SAPP_PLUGIN_LOG_HANDLE sapp_global_val->individual_fixed.plugin_log_handle @@ -34,7 +35,9 @@ extern volatile long long g_current_time_ms; #define ABBR_SAPP_TIMER_HANDLE sapp_global_val->individual_fixed.sapp_timer_handle #define ABBR_SAPP_START_TIME sapp_global_val->individual_fixed.sapp_start_time #define ABBR_CURRENT_TIME g_current_time +#define ABBR_MONOTONIC_TIME g_monotonic_time #define ABBR_CURRENT_TIME_MS g_current_time_ms +#define ABBR_MONOTONIC_TIME_MS g_monotonic_time_ms #define ABBR_INJECT_RST_NUM sapp_global_val->config.stream.tcp.inject.rst_num #define ABBR_INJECT_RST_SIGN sapp_global_val->config.stream.tcp.inject.rst_signature_enable #define ABBR_INTERFACE_TYPE sapp_global_val->config.packet_io.internal.interface.type_bin @@ -64,9 +67,6 @@ extern volatile long long g_current_time_ms; #define ABBR_MARSIO_LIBRARY_FILE sapp_global_val->config.library_file_path.libmarsio_file_path #define ABBR_MEMORY_STAT_LOG_DATA_FILE sapp_global_val->config.data_file_path.data_memory_stat_log_absolute -/* ��֮ǰ��ɢ��ȫ�ֱ���ǿ�Ƹ���Ϊ�µ�ȫ�ֱ��� */ -#define g_CurrentTime_ms g_current_time_ms -#define g_CurrentTime g_current_time #define g_sapp_log_handle sapp_global_val->individual_fixed.log_handle #define g_iThreadNum sapp_global_val->config.cpu.worker_threads #define g_packet_io_thread_num sapp_global_val->config.cpu.worker_threads diff --git a/include/private/stream_manage.h b/include/private/stream_manage.h index 87d4f21..25ab121 100644 --- a/include/private/stream_manage.h +++ b/include/private/stream_manage.h @@ -10,7 +10,6 @@ extern "C" {
#endif
-extern time_t g_CurrentTime;
extern int tcp_default_unorder;
extern unsigned short link_default_nopkt_time;
diff --git a/src/common/sapp_mem.c b/src/common/sapp_mem.c index 0b1395b..a770c70 100644 --- a/src/common/sapp_mem.c +++ b/src/common/sapp_mem.c @@ -190,9 +190,9 @@ void sapp_mem_stat_output(void) char time_string[128]; /* - ��ֹ����������һ������, �����˼ӵ� mem_stat_name_tuple[] ������, ����˳��, �˴�ҪУ��һ��. + ��ֹ����������һ������, �����˼ӵ� mem_stat_name_tuple[] ������, ����˳��, �˴�ҪУ��һ��. - TODO: ��ʵ��ʼ����֤һ�ξ���, û��Ҫÿ�������־ʱ�����!! + TODO: ��ʵ��ʼ����֤һ�ξ���, û��Ҫÿ�������־ʱ�����!! */ int stat_name_tuple_num = sizeof(mem_stat_name_tuple)/sizeof(mem_stat_name_tuple_t); assert(stat_name_tuple_num == __SAPP_MEM_TYPE_MAX); @@ -231,7 +231,7 @@ void sapp_mem_stat_output(void) fix_realtime_stat.mem_used_block[stat_index] += mem_used_stat->mem_used_block[stat_index]; fix_realtime_stat.mem_used_bytes[stat_index] += mem_used_stat->mem_used_bytes[stat_index]; } - /* �̶��ڴ�ʹ�����, SAPP_MEM_FIX_GLOBAL_VAL �Ƚ�����, ֱ�Ӵ�ȫ�ֱ����л�ȡ */ + /* �̶��ڴ�ʹ�����, SAPP_MEM_FIX_GLOBAL_VAL �Ƚ�����, ֱ�Ӵ�ȫ�ֱ����л�ȡ */ fix_realtime_stat.mem_used_block[SAPP_MEM_FIX_GLOBAL_VAL] = g_sapp_global_mem_used_block; fix_realtime_stat.mem_used_bytes[SAPP_MEM_FIX_GLOBAL_VAL] = g_sapp_global_mem_used_bytes; @@ -249,7 +249,7 @@ void sapp_mem_stat_output(void) fprintf(fp, "\n%7s\n", "Dynamic"); - /* �ȰѶ���̵߳���ֵ��� */ + /* �ȰѶ���̵߳���ֵ��� */ for(tseq=0;tseq<g_packet_io_thread_num;tseq++){ mem_used_stat = &sapp_global_val->mthread_volatile[tseq]->mem_used_stat; for(stat_index = __SAPP_MEM_TYPE_INIT+1; stat_index < __SAPP_MEM_TYPE_MAX; stat_index++){ @@ -292,7 +292,7 @@ char bloomfilter_stat_polling_entry(struct streaminfo *nouse1, void **nouse2, in { static time_t last_get_time[SAPP_MAX_THREADS] = {}; - if(ABBR_CURRENT_TIME <= last_get_time[thread_seq]) + if(ABBR_MONOTONIC_TIME <= last_get_time[thread_seq]) { return POLLING_STATE_IDLE; } @@ -303,7 +303,7 @@ char bloomfilter_stat_polling_entry(struct streaminfo *nouse1, void **nouse2, in sapp_global_val->mthread_volatile[thread_seq]->mem_used_stat.mem_used_block[SAPP_MEM_DYN_BLOOM_FILTER] = blocks; sapp_global_val->mthread_volatile[thread_seq]->mem_used_stat.mem_used_bytes[SAPP_MEM_DYN_BLOOM_FILTER] = bytes; - last_get_time[thread_seq] = ABBR_CURRENT_TIME; + last_get_time[thread_seq] = ABBR_MONOTONIC_TIME; return POLLING_STATE_WORK; } diff --git a/src/dealpkt/deal_ipv6.c b/src/dealpkt/deal_ipv6.c index f5847e6..b493e54 100644 --- a/src/dealpkt/deal_ipv6.c +++ b/src/dealpkt/deal_ipv6.c @@ -258,7 +258,6 @@ int ipv6_frag_hash_cmp(void *hash_key1, void *hash_key2) return memcmp(hash_key1, hash_key2, sizeof(struct ipv6_frag_key));
}
-#if USE_MESA_STREAM_HASH
static struct frag_ipq *ipv6_frag_queue_find(struct streaminfo_private *pstream_pr,
struct frag_manage *handle, struct ipv6_frag_key *ip6_frag_key)
{
@@ -283,21 +282,7 @@ static struct frag_ipq *ipv6_frag_queue_find(struct streaminfo_private *pstream_ return frag_ipq;
}
-#else
-static struct frag_ipq *ipv6_frag_queue_find(struct streaminfo_private *pstream_pr, struct frag_manage *handle,
- const struct mesa_ip6_hdr *raw_packet, struct ipv6_frag_hdr *ipv6_frag_hdr)
-{
- struct ipv6_frag_key ip6_key;
- ip6_key.identification = ipv6_frag_hdr->identification;
- ip6_key.pfstream_pr = pstream_pr;
- memcpy(&ip6_key.ip6_src, &raw_packet->ip6_src, sizeof(struct in6_addr));
- memcpy(&ip6_key.ip6_dst, &raw_packet->ip6_dst, sizeof(struct in6_addr));
- ip6_key.__pad__ = 0;
-
- return frag_ipq_find(handle, &ip6_key, sizeof(struct ipv6_frag_key));
-}
-#endif
static inline int ip6_buff_size(int tot_len)
{
@@ -305,58 +290,6 @@ static inline int ip6_buff_size(int tot_len) }
-#if (USE_MESA_STREAM_HASH==0)
-static void ipv6_frag_mem_clean_by_time(struct frag_manage *handle)
-{
- struct frag_ipq *tmp, *next;
- int raw_mem_size = handle->total_mem;
- tmp = handle->lru_head;
-
- while(tmp && (tmp->create_time + (time_t)IPV6_FRAG_TIMEOUT < g_CurrentTime))
- {
- next = tmp->lru_next;
-
- frag_ipq_kill(handle, tmp);
-
- if(raw_mem_size-handle->total_mem >= IPV6_FRAG_MEM_FREE_ONCE)
- {
- break;
- }
-
- tmp = next;
- }
-}
-
-
-static void ipv6_frag_mem_clean_by_size(struct frag_manage *handle)
-{
- struct frag_ipq *tmp, *next;
- int raw_mem_size = handle->total_mem;
- tmp = handle->lru_head;
-
- while(tmp && (handle->total_mem >= IPV6_FRAG_MEM_HIGH_THRESH))
- {
- next = tmp->lru_next;
-
- frag_ipq_kill(handle, tmp);
-
- if(raw_mem_size-handle->total_mem >= IPV6_FRAG_MEM_FREE_ONCE)
- {
- break;
- }
-
- tmp = next;
- }
-}
-
-
-static inline void ipv6_frag_mem_clean(struct frag_manage *handle)
-{
- ipv6_frag_mem_clean_by_time(handle);
- ipv6_frag_mem_clean_by_size(handle);
-}
-#endif
-
#if USE_MESA_STREAM_HASH
void build_ipv6_frag_key(struct streaminfo_private *pfstream_pr, const struct mesa_ip6_hdr *raw_packet,
struct ipv6_frag_hdr *ipv6_frag_hdr, struct ipv6_frag_key *ip6_frag_key)
diff --git a/src/dealpkt/deal_tcp.c b/src/dealpkt/deal_tcp.c index 297198c..46e0073 100644 --- a/src/dealpkt/deal_tcp.c +++ b/src/dealpkt/deal_tcp.c @@ -631,22 +631,12 @@ static struct streamindex *tcp_add_new_stream_bysyn(struct streamindex *pindex, #endif get_stream_carry_tunnel_type(pstream, NULL, &pstream_pr->stream_low_layer_tunnel_type); -#if 0 - //set_stream_addr(pindex_tcp->stream.pfather, this_tcphdr->th_sport, this_tcphdr->th_dport, &pindex_tcp->stream.addr); - //set_stream_addr(pindex_tcp->stream.pfather, this_tcphdr->th_sport, this_tcphdr->th_dport, &pindex_tcp->stream); - - if(0 == need_reverse){ - set_stream_addr(pstream->pfather, this_tcphdr->th_sport, this_tcphdr->th_dport, pstream); - }else{ - set_stream_addr(pstream->pfather, this_tcphdr->th_dport, this_tcphdr->th_sport, pstream); - } -#endif pdetail_pr=(struct tcpdetail_private *)sapp_mem_malloc(SAPP_MEM_DYN_TCP_DETAIL, threadnum,sizeof(struct tcpdetail_private)); pdetail=&pdetail_pr->tcpdetail_public; pindex_tcp->stream.stream_public.pdetail=(void *)pdetail_pr; memset(pdetail_pr,0,sizeof(struct tcpdetail_private)); - pdetail->createtime=g_CurrentTime; - pstream_pr->stream_create_timestamp_ms=g_CurrentTime_ms; + pdetail->createtime=ABBR_CURRENT_TIME; + pstream_pr->stream_create_timestamp_ms=ABBR_CURRENT_TIME_MS; if(createdir==DIR_S2C){ pdetail->clientpktnum++; pdetail->clientbytes+= datalen; /* 2014-12-19 lijia add, for SYN pkt append data */ @@ -668,7 +658,6 @@ static struct streamindex *tcp_add_new_stream_bysyn(struct streamindex *pindex, pstream = &pstream_pr->stream_public; pdetail_pr = (struct tcpdetail_private *)pstream->pdetail; pdetail = (struct tcpdetail *)pdetail_pr; - // add by lqy 20150107, ???��??? if (createdir == DIR_S2C) { pdetail->clientpktnum = 1; @@ -687,20 +676,18 @@ static struct streamindex *tcp_add_new_stream_bysyn(struct streamindex *pindex, pstream_pr->has_duplicate_pkt = 0; pdetail_pr->drop_stream_flag = 0; - /* ???????, ??????????????streamid */ pindex_tcp->stream.global_stream_id = get_global_stream_id(threadnum); pindex_tcp->stream.stream_trace_id=0; - pdetail->createtime=g_CurrentTime; - pstream_pr->stream_create_timestamp_ms=g_CurrentTime_ms; + pdetail->createtime=ABBR_CURRENT_TIME; + pstream_pr->stream_create_timestamp_ms=ABBR_CURRENT_TIME_MS; - /* ????????, ?????��????ddos ?? */ if(pstream_pr->create_dir_by_well_known_port != 1) { pstream_pr->under_ddos_bypass = packet_io_under_ddos_should_bypass(threadnum); if (pstream_pr->under_ddos_bypass == 0 && G_MESA_GLOBAL_STREAM[threadnum]->tcp_opening_ratelimiter != NULL) { if(token_bucket_consume(G_MESA_GLOBAL_STREAM[threadnum]->tcp_opening_ratelimiter, 1, - g_current_time_ms) == 0) + ABBR_MONOTONIC_TIME_MS) == 0) { pstream_pr->under_ddos_bypass = 1; sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[threadnum]->sys_stat; @@ -747,8 +734,8 @@ static struct streamindex *tcp_add_new_stream_bysyn(struct streamindex *pindex, //pdetail->serverpkt++; //adjust by lqy 20140515 ??????????? pdetail_pr->C2S_first_ack_seq = ntohl (this_tcphdr->th_ack); } - pdetail->lastmtime=g_CurrentTime; - pstream_pr->stream_lastupdate_timestamp_ms=g_CurrentTime_ms; + pdetail->lastmtime=ABBR_CURRENT_TIME; + pstream_pr->stream_lastupdate_timestamp_ms=ABBR_CURRENT_TIME_MS; pdetail_pr->link_state=STREAM_LINK_JUST_EST; pstream->stream_state=TCP_SYN_STATE; @@ -1004,10 +991,10 @@ static struct streamindex *tcp_add_new_stream_bydata(struct streamindex *pindex, { pstream->pktstate = OP_STATE_PENDING; } - pdetail->createtime=g_CurrentTime; - pdetail->lastmtime=g_CurrentTime; - pstream_pr->stream_create_timestamp_ms=g_CurrentTime_ms; - pstream_pr->stream_lastupdate_timestamp_ms=g_CurrentTime_ms; + pdetail->createtime=ABBR_CURRENT_TIME; + pdetail->lastmtime=ABBR_CURRENT_TIME; + pstream_pr->stream_create_timestamp_ms=ABBR_CURRENT_TIME_MS; + pstream_pr->stream_lastupdate_timestamp_ms=ABBR_CURRENT_TIME_MS; pdetail_pr->link_state=STREAM_LINK_DATA; if(pstream_pr->under_ddos_bypass){ @@ -2227,7 +2214,7 @@ static inline int tcp_tuple4_reuse(const struct streaminfo *pstream, const struc /* lijia 2017-12-06 add */ if((1 == is_reuse) && (sapp_global_val->config.stream.tcp.tuple4_reuse_time_interval > 0)){ - if(pdetail_pr->tcpdetail_public.createtime + sapp_global_val->config.stream.tcp.tuple4_reuse_time_interval >= (UINT64)g_CurrentTime){ + if(pdetail_pr->tcpdetail_public.createtime + sapp_global_val->config.stream.tcp.tuple4_reuse_time_interval >= (UINT64)ABBR_CURRENT_TIME){ is_reuse = 0; } } @@ -2252,8 +2239,8 @@ static int tcp_deal_data_stream(struct streamindex *pindex,const void *this_iphd - pdetail->lastmtime=(long)g_CurrentTime; - pstream_pr->stream_lastupdate_timestamp_ms=g_CurrentTime_ms; + pdetail->lastmtime=(long)ABBR_CURRENT_TIME; + pstream_pr->stream_lastupdate_timestamp_ms=ABBR_CURRENT_TIME_MS; tcp_deal_ack(pstream,this_tcphdr); @@ -2477,7 +2464,7 @@ static int tcp_deal_nouse_stream(struct streamindex *pindex,const void *this_iph if(this_tcphdr->th_flags & TH_FIN || this_tcphdr->th_flags & TH_RST) { struct stream_list *lru_list_root=&(G_MESA_GLOBAL_STREAM[pstream->threadnum]->tcpList[pstream->stream_state]); - timeouts_add(lru_list_root->streamindex_timer, &pindex->timeout, tcp_closing_timeout*1000+g_CurrentTime_ms); + timeouts_add(lru_list_root->streamindex_timer, &pindex->timeout, tcp_closing_timeout*1000+ABBR_MONOTONIC_TIME_MS); } return PASS; @@ -2496,7 +2483,7 @@ static char tcp_process_newstreambydata(struct streamindex *pindex_tcp,const voi pdetail_pr=(struct tcpdetail_private *)(pstream->pdetail); pdetail=(struct tcpdetail *)(pstream->pdetail); - pdetail->lastmtime=g_CurrentTime; + pdetail->lastmtime=ABBR_CURRENT_TIME; if(pstream->curdir==DIR_S2C) { pdetail->clientbytes+=tcplen; @@ -2719,11 +2706,11 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s } pdetail_pr =(struct tcpdetail_private*)(pstream->pdetail); - if(pdetail_pr->offload_stream_flag==(SMART_OFFLOAD_FLAG_TCP|SMART_OFFLOAD_FLAG_TCPALL) && (g_CurrentTime > pdetail_pr->offload_stream_timestamp_s)) + if(pdetail_pr->offload_stream_flag==(SMART_OFFLOAD_FLAG_TCP|SMART_OFFLOAD_FLAG_TCPALL) && (ABBR_CURRENT_TIME > pdetail_pr->offload_stream_timestamp_s)) { local_sys_stat->count[SAPP_STAT_TCP_OFFLOAD_STREAM]++; MESA_send_smart_offload(pstream, (const void *)raw_pkt, pstream->threadnum); - pdetail_pr->offload_stream_timestamp_s = g_CurrentTime; + pdetail_pr->offload_stream_timestamp_s = ABBR_CURRENT_TIME; } } } @@ -2779,8 +2766,8 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s if(unlikely(pdetail_pr->drop_stream_flag != 0) && raw_pkt->is_ctrl_pkt==0){ sapp_runtime_log(RLOG_LV_DEBUG, "TCP stream: %s, has been set drop flag, curdir:%d, return DROP.", printaddr(&pstream->addr, pstream->threadnum), pstream->curdir); - pdetail->lastmtime = g_CurrentTime; - pstream_pr->stream_lastupdate_timestamp_ms = g_CurrentTime_ms; + pdetail->lastmtime = ABBR_CURRENT_TIME; + pstream_pr->stream_lastupdate_timestamp_ms = ABBR_CURRENT_TIME_MS; lrustream(pindex_tcp); if((this_tcphdr->th_flags & TH_RST) && tcplen == 0) @@ -2891,8 +2878,8 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s lrustream(pindex_tcp); - pdetail->lastmtime=g_CurrentTime; - pstream_pr->stream_lastupdate_timestamp_ms=g_CurrentTime_ms; + pdetail->lastmtime=ABBR_CURRENT_TIME; + pstream_pr->stream_lastupdate_timestamp_ms=ABBR_CURRENT_TIME_MS; pstream->addr.pkttype = PKT_TYPE_NORMAL;//add by lqy 20151222, init pkttype pdetail_pr->tcpoverlen=0;//add by lqy 20150325 @@ -2903,13 +2890,13 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s } else { - if(pdetail_pr->offload_stream_flag==(SMART_OFFLOAD_FLAG_TCP|SMART_OFFLOAD_FLAG_TCPALL) && (g_CurrentTime > pdetail_pr->offload_stream_timestamp_s)) + if(pdetail_pr->offload_stream_flag==(SMART_OFFLOAD_FLAG_TCP|SMART_OFFLOAD_FLAG_TCPALL) && (ABBR_CURRENT_TIME > pdetail_pr->offload_stream_timestamp_s)) { local_sys_stat->count[SAPP_STAT_TCP_OFFLOAD_PKTS]++; local_sys_stat->length[SAPP_STAT_TCP_OFFLOAD_BYTES]+= tcplen; MESA_send_smart_offload(pstream, (const void *)raw_pkt, pstream->threadnum); - pdetail_pr->offload_stream_timestamp_s = g_CurrentTime; + pdetail_pr->offload_stream_timestamp_s = ABBR_CURRENT_TIME; return PASS; } if (likely(raw_pkt->is_ctrl_pkt == 0)) @@ -2975,11 +2962,11 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s if(pdetail_pr != NULL && pdetail_pr->offload_stream_flag==(SMART_OFFLOAD_FLAG_TCP|SMART_OFFLOAD_FLAG_TCPALL) && DROP!=ret - && (g_CurrentTime > pdetail_pr->offload_stream_timestamp_s)) + && (ABBR_CURRENT_TIME > pdetail_pr->offload_stream_timestamp_s)) { local_sys_stat->count[SAPP_STAT_TCP_OFFLOAD_STREAM]++; MESA_send_smart_offload(pstream, (const void *)raw_pkt, pstream->threadnum); - pdetail_pr->offload_stream_timestamp_s = g_CurrentTime; + pdetail_pr->offload_stream_timestamp_s = ABBR_CURRENT_TIME; } fun_exit: diff --git a/src/dealpkt/deal_udp.c b/src/dealpkt/deal_udp.c index 9eac4bb..bffeafe 100644 --- a/src/dealpkt/deal_udp.c +++ b/src/dealpkt/deal_udp.c @@ -231,11 +231,11 @@ static struct streamindex *udp_add_new_stream(struct streamindex *pindex, pstream_udp->opstate=OP_STATE_PENDING; pstream_udp->pktstate=OP_STATE_PENDING; - pdetail->createtime=g_CurrentTime; + pdetail->createtime=ABBR_CURRENT_TIME; pstream_udp_pr->global_stream_id = get_global_stream_id(threadnum); pstream_udp_pr->stream_trace_id=0; - pstream_udp_pr->stream_create_timestamp_ms=g_CurrentTime_ms; - pdetail->lastmtime=g_CurrentTime; + pstream_udp_pr->stream_create_timestamp_ms=ABBR_CURRENT_TIME_MS; + pdetail->lastmtime=ABBR_CURRENT_TIME; if(pstream_udp_pr->under_ddos_bypass){ sapp_global_val->mthread_volatile[threadnum]->sys_stat.count[SAPP_STAT_UDP_BYPASS_STREAM]++; @@ -351,7 +351,7 @@ void udp_free_stream(struct streamindex *pindex) pindex->stream.stream_public.threadnum, pstream->type, pstream->stream_state, - g_CurrentTime); + ABBR_CURRENT_TIME); if(pstream->pdetail!=NULL){ sapp_mem_free(SAPP_MEM_DYN_UDP_DETAIL, threadnum,pstream->pdetail); @@ -460,10 +460,10 @@ static int udp_reset_stream(struct streamindex *pindex) pdetail_pr->drop_stream_flag = 0; pdetail_pr->apme=NULL; - pdetail->createtime = g_CurrentTime; + pdetail->createtime = ABBR_CURRENT_TIME; pstream_pr->global_stream_id = get_global_stream_id(threadnum); pstream_pr->stream_trace_id = 0; - pstream_pr->stream_create_timestamp_ms = g_CurrentTime_ms; + pstream_pr->stream_create_timestamp_ms = ABBR_CURRENT_TIME_MS; plist = &(G_MESA_GLOBAL_STREAM[threadnum]->udpList[UDP_ONE_STATE]); pstream->stream_state = UDP_ONE_STATE; streamaddlist(pindex, plist); @@ -623,10 +623,10 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ set_addr_recur(pstream, 1); } - pdetail->createtime = g_CurrentTime; + pdetail->createtime = ABBR_CURRENT_TIME; pstream_pr->global_stream_id = get_global_stream_id(thread_num); pstream_pr->stream_trace_id=0; - pstream_pr->stream_create_timestamp_ms=g_CurrentTime_ms; + pstream_pr->stream_create_timestamp_ms=ABBR_CURRENT_TIME_MS; pdetail->datalen = datalen; pdetail->pdata = (char *)udph + sizeof (struct udphdr); pstream->pdetail=(void *)pdetail; @@ -682,8 +682,8 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ //pstream->addr.pktipfragtype = pstream->stream_public.addr.pktipfragtype; pdetail_pr=(struct udpdetail_private *)(pstream->pdetail); - pstream->pudpdetail->lastmtime=(long)g_CurrentTime; - pstream_pr->stream_lastupdate_timestamp_ms=g_CurrentTime_ms; + pstream->pudpdetail->lastmtime=(long)ABBR_CURRENT_TIME; + pstream_pr->stream_lastupdate_timestamp_ms=ABBR_CURRENT_TIME_MS; if(pstream_pr->under_ddos_bypass){ local_sys_stat->count[SAPP_STAT_UDP_BYPASS_PKTS]++; @@ -771,12 +771,12 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ if(pdetail_pr->offload_stream_flag==SMART_OFFLOAD_FLAG_UDP && pstream_pr->stream_carry_up_layer_tunnel_type==STREAM_TUNNLE_NON && DROP!=ret - && (g_CurrentTime > pdetail_pr->offload_stream_timestamp_s)) + && (ABBR_CURRENT_TIME > pdetail_pr->offload_stream_timestamp_s)) { local_sys_stat->count[SAPP_STAT_UDP_OFFLOAD_PKTS]++; local_sys_stat->length[SAPP_STAT_UDP_OFFLOAD_BYTES]+= ulen; MESA_send_smart_offload(pstream, (const void *)raw_pkt, pstream->threadnum); - pdetail_pr->offload_stream_timestamp_s = g_CurrentTime; + pdetail_pr->offload_stream_timestamp_s = ABBR_CURRENT_TIME; return PASS; } @@ -784,11 +784,11 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ udp_cleardata(pstream); } pdetail_pr = (struct udpdetail_private *)(pstream->pdetail); - if (pdetail_pr != NULL && pdetail_pr->offload_stream_flag == SMART_OFFLOAD_FLAG_UDP && pstream_pr->stream_carry_up_layer_tunnel_type == STREAM_TUNNLE_NON && DROP != ret && (g_CurrentTime > pdetail_pr->offload_stream_timestamp_s)) + if (pdetail_pr != NULL && pdetail_pr->offload_stream_flag == SMART_OFFLOAD_FLAG_UDP && pstream_pr->stream_carry_up_layer_tunnel_type == STREAM_TUNNLE_NON && DROP != ret && (ABBR_CURRENT_TIME > pdetail_pr->offload_stream_timestamp_s)) { local_sys_stat->count[SAPP_STAT_UDP_OFFLOAD_STREAM]++; MESA_send_smart_offload(pstream, (const void *)raw_pkt, pstream->threadnum); - pdetail_pr->offload_stream_timestamp_s = g_CurrentTime; + pdetail_pr->offload_stream_timestamp_s = ABBR_CURRENT_TIME; return PASS; } } @@ -953,8 +953,8 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe pstream=&(pstream_pr->stream_public); pdetail_pr=(struct udpdetail_private *)(pstream->pdetail); - pstream->pudpdetail->lastmtime=(long)g_CurrentTime; - pstream_pr->stream_lastupdate_timestamp_ms=g_CurrentTime_ms; + pstream->pudpdetail->lastmtime=(long)ABBR_CURRENT_TIME; + pstream_pr->stream_lastupdate_timestamp_ms=ABBR_CURRENT_TIME_MS; if(pstream_pr->under_ddos_bypass){ local_sys_stat->count[SAPP_STAT_UDP_BYPASS_PKTS]++; @@ -1019,12 +1019,12 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe if(pdetail_pr->offload_stream_flag==SMART_OFFLOAD_FLAG_UDP && pstream_pr->stream_carry_up_layer_tunnel_type==STREAM_TUNNLE_NON && DROP!=ret - && (g_CurrentTime > pdetail_pr->offload_stream_timestamp_s)) + && (ABBR_CURRENT_TIME > pdetail_pr->offload_stream_timestamp_s)) { local_sys_stat->count[SAPP_STAT_UDP_OFFLOAD_PKTS]++; local_sys_stat->length[SAPP_STAT_UDP_OFFLOAD_BYTES]+= ulen; MESA_send_smart_offload(pstream, (const void *)raw_pkt, pstream->threadnum); - pdetail_pr->offload_stream_timestamp_s = g_CurrentTime; + pdetail_pr->offload_stream_timestamp_s = ABBR_CURRENT_TIME; pstream_pr->packet_process_context=0; return PASS; } diff --git a/src/dealpkt/duplicate_pkt_distinguish.c b/src/dealpkt/duplicate_pkt_distinguish.c index 54a1593..6d960fb 100644 --- a/src/dealpkt/duplicate_pkt_distinguish.c +++ b/src/dealpkt/duplicate_pkt_distinguish.c @@ -12,18 +12,18 @@ extern "C" { 识别因路由策略导致的重复流量, 首次收到数据包加入bloom filter, 每个流的前N个包扫描bloom filter, 重复的数据包直接转发即可. - ip层的ttl, hop不能算为key, 因为经过了几跳路由器又回绕了, ttl肯定会变�??, 而上层的数据包确实是重复�??. + ip层的ttl, hop不能算为key, 因为经过了几跳路由器又回绕了, ttl肯定会变�??, 而上层的数据包确实是重复�??. */ /* 2021-05-18 lijia close ipv6 protocol: 重复流量识别bloom filter句柄, 根据流量方向和协议的不同, 功能分为三类, - IPv6因为没有Ipid字段, 无法区别真正的应用层重传和重复流�??, 开启了会导致断网或者CT, 所以不支持!!! + IPv6因为没有Ipid字段, 无法区别真正的应用层重传和重复流�??, 开启了会导致断网或者CT, 所以不支持!!! - 对于IPv6的两种情�??: - 1)如果开启了代理策略, 重传包被识别成了重复包的�??, sapp就直接PASS�??, 实际那个包是真实通信双方发的, 没有经过tfe处理, 可能就断网了. - 2)如果开启了firewall的drop策略, 第一次drop成功�??, 但应用层会重�??, 重传包被识别成了重复包的�??, sapp就直接PASS�??, 导致CT. + 对于IPv6的两种情�??: + 1)如果开启了代理策略, 重传包被识别成了重复包的�??, sapp就直接PASS�??, 实际那个包是真实通信双方发的, 没有经过tfe处理, 可能就断网了. + 2)如果开启了firewall的drop策略, 第一次drop成功�??, 但应用层会重�??, 重传包被识别成了重复包的�??, sapp就直接PASS�??, 导致CT. */ void *bloom_new(const sapp_dup_pkt_t *dup_conf, struct timeval now, long now_ms) @@ -236,8 +236,8 @@ int sapp_dup_stream_search(struct streaminfo *a_stream) key_len=sizeof(struct stream_tuple4_v6); } - struct timeval now={g_CurrentTime, 0}; - return bloom_check(sapp_global_val->mthread_volatile[a_stream->threadnum]->dup_pkt_distinguish_handle, key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, g_current_time_ms); + struct timeval now={ABBR_MONOTONIC_TIME, 0}; + return bloom_check(sapp_global_val->mthread_volatile[a_stream->threadnum]->dup_pkt_distinguish_handle, key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, ABBR_MONOTONIC_TIME_MS); } @@ -255,8 +255,8 @@ void sapp_dup_stream_add(struct streaminfo *a_stream) key = (void *)a_stream->addr.tuple4_v6; key_len=sizeof(struct stream_tuple4_v6); } - struct timeval now={g_CurrentTime, 0}; - bloom_add(sapp_global_val->mthread_volatile[a_stream->threadnum]->dup_pkt_distinguish_handle, key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, g_current_time_ms); + struct timeval now={ABBR_MONOTONIC_TIME, 0}; + bloom_add(sapp_global_val->mthread_volatile[a_stream->threadnum]->dup_pkt_distinguish_handle, key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, ABBR_MONOTONIC_TIME_MS); } static inline int sapp_set_dup_pkt_key(enum addr_type_t addr_type, enum stream_type_t stream_type, const void *iphdr, @@ -276,8 +276,8 @@ static inline int sapp_set_dup_pkt_key(enum addr_type_t addr_type, enum stream_t if (stream_type == STREAM_TYPE_UDP) { const struct mesa_udp_hdr *uhdr = (const struct mesa_udp_hdr *)l4_hdr; - l4->tcp_seq = 0x5A5A5A5A; /* udp没有, 但设�??0可能对某些hash函数不友�??, 此处设个固定�?? */ - l4->tcp_ack = 0xA5A5A5A5; /* udp没有, 但设�??0可能对某些hash函数不友�??, 此处设个固定�?? */ + l4->tcp_seq = 0x5A5A5A5A; /* udp没有, 但设�??0可能对某些hash函数不友�??, 此处设个固定�?? */ + l4->tcp_ack = 0xA5A5A5A5; /* udp没有, 但设�??0可能对某些hash函数不友�??, 此处设个固定�?? */ l4->sport = uhdr->uh_sport; l4->dport = uhdr->uh_dport; l4->checksum = uhdr->uh_sum; @@ -314,15 +314,15 @@ int sapp_dup_pkt_identify(int tid, struct streaminfo_private *pstream_pr, { int is_dup_pkt = 0; union sapp_dup_pkt_key dup_bloom_key; - struct timeval now={g_CurrentTime, 0}; + struct timeval now={ABBR_MONOTONIC_TIME, 0}; size_t key_len = sapp_set_dup_pkt_key((enum addr_type_t)pstream_pr->stream_public.addr.addrtype, (enum stream_type_t)pstream_pr->stream_public.type, ip_hdr, (void *)l4_hdr, &dup_bloom_key); - is_dup_pkt= bloom_check(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, g_current_time_ms); + is_dup_pkt= bloom_check(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, ABBR_MONOTONIC_TIME_MS); if(is_dup_pkt != 0){ pstream_pr->has_duplicate_pkt = 1; }else{ if(need_add_bloom_filter){ - bloom_add(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, g_current_time_ms); + bloom_add(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, ABBR_MONOTONIC_TIME_MS); } } return is_dup_pkt; @@ -333,9 +333,9 @@ void sapp_dup_pkt_mark_l4(struct streaminfo *a_stream, const void *ip_hdr, const union sapp_dup_pkt_key dup_bloom_key; size_t key_len = 0; int ret = 0; - struct timeval now={g_CurrentTime, 0}; + struct timeval now={ABBR_MONOTONIC_TIME, 0}; key_len = sapp_set_dup_pkt_key((enum addr_type_t)a_stream->addr.addrtype, (enum stream_type_t)a_stream->type, ip_hdr, l4_hdr, &dup_bloom_key); - bloom_add(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, g_current_time_ms); + bloom_add(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now, ABBR_MONOTONIC_TIME_MS); return; } @@ -351,12 +351,12 @@ int sapp_dup_pkt_init(void) return 0; } - /* 流量入口有三个开�??, 识别句柄只有一�??, - 拆分句柄多耗费内存, 且判断时每个包需要扫描多个句�??, + /* 流量入口有三个开�??, 识别句柄只有一�??, + 拆分句柄多耗费内存, 且判断时每个包需要扫描多个句�??, 可能好处只是准确率高了一点点而已 */ struct timeval now={time(NULL), 0}; for(i = 0; i < sapp_global_val->config.cpu.worker_threads; i++){ - sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle = bloom_new(p_dup_conf, now, g_current_time_ms); + sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle = bloom_new(p_dup_conf, now, ABBR_MONOTONIC_TIME_MS); if(NULL == sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle){ sapp_log(RLOG_LV_FATAL, 1, 1, "dup_pkt_distinguish init error!"); return -1; diff --git a/src/dealpkt/g_device.c b/src/dealpkt/g_device.c index bdd3862..2f26768 100644 --- a/src/dealpkt/g_device.c +++ b/src/dealpkt/g_device.c @@ -12,12 +12,12 @@ extern "C" { #include "sapp_declaration.h" -char pcap_gdev_card[128]; /* 2012-08-14 LiJia add, �����豸ģʽ�£������������ƣ�ͨ����sendto_gdev_cardһ�� */ -char sendto_gdev_card[128]; /* ���������豸�Ĵ���ģʽ���������ݽӿ����� */ -unsigned char sendto_gdev_card_mac[6]; /* �������ݽӿڵ�MAC��ַ */ -int sendto_gdev_card_ip = 0; /* �������ݽӿڵ�IP��ַ, ������ */ -char config_gdev_card_ip[20] = {}; /* �������ļ��ж���ķ������ݽӿ�IP�� �ӿ�û������IP��ַʱʹ�� */ -extern char g_up_dev_name[DEV_NAME_STR_LEN]; /* Ĭ�ϲ������� */ +char pcap_gdev_card[128]; /* 2012-08-14 LiJia add, �����豸ģʽ�£������������ƣ�ͨ����sendto_gdev_cardһ�� */ +char sendto_gdev_card[128]; /* ���������豸�Ĵ���ģʽ���������ݽӿ����� */ +unsigned char sendto_gdev_card_mac[6]; /* �������ݽӿڵ�MAC��ַ */ +int sendto_gdev_card_ip = 0; /* �������ݽӿڵ�IP��ַ, ������ */ +char config_gdev_card_ip[20] = {}; /* �������ļ��ж���ķ������ݽӿ�IP�� �ӿ�û������IP��ַʱʹ�� */ +extern char g_up_dev_name[DEV_NAME_STR_LEN]; /* Ĭ�ϲ������� */ #define GDEV_LOG_NAME "gdev_ip.log" #define GDEV_LOG_MAX_NUM (128) @@ -27,7 +27,7 @@ extern char g_up_dev_name[DEV_NAME_STR_LEN]; /* Ĭ�ϲ������� */ int GDEV_IP_NUM = 0; //static struct gdev_status GDEV_IP_LOG[GDEV_LOG_MAX_NUM]; //static pthread_mutex_t GDEV_IP_LOG_MUTEX; -//static unsigned int gdev_log_write_counter = 1; /* ���ڼ�������ij��ֵʱ��д�ļ� */ +//static unsigned int gdev_log_write_counter = 1; /* ���ڼ�������ij��ֵʱ��д�ļ� */ extern char *timet_to_str(time_t timet, char *time_str, int time_str_len); @@ -39,7 +39,7 @@ extern FILE *packet_io_open_log_file(const char *log_file_name, const char *mode extern int MESA_get_dev_ipv4(const char *device, int *ip_add); extern int MESA_get_dev_mac(const char *device, unsigned char mac[6]); -/* �Ƿ�ΪIPv6˽�е�ַ */ +/* �Ƿ�ΪIPv6˽�е�ַ */ inline int is_private_addr_v6(struct in6_addr ip6_add) { /* Link-Local address, first 10 bits is 1111111010 */ @@ -59,7 +59,7 @@ inline int is_private_addr_v6(struct in6_addr ip6_add) return 0; } -/* �Ƿ�ΪIPv6�鲥��ַ */ +/* �Ƿ�ΪIPv6�鲥��ַ */ int is_multicast_addr_v6(struct in6_addr ip6_add) { /* IPv6 multicast address first 8 bits is 11111111 */ @@ -73,7 +73,7 @@ int is_multicast_addr_v6(struct in6_addr ip6_add) static int gdev_check_ipv6_pkt(struct mesa_ip6_hdr *a_packet) { - /* 2012-11-01 add, �������豸ģʽ�£��������鲥��ַ���� */ + /* 2012-11-01 add, �������豸ģʽ�£��������鲥��ַ���� */ /* @@ -130,7 +130,7 @@ int gdev_check_pkt(int addr_type, void *pkt_data) return ret; } -/* �����豸�������ARPЭ�� +/* �����豸�������ARPЭ�� return value: 1: is gdev keepalive pkt; 0: not gdev keepalive pkt; @@ -141,7 +141,7 @@ static int gdev_keepalive_arp(const raw_pkt_t *raw_pkt, int thread_id, unsigned struct mesa_arp_hdr *arp_hdr = (struct mesa_arp_hdr *)((char *)raw_eth_hdr + ETHERNET_HDR_LEN); struct mesa_ethernet_hdr *send_eth_hdr; - /* һЩ�������� */ + /* һЩ�������� */ if(ntohs(raw_eth_hdr->ether_type) != ETHERTYPE_ARP){ return -1; } @@ -165,8 +165,8 @@ static int gdev_keepalive_arp(const raw_pkt_t *raw_pkt, int thread_id, unsigned } -/* �����豸�������ICMPЭ�� */ -#if 0 /* ����IP����ʵ�� */ +/* �����豸�������ICMPЭ�� */ +#if 0 /* ����IP����ʵ�� */ static int gdev_keepalive_icmp(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, unsigned char *send_buf) { struct mesa_ethernet_hdr *eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data; @@ -175,7 +175,7 @@ static int gdev_keepalive_icmp(const raw_pkt_t *raw_pkt, int thread_id, unsigned unsigned char *icmp_payload; int icmp_payload_len; - /* һЩ�������� */ + /* һЩ�������� */ if(ntohs(eth_hdr->ether_type) != ETHERTYPE_IP){ return -1; } @@ -228,8 +228,8 @@ static int gdev_keepalive_icmp(const raw_pkt_t *raw_pkt, int thread_id, unsigned -/* ���ں������豸�������� - �������豸���ӵĽӿ�һ��û��·�ɺ�IP��ַ, ��Ҫ���ʹ�mac���ԭʼ��. +/* ���ں������豸�������� + �������豸���ӵĽӿ�һ��û��·�ɺ�IP��ַ, ��Ҫ���ʹ�mac���ԭʼ��. return value: >0: is gdev keepalive pkt; @@ -257,7 +257,7 @@ int gdev_keepalive(const raw_pkt_t *raw_pkt, int thread_id, int pro_type, unsign switch(pro_type) { -#if 0 /* ����IP����ʵ�� */ +#if 0 /* ����IP����ʵ�� */ case GDEV_KEEPALIVE_TYPE_ICMP: ret = gdev_keepalive_icmp(raw_pkt, thread_id, dir, snd_handle->send_buf); low_layer_type = __ADDR_TYPE_IP_PAIR_V4; @@ -268,7 +268,7 @@ int gdev_keepalive(const raw_pkt_t *raw_pkt, int thread_id, int pro_type, unsign //low_layer_type = ADDR_TYPE_ARP; break; -#if 0 /* ����UDP����ʵ�� */ +#if 0 /* ����UDP����ʵ�� */ case GDEV_KEEPALIVE_TYPE_BFD: ret = gdev_keepalive_bfd(raw_pkt, thread_id, dir, snd_handle->send_buf); low_layer_type = __ADDR_TYPE_IP_PAIR_V4; @@ -285,9 +285,9 @@ int gdev_keepalive(const raw_pkt_t *raw_pkt, int thread_id, int pro_type, unsign /* TODO: - arpЭ���MAC��ַ����ת����ע��һ��, ԭʼ����Ŀ��MAC��ȫFF, ��Ҫ��ȷ��ԴMACΪ����IP, - ����ʹ��packet_io_sendϵ�к���, - Ҫʹ��packet_io_send_raw()����. + arpЭ���MAC��ַ����ת����ע��һ��, ԭʼ����Ŀ��MAC��ȫFF, ��Ҫ��ȷ��ԴMACΪ����IP, + ����ʹ��packet_io_sendϵ�к���, + Ҫʹ��packet_io_send_raw()����. */ ret = packet_io_send_raw(thread_id, (char *)snd_handle->send_buf, @@ -302,193 +302,15 @@ err: return -1; } -#if 0 -static void gdev_status_insert(int index, unsigned char *data, char keepalive_type) -{ - struct mesa_ethernet_hdr *eth_hdr = (struct mesa_ethernet_hdr *)data; - struct mesa_ip4_hdr *ip_hdr = (struct mesa_ip4_hdr *)(data + SENDPACKET_ETH_H); - - GDEV_IP_LOG[index].gdev_ip = ip_hdr->ip_src.s_addr; - memcpy(GDEV_IP_LOG[index].gdev_mac, eth_hdr->ether_shost, 6); - GDEV_IP_LOG[index].last_time = g_CurrentTime; - - if(GDEV_KEEPALIVE_TYPE_ICMP == keepalive_type) - { - GDEV_IP_LOG[index].gdev_keepalive_str = (char *)"ICMP"; - } - else if(GDEV_KEEPALIVE_TYPE_BFD == keepalive_type) - { - GDEV_IP_LOG[index].gdev_keepalive_str =(char *)"BFD"; - } - else - { - GDEV_IP_LOG[index].gdev_keepalive_str =(char *) "Uknown"; - } - GDEV_IP_NUM++; -} - -void gdev_keepalive_log(void ) -{ - int i; - char local_ip_str[16]; - char gdev_ip_str[16]; - char time_now_str[32]; - - FILE *gdev_status_fp = NULL;// to do packet_io_open_log_file("gdev_keepalive.log", "w+"); - if(NULL == gdev_status_fp) - { - return; - } - - if(0 == GDEV_IP_NUM) /* ��ǰ������ */ - { - return; - } - - fprintf(gdev_status_fp, "%-20s %-16s %-16s %-20s %-20s\n", "Last update time", "Local-ip", "Gdev-ip", "Gdev-mac", "Gdev-keepalive-type"); - - for(i = 0; GDEV_IP_LOG[i].gdev_ip != 0 && i < GDEV_LOG_MAX_NUM; i++) - { - // to do timet_to_str - //timet_to_str(GDEV_IP_LOG[i].last_time, time_now_str, 32); - fprintf(gdev_status_fp, "%-20s ", time_now_str); - inet_ntop(AF_INET, &sendto_gdev_card_ip, local_ip_str, 16); - inet_ntop(AF_INET, &GDEV_IP_LOG[i].gdev_ip, gdev_ip_str, 16); - fprintf(gdev_status_fp, "%-16s %-16s ", local_ip_str, gdev_ip_str); - fprintf(gdev_status_fp, "%02x-%02x-%02x-%02x-%02x-%02x ", - GDEV_IP_LOG[i].gdev_mac[0], - GDEV_IP_LOG[i].gdev_mac[1], - GDEV_IP_LOG[i].gdev_mac[2], - GDEV_IP_LOG[i].gdev_mac[3], - GDEV_IP_LOG[i].gdev_mac[4], - GDEV_IP_LOG[i].gdev_mac[5]); - fprintf(gdev_status_fp, "%-20s\n", GDEV_IP_LOG[i].gdev_keepalive_str); - } - - return; -} -#endif - -#if 0 -static void gdev_status_update(unsigned char *data, char keepalive_type) -{ - int i; - struct mesa_ip4_hdr *ip_hdr = (struct mesa_ip4_hdr *)(data + SENDPACKET_ETH_H); - unsigned int gdev_ip = ip_hdr->ip_src.s_addr; - - pthread_mutex_lock(&GDEV_IP_LOG_MUTEX); - - for(i = 0; i < GDEV_LOG_MAX_NUM; i++) - { - if(gdev_ip == GDEV_IP_LOG[i].gdev_ip) /* �Ѿ������˼�¼,����ʱ�� */ - { - GDEV_IP_LOG[i].last_time = g_CurrentTime; - goto exit; - } - - if(0 == GDEV_IP_LOG[i].gdev_ip) - { - gdev_status_insert(i, data, keepalive_type); - goto exit; - } - } - - if(GDEV_LOG_MAX_NUM == i) - { - //to do - //MESA_runtime_log(RLOG_LV_INFO, "gdev_status", "Too many gdev ip!\n"); - } - - -exit: - pthread_mutex_unlock(&GDEV_IP_LOG_MUTEX); - return; -} - - - -/* 2012-08-03 LiJia add, ��¼����ͨ�ŵ����������豸��IP��MAC�ͱ���Э�����Ϣ�� - Bug: �������������ping��������������һ̨��ͨPC���������豸��Ҳ���¼����־��. -*/ -int gdev_log_init(void) -{ - if(GDEV_STATUS_SWITCH) - { - pthread_mutex_init(&GDEV_IP_LOG_MUTEX, NULL); - } - - return 0; -} -#endif - #ifdef CAPTURE_MODE_DPDK_VXLAN -/* ��ʱ���DPDK-RTE��ʹ��ʱ, ����ȡmac��ַ������ */ +/* ��ʱ���DPDK-RTE��ʹ��ʱ, ����ȡmac��ַ������ */ int dpdk_get_mac_addr(unsigned int port, uint8_t mac_addr[6]) ; #endif -#if 0 -int gdev_init(void) -{ - char gdev_ip_str[32]; - char gdev_device[128]; - - if(g_topology_mode != NET_CONN_SERIAL_GDEV){ - return 0; - } - - MESA_load_profile_string_def((char *)"conf/gdev.conf", (char *)"Module", (char *)"sendto_gdev_ip", gdev_ip_str, 32, (char *)""); - MESA_load_profile_string_def((char *)"conf/gdev.conf", (char *)"Module", (char *)"sendto_gdev_card", gdev_device, 128, (char *)""); - - if('\0' == gdev_device[0]){ - printf("Can't get sendto_gdev_card in %s!\n", "conf/gdev.conf"); - assert(0); - } - - if('\0' == gdev_ip_str[0]){ - if(MESA_get_dev_ipv4(gdev_device, &sendto_gdev_card_ip) < 0){ - printf("Can't get gdev ip in %s!\n", "conf/gdev.conf"); - assert(0); - } - } - - if(inet_pton(AF_INET, gdev_ip_str, &sendto_gdev_card_ip) <= 0){ - printf("gdev ip in %s is invalid!\n", "conf/gdev.conf"); - assert(0); - } - - if(0 == sendto_gdev_card_ip){ - printf("Can't get %s ip address!\n", sendto_gdev_card); - assert(0); - } - -#if (0 == IOMODE_MARSIO) - if(MESA_get_dev_mac(gdev_device, sendto_gdev_card_mac) < 0){ -#ifdef CAPTURE_MODE_DPDK_VXLAN - dpdk_get_mac_addr(0, sendto_gdev_card_mac); - if(memcmp(empty_mac_addr, sendto_gdev_card_mac, 6) == 0){ - printf("Can't get gdev interface %s MAC!\n", sendto_gdev_card); - assert(0); - } -#else - printf("Can't get gdev interface %s MAC!\n", sendto_gdev_card); - assert(0); -#endif - } -#endif - - if(GDEV_STATUS_SWITCH) - { - gdev_log_init(); - } - - return 0; -} -#endif - #ifdef __cplusplus } diff --git a/src/dealpkt/ip_reassembly.c b/src/dealpkt/ip_reassembly.c index ce9def3..bd4c115 100644 --- a/src/dealpkt/ip_reassembly.c +++ b/src/dealpkt/ip_reassembly.c @@ -1,7 +1,7 @@ /*
* Description:
- * IP��Ƭ����Ĺ�����������Э��汾��,
- * ��IPv4��IPv6Э��������صĺ��������ڴ˻������ٴη�װ.
+ * IP��Ƭ����Ĺ�����������Э��汾��,
+ * ��IPv4��IPv6Э��������صĺ��������ڴ˻������ٴη�װ.
*
* Author: Li Jia<[email protected]>
* Date: 2012-06-06
@@ -19,7 +19,7 @@ extern "C" { extern void raw_frags_list_free_one(int thread_num, void *);
-/* ����size��С��һ���ڴ棬ͬʱ�������ڴ�ռ��ֵ */
+/* ����size��С��һ���ڴ棬ͬʱ�������ڴ�ռ��ֵ */
void *frag_malloc(struct frag_manage *handle, int size)
{
void *p = sapp_mem_malloc(SAPP_MEM_DYN_IP_FRAG_PKT, handle->thread_num, size);
@@ -30,7 +30,7 @@ void *frag_malloc(struct frag_manage *handle, int size) }
-/* ��Ҫ�����free��ָ����ָ���ڴ��Ĵ�С������ͳ���ڴ�ռ��ֵ */
+/* ��Ҫ�����free��ָ����ָ���ڴ��Ĵ�С������ͳ���ڴ�ռ��ֵ */
void frag_free(struct frag_manage *handle, void *free_p, int size)
{
sapp_mem_free(SAPP_MEM_DYN_IP_FRAG_PKT, handle->thread_num, free_p);
@@ -41,10 +41,10 @@ void frag_free(struct frag_manage *handle, void *free_p, int size) #if (USE_MESA_STREAM_HASH==0)
-/* ��һ����ipq�ṹ����LRU���� */
+/* ��һ����ipq�ṹ����LRU���� */
void frag_add_lru_node (struct frag_manage *handle, struct frag_ipq *new_node)
{
- /* �½ڵ��������β */
+ /* �½ڵ��������β */
if(handle->lru_tail)
{
handle->lru_tail->lru_next = new_node;
@@ -52,7 +52,7 @@ void frag_add_lru_node (struct frag_manage *handle, struct frag_ipq *new_node) new_node->lru_next = NULL;
handle->lru_tail = new_node;
}
- else /* ��һ���ڵ� */
+ else /* ��һ���ڵ� */
{
new_node->lru_next = NULL;
new_node->lru_prev = NULL;
@@ -62,14 +62,14 @@ void frag_add_lru_node (struct frag_manage *handle, struct frag_ipq *new_node) }
-/* ��һ��ipq�ṹ��LRU������ɾ�� */
+/* ��һ��ipq�ṹ��LRU������ɾ�� */
void frag_del_lru_node (struct frag_manage *handle, struct frag_ipq *del_node)
{
if(del_node->lru_prev)
{
del_node->lru_prev->lru_next = del_node->lru_next;
}
- else /* ��ǰ�ڵ�Ϊ����ͷ */
+ else /* ��ǰ�ڵ�Ϊ����ͷ */
{
handle->lru_head = del_node->lru_next;
}
@@ -78,14 +78,14 @@ void frag_del_lru_node (struct frag_manage *handle, struct frag_ipq *del_node) {
del_node->lru_next->lru_prev = del_node->lru_prev;
}
- else /* ��ǰ�ڵ�Ϊ����β */
+ else /* ��ǰ�ڵ�Ϊ����β */
{
handle->lru_tail = del_node->lru_prev;
}
}
-/* ��ipq�ṹ��LRU���£�ʵ�ʾ��Ǵ�������ȡ�������ٷ���LRU����β.*/
+/* ��ipq�ṹ��LRU���£�ʵ�ʾ��Ǵ�������ȡ�������ٷ���LRU����β.*/
void frag_lru_update(struct frag_manage *handle, struct frag_ipq *ipq)
{
frag_del_lru_node(handle, ipq);
@@ -93,11 +93,11 @@ void frag_lru_update(struct frag_manage *handle, struct frag_ipq *ipq) }
-/* ��һ����ipq�ṹ����HASH�� */
+/* ��һ����ipq�ṹ����HASH�� */
void frag_add_hash_node (struct frag_manage *handle, struct frag_ipq *new_node)
{
struct frag_ipq *tmp = NULL;
- unsigned int hash_index = new_node->hash_index;/* HASHֵ��frag_ipq_find()���Ѿ������ */
+ unsigned int hash_index = new_node->hash_index;/* HASHֵ��frag_ipq_find()���Ѿ������ */
for(tmp = handle->frag_hash_table[hash_index]; tmp; tmp = tmp->hash_next)
{
@@ -112,7 +112,7 @@ void frag_add_hash_node (struct frag_manage *handle, struct frag_ipq *new_node) return;
}
- /* �½ڵ㣬����HASH-SLOT��һ���ڵ� */
+ /* �½ڵ㣬����HASH-SLOT��һ���ڵ� */
new_node->hash_next = handle->frag_hash_table[hash_index];
new_node->hash_prev = NULL;
@@ -127,7 +127,7 @@ void frag_add_hash_node (struct frag_manage *handle, struct frag_ipq *new_node) }
-/* ��һ��ipq�ṹ��HASH����ɾ�� */
+/* ��һ��ipq�ṹ��HASH����ɾ�� */
void frag_del_hash_node (struct frag_manage *handle, struct frag_ipq *del_node)
{
unsigned int hash_index = del_node->hash_index;
@@ -136,7 +136,7 @@ void frag_del_hash_node (struct frag_manage *handle, struct frag_ipq *del_node) {
del_node->hash_prev->hash_next = del_node->hash_next;
}
- else /* HASH-slot�е�һ���ڵ� */
+ else /* HASH-slot�е�һ���ڵ� */
{
handle->frag_hash_table[hash_index] = del_node->hash_next;
}
@@ -148,7 +148,7 @@ void frag_del_hash_node (struct frag_manage *handle, struct frag_ipq *del_node) }
#endif
-/* ����һ���µķ�Ƭ�ṹ��ͬʱ��¼�˷�Ƭ��offset��endֵ */
+/* ����һ���µķ�Ƭ�ṹ��ͬʱ��¼�˷�Ƭ��offset��endֵ */
struct ip_frags* frags_create(struct frag_manage *handle, int offset, int end)
{
struct ip_frags *frags = (struct ip_frags *)frag_malloc(handle, sizeof(struct ip_frags));
@@ -162,7 +162,7 @@ struct ip_frags* frags_create(struct frag_manage *handle, int offset, int end) }
-/* ��IPQ������ɾ��һ��IP��Ƭ�ṹ */
+/* ��IPQ������ɾ��һ��IP��Ƭ�ṹ */
void frags_kill(struct frag_manage *handle, struct frag_ipq *ipq, struct ip_frags *frags_del)
{
if(frags_del->prev)
@@ -191,7 +191,7 @@ void frags_kill(struct frag_manage *handle, struct frag_ipq *ipq, struct ip_frag |-------------------buf_size ----------------------|
|---first ip hdr len --| --- ip frags total len ---|
- buf_size�ڴ��Ϊ����, ��һ����Ƭ����ԭʼͷ�����ܵķ�Ƭ���ݳ���֮��.
+ buf_size�ڴ��Ϊ����, ��һ����Ƭ����ԭʼͷ�����ܵķ�Ƭ���ݳ���֮��.
*/
struct frag_ipq* frag_ipq_create(int thread_num)
{
@@ -202,16 +202,16 @@ struct frag_ipq* frag_ipq_create(int thread_num) ipq->thread_num = thread_num;
- /* Ϊ��IP������ռ�, ��ʼ��СΪ2048�ֽ� */
+ /* Ϊ��IP������ռ�, ��ʼ��СΪ2048�ֽ� */
ipq->new_iph = sapp_mem_malloc(SAPP_MEM_DYN_IP_FRAG_PKT, thread_num, IP_FRAG_DEFAULT_BUF_SIZE);
ipq->buf_size = IP_FRAG_DEFAULT_BUF_SIZE;
- ipq->create_time = g_CurrentTime;
+ ipq->create_time = ABBR_CURRENT_TIME;
return ipq;
}
#else
-/* ����һ���µķ�Ƭ������� */
+/* ����һ���µķ�Ƭ������� */
struct frag_ipq* frag_ipq_create(struct frag_manage *handle, void *key_stack,
int key_size, unsigned int hash_index)
{
@@ -229,11 +229,11 @@ struct frag_ipq* frag_ipq_create(struct frag_manage *handle, void *key_stack, ipq->hash_index = hash_index;
- /* Ϊ��IP������ռ�, ��ʼ��СΪ2048�ֽ� */
+ /* Ϊ��IP������ռ�, ��ʼ��СΪ2048�ֽ� */
ipq->new_iph = frag_malloc(handle, IP_FRAG_DEFAULT_BUF_SIZE);
ipq->buf_size = IP_FRAG_DEFAULT_BUF_SIZE;
- ipq->create_time = g_CurrentTime;
+ ipq->create_time = ABBR_CURRENT_TIME;
frag_add_lru_node(handle, ipq);
frag_add_hash_node(handle, ipq);
@@ -244,7 +244,7 @@ struct frag_ipq* frag_ipq_create(struct frag_manage *handle, void *key_stack, #if USE_MESA_STREAM_HASH==0
-/* ��ȫɾ��һ��ipq�ṹ���ͷ����е��ڴ���Դ */
+/* ��ȫɾ��һ��ipq�ṹ���ͷ����е��ڴ���Դ */
void frag_ipq_kill(struct frag_manage *handle, struct frag_ipq *ipq)
{
struct ip_frags *frag, *next;
@@ -280,7 +280,7 @@ void frag_ipq_kill(struct frag_manage *handle, struct frag_ipq *ipq) #endif
#if (USE_MESA_STREAM_HASH==0)
-/* ���ݲ���key���ҵ��˷�Ƭ��������ipq���� */
+/* ���ݲ���key���ҵ��˷�Ƭ��������ipq���� */
struct frag_ipq* frag_ipq_find(struct frag_manage *handle, void *key, int key_size)
{
uint32 hash_index;
@@ -296,8 +296,8 @@ struct frag_ipq* frag_ipq_find(struct frag_manage *handle, void *key, int key_si }
}
- /* �Ҳ�����Ӧipq�ṹ�Ļ������½�ipq�ṹ������hash_index��Ϊһ��������
- ���ݸ�frag_ipq_create(), �������HASH��ʱ���ٴμ���һ��HASHֵ.
+ /* �Ҳ�����Ӧipq�ṹ�Ļ������½�ipq�ṹ������hash_index��Ϊһ��������
+ ���ݸ�frag_ipq_create(), �������HASH��ʱ���ٴμ���һ��HASHֵ.
*/
if(NULL == ipq)
{
@@ -309,8 +309,8 @@ struct frag_ipq* frag_ipq_find(struct frag_manage *handle, void *key, int key_si #endif
/*
- �յ����еķ�Ƭ�����������һ��������ԭʼ�������ͷ�ռ�õ����������ڴ���Դ.
- ����ֵ: ԭʼIP��ͷָ��
+ �յ����еķ�Ƭ�����������һ��������ԭʼ�������ͷ�ռ�õ����������ڴ���Դ.
+ ����ֵ: ԭʼIP��ͷָ��
*/
#if USE_MESA_STREAM_HASH
void *frag_reassemble(struct frag_manage *handle, struct frag_ipq *ipq)
@@ -319,7 +319,7 @@ void *frag_reassemble(struct frag_manage *handle, struct frag_ipq *ipq) new_iph = ipq->new_iph;
- /* ����ֻ�����ڴ�ռ��ֵ��ʵ�ʵ��ڴ�free�������ϲ�ģ�鴦����֮�� */
+ /* ����ֻ�����ڴ�ռ��ֵ��ʵ�ʵ��ڴ�free�������ϲ�ģ�鴦����֮�� */
handle->total_mem -= ipq->buf_size;
return new_iph;
@@ -345,7 +345,7 @@ void *frag_reassemble(struct frag_manage *handle, struct frag_ipq *ipq) new_iph = ipq->new_iph;
- /* ����ֻ�����ڴ�ռ��ֵ��ʵ�ʵ��ڴ�free�������ϲ�ģ�鴦����֮�� */
+ /* ����ֻ�����ڴ�ռ��ֵ��ʵ�ʵ��ڴ�free�������ϲ�ģ�鴦����֮�� */
handle->total_mem -= ipq->buf_size;
frag_free(handle, ipq->hash_key, ipq->hash_key_size);
@@ -364,7 +364,7 @@ static inline unsigned int rol32(unsigned int word, unsigned int shift) return (word << shift) | (word >> (32 - shift));
}
-/* HASH�㷨��COPY��LINUX�ں�Դ���� */
+/* HASH�㷨��COPY��LINUX�ں�Դ���� */
#define __frag_common_hash(a, b, c) { \
c ^= b; c -= rol32(b, 14); \
a ^= c; a -= rol32(c, 11); \
@@ -375,7 +375,7 @@ static inline unsigned int rol32(unsigned int word, unsigned int shift) c ^= b; c -= rol32(b, 24); \
}
-/* HASH�㷨��COPY��LINUX�ں�Դ���� */
+/* HASH�㷨��COPY��LINUX�ں�Դ���� */
unsigned int frag_common_hash(unsigned int a, unsigned int b, unsigned int c, unsigned int initval)
{
a += JHASH_INITVAL;
diff --git a/src/dealpkt/plug_support.c b/src/dealpkt/plug_support.c index fab2c0d..368c0fb 100644 --- a/src/dealpkt/plug_support.c +++ b/src/dealpkt/plug_support.c @@ -770,12 +770,12 @@ void layer_addr_free(struct layer_addr *paddrinfo) time_t get_timestamp_s(void)
{
- return g_CurrentTime;
+ return ABBR_CURRENT_TIME;
}
long long get_timestamp_ms(void)
{
- return g_CurrentTime_ms;
+ return ABBR_CURRENT_TIME_MS;
}
/*
@@ -1099,7 +1099,7 @@ int MESA_set_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o timeout_init(&funinfo->timeout, TIMEOUT_ABS);
G_MESA_GLOBAL_STREAM[pstream->threadnum]->user_define_timer_cnt+=1;
}
- timeouts_add(G_MESA_GLOBAL_STREAM[pstream->threadnum]->user_define_timer, &funinfo->timeout, set_timer_s*1000+g_CurrentTime_ms);
+ timeouts_add(G_MESA_GLOBAL_STREAM[pstream->threadnum]->user_define_timer, &funinfo->timeout, set_timer_s*1000+ABBR_MONOTONIC_TIME_MS);
ret = 0;
}
break;
diff --git a/src/dealpkt/stream_manage.c b/src/dealpkt/stream_manage.c index ebb9f69..ff1dd71 100644 --- a/src/dealpkt/stream_manage.c +++ b/src/dealpkt/stream_manage.c @@ -84,25 +84,25 @@ static int init_stream_detail(struct global_stream *g_stream) if (sapp_global_val->config.stream.udp.max_opening_per_sec > 0) { g_stream->udp_opening_ratelimiter = - token_bucket_new(g_CurrentTime_ms, sapp_global_val->config.stream.udp.max_opening_per_sec, + token_bucket_new(ABBR_MONOTONIC_TIME_MS, sapp_global_val->config.stream.udp.max_opening_per_sec, sapp_global_val->config.stream.udp.max_opening_per_sec); } if (sapp_global_val->config.stream.tcp.max_opening_per_sec > 0) { g_stream->tcp_opening_ratelimiter = - token_bucket_new(g_CurrentTime_ms, sapp_global_val->config.stream.tcp.max_opening_per_sec, + token_bucket_new(ABBR_MONOTONIC_TIME_MS, sapp_global_val->config.stream.tcp.max_opening_per_sec, sapp_global_val->config.stream.tcp.max_opening_per_sec); } if (sapp_global_val->config.stream.udp.max_timeouts_per_sec > 0) { g_stream->udp_timeout_ratelimiter = - token_bucket_new(g_CurrentTime_ms, sapp_global_val->config.stream.udp.max_timeouts_per_sec, + token_bucket_new(ABBR_MONOTONIC_TIME_MS, sapp_global_val->config.stream.udp.max_timeouts_per_sec, sapp_global_val->config.stream.udp.max_timeouts_per_sec); } if (sapp_global_val->config.stream.tcp.max_timeouts_per_sec > 0) { g_stream->tcp_timeout_ratelimiter = - token_bucket_new(g_CurrentTime_ms, sapp_global_val->config.stream.tcp.max_timeouts_per_sec, + token_bucket_new(ABBR_MONOTONIC_TIME_MS, sapp_global_val->config.stream.tcp.max_timeouts_per_sec, sapp_global_val->config.stream.tcp.max_timeouts_per_sec); } @@ -213,7 +213,7 @@ static void stream_timeout_shift_lrulist(struct streamindex *pindex, unsigned sh lru_list_root=&(G_MESA_GLOBAL_STREAM[pstream->threadnum]->udpList[pstream->stream_state]); } - timeouts_add(lru_list_root->streamindex_timer, &pindex->timeout, new_timeout*1000+g_CurrentTime_ms); + timeouts_add(lru_list_root->streamindex_timer, &pindex->timeout, new_timeout*1000+ABBR_MONOTONIC_TIME_MS); return; } @@ -323,10 +323,10 @@ void streamaddlist(struct streamindex *pindex,struct stream_list *plist) struct streamindex *pindex_to_del = NULL; if(plist->cnt >= plist->max_cnt-1 && plist->cnt > 0) { - if(plist->last_update_timer_ms < g_CurrentTime_ms) + if(plist->last_update_timer_ms < ABBR_MONOTONIC_TIME_MS) { - timeouts_update(plist->streamindex_timer, g_CurrentTime_ms); - plist->last_update_timer_ms = g_CurrentTime_ms; + timeouts_update(plist->streamindex_timer, ABBR_MONOTONIC_TIME_MS); + plist->last_update_timer_ms = ABBR_MONOTONIC_TIME_MS; plist->interval_to_next_timeout_ms=timeouts_timeout(plist->streamindex_timer); } struct timeout *t = NULL; @@ -349,7 +349,7 @@ void streamaddlist(struct streamindex *pindex,struct stream_list *plist) pindex_to_del->stream.stream_public.stream_state, pindex_to_del->stream.stream_public.ptcpdetail->createtime, pindex_to_del->stream.stream_public.ptcpdetail->lastmtime, - g_CurrentTime); + ABBR_CURRENT_TIME); if(pindex_to_del->stream.stream_public.type == STREAM_TYPE_UDP && sapp_global_val->config.packet_io.dup_pkt_para.kickout_udp_stream_enabled) { sapp_dup_stream_add(&pindex_to_del->stream.stream_public); @@ -363,18 +363,18 @@ void streamaddlist(struct streamindex *pindex,struct stream_list *plist) timeout_init(&pindex->timeout, TIMEOUT_ABS); if (pstream->stream_state == TCP_SYN_STATE && pstream->type == STREAM_TYPE_TCP) { - next_timeout_ms = tcp_opening_timeout * 1000 + g_CurrentTime_ms; + next_timeout_ms = tcp_opening_timeout * 1000 + ABBR_MONOTONIC_TIME_MS; } else if ((pstream->stream_state == TCP_NOUSE_STATE && pstream->type == STREAM_TYPE_TCP) && (sapp_global_val->config.stream.tcp.fast_close_discard == 1)) { if(pstream_pr->set_special_timeout==0) { - next_timeout_ms = tcp_closing_timeout * 1000 + g_CurrentTime_ms; + next_timeout_ms = tcp_closing_timeout * 1000 + ABBR_MONOTONIC_TIME_MS; } else { - next_timeout_ms = pindex->stream.timeout * 1000 + g_CurrentTime_ms; + next_timeout_ms = pindex->stream.timeout * 1000 + ABBR_MONOTONIC_TIME_MS; } } else @@ -382,7 +382,7 @@ void streamaddlist(struct streamindex *pindex,struct stream_list *plist) long set_timeout = pindex->stream.timeout; if (set_timeout == 0) set_timeout = MAX_DEFALUT_TIMEOUT_S; - next_timeout_ms = set_timeout * 1000 + g_CurrentTime_ms; + next_timeout_ms = set_timeout * 1000 + ABBR_MONOTONIC_TIME_MS; } timeouts_add(plist->streamindex_timer, &pindex->timeout, next_timeout_ms); sapp_runtime_log(RLOG_LV_DEBUG, "streamaddlist timeout_add: %s, thread:%d, stream_type:%d, stream_state:%d, curtime:%ld, next_timeout_s:%ld!", @@ -390,7 +390,7 @@ void streamaddlist(struct streamindex *pindex,struct stream_list *plist) pindex->stream.stream_public.threadnum, pstream->type, pstream->stream_state, - g_CurrentTime, + ABBR_CURRENT_TIME, next_timeout_ms); plist->cnt++; @@ -457,15 +457,15 @@ int del_stream_by_time(struct stream_list *plist, int tid, enum stream_type_t ty struct timeout *t=NULL; struct global_stream *g_stream = G_MESA_GLOBAL_STREAM[tid]; sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[tid]->sys_stat; - if(unlikely(plist->last_update_timer_ms < g_CurrentTime_ms)) + if(unlikely(plist->last_update_timer_ms < ABBR_MONOTONIC_TIME_MS)) { - timeouts_update(plist->streamindex_timer, g_CurrentTime_ms); + timeouts_update(plist->streamindex_timer, ABBR_MONOTONIC_TIME_MS); if(g_stream->user_define_timer_cnt > 0) { - timeouts_update(g_stream->user_define_timer, g_CurrentTime_ms); + timeouts_update(g_stream->user_define_timer, ABBR_MONOTONIC_TIME_MS); g_stream->interval_to_next_timeout_ms = timeouts_timeout(g_stream->user_define_timer); } - plist->last_update_timer_ms = g_CurrentTime_ms; + plist->last_update_timer_ms = ABBR_MONOTONIC_TIME_MS; plist->interval_to_next_timeout_ms=timeouts_timeout(plist->streamindex_timer); } else @@ -527,7 +527,7 @@ int del_stream_by_time(struct stream_list *plist, int tid, enum stream_type_t ty if(app_ret == APP_STATE_GIVEME) { - timeouts_add(g_stream->user_define_timer, t, funinfo->set_timer_s*1000+g_CurrentTime_ms); + timeouts_add(g_stream->user_define_timer, t, funinfo->set_timer_s*1000+ABBR_MONOTONIC_TIME_MS); } else { @@ -555,18 +555,18 @@ void lrustream(struct streamindex *pindex) if (pstream->stream_state == TCP_SYN_STATE && pstream->type == STREAM_TYPE_TCP) { - timeouts_add(plist->streamindex_timer, &pindex->timeout, tcp_opening_timeout * 1000 + g_CurrentTime_ms); + timeouts_add(plist->streamindex_timer, &pindex->timeout, tcp_opening_timeout * 1000 + ABBR_MONOTONIC_TIME_MS); } else if (pstream->stream_state == TCP_NOUSE_STATE && pstream->type == STREAM_TYPE_TCP && (sapp_global_val->config.stream.tcp.fast_close_discard == 1)) { if (pstream_pr->set_special_timeout == 0) { - timeouts_add(plist->streamindex_timer, &pindex->timeout, tcp_closing_timeout * 1000 + g_CurrentTime_ms); + timeouts_add(plist->streamindex_timer, &pindex->timeout, tcp_closing_timeout * 1000 + ABBR_MONOTONIC_TIME_MS); } else { - timeouts_add(plist->streamindex_timer, &pindex->timeout, pindex->stream.timeout * 1000 + g_CurrentTime_ms); + timeouts_add(plist->streamindex_timer, &pindex->timeout, pindex->stream.timeout * 1000 + ABBR_MONOTONIC_TIME_MS); } } else @@ -1449,7 +1449,7 @@ void hash_add_stream(struct streamindex *pindex) if (STREAM_TYPE_UDP == ptmp->type && G_MESA_GLOBAL_STREAM[threadnum]->udp_opening_ratelimiter != NULL) { if (token_bucket_consume(G_MESA_GLOBAL_STREAM[threadnum]->udp_opening_ratelimiter, 1, - g_current_time_ms) == 0) + ABBR_MONOTONIC_TIME_MS) == 0) { pindex->stream.under_ddos_bypass = 1; local_sys_stat->count[SAPP_STAT_UDP_OPENING_OVERSPEED]++; @@ -1458,7 +1458,7 @@ void hash_add_stream(struct streamindex *pindex) if (STREAM_TYPE_TCP == ptmp->type && G_MESA_GLOBAL_STREAM[threadnum]->tcp_opening_ratelimiter != NULL) { if (token_bucket_consume(G_MESA_GLOBAL_STREAM[threadnum]->tcp_opening_ratelimiter, 1, - g_current_time_ms) == 0) + ABBR_MONOTONIC_TIME_MS) == 0) { pindex->stream.under_ddos_bypass = 1; local_sys_stat->count[SAPP_STAT_TCP_OPENING_OVERSPEED]++; @@ -2426,7 +2426,7 @@ unsigned long long get_global_stream_id(unsigned long long thread_seq) unsigned long long relative_base_time; stream_seq = sapp_global_val->mthread_volatile[thread_seq]->stream_seq_per_thread++ % THREAD_SEQ_MAX; - relative_base_time = (g_CurrentTime - sapp_global_val->config.stream.stream_id_base_time_t) % RELATIVE_TIME_MAX; + relative_base_time = (ABBR_CURRENT_TIME - sapp_global_val->config.stream.stream_id_base_time_t) % RELATIVE_TIME_MAX; glo_sid = (thread_seq << 43) | (relative_base_time << 15) | (stream_seq); diff --git a/src/extensions/inline_keepalive.cpp b/src/extensions/inline_keepalive.cpp index 8e79bf6..d913766 100644 --- a/src/extensions/inline_keepalive.cpp +++ b/src/extensions/inline_keepalive.cpp @@ -1,11 +1,11 @@ /* - ��WY��Ŀ��������, �Ƿ���GDEV�����Ǹ��ݲ��������״̬��̬����, �������ٹ̶�һֱ����, + ��WY��Ŀ��������, �Ƿ���GDEV�����Ǹ��ݲ��������״̬��̬����, �������ٹ̶�һֱ����, - ���Խ�GDEV-KEEPALIVE���ܴ�ƽ̨�а���, - ���ص�IP��UDP�������ԭ�б����. + ���Խ�GDEV-KEEPALIVE���ܴ�ƽ̨�а���, + ���ص�IP��UDP�������ԭ�б����. - Ŀǰû��arp_entry, ethernet_entry, ARP�ظ�������ʱ������ƽ̨�ڲ�. + Ŀǰû��arp_entry, ethernet_entry, ARP�ظ�������ʱ������ƽ̨�ڲ�. */ #include <pthread.h> @@ -27,10 +27,10 @@ extern char * (*ptr_marsio_buff_append)(marsio_buff_t *m, uint16_t len); extern void (*ptr_marsio_buff_free)(struct mr_instance * instance, marsio_buff_t *marsio_buff[],unsigned int nr_mbufs, int socket_id, int thread_id); #endif -#define MAX_SUPPORT_GDEV_NUM (64) /* ÿ���߳������֧��inline device������, ���ݷ������Ժ��߳����IJ�ͬ, ��Сֵ��MAX_SUPPORT_GDEV_NUM, ���ֵ��MAX_SUPPORT_GDEV_NUM * sapp_thread_count */ -#define MAX_VXLAN_SERVICE_NUM (256) /* Ŀǰ���֧��255�ֲ�ͬҵ��, �����±������255 */ +#define MAX_SUPPORT_GDEV_NUM (64) /* ÿ���߳������֧��inline device������, ���ݷ������Ժ��߳����IJ�ͬ, ��Сֵ��MAX_SUPPORT_GDEV_NUM, ���ֵ��MAX_SUPPORT_GDEV_NUM * sapp_thread_count */ +#define MAX_VXLAN_SERVICE_NUM (256) /* Ŀǰ���֧��255�ֲ�ͬҵ��, �����±������255 */ -#define MAX_NO_PKT_TIMEOUT (120) /* ������ô��ʱ��һֱû�����, �Ѵ��豸�� */ +#define MAX_NO_PKT_TIMEOUT (120) /* ������ô��ʱ��һֱû�����, �Ѵ��豸�� */ static void *gdev_kp_log_handle; enum prog_work_mode_t{ @@ -47,27 +47,27 @@ enum gdev_keepalive_fs2_column_t{ /* - ÿ���߳�, ÿ��Inline-DEV-IP, ÿ��ҵ��ֱ�ͳ��. + ÿ���߳�, ÿ��Inline-DEV-IP, ÿ��ҵ��ֱ�ͳ��. */ typedef struct { int gdev_keepalive_type; /* for example: GDEV_KEEPALIVE_TYPE_BFD */ //int gdev_keepalive_service_num; - unsigned int keepalive_request_num; /* ��ǰҵ�����������, ÿ��һ��ʱ������ */ - unsigned int keepalive_reply_num; /* ��ǰҵ��Ӧ�������, ����service��ͬ, ����ijЩҵ����ⲻ�ظ�Ӧ��, ����request����һ������reply */ - int field_stat_line_id; /* fs2 �������id */ - time_t last_time; /* ��ǰҵ�����һ���յ��������ʱ�� */ + unsigned int keepalive_request_num; /* ��ǰҵ�����������, ÿ��һ��ʱ������ */ + unsigned int keepalive_reply_num; /* ��ǰҵ��Ӧ�������, ����service��ͬ, ����ijЩҵ����ⲻ�ظ�Ӧ��, ����request����һ������reply */ + int field_stat_line_id; /* fs2 �������id */ + time_t last_time; /* ��ǰҵ�����һ���յ��������ʱ�� */ }gdev_keepalive_status_per_service_t; typedef struct{ - int inuse_flag; /* ��λ�ñ�ռ�� */ + int inuse_flag; /* ��λ�ñ�ռ�� */ unsigned int gdev_ip_network_order; - unsigned int keepalive_request_num; /* ��ǰ�豸�������������, ÿ��һ��ʱ������ */ - unsigned int keepalive_reply_num; /* ��ǰ�豸����Ӧ�������, ����service��ͬ, ����ijЩҵ����ⲻ�ظ�Ӧ��, ����request����һ������reply */ + unsigned int keepalive_request_num; /* ��ǰ�豸�������������, ÿ��һ��ʱ������ */ + unsigned int keepalive_reply_num; /* ��ǰ�豸����Ӧ�������, ����service��ͬ, ����ijЩҵ����ⲻ�ظ�Ӧ��, ����request����һ������reply */ int fs2_line_id; - time_t last_time; /* ��ǰ�豸���һ���յ��������ʱ�� */ - gdev_keepalive_status_per_service_t service_array[MAX_VXLAN_SERVICE_NUM]; /* ��BFDЭ���������service, ICMPĬ�϶���0��ҵ�� */ + time_t last_time; /* ��ǰ�豸���һ���յ��������ʱ�� */ + gdev_keepalive_status_per_service_t service_array[MAX_VXLAN_SERVICE_NUM]; /* ��BFDЭ���������service, ICMPĬ�϶���0��ҵ�� */ }gdev_keepalive_status_per_dev_t; @@ -80,30 +80,28 @@ typedef struct _gdev_keepalive_status_per_thread gdev_keepalive_status_per_threa /* - ˵��: gdev�ı���״̬����һ����������, ��Ϊ���Ȳ�֪������, + ˵��: gdev�ı���״̬����һ����������, ��Ϊ���Ȳ�֪������, - ��Ϊʲô����hash? ����? ��̬����? + ��Ϊʲô����hash? ����? ��̬����? - ����ģʽ�Ƕ���߳�д, һ���̶߳�ȡ���������, ����Ƕ�̬�����ݽṹ, �ⲻ��Ҫ����, - ʹ���������ȷ��������ڴ�, ����־λinuse_flag��ʾ�Ƿ���ʹ��, ��֤��д����ͻ. + ����ģʽ�Ƕ���߳�д, һ���̶߳�ȡ���������, ����Ƕ�̬�����ݽṹ, �ⲻ��Ҫ����, + ʹ���������ȷ��������ڴ�, ����־λinuse_flag��ʾ�Ƿ���ʹ��, ��֤��д����ͻ. */ static gdev_keepalive_status_per_thread_t GDEV_KEEPALIVE_STAT[MAX_THREAD_NUM]; -static volatile int g_dev_keepalive_flag = 1; /* ȫ�ֱ����־, ���в���������������Ҫ������������ */ +static volatile int g_dev_keepalive_flag = 1; /* ȫ�ֱ����־, ���в���������������Ҫ������������ */ -static volatile struct gdev_keepalive_service_ctrl g_dev_keepalive_service_ctrl_array[MAX_VXLAN_SERVICE_NUM];/* ����ij��ҵ����Ƿ� */ +static volatile struct gdev_keepalive_service_ctrl g_dev_keepalive_service_ctrl_array[MAX_VXLAN_SERVICE_NUM];/* ����ij��ҵ����Ƿ� */ -//extern int g_packet_io_thread_num; -//extern time_t g_CurrentTime; -static int g_dev_keepalive_default_action = 1; /* ����g_dev_keepalive_service_ctrl_array��û�е�ҵ���, �DZ���Dz����� */ -static unsigned int sendto_gdev_card_ip; /* ��Gdev����������IP��ַ, ������, network-order */ +static int g_dev_keepalive_default_action = 1; /* ����g_dev_keepalive_service_ctrl_array��û�е�ҵ���, �DZ���Dz����� */ +static unsigned int sendto_gdev_card_ip; /* ��Gdev����������IP��ַ, ������, network-order */ extern int sendpacket_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum, u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, unsigned char *buf); extern char *timet_to_str(time_t timet, char *time_str, int time_str_len); static int vxlan_sport_service_map_init(void); extern void del_last_rn(char *data, int max_len); -static unsigned char g_vxlan_sport_to_service_id[65536]; /* �����±�ΪԴ�˿�, ֵΪservice-id, �������ֵ��65535 */ +static unsigned char g_vxlan_sport_to_service_id[65536]; /* �����±�ΪԴ�˿�, ֵΪservice-id, �������ֵ��65535 */ static int gdev_kp_action_judge(int service_id) @@ -117,10 +115,10 @@ static int gdev_kp_action_judge(int service_id) /* - prometheus fs2 line���Ʋ��ܰ�����Щ�ַ�: + prometheus fs2 line���Ʋ��ܰ�����Щ�ַ�: const char* reserverd="|:\n\r. \t<>[]#!@"; - ����ip��ַ�ķָ�����Ҫ�ij�'_' + ����ip��ַ�ķָ�����Ҫ�ij�'_' */ static const char *fs2_inet_ntop(unsigned int gip_net, char *buf, int buf_len) { @@ -175,7 +173,7 @@ static void gdev_keepalive_stat_update(int tid, unsigned int gip_net, int type, /* update this device */ cur_thread_stat->gdev_array[index].inuse_flag = 1; cur_thread_stat->gdev_array[index].gdev_ip_network_order = gip_net; - cur_thread_stat->gdev_array[index].last_time = g_CurrentTime; + cur_thread_stat->gdev_array[index].last_time = ABBR_CURRENT_TIME; cur_thread_stat->gdev_array[index].keepalive_request_num++; cur_thread_stat->gdev_array[index].keepalive_reply_num++; @@ -185,12 +183,12 @@ static void gdev_keepalive_stat_update(int tid, unsigned int gip_net, int type, if(action){ cur_thread_stat->gdev_array[index].service_array[service_id].keepalive_reply_num++; } - cur_thread_stat->gdev_array[index].service_array[service_id].last_time = g_CurrentTime; + cur_thread_stat->gdev_array[index].service_array[service_id].last_time = ABBR_CURRENT_TIME; return; } -/* �����豸�������BFDЭ�� */ +/* �����豸�������BFDЭ�� */ static int gdev_keepalive_bfd_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, unsigned char *send_buf) { char payload_buf[1472]; @@ -207,13 +205,13 @@ static int gdev_keepalive_bfd_plug(const raw_pkt_t *raw_pkt, int thread_id, unsi service_id = vxlan_sport_map_to_service_id(ntohs(udp_hdr->uh_sport)); action = gdev_kp_action_judge(service_id); - /* ��ʹaction=0, stat_updateҲҪ����, ��Ҫͳ�Ʋ��ظ������ҵ����Ϣ */ + /* ��ʹaction=0, stat_updateҲҪ����, ��Ҫͳ�Ʋ��ظ������ҵ����Ϣ */ gdev_keepalive_stat_update(thread_id, ip_hdr->ip_src.s_addr, GDEV_KEEPALIVE_TYPE_BFD, service_id, action); if(0 == action){ return -1; } - /* ��ȡ����service_id, ����Ӧ�ûظ�����Ӧ��, go on !! */ + /* ��ȡ����service_id, ����Ӧ�ûظ�����Ӧ��, go on !! */ memcpy(payload_buf, bfd_net_hdr, payload_len); @@ -232,7 +230,7 @@ static int gdev_keepalive_bfd_plug(const raw_pkt_t *raw_pkt, int thread_id, unsi sendpacket_build_ethernet(raw_eth_hdr->ether_shost, raw_eth_hdr->ether_dhost, ETH_P_IP, NULL, 0, send_buf); - sendpacket_build_udp_dual_stack(ntohs(udp_hdr->uh_sport), /* BFDЭ�鲻����Դ��Ŀ�Ķ˿� */ + sendpacket_build_udp_dual_stack(ntohs(udp_hdr->uh_sport), /* BFDЭ�鲻����Դ��Ŀ�Ķ˿� */ ntohs(udp_hdr->uh_dport), (char *)bfd_send_hdr, payload_len, @@ -246,7 +244,7 @@ static int gdev_keepalive_bfd_plug(const raw_pkt_t *raw_pkt, int thread_id, unsi ip_hdr->ip_ttl, IPPROTO_UDP, ip_hdr->ip_dst.s_addr, - ip_hdr->ip_src.s_addr, /* ����Դ��Ŀ��IP��ַ */ + ip_hdr->ip_src.s_addr, /* ����Դ��Ŀ��IP��ַ */ NULL, 0, send_buf + SENDPACKET_ETH_H); @@ -261,7 +259,7 @@ static int gdev_keepalive_bfd_plug(const raw_pkt_t *raw_pkt, int thread_id, unsi return SENDPACKET_IP_H + SENDPACKET_UDP_H+sizeof(bfd_header_t) + sizeof(struct mesa_ethernet_hdr); } -/* �����豸�������BFDЭ�� */ +/* �����豸�������BFDЭ�� */ static int gdev_keepalive_icmp_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, unsigned char *send_buf) { struct mesa_ethernet_hdr *raw_eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data; @@ -355,10 +353,10 @@ err: return -1; } -/* �ڴ���UDP����, ����ʶ����Щ������BFD����� */ +/* �ڴ���UDP����, ����ʶ����Щ������BFD����� */ static inline int gdev_bfd_pkt_identify(const struct streaminfo *a_udp) { - if(g_topology_mode != NET_CONN_SERIAL_GDEV){ /* ��G����ģʽ */ + if(g_topology_mode != NET_CONN_SERIAL_GDEV){ /* ��G����ģʽ */ return 0; } @@ -371,7 +369,7 @@ static inline int gdev_bfd_pkt_identify(const struct streaminfo *a_udp) return 0; } - if(ADDR_TYPE_IPV4 != a_udp->addr.addrtype){ /* Ŀǰ������IPv4 */ + if(ADDR_TYPE_IPV4 != a_udp->addr.addrtype){ /* Ŀǰ������IPv4 */ return 0; } @@ -495,8 +493,8 @@ static void gdev_keepalive_clear_stat(void) this_dev_stat->keepalive_request_num = 0; this_dev_stat->keepalive_reply_num = 0; -#if 0 /* �Ȳ�֧����̭, ��Ϊ��ǰ�豸��line_id�Ѿ�ע�ᵽfs2, ����ʹ�õĻ�, name������ */ - if(this_dev_stat->last_time + MAX_NO_PKT_TIMEOUT < g_CurrentTime){ +#if 0 /* �Ȳ�֧����̭, ��Ϊ��ǰ�豸��line_id�Ѿ�ע�ᵽfs2, ����ʹ�õĻ�, name������ */ + if(this_dev_stat->last_time + MAX_NO_PKT_TIMEOUT < ABBR_CURRENT_TIME){ char dev_ip_str[INET6_ADDRSTRLEN]; this_dev_stat->inuse_flag = 0; inet_ntop(AF_INET, &this_dev_stat->gdev_ip_network_order, dev_ip_str, sizeof(dev_ip_str)); @@ -531,7 +529,7 @@ static void *gdev_keepalive_log_thread(void *arg) last_op_time = time(NULL); __gdev_keepalive_pkt_calc_pps(); gdev_keepalive_update_local_log(); - //gdev_keepalive_clear_stat(); /* ÿ����ռ���, ֻ����һ��ʱ������� */ + //gdev_keepalive_clear_stat(); /* ÿ����ռ���, ֻ����һ��ʱ������� */ } return NULL; @@ -550,14 +548,14 @@ static int gdev_kp_update_service_ctrl(const struct gdev_keepalive_service_ctrl -/* vxlan�������, vpn-id, Դ�˿ں�ҵ��ID֮��Ĺ�ϵ, �����ļ���ʽ: +/* vxlan�������, vpn-id, Դ�˿ں�ҵ��ID֮��Ĺ�ϵ, �����ļ���ʽ: service-id VPN-id Sport-range 1 101 50000-50016 2 102 50064-50080 ...... - ���ڸ�֪�ϲ�Ӧ��ҵ���, �ʹ�������ҵ���Ƿ���Ҫ����. + ���ڸ�֪�ϲ�Ӧ��ҵ���, �ʹ�������ҵ���Ƿ���Ҫ����. */ @@ -603,7 +601,7 @@ static int vxlan_sport_service_map_init(void) } tmp_service_id = atoi(section); - /* VPN-id, ��ʱ����ת��, ֱ�Ӽ�100����ҵ��� */ + /* VPN-id, ��ʱ����ת��, ֱ�Ӽ�100����ҵ��� */ section = strtok_r(NULL, delim, &save_ptr); if(NULL == section){ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", ABBR_VXLAN_SPORT_MAP_CONF_FILE); @@ -658,7 +656,7 @@ done: extern "C" { #endif -/* �������vxlanģʽ��, ���ݰ��Ƿ�������� */ +/* �������vxlanģʽ��, ���ݰ��Ƿ�������� */ int vxlan_packet_is_myself(const raw_pkt_t *rawpkt) { struct mesa_ip4_hdr *ip4h = (struct mesa_ip4_hdr *)((char *)rawpkt->raw_pkt_data + sizeof(struct mesa_ethernet_hdr)); @@ -701,14 +699,14 @@ int gdev_keepalive_set_opt(const SAPP_TLV_T *tlv_value) ret = gdev_kp_update_service_ctrl(actual_val); if(ret < 0){ - if(last_log_time < g_CurrentTime){ - last_log_time = g_CurrentTime; + if(last_log_time < ABBR_CURRENT_TIME){ + last_log_time = ABBR_CURRENT_TIME; MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "set gdev-keepalive error! service:%d, action:%d", actual_val->service_num, actual_val->keepalive_switch); } }else{ - if(last_log_time < g_CurrentTime){ - last_log_time = g_CurrentTime; + if(last_log_time < ABBR_CURRENT_TIME){ + last_log_time = ABBR_CURRENT_TIME; MESA_handle_runtime_log(gdev_kp_log_handle, 10, "[gdev_keepalive]", "set gdev-keepalive, service:%d, action:%d", actual_val->service_num, actual_val->keepalive_switch); } @@ -722,9 +720,9 @@ int gdev_keepalive_set_opt(const SAPP_TLV_T *tlv_value) return -1; } g_dev_keepalive_flag = tlv_value->int_value; - if(last_log_time < g_CurrentTime){ + if(last_log_time < ABBR_CURRENT_TIME){ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "set global keepalive to %d", tlv_value->int_value); - last_log_time = g_CurrentTime; + last_log_time = ABBR_CURRENT_TIME; } } break; @@ -791,10 +789,10 @@ char gdev_keepalive_udp_entry(const struct streaminfo *a_udp, void **pme, int t a_udp_pr = (const struct streaminfo_private *)a_udp; kp_ret = gdev_keepalive_plug(a_udp_pr->raw_pkt, a_udp->threadnum, a_udp->routedir, GDEV_KEEPALIVE_TYPE_BFD); if(kp_ret < 0){ - /* ������, socket�ȴ����ܷ���APP_STATE_DROPME, ����DROP ME����Ҳ�ò������������, ���Dz������ͨ��gdev_keepalive_set_opt()�رձ����, ����Ҫ����DROPPKT, ���ܰ��������ע */ + /* ������, socket�ȴ����ܷ���APP_STATE_DROPME, ����DROP ME����Ҳ�ò������������, ���Dz������ͨ��gdev_keepalive_set_opt()�رձ����, ����Ҫ����DROPPKT, ���ܰ��������ע */ entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; }else{ - entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; /* �����, ������ǰ�� */ + entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; /* �����, ������ǰ�� */ } return entry_ret; @@ -826,7 +824,7 @@ char gdev_keepalive_ip_entry(const struct streaminfo *pstream,unsigned char rout if(kp_ret < 0){ entry_ret = APP_STATE_DROPME | APP_STATE_DROPPKT; }else{ - entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; /* �����, ������ǰ�� */ + entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; /* �����, ������ǰ�� */ } return entry_ret; @@ -843,7 +841,7 @@ int gdev_keepalive_plug_init(void) gdev_kp_log_handle = sapp_global_val->individual_fixed.log_handle; - /* ���߳�ģʽ��α��������, 64B������� */ + /* ���߳�ģʽ��α��������, 64B������� */ assert(sizeof(gdev_keepalive_status_per_thread_t) % 64 == 0); opt_len = sizeof(deploy_mode_string); @@ -853,7 +851,7 @@ int gdev_keepalive_plug_init(void) return -1; } - if(strncasecmp(deploy_mode_string, "inline", strlen("inline")) != 0){ /* ��G����ģʽ */ + if(strncasecmp(deploy_mode_string, "inline", strlen("inline")) != 0){ /* ��G����ģʽ */ MESA_handle_runtime_log(gdev_kp_log_handle, 30, "[gdev_keepalive]", "not inline mode, can't load gdev_keepalive.so\n"); return -1; } diff --git a/src/extensions/sapp_assistant.cpp b/src/extensions/sapp_assistant.cpp index f767757..16ddb05 100644 --- a/src/extensions/sapp_assistant.cpp +++ b/src/extensions/sapp_assistant.cpp @@ -1,5 +1,5 @@ /* - ���ļ���ƽ̨���Ĺ��ܺͺ���(Ip��Ƭ, ����ԭ, ��������, ���������?), + ���ļ���ƽ̨���Ĺ��ܺͺ���(Ip��Ƭ, ����ԭ, ��������, ���������?), ���ṩ������ҵ�����Ľӿ�, ��sapp_get_platform_opt��, ��Ϊһ��.so�ļ����ص�ƽ̨, ���ڸ��²���. */ @@ -12,8 +12,6 @@ -//extern time_t g_CurrentTime;//add by lqy 20070606 -//extern int g_packet_io_thread_num; extern char g_app_instance_name[64]; static pthread_mutex_t g_plug_Independent_thread_mutex; @@ -36,7 +34,7 @@ int sapp_identify_tunnel_inner_pkt(const raw_pkt_t *raw_pkt) #if IOMODE_MARSIO if (CAP_MODEL_MARSIOV4 == g_packet_io_cap_mode) { - /* û��mrtunnatʱ, �������l2_l3_tunnel_support, Ҫ�ж�overlay����, �Ƿ��Ǹ�������, �Ƿ��Ǿ���overlayԭʼ��·��İ�? */ + /* û��mrtunnatʱ, �������l2_l3_tunnel_support, Ҫ�ж�overlay����, �Ƿ��Ǹ�������, �Ƿ��Ǿ���overlayԭʼ��·��İ�? */ if (raw_pkt->is_overlay_pkt) { ret = 1; @@ -56,7 +54,7 @@ int sapp_identify_broad_multicast_pkt(const void *this_layer_data, const raw_pkt } if(memcmp(G_BROADCAST_ADDR, p_eth_hdr->ether_dhost, ETH_ALEN) == 0){ - /* G����ģʽ�£���ARPЭ��Ĺ㲥����ֱ�Ӷ���?! ��ֹ�ٻ�ע��������, ��ɹ㲥�籩����������? */ + /* G����ģʽ�£���ARPЭ��Ĺ㲥����ֱ�Ӷ���?! ��ֹ�ٻ�ע��������, ��ɹ㲥�籩����������? */ if(eth_type != ETH_P_ARP){ return 1; } @@ -112,7 +110,7 @@ static inline unsigned long long __get_platform_opt_traffic(int ctype, sapp_sys_ return tmp_long; } -/* 2017-09-04 lijia add, for ��������, �����ȡƽ�?�ڲ����� */ +/* 2017-09-04 lijia add, for ��������, �����ȡƽ�?�ڲ����� */ extern "C" int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, int *opt_val_len) { int ret = 0; @@ -497,7 +495,7 @@ extern "C" int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, break; } time_t *curtime = (time_t *)opt_val; - *curtime = g_CurrentTime; + *curtime = ABBR_CURRENT_TIME; } break; @@ -509,7 +507,7 @@ extern "C" int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, break; } long long *curtime_ms = (long long *)opt_val; - *curtime_ms = g_CurrentTime_ms; + *curtime_ms = ABBR_CURRENT_TIME_MS; } break; @@ -523,7 +521,7 @@ extern "C" int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_CURTIME_STRING error:opt_val_len:%d is invalid!\n", *opt_val_len); break; } - time_t cur_time = g_CurrentTime; + time_t cur_time = ABBR_CURRENT_TIME; struct tm date_loc; localtime_r(&cur_time, &date_loc); @@ -560,7 +558,7 @@ extern "C" int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, } break; - /* �ⲿ���Ƶ������rand�Ⱥ����Ƚ�����CPU, ʹ��CPU��ǰ��ʱ��������, �͵�ǰƽ̨�����İ���ƴ��һ�������? */ + /* �ⲿ���Ƶ������rand�Ⱥ����Ƚ�����CPU, ʹ��CPU��ǰ��ʱ��������, �͵�ǰƽ̨�����İ���ƴ��һ�������? */ case SPO_RAND_NUMBER: { if(*opt_val_len != sizeof(long long)){ @@ -596,7 +594,7 @@ extern "C" int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, pthread_mutex_lock(&g_plug_Independent_thread_mutex); - /* Ϊ����һ���̶߳�ε��ô˽ӿ�?, �Ȳ���֮ǰ�Ƿ��? */ + /* Ϊ����һ���̶߳�ε��ô˽ӿ�?, �Ȳ���֮ǰ�Ƿ��? */ for(i = 0; i < sapp_global_val->config.cpu.send_only_threads_max_num; i++){ if(g_plug_Independent_thread_pid[i] == this_pid){ id_index = i; @@ -611,7 +609,7 @@ extern "C" int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, break; } } - if(i >= sapp_global_val->config.cpu.send_only_threads_max_num ){ /* ���������߳��������? */ + if(i >= sapp_global_val->config.cpu.send_only_threads_max_num ){ /* ���������߳��������? */ sapp_runtime_log(RLOG_LV_FATAL, "Independent_thread num more than CPU->send_only_threads_max:%d!\n", sapp_global_val->config.cpu.send_only_threads_max_num); *opt_int = -1; diff --git a/src/packet_io/cycle_pkt_dump_through_write_offset.c b/src/packet_io/cycle_pkt_dump_through_write_offset.c index 8b1aa7b..2986f7e 100644 --- a/src/packet_io/cycle_pkt_dump_through_write_offset.c +++ b/src/packet_io/cycle_pkt_dump_through_write_offset.c @@ -5,19 +5,19 @@ /* 2015-04-15 , LiJia. - ����cycle_pkt_dump����, - ����ʵʱѭ���洢���ݰ���Ŀ���ǽ����������������ҵ���ֻ����һ��core, ��BUG����������. - sapp����coredump�� 'pkt_dump_file_root_dir'Ŀ¼��洢���һ��ʱ���յ��İ�, - ���ö���ģʽ���֣����п��ܷ���BUG������Դ�� - ������������֣���pkt_dump_file_max_size�ʵ�����һЩ. + ����cycle_pkt_dump����, + ����ʵʱѭ���洢���ݰ���Ŀ���ǽ����������������ҵ���ֻ����һ��core, ��BUG����������. + sapp����coredump�� 'pkt_dump_file_root_dir'Ŀ¼��洢���һ��ʱ���յ��İ�, + ���ö���ģʽ���֣����п��ܷ���BUG������Դ�� + ������������֣���pkt_dump_file_max_size�ʵ�����һЩ. - main.conf������1���µ�section��5������������: + main.conf������1���µ�section��5������������: [pkt_dump] - pkt_dump_switch=0 //�ܿ��� - pkt_dump_total_size=1000 //root_dir�ܼ�.pcap�ļ��Ĵ�С, ��λ:MB, ��ֹ������ƶ�������д��Ӳ�� - pkt_dump_file_max_size=200 //pcap�ļ�ÿ���߳̿������ֵ, ��λ:MB. - pkt_dump_file_root_dir=/dev/shm //pcap�洢·��, �Ƽ�/dev/shm, ��Ӳ���ٶȿ�ܶ� - pkt_dump_thread_seq=0,2,4,6,8 //ÿ���̵߳Ŀ��أ���Ϊ�����������ܾ���ȫ���洢���Ǿ�����������ֻ���ò����̵߳�dump���� , all=ȫ���� + pkt_dump_switch=0 //�ܿ��� + pkt_dump_total_size=1000 //root_dir�ܼ�.pcap�ļ��Ĵ�С, ��λ:MB, ��ֹ������ƶ�������д��Ӳ�� + pkt_dump_file_max_size=200 //pcap�ļ�ÿ���߳̿������ֵ, ��λ:MB. + pkt_dump_file_root_dir=/dev/shm //pcap�洢·��, �Ƽ�/dev/shm, ��Ӳ���ٶȿ�ܶ� + pkt_dump_thread_seq=0,2,4,6,8 //ÿ���̵߳Ŀ��أ���Ϊ�����������ܾ���ȫ���洢���Ǿ�����������ֻ���ò����̵߳�dump���� , all=ȫ���� */ @@ -37,9 +37,9 @@ typedef struct{ unsigned long long total_pkt_bytes; unsigned long long discard_pkt_num; unsigned long long discard_pkt_bytes; - char __pad__[32]; /* 64�ֽ�cache���� */ + char __pad__[32]; /* 64�ֽ�cache���� */ }pkt_dump_status_t; -static pkt_dump_status_t PKT_DISCARD_STAT[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; /* ���������߳�, tcpdump_mesaģʽΪINJECTʱҲҪ���� */ +static pkt_dump_status_t PKT_DISCARD_STAT[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; /* ���������߳�, tcpdump_mesaģʽΪINJECTʱҲҪ���� */ #endif @@ -48,13 +48,12 @@ const int tcpdump_mesa_version_VERSION_20190820 = 20190820; extern int g_use_MESA_sleep_sw; extern void MESA_sleep(void); extern int MESA_mkdir_p(const char *pathname, mode_t mode); -//extern time_t g_CurrentTime; //extern int g_packet_io_thread_num; //extern int g_iThreadNum; /* for dual_stack, start */ -//static char G_PKT_DUMP_ROOT_DIR[PATH_MAX]; /* ����ָ��Ϊ/dev/shm, �ٶȿ� */ -static long G_PKT_DUMP_FILE_SIZE = 104857600; /* Ĭ��100MB, ���߳� */ -int G_PKT_DUMP_SW = 0; /* Ĭ�Ϲر� */ -int G_PKT_DUMP_MODE = PKT_DUMP_LOCAL_FILE; /* Ĭ����д�������ļ� */ +//static char G_PKT_DUMP_ROOT_DIR[PATH_MAX]; /* ����ָ��Ϊ/dev/shm, �ٶȿ� */ +static long G_PKT_DUMP_FILE_SIZE = 104857600; /* Ĭ��100MB, ���߳� */ +int G_PKT_DUMP_SW = 0; /* Ĭ�Ϲر� */ +int G_PKT_DUMP_MODE = PKT_DUMP_LOCAL_FILE; /* Ĭ����д�������ļ� */ static int G_PKT_DUMP_PER_THREAD_SW[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; static int pkt_dump_thread_num = 1; @@ -65,16 +64,16 @@ static long G_PCAP_SIZE[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; static char G_PKT_DUMP_FILTER_STR[PATH_MAX]; static struct bpf_program G_PKT_DUMP_BPF_FILTER[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; -static unsigned short pkt_dump_data_offset = 0; /* ����ʱ��ָ��ƫ����, ����vxlan�����²����ڲ����ݰ� */ -static unsigned short pkt_dump_tcp_bind_port = 12345; /* Ĭ��TCP�����˿�, ���ڽ����ⲿtcpdump���� */ -static int pkt_dump_tcp_cmd_sd = -1;/* TCP fd, ���ڽ����ⲿtcpdump���� */ -static volatile int pkt_dump_udp_socket_peer_alive = 0; /* �ⲿtcpdump�Ƿ��� */ -static int pkt_dump_udp_pkt_sd[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; /* UDP�������ݰ�fd */ +static unsigned short pkt_dump_data_offset = 0; /* ����ʱ��ָ��ƫ����, ����vxlan�����²����ڲ����ݰ� */ +static unsigned short pkt_dump_tcp_bind_port = 12345; /* Ĭ��TCP�����˿�, ���ڽ����ⲿtcpdump���� */ +static int pkt_dump_tcp_cmd_sd = -1;/* TCP fd, ���ڽ����ⲿtcpdump���� */ +static volatile int pkt_dump_udp_socket_peer_alive = 0; /* �ⲿtcpdump�Ƿ��� */ +static int pkt_dump_udp_pkt_sd[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; /* UDP�������ݰ�fd */ static struct sockaddr_in udp_recv_addr; -static int tcpdump_perceptive_flag = 0; /* �������ģʽ, ���Է��ֶ������� */ -static int greedy_seek_flag = 0; /* ƫ�Ƶ����ڲ�IP, ��������ģʽ�²���BUG */ +static int tcpdump_perceptive_flag = 0; /* �������ģʽ, ���Է��ֶ������� */ +static int greedy_seek_flag = 0; /* ƫ�Ƶ����ڲ�IP, ��������ģʽ�²���BUG */ static int tcpdump_mesa_pkt_classify = PKT_CLASSIFY_IN; -static int pkt_classify_watermark_flag = 0; /* ���沶����Դֵ��dmac, ���ڷֱ����ݰ���Դ */ +static int pkt_classify_watermark_flag = 0; /* ���沶����Դֵ��dmac, ���ڷֱ����ݰ���Դ */ static pthread_t g_socket_mode_cmd_listen_thread_id; static unsigned char phony_mac_hdr[14] = @@ -85,7 +84,7 @@ static unsigned char phony_mac_hdr[14] = }; -/* ���ߴ�����������, δָ����������, ��ͨ��sendto���ʹ������ݰ�, ����sapp����, �������ò������� */ +/* ���ߴ�����������, δָ����������, ��ͨ��sendto���ʹ������ݰ�, ����sapp����, �������ò������� */ typedef struct{ int sample_pkt_num; unsigned int perceptive_mode_pkt_seq; @@ -94,8 +93,8 @@ typedef struct{ static pkt_dump_mthread_t pkt_dump_mthread_info[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; -static int raw_cfg_pkt_dump_ratio = 30; /* ȫ��Ĭ�ϲ���������, ��ʾÿ��N��������һ��, ��ֹ��������tcpdump_mesa����ƽ̨���� */ -static int cur_conn_pkt_dump_ratio = 30; /* ��ǰ���ӵIJ���������, ���������host, port��bpf����, ��Ϊȫ����ģʽ, debug�Ŵ��� */ +static int raw_cfg_pkt_dump_ratio = 30; /* ȫ��Ĭ�ϲ���������, ��ʾÿ��N��������һ��, ��ֹ��������tcpdump_mesa����ƽ̨���� */ +static int cur_conn_pkt_dump_ratio = 30; /* ��ǰ���ӵIJ���������, ���������host, port��bpf����, ��Ϊȫ����ģʽ, debug�Ŵ��� */ typedef struct { @@ -120,8 +119,8 @@ typedef struct { }pkt_dump_pkt_hdr_t; typedef struct{ - enum addr_type_t low_layer_type; /* ԭʼ����ײ�Э�������, ������MAC(pcap����), Ҳ������IPv4(pag����) */ - int raw_pkt_len; /* ԭʼ���ܳ��� */ + enum addr_type_t low_layer_type; /* ԭʼ����ײ�Э�������, ������MAC(pcap����), Ҳ������IPv4(pag����) */ + int raw_pkt_len; /* ԭʼ���ܳ��� */ //char pkt_data[]; }pkt_dump_pipe_t; @@ -194,7 +193,7 @@ retry: default: sapp_runtime_log(20, "pkt dump, write error:%s\n", strerror(errno)); - /* д�������ռ䲻��, ��������, �����Ӱ���������������� */ + /* д�������ռ䲻��, ��������, �����Ӱ���������������� */ break; } }else{ @@ -206,98 +205,6 @@ retry: return expect_count - left_count; } -#if 0 -static void *cycle_pkt_dump_check_father(void *arg) -{ - while(1){ - if(1 == getppid()){ /* �����̱�Ϊinit, ˵���������Ѿ��˳� */ - exit(1); - }else{ - sapp_usleep(100000); - } - } - - return NULL; -} - - -static void *cycle_pkt_dump_thread(void *arg) -{ - int thread_seq = *((int *)arg); - FILE *fp; - int file_name_post_prefix = 0, ret, pfile_hdr_flag = 0; - long tot_pcap_file_len = 0; - char pkt_buf[65536]; - char dump_file_name[PATH_MAX]; - pkt_dump_pkt_hdr_t *ppkt_hdr; - int pkt_len; - int skip_pkt_hdr_len; /* Ԥ����ͷ���ռ䳤��, ���ݲ���ģʽ��ͬ, ���ܻ����Eth�� */ - - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getpid(), thread_seq, file_name_post_prefix); - fp = fopen(dump_file_name, "w+"); - if(NULL == fp){ - printf("fopen %s error!\n", dump_file_name); - goto done; - } - ppkt_hdr = (pkt_dump_pkt_hdr_t *)pkt_buf; - ppkt_hdr->ts.tv_usec = 0; -#ifdef CAPTURE_MODE_PAG - memcpy(pkt_buf+sizeof(pkt_dump_pkt_hdr_t), phony_mac_hdr, 14); - skip_pkt_hdr_len = sizeof(pkt_dump_pkt_hdr_t) + 14; -#else - skip_pkt_hdr_len = sizeof(pkt_dump_pkt_hdr_t); -#endif - while(1){ - /* ��pcap��ͷ���ռ�Ԥ��, ����ֻ��һ��fwrite, �ͽ�ͷ��������һ��д�� */ - pkt_len = read(G_UNIX_DOMAIN_SD[thread_seq], (char *)pkt_buf+skip_pkt_hdr_len, 2048); - if(0 == pkt_len){ - goto done; - }else if(pkt_len < 0){ - continue; - } - - /* pcap file header, first time */ - if(0 == pfile_hdr_flag){ - fwrite(&pfile_hdr, sizeof(pkt_dump_file_hdr_t), 1, fp); - tot_pcap_file_len += sizeof(pkt_dump_file_hdr_t); - pfile_hdr_flag = 1; - } - /* ���°�����, ʱ��� */ - ppkt_hdr->ts.tv_sec = (unsigned int )g_CurrentTime; -#ifdef CAPTURE_MODE_PAG - ppkt_hdr->caplen = pkt_len+14; - ppkt_hdr->len = pkt_len+14; -#else - ppkt_hdr->caplen = pkt_len; - ppkt_hdr->len = pkt_len; -#endif - - fwrite(pkt_buf, pkt_len+skip_pkt_hdr_len, 1, fp); - tot_pcap_file_len += pkt_len+skip_pkt_hdr_len; - - /* �����������, ѭ��д�ļ� */ - if(tot_pcap_file_len >= G_PKT_DUMP_FILE_SIZE){ - fclose(fp); - file_name_post_prefix = file_name_post_prefix ^ 1; - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getpid(), thread_seq, file_name_post_prefix); - fp = fopen(dump_file_name, "w+"); /* cycle write two files */ - if(NULL == fp){ - printf("fopen %s error!\n", dump_file_name); - goto done; - } - tot_pcap_file_len = 0; - pfile_hdr_flag = 0; - } - } - -done: - - return NULL; -} -#endif - static inline int cycle_pkt_dump_sample_by_ratio(int thread_seq) { if(pkt_dump_mthread_info[thread_seq].sample_pkt_num++ >= cur_conn_pkt_dump_ratio){ @@ -310,17 +217,17 @@ static inline int cycle_pkt_dump_sample_by_ratio(int thread_seq) extern char *timet_to_str(time_t timet, char *time_str, int time_str_len); static char udp_start_time_str[64]; -static long long tot_udp_send_succ_num = 0; /* sendto�ɹ����� */ -static long long tot_udp_send_err_num = 0; /* ���ʹ�������, �绺������ԭ�� */ -static long long tot_udp_send_willful_discard_num = 0; /* ������������ */ +static long long tot_udp_send_succ_num = 0; /* sendto�ɹ����� */ +static long long tot_udp_send_err_num = 0; /* ���ʹ�������, �绺������ԭ�� */ +static long long tot_udp_send_willful_discard_num = 0; /* ������������ */ /* - Ϊ��DEBUG����, ֧�ֹ������ڲ����Ԫ��, ��tcpdump -w �洢�İ������������������������ݰ�. + Ϊ��DEBUG����, ֧�ֹ������ڲ����Ԫ��, ��tcpdump -w �洢�İ������������������������ݰ�. return value: - >=0: ��������, �����tcpdump_mesa; - <0: ������bpf����, ���ϲ�������, ����. + >=0: ��������, �����tcpdump_mesa; + <0: ������bpf����, ���ϲ�������, ����. */ static int cycle_pkt_dump_seek_to_inner_ip(char *pkt_buf, int pktlen, int thread_seq) { @@ -342,16 +249,16 @@ static int cycle_pkt_dump_seek_to_inner_ip(char *pkt_buf, int pktlen, int thread ip4hdr_greedy = (struct mesa_ip4_hdr *)MESA_jump_layer_greedy(pkt_buf, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4); if(ip4hdr_greedy){ if((char *)ip4hdr_greedy == first_ip_layer){ - bpf_match_pkt_len = pktlen; /* ���ڲ�͵�һ��IPһ��, ˵���DZ�ethernet->IPv4��, ����memmove���� */ + bpf_match_pkt_len = pktlen; /* ���ڲ�͵�һ��IPһ��, ˵���DZ�ethernet->IPv4��, ����memmove���� */ }else{ if(pktlen <= ((char *)ip4hdr_greedy - pkt_buf)){ - return -1; /* ����ֲ���ԭ��, ��ת���ڲ��ͷ�����, ����!! */ + return -1; /* ����ֲ���ԭ��, ��ת���ڲ��ͷ�����, ����!! */ } memmove(pkt_buf + sizeof(struct mesa_ethernet_hdr), ip4hdr_greedy, pktlen - ((char *)ip4hdr_greedy - pkt_buf)); bpf_match_pkt_len = pktlen - ((char *)ip4hdr_greedy - pkt_buf) + sizeof(struct mesa_ethernet_hdr); - ehdr->ether_type = htons(ETHERTYPE_IP); /* ��һ����ܲ���IPV4, ����MPLS, VLAN��, ��Ҫ�ij�IP, �Ա�bpf����������ȷִ�� */ + ehdr->ether_type = htons(ETHERTYPE_IP); /* ��һ����ܲ���IPV4, ����MPLS, VLAN��, ��Ҫ�ij�IP, �Ա�bpf����������ȷִ�� */ } if(bpf_match_pkt_len <= 0){ @@ -359,8 +266,8 @@ static int cycle_pkt_dump_seek_to_inner_ip(char *pkt_buf, int pktlen, int thread return -1; } - /* �������ȷ�Ĺ�������, ���������, ��֤��������ȫ, ���ϵ�������ͼ; - ���û�й�������, ��ȫ����ģʽ, Ϊ�˾�����Ӱ��������߳�, ���ݲ�����ֻ��һ���ְ�. + /* �������ȷ�Ĺ�������, ���������, ��֤��������ȫ, ���ϵ�������ͼ; + ���û�й�������, ��ȫ����ģʽ, Ϊ�˾�����Ӱ��������߳�, ���ݲ�����ֻ��һ���ְ�. */ if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ bpf_match_ipv4 = bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, @@ -373,16 +280,16 @@ static int cycle_pkt_dump_seek_to_inner_ip(char *pkt_buf, int pktlen, int thread ip6hdr_greedy = (struct mesa_ip6_hdr *)MESA_jump_layer_greedy(pkt_buf, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6); if(ip6hdr_greedy){ if((char *)ip6hdr_greedy == first_ip_layer){ - bpf_match_pkt_len = pktlen; /* ���ڲ�͵�һ��IPһ��, ˵���DZ�ethernet->IPv6��, ����memmove���� */ + bpf_match_pkt_len = pktlen; /* ���ڲ�͵�һ��IPһ��, ˵���DZ�ethernet->IPv6��, ����memmove���� */ }else{ if(pktlen <= ((char *)ip4hdr_greedy - pkt_buf)){ - return -1; /* ����ֲ���ԭ��, ��ת���ڲ��ͷ�����, ����!! */ + return -1; /* ����ֲ���ԭ��, ��ת���ڲ��ͷ�����, ����!! */ } memmove(pkt_buf + sizeof(struct mesa_ethernet_hdr), ip6hdr_greedy, pktlen - ((char *)ip6hdr_greedy - pkt_buf)); bpf_match_pkt_len = pktlen - ((char *)ip4hdr_greedy - pkt_buf) + sizeof(struct mesa_ethernet_hdr); - ehdr->ether_type = htons(ETHERTYPE_IPv6); /* ��һ����ܲ���IPV6, ����MPLS, VLAN��,��Ҫ�ij�IP,�Ա�bpf����������ȷִ�� */ + ehdr->ether_type = htons(ETHERTYPE_IPv6); /* ��һ����ܲ���IPV6, ����MPLS, VLAN��,��Ҫ�ij�IP,�Ա�bpf����������ȷִ�� */ } if(bpf_match_pkt_len <= 0){ @@ -391,8 +298,8 @@ static int cycle_pkt_dump_seek_to_inner_ip(char *pkt_buf, int pktlen, int thread } - /* �������ȷ�Ĺ�������, ���������, ��֤��������ȫ, ���ϵ�������ͼ; - ���û�й�������, ��ȫ����ģʽ, Ϊ�˾�����Ӱ��������߳�, ���ݲ�����ֻ��һ���ְ�. + /* �������ȷ�Ĺ�������, ���������, ��֤��������ȫ, ���ϵ�������ͼ; + ���û�й�������, ��ȫ����ģʽ, Ϊ�˾�����Ӱ��������߳�, ���ݲ�����ֻ��һ���ְ�. */ if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ bpf_match_ipv6 = bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, @@ -404,7 +311,7 @@ static int cycle_pkt_dump_seek_to_inner_ip(char *pkt_buf, int pktlen, int thread } if(bpf_match_ipv4 || bpf_match_ipv6){ - return 1; /* ����ͷ�����м��������tcpdump_mesa */ + return 1; /* ����ͷ�����м��������tcpdump_mesa */ }else{ if(cur_conn_pkt_dump_ratio > 0){ if(0 == cycle_pkt_dump_sample_by_ratio(thread_seq)){ @@ -430,7 +337,7 @@ static void pkt_dump_with_watermark(int tid, const void *rawpkt, int pktlen, enu return; } - /* ��watermark��ǩҪ��ԭʼ��mac��ַ, copyһ�� */ + /* ��watermark��ǩҪ��ԭʼ��mac��ַ, copyһ�� */ memcpy(temp_pkt_buf, rawpkt, pktlen); ehdr = (struct mesa_ethernet_hdr *)temp_pkt_buf; @@ -470,8 +377,8 @@ static void pkt_dump_with_watermark(int tid, const void *rawpkt, int pktlen, enu /* bingo, match filter, sendto */ ret = sendto(pkt_dump_udp_pkt_sd[tid], - (void *)ehdr, /* ����ʱʹ���ڲ����ݰ�ͷ, ��Ҫ��������ԭʼ�� */ - pktlen, /* ����ʱʹ���ڲ����ݰ�ͷ, ��Ҫ��������ԭʼ�� */ + (void *)ehdr, /* ����ʱʹ���ڲ����ݰ�ͷ, ��Ҫ��������ԭʼ�� */ + pktlen, /* ����ʱʹ���ڲ����ݰ�ͷ, ��Ҫ��������ԭʼ�� */ MSG_DONTWAIT, (const struct sockaddr *)&udp_recv_addr, sizeof(udp_recv_addr)); @@ -489,7 +396,7 @@ static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_ra { const unsigned char *pktdata, *for_bpf_filter_data; int pktlen, for_bpf_filter_len, ret; - char modify_pkt_buf[2048]; /* ��Ҫ��ԭʼ��, ��copy����ʱ������ */ + char modify_pkt_buf[2048]; /* ��Ҫ��ԭʼ��, ��copy����ʱ������ */ struct perceptive_info *pperceptive_info; const sapp_config_tools_pktdump_t *pktdump_cfg = &sapp_global_val->config.tools.pkt_dump; @@ -499,7 +406,7 @@ static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_ra if(0 == G_PKT_DUMP_PER_THREAD_SW[thread_seq]){ return; } - /* ԭʼ������ƫ������, ������һ��Ethernet֡, ���� */ + /* ԭʼ������ƫ������, ������һ��Ethernet֡, ���� */ if(pkt_dump_data_offset + 14 > p_raw_pkt->raw_pkt_len){ return; } @@ -521,8 +428,8 @@ static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_ra if(0 == greedy_seek_flag){ - /* �������ȷ�Ĺ�������, ���������, ��֤��������ȫ, ���ϵ�������ͼ; - ���û�й�������, ��ȫ����ģʽ, Ϊ�˾�����Ӱ��������߳�, ���ݲ�����ֻ��һ���ְ�. + /* �������ȷ�Ĺ�������, ���������, ��֤��������ȫ, ���ϵ�������ͼ; + ���û�й�������, ��ȫ����ģʽ, Ϊ�˾�����Ӱ��������߳�, ���ݲ�����ֻ��һ���ְ�. */ if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ if(0 == bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, @@ -577,9 +484,9 @@ static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_ra } } - if(tcpdump_perceptive_flag > 0){ /* ������� */ + if(tcpdump_perceptive_flag > 0){ /* ������� */ memcpy(modify_pkt_buf, pktdata, pktlen>2048?2048:pktlen); - pperceptive_info = (struct perceptive_info *)&modify_pkt_buf[6]; /* ����ԴMAC��ַ */ + pperceptive_info = (struct perceptive_info *)&modify_pkt_buf[6]; /* ����ԴMAC��ַ */ pperceptive_info->thread_id = thread_seq; pperceptive_info->pkt_seq = htonl(pkt_dump_mthread_info[thread_seq].perceptive_mode_pkt_seq); pkt_dump_mthread_info[thread_seq].perceptive_mode_pkt_seq++; @@ -593,13 +500,13 @@ static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_ra /* bingo, match filter, sendto */ ret = sendto(pkt_dump_udp_pkt_sd[thread_seq], - pktdata,//(char *)p_raw_pkt->raw_pkt_data, /* ����ʱʹ���ڲ����ݰ�ͷ, ��Ҫ��������ԭʼ�� */ - pktlen,//p_raw_pkt->raw_pkt_len, /* ����ʱʹ���ڲ����ݰ�ͷ, ��Ҫ��������ԭʼ�� */ + pktdata,//(char *)p_raw_pkt->raw_pkt_data, /* ����ʱʹ���ڲ����ݰ�ͷ, ��Ҫ��������ԭʼ�� */ + pktlen,//p_raw_pkt->raw_pkt_len, /* ����ʱʹ���ڲ����ݰ�ͷ, ��Ҫ��������ԭʼ�� */ MSG_DONTWAIT, (const struct sockaddr *)&udp_recv_addr, sizeof(udp_recv_addr)); if((ret < 0) && (EINTR == errno)){ - /* ���ȱ�֤sapp��������, ���ж���ɵķ���ʧ��ֻ����һ��, ������������ */ + /* ���ȱ�֤sapp��������, ���ж���ɵķ���ʧ��ֻ����һ��, ������������ */ ret = sendto(pkt_dump_udp_pkt_sd[thread_seq], pktdata,///(char *)p_raw_pkt->raw_pkt_data, pktlen,///p_raw_pkt->raw_pkt_len, @@ -619,8 +526,8 @@ static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_ra static void __do_cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt, enum _pkt_classify class_val) { int ret; - /* ����Ϊpcap_hdr[2]����,��һ��СС��trick, ����[0]��ʾpcap��ͷ����Ϣ, - ����[1]��ʾ��PAGģʽ��, �洢��etherhdr, pkt_dump_pkt_hdr_tΪ16�ֽ�, ���ÿ��Է�һ��������ether hdr. + /* ����Ϊpcap_hdr[2]����,��һ��СС��trick, ����[0]��ʾpcap��ͷ����Ϣ, + ����[1]��ʾ��PAGģʽ��, �洢��etherhdr, pkt_dump_pkt_hdr_tΪ16�ֽ�, ���ÿ��Է�һ��������ether hdr. */ pkt_dump_pkt_hdr_t pcap_hdr[2]; int write_hdr_len; @@ -664,8 +571,8 @@ static void __do_cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt, enum fwrite(&pfile_hdr, sizeof(pkt_dump_file_hdr_t), 1, G_PKT_DUMP_FP[thread_seq]); } - /* ���°�����, ʱ��� */ - pcap_hdr[0].ts.tv_sec = (unsigned int )g_CurrentTime; + /* ���°�����, ʱ��� */ + pcap_hdr[0].ts.tv_sec = (unsigned int )ABBR_CURRENT_TIME; if(p_raw_pkt->low_layer_type != CAP_LEVEL_MAC){ pcap_hdr[0].caplen = p_raw_pkt->raw_pkt_len+14; @@ -684,12 +591,12 @@ static void __do_cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt, enum } ret = fwrite(p_raw_pkt->raw_pkt_data, p_raw_pkt->raw_pkt_len, 1, G_PKT_DUMP_FP[thread_seq]); if(unlikely(ret < 1)){ - /* ���ֻд��ͷ��, ��д���ݳ��ִ���, �ع� */ + /* ���ֻд��ͷ��, ��д���ݳ��ִ���, �ع� */ fseek(G_PKT_DUMP_FP[thread_seq], (int)0-(int)sizeof(pkt_dump_pkt_hdr_t), SEEK_CUR); return; } - /* �����������, ѭ��д�ļ� */ + /* �����������, ѭ��д�ļ� */ G_PCAP_SIZE[thread_seq] += write_hdr_len + p_raw_pkt->raw_pkt_len; if(unlikely(G_PCAP_SIZE[thread_seq] >= G_PKT_DUMP_FILE_SIZE)){ fclose(G_PKT_DUMP_FP[thread_seq]); @@ -720,10 +627,10 @@ void cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt) } /* - TODO: ���һ�����ж����ǩ, �����ظ����ݰ�REPEAT, ͬʱ�϶���FORWARD, - ����ddosʱ, BYPASS�İ���ʵҲ��FORWARD, - ʹ�ö����־λ��ʾ, ��������������һ��, watermark����ͬʱ������ǩ, - ���Խ�ԼһЩCPU��IO��Դ. + TODO: ���һ�����ж����ǩ, �����ظ����ݰ�REPEAT, ͬʱ�϶���FORWARD, + ����ddosʱ, BYPASS�İ���ʵҲ��FORWARD, + ʹ�ö����־λ��ʾ, ��������������һ��, watermark����ͬʱ������ǩ, + ���Խ�ԼһЩCPU��IO��Դ. */ void cycle_pkt_dump_by_classify(int thread_seq, const raw_pkt_t *p_raw_pkt, enum _pkt_classify class_val) { @@ -779,9 +686,9 @@ static void pkt_dump_sig_ignore(int sig) static void pkt_dump_sig_handle(int sig) { - signal(SIGSEGV, pkt_dump_sig_ignore); /* SIGSEGV����������, ��һ����ٵ��жϴ�������ƭ��ϵͳ */ - sync(); /* ����������δд�����̵�����ǿ��д�� */ - abort(); /* ��ֹ����, ����core�ļ� */ + signal(SIGSEGV, pkt_dump_sig_ignore); /* SIGSEGV����������, ��һ����ٵ��жϴ�������ƭ��ϵͳ */ + sync(); /* ����������δд�����̵�����ǿ��д�� */ + abort(); /* ��ֹ����, ����core�ļ� */ } static void pkt_dump_set_default_opt(void) @@ -792,7 +699,7 @@ static void pkt_dump_set_default_opt(void) udp_recv_addr.sin_addr.s_addr = htonl(0x7f000001); udp_recv_addr.sin_port = htons(12345); - /* ��ԭʼ���ø���һ��, ��Ϊudpģʽ��, ���ܻ�����-k�����ı��ֵ */ + /* ��ԭʼ���ø���һ��, ��Ϊudpģʽ��, ���ܻ�����-k�����ı��ֵ */ for(i = 0; i < MAX_THREAD_NUM; i++){ G_PKT_DUMP_PER_THREAD_SW[i] = pktdump_cfg->dump_thread_id_mask[i]; } @@ -806,7 +713,7 @@ static void pkt_dump_parse_opt_rcv_port(const struct pkt_dump_opt *cmd_opt, cons { unsigned short *rcv_port = (unsigned short *)opt_val; - udp_recv_addr.sin_port = *rcv_port; /* �˴�ֱ��ʹ�������� */ + udp_recv_addr.sin_port = *rcv_port; /* �˴�ֱ��ʹ�������� */ } static void pkt_dump_parse_opt_bpf_filter(const struct pkt_dump_opt *cmd_opt, const char *opt_val) @@ -815,7 +722,7 @@ static void pkt_dump_parse_opt_bpf_filter(const struct pkt_dump_opt *cmd_opt, co printf("bpf filter string is too long: %s\n", opt_val); return; } - memcpy(G_PKT_DUMP_FILTER_STR, opt_val, ntohs(cmd_opt->opt_len)); /* �Ѱ�����EOF */ + memcpy(G_PKT_DUMP_FILTER_STR, opt_val, ntohs(cmd_opt->opt_len)); /* �Ѱ�����EOF */ } static void pkt_dump_parse_opt_dump_offset(const struct pkt_dump_opt *cmd_opt, const char *opt_val) @@ -825,8 +732,8 @@ static void pkt_dump_parse_opt_dump_offset(const struct pkt_dump_opt *cmd_opt, c } /* - tcpdump_mesa�������char����Ϊ��λ������thread_id, ���糤����3, ������[1,3,5], - ��ʾ��1,3,5�߳̿�����������. + tcpdump_mesa�������char����Ϊ��λ������thread_id, ���糤����3, ������[1,3,5], + ��ʾ��1,3,5�߳̿�����������. */ static void pkt_dump_parse_opt_thread_index(const struct pkt_dump_opt *cmd_opt, const char *opt_val) { @@ -834,7 +741,7 @@ static void pkt_dump_parse_opt_thread_index(const struct pkt_dump_opt *cmd_opt, unsigned short opt_len = ntohs(cmd_opt->opt_len); unsigned char *thread_index = (unsigned char *)opt_val; - /* Ĭ��ֵ��1, �˴������������������, ֻ�����ض��߳� */ + /* Ĭ��ֵ��1, �˴������������������, ֻ�����ض��߳� */ memset(G_PKT_DUMP_PER_THREAD_SW, 0, sizeof(G_PKT_DUMP_PER_THREAD_SW)); for(i = 0; i < opt_len; i++){ @@ -888,7 +795,7 @@ static void cycle_pkt_dump_command_parse(int connfd) struct pkt_dump_handshake pkt_hdr; struct pkt_dump_opt cmd_opt; - /* tcpdump_mesa�ȷ��̶�ͷ��, �����ж�magic, ѡ������, �汾��֮��� */ + /* tcpdump_mesa�ȷ��̶�ͷ��, �����ж�magic, ѡ������, �汾��֮��� */ ret = MESA_sock_greedy_read(connfd, &pkt_hdr, sizeof(pkt_hdr), -1); if(0 == ret){ goto err_exit; @@ -902,7 +809,7 @@ static void cycle_pkt_dump_command_parse(int connfd) goto err_exit; } - /* �ݲ��ϸ����Զ�tcpdump_mesa�汾��, ֻ��ӡ������Ϣ */ + /* �ݲ��ϸ����Զ�tcpdump_mesa�汾��, ֻ��ӡ������Ϣ */ #if 0 if(ntohl(pkt_hdr.version) != (unsigned int)tcpdump_mesa_version_VERSION_20181114){ printf("Remote tcpdump_mesa version is incompatible!\n"); @@ -966,7 +873,7 @@ static void cycle_pkt_dump_command_parse(int connfd) break; default: - /* δ֪ѡ������������ */ + /* δ֪ѡ������������ */ break; } } @@ -974,12 +881,12 @@ static void cycle_pkt_dump_command_parse(int connfd) if(greedy_seek_flag == 1)pcap_link_type = DLT_RAW; for(i = 0; i < (unsigned int )g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num; i++){ - if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ /* ����û��filter, ��ȫ���� */ + if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ /* ����û��filter, ��ȫ���� */ if(pcap_compile_nopcap(65535, pcap_link_type, &G_PKT_DUMP_BPF_FILTER[i], G_PKT_DUMP_FILTER_STR, 100, 0) < 0){ printf("Compile pcap filter '%s' error\n", G_PKT_DUMP_FILTER_STR); goto err_exit; } - /* �������ȷ�Ĺ�������, ���������, ��֤�����������ϵ�������ͼ */ + /* �������ȷ�Ĺ�������, ���������, ��֤�����������ϵ�������ͼ */ cur_conn_pkt_dump_ratio = 0; } } @@ -992,7 +899,7 @@ static void cycle_pkt_dump_command_parse(int connfd) timet_to_str(time(NULL), udp_start_time_str, 64); - /* ��tcpdump_mesa���������Ժ��ٴ����κ�����, ������ȡ�������κν���, ֱ���Զ�tcpdump_mesa���ӽ��� */ + /* ��tcpdump_mesa���������Ժ��ٴ����κ�����, ������ȡ�������κν���, ֱ���Զ�tcpdump_mesa���ӽ��� */ while(MESA_sock_greedy_read(connfd, cmd_buf, sizeof(cmd_buf), -1) != 0); MESA_handle_runtime_log(g_sapp_log_handle, 20, "tcpdump_mesa", "capture start at %s, send pkt succ: %lld, error: %lld, willful discard:%lld!", @@ -1002,11 +909,11 @@ static void cycle_pkt_dump_command_parse(int connfd) tot_udp_send_willful_discard_num); err_exit: - /* �ָ����ֱ�����Ĭ��ֵ */ - pkt_dump_udp_socket_peer_alive = 0; /* NOTE: ���������жϺ�, ��һ���ȹرղ������� */ - tot_udp_send_succ_num = 0; /* sendto�ɹ����� */ - tot_udp_send_err_num = 0; /* ���ʹ�������, �绺������ԭ�� */ - tot_udp_send_willful_discard_num = 0; /* ������������ */ + /* �ָ����ֱ�����Ĭ��ֵ */ + pkt_dump_udp_socket_peer_alive = 0; /* NOTE: ���������жϺ�, ��һ���ȹرղ������� */ + tot_udp_send_succ_num = 0; /* sendto�ɹ����� */ + tot_udp_send_err_num = 0; /* ���ʹ�������, �绺������ԭ�� */ + tot_udp_send_willful_discard_num = 0; /* ������������ */ tcpdump_perceptive_flag = 0; greedy_seek_flag = 0; pkt_classify_watermark_flag = 0; @@ -1016,9 +923,9 @@ err_exit: pkt_dump_data_offset = 0; cur_conn_pkt_dump_ratio = raw_cfg_pkt_dump_ratio; - /* �ɵ������߳�ָ������, ÿ�λָ�Ĭ��ֵ */ + /* �ɵ������߳�ָ������, ÿ�λָ�Ĭ��ֵ */ memset(G_PKT_DUMP_PER_THREAD_SW, 0, sizeof(G_PKT_DUMP_PER_THREAD_SW)); - sapp_usleep(1000 * 500); /* ��ʱ�ͷ�, �������߳�����ʹ��BPF������ */ + sapp_usleep(1000 * 500); /* ��ʱ�ͷ�, �������߳�����ʹ��BPF������ */ for(i = 0; i < (unsigned int )g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num; i++){ pcap_freecode(&G_PKT_DUMP_BPF_FILTER[i]); pkt_dump_mthread_info[i].sample_pkt_num = 0; @@ -1033,7 +940,7 @@ static void * cycle_pkt_dump_udp_socket_daemon_thread(void *arg) socklen_t cliaddr_len; struct sockaddr_in cliaddr; int connfd; -#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_dump"); #endif @@ -1069,7 +976,7 @@ static int cycle_pkt_dump_socket_init(void) opt = 1; setsockopt(pkt_dump_tcp_cmd_sd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)); - /* ��Ϊ������ģʽ, ����sapp����destroy dev, �����˳����� */ + /* ��Ϊ������ģʽ, ����sapp����destroy dev, �����˳����� */ int flags = fcntl(pkt_dump_tcp_cmd_sd, F_GETFL, 0); fcntl(pkt_dump_tcp_cmd_sd , F_SETFL , flags|O_NONBLOCK); @@ -1082,9 +989,9 @@ static int cycle_pkt_dump_socket_init(void) printf("pkt dump bind cmd port %u error, %s!\n", pkt_dump_tcp_bind_port, strerror(errno)); return -1; } - listen(pkt_dump_tcp_cmd_sd, 1); /* ��֧�ֲ���, ��ʱֻ֧��һ���ͻ��˲��� */ + listen(pkt_dump_tcp_cmd_sd, 1); /* ��֧�ֲ���, ��ʱֻ֧��һ���ͻ��˲��� */ - /* ���ܻᲶ��inject����, ����ҪԤ�ȷ���send only max��fd */ + /* ���ܻᲶ��inject����, ����ҪԤ�ȷ���send only max��fd */ for(i = 0; i < g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num; i++){ pkt_dump_udp_pkt_sd[i] = socket(AF_INET, SOCK_DGRAM, 0); sapp_runtime_log(RLOG_LV_DEBUG, "cycle_pkt_dump_socket_init() create udp send packet socket:%d\n", pkt_dump_udp_pkt_sd[i]); @@ -1110,7 +1017,7 @@ int cycle_pkt_dump_init(int argc, char *argv[]) cur_conn_pkt_dump_ratio = pktdump_cfg->pkt_dump_ratio; G_PKT_DUMP_MODE = pktdump_cfg->mode_bin; - /* ��ԭʼ���ø���һ��, ��Ϊudpģʽ��, ���ܻ�����-k�����ı��ֵ */ + /* ��ԭʼ���ø���һ��, ��Ϊudpģʽ��, ���ܻ�����-k�����ı��ֵ */ for(i = 0; i < MAX_THREAD_NUM; i++){ G_PKT_DUMP_PER_THREAD_SW[i] = pktdump_cfg->dump_thread_id_mask[i]; } @@ -1136,7 +1043,7 @@ int cycle_pkt_dump_init(int argc, char *argv[]) G_PKT_DUMP_FILE_SIZE = (long)pktdump_cfg->file_size_max_per_thread * 1024L * 1024L ; signal(SIGPIPE, SIG_IGN); - /* ����SIGSEGV�ź�, ��֤�����쳣��ֹʱ, ���һ������BUG��pcap��������д��Ӳ�� */ + /* ����SIGSEGV�ź�, ��֤�����쳣��ֹʱ, ���һ������BUG��pcap��������д��Ӳ�� */ if((SIG_ERR == signal(SIGSEGV, pkt_dump_sig_handle))){ printf("Catch SIGSEGV error!\n"); } diff --git a/src/packet_io/packet_io_log.c b/src/packet_io/packet_io_log.c index b1c544f..7254a03 100644 --- a/src/packet_io/packet_io_log.c +++ b/src/packet_io/packet_io_log.c @@ -19,7 +19,7 @@ extern void pcap_detect_error(FILE *pcap_err_fp); } while(0) /* - �ж��ļ����Ƿ����. + �ж��ļ����Ƿ����. return value: 0: not exist 1: exist @@ -96,7 +96,7 @@ static int __MESA_mkdir_r(const char *dir, mode_t mode, int n) } -/* �ɵݹ齨������ļ��У�����ͬshell����: mkdir -p a/b/c/d */ +/* �ɵݹ齨������ļ��У�����ͬshell����: mkdir -p a/b/c/d */ int MESA_mkdir_p(const char *pathname, mode_t mode) { char *p; @@ -134,11 +134,11 @@ int MESA_mkdir_p(const char *pathname, mode_t mode) return -1; } - /* ��ǰĿ¼ */ + /* ��ǰĿ¼ */ if((strncasecmp(pathname, "./", 2) == 0) && (strlen(pathname) == 2)){ return 0; } - /* ��һ��Ŀ¼ */ + /* ��һ��Ŀ¼ */ if((strncasecmp(pathname, "../", 3) == 0) && (strlen(pathname) == 3)){ return 0; } @@ -192,7 +192,7 @@ char *timet_to_str(time_t timet, char *time_str, int time_str_len) -/* ÿ���Ե������ڽ����ļ��У��洢��־�ļ� */ +/* ÿ���Ե������ڽ����ļ��У��洢��־�ļ� */ static int packet_io_log_path_update(char *log_path, int path_len) { #define PACKET_IO_LOG_PREFIX "log/packet_io" @@ -204,7 +204,7 @@ static int packet_io_log_path_update(char *log_path, int path_len) return -1; } - now = localtime((time_t *)&g_CurrentTime); + now = localtime((time_t *)&ABBR_CURRENT_TIME); strftime(date_now, 16, "%Y-%m-%d", now); snprintf(log_path, path_len, "%s/%s", PACKET_IO_LOG_PREFIX, date_now); @@ -214,11 +214,11 @@ static int packet_io_log_path_update(char *log_path, int path_len) /* - ����־�ļ��������ļ����; - �˺������fopen()�����ǣ������ļ������Զ��ж����ڣ����õ������ڽ����ļ��У� - Ȼ���ڴ��ļ����ڴ洢��־�ļ��� ���������鿴. + ����־�ļ��������ļ����; + �˺������fopen()�����ǣ������ļ������Զ��ж����ڣ����õ������ڽ����ļ��У� + Ȼ���ڴ��ļ����ڴ洢��־�ļ��� ���������鿴. - warning: ���ô˺�������Ҫfclose()�ļ����! + warning: ���ô˺�������Ҫfclose()�ļ����! */ FILE *packet_io_open_log_file(const char *log_file_name, const char *mode) { @@ -245,8 +245,8 @@ FILE *packet_io_open_log_file(const char *log_file_name, const char *mode) } -/* 2012-09-13 LiJia add, ���ڼ��ͼ�¼�ײ㲶�����������״̬��Ϣ�̣߳� - �綪���������̶߳�������־���������豸�ı���������־�ȵ�. +/* 2012-09-13 LiJia add, ���ڼ��ͼ�¼�ײ㲶�����������״̬��Ϣ�̣߳� + �綪���������̶߳�������־���������豸�ı���������־�ȵ�. */ void *packet_io_stats_thread(void *arg) { @@ -255,7 +255,7 @@ void *packet_io_stats_thread(void *arg) { // to do ! - //��¼ÿ�ֲ�����Ķ�������������Ϣ + //��¼ÿ�ֲ�����Ķ�������������Ϣ //gdev_keepalive_log(); diff --git a/src/plugin/src/plugin.c b/src/plugin/src/plugin.c index 21bfd30..b1a3c5d 100644 --- a/src/plugin/src/plugin.c +++ b/src/plugin/src/plugin.c @@ -1232,9 +1232,9 @@ void plug_record_end_time(int plug_id, int thread_seq) if(total_usetime > plugctrl_runtime_info.max_runtime*1000) { plugctrl_runtime_info.interval_num[thread_seq]++; - if(g_CurrentTime-plugctrl_runtime_info.last_time[thread_seq]>60) + if(ABBR_CURRENT_TIME-plugctrl_runtime_info.last_time[thread_seq]>60) { - plugctrl_runtime_info.last_time[thread_seq]=g_CurrentTime; + plugctrl_runtime_info.last_time[thread_seq]=ABBR_CURRENT_TIME; plugctrl_runtime_info.interval_num[thread_seq]=0; } diff --git a/src/sapp_dev/sapp_init.c b/src/sapp_dev/sapp_init.c index ddac21e..1ae18f9 100644 --- a/src/sapp_dev/sapp_init.c +++ b/src/sapp_dev/sapp_init.c @@ -11,8 +11,6 @@ extern "C" { //static int threadnum = 1; static volatile long stream_num = 0; -//int g_iThreadNum = 1; -//time_t g_CurrentTime;//add by lqy 20070606 extern int sapp_args_v; int ipv4_frag_init(int thread_count, unsigned int hash_size); int ipv6_frag_init(int thread_count, unsigned hash_size); diff --git a/src/timer/sapp_timer.c b/src/timer/sapp_timer.c index b46f973..a0cfc68 100644 --- a/src/timer/sapp_timer.c +++ b/src/timer/sapp_timer.c @@ -16,6 +16,8 @@ extern "C" { volatile time_t g_current_time; volatile long long g_current_time_ms; +volatile time_t g_monotonic_time; +volatile long long g_monotonic_time_ms; sapp_timer_handle sapp_get_platform_standalone_timer(void); static void *sapp_standalone_timer_check_timeout(void *arg); @@ -40,9 +42,9 @@ static void __st_libev_callback(evutil_socket_t sd, short event, void *sapp_args sapp_timer_handle_inner_t *inner_h = inner_ev->timer_handle; if(STO_EFFECTIVE_SCOPE_STANDALONE_THREAD == inner_h->effective_mode){ - inner_ev->sapp_plug_cb_fun(inner_ev->timer_handle, inner_ev, -1, inner_ev->user_arg); /* ���ﴫ���ⲿ������������user_args */ + inner_ev->sapp_plug_cb_fun(inner_ev->timer_handle, inner_ev, -1, inner_ev->user_arg); /* ���ﴫ���ⲿ������������user_args */ }else{ - inner_ev->sapp_plug_cb_fun(inner_ev->timer_handle, inner_ev, inner_ev->timer_handle->effective_thread_index, inner_ev->user_arg); /* ���ﴫ���ⲿ������������user_args */ + inner_ev->sapp_plug_cb_fun(inner_ev->timer_handle, inner_ev, inner_ev->timer_handle->effective_thread_index, inner_ev->user_arg); /* ���ﴫ���ⲿ������������user_args */ } } #endif @@ -50,8 +52,8 @@ static void __st_libev_callback(evutil_socket_t sd, short event, void *sapp_args /* NOTE: STO_EFFECTIVE_SCOPE_PKT_PROCESS_THREADS: - running: �����ı�����inner_ev->effective_thread_pid�߳�. - not_run: ��ʼ����, ��effective_thread_index����С��thread_num; + running: �����ı�����inner_ev->effective_thread_pid�߳�. + not_run: ��ʼ����, ��effective_thread_index����С��thread_num; STO_EFFECTIVE_SCOPE_STANDALONE_THREAD: @@ -82,7 +84,7 @@ static int __st_timer_add_online(sapp_timer_handle_inner_t *inner_h, sapp_timer_ #ifdef LIBEVENT_ENABLED int ret = event_assign(inner_ev->libev_event, inner_h->libev_base, -1, EV_PERSIST, - __st_libev_callback, (void*)inner_ev); /* ��inner_ev��Ϊuser_args����libevent */ + __st_libev_callback, (void*)inner_ev); /* ��inner_ev��Ϊuser_args����libevent */ if(ret < 0){ return ST_RET_ERROR; } @@ -99,7 +101,7 @@ static int __st_timer_add_offline(sapp_timer_handle_inner_t *inner_h, sapp_timer { #ifdef LIBEVENT_ENABLED int ret = event_assign(inner_ev->libev_event, inner_h->libev_base, -1, EV_PERSIST, - __st_libev_callback, (void*)inner_ev); /* ��inner_ev��Ϊuser_args����libevent */ + __st_libev_callback, (void*)inner_ev); /* ��inner_ev��Ϊuser_args����libevent */ if(ret < 0){ return ST_RET_ERROR; } @@ -361,7 +363,7 @@ int sapp_timer_start(sapp_timer_handle h) pthread_t stand_alone_pid; if(__st_is_platform_timer(h)){ - return ST_RET_CANT_OP_PLATFORM_TIMER; /* �������ⲿ�����߲���ȫ�־�� */ + return ST_RET_CANT_OP_PLATFORM_TIMER; /* �������ⲿ�����߲���ȫ�־�� */ } sapp_timer_handle_inner_t *inner_h = (sapp_timer_handle_inner_t *)h; @@ -396,18 +398,14 @@ sapp_timer_handle sapp_get_platform_standalone_timer(void) } -static inline long long sapp_get_current_time_in_ms(void) +static inline void sapp_get_current_time_in_ms(int clock_id, time_t *time_s, long long *time_ms) { - long long tms; + if(time_s==NULL||time_ms==NULL)return; - //struct timeval t; - //gettimeofday(&t, NULL); - //tms = t.tv_sec * 1000 + t.tv_usec/1000; struct timespec t; - clock_gettime(CLOCK_REALTIME, &t); - tms = (t.tv_sec)*1000 + (t.tv_nsec)/(1000*1000); - - return tms; + clock_gettime(clock_id, &t); + *time_s=t.tv_sec; + *time_ms = (t.tv_sec)*1000 + (t.tv_nsec)/(1000*1000); } @@ -439,14 +437,14 @@ static void sapp_watch_dog(void) return; } - /* ��Ҫ��sapp.servie ���������: WatchdogSec=10s */ + /* ��Ҫ��sapp.servie ���������: WatchdogSec=10s */ sd_notify_enable=sd_watchdog_enabled(0, NULL); for (thread_index = 0; thread_index < sapp_global_val->config.cpu.worker_threads; thread_index++) { /* - �˴�����polling, ���������� SAPP_STAT_FETCH_PKT, ��Ϊû��Proxyʱ, polling���ܿ����ǹرյ�. - ��ǰʱ�̸�һ��֮ǰ����һ��, ˵���߳������� + �˴�����polling, ���������� SAPP_STAT_FETCH_PKT, ��Ϊû��Proxyʱ, polling���ܿ����ǹرյ�. + ��ǰʱ�̸�һ��֮ǰ����һ��, ˵���߳������� */ if (sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_FETCH_PKT] == 0) { @@ -471,7 +469,7 @@ static void sapp_watch_dog(void) break; } - /* ÿ������, ���һֱ�ۼ�, SAPP_STAT_FETCH_PKT�����̫����, ���ʹ�ü�¼��ʷ����, Ȼ���뵱ǰ���Աȵķ�ʽ, ���ܻ����, �����жϴ��� */ + /* ÿ������, ���һֱ�ۼ�, SAPP_STAT_FETCH_PKT�����̫����, ���ʹ�ü�¼��ʷ����, Ȼ���뵱ǰ���Աȵķ�ʽ, ���ܻ����, �����жϴ��� */ sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_FETCH_PKT] = 0; } @@ -508,8 +506,8 @@ void *sapp_time_loop_thread(void *arg) while(SAPP_STATE_PROCESSING == sapp_global_val->individual_volatile->current_state) { - ABBR_CURRENT_TIME = time(NULL); - ABBR_CURRENT_TIME_MS = sapp_get_current_time_in_ms(); + sapp_get_current_time_in_ms(CLOCK_REALTIME, &g_current_time, &g_current_time_ms); + sapp_get_current_time_in_ms(CLOCK_MONOTONIC, &g_monotonic_time, &g_monotonic_time_ms); sapp_usleep(1); } if(sapp_global_val->individual_volatile->current_state >= SAPP_STATE_READY_TO_EXIT) @@ -524,7 +522,7 @@ void *sapp_time_event_thread(void *arg) { time_t last_log_time; -#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_time_event"); #endif @@ -533,8 +531,8 @@ void *sapp_time_event_thread(void *arg) last_log_time = time(NULL); sapp_runtime_log(RLOG_LV_INFO, "sapp_time_event_thread, init!"); - /* Ϊ�˱�����docker, �����, �ڴ治��������, �˴������� current_state != SAPP_STATE_PROCESSING �ж����� - �������ֹ�dumpfileģʽ����ȡһ��pcap��, ˲����˳���, ���´˴���ѭ��������!! + /* Ϊ�˱�����docker, �����, �ڴ治��������, �˴������� current_state != SAPP_STATE_PROCESSING �ж����� + �������ֹ�dumpfileģʽ����ȡһ��pcap��, ˲����˳���, ���´˴���ѭ��������!! */ while(sapp_global_val->individual_volatile->current_state < SAPP_STATE_PROCESSING){ sapp_usleep(100); @@ -546,10 +544,10 @@ void *sapp_time_event_thread(void *arg) { /* NOTE: - Ϊʲô���������ַ�ʽ, ������do_something(); sleep(1); + Ϊʲô���������ַ�ʽ, ������do_something(); sleep(1); - ��Ϊdo_something()������дӲ��, �������ܾ����ļ�ʮms, �ټ���sleep(1)Ҳ�����Ǿ�ȷ������1��, ��������1��, - ������ͳ����ʱ���ʵ�ʱ�1���һЩ, ��ʱ�����к�, ���ͻ��ۻ�Խ��Խ��. + ��Ϊdo_something()������дӲ��, �������ܾ����ļ�ʮms, �ټ���sleep(1)Ҳ�����Ǿ�ȷ������1��, ��������1��, + ������ͳ����ʱ���ʵ�ʱ�1���һЩ, ��ʱ�����к�, ���ͻ��ۻ�Խ��Խ��. */ if(ABBR_CURRENT_TIME > last_log_time){ last_log_time = ABBR_CURRENT_TIME; @@ -592,7 +590,7 @@ int sapp_timer_destroy(sapp_timer_handle h) sapp_usleep(100); pthread_join(inner_h->effective_thread_pid, NULL); - //free �ڴ��� global_sapp_timer_destroy() ʵ�� + //free �ڴ��� global_sapp_timer_destroy() ʵ�� //free(h); #endif return ST_RET_SUCC; diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c index c2d5d2d..4f9f065 100644 --- a/test/test_app_sapp.c +++ b/test/test_app_sapp.c @@ -3212,8 +3212,6 @@ enum anti_flood_stat_type{ }; static unsigned long long anti_flood_stat[MAX_THREAD_NUM][8]; static time_t last_log_time; -//extern int g_packet_io_thread_num; -//extern time_t g_CurrentTime; static void anti_flood_stat_log(void) { FILE *fp; |
