diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index 7d7f3bb22a9..a9958d935c3 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -233,4 +233,43 @@ config NET_SENDFILE files out a TCP connection. endif # NET_TCP && !NET_TCP_NO_STACK + +if NET_STATISTICS + +config NET_TCP_DEBUG_DROP_RECV + bool "TCP/IP debug feature to drop receive packet" + default n + ---help--- + This is the debug feature to drop TCP/IP received packet + +if NET_TCP_DEBUG_DROP_RECV + +config NET_TCP_DEBUG_DROP_RECV_PROBABILITY + int "TCP/IP drop probability of received packet" + range 50 10000 + default 50 + ---help--- + This is the drop probability of received packet, Default: 1/50 + +endif # NET_TCP_DEBUG_DROP_RECV + +config NET_TCP_DEBUG_DROP_SEND + bool "TCP/IP debug feature to drop send packet" + default n + ---help--- + This is the debug feature to drop TCP/IP send packet + +if NET_TCP_DEBUG_DROP_SEND + +config NET_TCP_DEBUG_DROP_SEND_PROBABILITY + int "TCP/IP drop probability of send packet" + range 50 10000 + default 50 + ---help--- + This is the drop probability of send packet, Default: 1/50 + +endif # NET_TCP_DEBUG_DROP_SEND + +endif # NET_STATISTICS + endmenu # TCP/IP Networking diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index 7cda596ce9d..72710e45850 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -628,6 +628,37 @@ found: dev->d_len -= (len + iplen); +#if defined(CONFIG_NET_STATISTICS) && \ + defined(CONFIG_NET_TCP_DEBUG_DROP_RECV) + +#pragma message \ + "CONFIG_NET_TCP_DEBUG_DROP_RECV is selected, this is debug " \ + "feature to drop the tcp received packet on the floor, " \ + "please confirm the configuration again if you do not want " \ + "debug the TCP stack." + + /* Debug feature to drop the tcp received packet on the floor */ + + if (dev->d_len > 0) + { + if ((g_netstats.tcp.recv % + CONFIG_NET_TCP_DEBUG_DROP_RECV_PROBABILITY) == 0) + { + uint32_t seq = tcp_getsequence(tcp->seqno); + + g_netstats.tcp.drop++; + + ninfo("TCP DROP RCVPKT: " + "[%d][%" PRIu32 " : %" PRIu32 " : %d]\n", + g_netstats.tcp.drop, seq, TCP_SEQ_ADD(seq, dev->d_len), + dev->d_len); + + dev->d_len = 0; + return; + } + } +#endif + /* Check if the sequence number of the incoming packet is what we are * expecting next. If not, we send out an ACK with the correct numbers * in, unless we are in the SYN_RCVD state and receive a SYN, in which diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 2d8f2f297b0..1cf14ec894f 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -575,6 +575,34 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, /* Complete the common portions of the TCP message */ tcp_sendcommon(dev, conn, tcp); + +#if defined(CONFIG_NET_STATISTICS) && \ + defined(CONFIG_NET_TCP_DEBUG_DROP_SEND) + +#pragma message \ + "CONFIG_NET_TCP_DEBUG_DROP_SEND is selected, this is debug " \ + "feature to drop the tcp send packet on the floor, " \ + "please confirm the configuration again if you do not want " \ + "debug the TCP stack." + + /* Debug feature to drop the tcp received packet on the floor */ + + if ((flags & TCP_PSH) != 0) + { + if ((g_netstats.tcp.sent % + CONFIG_NET_TCP_DEBUG_DROP_SEND_PROBABILITY) == 0) + { + uint32_t seq = tcp_getsequence(tcp->seqno); + + ninfo("TCP DROP SNDPKT: " + "[%d][%" PRIu32 " : %" PRIu32 " : %d]\n", + g_netstats.tcp.sent, seq, TCP_SEQ_ADD(seq, dev->d_sndlen), + dev->d_sndlen); + + dev->d_len = 0; + } + } +#endif } /****************************************************************************