Skip to content

Home Wi-Fi: mods' connections and their services' lookups get through - #420

Open
AwsomeFox wants to merge 7 commits into
wifi/wpa-checksumfrom
wifi/home-routing
Open

AwsomeFox wants to merge 7 commits into
wifi/wpa-checksumfrom
wifi/home-routing

Conversation

@AwsomeFox

@AwsomeFox AwsomeFox commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stack: 2 of 5, on #419 (same files). Review after #419.

Both found on an Ioniq 5 US 260507 (rc.10) with a test mod that downloads over Home Wi-Fi, once #419 let it join.

1. Mods' connections over Home Wi-Fi were refused

HMGAPI_CELL sits in filter OUTPUT with -o rmnet+ -m owner --gid-owner 2951 -j REJECT (and the home mods' uids). In OUTPUT, -o is the interface from the initial route lookup. HMG-API's mark comes later (mangle OUTPUT → reroute to table 95). A TCP connect to the internet first routes by the main table (default via rmnet0), so its SYN was rejected even though it would have left on wlan0. On the car: HMGAPI_CELL counted the rejected SYNs, and HMGAPI_HOMEOUT's MASQUERADE only matched DNS to the on-link router.

Fix (Network.java, wifi.sh):

  • With Home Wi-Fi on, the IPv4 REJECTs for the home group and the home mods' uids are gone from OUTPUT. Instead, mangle POSTROUTING → HMGAPI_HOMECELL: -o rmnet+ -m mark --mark 0x2951 -j DROP, after the reroute, so nothing marked ever leaves on mobile data.
  • Table 95 is never empty: unreachable default while Home Wi-Fi is down (keeper start, route_down), so marked traffic fails rather than falling through to the main table.
  • IPv6 isn't routed to Home Wi-Fi, so it stays refused in OUTPUT. With the switch off, everything stays as before.
  • mods_ok counts the new rule set and checks the POSTROUTING jump.

2. Services' DNS lookups never left the unit

A service runs with ANDROID_DNS_MODE=local. On these units that resolver has no servers in the service's process (they live in netd's cache), so bionic asks 127.0.0.1:53. HMGAPI_HOMEDNS DNATs those to Home Wi-Fi's server but the source stays 127.0.0.1, which the kernel won't route out of wlan0. Seen in nf_conntrack: src=127.0.0.1 dst=127.0.0.1 dport=53 [UNREPLIED] for every lookup.

Fix (wifi.sh, while Home Wi-Fi is up): route_localnet=1 on wlan0 (the queries are masqueraded by HMGAPI_HOMEOUT, so nothing leaves as 127.0.0.1), plus HMGAPI_HOMELO first in INPUT: -i wlan0 -d 127.0.0.0/8 only for ESTABLISHED,RELATED, everything else dropped, so the home network can't reach the unit's loopback services. Both come off in route_down.

Tested

  • homewifi-test.sh: 172 checks (the new rule sets, the unreachable default, route_localnet on and off, the guard). The fake ip learned route add and route show table N.
  • net-test.sh.
  • On the car, by hand: a root service's TCP connect with the mark on the socket worked end to end, and a raw DNS query to the router from the service was answered. The rule changes themselves haven't run on a car yet, and the reroute explanation is from the counters, not a packet trace (no tcpdump on the unit).
  • Not checked: cars with the stock whitelist firewall (iptrules, e.g. US Ioniq 6). Home Wi-Fi replies on wlan0 may need a rule there too; this PR doesn't change that.

Review follow-ups (Nov 30)

  • route_up: route_localnet goes to 0 before HMGAPI_HOMELO is flushed for a new DNS server, so 127/8 from wlan0 is never unguarded (tested: every flush sees 0).
  • HMGAPI_HOMECELL also drops the home group's (gid 2951) and the home apps' (uid) traffic on rmnet+ by owner, so the block holds without the mark; mods_ok checks those rules.
  • no_route() moved here from Home Wi-Fi: keep the car's Wi-Fi checksum in step, so the client starts #419.
  • The "no gap" wording now covers building the rules only: a repair (mods_fw_down; mods_up) still has a short gap, as before this PR.

🤖 Generated with Claude Code

Both found on an Ioniq 5 US 260507 (rc.10) with a mod that downloads over home Wi-Fi.

- Connections were refused. The mods' cellular block sat in filter OUTPUT, where -o is the route
  a packet had before HMG-API's mark (mangle OUTPUT) moved it to table 95: a connection whose
  first route was the main table's (mobile data) was rejected there, though it would have left
  on wlan0. With home Wi-Fi on, the IPv4 block for the home group and the mods that asked runs
  after the reroute instead (mangle POSTROUTING, HMGAPI_HOMECELL: nothing marked leaves on
  rmnet), and table 95 is never empty: an unreachable default while home Wi-Fi is down, so
  marked traffic fails rather than falling through to mobile data. IPv6, and everything with
  home Wi-Fi off, is refused in OUTPUT as before.
- A service's resolver (ANDROID_DNS_MODE=local) has no servers in its process and asks
  127.0.0.1:53. The DNAT to home Wi-Fi's server kept 127.0.0.1 as the source, which the kernel
  won't route out of wlan0. While home Wi-Fi is up: route_localnet on wlan0 (the queries are
  masqueraded by HMGAPI_HOMEOUT), and HMGAPI_HOMELO lets only answers come back in for 127.x.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox and others added 3 commits November 27, 2026 09:09
HMGAPI_HOMELO lets in, for 127.x on wlan0, only the DNS server's answers
(its address, port 53, established), and it is checked on every
route_up instead of only when the lease changes: the stock firewall
reloading flushes INPUT and can put its own jump first. route_localnet
is on only while the guard is first in INPUT; a guard that can't go in
is said and route_localnet stays off. The nat OUTPUT jump to
HMGAPI_HOMEDNS is checked on every pass too.

The network keeper builds the post-reroute DROP, the mark, masquerade,
table 95's unreachable default and the fwmark rule before the IPv4 home
REJECTs leave, and fills the cellular chain before OUTPUT jumps to it.
mods_ok also checks the DROP inside HMGAPI_HOMECELL. wifi.sh down,
net.sh down and the uninstaller take table 95's unreachable default
out.

The test's fake ip route replace/add now key routes as the kernel does
(table, destination, metric; not the type), so a default via the
gateway replaces the unreachable one.

Tested off-car only (homewifi-test.sh with bash, net-test.sh,
install/common/test.sh). Not yet checked on a car with the stock
whitelist firewall (US Ioniq 6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With SO_MARK alone a socket uses the main table (mobile data) until the
network keeper's fwmark rule is in; HMG-API's own downloads bind to
wlan0 too and fail if either is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwsomeFox
AwsomeFox marked this pull request as ready for review November 28, 2026 15:50
@AwsomeFox
AwsomeFox requested review from a team and VysseCodes as code owners November 28, 2026 15:50
@isaacwisdom
isaacwisdom added this pull request to stack #443 November 28, 2026 17:44
isaacwisdom
isaacwisdom previously approved these changes Nov 28, 2026

@isaacwisdom isaacwisdom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found.

@VysseCodes VysseCodes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three notes:

  1. Flush order in route_up: HMGAPI_HOMELO is flushed while route_localnet on wlan0 is still 1, so for a moment 127/8 from wlan0 isn't guarded. Please set route_localnet to 0 first, then flush.
  2. Cellular block by mark only: HMGAPI_HOMECELL drops -o rmnet+ traffic carrying mark 0x2951. If the mark rule goes missing (flushed, failed restore), home mods' traffic could reach cellular. Please also drop home mods' uids/gid on rmnet+ with an owner match, so the block holds without the mark.
  3. "No gap" claim: the repair path (mods_fw_down; mods_up) still leaves a short gap, as it did before this PR. Not a blocker, but please soften the claim in the description/comments or close that path too.

Merge order: after #419, before #422.

AwsomeFox and others added 2 commits November 30, 2026 16:36
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wner DROPs on rmnet, no_route here)

- route_up: route_localnet is set to 0 before HMGAPI_HOMELO is flushed for a new DNS server,
  so 127/8 from wlan0 is never unguarded (test: every flush sees 0).
- HMGAPI_HOMECELL also drops the home group's and the home apps' traffic on rmnet+ by owner,
  so the block holds if the mark rule is lost; mods_ok counts its rules.
- no_route() moves here from #419, which never called it.
- The comments and changelog no longer claim a repair has no gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit that referenced this pull request Nov 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit that referenced this pull request Nov 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwsomeFox

Copy link
Copy Markdown
Contributor Author

All three done in 32f9c50:

  1. route_up sets route_localnet to 0 before flushing HMGAPI_HOMELO. A new test checks every flush sees 0, and fails without the fix.
  2. HMGAPI_HOMECELL also drops the home group (gid 2951) and each home app's uid on rmnet+ by owner, so the block holds if the mark rule is gone. mods_ok counts those rules and rebuilds when one is missing (tested).
  3. The comments, changelog and description now say a repair still has a short gap. I didn't close that path here.

no_route() moved in from #419.

@amc2002

amc2002 commented Dec 2, 2026

Copy link
Copy Markdown

Data point from a US EV6 (CVEV, 260507) on HMG-API 1.1.0: a test mod with "wifi": {"home": true} showed Home Wi-Fi as up (rssi -30), plex.tv resolved fine, but every TCP connect to port 443 came back ECONNREFUSED. That looks like the HMGAPI_CELL reject you describe here, right? Joining through NEMESIS's Wi-Fi instead worked. Is there a test build of #419/#420 I could try? Happy to send logs.

…outing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit that referenced this pull request Dec 2, 2026
The only conflict was tools/test-all.sh: this branch's fetch-test.sh and
release/2.0's core/client/test.sh both go in ALL and FAST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

4 participants