REGISTER 失败:Path 头超 255 上限(SBC 长 privatelink 域名累计触发)

涉及日志(k8s-node-vmddm1-3dnzcqst5v / opensips[529] / 2026-06-26 11:36:41 / call_id tenant00000001 / 注册号 80000001@node-02.example.internal / 源 IP 192.168.35.3 / WebPhone 1.17.3 / 拓扑:SBC↔Edge=TCP,Edge↔Core=UDP)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Jun 26 11:36:41.481178 opensips[526] REGISTER ... call_id=tenant00000001 ... cseq=1 sip:80000001@node-02.example.internal -> sip:sbc-01.example.internal:18627;transport=tcp >>> r_prep >>
Jun 26 11:36:41.481245 opensips[526] ... >>> received REGISTER, Expired Time is 120
Jun 26 11:36:41.481272 opensips[526] ... >>> Auth error! reason: no_credentials ← 首次未带 Auth,正常 challenge
Jun 26 11:36:41.481328 opensips[526] ... JSON: { "reply_state": 401, "reason": "no_credentials", "from_user": "80000001", "domain": "node-02.example.internal", "user_Agent": "WebPhone 1.17.3", "source_ip": "192.168.35.3" }

Jun 26 11:36:41.562280 opensips[529] REGISTER ... cseq=2 ... >>> r_prep >> ← WebPhone 带 Auth 重发
Jun 26 11:36:41.562835 opensips[529] 80000001@node-02.example.internal register_success ← Auth 通过
Jun 26 11:36:41.562907 opensips[529] ERROR:registrar:build_path_vector: Overall Path body exceeds max. length of 255 ★ 爆点
Jun 26 11:36:41.562914 opensips[529] ERROR:registrar:insert_contacts: failed to extract contact info
Jun 26 11:36:41.562971 opensips[529] 80000001@node-02.example.internal register_offline
Jun 26 11:36:41.563005 opensips[529] ERROR REGISTER ... >>> location save error: 192.168.17.107:1055;transport=ws;ob
Jun 26 11:36:41.563052 opensips[529] ... JSON: { "reply_state": 503, "reason": "Service Unavailable", ... }
Jun 26 11:36:41.563072 opensips[529] ERROR REGISTER ... >>> Auth error! reason: too_many_registered
Jun 26 11:36:41.563082 opensips[529] ... >>> too_many_registered:66850
Jun 26 11:36:41.563089 opensips[529] ... >>> metadata_has_raised flag is set, shouldn't duplicately state error.

--- 对照(同窗口同配置的 AgentSimulator 案例,成功)---
Jun 26 11:36:41.920350 opensips[531] REGISTER ... call_id=e0de2ddc11cd4482ba67b492bb779b0b@192.168.71.30 cseq=2106 sip:80000128@node-02.example.internal -> sip:sbc-01.example.internal:18627;transport=tcp >>> r_prep >>
Jun 26 11:36:41.920434 opensips[531] ... >>> Auth error! reason: no_credentials ← 同样先 challenge
Jun 26 11:36:41.928905 opensips[530] REGISTER ... cseq=2107 ... >>> r_prep >> ← 带 Auth 重发
Jun 26 11:36:41.929327 opensips[530] 80000128@node-02.example.internal register_success ← ✅ 成功(域名短、contact 短,未撞 255)

关键观察:registrar:build_path_vector: Overall Path body exceeds max. length of 255 是这次故障的爆点——WebPhone 经 SBC(TCP,含 sip:sbc-01.example.internal:18627;transport=tcp 这类长 privatelink 域名)→ Edge(TCP↔UDP 转换)→ Core(UDP,registrar)多段转发,每段都会追加 Path,叠加 Edge 的 use_received=1 让每段 Path 再带上 received 参数,最终累计突破 registrar 模块硬编码的 255 B 上限,insert_contacts 失败,Core 回 503。对照组(AgentSimulator + 短域名 node-02.example.internal)的 Path body 仍在 255 以内,注册成功。


0. 原因分析

项目 值
故障现象 REGISTER Auth 通过但 contact 持久化失败,周期性 register_offline
爆点日志 registrar:build_path_vector: Overall Path body exceeds max. length of 255
次级错误 registrar:insert_contacts: failed to extract contact info
OpenSIPS 内部应答 reply_state=503 Service Unavailable(SBC 侧抓包可能见 400,中转改写)
上限来源 OpenSIPS registrar 模块源码硬编码(非协议层限制)
触发因素 SBC 配置的 Edge 地址过长(含 sbc-02.example.internal 长域名)+ Edge 段 use_received=1 让 Path 携带 received 参数 + 默认 enable_double_path=1 在某些路径上再叠一段
对照(成功) 80000128@node-02.example.internal + AgentSimulator,域名短、contact 短,Path body 未撞 255
修复 Edge 节点关闭二次 Path 追加:modparam("path", "enable_double_path", 0)

0.1 为什么 Auth 通过了却保存失败

OpenSIPS registrar 处理 REGISTER 分两步:

  1. Auth 校验(www_authenticate / proxy_authenticate)—— 只验证凭证,不查 Path
  2. Contact 持久化(save("...") → insert_contacts → build_path_vector)—— 这里才解析 Path body

本案例 Auth 已通过(日志 register_success),但 build_path_vector 发现 Path body 超 255,insert_contacts 失败,于是 register_offline、回 503。Auth 与 Path 校验是两条独立链路,前者通过不代表后者能过。

0.2 为什么 too_many_registered 是误报

503 之后日志接着打 Auth error! reason: too_many_registered + too_many_registered:66850 + metadata_has_raised flag is set, shouldn't duplicately state error。这不是真的注册量超限——metadata_has_raised 提示同一请求的错误状态已被置位,后续的 too_many_registered 只是状态机的次生标记。真正的失败原因仍是 Path 超 255。

0.3 为什么 AgentSimulator 案例能成功

  • 域名短:node-02.example.internal(10 字符)vs node-02.example.internal(17 字符)
  • Contact 形态:AgentSimulator 走 UDP,contact 简短;WebPhone 走 WebSocket(192.168.17.107:1055;transport=ws;ob),contact 含 ;ob 等额外参数
  • 累计差:几项叠加让对照组 Path body 仍在 255 以内,所以 register_success 不再被 register_offline 覆盖

1. 修复方案:关闭 Edge 段的二次 Path 追加

所述「255 上限」是 OpenSIPS registrar 模块对 Path body 的硬编码限制,并非 SIP 协议层面的限制。最简修复是减少 Path 累计——Edge 默认 enable_double_path=1 时会在已有 Path 之上再插一段;置 0 后不再叠加,Path body 长度回到 255 以内。

改动位置:edge-cfg 项目 opensips.cfg,紧贴现有 modparam("path", "use_received", 1)(line 92)之后。

opensips.cfg (line 92)

新增一行:

1
modparam("path", "enable_double_path", 0)

改动后效果(line 92~93 相邻):

1
2
modparam("path", "use_received", 1)
modparam("path", "enable_double_path", 0)

语义(OpenSIPS path 模块):enable_double_path=0 禁用第二个 Path 头的插入;Edge 收到带 Path 的 REGISTER 时不再叠加自己的 Path 段,最终到达 Core 的 Path body 长度回到 255 以内。

生效方式

1
2
3
4
# 滚动重启 Edge 节点 opensips
systemctl restart opensips
# 或热加载(若 edge-cfg 部署链路支持配置热加载)
opensips-cli -x mi reload opensips

该改动只作用于 Edge 段;Core 侧无需改动。SBC 侧也不需要改 privatelink 域名——长域名本身合法,只是触发了 registrar 的 Path 长度上限。


2. 验证修复

① 检查 opensips 进程是否正常拉起

1
2
systemctl status opensips
journalctl -u opensips -n 100 --no-pager | grep -iE "error|path|registrar"

期望无 modparam 解析错误,无 path.so 加载失败。

② 端到端验证:触发 WebPhone 重注册

1
tail -f /var/log/messages | grep -E "REGISTER|build_path_vector|insert_contacts|register_(success|offline)|location save error"
  • 修复前(本次故障):每次 WebPhone REGISTER 周期都看到 build_path_vector ... exceeds max. length of 255 → register_offline → reply_state=503
  • 修复后(期望):WebPhone REGISTER → 401 challenge → 200 OK,register_success 后无 register_offline / location save error

③ 数据库验证:contact 已写入 location 表

1
2
3
-- 在 Core 节点的 location 库执行
SELECT username, domain, contact, received, path FROM location
WHERE username = '80000001' AND domain = 'node-02.example.internal';

期望:能查到一行有效记录,path 字段非空且长度 < 255。修复前该查询要么无记录(被 register_offline 清掉),要么 path 字段残缺。

④ 抓包验证(可选,最可信)

1
2
# 在 Core 节点抓 Edge → Core 的 UDP REGISTER
tcpdump -i any -nn -A -s0 'udp port 5060 and (src host <edge_ip> or dst host <edge_ip>)' | grep -A2 -E "REGISTER|Path:"

期望:REGISTER 报文里只有一段 Path(修复前是两段叠加)。


3. RFC 与参考文档

3.1 SIP 协议规范(核心)

  • RFC 3261 — SIP: Session Initiation Protocol

  • RFC 3327 — SIP Extension Header Field for Registering Non-Adjacent Contacts

    • 定义 Path 头字段语义、add_path 行为、registrar 如何处理多段 Path
    • 本故障的直接协议依据——255 上限是 OpenSIPS 实现层限制,协议层并未规定
    • URL: https://www.rfc-editor.org/rfc/rfc3327
  • RFC 3608 — Session Initiation Protocol (SIP) Extension Header Field for Service Route Discovery

    • Path 与 Service-Route 的配合使用,后续 INVITE 路由依据

3.2 OpenSIPS 模块文档(实现层)

3.3 WebSocket / WebPhone 相关

  • RFC 7118 — The WebSocket Protocol as a Transport for SIP

4. 附录

4.1 关键日志锚点

内容 模块:函数 行号 说明
REGISTER 进入处理 OpenSIPS 业务日志 32670-32672 r_prep >> → processing → received REGISTER, Expired Time is 120
Auth challenge OpenSIPS 业务日志 32673-32674 Auth error! reason: no_credentials(首次未带 Auth)
上报 401 JSON 上报 32675 reply_state=401, reason=no_credentials
WebPhone 带 Auth 重发 OpenSIPS 业务日志 32676-32678 cseq=2
Auth 通过 registrar 业务日志 32679 register_success
Path 累计超长(爆点) registrar:build_path_vector 32680 Overall Path body exceeds max. length of 255
contact 持久化失败 registrar:insert_contacts 32681 failed to extract contact info
用户标记 offline registrar 业务日志 32682 register_offline
location save error 上层封装 32683 location save error: <contact>
最终 SIP 应答 JSON 上报 32684 reply_state=503(SBC 抓包可能见 400)
次生标记 registrar 32685-32687 too_many_registered(误报,非真实超限)

4.2 相关文档


© 2018–2026 小周周 · 使用 Stellar 构建

站内搜索

没有找到内容!