mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 08:02:40 +00:00
Users' reports: the region probe never reads past the eMMC, RNDIS joins the bridge first, fw4's LAN rules on 5.4
Three defects users measured (FINDINGS 38): - #43, #52, #65: on an F50 whose partition table ends at the end of the eMMC, region_probe gave a region of -4 MiB whose superblock lies 2 bytes past the last sector, and the dd that probed it never returned (100 % of a core, immune to kill -9, the SoC at 97 C). The legacy offset 27762098176 was read beyond a 32 GB eMMC the same way. storage.sh (install.sh, uninstall.sh, reset-password.sh, the Magisk installer) and install.ps1: a region whose boundaries cross is empty, and a candidate superblock is read only when it lies on the disk. test_installer.Region runs that layout and checks no dd crosses the disk's end. - #45 (MRWOODEN's fix, applied as sent): the LAN hook enslaved rndis0 after taking the bridge's address off the ports, so a system switched to RNDIS after the install had the LAN address on br-lan and on rndis0 and served nobody. rndis0 joins the bridge first; after the gadget's re-enumeration the netdevs are bridged again. - #67 (and #61 by its symptoms): on 5.4 fw4's reload on every ifup failed ("flowtable ft: Resource busy": the kernel counts a flowtable the same transaction deleted), so the S19 ruleset - rendered before br-lan and sipa_eth0 existed, with no LAN input rules and no masquerade - stayed for the whole boot: no DHCP, no LuCI, no NAT. 90-mu300 names the lan and wan zones' devices once, so the boot ruleset is complete; a new hotplug.d/iface/19-mu300-fw4 deletes the stale flowtable on 5.4 before 20-firewall's reload. README: the two symptoms under Common problems. FINDINGS 38d: #20 was fixed in 31f (v2026.10.11), #64 is relay plus NAT66 by design. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kz6fYVH558tbiDCYWXcuSa
This commit is contained in:
1 parent
94e71e2b39
commit
bde23d0033
11 files changed
+300
-13
No files matched your search
@@ -697,6 +697,17 @@ tell them apart.
|
||||
**No internet.** Check that the SIM has a data plan, then run `sudo mobile-data status`. A missing plan looks like a
|
||||
connection that keeps dropping.
|
||||
|
||||
**OpenWrt on kernel 5.4: no address, no web interface, nothing connects to the hotspot** (releases up to
|
||||
v2026.10.11). The firewall's boot ruleset had no rules for the LAN, and on 5.4 the reload that should have added them
|
||||
always failed ([FINDINGS 38c](docs/FINDINGS.md)). Fixed from the next release; until then the USB serial console
|
||||
(`ttyGS0`, a root shell) is the way in, and `nft delete flowtable inet fw4 ft; fw4 reload` brings the LAN up. On
|
||||
5.4 a firewall change saved in LuCI still needs those two commands (or a reboot) to take effect.
|
||||
|
||||
**The installer prints nothing for minutes and the device gets hot.** A read past the end of the eMMC never
|
||||
returned on devices whose partition table ends at the end of the disk (the 32 GB variant and an F50 with no gap
|
||||
behind `userdata`; [FINDINGS 38a](docs/FINDINGS.md)). Fixed from the next release; reboot the device to end the
|
||||
stuck reads, then install with the new installer.
|
||||
|
||||
**Kernel warnings are not in `journalctl -k`.** On Ubuntu they are in `journalctl -t kernel` (warnings and errors
|
||||
only, from the start of each boot, with the kernel's own timestamps; repeating vendor chatter is left out, see
|
||||
`/etc/mu300/kmsg-ignore`). Everything else is in `dmesg`.
|
||||
|
||||
@@ -97,6 +97,10 @@ what replaced it. The table below gives each section's state.
|
||||
| 35 | kanoqwq's fixes, measured | current (panel languages: PR #48) |
|
||||
| 36 | Power profiles: idle radios, the charging boot, the charge guard | current; power table and device questions open (PR #62) |
|
||||
| 37 | System suspend | current (fixes on branch `suspend-drivers`); power not measured |
|
||||
| 38 | Three defects from users' reports, 2026-10-07 | current |
|
||||
| 38a | A read past the end of the eMMC never returns | current (fixed) |
|
||||
| 38b | RNDIS: the port kept the bridge's address | current (fixed) |
|
||||
| 38c | fw4 on 5.4: the boot ruleset without the LAN, and a reload that always fails | current (fixed at boot; a reload by hand still needs the flowtable deleted first) |
|
||||
|
||||
## Hardware and firmware facts
|
||||
|
||||
@@ -2946,3 +2950,108 @@ Logs of every run stayed on F50-B under `/root/susp/` (the spike: `*.log`, dmesg
|
||||
the two panic records) and `/root/susp2/` (the follow-up, with the scripts that ran them). F50-B was left on the
|
||||
6.18.55 build of branch `suspend-drivers` (radio on, Wi-Fi client, one more 20 s `mem` checked). The 7.2.9
|
||||
build of the branch compiles, kernel and all modules; it has not been booted yet.
|
||||
|
||||
## Users' reports
|
||||
|
||||
### 38. Three defects from users' reports, 2026-10-07
|
||||
|
||||
Three issues came in with their own measurements, two of them with the fix; what follows is what was taken from
|
||||
them, checked against the code, and what the release carries.
|
||||
|
||||
#### 38a. A read past the end of the eMMC never returns (#43, #52, #65)
|
||||
|
||||
Every installer probes the free region for an existing `mu300root` with three tiny reads of its superblock:
|
||||
`dd if=/dev/block/mmcblk0 bs=1 skip=$((OFF + 1080)) count=2`, where `OFF` is the first 2 MiB boundary behind
|
||||
the last partition, and once more at the fixed offset of the first releases, 27762098176. On the F50 of #65 the
|
||||
partition table ends 2 MiB before the end of the eMMC (61079552 sectors, the last partition ends at 61075456), so
|
||||
the first boundary behind it *is* the end of the disk, the last boundary before the backup GPT lies before it,
|
||||
and `region_probe`'s arithmetic gave a region of -4 MiB (the same number issue #32 had seen) whose superblock
|
||||
starts 2 bytes past the last sector. The eMMC driver of this device never completes a read past its end: the
|
||||
`dd` stays runnable at 100 % of one core, survives `kill -9`, and every retry adds another one - four of them
|
||||
held the SoC at 97 °C in #65 until a reboot. #52 (the Magisk installer, OpenWrt to the card) showed the same
|
||||
`dd` at byte 31272731704, which is that very offset; #43 had pinned the installer's silence to
|
||||
`region_find_existing` without seeing why. The legacy offset is the same trap on the 32 GB variant: it lies
|
||||
beyond that eMMC altogether and was read all the same.
|
||||
|
||||
Fixed in `tools/storage.sh` (which `install.sh`, `uninstall.sh`, `tools/reset-password.sh` and the Magisk
|
||||
installer share) and in `install.ps1`: a region whose boundaries cross is an empty one (`SIZE=0`; the installers
|
||||
then offer the card or the repartitioning, as they do for any region that is too small), and a candidate
|
||||
superblock is read only when it lies on the disk (`region_on_disk`, `RegionOnDisk`). The SD-card installation of
|
||||
#52 and #65 goes through without a single read past the end. `tests/test_installer.py` (`Region`) runs the
|
||||
layout of #65 against the functions and checks that no `dd` crosses the disk's last byte.
|
||||
|
||||
Not taken from #65: a wall-clock limit around every device command in `install.ps1`, and a port of
|
||||
`sd_release` to the host side. The card is released on the device, by `tools/android-install.sh`, before
|
||||
anything is written to it (both installers run that script); the reads before it only look at the card. The
|
||||
limit is worth having for the day another request is lost, but it is the larger change and is not needed once
|
||||
nothing is read past the end.
|
||||
|
||||
#### 38b. RNDIS: the port kept the bridge's address (#45)
|
||||
|
||||
An OpenWrt system installed with NCM (the default) and switched to RNDIS later has `usb0` in its bridge section
|
||||
and not `rndis0`; the LAN hook (`hotplug.d/iface/10-mu300-usb`, K9/K27) puts `rndis0` into `br-lan` on every LAN
|
||||
ifup. It did that *after* the loop that takes the early server's address off the bridge's ports, and that loop
|
||||
only looks at ports: `rndis0` was not one yet, kept `192.168.77.1/24`, and then became a port - the bridge and
|
||||
one of its ports with the same address, two equal routes, and the device could not reach its own Wi-Fi client
|
||||
nor the USB host, with the serial console the only way in. MRWOODEN measured it on an F50 (6.18, `openwrt-luci`,
|
||||
Windows without `UsbNcm.sys`) and sent the fix: join first, then take the address off; and after the hook's own
|
||||
re-enumeration of the gadget (K10), which destroys the function's netdev and binds a new one, put the gadget
|
||||
netdevs back into the bridge, since netifd re-adds a port it has in its configuration (`usb0`) and never one it
|
||||
never had. Applied as sent, with the regression test (`test_early_dhcp`: the RNDIS netdev that is not a port
|
||||
yet). Verified on the reporter's device: `br-lan` the only holder of the address, both the Wi-Fi client and the
|
||||
USB host served by the one `dnsmasq`, `rndis0` still a port after the rebind.
|
||||
|
||||
#### 38c. fw4 on 5.4: the boot ruleset without the LAN, and a reload that always fails (#67, #61)
|
||||
|
||||
AgentFan0315 took a fresh `openwrt-luci` on 5.4 (v2026.10.11) apart layer by layer: Wi-Fi and USB clients
|
||||
associate, their DHCP requests enter the kernel (an ingress counter on `wlan0` climbs), and die before any rule:
|
||||
the live `inet fw4` table has no `iifname "br-lan" jump input_lan` and no `srcnat_wan` jump, while `fw4 print`
|
||||
renders both. Two things stack:
|
||||
|
||||
1. fw4 renders a zone's rules from the devices its networks have *at the time*. S19 `firewall` runs before S20
|
||||
`network`, so at boot neither `br-lan` nor the modem's `sipa_eth0` exists, and the LAN's input rules and
|
||||
the wan's masquerade are left out of the first ruleset - to be filled in by the reload that every ifup
|
||||
triggers (`hotplug.d/iface/20-firewall`). That is how plain OpenWrt works too.
|
||||
2. On 5.4 that reload fails. fw4 replaces its ruleset in one transaction (`flush table inet fw4`, or `delete
|
||||
flowtable inet fw4 ft`, then the table again with its flowtable `ft`). The 5.4 kernel refuses a flowtable that
|
||||
names a device another flowtable of the same table has, and it counts the one the same transaction has just
|
||||
deleted: that one leaves the table's list only at the commit, and 5.4's `nf_tables_newflowtable` walks the
|
||||
list without regard to the pending deletion (the check skips inactive entries from 5.13 on). `flowtable ft {
|
||||
... } Error: Resource busy`, the whole transaction is rejected, and the S19 ruleset stays. The flowtable exists
|
||||
from S19 on because the `earlyusb` zone names `usb0`, which init has made by then, and fw4 puts every zone
|
||||
device into `ft`. The first ruleset is therefore the one with the flowtable and without the LAN, and nothing
|
||||
after it can replace it. Deleting the flowtable on its own (`nft delete flowtable inet fw4 ft`), in a
|
||||
transaction that is committed before the reload, is enough: the reload then creates it afresh.
|
||||
|
||||
So the LAN had no DHCP, no LuCI and no NAT on every boot of a 5.4 `openwrt-luci`, which is also what #61 reports
|
||||
(installed with 5.4 and the panel: detected as a USB network, "no ssh and no webui", Wi-Fi visible but nothing
|
||||
connects; the serial console at `ttyGS0` is the way to `mu300-next-boot android` in that state). The mainline
|
||||
kernels update a flowtable in place and were never affected, which is why the maintainer's own tests (31, 35,
|
||||
on 6.18 and 7.2) did not see it.
|
||||
|
||||
Two fixes, both in `openwrt/overlay`:
|
||||
|
||||
* `uci-defaults/90-mu300` names the devices of the `lan` and `wan` zones (`br-lan`, `sipa_eth0`) next to their
|
||||
networks, once, on every system (the reporter's workaround, the pattern of the `earlyusb` zone): the S19
|
||||
ruleset is complete whatever the reloads do. Verified by the reporter across reboots.
|
||||
* `hotplug.d/iface/19-mu300-fw4`, on a 5.4 kernel only, deletes the stale flowtable right before 20-firewall's
|
||||
reload, under the same conditions 20-firewall reloads on: an ifup of an interface that is in a zone. The reload
|
||||
succeeds; the offloaded flows of the moment take the ordinary path until the flowtable is back.
|
||||
|
||||
Not covered on 5.4: a reload that is not an ifup's - the firewall saved in LuCI, `fw4 reload` by hand - still
|
||||
fails while the flowtable is there. Until a cleaner hook is found (the flowtable deleted from fw4's own reload
|
||||
path), the way to apply a firewall change on 5.4 is `nft delete flowtable inet fw4 ft; fw4 reload`, or a reboot.
|
||||
Turning software flow offloading off would end that, at the cost of the fast path on the one kernel that has
|
||||
none other.
|
||||
|
||||
#### 38d. Reports that were already fixed, or are not defects
|
||||
|
||||
* #20 (soft lockup in `sipa_dele`, `get pd fail ret = 1` at 149 lines a second, 6.18.54 of 2026-09-28): the
|
||||
vendor loop that retried `pm_runtime_get_sync()` every millisecond and took its `1` (already active) for a
|
||||
failure - §31f, fixed on 2026-10-05 and in v2026.10.11's 6.18 bundle.
|
||||
* #64 (IPv6: relay or NAT66?): both, on purpose. The `openwrt-luci` system relays the carrier's RA and DHCPv6 to
|
||||
the LAN (clients get public addresses from the bearer's /64) *and* masquerades v6 egress through the device's
|
||||
own address (`masq6`, `91-mu300-luci`, K30), because the carrier routes one address per bearer and replies to a
|
||||
client's public address would otherwise not come back; `ndp-learn` routes the /64 to `br-lan` for the same
|
||||
reason. The `masq '1'` of the wan zone is IPv4 only (fw4's `masq6` is the v6 one). Plain OpenWrt keeps `extend`
|
||||
and neither.
|
||||
@@ -424,6 +424,9 @@ if ($parts.Count -ne 2) { Die (T 'could not read the partition table from the de
|
||||
[int64]$lastEnd = $parts[0]; [int64]$disk = $parts[1]
|
||||
[int64]$start = [math]::Floor($lastEnd / 4096 + 1) * 4096
|
||||
[int64]$end = [math]::Floor(($disk - 34) / 4096 - 1) * 4096
|
||||
# A partition table that ends at the end of the eMMC (issue #65): the boundaries cross, and a negative size is not
|
||||
# a region but an empty one (the card is offered instead), whose start is never read (RegionOnDisk).
|
||||
if ($end -le $start) { $end = $start }
|
||||
[int64]$OFF = $start * 512
|
||||
[int64]$SIZE = ($end - $start) * 512
|
||||
function Gib([int64]$b) { '{0:N1} GiB' -f ($b / 1GB) }
|
||||
@@ -546,8 +549,14 @@ if ($SD_MODE -eq 0 -and $SIZE -lt 700MB) {
|
||||
Die ((T 'only {1} MiB of free space after the last partition: this device has a different layout, nothing is changed.' $mib) + "`n" + (T 'Please report the numbers above (eMMC size and where the partitions end); they identify the variant.'))
|
||||
}
|
||||
|
||||
# Whether the ext4 superblock of a region at BYTES (its second KiB) lies on the eMMC. A read past the end of the disk
|
||||
# never returns on this device: the dd spins on one core, survives kill -9 and heats the SoC until a reboot (issues
|
||||
# #43, #52, #65: a 32 GB eMMC whose table ends at its end puts the region's start at the disk's end, and the fixed
|
||||
# offset of the first releases lies beyond a 32 GB eMMC altogether).
|
||||
function RegionOnDisk([int64]$bytes) { [math]::Floor(($bytes + 2048) / 512) -le $disk }
|
||||
$existing = 'no'
|
||||
foreach ($cand in @($OFF, 27762098176)) {
|
||||
if (-not (RegionOnDisk $cand)) { continue }
|
||||
$m = (SuDo "dd if=/dev/block/mmcblk0 bs=1 skip=$($cand + 1080) count=2 2>/dev/null | od -An -tx1") -replace '\s', ''
|
||||
$l = (SuDo "dd if=/dev/block/mmcblk0 bs=1 skip=$($cand + 1144) count=16 2>/dev/null") -replace '\0', ''
|
||||
if ($m -eq '53ef' -and $l.Trim() -eq 'mu300root') {
|
||||
|
||||
@@ -8,6 +8,16 @@
|
||||
# through the wrong device and the host cannot even ping br-lan. It is taken off a bridge port only when it is the
|
||||
# bridge's own, after netifd has put that on br-lan. And rndis0: an installed system's bridge section may predate a
|
||||
# switch to RNDIS, so it is put back into br-lan on every LAN ifup (a network reload too).
|
||||
#
|
||||
# The gadget's netdev joins the bridge before anything is taken off it: the loop below can only take the address
|
||||
# off a port that already is one. The other way round (until 2026-10-07), rndis0 - which an install that switched
|
||||
# to RNDIS later does not have in its bridge section - was not a port yet when the loop ran, kept the address
|
||||
# while br-lan held the same one, and neither the Wi-Fi clients nor the USB host could use the LAN (issue #45,
|
||||
# measured on a user's F50; the serial console was the only way in).
|
||||
if [ -e /sys/class/net/rndis0 ]; then
|
||||
ip link set rndis0 master br-lan 2>/dev/null
|
||||
ip link set rndis0 up 2>/dev/null
|
||||
fi
|
||||
pid=$(cat /run/mu300-early-udhcpd.pid 2>/dev/null)
|
||||
[ -n "$pid" ] && kill "$pid" 2>/dev/null
|
||||
rm -f /run/mu300-early-udhcpd.pid
|
||||
@@ -22,10 +32,6 @@ if [ -n "$bridge_ip" ]; then
|
||||
ip addr del "$nic_ip" dev "$nic" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
if [ -e /sys/class/net/rndis0 ]; then
|
||||
ip link set rndis0 master br-lan 2>/dev/null
|
||||
ip link set rndis0 up 2>/dev/null
|
||||
fi
|
||||
|
||||
# The ECM gadget was bound in the initramfs; macOS keeps the link inactive after netifd reconfigures usb0
|
||||
# (at boot and on every network restart). Re-enumerate the gadget whenever the LAN comes up, at most every 20 s,
|
||||
@@ -46,4 +52,13 @@ udc=$(cat $g/UDC)
|
||||
echo "" > $g/UDC 2>/dev/null
|
||||
sleep 1
|
||||
echo "$udc" > $g/UDC && logger -t mu300 "usb gadget re-enumerated on $udc"
|
||||
# The rebind took the function's netdev away and bound a new one, which has to be a bridge port again, or the
|
||||
# USB host is left on a bare netdev with no server (the early one is gone) and no LAN. netifd puts back a port
|
||||
# that is in its configuration (usb0), never one it never had (rndis0) - issue #45.
|
||||
sleep 1
|
||||
for nic in usb0 rndis0; do
|
||||
[ -e /sys/class/net/$nic ] || continue
|
||||
ip link set "$nic" master br-lan 2>/dev/null
|
||||
ip link set "$nic" up 2>/dev/null
|
||||
done
|
||||
) &
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# MU300, the 5.4 kernel: fw4's stale flowtable goes before the reload that 20-firewall runs on this ifup.
|
||||
#
|
||||
# fw4 replaces its ruleset in one transaction - "flush table inet fw4" (or "delete flowtable inet fw4 ft"), then
|
||||
# the table again, its flowtable ft included. The 5.4 kernel refuses a flowtable that names a device another
|
||||
# flowtable of the table has, and it counts the one the same transaction just deleted: that one leaves the table's
|
||||
# list only at the commit, and 5.4's nf_tables_newflowtable takes no notice of the pending deletion (the check
|
||||
# skips inactive entries from 5.13 on). So "flowtable ft { ... } Error: Resource busy", the transaction fails, and
|
||||
# the ruleset on the device stays the one fw4 rendered at S19 - before netifd made br-lan and the modem's
|
||||
# sipa_eth0 - with no input rules for the LAN and no masquerade (issue #67; #61 looks the same: no DHCP, no LuCI,
|
||||
# no SSH, only the serial console). The flowtable deleted here, in a transaction of its own, is simply re-created
|
||||
# by the reload, which then succeeds; the offloaded flows take the ordinary path until it is back, nothing else
|
||||
# changes. Only when the reload is coming (the same conditions as 20-firewall's), and only on 5.4: the mainline
|
||||
# kernels update a flowtable in place and need none of this.
|
||||
#
|
||||
# Not covered: a reload that is not an ifup's - the firewall saved in LuCI, "fw4 reload" by hand - still fails on
|
||||
# 5.4 while the flowtable is there (docs/FINDINGS.md 38): "nft delete flowtable inet fw4 ft; fw4 reload".
|
||||
[ "$ACTION" = ifup ] || exit 0
|
||||
case $(uname -r) in 5.4.*) ;; *) exit 0 ;; esac
|
||||
/etc/init.d/firewall enabled 2>/dev/null || exit 0
|
||||
fw4 -q network "$INTERFACE" >/dev/null 2>&1 || exit 0
|
||||
nft list flowtables inet fw4 2>/dev/null | grep -q 'flowtable ft ' || exit 0
|
||||
nft delete flowtable inet fw4 ft 2>/dev/null && logger -t mu300 "fw4 flowtable deleted before the reload (5.4 kernel, ifup $INTERFACE)"
|
||||
exit 0
|
||||
@@ -99,6 +99,17 @@ if ! uci -q show firewall | grep -q "^firewall\.@zone\[[0-9]*\]\.name='earlyusb'
|
||||
uci set firewall.$early.output='ACCEPT'
|
||||
uci set firewall.$early.forward='REJECT'
|
||||
fi
|
||||
# Issue #67: the lan and wan zones name their devices, not only their networks. fw4 renders a zone's rules from
|
||||
# the devices its networks have at the time, and S19 firewall runs before S20 network: on the boot ruleset neither
|
||||
# br-lan nor the modem's sipa_eth0 exists yet, so the LAN's input rules and the wan's masquerade are left out, for
|
||||
# the reload every ifup triggers to fill in. On the 5.4 kernel that reload failed (hotplug.d/iface/19-mu300-fw4),
|
||||
# and the device came up with no DHCP, no LuCI and no NAT on every boot (#67; #61 looks the same). With the devices
|
||||
# named, the boot ruleset is complete whatever the reloads do. Added to a zone that lacks its device; once.
|
||||
for zd in lan:br-lan wan:sipa_eth0; do
|
||||
zone=$(uci -q show firewall | sed -n "s/^\(firewall\.@zone\[[0-9]*\]\)\.name='${zd%:*}'$/\1/p" | head -1)
|
||||
[ -n "$zone" ] || continue
|
||||
case " $(uci -q get $zone.device) " in *" ${zd#*:} "*) ;; *) uci add_list $zone.device="${zd#*:}" ;; esac
|
||||
done
|
||||
# LuCI's language (both systems) is English, not "auto" (which follows the browser): once, with its own marker
|
||||
# luci.mu300.lang, so a language the user picks later stays through every update. A system from before the marker
|
||||
# that still says "auto" (or nothing) gets English too: auto was nobody's choice there (luci-base's default, and
|
||||
|
||||
@@ -238,7 +238,8 @@ class EarlyUsbOpenWrt(ShellTest):
|
||||
self.tearDown(); self.setUp()
|
||||
|
||||
# --- hotplug iface/10-mu300-usb (K9; K10 rejected: the re-enumeration stays)
|
||||
def hotplug(self, shell, stamp_age=None, bridge='10.1.2.1/24', port='10.1.2.1/24'):
|
||||
def hotplug(self, shell, stamp_age=None, bridge='10.1.2.1/24', port='10.1.2.1/24', rndis_port='yes',
|
||||
rndis_addr=''):
|
||||
(self.tmp / 'run' / 'mu300-early-udhcpd.pid').write_text('4242\n')
|
||||
(self.tmp / 'uptime').write_text('100.50 90.00\n')
|
||||
(self.tmp / 'mounts').write_text(f'configfs {self.tmp}/cfg configfs rw 0 0\n')
|
||||
@@ -247,13 +248,19 @@ class EarlyUsbOpenWrt(ShellTest):
|
||||
(g / 'UDC').write_text('25100000.dwc3\n')
|
||||
if stamp_age is not None:
|
||||
(self.tmp / 'stamp').write_text(f'{100 - stamp_age}\n')
|
||||
# usb0 kept the bridge's address; rndis0 is in the bridge without it
|
||||
# usb0 kept the bridge's address; rndis0 is in the bridge without it - unless the test says otherwise:
|
||||
# RNDIS_PORT=no is a rndis0 that is not a bridge port until the hook makes it one (the stub remembers the
|
||||
# enslavement), RNDIS_ADDR an address preinit left on it (issue #45)
|
||||
self.stub('ip', 'echo "ip $*" >> "$STUBLOG/ip.log"\n'
|
||||
f'rp={rndis_port}; grep -q "^ip link set rndis0 master br-lan$" "$STUBLOG/ip.log" && rp=yes\n'
|
||||
'case "$*" in\n'
|
||||
f'"-4 -o addr show dev br-lan") echo "9: br-lan inet {bridge} scope global br-lan" ;;\n'
|
||||
'"-o link show dev usb0"|"-o link show dev rndis0") echo "7: $5: <UP> mtu 1500 master br-lan state UP" ;;\n'
|
||||
'"-o link show dev usb0") echo "7: usb0: <UP> mtu 1500 master br-lan state UP" ;;\n'
|
||||
'"-o link show dev rndis0") [ "$rp" = yes ] && echo "8: rndis0: <UP> mtu 1500 master br-lan state UP" ||'
|
||||
' echo "8: rndis0: <UP> mtu 1500 state UP" ;;\n'
|
||||
f'"-4 -o addr show dev usb0") echo "7: usb0 inet {port} scope global usb0" ;;\n'
|
||||
'esac')
|
||||
f'"-4 -o addr show dev rndis0") [ -n "{rndis_addr}" ] && echo "8: rndis0 inet {rndis_addr} scope global rndis0" ;;\n'
|
||||
'esac\nexit 0')
|
||||
body = self.text('etc/hotplug.d/iface/10-mu300-usb', **{
|
||||
'/run/': f'{self.tmp}/run/', '/sys/class/net/': f'{self.tmp}/net/', '/tmp/mu300-usb-rebound': f'{self.tmp}/stamp',
|
||||
'/sys/kernel/config': f'{self.tmp}/cfg', '/proc/uptime': f'{self.tmp}/uptime', '/proc/mounts': f'{self.tmp}/mounts'})
|
||||
@@ -279,6 +286,23 @@ class EarlyUsbOpenWrt(ShellTest):
|
||||
self.assertEqual('25100000.dwc3', (g / 'UDC').read_text().strip())
|
||||
self.tearDown(); self.setUp()
|
||||
|
||||
def test_rndis_joins_the_bridge_before_its_address_comes_off(self):
|
||||
"""Issue #45: a device whose bridge section predates the switch to RNDIS. Preinit's early server (K11)
|
||||
left the LAN address on rndis0, and rndis0 is not a bridge port when this hook runs. It used to be enslaved
|
||||
after the removal loop, so the address stayed while br-lan held the same one, and neither the Wi-Fi clients
|
||||
nor the USB host could use the LAN. Join first, then take the address off - and once only."""
|
||||
for shell in self.each_shell():
|
||||
self.netdevs('rndis0') # a RNDIS boot has no usb0
|
||||
self.hotplug(shell, port='', rndis_port='no', rndis_addr='10.1.2.1/24') # no usb0 address
|
||||
ip = (self.tmp / 'ip.log').read_text()
|
||||
self.assertIn('ip link set rndis0 master br-lan\n', ip)
|
||||
self.assertIn('ip addr del 10.1.2.1/24 dev rndis0\n', ip)
|
||||
self.assertLess(ip.index('ip link set rndis0 master br-lan\n'), ip.index('ip addr del 10.1.2.1/24 dev rndis0\n'))
|
||||
self.assertEqual(1, ip.count('ip addr del'))
|
||||
# after the re-enumeration the new netdev is a port again (the second half of the issue)
|
||||
self.assertEqual(2, ip.count('ip link set rndis0 master br-lan\n'))
|
||||
self.tearDown(); self.setUp()
|
||||
|
||||
def test_port_prefix_other_than_the_bridge(self):
|
||||
# I1: br-lan has the LAN as /16, preinit left a /24 on usb0 - its route would beat the bridge's
|
||||
for shell in self.each_shell():
|
||||
@@ -385,6 +409,46 @@ class EarlyUsbOpenWrt(ShellTest):
|
||||
self.assertIn(line + '\n', log)
|
||||
self.tearDown(); self.setUp()
|
||||
|
||||
def test_defaults_name_the_lan_and_wan_zone_devices_once(self):
|
||||
"""Issue #67: the zones carry their devices, so the S19 ruleset has the LAN's input rules and the wan's
|
||||
masquerade before netifd has made br-lan and sipa_eth0; added once, and not to a zone that has it."""
|
||||
for shell in self.each_shell():
|
||||
log = self.defaults(shell, runs=2)
|
||||
self.assertEqual(1, log.count('uci add_list firewall.@zone[0].device=br-lan\n'))
|
||||
self.assertEqual(1, log.count('uci add_list firewall.@zone[1].device=sipa_eth0\n'))
|
||||
self.assertEqual(self.uci('get', 'firewall.@zone[0].device'), 'br-lan')
|
||||
self.assertEqual(self.uci('get', 'firewall.@zone[1].device'), 'sipa_eth0')
|
||||
self.tearDown(); self.setUp()
|
||||
|
||||
# --- hotplug.d/iface/19-mu300-fw4 (issue #67): the 5.4 kernel's stale flowtable before 20-firewall's reload
|
||||
def fw4_hook(self, shell, kernel='5.4.254', action='ifup', iface='lan', flowtable=True, in_zone=True):
|
||||
self.stub('uname', f'echo {kernel}')
|
||||
self.stub('fw4', 'echo "fw4 $*" >> "$STUBLOG/fw4.log"; ' + ('exit 0' if in_zone else 'exit 1'))
|
||||
self.stub('nft', 'echo "nft $*" >> "$STUBLOG/nft.log"\n'
|
||||
'case "$*" in "list flowtables inet fw4") '
|
||||
+ ('printf "table inet fw4 {\\n\\tflowtable ft {\\n\\t}\\n}\\n"' if flowtable else ':')
|
||||
+ ' ;; esac')
|
||||
self.stub('logger', ':')
|
||||
body = self.text('etc/hotplug.d/iface/19-mu300-fw4', **{'/etc/init.d/firewall enabled': 'true'})
|
||||
r = self.sh(shell, f'ACTION={action} INTERFACE={iface}\n' + body)
|
||||
self.assertEqual(0, r.returncode, r.stderr)
|
||||
self.assertEqual('', r.stderr)
|
||||
nft = self.tmp / 'nft.log'
|
||||
return nft.read_text() if nft.exists() else ''
|
||||
|
||||
def test_fw4_hook_deletes_the_flowtable_on_5_4_before_the_reload(self):
|
||||
for shell in self.each_shell():
|
||||
self.assertIn('nft delete flowtable inet fw4 ft\n', self.fw4_hook(shell))
|
||||
self.tearDown(); self.setUp()
|
||||
|
||||
def test_fw4_hook_leaves_the_flowtable_alone_when_no_reload_follows_or_the_kernel_updates_it(self):
|
||||
for shell in self.each_shell():
|
||||
for kw in ({'kernel': '6.18.55'}, {'kernel': '7.2.9'}, {'action': 'ifdown'}, {'in_zone': False},
|
||||
{'flowtable': False}):
|
||||
with self.subTest(shell=' '.join(shell), **kw):
|
||||
self.assertNotIn('delete', self.fw4_hook(shell, **kw))
|
||||
self.tearDown(); self.setUp()
|
||||
|
||||
def test_defaults_bridge_rndis0_only_when_it_exists(self):
|
||||
for shell in self.each_shell():
|
||||
for present in (False, True):
|
||||
|
||||
+33
-3
@@ -466,11 +466,12 @@ class SdErase(ShellTest):
|
||||
class Region(ShellTest):
|
||||
"""storage.sh's region functions, with su_do running the device commands against a fake sysfs and eMMC file."""
|
||||
|
||||
def fake(self, ext4_at=None):
|
||||
def fake(self, ext4_at=None, full=False):
|
||||
sysfs = self.tmp / 'sys/block/mmcblk0'
|
||||
(sysfs / 'mmcblk0p1').mkdir(parents=True, exist_ok=True)
|
||||
(sysfs / 'mmcblk0p1/start').write_text('2048\n')
|
||||
(sysfs / 'mmcblk0p1/size').write_text(f'{4 << 21}\n') # ends at 8 GiB + 1 MiB
|
||||
# ends at 8 GiB + 1 MiB; full: 2 MiB before the end of the disk, the layout of issue #65
|
||||
(sysfs / 'mmcblk0p1/size').write_text(f'{((16 << 21) - 4096) if full else (4 << 21)}\n')
|
||||
(sysfs / 'size').write_text(f'{16 << 21}\n') # a 16 GiB eMMC
|
||||
emmc = self.tmp / 'mmcblk0'
|
||||
with open(emmc, 'wb') as f:
|
||||
@@ -482,7 +483,8 @@ class Region(ShellTest):
|
||||
return emmc
|
||||
|
||||
def run_region(self, shell, call):
|
||||
su = (f'su_do() {{ sh -c "$(printf "%s" "$1" | sed -e "s|/sys/block|{self.tmp}/sys/block|g" '
|
||||
su = (f'su_do() {{ printf "%s\\n" "$1" >> "{self.tmp}/su.log"; '
|
||||
f'sh -c "$(printf "%s" "$1" | sed -e "s|/sys/block|{self.tmp}/sys/block|g" '
|
||||
f'-e "s|/dev/block/mmcblk0|{self.tmp}/mmcblk0|g")"; }}\n')
|
||||
return self.sh(shell, su + f'. "{TOP}/tools/storage.sh"\n{call}\n'
|
||||
'echo "rc=$? OFF=$OFF SIZE=$SIZE existing=${existing:-} DIRTY=${DIRTY:-}"')
|
||||
@@ -509,6 +511,34 @@ class Region(ShellTest):
|
||||
self.assertIn('existing=no DIRTY=1', out)
|
||||
|
||||
|
||||
def test_a_table_that_ends_at_the_end_of_the_disk_is_an_empty_region_and_is_never_read(self):
|
||||
"""Issue #65 (and #43, #52): the last partition ends 2 MiB before the end of the eMMC. The first boundary
|
||||
behind it is the end of the disk and the last one before the backup GPT lies before it: a negative size,
|
||||
and a probe of the region's superblock 2 bytes past the last sector - a dd that never returns on the
|
||||
device. The region is empty, and nothing past the disk's last sector is read; the fixed offset of the
|
||||
first releases (27762098176) lies beyond this 16 GiB disk and is not read either."""
|
||||
self.fake(full=True)
|
||||
disk = 16 << 21
|
||||
for shell in self.each_shell():
|
||||
out = self.run_region(shell, 'region_probe; region_find_existing').stdout
|
||||
self.assertIn(f'rc=0 OFF={disk * 512} SIZE=0 existing=no', out)
|
||||
for cmd in (self.tmp / 'su.log').read_text().splitlines():
|
||||
m = re.search(r'dd if=/dev/block/mmcblk0 bs=1 skip=(\d+) count=(\d+)', cmd)
|
||||
if m:
|
||||
self.assertLessEqual(int(m.group(1)) + int(m.group(2)), disk * 512, cmd)
|
||||
(self.tmp / 'su.log').unlink()
|
||||
|
||||
def test_the_legacy_offset_is_read_only_on_a_disk_that_holds_it(self):
|
||||
start = ((2048 + (4 << 21)) // 4096 + 1) * 4096 * 512
|
||||
self.fake(ext4_at=start)
|
||||
for shell in self.each_shell():
|
||||
self.run_region(shell, 'region_probe; region_find_existing')
|
||||
log = (self.tmp / 'su.log').read_text()
|
||||
self.assertIn(f'skip={start + 1080}', log)
|
||||
self.assertNotIn('skip=27762099256', log, 'the legacy offset lies beyond a 16 GiB disk')
|
||||
(self.tmp / 'su.log').unlink()
|
||||
|
||||
|
||||
class ChooseSystems(ShellTest):
|
||||
"""install.sh's choose_systems, cut out between its markers: which systems, which OpenWrt, which one boots."""
|
||||
SRC = (TOP / 'install.sh').read_text()
|
||||
|
||||
@@ -40,9 +40,11 @@ fi
|
||||
OFF=; SIZE=
|
||||
if [ -z "$MOUNTENV" ]; then
|
||||
# the same search install.sh does; all byte arithmetic happens here, not in Android's 32-bit shell
|
||||
set -- $(su_do 'e=0; for p in /sys/block/mmcblk0/mmcblk0p*; do x=$(( $(cat $p/start) + $(cat $p/size) )); [ $x -gt $e ] && e=$x; done; echo $e')
|
||||
[ -n "${1:-}" ] || die "could not read the partition table from the device"
|
||||
set -- $(su_do 'e=0; for p in /sys/block/mmcblk0/mmcblk0p*; do x=$(( $(cat $p/start) + $(cat $p/size) )); [ $x -gt $e ] && e=$x; done; echo $e $(cat /sys/block/mmcblk0/size)')
|
||||
[ $# -eq 2 ] || die "could not read the partition table from the device"
|
||||
disk=$2
|
||||
for cand in $(( ($1 / 4096 + 1) * 4096 * 512 )) 27762098176; do
|
||||
region_on_disk "$cand" || continue # never read past the end of the eMMC (storage.sh)
|
||||
m=$(su_do "dd if=/dev/block/mmcblk0 bs=1 skip=$((cand + 1080)) count=2 2>/dev/null | od -An -tx1" | tr -d ' ')
|
||||
l=$(su_do "dd if=/dev/block/mmcblk0 bs=1 skip=$((cand + 1144)) count=16 2>/dev/null" | tr -d '\000')
|
||||
if [ "$m" = 53ef ] && [ "$l" = mu300root ]; then
|
||||
|
||||
@@ -134,14 +134,25 @@ region_probe() {
|
||||
last_end=$1; disk=$2
|
||||
start=$(( (last_end / 4096 + 1) * 4096 ))
|
||||
end=$(( ((disk - 34) / 4096 - 1) * 4096 ))
|
||||
# A partition table that ends at the end of the eMMC (one alignment block or less behind the last partition,
|
||||
# issue #65): the two boundaries cross, and a negative size is not a region. It is an empty one - the callers
|
||||
# then offer the card or make room - and its start is not read (region_find_existing).
|
||||
[ $end -gt $start ] || end=$start
|
||||
OFF=$((start * 512)); SIZE=$(( (end - start) * 512 ))
|
||||
}
|
||||
|
||||
# region_on_disk BYTES: whether the ext4 superblock of a region at BYTES (its second KiB) lies on the eMMC. A read
|
||||
# past the end of the disk never returns on this device: the dd spins on one core, survives kill -9 and heats the
|
||||
# SoC until a reboot (issues #43, #52, #65 - a 32 GB eMMC whose table ends at its end puts the region's start at the
|
||||
# disk's end, and the fixed offset of the first releases lies beyond a 32 GB eMMC altogether).
|
||||
region_on_disk() { [ $(( ($1 + 2048) / 512 )) -le "${disk:?region_probe first}" ]; }
|
||||
|
||||
# an existing installation defines the region (it may have been created with a slightly different size, or at the
|
||||
# fixed offset of the first releases)
|
||||
region_find_existing() {
|
||||
existing=no
|
||||
for cand in $OFF 27762098176; do
|
||||
region_on_disk "$cand" || continue
|
||||
m=$(su_do "dd if=/dev/block/mmcblk0 bs=1 skip=$((cand + 1080)) count=2 2>/dev/null | od -An -tx1" | tr -d ' ')
|
||||
l=$(su_do "dd if=/dev/block/mmcblk0 bs=1 skip=$((cand + 1144)) count=16 2>/dev/null" | LC_ALL=C tr -d '\000')
|
||||
if [ "$m" = 53ef ] && [ "$l" = mu300root ]; then
|
||||
|
||||
@@ -43,6 +43,7 @@ last_end=$1; disk=$2
|
||||
OFF=; SIZE=
|
||||
start=$(( (last_end / 4096 + 1) * 4096 * 512 ))
|
||||
for cand in $start 27762098176; do
|
||||
region_on_disk "$cand" || continue # never read past the end of the eMMC (storage.sh)
|
||||
m=$(su_do "dd if=/dev/block/mmcblk0 bs=1 skip=$((cand + 1080)) count=2 2>/dev/null | od -An -tx1" | tr -d ' ')
|
||||
l=$(su_do "dd if=/dev/block/mmcblk0 bs=1 skip=$((cand + 1144)) count=16 2>/dev/null" | tr -d '\000')
|
||||
if [ "$m" = 53ef ] && [ "$l" = mu300root ]; then
|
||||
|
||||
Reference in new issue
Block a user