-
Notifications
You must be signed in to change notification settings - Fork 195
Tsi: handle protocol field to make DGRAM+ICMP ping work #690
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
Draft
mtjhrc
wants to merge
5
commits into
containers:main
Choose a base branch
from
mtjhrc:tsi-icmp-ping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39d8d9f
devices/vsock: forward protocol field to make DGRAM+ICMP ping work
mtjhrc a5b72fb
tests: add needs_host_network() to skip namespace isolation
mtjhrc f60f152
tests: add tsi-ping test for ICMP through TSI
mtjhrc a40c548
init: enable ping_group_range for ICMP ping sockets
mtjhrc 360ebf2
devices/vsock: strip IP header from macOS ICMP ping replies
mtjhrc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||||||
| use macros::{guest, host}; | ||||||||||
|
|
||||||||||
| pub struct TestTsiPing; | ||||||||||
|
|
||||||||||
| #[host] | ||||||||||
| mod host { | ||||||||||
| use super::*; | ||||||||||
| use crate::common::setup_fs_and_enter; | ||||||||||
| use crate::{krun_call, krun_call_u32}; | ||||||||||
| use crate::{ShouldRun, Test, TestOutcome, TestSetup}; | ||||||||||
| use krun_sys::*; | ||||||||||
|
|
||||||||||
| const CONTAINERFILE: &str = "\ | ||||||||||
| FROM fedora:44 | ||||||||||
| RUN dnf install -y iputils && dnf clean all | ||||||||||
| "; | ||||||||||
|
|
||||||||||
| impl Test for TestTsiPing { | ||||||||||
| fn rootfs_image(&self) -> Option<&'static str> { | ||||||||||
| Some(CONTAINERFILE) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fn should_run(&self) -> ShouldRun { | ||||||||||
| ShouldRun::Yes | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fn timeout_secs(&self) -> u64 { | ||||||||||
| 30 | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fn needs_host_network(&self) -> bool { | ||||||||||
| true | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fn start_vm(self: Box<Self>, test_setup: TestSetup) -> anyhow::Result<()> { | ||||||||||
| unsafe { | ||||||||||
| krun_call!(krun_set_log_level(KRUN_LOG_LEVEL_TRACE))?; | ||||||||||
| let ctx = krun_call_u32!(krun_create_ctx())?; | ||||||||||
| krun_call!(krun_set_vm_config(ctx, 1, 512))?; | ||||||||||
| setup_fs_and_enter(ctx, test_setup)?; | ||||||||||
| } | ||||||||||
| Ok(()) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fn check(self: Box<Self>, stdout: Vec<u8>, _test_setup: TestSetup) -> TestOutcome { | ||||||||||
| let output = String::from_utf8(stdout).unwrap_or_default(); | ||||||||||
| if output == "OK\n" { | ||||||||||
| TestOutcome::Pass | ||||||||||
| } else { | ||||||||||
| TestOutcome::Fail(format!("expected {:?}, got {:?}", "OK\n", output)) | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[guest] | ||||||||||
| mod guest { | ||||||||||
| use super::*; | ||||||||||
| use crate::Test; | ||||||||||
| use std::process::Command; | ||||||||||
|
|
||||||||||
| impl Test for TestTsiPing { | ||||||||||
| fn in_guest(self: Box<Self>) { | ||||||||||
| // Ping an external address so the guest kernel can't satisfy it | ||||||||||
| // locally — forces the TSI vsock proxy path. Without the | ||||||||||
| // protocol fix, TSI creates a UDP socket and ping times out. | ||||||||||
| let output = Command::new("/usr/bin/ping") | ||||||||||
| .args(["-c", "3", "-W", "2", "8.8.8.8"]) | ||||||||||
| .output() | ||||||||||
| .expect("Failed to run ping"); | ||||||||||
|
|
||||||||||
| if output.status.success() { | ||||||||||
| println!("OK"); | ||||||||||
| } else { | ||||||||||
| let stderr = String::from_utf8_lossy(&output.stderr); | ||||||||||
| let stdout = String::from_utf8_lossy(&output.stdout); | ||||||||||
|
Comment on lines
+75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the repository's general rules, test code should prefer using
Suggested change
References
|
||||||||||
| panic!( | ||||||||||
| "ping failed (exit={}):\nstdout: {}\nstderr: {}", | ||||||||||
| output.status, stdout, stderr | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On macOS,
SOCK_DGRAMsockets withIPPROTO_ICMPV6do not prepend the IPv6 header to the received data (unlike IPv4 ICMP sockets which prepend the IPv4 header). Furthermore, the IPv6 header does not have an Internet Header Length (IHL) field atbuf[0] & 0x0F.Including
IPPROTO_ICMPV6in this stripping logic will cause the code to incorrectly strip bytes from the actual ICMPv6 header (for example, corrupting the ICMPv6 Echo Reply type/code), leading to broken IPv6 ping functionality on macOS. This stripping logic should only be applied toIPPROTO_ICMP(IPv4).