vtun: wait for the network before starting, and pace the restart loop - #2406
vtun: wait for the network before starting, and pace the restart loop#2406openipc-ai wants to merge 1 commit into
Conversation
Reported in #2319: a camera that loses power comes back with vtund filling the whole 64KB syslog ring with vtund[21576]: syntax error line 5 vtund[21576]: No hosts defined and nothing else from that boot survives. It is not a name-resolution failure, despite where the report started. The session name is the MAC of the default-route interface, so on a boot that reaches here before the network is up, `ip r` matches nothing, identity_src is empty, `cat /sys/class/net//address` fails, and config() writes an empty session name -- which is line 5 of the file it generates. vtund says exactly what it is looking at and exits. The loop had no delay at all, so it did that as fast as the SoC allowed: 17 launches in two seconds in a stubbed run, two syslog lines each, which fills 64KB in under a minute. So identity() now reports that it has no identity instead of returning empty strings the caller cannot tell from a MAC, and the loop waits for one. The name half of the original report is real too -- vtund resolves the server itself and exits when it cannot -- so the wait covers that as well, reusing the literal-address test from /usr/sbin/wireguard so a numeric server never waits on a resolver it does not need. The remaining failures get a floor under their restart rate. vtund's own keepalive is 10:5, so it reconnects a live session by itself; this delay only paces the restarts it could not.
|
Unfortunately, all of my cameras are currently deployed in production and are remote, so I cannot reliably reproduce the conditions where the camera boots before the network is available or DNS is temporarily unavailable. I was able to test similar WireGuard behaviour when I had a test camera locally, but that camera is no longer available to me. The camera I used to test other issues today is also located in another country. One possible improvement, which may also make this and similar scripts easier to maintain, would be to extract the |
Problem
Reported by @usa- in #2319: after a power cut, a camera comes back with vtund filling the whole 64 KB syslog ring with the same two lines, so nothing else from that boot survives to be read.
It is not a name-resolution failure, despite where the report started. The session name is the MAC of the default-route interface:
On a boot that reaches
tunnelbefore the network is up,ip rmatches nothing,identity_srcis empty,cat /sys/class/net//addressfails, andconfig()writes an empty session name — which is line 5 of the file it generates. vtund names the line it is looking at and exits.The loop had no delay at all, so it did that as fast as the SoC allowed:
Two syslog lines per pass, no pause between passes, 64 KB gone in well under a minute.
What changes
One file,
general/package/vtund-openipc/files/tunnel.identity()reports that it has no identity instead of returning empty strings the caller cannot tell from a MAC, and the loop waits for one rather than writing a config it knows is broken./usr/sbin/wireguardso a numeric server never waits on a resolver it does not need.keepaliveis10:5, so it reconnects a live session by itself; this delay only paces the restarts it could not.tunnelalready backgrounds, so boot is not blocked.S98vtunis unchanged.At most two syslog lines per outage episode: one on entering the wait, one on leaving it.
Hardware tested on
None — I have no camera running vtund, which is why this is a draft. The Evidence below is a stubbed busybox-ash run and the repository's own checks, not a board. Someone with the reproducer from #2319 needs to confirm it on hardware before this is ready.
@usa- — you have both the fleet and the repro; would you try this one?
Evidence
Not from a camera.
vtund,ip,nslookupandloggerare shell stubs; the shell is the busyboxashthis tree builds. The scenario is "no default route yet", the #2319 boot.Before:
After:
The generated config, with the identity empty, showing what line 5 actually is:
The other three cases:
Repository checks:
Scope
general/package/all-patches/linux/(those go to OpenIPC/linux)general/overlay/or in a sharedload_<vendor>script hardcodes a value specific to my boardLD_PRELOAD, and no binaries that cannot be rebuilt from sourceThe unticked box is deliberate: this changes no
*_SITEand no*_VERSION, and vtund's existingSITEis sourceforge rather than an OpenIPC repository, so ticking it would claim something untrue.