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

Prevent use of socat in firecracker-pilot #41

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firecracker-pilot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ lazy_static = { version = "1.4" }
serde_yaml = { version = "0.9" }
strum = { version = "0.25", features = ["derive"] }
flakes = { version = "3.0.10 ", path = "../common", features = ["json"] }
libc = { version = "0.2" }
4 changes: 4 additions & 0 deletions firecracker-pilot/guestvm-tools/sci/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub const VM_QUIT: &str = "sci_quit";
pub const VHOST_TRANSPORT: &str = "vmw_vsock_virtio_transport";
pub const VM_PORT: u32 = 52;
pub const GUEST_CID: u32 = 3;
pub const RETRIES: u32 =
5;
pub const VM_WAIT_TIMEOUT_MSEC: u64 =
100;

pub fn debug(message: &str) {
if env::var("PILOT_DEBUG").is_ok() {
Expand Down
47 changes: 30 additions & 17 deletions firecracker-pilot/guestvm-tools/sci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ fn main() {
};
stream.shutdown(Shutdown::Both).unwrap();
if call_str.is_empty() {
// Caused by handshake check from the
// pilot, if the vsock connection between
// guest and host can be established
// Caused by handshake checks that connects
// without sending data
debug("No data received until connection end");
continue
}
debug(&format!(
Expand All @@ -330,25 +330,38 @@ fn main() {
}
}
debug(&format!(
"CALL SCI: {}", exec_cmd
"CALL SCI: string:'{}' u32:{}",
exec_cmd, exec_port_num
));

// Establish a VSOCK connection with the farend
let thread_handle = thread::spawn(move || {
match VsockStream::connect_with_cid_port(
2, exec_port_num
) {
Ok(vsock_stream) => {
redirect_command(
&exec_cmd, vsock_stream
);
},
Err(error) => {
debug(&format!(
"VSOCK-CONNECT failed with: {}",
error
));
let mut retry_count = 0;
loop {
if retry_count == defaults::RETRIES {
break
}
match VsockStream::connect_with_cid_port(
2, exec_port_num
) {
Ok(vsock_stream) => {
redirect_command(
&exec_cmd, vsock_stream
);
break
},
Err(error) => {
debug(&format!(
"[{}] VSOCK-CONNECT failed with: {}",
retry_count, error
));
let some_time = time::Duration::from_millis(
defaults::VM_WAIT_TIMEOUT_MSEC
);
thread::sleep(some_time);
}
}
retry_count += 1
}
});
if ! resume {
Expand Down
2 changes: 0 additions & 2 deletions firecracker-pilot/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pub const GC_THRESHOLD: usize = 20;
pub const VM_CID: u32 = 3;
pub const VM_PORT: u32 =
52;
pub const SOCAT: &str =
"/usr/bin/socat";
pub const RETRIES: u32 =
60;
pub const VM_WAIT_TIMEOUT_MSEC: u64 =
Expand Down
Loading
Loading