TCP协议选项

原文转自:http://blog.chinaunix.net/uid-20249205-id-1713871.html

Kind   Meaning                               Reference
----   -------------------------------   ---------
  0       End of Option List                 [RFC793]
  1       No-Operation                       [RFC793]
  2       Maximum Segment Size               [RFC793]
  3       WSOPT - Window Scale              [RFC1323]
  4       SACK Permitted                    [RFC2018]
  5       SACK                              [RFC2018]
  6       Echo (obsoleted by option 8)      [RFC1072]
  7       Echo Reply (obsoleted by option 8)[RFC1072]
  8       TSOPT - Time Stamp Option         [RFC1323]
  9       Partial Order Connection Permitted[RFC1693]
 10       Partial Order Service Profile     [RFC1693]
 11       CC                                [RFC1644]
 12       CC.NEW                            [RFC1644]
 13       CC.ECHO                           [RFC1644]
 14       TCP Alternate Checksum Request    [RFC1146]
 15       TCP Alternate Checksum Data       [RFC1146]
 16       Skeeter                           [Knowles]
 17       Bubba                             [Knowles]
 18       Trailer Checksum Option    [Subbu & Monroe]
 19       MD5 Signature Option              [RFC2385]
 20       SCPS Capabilities                   [Scott]
 21       Selective Negative Acknowledgements [Scott]
 22       Record Boundaries                   [Scott]
 23       Corruption experienced              [Scott]
 24       SNAP                             [Sukonnik]
 25       Unassigned (released 12/18/00)
 26       TCP Compression Filter           [Bellovin]

TCP选项(RFC793和更新的RFC1323)
– 这里充满了各种组合的可能性
– 应答方式“Query-Reply”,可以把多个选项
放到一个包中
– 有些高级选项在新的协议栈实现中加入

TCP选项
  每个选项的开始是1字节的kind字段,说明选项的类型。

Kind=0:选项表结束(1字节)

Kind=1:无操作(1字节)

Kind=2:最大报文段长度(4字节)   

Kind=3:窗口扩大因子(4字节)   

Kind=8:时间戳(10字节)

3、窗口扩大选项:
  窗口扩大选项使TCP的窗口定义从16位增加到32位,这并不是通过修改TCP首部来实现的,TCP首部仍然使用16位,而是通过定义一个选项实现对16位的扩大操作来完成的。

4、时间戳选项:
  时间戳选项使发送方在每个报文段中放置一个时间戳值。接收方在确认中返回这个数值,从而允许发送方为每一个收到的ACK计算RTT。

rfc793

Options:  variable

Options may occupy space at the end of the TCP header and are a multiple of 8 bits in length.  All options are included in the checksum.  An option may begin on any octet boundary.  There are two cases for the format of an option:

Case 1:  A single octet of option-kind.

Case 2:  An octet of option-kind, an octet of option-length, and
               the actual option-data octets.

The option-length counts the two octets of option-kind and option-length as well as the option-data octets.

Note that the list of options may be shorter than the data offset field might imply.  The content of the header beyond the End-of-Option option must be header padding (i.e., zero).

A TCP must implement all options.

Currently defined options include (kind indicated in octal):

Kind     Length    Meaning
      ----     ------    -------
       0         -       End of option list.
       1         -       No-Operation.
       2         4       Maximum Segment Size.

Specific Option Definitions

End of Option List

+--------+
        |00000000|
        +--------+
         Kind=0

This option code indicates the end of the option list.  This might not coincide with the end of the TCP header according to the Data Offset field.  This is used at the end of all options, not the end of each option, and need only be used if the end of the options would not otherwise coincide with the end of the TCP header.

No-Operation

+--------+
        |00000001|
        +--------+
         Kind=1

This option code may be used between options, for example, to align the beginning of a subsequent option on a word boundary. There is no guarantee that senders will use this option, so receivers must be prepared to process options even if they do not begin on a word boundary.

Maximum Segment Size 即MSS选项

+--------+--------+---------+--------+
        |00000010|00000100|   max seg size   |
        +--------+--------+---------+--------+
         Kind=2   Length=4
Maximum Segment Size Option Data:  16 bits

If this option is present, then it communicates the maximum receive segment size at the TCP which sends this segment. This field must only be sent in the initial connection request(i.e., in segments with the SYN control bit set).  If this option is not used, any segment size is allowed.

Padding:  variable

The TCP header padding is used to ensure that the TCP header ends and data begins on a 32 bit boundary.  The padding is composed of zeros.

rfc1323

1.3 Using TCP options

The extensions defined in this memo all use new TCP options.  We
      must address two possible issues concerning the use of TCP
      options: (1) compatibility and (2) overhead.

We must pay careful attention to compatibility, i.e., to
      interoperation with existing implementations.  The only TCP option
      defined previously, MSS, may appear only on a SYN segment.  Every
      implementation should (and we expect that most will) ignore
      unknown options on SYN segments.  However, some buggy TCP
      implementation might be crashed by the first appearance of an
      option on a non-SYN segment.  Therefore, for each of the
      extensions defined below, TCP options will be sent on non-SYN
      segments only when an exchange of options on the SYN segments has
      indicated that both sides understand the extension.  Furthermore,
      an extension option will be sent in a segment only if
      the corresponding option was received in the initial
      segment.

A question may be raised about the bandwidth and processing
      overhead for TCP options.  Those options that occur on SYN
      segments are not likely to cause a performance concern.  Opening a
      TCP connection requires execution of significant special-case
      code, and the processing of options is unlikely to increase that
      cost significantly.

On the other hand, a Timestamps option may appear in any data or
      ACK segment, adding 12 bytes to the 20-byte TCP header.  We believe that the bandwidth saved by reducing unnecessary
      retransmissions will more than pay for the extra header bandwidth.

There is also an issue about the processing overhead for parsing
      the variable byte-aligned format of options, particularly with a
      RISC-architecture CPU.  To meet this concern, Appendix A contains
      a recommended layout of the options in TCP headers to achieve
      reasonable data field alignment.  In the spirit of Header
      Prediction, a TCP can quickly test for this layout and if it is
      verified then use a fast path.  Hosts that use this canonical
      layout will effectively use the options as a set of fixed-format
      fields appended to the TCP header.  However, to retain the
      philosophical and protocol framework of TCP options, a TCP must be
      prepared to parse an arbitrary options field, albeit with less
      efficiency.

Finally, we observe that most of the mechanisms defined in this
      memo are important for LFN‘s and/or very high-speed networks.  For
      low-speed networks, it might be a performance optimization to NOT
      use these mechanisms.  A TCP vendor concerned about optimal
      performance over low-speed paths might consider turning these
      extensions off for low-speed paths, or allow a user or
      installation manager to disable them.

2. TCP WINDOW SCALE OPTION

TCP Window Scale Option (WSopt):

Kind: 3 Length: 3 bytes

+---------+---------+---------+
                | Kind=3  |Length=3 |shift.cnt|
                +---------+---------+---------+

This option is an offer, not a promise; both sides must send
         Window Scale options in their SYN segments to enable window
         scaling in either direction.  If window scaling is enabled,
         then the TCP that sent this option will right-shift its true
         receive-window values by ‘shift.cnt‘ bits for transmission in
         SEG.WND.  The value ‘shift.cnt‘ may be zero (offering to scale,
         while applying a scale factor of 1 to the receive window).

This option may be sent in an initial segment (i.e., a
         segment with the SYN bit on and the ACK bit off).  It may also
         be sent in a segment, but only if a Window Scale op-
         tion was received in the initial segment.  A Window Scale
         option in a segment without a SYN bit should be ignored.

The Window field in a SYN (i.e., a or ) segment
         itself is never scaled.

3.2  TCP Timestamps Option
 TCP Timestamps Option (TSopt):

Kind: 8

Length: 10 bytes

+-------+-------+---------------------+---------------------+
          |Kind=8 |  10   |   TS Value (TSval)  |TS Echo Reply (TSecr)|
          +-------+-------+---------------------+---------------------+
              1       1              4                     4

The Timestamps option carries two four-byte timestamp fields.
         The Timestamp Value field (TSval) contains the current value of
         the timestamp clock of the TCP sending the option.

The Timestamp Echo Reply field (TSecr) is only valid if the ACK
         bit is set in the TCP header; if it is valid, it echos a times-
         tamp value that was sent by the remote TCP in the TSval field
         of a Timestamps option.  When TSecr is not valid, its value
         must be zero.  The TSecr value will generally be from the most
         recent Timestamp option that was received; however, there are
         exceptions that are explained below.

A TCP may send the Timestamps option (TSopt) in an initial
         segment (i.e., segment containing a SYN bit and no ACK
         bit), and may send a TSopt in other segments only if it re-
         ceived a TSopt in the initial segment for the connection.

时间: 2024-10-02 11:18:10

TCP协议选项的相关文章

TCP协议中的SO_LINGER选项

TCP协议中的SO_LINGER选项 SO_LINGER选项用来设置延迟关闭的时间,等待套接字发送缓冲区中的数据发送完成.没有设置该选项时,在调用close()后,在发送完FIN后会立即进行一些清理工作并返回.如果设置了SO_LINGER选项,并且等待时间为正值,则在清理之前会等待一段时间. 以调用close()主动关闭为例,在发送完FIN包后,会进入FIN_WAIT_1状态.如果没有延迟关闭(即设置SO_LINGER选项),在调用tcp_send_fin()发送FIN后会立即调用sock_or

tcp协议分析

tcp协议解析 TCP在网络OSI的七层模型中的第四层--Transport层,IP在第三层--Network层,ARP在第二层--Data Link层.在第二层上的数据,我们叫Frame,在第三层上的数据叫Packet,第四层的数据叫Segment. 我们程序的数据首先会打到TCP的Segment中,然后TCP的Segment会打到IP的Packet中,然后再打到以太网Ethernet的Frame中,传到对端后,各个层解析自己的协议,然后把数据交给更高层的协议处理 TCP头格式 TCP数据段格

时间获取程序服务器 TCP 协议相关性

本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 最初代码: 这是一个简单的时间获取服务器程序.它和时间获取程序客户端一道工作. TCP/IPv4, IPv6 协议相关 IPv4 --> IPv6 (把代码中出现的左边的字符串换为右边的,就变成了IPv6版本的) sockaddr_in --> sockaddr_in6 AF_INET --> AF_INET6 sin_family --> sin6_family sin_p

TCP协议

TCP(Transmission Control Protocol )传输控制协议,是目前传输层应用最广泛的协议,当然这跟它的特性息息相关. 一.它的主要特性有: 1.可靠,面向连接 2.工作在传输层面向连接协议 3.全双工协议 4.半关闭(单方关闭) 5.错误检查 每个数据包有编号,对方收到之后,会告诉发送方收到了,回给对方说我下次希望收到第n+1个包,假如发送了三个包,但是接受方只收到了两个,会说下次希望收到第三个包,那么就实现了错误检查和重传 6.将数据打包成段,排序 即标记序列号,有时候

TCP协议疑难杂症全景解析

说明: 1).本文以TCP的发展历程解析容易引起混淆,误会的方方面面2).本文不会贴大量的源码,大多数是以文字形式描述,我相信文字看起来是要比代码更轻松的3).针对对象:对TCP已经有了全面了解的人.因为本文不会解析TCP头里面的每一个字段或者3次握手的细节,也不会解释慢启动和快速重传的定义4).除了<TCP/IP详解>(卷一,卷二)以及<Unix网络编程>以及Linux源代码之外,学习网络更好的资源是RFC 5).本文给出一个提纲,如果想了解细节,请直接查阅RFC 6).翻来覆去

TCP协议要点和难点全解

说明: 1).本文以TCP的发展历程解析容易引起混淆,误会的方方面面 2).本文不会贴大量的源码,大多数是以文字形式描述,我相信文字看起来是要比代码更轻松的 3).针对对象:对TCP已经有了全面了解的人.因为本文不会解析TCP头里面的每一个字段或者3次握手的细节,也不会解释慢启动和快速重传的定义 4).除了<TCP/IP详解>(卷一,卷二)以及<Unix网络编程>以及Linux源代码之外,学习网络更好的资源是RFC 5).本文给出一个提纲,如果想了解细节,请直接查阅RFC 6).翻

setsockopt 设置TCP的选项SO_LINGER

SO_LINGER选项用来设置延迟关闭的时间,等待套接字发送缓冲区中的数据发送完成. 没有设置该选项时,在调用close()后,在发送完FIN后会立即进行一些清理工作并返回.如果设置了SO_LINGER选项,并且等待时间为正值,则在清理之前会等待一段时间. 以调用close()主动关闭为例,在发送完FIN包后,会进入FIN_WAIT_1状态.如果没有延迟关闭(即设置SO_LINGER选项),在调用tcp_send_fin()发送FIN后会立即调用sock_orphan()将sock结构从进程上下

TCP协议及TCP正常连接与断开

一.TCP协议简介TCP,全称Transfer Control Protocol,中文名为传输控制协议,它工作在OSI的传输层,提供面向连接的可靠传输服务.TCP的工作主要是建立连接,然后从应用层程序中接收数据并进行传输.TCP采用虚电路连接方式进行工作,在发送数据前它需要在发送方和接收方建立一个连接,数据在发送出去后,发送方会等待接收方给出一个确认性的应答,否则发送方将认为此数据丢失,并重新发送此数据.下面我们来介绍一下TCP的报头结构和相关工作原理:1.TCP报头TCP报头总长最小为20个字

tcp协议头窗口,滑动窗口,流控制,拥塞控制关系

参考文章 TCP 的那些事儿(下) http://coolshell.cn/articles/11609.html tcp/ip详解--拥塞控制 & 慢启动 快恢复 拥塞避免 http://blog.csdn.net/kinger0/article/details/48206999 TCP window Full http://blog.csdn.net/abccheng/article/details/50503457 名词解释 MTU:maximum transmission unit,最大