net: context: Go back to LISTEN state when receiving RST

In LISTEN state ignore a TCP RST. In SYN RCVD state, reset TCP
connection state to LISTEN when a valid RST segment is received. In all
other states close the connection - except that these other states will
not be handled in tcp_syn_rcvd() function.

Jira: ZEP-2279

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
This commit is contained in:
Patrik Flykt 2017-06-22 11:07:09 +03:00 committed by Jukka Rissanen
commit ac07550566

View file

@ -1378,14 +1378,17 @@ NET_CONN_CB(tcp_syn_rcvd)
} }
/* /*
* If we receive RST, we go back to LISTEN state if the previous state * See RFC 793 chapter 3.4 "Reset Processing" and RFC 793, page 65
* was LISTEN, otherwise we go to CLOSED state. * for more details. If RST is received in SYN_RCVD state, go back
* See RFC 793 chapter 3.4 "Reset Processing" for more details. * to LISTEN state. No other states are valid for this function.
*/ */
if (NET_TCP_FLAGS(pkt) == NET_TCP_RST) { if (NET_TCP_FLAGS(pkt) == NET_TCP_RST) {
/* We only accept RST packet that has valid seq field. */ /* We only accept an RST packet that has valid seq field
if (!net_tcp_validate_seq(tcp, pkt)) { * and ignore RST received in LISTEN state.
*/
if (!net_tcp_validate_seq(tcp, pkt) ||
net_tcp_get_state(tcp) == NET_TCP_LISTEN) {
net_stats_update_tcp_seg_rsterr(); net_stats_update_tcp_seg_rsterr();
return NET_DROP; return NET_DROP;
} }
@ -1396,7 +1399,10 @@ NET_CONN_CB(tcp_syn_rcvd)
net_tcp_print_recv_info("RST", pkt, NET_TCP_HDR(pkt)->src_port); net_tcp_print_recv_info("RST", pkt, NET_TCP_HDR(pkt)->src_port);
if (net_tcp_get_state(tcp) != NET_TCP_LISTEN) { if (net_tcp_get_state(tcp) == NET_TCP_SYN_RCVD) {
net_tcp_change_state(tcp, NET_TCP_LISTEN);
} else {
NET_DBG("TCP socket not in SYN RCVD state, closing");
net_tcp_change_state(tcp, NET_TCP_CLOSED); net_tcp_change_state(tcp, NET_TCP_CLOSED);
} }