@@ -95,6 +95,7 @@ use crate::devices::virtio::vsock::metrics::METRICS;
9595use crate :: devices:: virtio:: vsock:: packet:: { VsockPacketHeader , VsockPacketRx , VsockPacketTx } ;
9696use crate :: logger:: IncMetric ;
9797use 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
144147impl < 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