A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
Diff: tcp/tcp.txt
- Revision:
- 75:603b10404183
- Parent:
- 72:19457bba58d0
- Child:
- 79:f50e02fb5c94
--- a/tcp/tcp.txt Mon Oct 29 09:33:44 2018 +0000 +++ b/tcp/tcp.txt Tue Oct 30 22:11:22 2018 +0000 @@ -6,52 +6,21 @@ TCB == Transmission Control Block RTO == Retransmission Time Out -Protocol -======== -Goes: -0 SYN -1 Data (length == MSS) -1+ MSS Data (length == MSS) -1+2xMSS Data (length < MSS) + FIN +Only received packets with a sequence of 1 (position == 0) is handled; any others are ignored. This works because we only handle the first line. + +From RFC793 +Reset Processing -TcpHandleReceivedPacket -======================= -Called from the network stack -Reads the header to get: the src and dst ports; the ACK and SEQ numbers; SYN, ACK, PSH, RST and FIN flags -Only handles dst port 80 (HTTP) -Retrieves the TCB for the src port -Handles RST or SYN requests -Subtract the initial sequence numbers to get the position in the query from the SEQ num and the position in the reply from the ACK num. -If the position in the query is not the same as the TCB recd bytes then adjust the TCB recd bytes -If the position in the reply is not the same as the TCB sent bytes then adjust the TCB sent bytes -Increment the TCB recd bytes by the received datalength and by 1 for a SYN or FIN -Handle the packet according to the TCB state, for established connections pass the position in the query and the position in the reply -Set the ACK number to the TCB recd bytes plus the ISN -Set the SEQ number to the TCB sent bytes plus the ISN -Increment the TCB sent bytes by the sent datalength and by 1 for a SYN or FIN -Swap the ports -Return to the network stack for unicast transmission + In all states except SYN-SENT, all reset (RST) segments are validated + by checking their SEQ-fields. A reset is valid if its sequence number + is in the window. In the SYN-SENT state (a RST received in response + to an initial SYN), the RST is acceptable if the ACK field + acknowledges the SYN. -Todo -==== -Separate the work into TcpHandleReceivedPacket and TcpPollForPacketToSend: this would allow RTO to be implemented. -Need to add the IP to the TCB -Change TCB_ACK_WAIT and TCB_FIN_WAIT to TCB_CLOSE_ACK_WAIT and TCB_CLOSE_FIN_WAIT -Add state TCB_SEND_ACK_WAIT -Add ackdBytes to TCB so that can tell if sentBytes has been acked or not; if so then send the next; if not and within timeout then wait; if not and RTO then send again - -State -===== -State Received Do New state -TCB_EMPTY SYN record ISN TCB_SYN_RECEIVED -TCB_SYN_RECEIVED ACK TCB_ESTABLISHED -TCB_ESTABLISHED -TCB_ACK_WAIT -TCB_FIN_WAIT - -State -TCB_EMPTY do nothing -TCB_SYN_RECEIVED if (TCB.sent == 0) or (TCB.sent == 1 and TCB.ackd == 0 and RTO) then send SYN ACK and ISN. -TCB_ESTABLISHED if (!TCB.finished) then send from TCB.sent. if RTO and TCB.ackd < TCB.sent then resend TCB.ackd -TCB_ACK_WAIT -TCB_FIN_WAIT + The receiver of a RST first validates it, then changes state. If the + receiver was in the LISTEN state, it ignores it. If the receiver was + in SYN-RECEIVED state and had previously been in the LISTEN state, + then the receiver returns to the LISTEN state, otherwise the receiver + aborts the connection and goes to the CLOSED state. If the receiver + was in any other state, it aborts the connection and advises the user + and goes to the CLOSED state. \ No newline at end of file