From 54f32f06111ef27e5ec83805ded09f3674c8a63f Mon Sep 17 00:00:00 2001 From: wangyu- Date: Wed, 11 Oct 2017 09:10:38 -0500 Subject: [PATCH] fixed clear bug,add option random-drop --- connection.cpp | 2 ++ misc.cpp | 12 ++++++++++++ network.cpp | 7 +++++++ network.h | 2 ++ 4 files changed, 23 insertions(+) diff --git a/connection.cpp b/connection.cpp index 7c3990b..968ce04 100644 --- a/connection.cpp +++ b/connection.cpp @@ -219,6 +219,7 @@ conv_manager_t::~conv_manager_t() } cnt++; } + clear_it=it; return 0; } @@ -451,6 +452,7 @@ int conn_manager_t::clear_inactive0() } cnt++; } + clear_it=it; return 0; } diff --git a/misc.cpp b/misc.cpp index 021f579..e324c26 100644 --- a/misc.cpp +++ b/misc.cpp @@ -236,6 +236,7 @@ void process_arg(int argc, char *argv[]) //process all options {"seq-mode", required_argument, 0, 1}, {"conf-file", required_argument, 0, 1}, {"force-sock-buf", no_argument, 0, 1}, + {"random-drop", required_argument, 0, 1}, {NULL, 0, 0, 0} }; @@ -558,10 +559,21 @@ void process_arg(int argc, char *argv[]) //process all options myexit(-1); } } + else if(strcmp(long_options[option_index].name,"random-drop")==0) + { + sscanf(optarg,"%d",&random_drop); + if(random_drop<0||random_drop>10000) + { + mylog(log_fatal,"random_drop must be between 0 10000 \n"); + myexit(-1); + } + mylog(log_info,"random_drop =%d \n",random_drop); + } else if(strcmp(long_options[option_index].name,"conf-file")==0) { mylog(log_info,"configuration loaded from %s\n",optarg); } + else { mylog(log_warn,"ignored unknown long option ,option_index:%d code:<%x>\n",option_index, optopt); diff --git a/network.cpp b/network.cpp index dfb5045..9416a18 100644 --- a/network.cpp +++ b/network.cpp @@ -15,6 +15,7 @@ u32_t link_level_header_len=0;//set it to 14 if SOCK_RAW is used in socket(PF_PA int seq_mode=3; int max_seq_mode=4; +int random_drop=0; int filter_port=-1; @@ -1623,6 +1624,12 @@ int recv_raw_tcp_deprecated(packet_info_t &info,char * &payload,int &payloadlen) }*/ int send_raw0(raw_info_t &raw_info,const char * payload,int payloadlen) { + if (random_drop != 0) { + if (get_true_random_number() % 10000 < (u32_t) random_drop) { + return 0; + } + } + packet_info_t &send_info=raw_info.send_info; packet_info_t &recv_info=raw_info.recv_info; mylog(log_trace,"send_raw : from %x %d to %x %d\n",send_info.src_ip,send_info.src_port,send_info.dst_ip,send_info.dst_port); diff --git a/network.h b/network.h index a0ff8c5..af0bfcf 100644 --- a/network.h +++ b/network.h @@ -21,6 +21,8 @@ extern int lower_level_manual; extern char if_name[100]; extern unsigned char dest_hw_addr[]; +extern int random_drop; + extern int ifindex; struct icmphdr