Skip to content

DDNS built into mr (Cloudflare, nothing resident) and Wake-on-LAN (#5, #7) - #71

Merged
Cd1s merged 1 commit into
mainfrom
feat/ddns-wol
Sep 25, 2026
Merged

Cd1s merged 1 commit into
mainfrom
feat/ddns-wol

Conversation

@Cd1s

@Cd1s Cd1s commented Sep 25, 2026

Copy link
Copy Markdown
Owner

What

DDNS (services.ddns, mr/mod_sys_ddns.go) — built into mr instead of a resident daemon.

  • Records: {name, zone, token_secret, ipv4: active | <wan> | off, ipv6: off | router | "::IID", ttl}. active = the healthy WAN with the lowest metric that has a public address; router = the router's own address from the delegated prefix; ::10 = that suffix on the LAN prefix (a NAS). Private (RFC 1918) and CGNAT (100.64/10) IPv4 is never published — the status says why.
  • Nothing waits in memory: WAN events start a sync through a new core hook Module.OnWAN(c, wan, event) (5 s debounce, flock), crond re-checks every interval minutes (default 10), an apply starts one (never fails the apply), 立即更新 / mr ddns update [--force].
  • Only on change: no request when the address is unchanged (a daily check asks the provider whether the record still holds it). Errors back off 1 → 60 min; a refused token stops that record until its config or token changes.
  • Cloudflare API v4: only content (and ttl if set) is patched — proxied flag, comments and tags stay; a missing record is created unproxied; records are never deleted. TLS verified against the image's CA bundle; ids validated before they go into a URL; answers capped; no redirects.
  • The token lives only in secrets.yaml and the request header: never in logs, the state file, mr ddns status, mr status or API answers (tested).
  • Web UI: DDNS card on the 服务 page (records, status, 立即更新). API sys.ddns (GET), sys.ddnsupdate (POST).
  • Left for 提议:DDNS 内置到 mr(不常驻) #5: other providers (each is one function in ddnsProviders), url: / fixed / mac: address sources, notifications, ACME reuse (提议:内置 HTTPS 反向代理 + 自动证书(mr-edge,DNS-01) #6).

Wake-on-LAN (mr/mod_sys_wol.go, #7): mr wol MAC|HOST [NETWORK], API sys.wol (POST), schedule action wol HOST; 唤醒 buttons on 终端设备 and DHCP 静态分配. The magic packet goes to the LAN network's broadcast address through its bridge only (SO_BINDTODEVICE) — it cannot leave through a WAN. No config, nothing resident.

Cost (arm64): DDNS ~61 KiB of code, WOL ~18 KiB; no resident RAM (crond runs while DDNS is on). Package-level patterns compile lazily (#8).

Why

The home router ran lucky (~50 MB RSS) mostly for DDNS; built-in DDNS that runs only on events and a cron tick is a step towards not needing it. WOL was a small, frequently requested feature.

Verification

  • Go tests: validation; crontab line on / off; the home config renders unchanged; address selection (CGNAT / private skipped); the Cloudflare client against an httptest server — no request when unchanged, backoff, refused token, daily repair of a hand-edited record, bad ids refused, unknown zone; WOL packet bytes, target resolution, a real send to a loopback listener.
  • CI (tools/ci.d/sys.sh): lab crontab lines for both; mr ddns status offline never shows the token; mr wol between two network namespaces — three exact packets from the router's address arrive at the LAN broadcast :9, nothing leaves on the WAN side.
  • Web UI checked in the mock UI (desktop, 360 px).
  • tools/ci.sh passes (private and public trees, clean remote checkouts).

Part of #5 · Closes #7

https://claude.ai/code/session_01HWeUjo1dmS7gBkCYHrVjCr

DDNS (services.ddns): records {name, zone, token_secret, ipv4: active|<wan>|off, ipv6: off|router|::IID,
ttl}. Runs as short `mr` invocations only: WAN events through a new core OnWAN hook (5 s debounce,
flock), crond every `interval` minutes, after an apply, 立即更新 / `mr ddns update`. The provider is
called only when the address changed (plus a daily check); errors back off 1..60 min, a refused token
stops the record until it changes. Cloudflare API v4: only content (and TTL) are patched, proxied /
comments / tags kept; missing records are created unproxied; nothing is deleted. Private / CGNAT IPv4
is never published. The token never appears in logs, state, status or API answers.

WOL: `mr wol MAC|HOST [NETWORK]`, API sys.wol (POST), schedule action wol; the magic packet goes to the
LAN network's broadcast address through its bridge only (SO_BINDTODEVICE), never a WAN. 唤醒 buttons on
终端设备 and DHCP 静态分配.

Tests (httptest Cloudflare, backoff, token never leaked, packet bytes) and CI (lab crontab lines,
`mr ddns status` offline, three WOL packets between network namespaces, nothing on the WAN side).

Part of #5
Closes #7
@Cd1s
Cd1s merged commit 6c6ec07 into main Sep 25, 2026
2 checks passed
@Cd1s
Cd1s deleted the feat/ddns-wol branch September 25, 2026 19:18
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.

提议:网络唤醒(WOL)

1 participant