From a63d7d44bf3cc2650cd10bb53c0daa39751d39a7 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 14:19:53 -0400 Subject: [PATCH 1/4] os: the net applier runs AFTER connman, which is what the discriminating row proved it must (#1513 review) The new row persisted an address DHCP would not hand out (10.0.2.250/24) and the boot came up with **no address at all**, connman reporting no manual config - then minutes later the static address appeared, applied by connman from its own stored config. Mechanism: connman ships as /etc/init.d/connman, which sorts under "c" - AFTER every numeric script - so 14onboard-net ran before the daemon that owns the link existed: connmanctl had no service, the ip fallback put the address on, and connman then took the link over and flushed it. So the applier is now zz-onboard-net (after connman, before zz-onboard-ports), waits up to 30 s for connman to publish a service for the interface's MAC, configures connman itself, and only falls back to ip if connman still has nothing to say. The row waits up to 90 s after the reboot for the address and requires Method=manual by then, instead of sampling the instant the shell appears. --- docs/os-v3.md | 2 +- os/v3/puppy/README.md | 2 +- os/v3/puppy/container-build.sh | 4 +-- .../init.d/{14onboard-net => zz-onboard-net} | 36 +++++++++++++------ os/v3/puppy/embed/usr/local/bin/1bit-network | 4 +-- os/v3/puppy/install-probe.sh | 6 ++++ 6 files changed, 37 insertions(+), 17 deletions(-) rename os/v3/puppy/embed/etc/init.d/{14onboard-net => zz-onboard-net} (70%) diff --git a/docs/os-v3.md b/docs/os-v3.md index 09a6da9f6..353b2b4dc 100644 --- a/docs/os-v3.md +++ b/docs/os-v3.md @@ -156,7 +156,7 @@ named here as what they are: | logging | `06onboard-logs` keeps the boot's logs on `/data/logs` — the partition, not the filesystem that the next appliance replaces | `/data/logs` non-empty on the installed boot | | packages and services | `apt` works and its packages land in the save layer; the appliance's own services are `/etc/init.d` scripts, which is what `rc.services` runs (there is no systemd here, and nothing pretends there is) | — | -| an optional static address | `1bit-network set-static [gateway] [dns…]` writes **`/data/net.conf`** — on the data partition, so it outlives an appliance update — and `/etc/init.d/14onboard-net` applies it at boot through **connman's own CLI** (`connmanctl config --ipv4 manual …`), with `ip` only as the fallback for a link connman has no service for yet. The console's static action stays session-only, because a wrong address on a headless box is a walk to the machine; this one is persistent **and reversible in one command**: `1bit-network reset` deletes the file and hands the interface back to DHCP. An unparsable or unusable file is not applied at all — the boot leaves the link on DHCP and says so in `/var/log/1bit-network.log` | `tests/one_bit_network_conf_test.sh` (the address and file validation, 26 arms, no root or interface needed) and the installed boot's `1bit-network` rows | +| an optional static address | `1bit-network set-static [gateway] [dns…]` writes **`/data/net.conf`** — on the data partition, so it outlives an appliance update — and `/etc/init.d/zz-onboard-net` applies it at boot through **connman's own CLI** (`connmanctl config --ipv4 manual …`), with `ip` only as the fallback for a link connman has no service for yet. The console's static action stays session-only, because a wrong address on a headless box is a walk to the machine; this one is persistent **and reversible in one command**: `1bit-network reset` deletes the file and hands the interface back to DHCP. An unparsable or unusable file is not applied at all — the boot leaves the link on DHCP and says so in `/var/log/1bit-network.log` | `tests/one_bit_network_conf_test.sh` (the address and file validation, 26 arms, no root or interface needed) and the installed boot's `1bit-network` rows | **Recovery, stated where someone under pressure will look:** `1bit-network reset` on tty1, the serial console, or the console menu's bash item. The file is `/data/net.conf`; deleting it is the same thing. diff --git a/os/v3/puppy/README.md b/os/v3/puppy/README.md index 7db5b0d19..73ddff04f 100644 --- a/os/v3/puppy/README.md +++ b/os/v3/puppy/README.md @@ -160,7 +160,7 @@ this recipe ships are: | `05onboard-data` | finds `1BIT-DATA` (`1bit.data=` on the boot line, else the label), mounts it at `/data`, creates the contract dirs, points `/etc/1bit/lemond.conf` at `/data/lemonade/lemond.conf`, copies `/data/ssh/authorized_keys` and links the host key from `/data/ssh`, and registers `/data/models` in Lemonade's `user_models.json` | | `10lemonade` | starts `/opt/1bit-package/lemond-onebit`, binds `0.0.0.0:13305`, logs to `/var/log/lemond-onebit.log`. **No key by default** (cycle 20, the owner's "blank key": the appliance ships like stock Lemonade). A key is opt-in and lives in `/etc/1bit/lemond.conf` (mode 600, a symlink onto `/data`) — console menu item 1 mints one, removes it, and restarts this service so lemond comes up in the other mode; nothing else in the image holds it | | `07onboard-user` | **the installed machine's normal account** (engine#712): on an installed boot only (`/data` mounted with `1bit-install`'s `.installed` on it) it creates `onebit` — home, bash, **locked password** so a key is the only way in — installs `/data/ssh/authorized_keys` as its `0600` key file (re-applied at every installed boot, exactly as `20onboard-ssh` does for root), and appends **one** sudo rule, `onebit ALL=(ALL) NOPASSWD: ALL`, backed up and proved with `sudo -n true` as that user, rolled back if it fails. A live stick exits without touching anything: a machine that forgets stays root-only | -| `14onboard-net` + `usr/local/bin/1bit-network` | **the persistent network identity** (engine#712): `1bit-network set-static [gateway] [dns…]` validates the answer, writes `/data/net.conf` (data partition, so it survives an appliance update) and applies it now through connman's own CLI; `14onboard-net` applies the same file at every boot, and does nothing at all when the file is absent or does not validate (a bad file leaves the link on DHCP rather than half-applying). `1bit-network reset` is the whole recovery path: it deletes the file and gives the interface back to DHCP. The console's own static action stays session-only on purpose | +| `zz-onboard-net` + `usr/local/bin/1bit-network` | **the persistent network identity** (engine#712): `1bit-network set-static [gateway] [dns…]` validates the answer, writes `/data/net.conf` (data partition, so it survives an appliance update) and applies it now through connman's own CLI; `zz-onboard-net` applies the same file at every boot, and does nothing at all when the file is absent or does not validate (a bad file leaves the link on DHCP rather than half-applying). `1bit-network reset` is the whole recovery path: it deletes the file and gives the interface back to DHCP. The console's own static action stays session-only on purpose | | `20onboard-ssh` | `ssh-keygen -A`, `/root/.ssh` 700 + `authorized_keys` 600, then sshd. An image with no key provisions no listener | | `21serial-console` | a root shell on `/dev/ttyS0`, only when the command line carries `1bit.serial=1` (that shell has no password, so it is opt-in) | | `26onboard-board` | `os/mini/board.sh` as `/usr/sbin/1bit-board` (the path release-check's `fans` row reads): EC fan curve, power profile and the detached boost loop, on a board whose DMI it knows; on any other machine it writes nothing and says so | diff --git a/os/v3/puppy/container-build.sh b/os/v3/puppy/container-build.sh index 04cead47e..b2e45345f 100644 --- a/os/v3/puppy/container-build.sh +++ b/os/v3/puppy/container-build.sh @@ -359,7 +359,7 @@ if [ -n "${PAYLOAD:-}" ]; then chmod 0755 "$skeleton/usr/local/bin/1bit-tty1" chmod 0755 "$skeleton"/etc/init.d/03onboard-efivars "$skeleton"/etc/init.d/05onboard-data \ "$skeleton"/etc/init.d/06onboard-logs "$skeleton"/etc/init.d/07onboard-user \ - "$skeleton"/etc/init.d/08onboard-presets "$skeleton"/etc/init.d/14onboard-net \ + "$skeleton"/etc/init.d/08onboard-presets "$skeleton"/etc/init.d/zz-onboard-net \ "$skeleton"/etc/init.d/10lemonade \ "$skeleton"/etc/init.d/18onboard-mdns \ "$skeleton"/etc/init.d/20onboard-ssh "$skeleton"/etc/init.d/21serial-console \ @@ -650,7 +650,7 @@ if [ -n "${PAYLOAD:-}" ]; then usr/local/bin/1bit-record usr/local/bin/1bit-lemonade-webapp \ usr/local/bin/1bit-webapp-proxy usr/local/bin/1bit-desktop usr/local/bin/1bit-logs \ etc/init.d/06onboard-logs etc/init.d/07onboard-user etc/init.d/08onboard-presets \ - etc/init.d/14onboard-net usr/local/bin/1bit-network \ + etc/init.d/zz-onboard-net usr/local/bin/1bit-network \ root/Startup/1bit-lemonade-webapp \ etc/personal_settings_popup_disabled etc/1bit/palemoon-prefs.js \ etc/init.d/24onboard-webapp opt/1bit/webapp/index.html \ diff --git a/os/v3/puppy/embed/etc/init.d/14onboard-net b/os/v3/puppy/embed/etc/init.d/zz-onboard-net similarity index 70% rename from os/v3/puppy/embed/etc/init.d/14onboard-net rename to os/v3/puppy/embed/etc/init.d/zz-onboard-net index e69119cd3..d30182690 100755 --- a/os/v3/puppy/embed/etc/init.d/14onboard-net +++ b/os/v3/puppy/embed/etc/init.d/zz-onboard-net @@ -14,11 +14,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# /etc/init.d/14onboard-net - apply the persistent network identity, if an install has one (engine#712). +# /etc/init.d/zz-onboard-net - apply the persistent network identity, if an install has one (engine#712). # # `/data/net.conf` is written by `1bit-network set-static` and lives on the DATA partition, so it survives an appliance -# update (nothing the OS set carries is touched). This runs after 05onboard-data has mounted /data and before the -# services that talk to the network; with no file, or a file that does not validate, it does NOTHING and says so - a +# update (nothing the OS set carries is touched). +# +# WHY THE NAME STARTS WITH zz-: connman ships as `/etc/init.d/connman`, which sorts under "c" - i.e. AFTER every numeric +# script - so a `14onboard-net` ran BEFORE the daemon that owns the link existed: `connmanctl` had no service, the `ip` +# fallback put the address on, and connman then took the link over and flushed it, so the machine came up with no address +# at all for a while (measured: the row saw "" right after the reboot and the static address only minutes later, +# applied by connman from its own stored config). Running after it means the config is given to connman itself. with no file, or a file that does not validate, it does NOTHING and says so - a # machine that cannot reach the LAN is worse than one on DHCP, and the repair path has to stay obvious: # # recovery: 1bit-network reset (tty1, the serial console, or the console menu's bash item) @@ -39,7 +44,7 @@ log() { printf '%s\n' "$*" | tee -a "$LOG"; } mkdir -p /tmp 2> /dev/null : >> "$LOG" 2> /dev/null || LOG=/dev/null -[ -f "$CONF" ] || { log "14onboard-net: no $CONF: the interface stays on DHCP (connman)"; exit 0; } +[ -f "$CONF" ] || { log "zz-onboard-net: no $CONF: the interface stays on DHCP (connman)"; exit 0; } # the same parse and validation as 1bit-network, sourced rather than copied: one definition of "a usable net.conf" NETWORK=/usr/local/bin/1bit-network @@ -48,13 +53,13 @@ if [ -r "$NETWORK" ]; then ONEBIT_NETWORK_LIB=1 . "$NETWORK" fi if ! command -v read_conf > /dev/null 2>&1 || ! command -v conf_ok > /dev/null 2>&1; then - log "14onboard-net: cannot load the parser from $NETWORK: leaving the network alone (recovery: 1bit-network reset)" + log "zz-onboard-net: cannot load the parser from $NETWORK: leaving the network alone (recovery: 1bit-network reset)" exit 0 fi read_conf "$CONF" if ! why=$(conf_ok 2>&1); then - log "14onboard-net: $CONF is not usable ($why): leaving the network on DHCP. Recovery: 1bit-network reset" + log "zz-onboard-net: $CONF is not usable ($why): leaving the network on DHCP. Recovery: 1bit-network reset" exit 0 fi @@ -62,11 +67,20 @@ fi i=0 while [ ! -e "/sys/class/net/$iface" ] && [ $i -lt 20 ]; do sleep 1; i=$((i + 1)); done if [ ! -e "/sys/class/net/$iface" ]; then - log "14onboard-net: $iface did not appear in 20 s: leaving the network alone" + log "zz-onboard-net: $iface did not appear in 20 s: leaving the network alone" exit 0 fi applied=no +# connman starts LATE (`/etc/init.d/connman` sorts under "c", after every numeric script), and this script is meant to +# run after it: give it up to 30 s to publish a service for this link rather than racing it +i=0 +while [ $i -lt 30 ]; do + connmanctl services 2> /dev/null | grep -q "$(cat "/sys/class/net/$iface/address" 2> /dev/null | tr -d ':')" && break + sleep 1 + i=$((i + 1)) +done + if command -v connmanctl > /dev/null 2>&1; then # WHICH service? connman's own name carries the interface's MAC (`ethernet__cable`), so the match is by MAC # from /sys/class/net: `awk '/^\*/ { print $2; exit }'` (the first version) reconfigured whichever link happened to @@ -102,10 +116,10 @@ if command -v connmanctl > /dev/null 2>&1; then sleep 1 i=$((i + 1)) done - [ "$applied" = yes ] || log "14onboard-net: connman accepted the config but does not report Method=manual" \ + [ "$applied" = yes ] || log "zz-onboard-net: connman accepted the config but does not report Method=manual" \ "for $svc (rc=$rc, see $LOG); falling back to ip" else - log "14onboard-net: connman has no service for $iface (mac ${mac:-unknown}): falling back to ip" + log "zz-onboard-net: connman has no service for $iface (mac ${mac:-unknown}): falling back to ip" fi fi @@ -119,9 +133,9 @@ if [ "$applied" = no ]; then fi if [ "$applied" = yes ]; then - log "14onboard-net: $iface carries $static${gateway:+ via $gateway} from $CONF" + log "zz-onboard-net: $iface carries $static${gateway:+ via $gateway} from $CONF" exit 0 fi -log "14onboard-net: could not apply $static to $iface (see $LOG); the link keeps whatever DHCP gave it." \ +log "zz-onboard-net: could not apply $static to $iface (see $LOG); the link keeps whatever DHCP gave it." \ "Recovery: 1bit-network reset" exit 0 diff --git a/os/v3/puppy/embed/usr/local/bin/1bit-network b/os/v3/puppy/embed/usr/local/bin/1bit-network index e458b3e56..6b532bf0f 100755 --- a/os/v3/puppy/embed/usr/local/bin/1bit-network +++ b/os/v3/puppy/embed/usr/local/bin/1bit-network @@ -224,7 +224,7 @@ esac tmp=$CONF.tmp { - echo "# written by 1bit-network on $(date -u +%FT%TZ); applied at boot by /etc/init.d/14onboard-net" + echo "# written by 1bit-network on $(date -u +%FT%TZ); applied at boot by /etc/init.d/zz-onboard-net" echo "# recovery: 1bit-network reset (from tty1, the serial console or the console menu)" echo "iface=$dev" echo "static=$addr" @@ -239,7 +239,7 @@ mv -f "$tmp" "$CONF" || fail "cannot install $CONF" sync say "1bit-network: persisted to $CONF (iface=$dev static=$addr gateway=${gw:--} dns=${dnsv:--})" -/etc/init.d/14onboard-net start || fail "applied the file but the interface did not take the address (see $LOG)" +/etc/init.d/zz-onboard-net start || fail "applied the file but the interface did not take the address (see $LOG)" if ip -4 -o addr show dev "$dev" 2> /dev/null | grep -q " ${addr%/*}/"; then say "1bit-network: $dev carries ${addr} now, and will again at the next boot" [ -z "$gw" ] || say " gateway $gw" diff --git a/os/v3/puppy/install-probe.sh b/os/v3/puppy/install-probe.sh index 436c0e9d8..efa3f0ce9 100755 --- a/os/v3/puppy/install-probe.sh +++ b/os/v3/puppy/install-probe.sh @@ -709,6 +709,12 @@ if assert_pupsfs: print("FAIL net the machine did not come back after the static-address reboot"); ok = False v.close() else: + # zz-onboard-net runs AFTER connman (which sorts under "c"), so it lands later than the shell: wait for + # it rather than sampling the instant the shell appears (measured: "" at the shell, the address + # minutes later from connman's own stored config - which is what "applied" must never look like) + val("WAITNET", "n=0; while [ $n -lt 18 ]; do " + "ip -4 -o addr show dev %s 2>/dev/null | grep -q '%s' && break; " + "sleep 5; n=$((n+1)); done; echo waited" % (dev, static_addr), timeout=180) per = val("PERSIST", "ip -4 -o addr show dev %s 2>/dev/null | awk '{ print $4 }'" % dev) f = val("CONF", "grep -c '^static=' /data/net.conf 2>/dev/null") cm = val("CONNMAN", "connmanctl services --properties 2>/dev/null | grep -c 'Method=manual'") From 1268784a5c07b2fe5d3024c6771d207cd3cf6659 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 14:38:49 -0400 Subject: [PATCH 2/4] os: one service lookup, reset really returns to DHCP, and the row asserts the applier's own evidence (#1513 review) * `connman_service_for_iface` now lives in 1bit-network (the sourced library) and is used by BOTH the boot applier and `1bit-network reset` - the reset kept the old "first connected service on any link" lookup, which is why a reset left the machine on the static address (measured: "after reset the link did not get its DHCP address back (10.0.2.250/24)"); * reset reports what connman did instead of assuming it worked, and says how to recover if connman refuses; * the row no longer looks for `Method=manual` in `connmanctl services --properties` - this build prints no IPv4 lines there (measured on the installed disk). It asserts the two things that cannot be true by accident: an address DHCP never hands out is on the interface after the reboot, and /var/log/1bit-network.log has THIS boot's application line from /data/net.conf. --- os/v3/puppy/embed/etc/init.d/zz-onboard-net | 7 +---- os/v3/puppy/embed/usr/local/bin/1bit-network | 32 +++++++++++++++----- os/v3/puppy/install-probe.sh | 19 +++++++----- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/os/v3/puppy/embed/etc/init.d/zz-onboard-net b/os/v3/puppy/embed/etc/init.d/zz-onboard-net index d30182690..f92d85443 100755 --- a/os/v3/puppy/embed/etc/init.d/zz-onboard-net +++ b/os/v3/puppy/embed/etc/init.d/zz-onboard-net @@ -85,12 +85,7 @@ if command -v connmanctl > /dev/null 2>&1; then # WHICH service? connman's own name carries the interface's MAC (`ethernet__cable`), so the match is by MAC # from /sys/class/net: `awk '/^\*/ { print $2; exit }'` (the first version) reconfigured whichever link happened to # be connected first - on a box with two interfaces that is the wrong one, silently. - mac=$(cat "/sys/class/net/$iface/address" 2> /dev/null | tr -d ':') - svc='' - if [ -n "$mac" ]; then - svc=$(connmanctl services 2> /dev/null | awk -v m="$mac" ' - index($0, m) { for (i = 1; i <= NF; i++) if ($i ~ /^(ethernet|wifi|bluetooth)_/) { print $i; exit } }') - fi + svc=$(connman_service_for_iface "$iface") if [ -n "$svc" ]; then # connman's manual IPv4 configuration takes ADDRESS and NETMASK as two fields (never a CIDR), the gateway third, # and DNS through --nameservers: `--ipv4 manual "$static" "$gateway"` sent "10.0.2.50/24" as the address and the diff --git a/os/v3/puppy/embed/usr/local/bin/1bit-network b/os/v3/puppy/embed/usr/local/bin/1bit-network index 6b532bf0f..d453eba89 100755 --- a/os/v3/puppy/embed/usr/local/bin/1bit-network +++ b/os/v3/puppy/embed/usr/local/bin/1bit-network @@ -135,6 +135,18 @@ conf_ok() { # the loaded values have to be usable, or the boot must not tou done return 0 } +# connman_service_for_iface IFACE: connman names a service after the link's MAC (`ethernet__cable`), so the match is +# by MAC out of /sys/class/net. Matching on "the first connected service" reconfigures whichever link happened to connect +# first - silently the wrong one on a machine with two interfaces (review finding on #1513). +connman_service_for_iface() { + [ -n "${1:-}" ] || return 1 + command -v connmanctl > /dev/null 2>&1 || return 1 + mac=$(cat "/sys/class/net/$1/address" 2> /dev/null | tr -d ':') + [ -n "$mac" ] || return 1 + connmanctl services 2> /dev/null | awk -v m="$mac" ' + index($0, m) { for (i = 1; i <= NF; i++) if ($i ~ /^(ethernet|wifi|bluetooth)_/) { print $i; exit } }' +} + # on this boot: the interface that carries the default route, else the first one that is not loopback and is up default_iface() { dev=$(ip route show default 2> /dev/null | awk '/^default/ { for (i = 1; i <= NF; i++) if ($i == "dev") { print $(i + 1); exit } }') @@ -190,14 +202,20 @@ fi if [ "$mode" = reset ]; then read_conf "$CONF" rm -f "$CONF" || fail "cannot remove $CONF" - # give the interface back to DHCP through connman, so a wrong address really is gone and not just forgotten + # give the interface back to DHCP through connman, so a wrong address really is gone and not just forgotten. + # The lookup is by MAC (the old one took the first connected service on any link, which on a two-interface machine + # is the wrong one), and the result is reported rather than assumed. if [ -n "${iface:-}" ] && command -v connmanctl > /dev/null 2>&1; then - svc=$(connmanctl services 2> /dev/null | awk -v i="$iface" ' - /^\*/ { name = $2; mac = $3 } - NF == 1 && name { print name; exit } - { }' | head -1) - [ -n "$svc" ] && connmanctl config "$svc" --ipv4 dhcp >> "$LOG" 2>&1 && \ - say "1bit-network: $svc back to DHCP" + svc=$(connman_service_for_iface "$iface") + if [ -n "$svc" ]; then + if connmanctl config "$svc" --ipv4 dhcp >> "$LOG" 2>&1; then + say "1bit-network: $svc back to DHCP" + else + say "1bit-network: connman refused to put $svc back on DHCP (see $LOG); restart it: /etc/init.d/connman restart" + fi + else + say "1bit-network: connman has no service for $iface; the link keeps its address until reconnect" + fi fi say "1bit-network: reset - $CONF removed, the next boot and this one use DHCP" say " (if the link still carries the old address, restart the network: /etc/init.d/connman restart)" diff --git a/os/v3/puppy/install-probe.sh b/os/v3/puppy/install-probe.sh index efa3f0ce9..cb2d2963e 100755 --- a/os/v3/puppy/install-probe.sh +++ b/os/v3/puppy/install-probe.sh @@ -717,18 +717,23 @@ if assert_pupsfs: "sleep 5; n=$((n+1)); done; echo waited" % (dev, static_addr), timeout=180) per = val("PERSIST", "ip -4 -o addr show dev %s 2>/dev/null | awk '{ print $4 }'" % dev) f = val("CONF", "grep -c '^static=' /data/net.conf 2>/dev/null") - cm = val("CONNMAN", "connmanctl services --properties 2>/dev/null | grep -c 'Method=manual'") - print("INFO net after the reboot: %s | net.conf static lines=%s | connman Method=manual=%s" % (per or "", f, cm)) + # `connmanctl services --properties` does not print the IPv4 configuration on this build (measured), so + # the proof is the applier's own log line from THIS boot plus an address DHCP would never hand out: + # an address cannot survive a reboot, so .250 on the interface means something applied it after boot. + bootline = val("BOOTLOG", "grep -c 'zz-onboard-net: .*carries 10.0.2.250' /var/log/1bit-network.log 2>/dev/null") + print("INFO net after the reboot: %s | net.conf static lines=%s | applier log lines for it=%s" + % (per or "", f, bootline or "0")) if static_addr not in per: print("FAIL net after the reboot the interface does not carry the static %s (%s)" % (static_addr, per or "")); ok = False elif f != "1": print("FAIL net /data/net.conf lost its static line across the reboot (%s)" % (f or "0")); ok = False - elif not cm.isdigit() or int(cm) < 1: - print("FAIL net connman does not report Method=manual after the reboot: the address may be" - " left over from before, not applied (%s)" % (cm or "")); ok = False + elif not bootline.isdigit() or int(bootline) < 1: + print("FAIL net the applier did not log that it applied the file after the reboot (%s lines)," + " so the address has no explanation on this boot" % (bootline or "")); ok = False else: - print("PASS net after a reboot %s carries %s and connman reports Method=manual: the address" - " is applied from /data/net.conf, not inherited" % (dev, static_addr)) + print("PASS net after a reboot %s carries %s (which DHCP never hands out) and" + " /var/log/1bit-network.log has this boot's application from /data/net.conf" + % (dev, static_addr)) val("RESETNET", "1bit-network reset 2>&1 | tr '\\n' '; '", timeout=180) left = val("LEFT", "ls /data/net.conf 2>&1 | head -1") # and DHCP has to come back on its own: a reset that leaves the box on the static address is a From a3e10ee21424bfda6b1edf1cbeb0b7d75e7eaaa3 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 15:40:44 -0400 Subject: [PATCH 3/4] os: deleting /data/net.conf by hand really is a recovery, and the row proves it (#1527 review) Review blocker 1, correct: connman keeps a manual configuration in ITS OWN state across reboots, so with the file gone `zz-onboard-net` exited at its first check and connman kept applying the old address - while `docs/os-v3.md` says "deleting it is the same thing" as `reset`. Fix: `set-static` records what it configured in `/data/.net-manual`, and a boot with no usable file but that marker hands the link back to DHCP itself (only configurations this box wrote are undone; a service it never touched is left alone). The marker is cleared when that succeeds, and `reset` clears it as before. The row now covers the hand-recovery too: set again, `rm -f /data/net.conf` (what someone in a rescue shell does), reboot, and the link must be back on the DHCP lease with the marker gone. Nits: the header splice in zz-onboard-net is rewritten; docs/README count the network test as the 43 assertions it now prints (was "26 arms"); `connman_service_for_iface` no longer leaks `mac` into its caller. --- docs/os-v3.md | 2 +- os/v3/puppy/embed/etc/init.d/zz-onboard-net | 35 ++++++++++++++++++-- os/v3/puppy/embed/usr/local/bin/1bit-network | 12 +++++-- os/v3/puppy/install-probe.sh | 25 ++++++++++++++ 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/docs/os-v3.md b/docs/os-v3.md index 353b2b4dc..b5953cd19 100644 --- a/docs/os-v3.md +++ b/docs/os-v3.md @@ -156,7 +156,7 @@ named here as what they are: | logging | `06onboard-logs` keeps the boot's logs on `/data/logs` — the partition, not the filesystem that the next appliance replaces | `/data/logs` non-empty on the installed boot | | packages and services | `apt` works and its packages land in the save layer; the appliance's own services are `/etc/init.d` scripts, which is what `rc.services` runs (there is no systemd here, and nothing pretends there is) | — | -| an optional static address | `1bit-network set-static [gateway] [dns…]` writes **`/data/net.conf`** — on the data partition, so it outlives an appliance update — and `/etc/init.d/zz-onboard-net` applies it at boot through **connman's own CLI** (`connmanctl config --ipv4 manual …`), with `ip` only as the fallback for a link connman has no service for yet. The console's static action stays session-only, because a wrong address on a headless box is a walk to the machine; this one is persistent **and reversible in one command**: `1bit-network reset` deletes the file and hands the interface back to DHCP. An unparsable or unusable file is not applied at all — the boot leaves the link on DHCP and says so in `/var/log/1bit-network.log` | `tests/one_bit_network_conf_test.sh` (the address and file validation, 26 arms, no root or interface needed) and the installed boot's `1bit-network` rows | +| an optional static address | `1bit-network set-static [gateway] [dns…]` writes **`/data/net.conf`** — on the data partition, so it outlives an appliance update — and `/etc/init.d/zz-onboard-net` applies it at boot through **connman's own CLI** (`connmanctl config --ipv4 manual …`), with `ip` only as the fallback for a link connman has no service for yet. The console's static action stays session-only, because a wrong address on a headless box is a walk to the machine; this one is persistent **and reversible in one command**: `1bit-network reset` deletes the file and hands the interface back to DHCP. An unparsable or unusable file is not applied at all — the boot leaves the link on DHCP and says so in `/var/log/1bit-network.log` | `tests/one_bit_network_conf_test.sh` (the address and file validation, the `prefix_to_mask` table and the CIDR split — 43 assertions, no root or interface needed) and the installed boot's `1bit-network` rows | **Recovery, stated where someone under pressure will look:** `1bit-network reset` on tty1, the serial console, or the console menu's bash item. The file is `/data/net.conf`; deleting it is the same thing. diff --git a/os/v3/puppy/embed/etc/init.d/zz-onboard-net b/os/v3/puppy/embed/etc/init.d/zz-onboard-net index f92d85443..6b5d8215c 100755 --- a/os/v3/puppy/embed/etc/init.d/zz-onboard-net +++ b/os/v3/puppy/embed/etc/init.d/zz-onboard-net @@ -23,8 +23,13 @@ # script - so a `14onboard-net` ran BEFORE the daemon that owns the link existed: `connmanctl` had no service, the `ip` # fallback put the address on, and connman then took the link over and flushed it, so the machine came up with no address # at all for a while (measured: the row saw "" right after the reboot and the static address only minutes later, -# applied by connman from its own stored config). Running after it means the config is given to connman itself. with no file, or a file that does not validate, it does NOTHING and says so - a -# machine that cannot reach the LAN is worse than one on DHCP, and the repair path has to stay obvious: +# applied by connman from its own stored config). Running after it means the config is given to connman itself. +# +# With NO file - or a file that does not validate - it does nothing to the interface, except undo a manual configuration +# this box set earlier (`/data/.net-manual`): deleting `/data/net.conf` from a rescue shell is the recovery the docs +# promise, and connman would otherwise keep applying the old address at every boot. Doing nothing to a link it did not +# configure is deliberate - a machine that cannot reach the LAN is worse than one on DHCP, and the repair path has to +# stay obvious: # # recovery: 1bit-network reset (tty1, the serial console, or the console menu's bash item) # @@ -44,7 +49,31 @@ log() { printf '%s\n' "$*" | tee -a "$LOG"; } mkdir -p /tmp 2> /dev/null : >> "$LOG" 2> /dev/null || LOG=/dev/null -[ -f "$CONF" ] || { log "zz-onboard-net: no $CONF: the interface stays on DHCP (connman)"; exit 0; } +MARK=$DATA/.net-manual + +# No file: nothing to apply. But connman keeps a manual configuration in its OWN state, so if this machine ever set one +# and the file is now gone (someone deleted /data/net.conf by hand - the recovery the docs promise), hand the link back +# to DHCP here. Only configurations this box wrote are undone: the marker says so, and a service we never touched is left +# alone. +if [ ! -f "$CONF" ]; then + if [ -f "$MARK" ]; then + miface=$(head -1 "$MARK" 2> /dev/null) + [ -n "$miface" ] || { log "zz-onboard-net: $MARK is empty; nothing to hand back"; exit 0; } + NETWORK=/usr/local/bin/1bit-network + # shellcheck disable=SC1090 # the image's own path; one definition of the format and the service lookup + [ -r "$NETWORK" ] && ONEBIT_NETWORK_LIB=1 . "$NETWORK" + svc=$(connman_service_for_iface "$miface" 2> /dev/null) + if [ -n "$svc" ] && connmanctl config "$svc" --ipv4 dhcp >> "$LOG" 2>&1; then + rm -f "$MARK" + log "zz-onboard-net: no $CONF and a manual config was ours: $svc handed back to DHCP" + else + log "zz-onboard-net: no $CONF, and $miface could not be handed back to DHCP (see $LOG); will retry next boot" + fi + exit 0 + fi + log "zz-onboard-net: no $CONF: the interface stays on DHCP (connman)" + exit 0 +fi # the same parse and validation as 1bit-network, sourced rather than copied: one definition of "a usable net.conf" NETWORK=/usr/local/bin/1bit-network diff --git a/os/v3/puppy/embed/usr/local/bin/1bit-network b/os/v3/puppy/embed/usr/local/bin/1bit-network index d453eba89..4a3d7367f 100755 --- a/os/v3/puppy/embed/usr/local/bin/1bit-network +++ b/os/v3/puppy/embed/usr/local/bin/1bit-network @@ -35,6 +35,9 @@ set -u DATA=/data CONF=$DATA/net.conf +# what WE put on connman's own state (it persists a manual config across reboots, independent of net.conf): the boot uses +# it to hand the link back to DHCP when the file is gone, and never touches a configuration it did not write +MARK=$DATA/.net-manual LOG=/var/log/1bit-network.log say() { printf '%s\n' "$*" | tee -a "$LOG"; } die() { say "1bit-network: REFUSED: $*" >&2; exit 2; } @@ -141,9 +144,9 @@ conf_ok() { # the loaded values have to be usable, or the boot must not tou connman_service_for_iface() { [ -n "${1:-}" ] || return 1 command -v connmanctl > /dev/null 2>&1 || return 1 - mac=$(cat "/sys/class/net/$1/address" 2> /dev/null | tr -d ':') - [ -n "$mac" ] || return 1 - connmanctl services 2> /dev/null | awk -v m="$mac" ' + _csfi_mac=$(cat "/sys/class/net/$1/address" 2> /dev/null | tr -d ':') + [ -n "$_csfi_mac" ] || return 1 + connmanctl services 2> /dev/null | awk -v m="$_csfi_mac" ' index($0, m) { for (i = 1; i <= NF; i++) if ($i ~ /^(ethernet|wifi|bluetooth)_/) { print $i; exit } }' } @@ -202,6 +205,7 @@ fi if [ "$mode" = reset ]; then read_conf "$CONF" rm -f "$CONF" || fail "cannot remove $CONF" + # the marker goes only after connman has been handed back below; if that fails it stays, and the next boot retries # give the interface back to DHCP through connman, so a wrong address really is gone and not just forgotten. # The lookup is by MAC (the old one took the first connected service on any link, which on a two-interface machine # is the wrong one), and the result is reported rather than assumed. @@ -217,6 +221,7 @@ if [ "$mode" = reset ]; then say "1bit-network: connman has no service for $iface; the link keeps its address until reconnect" fi fi + rm -f "$MARK" 2> /dev/null say "1bit-network: reset - $CONF removed, the next boot and this one use DHCP" say " (if the link still carries the old address, restart the network: /etc/init.d/connman restart)" exit 0 @@ -254,6 +259,7 @@ tmp=$CONF.tmp true } > "$tmp" || fail "cannot write $tmp" mv -f "$tmp" "$CONF" || fail "cannot install $CONF" +printf '%s\n' "$dev" > "$MARK" 2> /dev/null # so a boot without the file can undo what this command did sync say "1bit-network: persisted to $CONF (iface=$dev static=$addr gateway=${gw:--} dns=${dnsv:--})" diff --git a/os/v3/puppy/install-probe.sh b/os/v3/puppy/install-probe.sh index cb2d2963e..4924ad78b 100755 --- a/os/v3/puppy/install-probe.sh +++ b/os/v3/puppy/install-probe.sh @@ -750,6 +750,31 @@ if assert_pupsfs: else: print("PASS net reset removed /data/net.conf and the link is back on DHCP (%s)" % dhcp_addr.split("/")[0]) + # ---- and the OTHER documented recovery: delete /data/net.conf by hand (a rescue shell), reboot. + # connman keeps a manual configuration in its own state, so without the marker the box would stay + # on the static address for ever while the doc says "deleting it is the same thing" (review on + # #1527). Re-apply, then delete the file instead of using reset. + val("SETAGAIN", "1bit-network set-static %s %s >/dev/null 2>&1;" % (static_addr, gw or "") + + " rm -f /data/net.conf; ls /data/.net-manual >/dev/null 2>&1 && echo marker", timeout=240) + if not v.reboot(): + print("FAIL net the machine did not come back after the hand-deleted net.conf"); ok = False + v.close() + else: + val("WAITDHCP", "n=0; while [ $n -lt 24 ]; do " + "ip -4 -o addr show dev %s 2>/dev/null | grep -q '%s' && break; " + "sleep 5; n=$((n+1)); done; echo waited" % (dev, dhcp_addr.split('/')[0]), timeout=180) + back = val("DHCPBACK", "ip -4 -o addr show dev %s 2>/dev/null | awk '{ print $4 }'" % dev) + mk = val("MARK", "ls /data/.net-manual 2>&1 | head -1") + print("INFO net after deleting net.conf by hand and rebooting: %s | marker: %s" + % (back or "", mk[-40:])) + if dhcp_addr.split("/")[0] not in (back or ""): + print("FAIL net with net.conf deleted by hand the link did not return to DHCP (%s):" + " the documented hand-recovery does not recover" % (back or "")); ok = False + elif "No such file" not in mk: + print("FAIL net the marker survived: the box keeps undoing DHCP every boot (%s)" % mk[-40:]); ok = False + else: + print("PASS net deleting /data/net.conf by hand is a real recovery: the next boot" + " hands the link back to DHCP (%s) and clears the marker" % dhcp_addr.split("/")[0]) else: print("INFO net no global IPv4 address on this boot (%s): the static-address rows are a SKIP" % (cur or "")) wrote = val("WROTE", "sh -c 'echo 712 > /root/712-persist; sync; cat /root/712-persist'") From a1d486132e6772504a27a4e8506845f8635ad68c Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 16:21:04 -0400 Subject: [PATCH 4/4] os: the hand-back is waited for, retried and covers a broken file (#1527 review) Three paths in the new code did not do what their comments said, and the first two could cancel the very recovery the previous commit adds: 1. `reset` removed the marker **unconditionally**, after a failed hand-back too - and `net.conf` was already gone by then, so the next boot took the plain "stays on DHCP" branch and connman kept applying the old address for ever. The marker is now removed only inside the `--ipv4 dhcp` success branch, and the failure messages say it stays. 2. the no-file hand-back looked the service up **immediately**, but the 30 s wait for connman lived only in the file-present path below it - on a box where connman is slow that is "will retry next boot" at every boot, i.e. the hand-recovery never recovers. The wait is now inside `hand_back`, which both paths call. 3. a file that does not **validate** exits before any of that, so the header's "or a file that does not validate" was false: a hand-edited broken `net.conf` left connman applying the old address. It now goes through the same hand-back. The hand-back is one function (`hand_back`), the docs say what it does and note the one case it cannot fix (a box configured while #1513 was merged has a manual connman config and no marker: run `1bit-network reset` once). --- docs/os-v3.md | 6 +- os/v3/puppy/embed/etc/init.d/zz-onboard-net | 59 ++++++++++++++------ os/v3/puppy/embed/usr/local/bin/1bit-network | 8 ++- 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/docs/os-v3.md b/docs/os-v3.md index b5953cd19..ebf7d9972 100644 --- a/docs/os-v3.md +++ b/docs/os-v3.md @@ -159,7 +159,11 @@ named here as what they are: | an optional static address | `1bit-network set-static [gateway] [dns…]` writes **`/data/net.conf`** — on the data partition, so it outlives an appliance update — and `/etc/init.d/zz-onboard-net` applies it at boot through **connman's own CLI** (`connmanctl config --ipv4 manual …`), with `ip` only as the fallback for a link connman has no service for yet. The console's static action stays session-only, because a wrong address on a headless box is a walk to the machine; this one is persistent **and reversible in one command**: `1bit-network reset` deletes the file and hands the interface back to DHCP. An unparsable or unusable file is not applied at all — the boot leaves the link on DHCP and says so in `/var/log/1bit-network.log` | `tests/one_bit_network_conf_test.sh` (the address and file validation, the `prefix_to_mask` table and the CIDR split — 43 assertions, no root or interface needed) and the installed boot's `1bit-network` rows | **Recovery, stated where someone under pressure will look:** `1bit-network reset` on tty1, the serial console, or the -console menu's bash item. The file is `/data/net.conf`; deleting it is the same thing. +console menu's bash item — and deleting `/data/net.conf` really is the same thing: the boot undoes a manual configuration +*this box* wrote (it records that in `/data/.net-manual`) and leaves a connection it never touched alone. A file that no +longer parses is treated the same way: the address is handed back rather than left applied invisibly. +*A machine configured while #1513 was merged has a manual connman config and no marker, so run `1bit-network reset` once +after updating it.* ## The Ubuntu plan (history, not a target) diff --git a/os/v3/puppy/embed/etc/init.d/zz-onboard-net b/os/v3/puppy/embed/etc/init.d/zz-onboard-net index 6b5d8215c..86390d327 100755 --- a/os/v3/puppy/embed/etc/init.d/zz-onboard-net +++ b/os/v3/puppy/embed/etc/init.d/zz-onboard-net @@ -51,24 +51,43 @@ mkdir -p /tmp 2> /dev/null MARK=$DATA/.net-manual -# No file: nothing to apply. But connman keeps a manual configuration in its OWN state, so if this machine ever set one -# and the file is now gone (someone deleted /data/net.conf by hand - the recovery the docs promise), hand the link back -# to DHCP here. Only configurations this box wrote are undone: the marker says so, and a service we never touched is left -# alone. +# load the library first: it defines the format parse AND the service lookup, and the hand-back below needs both +NETWORK=/usr/local/bin/1bit-network +if [ -r "$NETWORK" ]; then + # shellcheck disable=SC1090 # the image's own path; one definition of the format and of the service lookup + ONEBIT_NETWORK_LIB=1 . "$NETWORK" +fi + +# hand_back REASON: give the interface this box configured back to DHCP. connman keeps a manual configuration in its OWN +# state, so removing /data/net.conf is not enough - without this the old address comes back at every boot and the recovery +# the docs promise does not recover (measured, and the review found the two paths that skipped it). +# The marker is removed ONLY when connman actually took the change: a failed hand-back has to stay visible to the next boot. +hand_back() { + miface=$(head -1 "$MARK" 2> /dev/null) + [ -n "$miface" ] || { log "zz-onboard-net: $1: $MARK is empty, so there is nothing to hand back"; return 1; } + # connman starts late (it sorts under "c"), so wait for it to publish a service for that interface before asking - + # the first version looked it up immediately and logged "will retry next boot" at every boot on a slow box + i=0 + while [ $i -lt 30 ]; do + [ -n "$(connman_service_for_iface "$miface" 2> /dev/null)" ] && break + sleep 1 + i=$((i + 1)) + done + svc=$(connman_service_for_iface "$miface" 2> /dev/null) + if [ -n "$svc" ] && connmanctl config "$svc" --ipv4 dhcp >> "$LOG" 2>&1; then + rm -f "$MARK" + log "zz-onboard-net: $1: $svc handed back to DHCP (that manual config was this box's)" + return 0 + fi + log "zz-onboard-net: $1: $miface could not be handed back to DHCP (see $LOG); the marker stays, the next boot retries" + return 1 +} + +# No file: nothing to apply - except undoing a manual configuration this box set earlier, which is the recovery the docs +# promise for `rm /data/net.conf`. A service this box never touched is left alone. if [ ! -f "$CONF" ]; then if [ -f "$MARK" ]; then - miface=$(head -1 "$MARK" 2> /dev/null) - [ -n "$miface" ] || { log "zz-onboard-net: $MARK is empty; nothing to hand back"; exit 0; } - NETWORK=/usr/local/bin/1bit-network - # shellcheck disable=SC1090 # the image's own path; one definition of the format and the service lookup - [ -r "$NETWORK" ] && ONEBIT_NETWORK_LIB=1 . "$NETWORK" - svc=$(connman_service_for_iface "$miface" 2> /dev/null) - if [ -n "$svc" ] && connmanctl config "$svc" --ipv4 dhcp >> "$LOG" 2>&1; then - rm -f "$MARK" - log "zz-onboard-net: no $CONF and a manual config was ours: $svc handed back to DHCP" - else - log "zz-onboard-net: no $CONF, and $miface could not be handed back to DHCP (see $LOG); will retry next boot" - fi + hand_back "no $CONF" exit 0 fi log "zz-onboard-net: no $CONF: the interface stays on DHCP (connman)" @@ -88,7 +107,13 @@ fi read_conf "$CONF" if ! why=$(conf_ok 2>&1); then - log "zz-onboard-net: $CONF is not usable ($why): leaving the network on DHCP. Recovery: 1bit-network reset" + # A broken file must not leave connman applying an address nobody can see: undo our own manual config, and say which + # case this is (the header promised exactly this, and it did not do it - review finding on #1527) + if [ -f "$MARK" ]; then + hand_back "$CONF is not usable ($why)" + else + log "zz-onboard-net: $CONF is not usable ($why): leaving the network on DHCP. Recovery: 1bit-network reset" + fi exit 0 fi diff --git a/os/v3/puppy/embed/usr/local/bin/1bit-network b/os/v3/puppy/embed/usr/local/bin/1bit-network index 4a3d7367f..ac73d241d 100755 --- a/os/v3/puppy/embed/usr/local/bin/1bit-network +++ b/os/v3/puppy/embed/usr/local/bin/1bit-network @@ -214,14 +214,16 @@ if [ "$mode" = reset ]; then if [ -n "$svc" ]; then if connmanctl config "$svc" --ipv4 dhcp >> "$LOG" 2>&1; then say "1bit-network: $svc back to DHCP" + # ONLY here: with the file already gone, a failed hand-back that also dropped the marker would leave no + # file, no marker and connman still applying the old address for ever - the hole this marker exists for + rm -f "$MARK" 2> /dev/null else - say "1bit-network: connman refused to put $svc back on DHCP (see $LOG); restart it: /etc/init.d/connman restart" + say "1bit-network: connman refused to put $svc back on DHCP (see $LOG); the marker stays and the next boot retries" fi else - say "1bit-network: connman has no service for $iface; the link keeps its address until reconnect" + say "1bit-network: connman has no service for $iface; the marker stays and the next boot retries" fi fi - rm -f "$MARK" 2> /dev/null say "1bit-network: reset - $CONF removed, the next boot and this one use DHCP" say " (if the link still carries the old address, restart the network: /etc/init.d/connman restart)" exit 0