Skip to content

Feat/startup connectivity check - #2037

Open
leochien0102 wants to merge 3 commits into
fw876:devfrom
leochien0102:feat/startup-connectivity-check
Open

Feat/startup connectivity check#2037
leochien0102 wants to merge 3 commits into
fw876:devfrom
leochien0102:feat/startup-connectivity-check

Conversation

@leochien0102

Copy link
Copy Markdown

目的

路由器开机时 WAN 链路可能尚未就绪,主节点域名通过 get_host_ip() 解析失败,
导致服务显示"运行中"但实际无法转发流量。本 PR 在开机路径增加可配置的联网检测,
等网络就绪后再启动服务。

特性

  • 新增 startup_check UCI 段,在"高级设置"中可配置
  • 两种探测方式:DNS 解析(默认)和 ICMP ping
  • 可配置探测服务器、解析域名、重试次数与间隔
  • 仅门控开机路径(SSR_BOOT),手动重启、ssr-monitor 重启、组件升级不受影响
  • 超时后照常启动,不会无限阻塞开机
  • 未配置主节点(global_server=nil)时跳过等待;探测间隔最小 1s;IPv6 地址走 ping6
  • DNS 探测优先 nslookup(定向查询),缺失时回退 resolveip(netifd 自带)
  • 以本检测取代 99-ssrplus-pppoe hotplug 脚本(原逻辑为 PPPoE 拨号后固定 sleep 10s 重启,
    现改为对任意 WAN 类型都有效的真实就绪探测)

提交

  1. wait for internet connectivity before starting at boot
  2. harden the startup connectivity check
  3. fall back to resolveip for the startup DNS probe

…boot

At boot the service could start before the WAN link was usable. Node
domains then failed to resolve via get_host_ip(), leaving the service
"running" while no traffic could actually pass.

Add a configurable startup connectivity check that gates the boot path
only:

- New "startup_check" UCI section, exposed under Advanced Settings
- Two probe methods: DNS resolution (default) and ICMP ping. DNS matches
  what the service actually depends on at startup; ping cannot prove the
  resolver is ready
- Configurable probe servers, resolve domain, retry count and interval
- Runs from boot() only, gated by SSR_BOOT. Manual restarts, ssr-monitor
  restarts and component upgrades are never delayed: the node IP is
  already persisted in UCI by then, so the check would add nothing
- On timeout the service starts anyway, so the check can never block
  startup indefinitely

Also drop the 99-ssrplus-pppoe hotplug script. It slept a fixed 10s after
a PPPoE ifup and restarted the service, which this check supersedes with
an actual readiness probe that works on any WAN type, including
single-arm setups with no WAN interface at all.
- Skip the boot wait when no main node is configured: a nil
  global_server means the service has nothing to resolve at boot
- Use ping6 for IPv6 probe hosts, as busybox ping is IPv4-only
- Clamp a zero retry interval to 1s so the probe loop never spins
- Run the wait after check_run_environment so local environment
  problems surface before the network wait
busybox does not always ship the nslookup applet, so the startup
connectivity check could silently fail on minimal builds. Prefer
nslookup for a targeted query of the configured server and fall back
to resolveip, which ships with netifd and is always present, resolving
via the system resolver - the same path get_host_ip() uses at startup.
@zxlhhyccc

zxlhhyccc commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

@leochien0102 这个PR你测试了吗?没问题吧?

@leochien0102

leochien0102 commented Aug 19, 2026

Copy link
Copy Markdown
Author

@leochien0102 这个PR你测试了吗?没问题吧?

@zxlhhyccc
我家里是x86的PVE虚拟机跑,WAN做PPPoE的,单位是Rockchip,WAN跑静态地址,都可以,也做了设置项,不需要可以关闭此功能。
PixPin_2026-08-19_08-04-30

以下是单位设备这里的启动日志,3次等待,网络通了才启动SSRP
2026-08-12 16:00:43: -----------end------------
2026-08-12 16:00:40: ChinaDNS-NG query and cache Started!
2026-08-12 16:00:40: ssr-rules: Using iptables

2026-08-12 16:00:39: gfw2ipset: Using iptables
2026-08-12 16:00:38: Main node:Xray 26.6.1 (Xray, Penetrates Everything.) OpenWrt (go1.26.4 linux/arm64) Started!
2026-08-12 16:00:36: Internet is reachable via 223.5.5.5 (dns, attempt 4)
2026-08-12 16:00:34: Waiting for internet access... (3/30)
2026-08-12 16:00:32: Waiting for internet access... (2/30)
2026-08-12 16:00:30: Waiting for internet access... (1/30)
2026-08-12 16:00:30: ----------start------------
2026-08-12 16:00:30: boot!

@zxlhhyccc

Copy link
Copy Markdown
Collaborator

@leochien0102 明天我来测试一下,没问题我将合并。

@leochien0102

Copy link
Copy Markdown
Author

补一个x86+PPPoE场景的日志

2026-08-22 12:28:07: gfw2ipset: Using iptables
2026-08-22 12:27:45: -----------end------------
2026-08-22 12:27:42: ChinaDNS-NG query and cache Started!
2026-08-22 12:27:42: ssr-rules: Using iptables
2026-08-22 12:27:41: gfw2ipset: Using iptables
2026-08-22 12:27:41: Main node:Xray 26.6.1 (Xray, Penetrates Everything.) OpenWrt (go1.26.5 linux/amd64) Started!
2026-08-22 12:27:40: Internet is reachable via 223.5.5.5 (dns, attempt 10)
2026-08-22 12:27:38: Waiting for internet access... (9/30)
2026-08-22 12:27:36: Waiting for internet access... (8/30)
2026-08-22 12:27:34: Waiting for internet access... (7/30)
2026-08-22 12:27:32: Waiting for internet access... (6/30)
2026-08-22 12:27:30: Waiting for internet access... (5/30)
2026-08-22 12:27:28: Waiting for internet access... (4/30)
2026-08-22 12:27:26: Waiting for internet access... (3/30)
2026-08-22 12:27:24: Waiting for internet access... (2/30)
2026-08-22 12:27:22: Waiting for internet access... (1/30)
2026-08-22 12:27:22: ----------start------------
2026-08-22 12:27:22: boot!

@zxlhhyccc

zxlhhyccc commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

@leochien0102 为什么不会检测?
image
image

@leochien0102

Copy link
Copy Markdown
Author

@leochien0102 为什么不会检测? image image

只在启动设备时会有这个等待,如果已经手动重启(修改配置或者更换节点之类的),不会触发等待,因为这种情况下,网络基本上是已经通了的。在设备启动时,会出现在网络还未连通时启动ssrp,此时ssrp状态显示运行中,但实际无法连接的情况。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants