Skip to content

Commit 20a56c4

Browse files
Merge #348
348: [plat-182] Inbound connections r=Pagten a=raoulstrackx Enables the enclave to listen for incoming connections This PR works together with [this rust PR](fortanix/rust#3) Co-authored-by: Raoul Strackx <[email protected]>
2 parents 57b724a + 1bbfc2c commit 20a56c4

File tree

12 files changed

+289
-47
lines changed

12 files changed

+289
-47
lines changed

Cargo.lock

Lines changed: 5 additions & 0 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
@@ -3,6 +3,7 @@ members = [
33
"fortanix-vme/fortanix-vme-abi",
44
"fortanix-vme/fortanix-vme-runner",
55
"fortanix-vme/tests/outgoing_connection",
6+
"fortanix-vme/tests/incoming_connection",
67
"intel-sgx/aesm-client",
78
"intel-sgx/dcap-provider",
89
"intel-sgx/dcap-ql-sys",

fortanix-vme/ci-common.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ function cargo_test {
100100
echo "Success"
101101
fi
102102
else
103-
${elf} -- --nocapture
104103
${elf} -- --nocapture > ${out} 2> ${err}
105104

106105
out=$(cat ${out} | grep -v "#" || true)

fortanix-vme/ci-fortanixvme.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ source ./ci-common.sh
66

77
function cleanup {
88
stop_runner
9+
killall test_interaction
910
}
1011

1112
function setup_environment {
@@ -50,7 +51,7 @@ function run_tests {
5051
fi
5152
}
5253

53-
run_tests outgoing_connection
54+
run_tests outgoing_connection incoming_connection
5455

5556
echo "********************************"
5657
echo "** All tests succeeded! **"

fortanix-vme/fortanix-vme-abi/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ compiler_builtins = { version = "0.1.0", optional = true }
1414
serde = { git = "https://github.com/fortanix/serde.git", branch = "master", default-features = false, features = ["derive", "alloc"] }
1515

1616
[features]
17-
default = []
17+
std = ["serde/std"]
18+
default = ["std"]
1819
docs = []
1920
rustc-dep-of-std = ["core", "alloc", "compiler_builtins/rustc-dep-of-std", "serde/rustc-dep-of-std"]

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#![no_std]
22
extern crate alloc;
3+
#[cfg(feature="std")]
4+
extern crate std;
35

46
use alloc::string::String;
57
use serde::{Deserialize, Serialize};
8+
#[cfg(feature="std")]
9+
use std::net::SocketAddr;
610

711
pub const SERVER_PORT: u32 = 10000;
812

@@ -11,11 +15,88 @@ pub enum Request {
1115
Connect {
1216
addr: String,
1317
},
18+
Bind {
19+
/// The address the listen to in the parent VM
20+
addr: String,
21+
/// The port the enclave is listening on to receive connections from the parent VM
22+
enclave_port: u32,
23+
},
24+
Accept {
25+
fd: i32,
26+
}
27+
}
28+
29+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
30+
pub enum Addr {
31+
IPv4 {
32+
ip: [u8; 4],
33+
port: u16,
34+
},
35+
IPv6 {
36+
ip: [u8; 16],
37+
port: u16,
38+
flowinfo: u32,
39+
scope_id: u32,
40+
},
41+
}
42+
43+
#[cfg(feature="std")]
44+
impl From<SocketAddr> for Addr {
45+
fn from(addr: SocketAddr) -> Addr {
46+
match addr {
47+
SocketAddr::V4(addr) => {
48+
Addr::IPv4 {
49+
ip: addr.ip().octets(),
50+
port: addr.port(),
51+
}
52+
},
53+
SocketAddr::V6(addr) => {
54+
Addr::IPv6 {
55+
ip: addr.ip().octets(),
56+
port: addr.port(),
57+
flowinfo: addr.flowinfo(),
58+
scope_id: addr.scope_id(),
59+
}
60+
}
61+
}
62+
}
1463
}
1564

1665
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
1766
pub enum Response {
1867
Connected {
1968
proxy_port: u32,
2069
},
70+
Bound {
71+
/// The TCP port the parent VM is listening on
72+
port: u16,
73+
/// The id used to identify the listener. It can be used for subsequent calls (e.g., to
74+
/// accept new incoming connections)
75+
fd: i32,
76+
},
77+
IncomingConnection {
78+
/// The address of the remote party
79+
peer: Addr,
80+
/// The vsock port number the runner will connect to the enclave in order to forward the
81+
/// incoming connection
82+
proxy_port: u32,
83+
}
84+
}
85+
86+
#[cfg(test)]
87+
mod test {
88+
use std::net::{IpAddr, SocketAddr};
89+
use std::str::FromStr;
90+
use crate::Addr;
91+
92+
#[test]
93+
fn test_addr() {
94+
let sock_addr = SocketAddr::from_str("10.11.12.13:4567").unwrap();
95+
if let Addr::IPv4 { port, ip } = sock_addr.into() {
96+
assert_eq!(IpAddr::from(ip), sock_addr.ip());
97+
assert_eq!(port, sock_addr.port());
98+
} else {
99+
panic!("Not IPv4")
100+
}
101+
}
21102
}

fortanix-vme/fortanix-vme-runner/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ edition = "2018"
55
authors = ["Fortanix, Inc."]
66

77
[dependencies]
8-
fortanix-vme-abi = { path = "../fortanix-vme-abi" }
8+
fnv = "1.0.7"
9+
fortanix-vme-abi = { path = "../fortanix-vme-abi", features = ["std"] }
910
nix = "0.22.1"
1011
serde = { version = "1.0", features = ["derive"] }
1112
serde_cbor = { version = "0.11" }

0 commit comments

Comments
 (0)