推荐阅读:
1、EVE-NG 2TB全网最新最全镜像下载地址(保持更新):
https://www.emulatedlab.com/thread-939-1-1.html2、EVE-NG 2025全网最新最全资源大全(保持更新):
https://www.emulatedlab.com/thread-2262-1-1.html3、EVE-NG 国代答疑频道(免费公开访问):
https://pd.qq.com/s/8d1hglslz1 纯BPF过滤表达式分析MSTP常见网络故障
1.1一、MSTP帧结构参考(BPF偏移计算)
1.1.1基础帧格式(从以太网头部开始):
0-5: 目的MAC (01:80:C2:00:00:00) 6-11: 源MAC 12-13: 长度/类型字段 14-15: LLC DSAP/SSAP (0x42/0x42) 16: LLC控制字段 (0x03) 17-18: 协议标识符 (0x0000) 19: 协议版本 (MSTP=0x03) 20: BPDU类型 (MSTP=0x02) 21: CIST标志位 22-29: CIST根桥ID 30-33: CIST外部路径开销 34-41: CIST指定桥ID 42-43: CIST指定端口ID 44-45: 消息年龄 46-47: 最大年龄 48-49: Hello时间 50-51: 转发延迟 52-53: 版本1长度 (MSTP=0x00) 54-55: 版本3长度 56-...: MST配置标识符和MSTI信息1.1.2MSTP关键字段结构:
56-71: 配置名称 (16字节) 72-75: 修订级别 (4字节) 76-91: 配置摘要 (16字节) 92-93: CIST内部根路径开销 94-101: CIST桥ID 102-103: CIST剩余跳数 104-...: MSTI配置信息1.2二、基础MSTP捕获表达式
# 1. 捕获所有MSTP帧 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 # 2. 精确捕获MSTP BPDU ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[20] == 0x02 # 3. 捕获CIST(公共内部生成树)BPDU ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[20] == 0x02 and ether[52:2] == 0x0000 # 4. 捕获MSTI(MST实例)信息 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[54:2] > 0x0000 # 5. 排除RSTP,只捕获MSTP ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and not ether[19] == 0x021.3三、MSTP协议版本和长度检查
# 1. 检查MSTP版本 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 # 2. 检查版本1长度(应为0) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[52:2] != 0x0000 # 3. 检查版本3长度(MSTP信息长度) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[54:2] == 0x0000 # 4. 检查BPDU类型(应为2) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[20] != 0x021.4四、CIST(公共实例)标志位分析(字节21)
1.4.1CIST标志位定义:
- Bit 0 (0x01): TC(拓扑变更)
- Bit 1 (0x02): 提议(Proposal)
- Bit 2-3 (0x0C): 端口角色(00=未知,01=备选,10=根,11=指定)
- Bit 4 (0x10): 学习(Learning)
- Bit 5 (0x20): 转发(Forwarding)
- Bit 6 (0x40): 协议(0=STP,1=RSTP/MSTP)
- Bit 7 (0x80): TC确认(TCA)
# 1. CIST端口角色检查 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x0C) == 0x08 # 根端口 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x0C) == 0x0C # 指定端口 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x0C) == 0x04 # 备选端口 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x0C) == 0x00 # 未知 # 2. CIST端口状态检查 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x30) == 0x00 # 阻塞 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x30) == 0x10 # 学习 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x30) == 0x30 # 转发 # 3. CIST拓扑变更标志 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x01) == 0x01 # TC ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x02) == 0x02 # 提议 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x80) == 0x80 # TCA1.5五、MST配置标识符检查(区域一致性检查)
# 1. 检查配置名称长度(16字节) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[56:16] == 0x00000000000000000000000000000000 # 2. 检查修订级别(4字节) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[72:4] == 0x00000000 # 3. 检查配置摘要(16字节) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[76:16] == 0x00000000000000000000000000000000 # 4. 捕获配置标识符为空的MSTP帧(可能配置错误) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[56:4] == 0x000000001.6六、CIST内部路径和桥ID检查
# 1. CIST内部根路径开销(字节92-93) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[92:2] == 0x0000 # 2. CIST桥ID(字节94-101) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[94:8] == 0x0000000000000000 # 3. CIST剩余跳数(字节102-103) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[102:2] > 0x0014 # 4. 检查CIST根桥ID与指定桥ID关系 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[22:8] == ether[34:8] # 5. 检查CIST外部根路径开销(字节30-33) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[30:4] == 0x000000001.7七、MST实例(MSTI)信息检查
1.7.1MSTI记录结构(从偏移104开始):
字节0-1: MSTI标志位 字节2-3: MSTI根路径开销 字节4-11: MSTI桥ID 字节12-13: MSTI端口优先级 字节14-15: MSTI剩余跳数# 1. 检查MSTI标志位(实例0-15) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[104:2] != 0x0000 # 2. 检查MSTI根路径开销 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[106:2] == 0x0000 # 3. 检查MSTI桥ID ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[108:8] == 0x0000000000000000 # 4. 检查MSTI端口优先级 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[116:2] == 0x0000 # 5. 检查MSTI剩余跳数 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[118:2] == 0x00001.8八、常见MSTP故障分析表达式
1.8.1故障1: MST区域不匹配
# 配置名称不匹配(检查前4字节) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[56:4] != 预期配置名称 # 修订级别不匹配 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[72:4] != 预期修订级别 # 配置摘要不匹配(检查前4字节) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[76:4] != 预期摘要1.8.2故障2: CIST根桥不一致
# 多个不同的CIST根桥ID ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[22:8] != 预期根桥ID # CIST根桥ID为0(未配置) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[22:8] == 0x0000000000000000 # CIST指定桥ID与根桥ID相同但非根桥 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[22:8] == ether[34:8] and ether[30:4] != 0x000000001.8.3故障3: 路径开销异常
# CIST外部路径开销异常 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[30:4] > 0x000186a0 # >100000 # CIST内部根路径开销异常 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[92:2] > 0x0fff # MSTI根路径开销异常 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[106:2] > 0x0fff1.8.4故障4: 跳数限制问题
# CIST剩余跳数为0(可能超出区域) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[102:2] == 0x0000 # CIST剩余跳数过大 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[102:2] > 0x0020 # MSTI剩余跳数为0 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[118:2] == 0x00001.8.5故障5: 版本不一致
# 版本1长度非0(应为0) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[52:2] != 0x0000 # 版本3长度为0(无MSTP信息) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[54:2] == 0x0000 # 协议版本不是3 ether dst 01:80:c2:00:00:00 and ether[19] != 0x031.8.6故障6: MST实例配置错误
# MSTI标志位异常 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[104:2] & 0xf000) != 0x0000 # MSTI桥ID为0 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[108:8] == 0x0000000000000000 # MSTI端口优先级为0 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[116:2] == 0x00001.9九、MSTP与RSTP互操作问题
# 1. 混合环境检测 ether dst 01:80:c2:00:00:00 and (ether[19] == 0x02 or ether[19] == 0x03) # 2. RSTP设备发送的BPDU(版本2) ether dst 01:80:c2:00:00:00 and ether[19] == 0x02 and ether[20] == 0x02 # 3. MSTP设备发送的BPDU(版本3) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[20] == 0x02 # 4. 检测版本冲突(RSTP标志位但MSTP版本) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[52:2] != 0x00001.10十、计时器和拓扑变更问题
# 1. 计时器检查 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[48:2] == 0x0000 # Hello时间为0 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[44:2] > ether[46:2] # 消息年龄超时 # 2. 拓扑变更风暴检测 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x01) == 0x01 # 3. 提议机制问题 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x02) == 0x02 and (ether[21] & 0x30) == 0x00 # 4. 端口状态异常 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x30) == 0x20 # 仅转发无学习1.11十一、组合故障诊断表达式
1.11.1综合MSTP健康检查:
ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ( # 基本协议错误 ether[20] != 0x02 or ether[52:2] != 0x0000 or ether[54:2] == 0x0000 or # 配置标识符问题 ether[56:4] == 0x00000000 or ether[72:4] == 0x00000000 or # 计时器问题 ether[48:2] == 0x0000 or ether[44:2] > ether[46:2] or # CIST问题 ether[22:8] == 0x0000000000000000 or ether[92:2] == 0x0000 or ether[102:2] == 0x0000 or # 端口状态问题 (ether[21] & 0x0C) == 0x00 or (ether[21] & 0x30) == 0x20 or # MSTI问题 (ether[104:2] & 0xf000) != 0x0000 )1.11.2区域不匹配检测:
ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ( # 配置名称前8字节为0 ether[56:8] == 0x0000000000000000 or # 修订级别为0 ether[72:4] == 0x00000000 or # 配置摘要前8字节为0 ether[76:8] == 0x0000000000000000 )1.11.3CIST故障检测:
ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ( # CIST根桥ID异常 ether[22:8] == 0x0000000000000000 or # CIST外部路径开销异常 ether[30:4] > 0x000f4240 or # CIST内部根路径开销异常 ether[92:2] > 0x0fff or # CIST剩余跳数问题 ether[102:2] == 0x0000 or ether[102:2] > 0x0020 )1.11.4MSTI故障检测:
ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ( # MSTI标志位异常(检查高位) (ether[104:2] & 0xf000) != 0x0000 or # MSTI根路径开销为0 ether[106:2] == 0x0000 or # MSTI桥ID为0 ether[108:8] == 0x0000000000000000 or # MSTI端口优先级为0 ether[116:2] == 0x0000 or # MSTI剩余跳数为0 ether[118:2] == 0x0000 )1.11.5严重故障过滤器:
# 可能导致环路的严重故障 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ( # BPDU过期但端口仍在转发 ether[44:2] >= ether[46:2] and (ether[21] & 0x20) == 0x20 or # CIST根桥ID冲突 ether[22:8] != ether[34:8] and ether[30:4] == 0x00000000 and (ether[21] & 0x0C) == 0x0C or # 区域配置完全为空 ether[56:16] == 0x00000000000000000000000000000000 and ether[72:4] == 0x00000000 and ether[76:16] == 0x00000000000000000000000000000000 )1.12十二、MSTP安全特性检查
1.12.1BPDU保护:
# 检测边缘端口是否收到MSTP BPDU ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and not ether[6:3] = 交换机OUI1.12.2根保护:
# 检测是否收到更优的CIST BPDU ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[22:2] < 当前CIST根桥优先级1.12.3环路保护:
# 检测根端口是否停止接收BPDU(需要时间序列分析) ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x0C) == 0x08 and ether[44:2] > 0x000a1.13十三、BPF表达式优化和组合
1.13.1高效过滤组合:
# 1. 基本MSTP捕获优化 ether[0:6] = 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[20] == 0x02 # 2. 检查关键字段组合 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x40) == 0x40 # 3. 使用掩码检查多个条件 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and (ether[21] & 0x3F) == 0x3F # 4. 排除非MSTP流量 ether dst 01:80:c2:00:00:00 and not ether[19] == 0x00 and not ether[19] == 0x02 # 5. 区域配置完整性检查 ether dst 01:80:c2:00:00:00 and ether[19] == 0x03 and ether[54:2] > 0x00401.14十四、常见故障场景与BPF表达式
| 故障现象 | BPF表达式 | 可能原因 |
|---|---|---|
| MST区域不匹配 | ether[56:4]==0x00000000 | 配置名称为空 |
| CIST根桥冲突 | ether[22:8]!=预期根桥ID | 多个区域根桥 |
| 路径计算错误 | ether[92:2]==0x0000 | 内部路径开销为0 |
| 跳数超出限制 | ether[102:2]==0x0000 | 超出最大跳数 |
| 实例配置错误 | ether[108:8]==0x0000000000000000 | MSTI桥ID为空 |
| 协议版本错误 | ether[19]!=0x03 | 运行RSTP而非MSTP |
1.15十五、BPF表达式使用注意事项
- 偏移量验证:不同厂商实现可能有细微差异,需验证偏移量
- 字节序:BPF使用网络字节序(大端序)
- 长度限制:BPF表达式有长度限制,复杂表达式可能需拆分
- 性能影响:复杂BPF表达式可能影响捕获性能
- 准确性:部分高级检查需结合上层协议分析
1.16总结
纯BPF表达式分析MSTP故障的关键点:
- 协议识别:版本=0x03,类型=0x02,版本1长度=0x0000
- 区域一致性:配置名称、修订级别、配置摘要必须一致
- CIST检查:根桥ID、路径开销、剩余跳数
- MSTI验证:实例标志、桥ID、路径开销、端口优先级
- 安全机制:BPDU保护、根保护、环路保护状态
MSTP故障分析相比STP/RSTP更复杂,需要关注区域配置一致性、多个生成树实例状态以及CIST与MSTI的交互关系。这些BPF表达式可用于实时监控和故障捕获,帮助快速定位MSTP相关问题。