The way I understand this, there are 2 ways to close TCP connection:
RST causes immediate connection termination, while in FIN you get a confirmation.
Do I understand this right, and are there any other distinctions between the two? Can those 2 flags be used together?
RST causes immediate connection termination, while in FIN you get a confirmation.
FIN Packet vs RST Packet Comparison – In case of FIN hosts get a confirmation. RST causes immediate connection termination without any confirmation. Condition For Sending. Fin is sent when the application tells TCP that it wants to close so TCP does 4 way handshake and closes the connection gracefully.
The FIN flag indicates the end of data transmission to finish a TCP connection. Their purposes are mutually exclusive.
A TCP Reset (RST) packet is used by a TCP sender to indicate that it will neither accept nor receive more data. Out-of-path network management devices may generate and inject TCP Reset packets in order to terminate undesired connections.
FIN says: "I finished talking to you, but I'll still listen to everything you have to say until you say that you're done."
RST says: "There is no conversation. I won't say anything and I won't listen to anything you say."
RST is useful if you have long lasting TCP connection with little traffic. If one of the computers is restarted, it forgets about the connection, and the other computer gets RST, as soon as it sends another packet.
FIN or RST would be sent in the following case
OS is doing the resource cleanup when your process exit without closing socket.
If your process call close(), FIN would be sent from the closing side by default (note: you can set socket option SO_LINGER to make it send RST instead of FIN)
If your process exit without closing the socket, kernel would close the tcp connection and do the clean up for your process. FIN or RST can be sent. If there is data in your receive queue, RST would be sent. Otherwise, FIN would be sent.
You can loop through tcp_close() in tcp.c for more details.(I am using kernel-2.6.32-573.7.1 from redhat branch)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With