5.23 Ethereal抓包时发现TCP校验和错误 https://scz.617.cn/network/200512281045.txt Q: 在Windows平台上用Ethereal抓包时发现TCP校验和错误,但应用层的反应告诉我,这 个报文的TCP校验和没问题。 A: 2000-03 网卡配置->高级->Rx Checksum Offload/Tx Checksum Offload,很可能你的这两处 设置是Enable,将之调整成Disable即可,代价是网络性能降低。 一般由操作系统的TCP/IP协议栈完成TCP/UDP/IP校验和的计算工作,这两处设置成 Enable之后,协议栈不再进行校验和的计算,而是由网卡自己完成。如果在前述位置 没有发现Rx Checksum Offload/Tx Checksum Offload项,有两种可能,一种是网卡 本身不支持这种功能,另一种是网卡驱动未提供配置项,后一种情形居多。 事实上该问题与使用何种Sniffer软件无关。 D: scz@nsfocus 2009-05-19 15:26 某些网卡驱动未在GUI界面上提供配置项,此时需要直接编辑注册表、重启OS使之生 效。下面试举两例: > ipconfig /all | findstr Description Description . . . . . . . . . . . : 3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible) 去如下位置搜索"3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible)": HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\ DriverDesc REG_SZ "3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible)" NetworkAddress REG_SZ 000000111111 RxChecksum REG_SZ DISABLE(与之相对的是ENABLE) TxChecksum REG_SZ DISABLE(与之相对的是ENABLE) > ipconfig /all | findstr Description Description . . . . . . . . . . . : Broadcom NetXtreme 57xx Gigabit Controller 去如下位置搜索"Broadcom NetXtreme 57xx Gigabit Controller": HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\ DriverDesc REG_SZ "Broadcom NetXtreme 57xx Gigabit Controller" NetworkAddress REG_SZ 000000111112 TaskOffloadCap REG_SZ "0"(我这里原来是"21") D: Cain 有个全局开关: netsh int ip set global taskoffload=disable 执行完上述命令之后,禁用、重新启用网卡,使之生效,不必重启OS。 D: robinh00d@nsfocus 2012-05-21 看到这么一段内容: -------------------------------------------------------------------------- 很早以前(至少12年前),一般由操作系统的TCP/IP协议栈完成TCP/UDP/IP校验和的计 算工作。后来,很多网卡可以完成这项工作,TCP/IP协议栈不再需要计算校验和,而 是由网卡自己完成,这样会提高系统整体性能。操作系统以及网卡驱动一般会有相应 的配置项,以控制是否启用这项功能。现在都是默认启用的。如果在一台启用了该功 能的主机上抓包,NDIS Protocol Driver捕获由本机发出去的报文时,相应报文尚未 经网卡处理并设置正确的TCP/UDP/IP校验和,报文中对应字段的数据是内存残像,没 有任何意义;Wireshark检查到校验和不正确,会报告出来。 该问题与使用何种Sniffer软件无关。 可以尝试在网卡属性的高级配置页里找TaskOffload功能相关的配置项,其名称各不 相同,需要具体识别。很多网卡驱动未在GUI界面上提供配置项,此时需要直接编辑 注册表,键值名称各不相同,甚至缺省情况下键值不存在。 -------------------------------------------------------------------------- 查阅WDK文档: -------------------------------------------------------------------------- WDK文档 Device and Driver Technologies Network Devices Network Drivers Prior to Windows Vista Design Guide NDIS Miniport Drivers (NDIS 5.1) Task Offload (NDIS 5.1) Offloading Checksum Tasks (NDIS 5.1) Using Registry Values to Enable and Disable Task Offloading (NDIS 5.1) -------------------------------------------------------------------------- WDK文档 Device and Driver Technologies Network Devices Network Drivers for Windows Vista and Later Design Guide Scalable Networking TCP/IP Offload Task Offload Using Registry Values to Enable and Disable Task Offloading Offloading Checksum Tasks -------------------------------------------------------------------------- 两处"Offloading Checksum Tasks"中有同一段内容: -------------------------------------------------------------------------- Before offloading the checksum calculation for a TCP packet, the TCP/IP transport calculates the one's complement sum for the TCP pseudoheader. The TCP/IP transport calculates the one's complement sum across all fields in the pseudoheader, including Source IP Address, Destination IP Address, Protocol, and the TCP length for TCP packets. The TCP/IP transport enters the one's complement sum for the pseudoheader in the Checksum field of the TCP header. The one's complement sum for the pseudoheader provided by the TCP/IP transport gives the NIC an early start in calculating the real TCP checksum for the send packet. To calculate the actual TCP checksum, the NIC calculates the variable part of the TCP checksum (for the TCP header and payload), adds this checksum to the one's complement sum for the pseudoheader calculated by the TCP/IP transport, and calculates the 16-bit one's complement for the checksum. For more information about calculating such checksums, see RFC 793 and RFC 1122. Note that the TCP/IP transport always ensures that the checksum field in the IP header of a packet is set to zero before passing the packet to an underlying miniport driver. The miniport driver should ignore the checksum field in an IP header. The miniport driver does not need to verify that the checksum field is set to zero and does not need to set this field to zero. -------------------------------------------------------------------------- 从上述内容得知,Transport会先计算TCP伪首部的校验和,网卡会计算剩下部分的校 验和,然后结合二者计算出完整的th_sum并填写到报文中去。 网上部分文章认为开启TaskOffload功能后Transport填充的th_sum是内存残像,这其 实是不对的。开启"Offloading Checksum Tasks"之后,th_sum的计算工作并不是完 全交给网卡来做,Transport还是要承担部分计算工作。某些特定情况下可以利用这 点检查CAP文件是否被动过。 netsh int ip set global taskoffload=disable 这条命令实际设置的注册表项如下: -------------------------------------------------------------------------- Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters] "DisableTaskOffload"=dword:00000001 -------------------------------------------------------------------------- Setting this value to 1 disables all task offloads from the TCP/IP transport. Setting this value to zero enables all task offloads. -------------------------------------------------------------------------- D: scz@nsfocus 2012-05-21 在WDK的"Using Registry Values to Enable and Disable Task Offloading"里提到 好几个注册表项: *IPChecksumOffloadIPv4 *TCPChecksumOffloadIPv4 *UDPChecksumOffloadIPv4 *TCPUDPChecksumOffloadIPv4 *TCPChecksumOffloadIPv6 *UDPChecksumOffloadIPv6 *TCPUDPChecksumOffloadIPv6 注意,键值名称首字符是*号。 首先去如下位置定位网卡: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\ 这个可以靠IPAddress定位,比如我这里: -------------------------------------------------------------------------- Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\{C378CE35-E934-4FCA-99E8-73DE20DD5C1B}] "IPAddress"=hex(7):31,00,39,00,32,00,2e,00,31,00,36,00,38,00,2e,00,37,00,2e,00,\ 32,00,00,00,00,00 -------------------------------------------------------------------------- 然后去如下位置搜索网卡: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\ 在这里搜索"{C378CE35-E934-4FCA-99E8-73DE20DD5C1B}": -------------------------------------------------------------------------- Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007] "NetCfgInstanceId"="{C378CE35-E934-4FCA-99E8-73DE20DD5C1B}" "*TCPChecksumOffloadIPv4"="3" "*TCPChecksumOffloadIPv6"="3" "*UDPChecksumOffloadIPv4"="3" "*UDPChecksumOffloadIPv6"="3" "*IPChecksumOffloadIPv4"="3" "DriverDesc"="Intel(R) 82579LM Gigabit Network Connection" "NetworkAddress"="000000111111" -------------------------------------------------------------------------- 也可以直接用DriverDesc的值来搜索定位这个地方: > ipconfig /all | findstr Description Description . . . . . . . . . . . : Intel(R) 82579LM Gigabit Network Connection Description . . . . . . . . . . . : Microsoft ISATAP Adapter Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface 这个地方里有很多可修改的值,比如NetworkAddress。 所有关于"Offloading Checksum Tasks"的键值都是REG_SZ类型,取值如下: -------------------------------------------------------------------------- 0 Disabled 1 Tx Enabled 2 Rx Enabled 3(Default) Tx & Rx Enabled -------------------------------------------------------------------------- 看上去,从Vista开始,开启"Offloading Checksum Tasks"的注册表键值名称被统一 了,这是好消息。不过并不是所有的网卡驱动会在GUI界面上提供配置项,我这里就 没有,只能regedit。