Skip to content

Commit 110b50d

Browse files
authored
Merge pull request #39 from hyperlight-dev/fix/networking-dns
fix: accept unimplemented socket options, bump 0.3.0
2 parents cb048d7 + fe6972d commit 110b50d

3 files changed

Lines changed: 21 additions & 30 deletions

File tree

host/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

host/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hyperlight-unikraft-host"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "Embedded Hyperlight host for running Unikraft unikernels"
66
license = "MIT OR Apache-2.0"

host/src/lib.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,21 +1176,17 @@ fn register_net_tools(
11761176
let value = args["value"].as_i64().unwrap_or(0) as i32;
11771177
let tbl = t.lock().unwrap();
11781178
let sock = tbl.get_socket(fd)?;
1179-
// SOL_SOCKET=1, SO_REUSEADDR=2
1180-
if level == 1 && optname == 2 {
1181-
sock.set_reuse_address(value != 0)?;
1182-
// SOL_SOCKET=1, SO_KEEPALIVE=9
1183-
} else if level == 1 && optname == 9 {
1184-
sock.set_keepalive(value != 0)?;
1185-
// IPPROTO_TCP=6, TCP_NODELAY=1
1186-
} else if level == 6 && optname == 1 {
1187-
sock.set_nodelay(value != 0)?;
1188-
} else {
1189-
return Err(anyhow!(
1190-
"unsupported socket option: level={}, optname={}",
1191-
level,
1192-
optname
1193-
));
1179+
match (level, optname) {
1180+
// SOL_SOCKET(1), SO_REUSEADDR(2)
1181+
(1, 2) => sock.set_reuse_address(value != 0)?,
1182+
// SOL_SOCKET(1), SO_KEEPALIVE(9)
1183+
(1, 9) => sock.set_keepalive(value != 0)?,
1184+
// IPPROTO_TCP(6), TCP_NODELAY(1)
1185+
(6, 1) => sock.set_nodelay(value != 0)?,
1186+
// Silently accepted — the dispatch round-trip makes
1187+
// guest-side timeouts and error-reporting opts
1188+
// counterproductive; the guest's own retry logic suffices.
1189+
_ => {}
11941190
}
11951191
Ok(json!({}))
11961192
});
@@ -1203,19 +1199,14 @@ fn register_net_tools(
12031199
let optname = args["optname"].as_i64().unwrap_or(0) as i32;
12041200
let tbl = t.lock().unwrap();
12051201
let sock = tbl.get_socket(fd)?;
1206-
let val: i32 = if level == 1 && optname == 3 {
1207-
// SOL_SOCKET + SO_TYPE — return the actual socket type
1208-
tbl.get_sock_type(fd)?
1209-
} else if level == 1 && optname == 2 {
1210-
sock.reuse_address()? as i32
1211-
} else if level == 6 && optname == 1 {
1212-
sock.nodelay()? as i32
1213-
} else {
1214-
return Err(anyhow!(
1215-
"unsupported socket option: level={}, optname={}",
1216-
level,
1217-
optname
1218-
));
1202+
let val: i32 = match (level, optname) {
1203+
// SOL_SOCKET(1), SO_TYPE(3)
1204+
(1, 3) => tbl.get_sock_type(fd)?,
1205+
// SOL_SOCKET(1), SO_REUSEADDR(2)
1206+
(1, 2) => sock.reuse_address()? as i32,
1207+
// IPPROTO_TCP(6), TCP_NODELAY(1)
1208+
(6, 1) => sock.nodelay()? as i32,
1209+
_ => 0,
12191210
};
12201211
Ok(json!({ "value": val }))
12211212
});

0 commit comments

Comments
 (0)