Skip to content

Dns rs#3464

Merged
robgjansen merged 5 commits intoshadow:mainfrom
robgjansen:dns-rs
Dec 23, 2024
Merged

Dns rs#3464
robgjansen merged 5 commits intoshadow:mainfrom
robgjansen:dns-rs

Conversation

@robgjansen
Copy link
Copy Markdown
Member

Convert DNS module to Rust and remove C implementation.

Follow-up to #3455 and #3463 ; this should be rebased and merged AFTER #3455 and #3463 are merged.

@robgjansen robgjansen self-assigned this Dec 12, 2024
@github-actions github-actions bot added Component: Testing Unit and integration tests and frameworks Component: Main Composing the core Shadow executable labels Dec 12, 2024
@robgjansen
Copy link
Copy Markdown
Member Author

I could use some advice on the miri error. It looks like perhaps the miri test environment does not support the memfd syscall, which is used in the Rust DNS module and thus the DNS test cases. I'm wondering if this is a valid case where we should turn off the miri test for the DNS unit tests, and if so how to do that.

@robgjansen
Copy link
Copy Markdown
Member Author

Looks like we could ignore a test in miri with #[cfg_attr(miri, ignore)], but still not sure if it is valid to do so in this case.

@stevenengler
Copy link
Copy Markdown
Contributor

I could use some advice on the miri error. It looks like perhaps the miri test environment does not support the memfd syscall, which is used in the Rust DNS module and thus the DNS test cases. I'm wondering if this is a valid case where we should turn off the miri test for the DNS unit tests, and if so how to do that.

Looks like we could ignore a test in miri with #[cfg_attr(miri, ignore)], but still not sure if it is valid to do so in this case.

I think there are two equally fine options:

  1. Since the new rust code is not using any unsafe (within shadow's code at least), it's fine to skip miri tests with #[cfg_attr(miri, ignore)]. In theory since the test only uses the new code and none of the new code uses unsafe, miri shouldn't be needed.

  2. It's not bad to test with miri anyways. Instead of disabling the test under miri, you could modify DnsBuilder::into_dns to do something like:

#[cfg(not(miri))]
let mut file = File::from(rustix::fs::memfd_create(name, MemfdFlags::CLOEXEC)?);
#[cfg(miri)]
let mut file = tempfile::tempfile().unwrap();

@stevenengler
Copy link
Copy Markdown
Contributor

It seems like miri is getting stuck due to the "/proc/pid/fd/X" :( Here's a playground link that shows miri not working with the "/proc/self/fd/{}" line, but working if you just reuse the original file:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2274b85d39a3b2925618e371c84b1ebe

I'm guessing that since miri does it's own virtualized file descriptors, it just doesn't support these paths.

The only thing I can think to do instead is to try using a NamedTempFile, using NamedTempFile::keep, using the returned path for hosts_path, and then adding a drop handler to Dns which deletes the file with that path if miri is being used.

Copy link
Copy Markdown
Contributor

@stevenengler stevenengler left a comment

Choose a reason for hiding this comment

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

🎉

@robgjansen robgjansen mentioned this pull request Dec 15, 2024
@github-actions github-actions bot added the Component: Documentation In-repository documentation, under docs/ label Dec 20, 2024
@robgjansen robgjansen enabled auto-merge December 23, 2024 01:05
@robgjansen robgjansen merged commit 3fcf943 into shadow:main Dec 23, 2024
@robgjansen robgjansen deleted the dns-rs branch December 23, 2024 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Documentation In-repository documentation, under docs/ Component: Main Composing the core Shadow executable Component: Testing Unit and integration tests and frameworks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants