Lost Packets And Duplicate Packets Scenario in Three way Hand-shaking - networking

In the process of 3 way hand-shaking between a client and a server, what will happen in the following scenarios? Thanks.
Lost (control) packets:
What happen if SYN lost? client vs. server actions
What happen if SYN+ACK lost? client vs. server actions
What happen if ACK lost? client vs. server actions
Duplicate (control) packets:
What does server do if duplicate SYN received?
What does client do if duplicate SYN+ACK received?
What does server do if duplicate ACK received?

What happen if SYN lost?
It is retransmitted by the client if it hasn't been acknowledged by the server with a SYN-ACK.
What happen if SYN+ACK lost?
The SYN is retransmitted by the client if it hasn't been acknowledged by the server with a SYN-ACK.
What happen if ACK lost?
The SYN-ACK is retransmitted by the server if it hasn't been acknowledged by the client with an ACK.
What does server do if duplicate SYN received?
It retransmits the SYN-ACK.
What does client do if duplicate SYN+ACK received?
It retransmits the ACK.
What does server do if duplicate ACK received?
Nothing.

Related

will server retransmit an ACK packet?

A tcp connection has a client and a server, my question is will the server start a timer when it sends an ACK packet to the client? and will the server retransmit that ACK packet if the packet gets timeout or lost?
will the server start a timer when it sends an ACK packet to the client?
The server will not control if the ACK was received by the client. If the client does not receive an ACK for transmitted data it will assume that either the data or the ACK to the data got lost. In this case it will simply resend the unacknowledged data - which will result in the server sending another ACK for the same data.

What happen when in 3 way handshake, Server did not get client's ACK message?

I understand that the client and the server are connected after client receives SYN ACK messages from the server during 3 way handshake and sending ACK messages to the Server. After they are connected, when the client sends the other messages to the server, what happens if that messages arrives at the server before the ACK message that client sent when doing the 3 way handshake?
what happens if that messages arrives at the server before the ACK message that client sent when doing the 3 way handshake?
ACK is just the flag in the TCP header together with the sequence number of the latest received data. It can be contained in an empty packet (i.e. no payload, just TCP header) but also in a packet with payload. It does not matter if a specific packet with an ACK is received as long as an ACK covering the data is received at all.
This means it is sufficient if the initial data send by the client cover the final ACK for the TCP handshake. In fact there is not even a need to send a standalone ACK (without payload) from the client at all to finish the TCP handshake but the client can start sending data as soon as the client has received the SYN and ACK from the server.

tcp syn retransmission after recieving RST?

I am using a simulator. in this simulator when a client sends a tcp syn request to a server and server responds it with RST packet (when the requesting port is close) the same client sends tcp syn retransmission to the same server (and the same port) for four times. i want to know real networks do the same? i mean in real networks if a client sends a tcp syn to a server and recieve RST , do that client sends tcp syn retransmission to that server for four times?
It totally depends on the client implementation. If you program a client to respond to a server's RST with a SYN 4 times, then that's what it will do. It might be that the server is sending an RST because it's detecting a SYN flood (if you keep on sending SYNs unsuccessfully, eventually heuristics will class it as such).
You may want to play with Scapy so you can easily write the client for these kinds of questions.

Doubt in Three way handshake in TCP and Unix listen function

Connect function returns after sending the last ACK(3rd segment of 3-way handshake of initiating TCP connection). What happens if this 3rd segment is lost because listen is still waiting for ACK at server but there is no one at client to send that ACK again ?
If the client sends its ACK with a data packet, and it gets lost, the client will notice that the data hasn't been ACKd by the server and resend the packet.
If the client sends its ACK in a separate packet, and it gets lost, the server will notice that the SYN/ACK hasn't been ACKd by the client and resend the packet. Client will respond by resending the ACK.
Whether the application's connect call is still blocking at that time doesn't matter, since the ACKing is done by the OS's TCP/IP implementation.

Will TCP Server retransmit SYN+ACK if Client is not reachable?

Assume the scenario that TCP client(A) sent SYN to the TCP Sever(B) and then TCP Client disconnected from the network, here TCP Server will be in the state SYN-RCVD how that TCP Server will know that Client is not reachable??
will TCP Server retransmit SYN+ACK ??
(Aif yes, How many times Server will retransmit SYN+ACK??
if no, How much time Server will remain in SYN-RCVD state??
will TCP Server retransmit SYN+ACK ??
Yes
How many times Server will retransmit SYN+ACK??
Depends on OS configuration.
In Linux:
/proc/sys/net/ipv4/tcp_synack_retries
In windows: HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpMaxConnectResponseRetransmissions
How much time Server will remain in SYN-RCVD state??
Until the last retransmit of SYN-ACK timeouts.
Usually over 3 minutes.

Resources