ack increase monotonically

This commit is contained in:
wangyu 2017-08-04 12:46:46 +08:00
parent 5cf4cc7cb2
commit bc04a6898d
4 changed files with 68 additions and 4 deletions

View File

@ -14,6 +14,7 @@ unordered_map<int, const char*> raw_mode_tostring = {{mode_faketcp, "faketcp"},
int socket_buf_size=1024*1024;
static int random_number_fd=-1;
char iptables_rule[200];
program_mode_t program_mode=unset_mode;//0 unset; 1client 2server
uint64_t get_current_time()
{
@ -218,5 +219,64 @@ int char_to_numbers(const char * data,int len,id_t &id1,id_t &id2,id_t &id3)
return 0;
}
bool larger_than_u32(uint32_t a,uint32_t b)
{
program_mode_t program_mode=unset_mode;//0 unset; 1client 2server
uint32_t smaller,bigger;
smaller=min(a,b);//smaller in normal sense
bigger=max(a,b);
uint32_t distance=min(bigger-smaller,smaller+(0xffffffff-bigger+1));
if(distance==bigger-smaller)
{
if(bigger==a)
{
return 1;
}
else
{
return 0;
}
}
else
{
if(smaller==b)
{
return 0;
}
else
{
return 1;
}
}
}
bool larger_than_u16(uint16_t a,uint16_t b)
{
uint16_t smaller,bigger;
smaller=min(a,b);//smaller in normal sense
bigger=max(a,b);
uint16_t distance=min(bigger-smaller,smaller+(0xffff-bigger+1));
if(distance==bigger-smaller)
{
if(bigger==a)
{
return 1;
}
else
{
return 0;
}
}
else
{
if(smaller==b)
{
return 0;
}
else
{
return 1;
}
}
}

View File

@ -117,7 +117,8 @@ uint32_t get_true_random_number();
uint32_t get_true_random_number_nz();
uint64_t ntoh64(uint64_t a);
uint64_t hton64(uint64_t a);
bool larger_than_u16(uint16_t a,uint16_t b);
bool larger_than_u32(uint32_t a,uint32_t b);
void setnonblocking(int sock);
int set_buf_size(int fd);

View File

@ -2763,6 +2763,7 @@ void iptables_warn()
}
int main(int argc, char *argv[])
{
//printf("%d %d %d %d",larger_than_u32(1,2),larger_than_u32(2,1),larger_than_u32(0xeeaaeebb,2),larger_than_u32(2,0xeeaaeebb));
//assert(0==1);
dup2(1, 2);//redirect stderr to stdout
signal(SIGINT, INThandler);

View File

@ -1318,6 +1318,7 @@ int after_recv_raw0(raw_info_t &raw_info)
send_info.ts_ack=recv_info.ts;
if (recv_info.syn == 0 && recv_info.ack == 1 && raw_info.last_recv_len != 0) //only modify send_info when the packet is not part of handshake
{
if(larger_than_u32(recv_info.seq+raw_info.last_recv_len,send_info.ack_seq))
send_info.ack_seq = recv_info.seq+raw_info.last_recv_len;//TODO only update if its larger
}
}
@ -1325,6 +1326,7 @@ int after_recv_raw0(raw_info_t &raw_info)
{
if(program_mode==server_mode)
{
if(larger_than_u16(recv_info.icmp_seq,send_info.icmp_seq))
send_info.icmp_seq = recv_info.icmp_seq; //TODO only update if its larger
}
}