Commit Graph

13 Commits

Author SHA1 Message Date
Red Bear OS efa24228e3 review: fix 5 panic/crash bugs + 1 off-by-2 + add 6 regression tests
CRITICAL BUGS FIXED:

1. STP build_bpdu runtime panic (link/stp.rs:121-123)
   - Duration::total_millis() returns i64, to_be_bytes() = [u8; 8]
   - But destination buffers (buf[29..31], buf[31..33], buf[33..35]) are 2 bytes
   - copy_from_slice panics on length mismatch
   - Triggered by every root bridge hello BPDU — daemon crash
   - Fix: convert to ticks (1s = 256 ticks per IEEE 802.1D) as u16

2. SLAAC PIO off-by-2 byte parsing (slaac.rs:155-180)
   - parse_router_advertisement used opt_data[2] for prefix length
   - After pos += 2 consumed type+length, opt_data[0] is the prefix length
   - All PIO fields were off by 2 — SLAAC got wrong prefix length, flags,
     valid_lifetime (read Preferred Lifetime), preferred_lifetime (read Reserved2)
   - Fix: use opt_data[0] for prefix length, [1] for flags, [2..6] for valid,
     [6..10] for preferred, [14..30] for prefix bytes

3. ICMPv4 error wrong IHL extraction (icmp_error.rs:25, 62)
   - (ipv4.version() & 0x0f) * 4 always computed 16
   - smoltcp's version() returns 4 (version), not combined byte
   - Fix: use ipv4.header_len()

4. UDP can_recv panic on port-only endpoint (scheme/udp.rs:54)
   - data.addr.unwrap() panics if addr is None (e.g. udp/:53)
   - is_specified() returns true when port is non-zero, even if addr is None
   - Fix: use let-else pattern, accept all packets if addr is None

5. TCP .expect() calls crash daemon (scheme/tcp.rs)
   - 5 .expect() calls in connect/listen/send/recv paths
   - Any socket error panics the entire netstack daemon
   - Fix: replace with .map_err() returning EIO

6. ICMP .unwrap() on malformed packets (scheme/icmp.rs:217-220)
   - recv().expect() panics, Icmpv4Repr::parse().unwrap() panics
   - Crafted/malformed ICMP packets would crash the daemon
   - Fix: use match, drop unparseable packets

NEW TESTS (6 added, 29 total now passing):
- icmp_error::icmpv4_short_packet_returns_none
- icmp_error::icmpv4_preserves_destination_address (regression for bug 3)
- icmp_error::icmpv4_with_ip_options_includes_extended_header
- slaac::ra_with_pio_64_parses_correctly (regression for bug 2)
- link::stp::bpdu_minimal_parses
- link::stp::bpdu_short_returns_none
- link::stp::bpdu_wrong_protocol_returns_none
- link::stp::build_bpdu_does_not_panic (regression for bug 1)

The SLAAC test would have failed before the off-by-2 fix.
The STP build_bpdu test would have panicked before the ticks fix.
The ICMP tests verify the full IP header (incl. IHL=6 options) is preserved.
2026-07-08 23:41:42 +03:00
Red Bear OS 9bab466704 netcfg: interface enable/disable control (ip link set eth0 down/up)
LinkDevice trait gains is_enabled() and set_enabled() with defaults.
EthernetLink stores enabled flag (default: true). When disabled,
link_state() reports 'down' regardless of hardware_address presence.

netcfg/ifaces/eth0/enabled is rw:
  cat /scheme/netcfg/ifaces/eth0/enabled  →  'up' or 'down'
  echo up   > .../enabled  →  bring interface up
  echo down > .../enabled  →  bring interface down
  echo on/off/1/0/yes/no  →  also accepted

Mirrors Linux 'ip link set dev <state>'.

Pre-existing link state (hardware_address Some/None) unchanged;
the enabled flag adds a software override layer that can be
toggled without restarting the netstack.
2026-07-08 18:24:02 +03:00
Red Bear OS 30db94c970 stp: integrate 802.1D Spanning Tree Protocol into BridgeDevice
Adds loop prevention to Ethernet bridges:
- BridgeDevice gains stp: Option<StpState> field
- enable_stp(priority, mac) method initializes STP per-bridge
- BPDU frames (dst 01:80:c2:00:00:00) intercepted in recv(),
  processed locally, never forwarded
- STP hello timer sends periodic BPDUs on all ports (root bridge)
- flood() skips STP-blocked ports
- build_bpdu() made public for bridge integration
- stp module declared in link/mod.rs

The recv() flow now: age MACs → check STP hello timer →
poll ports → detect BPDU (absorb) → normal frame (learn + forward).

Reference: Linux 7.1 net/bridge/br_stp.c, br_stp_bpdu.c, br_stp_timer.c
2026-07-08 13:38:38 +03:00
Red Bear OS bb3e36e4e0 restore: networking stack files from reflog (Phases 1-6)
Recovered from reflog commits 1c80937e and d0ecc067 after force-push data loss.
Includes: filter/, icmp_error.rs, slaac.rs, bond.rs, bridge.rs, gre.rs, ipip.rs,
qdisc.rs, tun.rs, vlan.rs, vxlan.rs, netfilter.rs, tun.rs, conntrack.rs, nat.rs,
rule.rs, table.rs, redbear-ufw/, dhcpv6d/, netdiag/ — 39 files total.
2026-07-08 13:27:49 +03:00
Red Bear OS d0ecc06734 networking: update Cargo.lock 2026-07-07 21:47:58 +03:00
Red Bear OS 384ab65f2f 0.3.0: bump libredox/redox-scheme lockfile versions to +rb0.3.0 2026-07-06 20:41:28 +03:00
vasilito 1bfba43a5b 0.3.0: bump redox_syscall references to +rb0.3.0 2026-07-06 19:49:18 +03:00
Red Bear OS e653ef10d6 base: revert oneshot_async service types, fix local fork deps, migrate remote to RedBear-OS
- Revert initfs/rootfs service types from oneshot_async to blocking
  Scheme/Notify/Oneshot to fix init ordering races.
- Add /scheme/pci retry loop in pcid-spawner.
- Bump redox_event to 0.4.8; use local paths for redox-ioctl and redox-rt.
- Regenerate Cargo.lock / bootstrap/Cargo.lock with only local forks.
- Update submodule origin from redbear-os-base.git to RedBear-OS.git
  branch submodule/base per single-repo policy.
2026-07-05 22:25:00 +03:00
vasilito a3b8a34d9c acpid: fix extra closing brace in getdents match
In drivers/acpid/src/scheme.rs, the getdents function's
match on HandleKind has 8 arm-close braces for 8 arms,
but the source had 9 closing braces (the 9th at line
669 was extra, indented differently from the match
opener at line 538). Rust's parser couldn't match
them up:

  error: unexpected closing delimiter: '}'
  note: this delimiter might not be properly closed...
  note: ...as it matches this but it has different indentation

The extra brace was at line 669, immediately after the
HandleKind::ProcFile | DmiDir arm body, before the '_'
wildcard. Removing it (so the 8 arm-closes match the 8
arms) makes the match block close cleanly. The match
block now closes at the proper 8-space indent, matching
the 'match' keyword.

This is a pre-existing bug in the Phase II.X.W commit
'dcd70a1 acpid: Phase II.X.W S3 wake handling + kstop_enter_s3 helper'.
The brace was probably added by mistake during one of
the Phase II.X.W edits. The Phase II.X.W build was
presumably tested on hardware that didn't exercise the
getdents path that triggers this brace mismatch.

Discovered when the redbear-mini build started exercising
the acpid getdents path. Fix: delete the extra brace.
2026-07-02 11:37:53 +03:00
Red Bear OS 59f3e42af6 base: unify syscall dependency to local path source
Change [workspace.dependencies] redox_syscall from git URL to path = "../syscall"
to match the [patch.crates-io] source. This eliminates the dual-source 0.8.1
conflict (git checkout vs local path) that caused 'multiple different versions
of crate syscall in the dependency graph' compilation errors in scheme-utils
and daemon crates.

The local fork at local/sources/syscall/ is upstream 79cb6d9 (0.8.1).

parking_lot_core 0.9.12 still pulls redox_syscall 0.5.18 from crates.io
(semver prevents the path patch from satisfying ^0.5), but its syscall::Error
type is internal and does not leak into public APIs.
2026-07-01 07:08:58 +03:00
Red Bear OS ae57fe3226 base: re-sync ACPI userspace with upstream master
Phase B of the ACPI fork-sync plan (local/docs/ACPI-FORK-SYNC-STRATEGY-2026-06-30.md).
Pairs with the kernel fork-sync commit 4f2a043.

Restores the base fork to match upstream Redox OS base master for the
ACPI userspace:

- Cargo.toml (workspace):
  * Add acpi = { git = "...redox-os/acpi.git", branch = "redox-6.x" }
    workspace dependency. The jackpot51/acpi GitHub fork was
    deprecated in favor of the gitlab.redox-os.org fork that
    tracks the redox-6.x branch (has AcpiVerb-style AML updates,
    PIIX4 fixes, VirtualBox boot fix per upstream MR #243).
  * Switch redox_syscall from crates.io 0.8.1 to a git ref of
    gitlab.redox-os.org/redox-os/syscall.git, with [patch.crates-io]
    redirecting crates.io consumers to the gitlab fork. The
    crates.io 0.8.1 release predates AcpiVerb (commit 79cb6d9)
    that the kernel MR #613 / base MR #275 introduce.

- drivers/acpid/Cargo.toml: acpi.workspace = true.

- drivers/amlserde/Cargo.toml: acpi.workspace = true.

- drivers/hwd/Cargo.toml: add redox_syscall.workspace = true
  dependency. HWD now needs the AcpiVerb enum to construct Fd-based
  calls into the kernel ACPI scheme.

- drivers/amlserde/src/lib.rs: split AmlSerdeReferenceKind::LocalOrArg
  into 4 separate variants matching the new gitlab acpi crate
  ReferenceKind enum:
    Local, Arg, Index, Named
  Required by upstream commit "Update ACPI crate" (f2f834d4).

- drivers/acpid/src/main.rs: rewrite the RXSDT and kstop acquisition
  to use the new Fd::open + call_ro(AcpiVerb::*) interface:
    kernel_acpi_handle = Fd::open("/scheme/kernel.acpi", O_CLOEXEC, 0)
    rxsdt = kernel_acpi_handle.call_ro(buf, READ, &[ReadRxsdt])
    shutdown_pipe = kernel_acpi_handle.openat("kstop", O_CLOEXEC, 0)
  Also fixes the nsmgr deadlock by moving setrens(0, 0) BEFORE
  daemon.ready() (upstream commit 9dd6901d).

- drivers/hwd/src/backend/acpi.rs: rewrite AcpiBackend::new() to use
  the new Fd::open + call_ro(AcpiVerb::ReadRxsdt) interface, matching
  the kernel ACPI scheme rewrite.

Verified by: CI=1 ./local/scripts/build-redbear.sh redbear-mini
succeeded with exit 0, producing build/x86_64/redbear-mini.iso
(512 MB) at 2026-06-30 04:54.
2026-06-30 04:56:51 +03:00
Red Bear OS 011f0de1ae Bump redox_syscall to 0.8.1, libredox to 0.1.17 (upstream adaptation) 2026-06-27 10:44:52 +03:00
Red Bear OS dd08b76a39 Red Bear OS base baseline from 0.1.0 pre-patched archive 2026-06-27 09:21:43 +03:00