Files
RedBear-OS/netstack/src
Red Bear OS e416b48bd8 review: fix 5 panic/crash bugs + 1 two-phase pattern + 3 semantic bugs
CRITICAL BUGS FIXED:

1. Smolnetd startup panic on missing/malformed ip_router cfg (scheme/mod.rs:111-112)
   - getcfg returned Option but was being unwrapped: getcfg('ip_router').unwrap()
   - .expect('Can't parse the ip_router cfg.') on malformed IP would panic
   - Fix: match on Result, fall back to 0.0.0.0 with warning log

2. Smolnetd default route panic on 0.0.0.0 gateway (scheme/mod.rs:140-142)
   - iface.routes_mut().add_default_ipv4_route(0.0.0.0).expect(...) panics
   - smoltcp rejects default route with 0.0.0.0 as gateway
   - Fix: skip route addition when gateway is unspecified

3. TUN event loop destroyed data (scheme/tun.rs:119-133)
   - Loop moved packets from dev.tx to dev.rx - stealing data userspace was
     supposed to read (since dev.tx is aliased to device_rx)
   - Fix: only clear stale packets from dev.tx; data transfer between
     userspace and network is via TunDevice::recv() called by poller

4. ip_forward sysctl broke two-phase write/commit pattern (netcfg/mod.rs:367-389)
   - write_line closure immediately called ip_forward.set()
   - Inconsistent with other writable nodes
   - Fix: write_line stores value in cur_value, commit applies it

5. ICMP Udp socket was non-functional (scheme/icmp.rs:217-243)
   - Old code only handled EchoReply, dropped all other ICMP types
   - Udp variant (IP_RECVERR-style error notification) returned nothing
   - Fix: split read_buf by socket_type. Echo still only matches EchoReply.
     Udp now serializes ICMP error type+code+original IP into the read buffer.

SEMANTIC BUGS FIXED:

6. UDP connected local_addr resolution was inverted (scheme/udp.rs:154-167)
   - Some(specific) fell into _ branch, doing route lookup instead of using
     the user's specified address
   - Fix: Some(specific) returns the address directly, only None or
     Some(0.0.0.0) trigger route lookup

7. claim_port_reuse lacked documentation (port_set.rs:50-53)
   - Always returned true, but semantics of why it never fails was unclear
   - Fix: doc comment explains the two-phase collision check (claim_port
     first, claim_port_reuse only on SO_REUSEADDR path)

All 29 existing tests still pass.
2026-07-09 00:13:29 +03:00
..