Skip to content

Commit

Permalink
introduce huge_buf_len and huge_data_len
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Jul 15, 2020
1 parent b3e06de commit 79bb28f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
10 changes: 5 additions & 5 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ struct not_copy_able_t
}
};

const int single_max_data_len=1800;
const int max_data_len=single_max_data_len*10;
const int buf_len=max_data_len+800;
const int huge_data_len=65535+100; //a packet with link level header might be larger than 65535
const int huge_buf_len=huge_data_len+100;

const int max_data_len=1800;
const int buf_len=max_data_len+400;

//const int max_data_len_gro=max_data_len*10;
//const int buf_len_gro=max_data_len_gro+400;
//const int max_address_len=512;

u64_t get_current_time();
Expand Down
5 changes: 3 additions & 2 deletions connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,10 @@ int recv_safer_multi(conn_info_t &conn_info,vector<char> &type_arr,vector<string
mylog(log_debug,"illegal single_len %d(%d), recv_len %d left,dropped\n",single_len,single_len_no_xor,recv_len);
break;
}
if(single_len> single_max_data_len )
if(single_len> max_data_len )
{
mylog(log_warn,"single_len %d(%d) > %d, maybe you need to turn down mtu at upper level\n",single_len,single_len_no_xor,single_max_data_len);
mylog(log_warn,"single_len %d(%d) > %d, maybe you need to turn down mtu at upper level\n",single_len,single_len_no_xor,max_data_len);
break;
}

int ret = reserved_parse_safer(conn_info, recv_data, single_len, type, data, len);
Expand Down
22 changes: 11 additions & 11 deletions network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const u32_t receive_window_lower_bound=40960;
const u32_t receive_window_random_range=512;
const unsigned char wscale=0x05;

char g_packet_buf[buf_len]; //looks dirty but works well
char g_packet_buf[huge_buf_len]; //looks dirty but works well
int g_packet_buf_len=-1;
int g_packet_buf_cnt=0;

Expand Down Expand Up @@ -834,37 +834,37 @@ int pre_recv_raw_packet()
assert(g_packet_buf_cnt==0);

g_sockaddr_len=sizeof(g_sockaddr.ll);
g_packet_buf_len = recvfrom(raw_recv_fd, g_packet_buf, max_data_len+1, 0 ,(sockaddr*)&g_sockaddr , &g_sockaddr_len);
g_packet_buf_len = recvfrom(raw_recv_fd, g_packet_buf, huge_data_len+1, 0 ,(sockaddr*)&g_sockaddr , &g_sockaddr_len);
//assert(g_sockaddr_len==sizeof(g_sockaddr.ll)); //g_sockaddr_len=18, sizeof(g_sockaddr.ll)=20, why its not equal? maybe its bc sll_halen is 6?

//assert(g_addr_ll_size==sizeof(g_addr_ll));

if(g_packet_buf_len==max_data_len+1)
if(g_packet_buf_len==huge_data_len+1)
{
if(g_fix_gro==0)
{
mylog(log_warn,"huge packet, data_len %d > %d(max_data_len),dropped\n",g_packet_buf_len,max_data_len);
mylog(log_warn,"huge packet, data_len %d > %d,dropped\n",g_packet_buf_len,huge_data_len);
return -1;
}
else
{
mylog(log_debug,"huge packet, data_len %d > %d(max_data_len),not dropped\n",g_packet_buf_len,max_data_len);
g_packet_buf_len=max_data_len;
mylog(log_debug,"huge packet, data_len %d > %d,not dropped\n",g_packet_buf_len,huge_data_len);
g_packet_buf_len=huge_data_len;
}
}

if(g_packet_buf_len> single_max_data_len+1)
if(g_packet_buf_len> max_data_len+1)
{
if(g_fix_gro==0)
{
mylog(log_warn, "huge packet, data_len %d > %d(single_max_data_len) dropped, maybe you need to turn down mtu at upper level, or you may take a look at --fix-gro\n", g_packet_buf_len,
single_max_data_len);
mylog(log_warn, "huge packet, data_len %d > %d(max_data_len) dropped, maybe you need to turn down mtu at upper level, or you may take a look at --fix-gro\n", g_packet_buf_len,
max_data_len);
return -1;
}
else
{
mylog(log_debug, "huge packet, data_len %d > %d(single_max_data_len) not dropped\n", g_packet_buf_len,
single_max_data_len);
mylog(log_debug, "huge packet, data_len %d > %d(max_data_len) not dropped\n", g_packet_buf_len,
max_data_len);
//return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion network.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern int random_drop;

extern int ifindex;

extern char g_packet_buf[buf_len];
extern char g_packet_buf[huge_buf_len];
extern int g_packet_buf_len;
extern int g_packet_buf_cnt;

Expand Down

0 comments on commit 79bb28f

Please sign in to comment.