oxidecomputer / oxidecomputer/netadm-sys
libnet casts interface-name bytes to i8 and types l2_addr as Vec<i8>, breaking builds where c_char is unsigned
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
Description
libnet/src/ioctl.rs assumes c_char is signed in four places. On aarch64,
where it is unsigned, the crate fails to compile:
error[E0308]: mismatched types
--> libnet/src/ioctl.rs:480:38
|
480 | arg.pr_name[..3].copy_from_slice(&b"mtu".map(|u| u as i8));
| found reference `&[i8; 3]`
error[E0308]: mismatched types
--> libnet/src/ioctl.rs:1835:28
|
1835 | ior.lifr_name[i] = b as i8;
error[E0308]: mismatched types
--> libnet/src/ioctl.rs:1855:27
|
1855 | l2_addr: unsafe { ior.lifr_lifru.lifru_nd_req.lnr_hdw_addr.to_vec() },
found struct `Vec<u8>`
error[E0308]: mismatched types
--> libnet/src/ioctl.rs:1868:28
|
1868 | ior.lifr_name[i] = *b as i8;
The three as i8 casts write into lifreq.lifr_name, which is a c_char
array. The fourth is the public Neighbor struct at line 1800:
pub l2_addr: Vec<i8>,
populated from lnr_hdw_addr.to_vec(), where lnr_hdw_addr is a c_char
array — so the field type and the value's type only agree on signed-char
platforms.
Steps to reproduce
- On aarch64 Linux, build anything depending on
libnet— for example
cargo build --bin mgd --bin ddmdin oxidecomputer/maghemite @ ce015cde. error: could not compile 'libnet' (lib) due to 4 previous errors
Expected result
The crate compiles wherever libc::c_char is defined.
Actual result
Four error[E0308] mismatches; libnet does not build, which blocks mgd and
ddmd.
Suggested fix
Use c_char rather than i8 at all four sites:
arg.pr_name[..3].copy_from_slice(&b"mtu".map(|u| u as ::libc::c_char));
pub l2_addr: Vec<::libc::c_char>,
ior.lifr_name[i] = b as ::libc::c_char;
ior.lifr_name[i] = *b as ::libc::c_char;
No behavioural change on x86_64. Note that changing l2_addr is a public API
change in the strict sense, though on every platform where the crate currently
builds the type is unchanged.
I appreciate this crate targets illumos, where the question may be moot. It is
reported because the compile failure is what blocks building maghemite on
aarch64 Linux, and the fix is mechanical.
Environment
libnet git+https://github.com/oxidecomputer/netadm-sys?branch=main
@ 4abde35f281e1934fccc316a212d86d21ddad6a9
via oxidecomputer/maghemite @ ce015cde17a1ebc839ae482026d522cf0e369a3b
platform aarch64-unknown-linux-gnu, Ubuntu 24.04
rust 1.96.1 (pinned by maghemite's rust-toolchain.toml)
Disclosure: this issue was investigated and written up with AI assistance
(Claude). Everything in it was measured rather than inferred — the timings,
error output, version numbers and reproduction steps are all from real runs on
real hardware, and where a fix is suggested it is one I am actually running. I
have read it through before filing. Happy to clarify anything or test a patch.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in libnet/src/ioctl.rs at the reported lines 480, 1835, 1855, and 1868, then inspect the Neighbor definition around line 1800. Reproduce with cargo build --bin mgd --bin ddmd on aarch64 Linux and verify the crate builds without the four type mismatches while preserving the reported interface behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- networking, operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100