-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCP_Notes.txt
94 lines (82 loc) · 5.21 KB
/
TCP_Notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Transport Control Protocol Notes
History:
--------
Original: RFC 793
Obsoleted Addenda: RFC 879, 2873, 6093, 6429, 6528, 6691
Current: RFC 9293
IPv4:
-----
TCP Datagram Structure:
-----------------------
When the payload of an IP packet is a TCP segment (informally called a 'packet'), its contents are structured as a
packet with its own header structure.
| IP Header | TCP Segment |
_____________/\____
/ \
| TCP Header | Data |
___/\_________________________________________________________
/ \
| Source Port (16b) | Dest Port (16b) |
| Sequence Number (32b) |
| Acknowledgement Number (32b) |
| Data Offset (4b) | Reserved (4b) | Flags (8b) | Window (16b) |
| Checksum (16b) | Urgent Pointer (16b) |
| Options (optional 32b to 288b) |
Where | Flags (8b) | = | CWR | ECE | URG | ACK | PSH | RST | SYN | FIN |
Field Descriptions:
-------------------
Source Port: Socket port number for source
Dest Port: Socket port number for dest
Sequence Number: If the SYN flag is set, this is the initial sequence number. The sequence number of the
actual first data byte and the acknowledged number in the corresponding ACK are this
sequence number + 1.
If the SYN flag is cleared, this is the accumulated sequence number of the first data byte
of this segment for the current session.
Acknowledgement Number: If the ACK flag is set, this is the next sequence number that the sender of the ACK
is expecting and acknowledges receipt of all prior bytes (if any). The first ACK sent by
each end acknowledges the other end's initial sequence number itself, but no data.
Data Offset: Specifies the size of the TCP header in 32-bit words. Min 5 words, max 15 words.
If "Data Offset" is 5, there is no Options section. Otherwise, the Options section is
32*(Data Offset - 5) bits = 4*(Data Offset - 5) bytes long.
Flags:
CWR: Congestion window reduced. Set by the sending host to indicate it received a TCP segment with the
ECE flag set and responded in congestion control mechanism.
ECE: ECN-Echo. If SYN flag is set, the TCP peer is ECN capable. If SYN flag is cleared, a packet was
received with its ECN flag set (in IP header) during normal transmission. In this case, it serves
as an indication of network congestion (or impending congestion) to the TCP sender.
URG: If set, the Urgent Pointer field is valid. Otherwise, the Urgent Pointer field is invalid.
ACK: If set, the Acknowledgement Number field is valid. Otherwise, the Acknowledgement Number field is invalid.
PSH: Push function. Asks to push the buffered data to the receiving application.
RST: Reset the connection.
SYN: Synchronize sequence numbers. Only the first packet sent from each end should have this flag set.
See also ECE flag and Sequence Number field.
FIN: Last packet from sender.
Window: Specifies the number of "window size units" that the sender of this segment is currently willing to receive.
(See "Window Scaling")
Checksum: A 16-bit checksum of the TCP header, the payload, and an IP pseudo-header including the source and dest
IP addresses, the protocol number (TCP=6), and the length of the TCP header+payload.
Options:
--------
The optional "Options" field in the TCP header is a concatenated list of various options, each with the following
format:
| Option-Kind (8b) | Option-Length (0b/8b) | Option-Data (variable) |
Option-Kind determines the meaning of the bytes that follow.
Option-Length specifies the length in bytes of the entire entry (including itself and the "Option-Kind" field).
Thus, the size of the Option-Data field is Option-Length-2.
Option-Kind Option-Length Option-Data Meaning
-----------------------------------------------
0 N/A N/A End of options list
1 N/A N/A No operation (used to align options field to 32-bit boundary)
2 4 SS Maximum segment size (2-bytes, since
3 3 S Window scale (See "Window Scaling")
4 2 N/A Selective Acknowledgement permitted
5 (10,18,26,34) BBBB,EEEE... Selective ACK of a block between 32-bit pointers (BBBB, EEEE)
Can selectively ACK up to 4 blocks.
8 10 TTTT,EEEE Timestamp and echo of previous timestamp
28 4 (empty?) User Timeout Option. See RFC 5482
29 N (?) TCP Authentication Option. See RFC 5925
30 N (?) Multipath TCP (MPTCP).
ECN = Explicit Congestion Notification. See IPv4_Notes.txt
Window Scaling:
---------------
TODO