Skip to content

Commit

Permalink
add warning when packet is truncated
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Jan 16, 2021
1 parent 6dcc971 commit af607e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
18 changes: 16 additions & 2 deletions tunnel_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ void data_from_local_or_fec_timeout(conn_info_t & conn_info,int is_time_out)
mylog(log_trace,"events[idx].data.u64 == (u64_t)local_listen_fd\n");
address_t::storage_t udp_new_addr_in={0};
socklen_t udp_new_addr_len = sizeof(address_t::storage_t);
if ((data_len = recvfrom(local_listen_fd, data, max_data_len, 0,
if ((data_len = recvfrom(local_listen_fd, data, max_data_len+1, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
mylog(log_debug,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",get_sock_error());
return;
};

if(data_len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d, packet truncated, dropped\n",max_data_len);
return ;
}

if(!disable_mtu_warn&&data_len>=mtu_warn)
{
mylog(log_warn,"huge packet,data len=%d (>=%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",data_len,mtu_warn);
Expand Down Expand Up @@ -122,7 +128,15 @@ static void remote_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)

int fd=fd_manager.to_fd(remote_fd64);

int data_len =recv(fd,data,max_data_len,0);
int data_len =recv(fd,data,max_data_len+1,0);

if(data_len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d, packet truncated, dropped\n",max_data_len);
return ;
}


mylog(log_trace, "received data from udp fd %d, len=%d\n", remote_fd,data_len);
if(data_len<0)
{
Expand Down
16 changes: 14 additions & 2 deletions tunnel_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ void data_from_remote_or_fec_timeout_or_conn_timer(conn_info_t & conn_info,fd64_
conn_info.update_active_time();

int fd=fd_manager.to_fd(fd64);
data_len=recv(fd,data,max_data_len,0);
data_len=recv(fd,data,max_data_len+1,0);

if(data_len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d, packet truncated, dropped\n",max_data_len);
return ;
}

mylog(log_trace,"received a packet from udp_fd,len:%d,conv=%d\n",data_len,conv);

Expand Down Expand Up @@ -135,12 +141,18 @@ static void local_listen_cb(struct ev_loop *loop, struct ev_io *watcher, int rev
int data_len;
address_t::storage_t udp_new_addr_in={0};
socklen_t udp_new_addr_len = sizeof(address_t::storage_t);
if ((data_len = recvfrom(local_listen_fd, data, max_data_len, 0,
if ((data_len = recvfrom(local_listen_fd, data, max_data_len+1, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",get_sock_error());
return;
};

if(data_len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d, packet truncated, dropped\n",max_data_len);
return ;
}

address_t addr;
addr.from_sockaddr((struct sockaddr *) &udp_new_addr_in,udp_new_addr_len);

Expand Down

0 comments on commit af607e4

Please sign in to comment.