Skip to content

feat: add IoT network routing through Tailscale (Allow Remote Access IoT) - #16

Open
schrodienieur wants to merge 1 commit into
RemoteToHome-io:mainfrom
schrodienieur:feat/iot-routing
Open

schrodienieur wants to merge 1 commit into
RemoteToHome-io:mainfrom
schrodienieur:feat/iot-routing

Conversation

@schrodienieur

@schrodienieur schrodienieur commented Aug 15, 2026 •

Copy link
Copy Markdown

Fixes #15

What

Adds the "Allow Remote Access IoT" toggle to the Tailscale Enhanced section, mirroring the existing Guest Network Access feature for the IoT zone (firmware 4.9+).

GL's "Advertise LAN Subnets" only covers the primary LAN. Smart-home devices on the AP-isolated IoT network (e.g. 192.168.10.0/24) were previously unreachable from tailnet devices.

Since v1.0.22 the kill switch covers the IoT zone, but not the remote-access side: advertising the IoT subnet and the iot ↔ tailscale0 forwardings. This adds those.

What it does

  • New "Allow Remote Access IoT" toggle in the plugin UI, shown on 4.9+ where GL creates the IoT network
  • Advertises the IoT subnet (br-iot) via tailscale set --advertise-routes
  • Creates iot <-> tailscale0 firewall forwardings (both directions)
  • Applies the same policy-route fixup as guest, so IoT clients can use the exit node and are covered by the kill switch's rule layer
  • Tears down cleanly on disable, Tailscale disable, or plugin removal

Files changed (12)

  • src/config/ts-fix — add route_iot option
  • src/scripts/ts-fix-reapply — IoT route advertise/remove, policy route, forwardings, teardown, reset (mirrors guest)
  • src/rpc/ts-fix — get_iot_subnet, update_iot_route, set_iot_ts_fw, fix_iot_policy_route, get_config/set_config wiring
  • src/www/ts-fix.js — "Allow Remote Access IoT" toggle row, tooltip, state, reapply + verify, firmware gating
  • pkg/prerm — IoT policy route + forwardings cleanup
  • README.md / pkg/control — feature and package description
  • tests/unit/test-iot-net.sh — new suite for the IoT helper and advertisement block
  • tests/unit/test-guest-net.sh, tests/unit/test-ks-armdisarm.sh, tests/unit/test-ts-state.sh, tests/README.md — extended to cover the IoT path (see notes below)

Notes for review

  • The IoT subnet comes from an iot_net helper (ipcalc.sh) beside the existing guest_net, not from zeroing the last octet, which is right only for a /24 and would miss GL's own from <net> rule on any other prefix.
  • The advertised-routes read is separated from the write, and its failure leaves the daemon-pending flag for the watchdog, so an unreadable list cannot be taken for "no routes" and drop every other advertised route. Route removal uses route_list_drop; the sed form it replaces failed on a subnet containing /.
  • route_list_drop moved into its own marked block. It was defined inside the guest_net block but is now used by both networks, so it no longer belongs to either one's helper block. Behaviour is unchanged.
  • test-guest-net.sh has two forced edits. extract() also pulls the route_list_drop block (it moved, and the suite still needs it for its drop cases), and the ipcalc.sh count is scoped to get_guest_subnet's body instead of the whole file, since a second network's helper makes a global count of 1 wrong. Nothing else in that file changed.
  • test-ks-armdisarm.sh changes are exact counts that the added calls made wrong: rules-ensure 2 → 3 in reapply and 1 → 2 in the RPC, tailscale set calls 10 → 15, and the bound total 17 → 25. No assertion was weakened.
  • The IoT row is hidden on pre-4.9 firmware, matching how the exit-node row is handled for the same split. There is no iot firewall zone to forward to on older firmware.

Verification

  • sh -n on the shell scripts, node --check on the injected JS, the Lua RPC module compiles
  • All 15 unit suites pass, including the new IoT suite and both legacy negative controls (7 DEFECT cases each fail against the pre-fix code, as intended)
  • ./pkg/build.sh 1.0.22 builds the ipk
  • Live-tested on a GL-BE6500 (firmware 4.9.0) running 1.0.22, with the plugin upgraded from 1.0.21: with the toggle on, the IoT subnet is advertised, the iot <-> tailscale0 forwardings and the destination-based policy rule are installed, and a device on 192.168.10.0/24 is reachable from a tailnet peer. Turning the toggle off removes the route, both forwardings and the policy rule while leaving the other advertised routes intact.
image

@remotetohome

Copy link
Copy Markdown
Contributor

Thanks for this PR. I replied on #15 with where it stands for v1.0.22 and v1.0.23: #15 (comment)

…IoT)

Rebased onto v1.0.22. GL's "Advertise LAN Subnets" only covers the primary
LAN, so smart-home devices on the AP-isolated IoT network were unreachable
from tailnet devices. This adds the remote-access side the kill switch
coverage in v1.0.22 does not provide: the IoT subnet route advertisement and
the iot <-> tailscale0 firewall forwardings.

Files:

- src/config/ts-fix: add the route_iot option.
- src/scripts/ts-fix-reapply: IoT route advertise/remove, policy route
  fixup, forwardings, teardown and reset, mirroring Route Guest.
- src/rpc/ts-fix: get_iot_subnet, update_iot_route, set_iot_ts_fw and
  fix_iot_policy_route, plus get_config/set_config wiring.
- src/www/ts-fix.js: the "Allow Remote Access IoT" toggle row, tooltip,
  state, reapply and verify.
- pkg/prerm: IoT policy route and forwarding cleanup on removal.
- README.md / pkg/control: feature and package description.
- tests/unit/test-iot-net.sh: new suite for the IoT helper and advertisement
  block, mirroring test-guest-net.sh.
- tests/unit: extend the existing Route Guest and kill switch suites to
  cover the IoT path.

Written against the v1.0.22 code rather than rebasing the v1.0.21 diff:

- The subnet comes from an iot_net helper (ipcalc.sh) beside the existing
  guest_net, not from zeroing the last octet, which is right only for a
  /24 and would miss GL's own "from <net>" rule on any other prefix.
- The advertised-routes read is separated from the write and its failure
  leaves the daemon-pending flag for the watchdog, so a failed read cannot
  be taken for "no routes" and drop every other advertised route. Route
  removal uses route_list_drop; the sed form failed on a subnet
  containing "/".
- Every tailscale CLI call runs under timeout 10 and logs its failure.
- route_list_drop moved into its own marked block. It was defined inside the
  guest_net block but is now called by both networks, so it belongs to
  neither one's helper block. Behaviour is unchanged.
- The kill switch moved to its own engine in v1.0.22, so this no longer
  installs ip rules of its own. The engine already covers iot
  (KS_SWAP_ZONES), and the disabled path re-asserts its rule layer via
  rules-ensure, the same way the guest path does.

Verified: sh -n on the scripts, node --check on the injected JS, the Lua
module compiles, all 15 unit suites pass (including both legacy negative
controls, whose 7 DEFECT cases each fail against the pre-fix code), and
./pkg/build.sh 1.0.22 builds the ipk.

Live-tested on a GL-BE6500 (firmware 4.9.0) running v1.0.22, with the plugin
upgraded from v1.0.21: with the toggle on, the IoT subnet advertises, the iot
<-> tailscale0 forwardings and the destination-based policy rule are installed,
and a device on 192.168.10.0/24 is reachable from a tailnet peer. Turning the
toggle off removes the route, both forwardings and the policy rule while
leaving the other advertised routes intact.
@schrodienieur

Copy link
Copy Markdown
Author

Thanks for this PR. I replied on #15 with where it stands for v1.0.22 and v1.0.23: #15 (comment)

Rebased onto 1.0.22 and force-pushed, 12 files changed, tested on GL-BE6500 4.9 firmware. Mind if you take a look when you get a chance?

@remotetohome

Copy link
Copy Markdown
Contributor

Sorry for the slow reply, @schrodienieur, and thanks for rebasing and testing on the BE6500. IoT routing is planned for v1.0.23 and your PR is the starting point for it. main has moved since (v1.0.22.1 shipped this week), so it now has conflicts. No need to rebase again yet: I'll pick it up from here when v1.0.23 work reaches it, with credit.

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.

Add IoT Network support like the existing Guest Network Access (advertise additional subnet)

2 participants