跳到主要内容

8. 故障管理

SCTP 提供健壮的故障检测和恢复机制, 以确保在网络故障条件下仍能可靠通信.

8.1. 端点故障检测

SCTP 端点必须能够检测对等端点的完全故障.

8.1.1. Association 级错误计数

每个 SCTP association 都维护一个 Association Error Counter:

  • 当任一目的地址的错误计数器达到阈值时, 该 association 被视为失败
  • 当 association 失败时, 端点应该向上层报告

8.1.2. 端点故障条件

当满足以下条件时, 端点被视为失败:

  1. 所有目的地址都被标记为 inactive
  2. association 的总错误计数超过 Association.Max.Retrans 阈值

Association.Max.Retrans: 推荐默认值为 10 次重传尝试.

8.1.3. 故障响应

检测到端点故障时:

1. Stop sending new data to that endpoint
2. Report association failure to upper layer
3. Destroy the Transmission Control Block (TCB)
4. Optional: Send ABORT chunk to notify peer

8.2. 路径故障检测

SCTP 可以检测单个传输路径故障, 而不影响整个 association (如果还有其他 active 路径可用).

8.2.1. 路径级错误计数

每个目的传输地址都维护一个 Path Error Counter:

  • 每次传输失败时递增
  • 传输成功或收到 HEARTBEAT ACK 时重置为 0

8.2.2. 路径故障条件

当满足以下条件时, 路径被视为 inactive:

  1. 连续传输失败达到 Path.Max.Retrans
  2. 连续 HEARTBEAT 失败达到 Path.Max.Retrans

Path.Max.Retrans: 推荐默认值为 5 次重传尝试.

8.2.3. 路径状态管理

路径状态:

  • Active: 路径可用于数据传输
  • Inactive: 路径暂时不可用

状态转换:

Active -> Inactive:
- Consecutive failures reach Path.Max.Retrans

Inactive -> Active:
- Receive valid HEARTBEAT ACK
- Successful data transmission with acknowledgement

8.2.4. 路径故障响应

当主路径失败时:

1. Mark path as inactive
2. Select another active path as new primary path
3. Retransmit unacknowledged data on new primary path
4. Continue monitoring inactive path with HEARTBEAT

路径选择策略:

  • 优先选择最近成功的路径
  • 考虑路径 RTT 和拥塞状态
  • 轮询可用路径以分散负载 (可选)

8.3. 路径 Heartbeat

HEARTBEAT 机制用于主动监测目的地址的可达性.

8.3.1. HEARTBEAT 发送规则

端点应该周期性地向每个空闲的目的地址发送 HEARTBEAT:

发送间隔:

HB.interval: Recommended default value is 30 seconds
Configurable range: 1 second to several minutes

发送条件:

  • 目的地在 HB.interval 时间内未发送任何数据
  • 目的地当前为 inactive (更频繁地探测)

HEARTBEAT 内容:

- Heartbeat Information TLV
- Sending timestamp
- Destination address information
- Optional: Sender-specific information

8.3.2. HEARTBEAT ACK 处理

收到 HEARTBEAT ACK 时:

1. Calculate RTT = current time - sending timestamp
2. Update destination's RTO
3. Mark destination as active
4. Reset path error counter to 0

8.3.3. HEARTBEAT 超时处理

如果在 RTO 时间内未收到 HEARTBEAT ACK:

1. Increment path error counter
2. If error count >= Path.Max.Retrans:
- Mark path as inactive
- If primary path, select new primary path
3. Continue sending HEARTBEAT to probe for recovery

8.3.4. 按需 HEARTBEAT

除了周期性 HEARTBEAT 外, 端点可以在以下情况下发送按需 HEARTBEAT:

  • 收到对等方的地址列表更新
  • 怀疑路径可能已经恢复
  • 需要快速验证路径可达性

8.4. 处理 "Out of the Blue" 分组

"Out of the Blue" 分组是端点收到的, 与任何已知 association 都不匹配的 SCTP 分组.

8.4.1. 识别 Out of the Blue 分组

当满足以下条件时, 分组被视为 "Out of the Blue":

  1. Verification Tag 与任何现有 association 都不匹配
  2. 源地址和端口与任何现有 association 都不匹配
  3. 目的端口匹配, 但不存在对应 association

8.4.2. Out of the Blue 分组处理规则

收到意外的 INIT chunk:

If endpoint is in CLOSED state:
- Respond with INIT ACK per normal procedure
Otherwise:
- Silently discard

收到意外的 ABORT chunk:

- If T bit is set:
- Verify using packet's Verification Tag
- Silently accept and discard

收到意外的 SHUTDOWN COMPLETE chunk:

- Verify T bit
- Silently accept and discard

收到其他意外 chunk:

Send ABORT chunk:
- Use received packet's Verification Tag
- Error cause: "Out of the Blue"
- T bit set to 1

8.4.3. ABORT Chunk 发送

当为响应 Out of the Blue 分组而发送 ABORT chunk 时:

ABORT Chunk Format:
- Chunk Type = 6
- T bit = 1
- Verification Tag = Verification Tag from received packet
- Error Cause (optional):
- Cause Code = 8 (Out of the Blue)
- Cause Info = Copy of received packet

8.4.4. 安全考虑

处理 Out of the Blue 分组时的安全措施:

  1. 响应速率限制: 避免被用于放大攻击
  2. 验证源地址: 在可能时验证源地址的合法性
  3. 记录异常: 记录频繁出现的 Out of the Blue 分组以检测攻击

8.5. Verification Tag 使用

Verification Tag 是 SCTP 防止分组伪造和注入攻击的关键安全机制.

8.5.1. Verification Tag 规则

发送分组时:

- Use Initiate Tag provided by peer in INIT or INIT ACK
- As Verification Tag field in SCTP common header

接收分组时:

- Verify Verification Tag matches local Tag
- Discard packet if doesn't match (except special cases)

特殊情况:

  • INIT chunk: Verification Tag 必须为 0
  • SHUTDOWN COMPLETE 和 ABORT: 可以使用 T bit 指示应使用哪个 Tag

8.5.2. 验证失败处理

收到 Verification Tag 不正确的分组时:

If INIT chunk:
- Handle per Section 8.4
If ABORT or SHUTDOWN COMPLETE with T bit=1:
- Verify using Verification Tag from packet
Otherwise:
- Silently discard packet
- Do not send any response

总结

SCTP 的故障管理机制提供多层健壮性:

  1. 多路径冗余: 单条路径故障不会影响 association
  2. 主动监测: HEARTBEAT 机制主动检测路径状态
  3. 快速故障切换: 检测到故障后立即切换到备用路径
  4. 防御机制: Verification Tag 防止恶意分组注入
  5. 可配置阈值: 允许根据网络条件调整故障检测灵敏度

这些机制共同确保 SCTP 在各种网络故障场景下的可靠性和可用性.