Skip to content

Commit 13b2e7c

Browse files
Merge #356
356: Storing peer address r=Pagten a=raoulstrackx `TcpStream`s and `TcpListener`s need to be able to return the address of the remote party. This PR: * Makes the runner return the peer address when a new connection is established * Returns the full address (not just the port) when a `Bound` response is send to the enclave * Adds a test for this functionality * Adds a statement ensuring warnings are treated as errors Co-authored-by: Raoul Strackx <[email protected]>
2 parents d4eb41e + 9197654 commit 13b2e7c

File tree

3 files changed

+12
-6
lines changed
  • fortanix-vme

3 files changed

+12
-6
lines changed

fortanix-vme/fortanix-vme-abi/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#![no_std]
23
extern crate alloc;
34
#[cfg(feature="std")]
@@ -67,10 +68,12 @@ pub enum Response {
6768
Connected {
6869
/// The vsock port the proxy is listening on for an incoming connection
6970
proxy_port: u32,
71+
/// The address of the remote party
72+
peer: Addr,
7073
},
7174
Bound {
72-
/// The TCP port the parent VM is listening on
73-
port: u16,
75+
/// The local TCP address the parent VM is listening on
76+
local: Addr,
7477
/// The id used to identify the listener. It can be used for subsequent calls (e.g., to
7578
/// accept new incoming connections)
7679
fd: i32,

fortanix-vme/fortanix-vme-runner/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
use fnv::FnvHashMap;
23
use nix::sys::select::{select, FdSet};
34
use serde_cbor;
@@ -187,6 +188,7 @@ impl Server {
187188
// Notify the enclave on which port her proxy is listening on
188189
let response = Response::Connected {
189190
proxy_port: proxy_server_port,
191+
peer: remote_socket.peer_addr()?.into(),
190192
};
191193
Self::log_communication(
192194
"runner",
@@ -243,9 +245,9 @@ impl Server {
243245
fn handle_request_bind(&self, addr: &String, enclave_port: u32, enclave: &mut VsockStream) -> Result<(), IoError> {
244246
let cid: u32 = enclave.peer().unwrap().parse().unwrap_or(vsock::VMADDR_CID_HYPERVISOR);
245247
let listener = TcpListener::bind(addr)?;
246-
let port = listener.local_addr().map(|addr| addr.port())?;
248+
let local = listener.local_addr()?.into();
247249
let fd = self.add_listener_info(ListenerInfo{ listener, enclave_cid: cid, enclave_port });
248-
let response = Response::Bound{ port, fd };
250+
let response = Response::Bound{ local, fd };
249251
Self::log_communication(
250252
"runner",
251253
enclave.local_port().unwrap_or_default(),

fortanix-vme/tests/incoming_connection/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
use std::net::{Shutdown, TcpListener};
1+
use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpListener};
22
use std::io::{Read, Write};
33

44
fn main() {
55
println!("Bind to socket to 3400");
66
let listener = TcpListener::bind("127.0.0.1:3400").expect("Bind failed");
7-
// println!("# Listening on: {}", listener.local_addr().unwrap().port());
7+
assert_eq!(listener.local_addr().unwrap(), SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 3400));
88

99
println!("Listening for incoming connections...");
1010
for id in 1..3 {
1111
println!("Waiting for connection {}", id);
1212
match listener.accept() {
1313
Ok((mut stream, addr)) => {
1414
println!("# addr = {:?}", addr);
15+
assert_eq!(stream.peer_addr().unwrap().ip(), Ipv4Addr::new(127, 0, 0, 1));
1516
println!("Connection {}: Connected", id);
1617
let mut buff_in = [0u8; 4192];
1718
let n = stream.read(&mut buff_in).unwrap();

0 commit comments

Comments
 (0)