推荐阅读:
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/8d1hglslzPAgP (Port Aggregation Protocol),思科链路聚合的另一个“私生子”,LACP的专有前辈。
它的过滤方式,和我那些已经逝去的回答里提到的CDP、VTP一样,都是靠那个该死的组播MAC地址和它独一无二的“私生子身份证号”(PID)。
1《BPF黑魔法:最终遗嘱》—— PAgP过滤
| 协议 (Protocol) | 协议全称 | SNAP PID | 捕获过滤器语法 (Capture Filter Syntax) |
|---|---|---|---|
| PAgP | Port Aggregation Protocol | 0x0104 | ether host 01:00:0c:cc:cc:cc and ether[20:2] == 0x0104 |
你需要的是用于分析PAGP(Port Aggregation Protocol,Cisco私有链路聚合协议)常见网络故障的纯BPF过滤表达式(无工具命令,仅核心过滤逻辑),我会结合PAGP的协议特征(Cisco私有EtherType=0x0104、组播目标MAC=01:00:0c:cc:cc:cc),按典型故障场景整理表达式,适配Wireshark、libpcap等所有基于pcap的工具。
2 纯BPF过滤表达式分析PAGP常见网络故障
PAGP (Port Aggregation Protocol) 是Cisco专有的链路聚合协议。以下是使用纯BPF表达式分析PAGP常见网络故障的完整指南:
2.1一、PAGP帧结构参考(BPF偏移计算)
2.1.1以太网头部(14字节)
- 目的MAC:
01:00:0C:CC:CC:CC(Cisco组播地址) - 源MAC:发送端口MAC
- Ethertype:
0x0104(Cisco专有协议)
2.1.2PAGP数据单元结构
字节偏移(从以太网头部开始): 0-5: 目的MAC (01:00:0C:CC:CC:CC) 6-11: 源MAC 12-13: Ethertype (0x0104) 14: 版本 (通常0x01) 15: 操作码 (Opcode) 16-17: 参数 (Payload Length) 18-19: 校验和 20-...: PAGP PDU数据2.1.3PAGP PDU关键字段(常见版本)
20: 协议版本 (0x01) 21: 类型 (0x01=Hello/0x02=Query) 22: 标志位 23: 邻居计数 24-31: 系统ID 32-33: 聚合组ID (Group ID) 34-35: 端口ID 36: 端口状态 37: 邻居列表开始...2.2二、基础PAGP捕获表达式
# 1. 捕获所有PAGP帧 ether proto 0x0104 # 2. 捕获发送到Cisco组播地址的PAGP ether dst 01:00:0C:CC:CC:CC and ether[12:2] == 0x0104 # 3. 捕获特定源MAC的PAGP帧 ether[6:6] = 00:11:22:33:44:55 and ether[12:2] == 0x0104 # 4. 验证PAGP版本(通常版本1) ether[12:2] == 0x0104 and ether[14] == 0x012.3三、PAGP操作码和类型分析
2.3.1操作码(字节15)常见值:
0x01: Hello消息0x02: 查询/响应0x03: 配置更新
# 1. 捕获Hello消息 ether[12:2] == 0x0104 and ether[15] == 0x01 # 2. 捕获查询/响应消息 ether[12:2] == 0x0104 and ether[15] == 0x02 # 3. 捕获配置更新消息 ether[12:2] == 0x0104 and ether[15] == 0x03 # 4. 捕获非Hello消息(用于故障诊断) ether[12:2] == 0x0104 and ether[15] != 0x012.4四、PAGP类型字段分析(字节21)
# 1. 捕获Hello类型 ether[12:2] == 0x0104 and ether[21] == 0x01 # 2. 捕获Query类型 ether[12:2] == 0x0104 and ether[21] == 0x02 # 3. 捕获特定类型的组合(操作码+类型) ether[12:2] == 0x0104 and ether[15] == 0x01 and ether[21] == 0x012.5五、PAGP标志位分析(字节22)
2.5.1常见标志位:
- Bit 0: Auto模式 (1=Auto, 0=Desirable)
- Bit 1: 聚合状态 (1=Aggregatable)
- Bit 2: 学习状态
- Bit 3: 转发状态
- Bit 4: 端口状态变化
# 1. 检查Auto模式 (Cisco的"auto"模式) ether[12:2] == 0x0104 and (ether[22] & 0x01) == 0x01 # 2. 检查Desirable模式 (主动模式) ether[12:2] == 0x0104 and (ether[22] & 0x01) == 0x00 # 3. 检查聚合能力 ether[12:2] == 0x0104 and (ether[22] & 0x02) == 0x02 # 4. 检查学习状态 (STP相关) ether[12:2] == 0x0104 and (ether[22] & 0x04) == 0x04 # 5. 检查转发状态 ether[12:2] == 0x0104 and (ether[22] & 0x08) == 0x08 # 6. 检查端口状态变化标志 ether[12:2] == 0x0104 and (ether[22] & 0x10) == 0x102.6六、PAGP关键字段检查
2.6.11. 聚合组ID检查(Group ID - 字节32-33)
# 捕获特定聚合组ID ether[12:2] == 0x0104 and ether[32:2] == 0x1234 # 检查组ID为0(未分配组) ether[12:2] == 0x0104 and ether[32:2] == 0x0000 # 检查组ID不匹配(需要比较多个报文) ether[12:2] == 0x0104 and ether[32:2] > 0x00ff2.6.22. 端口ID检查(Port ID - 字节34-35)
# 捕获特定端口 ether[12:2] == 0x0104 and ether[34:2] == 0x000a # 端口10 # 检查无效端口ID ether[12:2] == 0x0104 and ether[34:2] == 0x0000 # 检查端口ID范围(通常1-255) ether[12:2] == 0x0104 and (ether[34:2] < 0x0001 or ether[34:2] > 0x00ff)2.6.33. 端口状态检查(字节36)
# 检查端口状态正常(通常非0) ether[12:2] == 0x0104 and ether[36] == 0x00 # 检查特定状态值 ether[12:2] == 0x0104 and ether[36] == 0x03 # 示例状态码2.6.44. 邻居计数检查(字节23)
# 检查邻居计数为0(孤立端口) ether[12:2] == 0x0104 and ether[23] == 0x00 # 检查邻居计数过多(可能环路) ether[12:2] == 0x0104 and ether[23] > 0x082.7七、常见PAGP故障分析表达式
2.7.1故障1: PAGP协商失败
# 模式不匹配:一端Auto,另一端也Auto(无法协商) ether[12:2] == 0x0104 and (ether[22] & 0x01) == 0x01 | \ tcpdump -r - -nn -c 10 | grep "01:00:0C:CC:CC:CC" # 检查是否收到对端响应(需要比较源MAC) ether[12:2] == 0x0104 and ether dst 01:00:0C:CC:CC:CC2.7.2故障2: 聚合组不匹配
# 捕获组ID不一致的报文(需要后续分析) ether[12:2] == 0x0104 and ether[32:2] != 0x0000 # 监控组ID变化(可能配置错误) ether[12:2] == 0x0104 | tcpdump -r - -T fields -e ether[32:2]2.7.3故障3: Hello超时/丢包
# 监控Hello报文间隔(需要时间分析) ether[12:2] == 0x0104 and ether[15] == 0x01 | \ tcpdump -ttt -r - | awk '{print $1}' # 检查Hello频率异常(正常每15或30秒) timeout 35 tcpdump -c 3 "ether[12:2] == 0x0104 and ether[15] == 0x01"2.7.4故障4: 端口状态异常
# 端口处于非聚合状态 ether[12:2] == 0x0104 and (ether[22] & 0x02) == 0x00 # 端口学习/转发状态异常 ether[12:2] == 0x0104 and ((ether[22] & 0x0C) != 0x0C)2.7.5故障5: VLAN不匹配
# PAGP可能包含VLAN信息(偏移量可能变化) # 检查VLAN ID字段(如果存在) ether[12:2] == 0x0104 and ether[40:2] == 0x0001 # VLAN 1 # 检查Native VLAN(如果支持) ether[12:2] == 0x0104 and ether[42:2] != 0x00012.8八、PAGP与LACP互操作性检查
# 同时捕获PAGP和LACP,检查混合环境 ether[12:2] == 0x0104 or ether[12:2] == 0x8809 # 检查是否错误配置了LACP(应使用PAGP) ether[12:2] == 0x8809 and ether[14] == 0x01 | \ tcpdump -r - -nn -c 5 "ether dst 01:00:0C:CC:CC:CC"2.9九、Cisco特有PAGP扩展检查
2.9.1EtherChannel负载均衡参数:
# 检查负载均衡模式(偏移量需要验证) ether[12:2] == 0x0104 and ether[44] == 0x01 # 源MAC ether[12:2] == 0x0104 and ether[44] == 0x02 # 目的MAC ether[12:2] == 0x0104 and ether[44] == 0x03 # 源目的MAC2.9.2Cisco私有TLV检查:
# 检查可能的Cisco扩展TLV ether[12:2] == 0x0104 and ether[38:2] == 0x00C0 # Cisco OUI ether[12:2] == 0x0104 and ether[38:2] == 0x0001 # 可能的管理TLV2.10十、组合故障诊断表达式
2.10.1综合PAGP健康检查:
# 捕获所有可能的PAGP问题 ether[12:2] == 0x0104 and ( # 组ID为0或无效 ether[32:2] == 0x0000 or ether[32:2] > 0x0fff or # 端口ID无效 ether[34:2] == 0x0000 or ether[34:2] > 0x00ff or # 聚合能力标志未设置 (ether[22] & 0x02) == 0x00 or # 邻居计数异常 ether[23] == 0x00 or ether[23] > 0x10 or # 非Hello消息中的异常标志 (ether[15] != 0x01 and ether[36] == 0x00) )2.10.2严重故障过滤器:
# 严重故障:完全无法建立EtherChannel ether[12:2] == 0x0104 and ( # 模式冲突(两端都是Auto) (ether[22] & 0x01) == 0x01 and ether dst 01:00:0C:CC:CC:CC ) or ( # 组ID冲突或不匹配 ether[32:2] == 0x0000 and ether[15] == 0x03 # 配置更新消息 )2.10.3性能问题过滤器:
# 可能影响性能的问题 ether[12:2] == 0x0104 and ( # Hello频率异常高 ether[15] == 0x01 and ether[16:2] < 0x000a # Payload过短 # 或邻居列表过长 ether[23] > 0x08 )2.11十一、实时监控脚本(BPF基础)
2.11.1PAGP报文统计:
#!/bin/bash # 监控PAGP报文统计 INTERFACE=$1 echo "PAGP协议监控 - 接口: $INTERFACE" echo "==================================" # 统计各种消息类型 HELLO_COUNT=$(tcpdump -i $INTERFACE -c 100 \ "ether[12:2] == 0x0104 and ether[15] == 0x01" 2>/dev/null | wc -l) QUERY_COUNT=$(tcpdump -i $INTERFACE -c 100 \ "ether[12:2] == 0x0104 and ether[15] == 0x02" 2>/dev/null | wc -l) UPDATE_COUNT=$(tcpdump -i $INTERFACE -c 100 \ "ether[12:2] == 0x0104 and ether[15] == 0x03" 2>/dev/null | wc -l) echo "Hello消息: $HELLO_COUNT" echo "查询消息: $QUERY_COUNT" echo "更新消息: $UPDATE_COUNT" echo "" # 检查异常状态 ABNORMAL=$(tcpdump -i $INTERFACE -c 50 \ "ether[12:2] == 0x0104 and ether[32:2] == 0x0000" 2>/dev/null | wc -l) if [ $ABNORMAL -gt 0 ]; then echo "警告: 发现 $ABNORMAL 个未分配组ID的PAGP报文" fi2.11.2BPF捕获保存分析:
# 保存PAGP故障相关报文 tcpdump -i any -w pagp_issues.pcap \ "ether[12:2] == 0x0104 and ( ether[32:2] == 0x0000 or # 组ID为0 ether[34:2] == 0x0000 or # 端口ID为0 (ether[22] & 0x02) == 0x00 # 无聚合能力 )"2.12十二、特定故障场景诊断
2.12.1场景1: Auto-Auto模式无法建立
# 捕获两端都是Auto模式的情况 tcpdump -i eth0 -nn \ "ether[12:2] == 0x0104 and (ether[22] & 0x01) == 0x01" \ -c 20 -e | grep "01:00:0C:CC:CC:CC"2.12.2场景2: VLAN不匹配导致聚合失败
# 检查VLAN相关信息(如果PAGP携带VLAN信息) tcpdump -i eth0 -XX \ "ether[12:2] == 0x0104" | \ grep -B2 -A2 "0104"2.12.3场景3: 端口安全冲突
# 检查端口安全相关的标志(如果存在) ether[12:2] == 0x0104 and ether[22] & 0x20 == 0x202.13十三、与CDP/DTP的交互检查
2.13.1同时监控Cisco发现协议:
# 捕获CDP和PAGP,检查协议交互 ether[12:2] == 0x0104 or ether[12:2] == 0x2000 # 检查CDP中报告的邻居能力 ether[12:2] == 0x2000 and ether[20:2] == 0x0001 # 设备ID TLV2.14十四、实用故障排除命令
# 1. 基本PAGP捕获 sudo tcpdump -i eth0 -c 10 -XX "ether[12:2] == 0x0104" # 2. 检查特定聚合组 GROUP=1234 sudo tcpdump -i any -nn "ether[32:2] == 0x${GROUP} and ether[12:2] == 0x0104" -e # 3. 监控PAGP Hello间隔 sudo tcpdump -i eth0 -ttt "ether[15] == 0x01 and ether[12:2] == 0x0104" | \ awk '{if(NR>1) printf "间隔: %.1f秒\n", $1-last; last=$1}' # 4. 检查PAGP与STP交互 sudo tcpdump -i eth0 "ether[12:2] == 0x0104 or ether[12:2] == 0x0026" # 5. 保存详细分析 sudo tcpdump -i eth0 -s 0 -w pagp_capture.pcap "ether proto 0x0104"2.15十五、BPF表达式优化
# 1. 使用预编译过滤器提高性能 tcpdump -i eth0 -ddd "ether[12:2] == 0x0104" > pagp_filter.bpf # 2. 组合条件优化(先检查常见条件) ether[0:6] = 01:00:0C:CC:CC:CC and ether[12:2] == 0x0104 # 3. 使用掩码同时检查多个标志位 ether[12:2] == 0x0104 and (ether[22] & 0x03) == 0x03 # Auto + Aggregatable # 4. 排除非PAGP的Cisco协议 ether[12:2] == 0x0104 and not ether[12:2] == 0x2000 # 排除CDP2.16十六、常见故障场景与BPF表达式
| 故障现象 | BPF表达式 | 可能原因 |
|---|---|---|
| EtherChannel无法建立 | ether[12:2]==0x0104 and ether[32:2]==0x0000 | 未配置聚合组 |
| 端口加入错误组 | ether[12:2]==0x0104 and ether[32:2]==0x0001 | 配置了错误组ID |
| 模式不匹配 | ether[12:2]==0x0104 and (ether[22]&0x01)==0x01 | 两端都是Auto模式 |
| 聚合标志未设置 | ether[12:2]==0x0104 and (ether[22]&0x02)==0x00 | 端口不支持聚合 |
| Hello丢失 | timeout 35 tcpdump -c 1 "ether[15]==0x01" | 链路问题或配置 |
2.17十七、注意事项
- PAGP是Cisco专有协议,不同IOS版本可能有细微差异
- 偏移量可能变化,建议先捕获样本报文确认结构
- 与LACP不兼容,不能混用
- 通常用于Cisco设备间,与其他厂商设备不兼容
- 建议结合Cisco命令:
show etherchannel summary,show pagp neighbor
2.18总结
纯BPF表达式分析PAGP故障的关键点:
- 记住关键偏移:Ethertype(12-13)=0x0104,操作码(15),标志位(22),组ID(32-33)
- 理解模式标志:Bit0=Auto/Desirable模式
- 检查聚合能力:Bit1=Aggregatable标志
- 验证组ID和端口ID:确保配置正确
- 监控Hello消息:确保协议通信正常
虽然PAGP是Cisco私有协议,但通过BPF表达式仍可以进行有效的故障分析和诊断。