Correctly send RST packet to client and TCP server as gateway
I am programming a gateway which is one of the functions to kill connections when exchanging enough packets. I would like to know how to properly shape RST packets to be sent to the client and server to terminate the connection.
To test this I am using ftp connections / sessions. Right now, what I see is that when I send RST packets, the client responds infinitely with SYN packets, and the server just continues to stream with ACK packets. Please note that after I decide to destroy the connection, I block traffic between both ends.
I think there might be something wrong with the way I handle my SEQ and ACK numbers. I couldn't find ressources to explain what to do with the SEQ and ACK numbers when sending the RST packet. Right now I am setting SEQ to a new random number (with rand ()) and setting ACK to 0 (since I am not using the ACK flag). I am inverting the source address with the destination address and source port with the destination port and saw that I was calculating the checksums correctly.
It seems to me that both client and server do not accept completion.
source to share