Skip to content

Add DragonFly BSD platform backend#134

Merged
valpackett merged 4 commits into
valpackett:trunkfrom
lileding:dragonfly-bsd-backend
Jun 2, 2026
Merged

Add DragonFly BSD platform backend#134
valpackett merged 4 commits into
valpackett:trunkfrom
lileding:dragonfly-bsd-backend

Conversation

@lileding
Copy link
Copy Markdown
Contributor

@lileding lileding commented Jun 1, 2026

Summary

Add a native DragonFly BSD backend and list DragonFly BSD as a supported platform.

The backend implements the Platform surface with DragonFly-specific data sources:

  • CPU load from kern.cp_times
  • load average from getloadavg(3)
  • memory from vm.stats.vm.* page counters
  • swap from vm.swap_size, vm.swap_anon_use, and vm.swap_cache_use
  • boot time from kern.boottime
  • mounts from getfsstat(2)
  • block device statistics through libdevstat
  • network addresses through the shared Unix helper, with DragonFly link-local IPv6 normalization
  • network interface statistics through SIOCGIFDATA
  • CPU temperature through hw.sensors.*.temp*
  • battery/AC state through ACPI sysctls when present
  • socket statistics through TCP/UDP PCB list sysctls

A few Linux-specific fields that DragonFly does not expose directly are reported as zero, such as block merge counts and orphaned TCP sockets.

Testing

Tested on DragonFly BSD:

cargo check --example info
cargo test
cargo test --features serde
cargo clippy --all-targets --features serde
cargo run --example info

cargo clippy still reports the existing reader_utils::read_file dead-code warning and the existing needless lifetime warning in src/data.rs; this PR does not introduce new clippy errors.

lileding added 4 commits June 1, 2026 15:52
Add a native DragonFly BSD implementation for systemstat. The backend covers CPU load sampling, load average, memory, swap, boot time, mounts, network enumeration, and AC-power detection where available.

DragonFly has different VM, swap, and statfs details from FreeBSD, so keep the implementation separate while reusing the shared BSD and Unix helpers where they fit. Unsupported hardware- or route-specific statistics still return Unsupported explicitly.

Wire DragonFly into the platform module, lazy_static setup, and platform memory/swap data exports.
Add DragonFly implementations for interface statistics, CPU temperature, and ACPI battery life.

Read interface counters with SIOCGIFDATA, temperature from hw.sensors sensor sysctls, and battery state from hw.acpi.battery sysctls when present. Keep unsupported results explicit for block device and socket statistics.
Implement DragonFly block device statistics through libdevstat and socket statistics through TCP/UDP PCB list sysctls.

Normalize DragonFly link-local IPv6 addresses from getifaddrs by clearing embedded scope bits, and switch mounts to getfsstat so concurrent tests do not depend on getmntinfo static storage.
Comment thread src/platform/dragonfly.rs
/// (integers, `timeval`, ...). Reading a 4-byte kernel field into a zeroed
/// 8-byte `c_long` is safe on little-endian amd64: sysctl writes only the
/// kernel's actual length and the high bytes stay zero. DragonFly is amd64
/// only, so this holds.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, maybe this should be cfg()'d to little endian just in case someone decides to port dfly to aarch64be or something 🤣

Comment thread src/platform/dragonfly.rs

fn normalize_dragonfly_ipv6(addr: Ipv6Addr) -> Ipv6Addr {
let mut segments = addr.segments();
if segments[0] & 0xffc0 == 0xfe80 {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh.. interesting

@valpackett
Copy link
Copy Markdown
Owner

Very cool, thanks!!

@valpackett valpackett merged commit 2dc2cfd into valpackett:trunk Jun 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants