diff --git a/tunnel_client.cpp b/tunnel_client.cpp index 638e722..907d9bb 100644 --- a/tunnel_client.cpp +++ b/tunnel_client.cpp @@ -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); @@ -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) { diff --git a/tunnel_server.cpp b/tunnel_server.cpp index b1c8a1b..81f96d1 100644 --- a/tunnel_server.cpp +++ b/tunnel_server.cpp @@ -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); @@ -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);