diff options
| author | lijia <[email protected]> | 2021-04-20 19:03:05 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2021-04-20 19:03:05 +0800 |
| commit | 91bc8e3880ecf5c7f5a18a1392c7109c9babe0f8 (patch) | |
| tree | bfda41a6581069adc1010d03d52a65b4422f1132 | |
| parent | 6470fbc0e2b02b157cacf1fb0622ba81750ac959 (diff) | |
TSG-5514, TSG-6610, sapp支持systemd watch dog, 支持插件获取当前流是否有重复流量标志.v4.2.32
| -rw-r--r-- | include/private/sapp_global_val.h | 2 | ||||
| -rw-r--r-- | include/private/sapp_pkt_stat.h | 4 | ||||
| -rw-r--r-- | service/sapp_default.service.in | 1 | ||||
| -rw-r--r-- | service/sapp_marsio.service.in | 1 | ||||
| -rw-r--r-- | src/dealpkt/plug_support.c | 107 | ||||
| -rw-r--r-- | src/packet_io/packet_io_marsio.c | 1 | ||||
| -rw-r--r-- | src/packet_io/packet_io_pcap.c | 2 | ||||
| -rw-r--r-- | src/timer/sapp_timer.c | 34 | ||||
| -rw-r--r-- | test/test_app_sapp.c | 19 |
9 files changed, 139 insertions, 32 deletions
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h index 9f7c744..c1648de 100644 --- a/include/private/sapp_global_val.h +++ b/include/private/sapp_global_val.h @@ -346,7 +346,7 @@ typedef struct __sapp_gval_mthread sapp_gval_mthread_t; struct __sapp_gval_individual_volatile{ volatile time_t current_time; volatile long long current_time_ms; - volatile int current_state; + volatile int current_state; /* refer to enum sapp_state_t */ }__attribute__ ((aligned (64))); typedef struct __sapp_gval_individual_volatile sapp_gval_individual_volatile_t; diff --git a/include/private/sapp_pkt_stat.h b/include/private/sapp_pkt_stat.h index e4d43e1..f8a4a58 100644 --- a/include/private/sapp_pkt_stat.h +++ b/include/private/sapp_pkt_stat.h @@ -8,8 +8,10 @@ */ typedef enum __sapp_sys_stat_type{ + SAPP_STAT_FETCH_PKT, /* sapp���Դ�pcap, marsio��ȡ���ݰ��Ĵ���, �����Ľ��, ��Ҫ����������� */ + /* - ����overlay������, ���²���LINE�Ķ��������е���ʵͨ��˫��������, ����vxlan�ȷ�װ���ֽ���, + LINE����overlay������, ���²���LINE�Ķ��������е���ʵͨ��˫��������, ����vxlan�ȷ�װ���ֽ���, ����һ��vxlan���ܳ�����1000�ֽ�, vxlan overlay�����ethernet,ipv4,udp,vxlan, �ܳ�����50�ֽ�, ��SAPP_STAT_RCV_LINE��1000�ֽ�, SAPP_STAT_RCV_RAW��950�ֽ�. */ diff --git a/service/sapp_default.service.in b/service/sapp_default.service.in index cb61160..a5a383c 100644 --- a/service/sapp_default.service.in +++ b/service/sapp_default.service.in @@ -15,6 +15,7 @@ LimitCORE=infinity TasksMax=infinity Delegate=yes KillMode=processs +WatchdogSec=10s [Install] WantedBy=multi-user.target diff --git a/service/sapp_marsio.service.in b/service/sapp_marsio.service.in index 177f465..965585c 100644 --- a/service/sapp_marsio.service.in +++ b/service/sapp_marsio.service.in @@ -16,6 +16,7 @@ LimitCORE=infinity TasksMax=infinity Delegate=yes KillMode=process +WatchdogSec=10s [Install] WantedBy=multi-user.target diff --git a/src/dealpkt/plug_support.c b/src/dealpkt/plug_support.c index 3056ec3..240515c 100644 --- a/src/dealpkt/plug_support.c +++ b/src/dealpkt/plug_support.c @@ -983,7 +983,8 @@ static int MESA_get_stream_plug_pme(const struct streaminfo *pstream, void *opt_ this_plug_entry = plugin_get_plug_entry(in_arg->plug_name, in_arg->plug_entry_type); if(NULL == this_plug_entry){ - sapp_runtime_log(RLOG_LV_FATAL, "MESA_get_stream_opt() MSO_STREAM_PLUG_PME error, can't get plug:%s entry:%s address", in_arg->plug_name, in_arg->plug_entry_type); + sapp_runtime_log(RLOG_LV_FATAL, "%s,MESA_get_stream_opt() MSO_STREAM_PLUG_PME error, can't get plug:%s entry:%s address", + printaddr(&pstream->addr, pstream->threadnum), in_arg->plug_name, in_arg->plug_entry_type); return -1; } @@ -1007,7 +1008,7 @@ static int MESA_get_stream_plug_pme(const struct streaminfo *pstream, void *opt_ goto bingo; } }else{ - sapp_runtime_log(RLOG_LV_FATAL, "MESA_get_stream_opt() MSO_STREAM_PLUG_PME error, not support stream type:%d", pstream->type); + sapp_runtime_log(RLOG_LV_FATAL, "%s, MESA_get_stream_opt() MSO_STREAM_PLUG_PME error, not support stream type:%d", printaddr(&pstream->addr, pstream->threadnum),pstream->type); return -1; } @@ -1020,6 +1021,48 @@ bingo: return ret; } + +static int MESA_get_stream_dup_pkt_stat(const struct streaminfo *pstream, void *opt_val, int *opt_val_len) +{ + const struct streaminfo_private *pstream_pr = (struct streaminfo_private *)pstream; + int *res_val = (int *)opt_val; + int ret = 0; + + if(0 == sapp_global_val->config.packet_io.dup_pkt_para.dup_pkt_distinguish_enable){ + sapp_runtime_log(RLOG_LV_INFO, "%s, MESA_get_stream_opt() MSO_HAVE_DUP_PKT error, config duplicate_pkt_distinguish is not enable", + printaddr(&pstream->addr, pstream->threadnum)); + *res_val = -2; + return 0; + } + + if(pstream_pr->has_duplicate_pkt != 0){ + *res_val = 1; + return 0; + } + + /* �������ظ�������,����û�������ظ��� */ + if(STREAM_TYPE_TCP == pstream->type){ + if((pstream->ptcpdetail->clientpktnum <= SAPP_DUP_FIRST_PKT_NUM) && (pstream->ptcpdetail->serverpktnum <= SAPP_DUP_FIRST_PKT_NUM)){ /* ��̫��, �������ж���û���ظ��� */ + *res_val = -2; + }else{ + *res_val = 0; + } + }else if(STREAM_TYPE_UDP == pstream->type){ + if((pstream->pudpdetail->clientpktnum <= SAPP_DUP_FIRST_PKT_NUM) && (pstream->pudpdetail->serverpktnum <= SAPP_DUP_FIRST_PKT_NUM)){ /* ��̫��, �������ж���û���ظ��� */ + *res_val = -2; + }else{ + *res_val = 0; + } + }else{ + sapp_runtime_log(RLOG_LV_INFO, "%s, MESA_get_stream_opt() MSO_HAVE_DUP_PKT error, not support stream type:%d", + printaddr(&pstream->addr, pstream->threadnum), pstream->type); + *res_val = -2; + ret = -1; + } + + return ret; +} + int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt opt, void *opt_val, int *opt_val_len) { int ret = 0; @@ -1032,12 +1075,12 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case (int)MSO_MAX_UNORDER: { if(STREAM_TYPE_TCP != pstream->type){ - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_MAX_UNORDER error:stream type is not tcp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s, MESA_get_stream_opt() MSO_MAX_UNORDER error:stream type is not tcp!\n", printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } if(*opt_val_len < (int)sizeof(struct max_unorder_opt)){ - sapp_runtime_log(RLOG_LV_INFO,"MESA_get_stream_opt() MSO_MAX_UNORDER error:opt_val_len invalid, must be sizeof(struct max_unorder_opt)\n"); + sapp_runtime_log(RLOG_LV_INFO,"%s, MESA_get_stream_opt() MSO_MAX_UNORDER error:opt_val_len invalid, must be sizeof(struct max_unorder_opt)\n", printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1049,7 +1092,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case (int)MSO_NEED_ACK: { if(STREAM_TYPE_TCP != pstream->type){ - sapp_runtime_log(RLOG_LV_INFO,"MESA_get_stream_opt() MSO_NEED_ACK error:stream type is not tcp!\n"); + sapp_runtime_log(RLOG_LV_INFO,"%s, MESA_get_stream_opt() MSO_NEED_ACK error:stream type is not tcp!\n", printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1067,7 +1110,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o break; } if(STREAM_TYPE_TCP != pstream->type){ - sapp_runtime_log(RLOG_LV_INFO,"MESA_get_stream_opt() MSO_TAKEOVER error:stream type is not tcp!\n"); + sapp_runtime_log(RLOG_LV_INFO,"%s, MESA_get_stream_opt() MSO_TAKEOVER error:stream type is not tcp!\n", printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1081,7 +1124,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case (int)MSO_TIMEOUT: { if(sizeof(short) != *opt_val_len){ - sapp_runtime_log(RLOG_LV_INFO,"MESA_get_stream_opt() MSO_TIMEOUT error:opt_val_len invalid, must be sizeof(short)\n"); + sapp_runtime_log(RLOG_LV_INFO,"%s, MESA_get_stream_opt() MSO_TIMEOUT error:opt_val_len invalid, must be sizeof(short)\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1095,7 +1138,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case (int)MSO_IGNORE_RST_FIN: { if(STREAM_TYPE_TCP != pstream->type){ - sapp_runtime_log(RLOG_LV_INFO,"MESA_get_stream_opt() MSO_IGNORE_RST_FIN error:stream type is not tcp!\n"); + sapp_runtime_log(RLOG_LV_INFO,"%s, MESA_get_stream_opt() MSO_IGNORE_RST_FIN error:stream type is not tcp!\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1111,7 +1154,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o UCHAR *out_val = (UCHAR *)opt_val; if(STREAM_TYPE_TCP != pstream->type){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO,"MESA_get_stream_opt() MSO_TCP_CREATE_LINK_MODE error:stream type is not tcp!\n"); + sapp_runtime_log(RLOG_LV_INFO,"%s, MESA_get_stream_opt() MSO_TCP_CREATE_LINK_MODE error:stream type is not tcp!\n", printaddr(&pstream->addr, pstream->threadnum)); break; } @@ -1127,19 +1170,19 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o UINT32 *out_val = (UINT32 *)opt_val; if(STREAM_TYPE_TCP != pstream->type){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TCP_ISN_C2S error:stream type is not tcp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s, MESA_get_stream_opt() MSO_TCP_ISN_C2S error:stream type is not tcp!\n", printaddr(&pstream->addr, pstream->threadnum)); break; } pdetail_pr = (struct tcpdetail_private*)(pstream->pdetail); if(pdetail_pr->creat_mod != TCP_CTEAT_LINK_BYSYN){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TCP_ISN_C2S error: stream create mode is not by SYN!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s, MESA_get_stream_opt() MSO_TCP_ISN_C2S error: stream create mode is not by SYN!\n", printaddr(&pstream->addr, pstream->threadnum)); break; } if(0 == pdetail_pr->iserverseq){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TCP_ISN_C2S error: can't get SYN seq!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s, MESA_get_stream_opt() MSO_TCP_ISN_C2S error: can't get SYN seq!\n", printaddr(&pstream->addr, pstream->threadnum)); break; } @@ -1155,19 +1198,19 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o UINT32 *out_val = (UINT32 *)opt_val; if(STREAM_TYPE_TCP != pstream->type){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TCP_ISN_S2C error:stream type is not tcp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TCP_ISN_S2C error:stream type is not tcp!\n", printaddr(&pstream->addr, pstream->threadnum)); break; } pdetail_pr = (struct tcpdetail_private*)(pstream->pdetail); if(pdetail_pr->creat_mod != TCP_CTEAT_LINK_BYSYN){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TCP_ISN_S2C error: stream create mode is not by SYN!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TCP_ISN_S2C error: stream create mode is not by SYN!\n",printaddr(&pstream->addr, pstream->threadnum)); break; } if(0 == pdetail_pr->iclientseq){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TCP_ISN_S2C error: can't get SYN/ACK seq!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TCP_ISN_S2C error: can't get SYN/ACK seq!\n",printaddr(&pstream->addr, pstream->threadnum)); break; } @@ -1228,7 +1271,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o if(pstream->opstate != OP_STATE_CLOSE){ ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "MESA_get_stream_opt() MSO_STREAM_CLOSE_REASON error: stream %p has not closed!\n", pstream); + sapp_runtime_log(RLOG_LV_DEBUG, "%s,MESA_get_stream_opt() MSO_STREAM_CLOSE_REASON error:has not closed!\n",printaddr(&pstream->addr, pstream->threadnum)); break; } if(STREAM_TYPE_TCP == pstream->type){ @@ -1239,7 +1282,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o *close_reason = pstream_pr->stream_close_reason; }else{ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_STREAM_CLOSE_REASON error:unsupport stream type:%d!\n", pstream->type); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_STREAM_CLOSE_REASON error:unsupport stream type:%d!\n",printaddr(&pstream->addr, pstream->threadnum), pstream->type); } } break; @@ -1261,7 +1304,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o unsigned long long *out_args = (unsigned long long *)opt_val; unsigned long long dev_id = *out_args; if(dev_id < 0 || dev_id > 4095){ - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_GLOBAL_STREAM_ID error:invalid dev_id:%llu!\n", dev_id); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_GLOBAL_STREAM_ID error:invalid dev_id:%llu!\n", printaddr(&pstream->addr, pstream->threadnum), dev_id); return -1; } unsigned long long local_global_id = pstream_pr->global_stream_id; @@ -1274,7 +1317,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case MSO_TOTAL_INBOUND_PKT: { if((STREAM_TYPE_TCP != pstream->type) && (STREAM_TYPE_UDP != pstream->type)){ - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_INBOUND_PKT error: stream type is not tcp or udp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_INBOUND_PKT error: stream type is not tcp or udp!\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1286,7 +1329,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case MSO_TOTAL_OUTBOUND_PKT: { if((STREAM_TYPE_TCP != pstream->type) && (STREAM_TYPE_UDP != pstream->type)){ - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_OUTBOUND_PKT error: stream type is not tcp or udp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_OUTBOUND_PKT error: stream type is not tcp or udp!\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1298,7 +1341,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case MSO_TOTAL_INBOUND_BYTE: { if((STREAM_TYPE_TCP != pstream->type) && (STREAM_TYPE_UDP != pstream->type)){ - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE error: stream type is not tcp or udp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE error: stream type is not tcp or udp!\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1312,17 +1355,17 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o if(STREAM_TYPE_TCP == pstream->type){ if(G_TCP_FLOW_STAT_PROJECT_ID == -1){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE_RAW error: project tcp_flow_stat is not enable!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE_RAW error: project tcp_flow_stat is not enable!\n",printaddr(&pstream->addr, pstream->threadnum)); break; } }else if(STREAM_TYPE_UDP == pstream->type){ if(G_UDP_FLOW_STAT_PROJECT_ID == -1){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE_RAW error: project udp_flow_stat is not enable!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE_RAW error: project udp_flow_stat is not enable!\n",printaddr(&pstream->addr, pstream->threadnum)); break; } }else{ - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE error: stream type is not tcp or udp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE error: stream type is not tcp or udp!\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1336,7 +1379,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case MSO_TOTAL_OUTBOUND_BYTE: { if((STREAM_TYPE_TCP != pstream->type) && (STREAM_TYPE_UDP != pstream->type)){ - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_OUTBOUND_BYTE error: stream type is not tcp or udp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_OUTBOUND_BYTE error: stream type is not tcp or udp!\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1350,17 +1393,17 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o if(STREAM_TYPE_TCP == pstream->type){ if(G_TCP_FLOW_STAT_PROJECT_ID == -1){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE_RAW error: project tcp_flow_stat is not enable!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE_RAW error: project tcp_flow_stat is not enable!\n",printaddr(&pstream->addr, pstream->threadnum)); break; } }else if(STREAM_TYPE_UDP == pstream->type){ if(G_UDP_FLOW_STAT_PROJECT_ID == -1){ ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE_RAW error: project udp_flow_stat is not enable!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE_RAW error: project udp_flow_stat is not enable!\n",printaddr(&pstream->addr, pstream->threadnum)); break; } }else{ - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE error: stream type is not tcp or udp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_TOTAL_INBOUND_BYTE error: stream type is not tcp or udp!\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1374,7 +1417,7 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o { if ((STREAM_TYPE_TCP != pstream->type) && (STREAM_TYPE_UDP != pstream->type)) { - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() MSO_STREAM_CREATE_TIMESTAMP_MS error: stream type is not tcp or udp!\n"); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() MSO_STREAM_CREATE_TIMESTAMP_MS error: stream type is not tcp or udp!\n",printaddr(&pstream->addr, pstream->threadnum)); ret = -1; break; } @@ -1386,9 +1429,13 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o case MSO_STREAM_PLUG_PME: ret = MESA_get_stream_plug_pme(pstream, opt_val, opt_val_len); break; + + case MSO_HAVE_DUP_PKT: + ret = MESA_get_stream_dup_pkt_stat(pstream, opt_val, opt_val_len); + break; default: - sapp_runtime_log(RLOG_LV_INFO, "MESA_get_stream_opt() error:unsupport MESA_stream_opt type:%d!\n", (int)opt); + sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() error:unsupport MESA_stream_opt type:%d!\n",printaddr(&pstream->addr, pstream->threadnum), (int)opt); ret = -1; break; } diff --git a/src/packet_io/packet_io_marsio.c b/src/packet_io/packet_io_marsio.c index 73af258..d2666e7 100644 --- a/src/packet_io/packet_io_marsio.c +++ b/src/packet_io/packet_io_marsio.c @@ -843,6 +843,7 @@ static void *marsio4_worker(void *arg) } } + sapp_global_val->mthread_volatile[tid]->sys_stat.count[SAPP_STAT_FETCH_PKT]++; total_call_times++; if((rcv_pkt_tims % sapp_global_val->config.packet_io.polling_priority) == 0){ diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c index 3ae8804..13fc580 100644 --- a/src/packet_io/packet_io_pcap.c +++ b/src/packet_io/packet_io_pcap.c @@ -764,6 +764,8 @@ static void *__pcap_work_thread(void *arg) }
while(1){
+ sapp_global_val->mthread_volatile[thread_num]->sys_stat.count[SAPP_STAT_FETCH_PKT]++;
+
if(0 == MESA_lqueue_get_count(work_thread_pool[thread_num].pkt_queue)){
if(stream_process_polling(thread_num) != 0){
polling_work_times++;
diff --git a/src/timer/sapp_timer.c b/src/timer/sapp_timer.c index 88cea4c..68688bf 100644 --- a/src/timer/sapp_timer.c +++ b/src/timer/sapp_timer.c @@ -2,6 +2,7 @@ #include "sapp_private_api.h" #include "public/sapp_timer.h" #include "support/event2/event.h" +#include <systemd/sd-daemon.h> #ifdef __cplusplus extern "C" { @@ -411,6 +412,38 @@ static void *sapp_standalone_timer_check_timeout(void *arg) return NULL; } +static void sapp_watch_dog(void) +{ + const char *check_result = "WATCHDOG=1"; + int tid; + + if(sapp_global_val->individual_volatile->current_state != SAPP_STATE_PROCESSING){ + return; + } + + /* ��Ҫ��sapp.servie ���������: WatchdogSec=10s */ + if(sd_watchdog_enabled(0, NULL)) + { + for(tid = 0; tid < sapp_global_val->config.cpu.worker_threads; tid++){ + /* + �˴�����polling, ���������� SAPP_STAT_FETCH_PKT, ��Ϊû��Proxyʱ, polling���ܿ����ǹرյ�. + ��ǰʱ�̸�һ��֮ǰ����һ��, ˵���߳������� + */ + if(sapp_global_val->mthread_volatile[tid]->sys_stat.count[SAPP_STAT_FETCH_PKT] <= 0){ + check_result = "WATCHDOG=trigger"; + sapp_runtime_log(RLOG_LV_FATAL, "##### detect deadlock in thread:%d, send systemd notify WATCHDOG=trigger #####", tid); + break; + } + + /* ÿ������, ���һֱ�ۼ�, SAPP_STAT_FETCH_PKT�����̫����, ���ʹ�ü�¼��ʷ����, Ȼ���뵱ǰ���Աȵķ�ʽ, ���ܻ����, �����жϴ��� */ + sapp_global_val->mthread_volatile[tid]->sys_stat.count[SAPP_STAT_FETCH_PKT] = 0; + } + + sd_notify(0, check_result); + } + return; +} + void *sapp_time_event_thread(void *arg) { @@ -437,6 +470,7 @@ void *sapp_time_event_thread(void *arg) if(ABBR_CURRENT_TIME > last_log_time){ last_log_time = ABBR_CURRENT_TIME; sysinfo_output(); + sapp_watch_dog(); } ABBR_CURRENT_TIME_MS = sapp_get_current_time_in_ms(); diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c index 70793f3..8d16edc 100644 --- a/test/test_app_sapp.c +++ b/test/test_app_sapp.c @@ -3249,6 +3249,25 @@ char POLLING_ENTRY(struct streaminfo *stream, void **pme, int thread_seq,void * } +char fake_deadlock(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet) +{ + /* ����������߳�, ģ������ */ + int opt_val_len = sizeof(int); + int tid; + int tot_thread_cnt; + sapp_get_platform_opt(SPO_THREAD_COUNT, &tot_thread_cnt, &opt_val_len); + + tid = rand() % tot_thread_cnt; + + if(tid == pstream->threadnum){ + printf("thread:%d, fake deadlock!\n", tid); + while(1){pause();} + } + + return APP_STATE_GIVEME; +} + + int CHAR_INIT() { |
