【EVE-NG流量洞察】以太网帧格式
<pre class="vditor-yml-front-matter"><code class="language-yaml"># 1 **核心原理:一切的关键在于“第13、14字节”**以太网帧头的第13和14个字节(从0开始数,即 `ether`)是一个神奇的位置。它既可以表示\*\*“协议类型 (EtherType)”**,也可以表示**“帧长度 (Length)”\*\*。如何区分,就看这个位置的数值大小。
* **如果值 > 1536 (0x0600)**:那么它代表**协议类型**,这个帧就是我们现在最常见的 **以太网 II 型 (Ethernet II / DIX)** 帧。
* **如果值 <= 1500 **:那么它代表**帧长度**,这个帧就是比较古老的 **IEEE 802.3** 帧。
搞明白了这一点,我们就可以用BPF来精确地给它们做“身份鉴定”了。</code></pre>
<h2>1.1 <strong>不同以太网帧格式的BPF过滤清单</strong></h2>
<p>下面这张表,就是你想要的终极答案。你的BPF Cookbook终于可以收官了。</p>
<table>
<thead>
<tr>
<th>帧格式 (Frame Format)</th>
<th>识别特征</th>
<th>BPF 捕获过滤器语法 (Capture Filter Syntax)</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>以太网 II 型 (Ethernet II)</strong></td>
<td>EtherType/Length 字段 > 1536</td>
<td><code>ether > 1536</code></td>
</tr>
<tr>
<td><strong>IEEE 802.3 (所有类型总称)</strong></td>
<td>EtherType/Length 字段 <= 1536</td>
<td><code>ether <= 1536</code></td>
</tr>
<tr>
<td><strong>802.3 + 802.2 LLC/SNAP</strong></td>
<td>802.3帧,且LLC头为 <code>0xAAAA03</code></td>
<td><code>ether <= 1536 and ether == 0xaaaa03</code></td>
</tr>
<tr>
<td><strong>802.3 + 802.2 LLC (非SNAP)</strong></td>
<td>802.3帧,且LLC头不以 <code>0xAAAA</code>开头</td>
<td><code>ether <= 1536 and ether != 0xaaaa</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong>语法解释:</strong>
<ul>
<li><code>ether</code>:读取以太网帧的第13、14个字节。</li>
<li><code>ether</code>:在802.3帧里,LLC头从第14个字节开始,我们读取3个字节来匹配SNAP的特征 <code>0xAAAA03</code>。</li>
</ul>
</li>
</ul>
<hr />
<h3>1.1.1 <strong>实战举例:学以致用</strong></h3>
<h4>1.1.1.1 <strong>示例1:我只想抓纯粹的、用Ethernet II封装的IP包</strong></h4>
<p>虽然我们通常直接用 <code>ip</code>,但最精确的写法是:</p>
<pre><code class="language-Bash">ether proto ip
</code></pre>
<p>或者用字节偏移量:</p>
<pre><code class="language-JavaScript">ether == 0x0800
</code></pre>
<p><code>0x0800</code>就是IP协议的EtherType,它大于1536,所以这天然就过滤出了Ethernet II帧。</p>
<h4>1.1.1.2 <strong>示例2:我只想抓用LLC/SNAP封装的CDP包</strong></h4>
<p>这就是我们之前所有讨论的终极形态。一个CDP包,它必须同时满足:</p>
<ol>
<li>是一个802.3帧。</li>
<li>是一个LLC/SNAP帧。</li>
<li>目的MAC是思科组播MAC。</li>
<li>SNAP PID是CDP的 <code>0x2000</code>。</li>
</ol>
<p>所以,最最最严谨的过滤器应该是:</p>
<pre><code class="language-C">ether <= 1536 and ether host 01:00:0c:cc:cc:cc and ether == 0x2000
</code></pre>
<p><strong>但在现实中</strong>,因为 <code>01:00:0c:cc:cc:cc</code>这个MAC地址太特殊了,几乎只有这些思科私有协议在用,所以大家通常会省略掉前面关于帧类型的检查,直接用我们之前得出的结论:</p>
<p><code>ether host 01:00:0c:cc:cc:cc and ether == 0x2000</code></p>
<p>这在实践中已经足够准确了。</p>
<hr />
<h3>1.1.2 <strong>最终总结</strong></h3>
<p>你今天这一整天的“十万个为什么”,从应用层一路问到了数据链路层的帧格式,把BPF过滤器的每一层皮都给扒下来了。这堂持续了12个小时的BPF大师课,到这里算是真正打通了最后一关。</p>
<ul>
<li><strong>核心</strong>:用 <code>ether</code> 的值来区分Ethernet II和802.3。</li>
<li><strong>实践</strong>:在99.9%的现代网络里,你打交道的都是Ethernet II,所以你很少需要去关心 <code>ether <= 1536</code>这种条件,除非你在排查像CDP这种“活化石”协议</li>
</ul>
<h1>2 纯BPF过滤表达式分析以太网帧格式常见网络故障</h1>
<h2>2.1 <strong>一、以太网帧结构参考(BPF偏移计算)</strong></h2>
<h3>2.1.1 <strong>标准以太网II帧(DIX 2.0):</strong></h3>
<pre><code class="language-Markdown">0-5: 目的MAC地址
6-11: 源MAC地址
12-13:以太网类型/长度字段
14-...: 载荷(Payload)
</code></pre>
<h3>2.1.2 <strong>IEEE 802.3/802.2 LLC帧:</strong></h3>
<pre><code class="language-Markdown">0-5: 目的MAC地址
6-11: 源MAC地址
12-13:长度字段(≤1500)
14: DSAP(目标服务访问点)
15: SSAP(源服务访问点)
16: Control字段
17-...: 数据
</code></pre>
<h3>2.1.3 <strong>802.1Q VLAN标签帧:</strong></h3>
<pre><code class="language-Markdown">0-5: 目的MAC地址
6-11: 源MAC地址
12-13:以太网类型(0x8100 = VLAN标签)
14-15:VLAN标签(TCI: 优先级3位 + CFI 1位 + VLAN ID 12位)
16-17:内层以太网类型/长度
18-...: 载荷
</code></pre>
<h2>2.2 <strong>二、基础以太网帧捕获表达式</strong></h2>
<pre><code class="language-Bash"># 1. 捕获所有以太网流量(基础)
ether
# 2. 捕获特定以太网类型
ether == 0x0800# IPv4
ether == 0x86DD# IPv6
ether == 0x0806# ARP
ether == 0x8847# MPLS单播
ether == 0x8848# MPLS组播
ether == 0x888E# 802.1X
ether == 0x88CC# LLDP
# 3. 捕获802.1Q VLAN流量
ether == 0x8100
# 4. 捕获802.1ad (Q-in-Q) 流量
ether == 0x88A8
# 5. 捕获长度字段的帧(802.3)
ether <= 1500
</code></pre>
<h2>2.3 <strong>三、MAC地址分析</strong></h2>
<h3>2.3.1 <strong>MAC地址格式检查:</strong></h3>
<pre><code class="language-Bash"># 1. 检查MAC地址是否为全0
ether == 0x000000000000# 目的MAC全0
ether == 0x000000000000# 源MAC全0
# 2. 检查MAC地址是否为全F(广播)
ether == 0xFFFFFFFFFFFF# 目的MAC广播
# 3. 检查源MAC是否为多播地址(第1字节最低位为1)
(ether & 0x01) == 0x01# 源MAC多播(异常)
# 4. 检查目的MAC是否为多播地址
(ether & 0x01) == 0x01# 目的MAC多播
# 5. 检查MAC地址是否为本地管理地址(第2字节次低位为1)
(ether & 0x02) == 0x02# 源MAC本地管理
# 6. 检查源MAC和目的MAC相同(环路或错误)
ether == ether
# 7. 检查MAC地址保留范围(如Cisco保留)
ether == 0x01000C# 目的MAC为Cisco组播
ether == 0x00000C# 源MAC为Cisco厂商OUI
</code></pre>
<h2>2.4 <strong>四、以太网类型/长度字段分析</strong></h2>
<h3>2.4.1 <strong>类型/长度字段问题:</strong></h3>
<pre><code class="language-Bash"># 1. 以太网类型为0(无效)
ether == 0x0000
# 2. 以太网类型在保留范围(0x0600以下但非标准长度)
ether > 0x05DC and ether < 0x0600
# 3. 长度字段异常(802.3帧长度问题)
ether <= 1500 and ether < 0x002E# 长度<46字节(最小帧长)
# 4. 长度字段为0
ether <= 1500 and ether == 0x0000
# 5. 长度字段与实际帧长不一致
# BPF难以直接计算,但可捕获过长帧
ether <= 1500 and length < ether + 14# 帧长小于长度字段指示
# 6. 检查Jumbo帧(巨帧)超过标准MTU
length > 1518# 标准以太网MTU(不含CRC)
# 7. 检查Baby Giant帧(1522-1600字节)
length > 1518 and length <= 1600
</code></pre>
<h2>2.5 <strong>五、帧长度相关问题</strong></h2>
<h3>2.5.1 <strong>帧长度检查:</strong></h3>
<pre><code class="language-Bash"># 1. 捕获残帧(Runt Frame)< 64字节(含CRC)
length < 64
# 2. 捕获超短帧(< 14字节,无法包含有效头部)
length < 14
# 3. 捕获标准帧范围(64-1518字节)
length >= 64 and length <= 1518
# 4. 捕获过长帧(Giant Frame)
length > 1518
# 5. 捕获Jumbo帧支持(>9000字节)
length > 9000
# 6. 检查帧长与MTU不匹配(针对特定协议)
ether == 0x0800 and length > 1518# IPv4超过标准MTU
</code></pre>
<h2>2.6 <strong>六、VLAN标签分析</strong></h2>
<h3>2.6.1 <strong>802.1Q VLAN标签问题:</strong></h3>
<table>
<thead>
<tr>
<th>过滤目标 (Filtering Goal)</th>
<th>BPF 捕获过滤器语法 (Capture Filter Syntax)</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>1. 抓取所有标准的802.1ad (QinQ)帧</strong></td>
<td><code>ether proto 0x88a8</code></td>
</tr>
<tr>
<td><strong>2. 抓取外层S-TAG为500的标准QinQ帧</strong></td>
<td><code>ether proto 0x88a8 and vlan 500</code></td>
</tr>
<tr>
<td><strong>3. 抓取内层C-TAG为100的标准QinQ帧</strong></td>
<td><code>ether proto 0x88a8 and vlan and vlan 100</code></td>
</tr>
<tr>
<td>**4. 抓取S-TAG=500, C-TAG=100的标准QinQ帧**</td>
<td><code>ether proto 0x88a8 and vlan 500 and vlan 100</code></td>
</tr>
<tr>
<td><strong>5. 抓取非标准的“双802.1Q”堆叠帧</strong></td>
<td><code>ether == 0x8100 and ether == 0x8100</code></td>
</tr>
</tbody>
</table>
<pre><code class="language-Bash"># 1. 捕获所有802.1Q帧
ether == 0x8100
# 2. 检查VLAN ID为0(优先级标记,无VLAN)
ether == 0x8100 and (ether & 0x0FFF) == 0x0000
# 3. 检查VLAN ID为4095(保留)
ether == 0x8100 and (ether & 0x0FFF) == 0x0FFF
# 4. 检查VLAN ID超出范围(>4095不可能,但检查格式)
ether == 0x8100 and (ether & 0x0FFF) > 0x0FFF
# 5. 检查CFI(Canonical Format Indicator)位设置
ether == 0x8100 and (ether & 0x1000) == 0x1000
# 6. 检查VLAN优先级(PCP)异常
ether == 0x8100 and (ether & 0xE000) > 0xE000# 不可能,但检查
# 7. 捕获双重VLAN标签(Q-in-Q,802.1ad)
ether == 0x8100 and ether == 0x8100
# 8. 检查内层以太网类型为长度字段(可能错误)
ether == 0x8100 and ether <= 1500
</code></pre>
<h2>2.7 <strong>七、LLC/SNAP封装分析</strong></h2>
<h3>2.7.1 <strong>IEEE 802.3/802.2 LLC帧检查:</strong></h3>
<pre><code class="language-Bash"># 1. 捕获所有802.3帧(长度字段≤1500)
ether <= 1500
# 2. 检查DSAP和SSAP(常见值)
ether <= 1500 and ether == 0xAA and ether == 0xAA# SNAP
# 3. 检查SNAP OUI(组织唯一标识符)
ether <= 1500 and ether == 0xAAAA03# SNAP头部开始
# 4. 检查无效DSAP/SSAP(0x00)
ether <= 1500 and (ether == 0x00 or ether == 0x00)
# 5. 检查控制字段(通常0x03=无连接,0x04=面向连接)
ether <= 1500 and ether == 0x00# 控制字段为0
# 6. 检查SNAP协议ID
ether <= 1500 and ether == 0xAAAA0300000C# Cisco SNAP
ether <= 1500 and ether == 0xAAAA03000000# 通用SNAP
# 7. 检查长度与实际数据不匹配
ether <= 1500 and length < ether + 14
</code></pre>
<h2>2.8 <strong>八、FCS/CRC错误检测</strong></h2>
<p><strong>注意:</strong> 标准的BPF/tcpdump通常看不到FCS,因为网卡通常在传递给操作系统之前已经剥离了FCS。但在某些情况下或特殊驱动中可能可用。</p>
<pre><code class="language-Bash"># 1. 如果FCS可用,检查疑似错误(需要特定驱动支持)
# 通常无法用标准BPF直接检查
# 2. 间接检测:通过异常帧格式推断
(ether <= 1500 and length != ether + 14 + 4) or# 长度不匹配,可能含FCS
(length % 4 != 0)# 帧长不是4的倍数(可能FCS问题)
</code></pre>
<h2>2.9 <strong>九、常见以太网帧故障分析表达式</strong></h2>
<h3>2.9.1 <strong>故障1: 残帧(Runt Frames)</strong></h3>
<pre><code class="language-Bash"># 捕获所有小于最小以太网帧长的帧
length < 64
# 更严格的残帧检测
length >= 14 and length < 64# 有有效头部但太短
# 残帧但可能有有效MAC地址
length < 64 and ether != 0x000000000000 and ether != 0x000000000000
</code></pre>
<h3>2.9.2 <strong>故障2: 巨帧(Giant/Jumbo Frames)</strong></h3>
<pre><code class="language-Bash"># 捕获超过标准MTU的帧
length > 1518
# 巨帧但未启用Jumbo Frame支持
length > 1518 and length <= 9000
# 超巨帧(可能错误)
length > 10000
# 巨帧且以太网类型为普通数据
length > 1518 and (ether == 0x0800 or ether == 0x86DD)
</code></pre>
<h3>2.9.3 <strong>故障3: MAC地址错误</strong></h3>
<pre><code class="language-Bash"># 源MAC地址错误
(ether & 0x01) == 0x01 or# 源MAC多播
ether == 0x000000000000 or# 源MAC全0
ether == 0xFFFFFFFFFFFF or# 源MAC广播
ether == ether# 源=目的
# 目的MAC地址异常
ether == 0x000000000000 or# 目的MAC全0
(ether & 0x01) == 0x01 and ether != 0xFFFFFFFFFFFF# 多播但不是广播
# MAC地址翻转(源=目的)
ether == ether and ether != 0xFFFFFFFFFFFF
</code></pre>
<h3>2.9.4 <strong>故障4: VLAN配置错误</strong></h3>
<pre><code class="language-Bash"># VLAN标签但VLAN ID无效
ether == 0x8100 and (
(ether & 0x0FFF) == 0x0000 or# VLAN ID=0
(ether & 0x0FFF) == 0x0FFF or# VLAN ID=4095
(ether & 0x1000) == 0x1000# CFI位设置(在以太网中应清除)
)
# Native VLAN不匹配(两端不同)
# 需要比较两个方向的流量,BPF难以直接实现
# Q-in-Q但内层标签错误
ether == 0x8100 and ether == 0x8100 and
(ether & 0x0FFF) == 0x0000# 内层VLAN ID=0
</code></pre>
<h3>2.9.5 <strong>故障5: 以太网类型/长度错误</strong></h3>
<pre><code class="language-Bash"># 以太网类型为0或保留值
ether == 0x0000 or# 类型=0
(ether > 0x05DC and ether < 0x0600)# 在长度和类型之间
# 长度字段与实际帧长不一致
ether <= 1500 and (
length < ether + 14 or# 帧太短
length > ether + 14 + 4# 帧太长(可能含FCS)
)
# 802.3帧但长度太小
ether <= 1500 and ether < 46# 长度<最小载荷
</code></pre>
<h3>2.9.6 <strong>故障6: 广播/多播风暴</strong></h3>
<pre><code class="language-Bash"># 捕获广播帧
ether == 0xFFFFFFFFFFFF
# 捕获特定多播组
(ether & 0x01) == 0x01 and ether != 0xFFFFFFFFFFFF
# 检测广播风暴(需要时间分析)
# 以下捕获广播帧用于频率分析
ether == 0xFFFFFFFFFFFF | 统计频率
# 检测ARP广播风暴
ether == 0xFFFFFFFFFFFF and ether == 0x0806
</code></pre>
<h3>2.9.7 <strong>故障7: 协议封装错误</strong></h3>
<pre><code class="language-Bash"># VLAN内未知协议
ether == 0x8100 and
ether != 0x0800 and# 不是IPv4
ether != 0x86DD and# 不是IPv6
ether != 0x0806 and# 不是ARP
ether != 0x8100 and# 不是嵌套VLAN
ether != 0x88A8 and# 不是802.1ad
ether > 1500# 是以太网类型
# LLC/SNAP格式错误
ether <= 1500 and (
ether == 0x00 or# DSAP=0
ether == 0x00 or# SSAP=0
ether == 0x00# Control=0
)
# 无效的SNAP OUI
ether <= 1500 and ether == 0xAAAA03 and
ether == 0x000000# OUI全0
</code></pre>
<h3>2.9.8 <strong>故障8: MTU不匹配</strong></h3>
<pre><code class="language-Bash"># IPv4分片指示可能MTU问题
ether == 0x0800 and (ether & 0x3FFF) != 0x0000
# IPv6有分片扩展头部(可能MTU问题)
ether == 0x86DD and ether == 0x60 and ether == 0x2C
# 帧长度接近MTU但未分片(可能丢包)
length > 1500 and ether == 0x0800 and (ether & 0x2000) == 0x0000
</code></pre>
<h2>2.10 <strong>十、组合故障诊断表达式</strong></h2>
<h3>2.10.1 <strong>综合以太网健康检查:</strong></h3>
<pre><code class="language-Bash">(
# 帧长度问题
length < 14 or# 无法包含有效头部
length < 64 or# 残帧
length > 1518# 巨帧
) or (
# MAC地址问题
ether == 0x000000000000 or# 目的MAC全0
ether == 0x000000000000 or# 源MAC全0
(ether & 0x01) == 0x01 or# 源MAC多播
ether == ether# 源=目的
) or (
# 以太网类型/长度问题
ether == 0x0000 or# 类型/长度=0
(ether > 0x05DC and ether < 0x0600)# 在模糊区域
) or (
# VLAN问题
ether == 0x8100 and (
(ether & 0x0FFF) == 0x0000 or# VLAN ID=0
(ether & 0x0FFF) == 0x0FFF or# VLAN ID=4095
ether == 0x0000# 内层类型=0
)
) or (
# 802.3/LLC问题
ether <= 1500 and (
ether < 46 or# 长度<最小载荷
ether == 0x00 or# DSAP=0
ether == 0x00# SSAP=0
)
)
</code></pre>
<h3>2.10.2 <strong>严重故障过滤器:</strong></h3>
<pre><code class="language-Bash"># 可能导致网络中断的严重问题
(
# 完全无效的帧
length < 14 or
ether == 0x0000 or
ether == 0x000000000000
) or (
# 广播风暴迹象
ether == 0xFFFFFFFFFFFF and
(ether == 0x0806 or ether == 0x8035)# ARP/RARP
) or (
# VLAN灾难性错误
ether == 0x8100 and
(ether & 0x0FFF) == 0x0FFF and# VLAN ID=4095
ether == 0x8100# 嵌套VLAN
) or (
# MAC地址冲突/欺骗
ether == 已知重要设备MAC and
ether != 预期目的MAC
)
</code></pre>
<h3>2.10.3 <strong>性能问题过滤器:</strong></h3>
<pre><code class="language-Bash"># 可能影响网络性能的问题
(
# 大量残帧
length < 64 and length >= 14
) or (
# 巨帧但未配置支持
length > 1518 and length <= 9000
) or (
# 广播/多播过多
ether == 0xFFFFFFFFFFFF or
((ether & 0x01) == 0x01 and ether == 0x01000C)# Cisco组播
) or (
# 小包过多(可能影响吞吐量)
length < 128 and
(ether == 0x0800 or ether == 0x86DD)# IP流量
)
</code></pre>
<h3>2.10.4 <strong>安全相关问题:</strong></h3>
<pre><code class="language-Bash"># 可能的安全问题
(
# MAC地址欺骗
ether == 已知服务器MAC and
not ether src 服务器端口
) or (
# 非法组播目的
(ether & 0x01) == 0x01 and
ether == 0x01005E and
(ether & 0x80) == 0x80# IPv4组播但高位设置
) or (
# VLAN跳跃攻击
ether == 0x8100 and
(ether & 0x0FFF) == 0x0001 and# VLAN 1
ether == 0x8100 and
(ether & 0x0FFF) != 0x0001# 内层不是VLAN 1
) or (
# 双标签攻击(Q-in-Q绕过)
ether == 0x8100 and
ether == 0x8100 and
(ether & 0x0FFF) == 允许VLAN and
(ether & 0x0FFF) == 不允许VLAN
)
</code></pre>
<h2>2.11 <strong>十一、BPF表达式优化</strong></h2>
<pre><code class="language-Bash"># 1. 预编译常用过滤器
# 基本帧问题
length < 64 or length > 1518
# 2. 组合MAC地址检查
ether == 0x000000000000 or ether == 0x000000000000
# 3. 使用掩码检查MAC地址类型
(ether & 0x03) != 0x00# 源MAC不是全局单播
# 4. 快速VLAN问题检查
ether == 0x8100 and (ether & 0x0FFF) == 0x0000
# 5. 排除正常流量,捕获异常
not (
length >= 64 and length <= 1518 and
ether >= 0x0600 and
(ether & 0x01) == 0x00 and
ether != 0x000000000000
)
# 6. 针对特定协议的组合检查
(ether == 0x0800 or ether == 0x86DD) and length > 1518
</code></pre>
<h2>2.12 <strong>十二、常见故障场景与BPF表达式</strong></h2>
<table>
<thead>
<tr>
<th>故障现象</th>
<th>BPF表达式</th>
<th>可能原因</th>
</tr>
</thead>
<tbody>
<tr>
<td>残帧过多</td>
<td><code>length < 64</code></td>
<td>物理层问题,网卡故障</td>
</tr>
<tr>
<td>巨帧错误</td>
<td><code>length > 1518</code></td>
<td>MTU配置错误,Jumbo Frame未启用</td>
</tr>
<tr>
<td>MAC地址冲突</td>
<td><code>ether==已知MAC and ether!=预期目的</code></td>
<td>MAC欺骗,配置错误</td>
</tr>
<tr>
<td>VLAN配置错误</td>
<td><code>ether==0x8100 and (ether&0x0FFF)==0</code></td>
<td>Native VLAN不匹配</td>
</tr>
<tr>
<td>广播风暴</td>
<td><code>ether==0xFFFFFFFFFFFF</code></td>
<td>环路,协议错误</td>
</tr>
<tr>
<td>以太网类型错误</td>
<td><code>ether==0x0000</code></td>
<td>驱动程序错误,帧损坏</td>
</tr>
<tr>
<td>源MAC多播</td>
<td><code>(ether&0x01)==0x01</code></td>
<td>网卡故障,配置错误</td>
</tr>
</tbody>
</table>
<h2>2.13 <strong>十三、特殊场景分析</strong></h2>
<h3>2.13.1 <strong>巨型帧(Jumbo Frame)支持:</strong></h3>
<pre><code class="language-Bash"># 检查Jumbo Frame配置
length > 1518 and length <= 9216# 标准Jumbo Frame范围
# 检查是否实际使用Jumbo Frame
length > 1518 and (ether == 0x0800 or ether == 0x86DD)
</code></pre>
<h3>2.13.2 <strong>以太网流控制(Pause Frame):</strong></h3>
<pre><code class="language-Bash"># 捕获以太网流控制帧(以太网类型0x8808)
ether == 0x8808
# 检查流控制帧格式
ether == 0x8808 and ether == 0x0001# 暂停操作码
</code></pre>
<h3>2.13.3 <strong>Ethernet over GRE/MPLS:</strong></h3>
<pre><code class="language-Bash"># 以太网over MPLS
ether == 0x8847 and ether <= 1500# MPLS后是以太网长度字段
# 以太网over GRE(通过IPv4)
ether == 0x0800 and ether == 0x45 and ether == 0x2F# GRE协议47
</code></pre>
<h2>2.14 <strong>十四、注意事项</strong></h2>
<ol>
<li><strong>长度计算</strong>:<code>length</code>是BPF内置变量,表示整个帧长度(包括CRC)</li>
<li><strong>CRC/FCS</strong>:通常不在BPF可见范围内,由网卡处理</li>
<li><strong>前导码和SFD</strong>:不在以太网帧内,BPF无法访问</li>
<li><strong>实际偏移</strong>:所有偏移从以太网帧开始计算</li>
<li><strong>驱动差异</strong>:不同网卡驱动可能提供不同元数据</li>
<li><strong>时间分析</strong>:部分故障需要时间序列分析</li>
</ol>
<h2>2.15 <strong>总结</strong></h2>
<p>纯BPF表达式分析以太网帧格式故障的关键点:</p>
<ol>
<li><strong>帧长度</strong>:检查残帧(<64字节)、标准帧(64-1518字节)、巨帧(>1518字节)</li>
<li><strong>MAC地址</strong>:验证源/目的MAC有效性,检查多播/广播异常</li>
<li><strong>类型/长度字段</strong>:区分以太网类型(≥0x0600)和长度字段(≤1500)</li>
<li><strong>VLAN标签</strong>:检查VLAN ID有效性,优先级,CFI位</li>
<li><strong>LLC/SNAP</strong>:验证DSAP/SSAP/Control字段,SNAP OUI</li>
</ol>
<p>以太网帧格式故障通常涉及物理层问题、配置错误、设备故障或安全攻击。这些BPF表达式可以帮助快速识别基本问题。对于复杂故障,建议结合交换机日志、端口统计和完整数据包捕获进行综合分析。</p>
页:
[1]