Wireshark TS | DHCP 获取地址失败问题

221 阅读4分钟

前言

一个简单的 DHCP 故障案例,该案例来自于 Wireshark sharkfest 2018 - Point And ShootPacket,其中的 Case 1 CATV Box,描述的是在宾馆里客户所使用的 CATV 盒子,有的能正常启动,有的不能正常启动。

为了故障排查,用户捕获了两个 pcap 文件,一个 DHCP_SUCCESS,一个 DHCP_FAIL 。

问题信息

数据包跟踪文件基本信息如下:

λ capinfos 1_DHCP_*.pcap
File name:           1_DHCP_FAIL.pcap
File type:           Wireshark/tcpdump/... - pcap
File encapsulation:  Ethernet
File timestamp precision:  microseconds (6)
Packet size limit:   file hdr: 65535 bytes
Number of packets:   6
File size:           2768 bytes
Data size:           2648 bytes
Capture duration:    4.421288 seconds
First packet time:   2014-01-17 10:45:26.485101
Last packet time:    2014-01-17 10:45:30.906389
Data byte rate:      598 bytes/s
Data bit rate:       4791 bits/s
Average packet size: 441.33 bytes
Average packet rate: 1 packets/s
SHA256:              b16f09cd9fa72a2ea48ba46a5fa4afbbd6ea28f0053030843eef67e64447155d
RIPEMD160:           2ac9a830a3d8f8de6307dc444090da18ec695393
SHA1:                c1e9422e185b5d2c1245810daa9851b70241221f
Strict time order:   True
Number of interfaces in file: 1
Interface #0 info:
                     Encapsulation = Ethernet (1 - ether)
                     Capture length = 65535
                     Time precision = microseconds (6)
                     Time ticks per second = 1000000
                     Number of stat entries = 0
                     Number of packets = 6

File name:           1_DHCP_SUCCESS.pcap
File type:           Wireshark/tcpdump/... - pcap
File encapsulation:  Ethernet
File timestamp precision:  microseconds (6)
Packet size limit:   file hdr: 65535 bytes
Number of packets:   8
File size:           3930 bytes
Data size:           3778 bytes
Capture duration:    29.458387 seconds
First packet time:   2014-01-17 10:33:21.418832
Last packet time:    2014-01-17 10:33:50.877219
Data byte rate:      128 bytes/s
Data bit rate:       1025 bits/s
Average packet size: 472.25 bytes
Average packet rate: 0 packets/s
SHA256:              246baf09a06cdd9e6e62d9258a97c1997dd344973cfb225de118fd03b2b22b8c
RIPEMD160:           7249ed096edeaf41089b570405e3dcd8c8c9614c
SHA1:                9dd22cb49e6c606233f9ecd1d324557d6658b478
Strict time order:   True
Number of interfaces in file: 1
Interface #0 info:
                     Encapsulation = Ethernet (1 - ether)
                     Capture length = 65535
                     Time precision = microseconds (6)
                     Time ticks per second = 1000000
                     Number of stat entries = 0
                     Number of packets = 8

其中 DHCP FAIL 文件通过 Tcpdump 捕获,无截断,数据包捕获数量仅为 6 个,捕获持续时间为 4.4 秒,平均速率 4791 bps;DHCP SUCCESS 文件同样通过 Tcpdump 捕获,无截断,数据包捕获数量 8 个,捕获持续时间为 29.4 秒,平均速率 1025 bps。另专家信息中无任何信息,总体上来说数据包跟踪文件应该都是做了相关匿名和精准过滤,仅保留了 DHCP 问题相关数据包。

问题分析

在网络协议故障分析中,有一种经常会用到的方法是对比法,通过对比正常和问题时的抓包文件,有时候会很快地发现问题所在,本案例采用的就是此方法。

首先展开 DHCP SUCCESS 数据包信息,如下:

imagepng 可以看到两次完整且成功的 DHCP 工作过程,均经过了标准的 DHCP 四个阶段:Discover - Offer - Request - ACK 。

此处可忽略客户端和服务器 IP 的小问题,服务器一会是 192.168.2.1,一会又是 192.168.2.3 ,同样又是客户端 IP 192.168.2.2,可能原因是该数据包跟踪文件匿名化处理不够完善。

同时在 Info 信息列中,标注了 Transaction ID , 什么是 Transaction ID

imagepng

在 DHCP 消息格式中,有 4 个字节的 xid 字段,描述为 Transaction ID 是一个客户端选择的随机数,客户端和服务器使用它在两者之间关联消息和响应。

RFC 2131 The client generates and records a random transaction identifier and inserts that identifier into the 'xid' field. The server inserts the 'xid' field from the DHCPDISCOVER message into the 'xid' field of the DHCPOFFER message and sends the DHCPOFFER message to the requesting client.

可见每个标准 DHCP 交互过程中都有同样一个 DHCP Transaction ID。

λ tshark -r 1_DHCP_SUCCESS.pcap -T fields -e dhcp.id | uniq
0xfb0c077c
0xe1cb5e63

imagepng

再转向 DHCP FAIL 数据包信息,如下:

imagepng 可以看到两次失败的 DHCP 交互过程,经过成功案例的分析,可以对比看到问题明显出现在 DHCP Transaction ID 上,DHCP 服务器 192.168.100.1 两次返回的 DHCP Offer 消息所携带的 Transaction ID 均和客户端所生成的不一样,这样就会造成客户端默默丢弃这些数据包,自然也就无法正常得到 IP 地址进行通讯。

If the 'xid' of an arriving DHCPOFFER message does not match the 'xid' of the most recent DHCPDISCOVER message, the DHCPOFFER message must be silently discarded. Any arriving DHCPACK messages must be silently discarded.

λ tshark -r 1_DHCP_FAIL.pcap -T fields -e frame.number -e dhcp.option.dhcp -e dhcp.id
1       1       0xea928400
2       2       0xd03e6d43
3       5       0x8044fd8d
4       1       0xea928400
5       2       0x402ddad8
6       5       0x402ddad8

问题总结

当然最终的问题原因就是 DHCP 服务器(宽带路由器)错误的行为导致,像是部分 IOT 设备使用了不完善的 DHCP 软件实现。