net: tcp: Set errno properly if connecting to non listening port
If we try to connect to a port which no socket is listening to, we will get a packet with "ACK | RST" flags set. In this case the errno should be ECONNREFUSED instead of ETIMEDOUT like we used to return earlier. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
b864880000
commit
ec4973dd15
1 changed files with 12 additions and 0 deletions
|
@ -2417,6 +2417,18 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
|
|||
net_stats_update_tcp_seg_rst(net_pkt_iface(pkt));
|
||||
do_close = true;
|
||||
close_status = -ECONNRESET;
|
||||
|
||||
/* If we receive RST and ACK for the sent SYN, it means
|
||||
* that there is no socket listening the port we are trying
|
||||
* to connect to. Set the errno properly in this case.
|
||||
*/
|
||||
if (conn->in_connect) {
|
||||
fl = th_flags(th);
|
||||
if (FL(&fl, ==, RST | ACK)) {
|
||||
close_status = -ECONNREFUSED;
|
||||
}
|
||||
}
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue