Skip to content

Init scripts: parse netmask + gateway DNS instead of hardcoded /24 + 8.8.8.8 #275

@aniketmaurya

Description

@aniketmaurya

Context

CodeRabbit flagged two issues on `scripts/ci/preset-init.sh` in #271:

  1. Hardcoded `/24` netmask (preset-init.sh:64) — the kernel `ip=` cmdline format includes a netmask field at position 4, but we always assume /24. Breaks routing on non-/24 networks.

  2. Hardcoded Google DNS (preset-init.sh:66-68) — overwrites `/etc/resolv.conf` with `8.8.8.8` / `8.8.4.4` regardless of what the network supplies. Fails on locked-down/airgapped networks.

Both findings are valid. Skipped from #271 because the same patterns exist in the existing openclaw `/init` (builder.py::_base_init_script) — fixing only the layered preset init creates asymmetric behavior.

Fix

Apply CodeRabbit's proposed fixes to both init scripts so layered presets and openclaw stay in sync:

  • Parse `NETMASK` from `ip=::::...` and convert to CIDR prefix via a `netmask_to_prefix()` shell helper.
  • Use `GATEWAY` as the primary DNS resolver; only fall back to public 8.8.8.8/8.8.4.4 when no gateway is parsed.

Acceptance

  • VMs on non-/24 subnets (e.g. /16, /20) get correct routing.
  • VMs on networks where the gateway is also a DNS resolver use it; only fall through to Google DNS when the gateway is empty.
  • Existing /24 + 8.8.8.8 behavior preserved as fallback for current SmolVM-managed networking (which sets a /24 explicitly).

Files

  • `scripts/ci/preset-init.sh` — layered presets
  • `src/smolvm/images/builder.py::_base_init_script` — openclaw via the heredoc-generated /init

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions