Explorar el Código

Pass ConnectionInfo to connect.

This lets us send the correct buf_alloc with the connection request.
Andrew Walbran hace 1 año
padre
commit
5023129f32

+ 2 - 2
src/device/socket/multiconnectionmanager.rs

@@ -55,7 +55,7 @@ impl<H: Hal, T: Transport> VsockConnectionManager<H, T> {
         let mut new_connection_info = ConnectionInfo::new(destination, src_port);
         new_connection_info.buf_alloc = PER_CONNECTION_BUFFER_CAPACITY.try_into().unwrap();
 
-        self.driver.connect(destination, src_port)?;
+        self.driver.connect(&new_connection_info)?;
         debug!("Connection requested: {:?}", new_connection_info);
         self.connections.push(Connection {
             info: new_connection_info,
@@ -334,7 +334,7 @@ mod tests {
                     len: 0.into(),
                     socket_type: SocketType::Stream.into(),
                     flags: 0.into(),
-                    buf_alloc: 0.into(),
+                    buf_alloc: 1024.into(),
                     fwd_cnt: 0.into(),
                 }
             );

+ 1 - 1
src/device/socket/singleconnectionmanager.rs

@@ -40,7 +40,7 @@ impl<H: Hal, T: Transport> SingleConnectionManager<H, T> {
 
         let new_connection_info = ConnectionInfo::new(destination, src_port);
 
-        self.driver.connect(destination, src_port)?;
+        self.driver.connect(&new_connection_info)?;
         debug!("Connection requested: {:?}", new_connection_info);
         self.connection_info = Some(new_connection_info);
         Ok(())

+ 4 - 8
src/device/socket/vsock.rs

@@ -312,17 +312,13 @@ impl<H: Hal, T: Transport> VirtIOSocket<H, T> {
     /// This returns as soon as the request is sent; you should wait until `poll_recv` returns a
     /// `VsockEventType::Connected` event indicating that the peer has accepted the connection
     /// before sending data.
-    pub fn connect(&mut self, destination: VsockAddr, src_port: u32) -> Result {
+    pub fn connect(&mut self, connection_info: &ConnectionInfo) -> Result {
         let header = VirtioVsockHdr {
             op: VirtioVsockOp::Request.into(),
-            src_cid: self.guest_cid.into(),
-            dst_cid: destination.cid.into(),
-            src_port: src_port.into(),
-            dst_port: destination.port.into(),
-            ..Default::default()
+            ..connection_info.new_header(self.guest_cid)
         };
-        // Sends a header only packet to the tx queue to connect the device to the listening
-        // socket at the given destination.
+        // Sends a header only packet to the TX queue to connect the device to the listening socket
+        // at the given destination.
         self.send_packet_to_tx_queue(&header, &[])?;
 
         Ok(())