Skip to content

Commit 35a8af4

Browse files
committed
feat: Add seqpacket support
Modify the multiplexer and vsock backend to be able to handle vsock seqpacket connections based on the passed config parameter Co-authored-by: aerosouund <aerosound161@gmail.com> Signed-off-by: aerosouund <aerosound161@gmail.com>
1 parent f0691f8 commit 35a8af4

File tree

22 files changed

+664
-119
lines changed

22 files changed

+664
-119
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to
1212

1313
### Changed
1414

15+
- [#5595](https://github.com/firecracker-microvm/firecracker/pull/5595): Added `vsock_type`
16+
field to the vsock device API to denote the type of the underlying socket. Can be `stream`
17+
or `seqpacket`
18+
1519
### Deprecated
1620

1721
### Removed

Cargo.lock

Lines changed: 119 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ or_fun_call = "warn"
3333

3434
[profile.dev]
3535
panic = "abort"
36+
incremental = true
3637

3738
[profile.release]
3839
panic = "abort"

src/vmm/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ serde = { version = "1.0.228", features = ["derive", "rc"] }
4646
serde_json = "1.0.145"
4747
slab = "0.4.11"
4848
thiserror = "2.0.17"
49+
timerfd = "1.5.0"
50+
uds = "0.4.2"
4951
userfaultfd = "0.9.0"
5052
utils = { path = "../utils" }
5153
uuid = "1.19.0"

src/vmm/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ pub(crate) mod tests {
941941
vsock_config: VsockDeviceConfig,
942942
) {
943943
let vsock_dev_id = VSOCK_DEV_ID.to_owned();
944-
let vsock = VsockBuilder::create_unixsock_vsock(vsock_config).unwrap();
944+
let vsock = VsockBuilder::create_unixsock_vsock(&vsock_config).unwrap();
945945
let vsock = Arc::new(Mutex::new(vsock));
946946

947947
attach_unixsock_vsock_device(

src/vmm/src/device_manager/pci_mngr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ mod tests {
665665
use crate::vmm_config::memory_hotplug::MemoryHotplugConfig;
666666
use crate::vmm_config::net::NetworkInterfaceConfig;
667667
use crate::vmm_config::pmem::PmemConfig;
668-
use crate::vmm_config::vsock::VsockDeviceConfig;
668+
use crate::vmm_config::vsock::{VsockDeviceConfig, VsockType};
669669

670670
#[test]
671671
fn test_device_manager_persistence() {
@@ -723,6 +723,7 @@ mod tests {
723723
vsock_id: Some(vsock_dev_id.to_string()),
724724
guest_cid: 3,
725725
uds_path: tmp_sock_file.as_path().to_str().unwrap().to_string(),
726+
vsock_type: VsockType::Stream,
726727
};
727728
insert_vsock_device(&mut vmm, &mut cmdline, &mut event_manager, vsock_config);
728729
// Add an entropy device.

src/vmm/src/device_manager/persist.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ mod tests {
636636
use crate::vmm_config::memory_hotplug::MemoryHotplugConfig;
637637
use crate::vmm_config::net::NetworkInterfaceConfig;
638638
use crate::vmm_config::pmem::PmemConfig;
639-
use crate::vmm_config::vsock::VsockDeviceConfig;
639+
use crate::vmm_config::vsock::{VsockDeviceConfig, VsockType};
640640

641641
impl<T> PartialEq for VirtioDeviceState<T> {
642642
fn eq(&self, other: &VirtioDeviceState<T>) -> bool {
@@ -734,6 +734,7 @@ mod tests {
734734
vsock_id: Some(vsock_dev_id.to_string()),
735735
guest_cid: 3,
736736
uds_path: tmp_sock_file.as_path().to_str().unwrap().to_string(),
737+
vsock_type: VsockType::Stream,
737738
};
738739
insert_vsock_device(&mut vmm, &mut cmdline, &mut event_manager, vsock_config);
739740
// Add an entropy device.

src/vmm/src/devices/virtio/persist.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ mod tests {
269269
use crate::devices::virtio::transport::mmio::tests::DummyDevice;
270270
use crate::devices::virtio::vsock::{Vsock, VsockUnixBackend};
271271
use crate::snapshot::Snapshot;
272+
use crate::vmm_config::vsock::VsockType;
272273

273274
const DEFAULT_QUEUE_MAX_SIZE: u16 = 256;
274275
impl Default for QueueState {
@@ -486,7 +487,7 @@ mod tests {
486487
// Remove the file so the path can be used by the socket.
487488
temp_uds_path.remove().unwrap();
488489
let uds_path = String::from(temp_uds_path.as_path().to_str().unwrap());
489-
let backend = VsockUnixBackend::new(guest_cid, uds_path).unwrap();
490+
let backend = VsockUnixBackend::new(guest_cid, uds_path, VsockType::Stream).unwrap();
490491
let vsock = Vsock::new(guest_cid, backend).unwrap();
491492
let vsock = Arc::new(Mutex::new(vsock));
492493
let mmio_transport =

src/vmm/src/devices/virtio/vsock/csm/connection.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ use crate::devices::virtio::vsock::metrics::METRICS;
9595
use crate::devices::virtio::vsock::packet::{VsockPacketHeader, VsockPacketRx, VsockPacketTx};
9696
use crate::logger::IncMetric;
9797
use crate::utils::wrap_usize_to_u32;
98+
use crate::vmm_config::vsock::VsockType;
9899

99100
/// Trait that vsock connection backends need to implement.
100101
///
@@ -139,6 +140,8 @@ pub struct VsockConnection<S: VsockConnectionBackend> {
139140
/// Instant when this connection should be scheduled for immediate termination, due to some
140141
/// timeout condition having been fulfilled.
141142
expiry: Option<Instant>,
143+
/// Vsock type (stream or seqpacket)
144+
vsock_type: VsockType,
142145
}
143146

144147
impl<S> VsockChannel for VsockConnection<S>
@@ -509,6 +512,7 @@ where
509512
local_port: u32,
510513
peer_port: u32,
511514
peer_buf_alloc: u32,
515+
vsock_type: VsockType,
512516
) -> Self {
513517
Self {
514518
local_cid,
@@ -525,6 +529,7 @@ where
525529
last_fwd_cnt_to_peer: Wrapping(0),
526530
pending_rx: PendingRxSet::from(PendingRx::Response),
527531
expiry: None,
532+
vsock_type,
528533
}
529534
}
530535

@@ -535,6 +540,7 @@ where
535540
peer_cid: u64,
536541
local_port: u32,
537542
peer_port: u32,
543+
vsock_type: VsockType,
538544
) -> Self {
539545
Self {
540546
local_cid,
@@ -551,6 +557,7 @@ where
551557
last_fwd_cnt_to_peer: Wrapping(0),
552558
pending_rx: PendingRxSet::from(PendingRx::Request),
553559
expiry: None,
560+
vsock_type,
554561
}
555562
}
556563

@@ -671,9 +678,12 @@ where
671678
.set_dst_cid(self.peer_cid)
672679
.set_src_port(self.local_port)
673680
.set_dst_port(self.peer_port)
674-
.set_type(uapi::VSOCK_TYPE_STREAM)
675681
.set_buf_alloc(defs::CONN_TX_BUF_SIZE)
676682
.set_fwd_cnt(self.fwd_cnt.0);
683+
match self.vsock_type {
684+
VsockType::Seqpacket => hdr.set_type(uapi::VSOCK_TYPE_SEQPACKET),
685+
VsockType::Stream => hdr.set_type(uapi::VSOCK_TYPE_STREAM),
686+
};
677687
}
678688
}
679689

@@ -882,9 +892,15 @@ mod tests {
882892
LOCAL_PORT,
883893
PEER_PORT,
884894
PEER_BUF_ALLOC,
895+
VsockType::Stream,
885896
),
886897
ConnState::LocalInit => VsockConnection::<TestStream>::new_local_init(
887-
stream, LOCAL_CID, PEER_CID, LOCAL_PORT, PEER_PORT,
898+
stream,
899+
LOCAL_CID,
900+
PEER_CID,
901+
LOCAL_PORT,
902+
PEER_PORT,
903+
VsockType::Stream,
888904
),
889905
ConnState::Established => {
890906
let mut conn = VsockConnection::<TestStream>::new_peer_init(
@@ -894,6 +910,7 @@ mod tests {
894910
LOCAL_PORT,
895911
PEER_PORT,
896912
PEER_BUF_ALLOC,
913+
VsockType::Stream,
897914
);
898915
assert!(conn.has_pending_rx());
899916
conn.recv_pkt(&mut rx_pkt).unwrap();

0 commit comments

Comments
 (0)