Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: impl AsFd for {RawSocket, TunTapInterface} #916

Open
kennytm opened this issue Apr 5, 2024 · 0 comments
Open

feature request: impl AsFd for {RawSocket, TunTapInterface} #916

kennytm opened this issue Apr 5, 2024 · 0 comments

Comments

@kennytm
Copy link

kennytm commented Apr 5, 2024

I/O Safety (rust-lang/rfcs#3128, rust-lang/rust#87074) was introduced in Rust 1.63 which associated lifetime to file descriptors.

Some packages, in particular smol, only accepted the I/O-safety-based types instead of RawFd-based types.

While it is possible to convert a RawFd to the I/O-safe counterparts via the unsafe functions BorrowedFd::borrow_raw and OwnedFd::from_raw_fd, it is better if the unsafe operation can be hidden from the library user.

As of 0.11, only the following public types implemented AsRawFd:

Note that if we do impl AsFd for TunTapInterface, TunTapInterface::from_fd will need to be turned into an unsafe fn or accept an OwnedFd to avoid constructing a BorrowedFd from -1.

// this breaks the invariant that BorrowedFd != -1 without invoking unsafe
let device = TunTapInterface::from_fd(-1, Medium::Ip, 1400)?;
let fd = device.as_fd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant