Commit Graph

66 Commits

Author SHA1 Message Date
Red Bear OS b9e2ec31d5 netstack: add proptest cases to filter/table + filter/conntrack
Phase 7 of the systematic plan: proptest-driven property-based
testing for the firewall and conntrack state machines.

filter/table.rs: 2 proptest cases (prop_filter_table, prop_filter_counters)
  that generate random FilterRule sets and assert that:
  - the rule parser survives arbitrary input,
  - reset_counters() preserves rule state,
  - per-chain counters increment monotonically under repeated hits.

filter/conntrack.rs: 2 proptest cases (prop_conn_key, prop_conntrack_insert)
  that generate random 5-tuple keys and assert that:
  - ConnKey Hash/Eq produce stable results,
  - insert and lookup are round-trip consistent,
  - expiry cleanup does not panic on degenerate timestamps.

Both modules gate the new tests behind cfg(test) and only pull
proptest in as a dev-dependency (added to netstack/Cargo.toml).

This commit does not change the smoltcp 0.13.1 API call site in
scheme/ip.rs (RawSocket::new takes IpVersion not Some(IpVersion));
the merge had to repair a subagent helper that re-introduced Some().
2026-07-26 19:53:36 +09:00
Red Bear OS 20d805ed37 netstack: parse_endpoint accepts bracketed IPv6
The endpoint parser previously only handled dotted IPv4 syntax
('10.0.2.15:80'). Extend it to accept the dual form that this same
change adds to relibc:

    [hh:hh:hh:hh:hh:hh:hh:hh]:port      (global)
    [hh:hh:hh:hh:hh:hh:hh:hh%scope]:port (link-local w/ scope)

The presence of '[' at the start is the unambiguous discriminator: in
that case the rest up to ']' is the host and everything after is the
port. Outside of brackets, the legacy splitn(2, ':') behaviour is
kept for backwards compatibility with every existing profile file and
runtime caller.

A '\%scope' suffix (RFC 4007 zone id) is stripped before
Ipv6Address::from_str; Smoltcp does not encode the scope id in its
IpAddress so the underlying transport ignores it, which matches the
behaviour of the Linux 5.x IN6_IS_ADDR_LINKLOCAL check for routing
resolutions on a per-interface basis.
2026-07-26 16:56:28 +09:00
Red Bear OS b887d2b450 netstack: bump smoltcp 0.12.0 -> 0.13.1 in Cargo.toml
The 0.13 release line contains critical TCP correctness fixes that
backport into Red Bear:

- RFC 6298 retransmit backoff (was using a non-standard exponential
  backoff with a different initial value)
- zero-window probes (the previous code did not implement them, so
  connections stalled when the receiver advertised a 0 window)
- FIN retransmit in CLOSING state (the prior code only retransmitted
  FIN from FIN-WAIT-1 and never recovered from a lost second FIN)
- SYN crash on unspecified address (the kernel would panic on a
  SYN with src == 0.0.0.0; the 0.13.1 fix returns a RST)
- IPv6 SLAAC support on the wire when the upstream proto-ipv6
  feature is enabled (Red Bear already enables proto-ipv6)

The code in scheme/ip.rs is already in 0.13.1 form (RawSocket::new
takes IpVersion directly, not Option<IpVersion>) and scheme/icmp.rs
already uses the 0.13.1 ip_protocol() signature, so the migration is
intentionally restricted to the version field. The Cargo.lock will be
regenerated by the canonical build (cookbook uses --locked, so the
next build-redbear.sh run will refresh the lockfile after the
workspace can resolve smoltcp 0.13.1).
2026-07-26 16:36:50 +09:00
Red Bear OS 9e5f915d42 netstack+drivers: TCP write_buf return, dhcpd iface arg, virtio DMA sync, ip fpath
- tcp/scheme/tcp.rs: write_buf now returns the actual bytes from
  send_slice() instead of buf.len(). Fixes TCP silent data truncation
  when the send buffer cannot accept the full request.
- netstack/scheme/ip.rs: fpath() uses .expect() with a message in place
  of .unwrap() for clearer diagnostics on buffer write failure.
- dhcpd/main.rs: parse the first non-flag positional argument as the
  interface name. Previously dhcpd was hardcoded to 'eth0', which broke
  when netctl spawned dhcpd with a different iface name.
- drivers/common/dma.rs: introduce Dma::sync_for_cpu() and
  sync_for_device() that issue acquire/release fences. Provides a
  portable API for DMA-buffer ordering without a hard dependency on
  architecture-specific memory barriers.
- drivers/net/virtio-netd/scheme.rs: call sync_for_cpu() before reading
  the VirtHeader in try_recv and sync_for_device() before queueing the
  TX chain. Eliminates the risk of reading partially-written DMA
  contents on architectures where the device and CPU do not share a
  coherent cache.
2026-07-26 16:26:58 +09:00
Red Bear OS 2e5e516587 net: wait for async NIC attach instead of one-shot-exit (fixes no-eth0 boot)
driver-manager attaches NIC drivers asynchronously, so on a fresh boot the
network.* scheme does not exist yet when smolnetd/dhcpd run (both gated only on
the driver-manager service having *started*). smolnetd scanned /scheme once,
found nothing, and exited -> /scheme/netcfg never came up -> dhcpd/netctl failed
with "Can't open /scheme/netcfg/ifaces/eth0/mac" and DHCP timed out.

- smolnetd: poll (bounded 20s) for a network.* adapter to appear before giving
  up; oneshot_async so this never blocks boot. Give-up log now distinguishes
  genuinely-NIC-less from a NIC-present-but-driver-failed (stale driver) case.
- dhcpd: wait (bounded 20s) for /scheme/netcfg/ifaces/eth0/mac to appear before
  attempting DHCP, instead of one-shot "Can't open"; exit clean if no NIC.
2026-07-25 16:02:50 +09:00
Red Bear OS 0120017484 fix(net): silence benign no-network warnings; add e1000e (82574) support
- smolnetd: an empty ip_router (DHCP-managed or deliberately network-less like
  the bare target) is a valid 'no default gateway' state, not a malformed config
  -> no warning.
- router: a limited/directed IPv4 broadcast (DHCP DISCOVER to 255.255.255.255
  before any lease/route exists) legitimately has no routing-table entry; don't
  warn 'No route found' for broadcast destinations.
- e1000d: add the 82574L (0x10d3, QEMU '-device e1000e') to the E1000 match
  list; it keeps the legacy descriptor/register interface this driver uses.
  I219 is intentionally excluded (integrated MDIO PHY, different init).
2026-07-18 00:49:44 +09:00
Red Bear OS 1769b083ab fix(boot): clean up bare/mini boot warnings and errors
- init: add condition_path_exists so optional-daemon units (dbus, seatd,
  thermald, evdevd) are silently skipped when their binary is absent in a
  minimal image, instead of emitting [FAILED] 'No such file or directory' on
  the bare target. Boot-critical units omit the field and still hard-fail.
- ahcid: an empty ATAPI/optical drive (QEMU's default DVD-ROM, most bare-metal
  optical bays) failed READ CAPACITY and logged 4 ERROR lines every boot;
  register it with a zero block count as a normal no-media state and drop the
  HBA register dump to debug level.
- netstack: a machine with no NIC (bare, or an unsupported NIC) logged an ERROR
  and exited non-zero; treat 'no network adapter' as a normal idle state
  (info + clean exit).
- dhcpd: cut the socket timeout 30s -> 8s so the network stage fails fast when
  no DHCP server answers instead of stalling boot.
2026-07-18 00:29:43 +09:00
Red Bear OS bd595851e2 base: apply Red Bear patches on latest upstream/main
251 files: init, acpid, ipcd, netcfg, ihdgd, virtio-gpud, scheme-utils,
inputd, block driver, ptyd, ramfs, randd, initfs bootstrap, path deps,
version +rb0.3.1, author attribution
2026-07-11 11:39:24 +03:00
Anhad Singh cdea756569 fix(tcp/write_buf): incorrect return value
On success, the number of bytes written should be returned.

Previously `buf.len()` was always returned. The function `send_slice`
> ... returns the amount of octets actually enqueued, which is limited
> by the amount of free space in the transmit buffer; down to zero.

"down to zero" is okay as that is checked by `can_send`.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-06-25 23:55:00 +10:00
Anhad Singh 7bfca6c5ab misc(netstack): update smoltcp to v0.13.1
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-06-24 16:56:05 +10:00
Antoine Reversat ddb7de4ea7 Remove max loglevel feature from netstack and reduce default loglevel 2026-05-06 16:30:45 -04:00
bjorn3 8e2b451965 Update Makefile in preparation for using it in the base recipes 2026-04-20 21:00:10 +02:00
bjorn3 69c1f56cf0 Workaround hardlink issue in CI 2026-04-19 21:24:09 +02:00
bjorn3 daf726c30d scheme-utils: Have FpathWriter handle writing the scheme name 2026-04-19 19:07:41 +02:00
bjorn3 64d23e9e05 scheme-utils: Introduce FpathWriter helper 2026-04-19 19:07:41 +02:00
Wildan M 40b1dce975 Add compiling and testing with Makefile 2026-04-19 15:48:52 +07:00
bjorn3 cdede58055 Couple of minor scheme related cleanups 2026-04-16 18:44:07 +02:00
bjorn3 317a0178b6 Introduce scheme-utils crate and HandleMap type
HandleMap deduplicates the id assignment for handles and unlike most
existing implementations handles overflow just fine.
2026-04-13 22:19:07 +02:00
Benton60 2440ef302b switch to using the remote endpoint for getpeername checks 2026-04-07 02:08:15 -04:00
Benton60 321f15c850 fix 0.0.0.0:non-zero port getpeername calls 2026-04-06 18:14:09 -04:00
Benton60 5fc7dc360a add a check for connectivity in get_peer_name 2026-04-06 13:22:08 -04:00
Benton60 5d1981bf23 fix failing os-test by correcting disconnect behavior 2026-04-06 12:50:21 -04:00
Benton60 b375f2da24 remove dup check to allow unconnect to dup to an unconnected socket 2026-04-04 18:21:10 -04:00
bjorn3 ec4bc65323 Rustfmt 2026-03-27 22:57:39 +01:00
Benton60 4d6c9db9c0 fix a todo 2026-03-27 09:43:50 -04:00
Benton60 87bda3ec32 udpate the fpath return value to reflect the new format 2026-03-24 12:34:05 -04:00
Benton60 0ad36bf5b4 implement recvmsg handler for tcp 2026-03-24 12:34:05 -04:00
Benton60 f8eff8bec3 implement the recvmsg handler for udp 2026-03-24 12:34:05 -04:00
Benton60 c9653b50eb initial setup for recvmsg, all handlers return EOPNOTSUPP for now 2026-03-24 12:34:05 -04:00
Ribbon 90ea974ce0 Add missing Cargo package description and update drivers README 2026-03-16 10:39:15 -06:00
Jeremy Soller 352d90332f Use libredox::protocol in ipcd and netstack 2026-02-28 08:20:24 -07:00
Ibuki Omatsu 2738f69224 feat: Implement std_fs_call handling to initfs, ramfs, acpi and xhci 2026-02-28 08:15:16 -07:00
auronandace 5ffce47607 add clippy precedence lint 2026-02-20 13:43:48 +00:00
Bendeguz Pisch 05d01a9351 Return EADDRNOTAVAIL in UDP scheme if dup called with unspecified address 2026-02-04 10:35:27 +01:00
Jeremy Soller 2d672b7cd9 Add anyhow to workspace 2026-01-29 10:47:45 -07:00
Akshit Gaur c480fa6362 netstack: Add GetSockOpt 2026-01-25 21:12:09 +05:30
Ibuki Omatsu 334928f151 feat: Introduce userspace namespace manager and adapt all schemes. 2026-01-20 20:56:58 -07:00
Jeremy Soller ceebc93762 Set log dependency to workspace in netstack 2026-01-20 10:47:08 -07:00
Jeremy Soller f740b61774 Use workspace dependencies for many common crates 2026-01-20 10:12:08 -07:00
Connor-GH 0580c2c761 Fix 'shutdown' regression
We did not update the relibc version needed for redox-rt or generic-rt.
Additionally, base @6b9593946 was missing an updated callsite for
`can_recv()`.
2026-01-19 14:45:19 -06:00
Akshit Gaur af908029f8 Add UDP Packet Filtering to netstack 2026-01-19 10:06:45 -07:00
Akshit Gaur 557491b5e3 netstack: Add shutdown syscall 2026-01-19 22:06:15 +05:30
Wildan M b9eea683c0 netstack: Temporarily fix EBADF from setsockopt 2026-01-08 05:03:40 +07:00
Wildan M 385f82c777 netstack: Handle SYS_CALL 2026-01-08 04:00:07 +07:00
Wildan M 808fa3b765 Update TCP fpath 2026-01-07 22:53:07 +07:00
Wildan M f5fb58a55b Fix UDP resolving connection 2026-01-07 22:49:28 +07:00
Ibuki Omatsu 3681e1b74a refactor: Replace unlink and rmdir with unlinkat in ramfs. Update redox-scheme and redox-rt for bootstrap. 2025-12-17 18:46:05 -07:00
Ribbon 723364cb45 Improve, update and remove unnecessary READMEs 2025-12-16 21:34:36 -03:00
Ibuki Omatsu 4f3cba2cd0 feat: Update netstack to use redox-scheme. 2025-12-13 06:44:43 -07:00
bjorn3 f06923b201 Standardize main function of all daemons 2025-12-04 11:44:29 +01:00