Skip to content

Commit

Permalink
wasi implementations: use rc-2024-01-16 for sockets, cli, http (#7781) (
Browse files Browse the repository at this point in the history
#7785)

* wasi: pull in contents of wasi-sockets, wasi-http, and wasi-cli 0.2.0-rc-2024-01-16

* command-extended and test worlds: use rc-2024-01-16

* sockets implementation: v6only is now mandatory

* adapter: cli imports and exports are from rc-2024-01-16 now

* eliminate ipv6-only methods and tests

* a v6_client.blocking_connect(net, v4_listener) will always fail
  with INVAL right away.
* eliminate the paths where a v6 client is allowed to connect to v4.
* eliminate the udp_dual_stack_conversation from udp_sample_application

* component-basic: update wasi:cli version

* wasi-http: sync wit directory

* wasi-http: fix import version

* code review from dave

* test both ipv4 address on v6 socket, and ipv6-mapped-ipv4 on v6 socket, both fail
  • Loading branch information
Pat Hickey authored Jan 17, 2024
1 parent 0b63202 commit 2af1a89
Show file tree
Hide file tree
Showing 42 changed files with 171 additions and 525 deletions.
12 changes: 0 additions & 12 deletions crates/test-programs/src/bin/preview2_tcp_bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,11 @@ fn test_tcp_bind_dual_stack(net: &Network) {
let sock = TcpSocket::new(IpAddressFamily::Ipv6).unwrap();
let addr = IpSocketAddress::new(IpAddress::IPV4_MAPPED_LOOPBACK, 0);

// Even on platforms that don't support dualstack sockets,
// setting ipv6_only to true (disabling dualstack mode) should work.
sock.set_ipv6_only(true).unwrap();

// Binding an IPv4-mapped-IPv6 address on a ipv6-only socket should fail:
assert!(matches!(
sock.blocking_bind(net, addr),
Err(ErrorCode::InvalidArgument)
));

sock.set_ipv6_only(false).unwrap();

sock.blocking_bind(net, addr).unwrap();

let bound_addr = sock.local_address().unwrap();

assert_eq!(bound_addr.family(), IpAddressFamily::Ipv6);
}

fn main() {
Expand Down
19 changes: 6 additions & 13 deletions crates/test-programs/src/bin/preview2_tcp_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,16 @@ fn test_tcp_connect_dual_stack(net: &Network) {

// Tests:

// Even on platforms that don't support dualstack sockets,
// setting ipv6_only to true (disabling dualstack mode) should work.
v6_client.set_ipv6_only(true).unwrap();

// Connecting to an IPv4-mapped-IPv6 address on an ipv6-only socket should fail:
// Connecting to an IPv4 address on an IPv6 socket should fail:
assert!(matches!(
v6_client.blocking_connect(net, v4_listener_addr),
Err(ErrorCode::InvalidArgument)
));
// Connecting to an IPv4-mapped-IPv6 address on an IPv6 socket should fail:
assert!(matches!(
v6_client.blocking_connect(net, v6_listener_addr),
Err(ErrorCode::InvalidArgument)
));

v6_client.set_ipv6_only(false).unwrap();

v6_client.blocking_connect(net, v6_listener_addr).unwrap();

let connected_addr = v6_client.local_address().unwrap();

assert_eq!(connected_addr.family(), IpAddressFamily::Ipv6);
}

fn main() {
Expand Down
25 changes: 0 additions & 25 deletions crates/test-programs/src/bin/preview2_tcp_sockopts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ fn test_tcp_sockopt_defaults(family: IpAddressFamily) {

assert_eq!(sock.address_family(), family);

if family == IpAddressFamily::Ipv6 {
sock.ipv6_only().unwrap(); // Only verify that it has a default value at all, but either value is valid.
}

sock.keep_alive_enabled().unwrap(); // Only verify that it has a default value at all, but either value is valid.
assert!(sock.keep_alive_idle_time().unwrap() > 0);
assert!(sock.keep_alive_interval().unwrap() > 0);
Expand All @@ -26,11 +22,6 @@ fn test_tcp_sockopt_defaults(family: IpAddressFamily) {
fn test_tcp_sockopt_input_ranges(family: IpAddressFamily) {
let sock = TcpSocket::new(family).unwrap();

if family == IpAddressFamily::Ipv6 {
assert!(matches!(sock.set_ipv6_only(true), Ok(_)));
assert!(matches!(sock.set_ipv6_only(false), Ok(_)));
}

assert!(matches!(
sock.set_listen_backlog_size(0),
Err(ErrorCode::InvalidArgument)
Expand Down Expand Up @@ -90,13 +81,6 @@ fn test_tcp_sockopt_input_ranges(family: IpAddressFamily) {
fn test_tcp_sockopt_readback(family: IpAddressFamily) {
let sock = TcpSocket::new(family).unwrap();

if family == IpAddressFamily::Ipv6 {
sock.set_ipv6_only(true).unwrap();
assert_eq!(sock.ipv6_only().unwrap(), true);
sock.set_ipv6_only(false).unwrap();
assert_eq!(sock.ipv6_only().unwrap(), false);
}

sock.set_keep_alive_enabled(true).unwrap();
assert_eq!(sock.keep_alive_enabled().unwrap(), true);
sock.set_keep_alive_enabled(false).unwrap();
Expand Down Expand Up @@ -125,15 +109,10 @@ fn test_tcp_sockopt_inheritance(net: &Network, family: IpAddressFamily) {
let bind_addr = IpSocketAddress::new(IpAddress::new_loopback(family), 0);
let listener = TcpSocket::new(family).unwrap();

let default_ipv6_only = listener.ipv6_only().unwrap_or(false);
let default_keep_alive = listener.keep_alive_enabled().unwrap();

// Configure options on listener:
{
if family == IpAddressFamily::Ipv6 {
listener.set_ipv6_only(!default_ipv6_only).unwrap();
}

listener
.set_keep_alive_enabled(!default_keep_alive)
.unwrap();
Expand All @@ -154,10 +133,6 @@ fn test_tcp_sockopt_inheritance(net: &Network, family: IpAddressFamily) {

// Verify options on accepted socket:
{
if family == IpAddressFamily::Ipv6 {
assert_eq!(accepted_client.ipv6_only().unwrap(), !default_ipv6_only);
}

assert_eq!(
accepted_client.keep_alive_enabled().unwrap(),
!default_keep_alive
Expand Down
56 changes: 0 additions & 56 deletions crates/test-programs/src/bin/preview2_tcp_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ fn test_tcp_unbound_state_invariants(family: IpAddressFamily) {
assert_eq!(sock.is_listening(), false);
assert_eq!(sock.address_family(), family);

if family == IpAddressFamily::Ipv6 {
assert!(matches!(sock.ipv6_only(), Ok(_)));

// Even on platforms that don't support dualstack sockets,
// setting ipv6_only to true (disabling dualstack mode) should work.
assert!(matches!(sock.set_ipv6_only(true), Ok(_)));
} else {
assert!(matches!(sock.ipv6_only(), Err(ErrorCode::NotSupported)));
assert!(matches!(
sock.set_ipv6_only(true),
Err(ErrorCode::NotSupported)
));
}

assert!(matches!(sock.set_listen_backlog_size(32), Ok(_)));
assert!(matches!(sock.keep_alive_enabled(), Ok(_)));
assert!(matches!(sock.set_keep_alive_enabled(false), Ok(_)));
Expand Down Expand Up @@ -100,20 +86,6 @@ fn test_tcp_bound_state_invariants(net: &Network, family: IpAddressFamily) {
assert_eq!(sock.is_listening(), false);
assert_eq!(sock.address_family(), family);

if family == IpAddressFamily::Ipv6 {
assert!(matches!(sock.ipv6_only(), Ok(_)));
assert!(matches!(
sock.set_ipv6_only(true),
Err(ErrorCode::InvalidState)
));
} else {
assert!(matches!(sock.ipv6_only(), Err(ErrorCode::NotSupported)));
assert!(matches!(
sock.set_ipv6_only(true),
Err(ErrorCode::NotSupported)
));
}

assert!(matches!(sock.set_listen_backlog_size(32), Ok(_)));
assert!(matches!(sock.keep_alive_enabled(), Ok(_)));
assert!(matches!(sock.set_keep_alive_enabled(false), Ok(_)));
Expand Down Expand Up @@ -169,20 +141,6 @@ fn test_tcp_listening_state_invariants(net: &Network, family: IpAddressFamily) {
assert_eq!(sock.is_listening(), true);
assert_eq!(sock.address_family(), family);

if family == IpAddressFamily::Ipv6 {
assert!(matches!(sock.ipv6_only(), Ok(_)));
assert!(matches!(
sock.set_ipv6_only(true),
Err(ErrorCode::InvalidState)
));
} else {
assert!(matches!(sock.ipv6_only(), Err(ErrorCode::NotSupported)));
assert!(matches!(
sock.set_ipv6_only(true),
Err(ErrorCode::NotSupported)
));
}

assert!(matches!(
sock.set_listen_backlog_size(32),
Ok(_) | Err(ErrorCode::NotSupported)
Expand Down Expand Up @@ -238,20 +196,6 @@ fn test_tcp_connected_state_invariants(net: &Network, family: IpAddressFamily) {
assert_eq!(sock.is_listening(), false);
assert_eq!(sock.address_family(), family);

if family == IpAddressFamily::Ipv6 {
assert!(matches!(sock.ipv6_only(), Ok(_)));
assert!(matches!(
sock.set_ipv6_only(true),
Err(ErrorCode::InvalidState)
));
} else {
assert!(matches!(sock.ipv6_only(), Err(ErrorCode::NotSupported)));
assert!(matches!(
sock.set_ipv6_only(true),
Err(ErrorCode::NotSupported)
));
}

assert!(matches!(sock.keep_alive_enabled(), Ok(_)));
assert!(matches!(sock.set_keep_alive_enabled(false), Ok(_)));
assert!(matches!(sock.keep_alive_idle_time(), Ok(_)));
Expand Down
12 changes: 0 additions & 12 deletions crates/test-programs/src/bin/preview2_udp_bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,11 @@ fn test_udp_bind_dual_stack(net: &Network) {
let sock = UdpSocket::new(IpAddressFamily::Ipv6).unwrap();
let addr = IpSocketAddress::new(IpAddress::IPV4_MAPPED_LOOPBACK, 0);

// Even on platforms that don't support dualstack sockets,
// setting ipv6_only to true (disabling dualstack mode) should work.
sock.set_ipv6_only(true).unwrap();

// Binding an IPv4-mapped-IPv6 address on a ipv6-only socket should fail:
assert!(matches!(
sock.blocking_bind(net, addr),
Err(ErrorCode::InvalidArgument)
));

sock.set_ipv6_only(false).unwrap();

sock.blocking_bind(net, addr).unwrap();

let bound_addr = sock.local_address().unwrap();

assert_eq!(bound_addr.family(), IpAddressFamily::Ipv6);
}

fn main() {
Expand Down
47 changes: 15 additions & 32 deletions crates/test-programs/src/bin/preview2_udp_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,21 @@ fn test_udp_connect_dual_stack(net: &Network) {
IpSocketAddress::new(IpAddress::IPV4_MAPPED_LOOPBACK, v4_server_addr.port());

// Tests:
{
let v6_client = UdpSocket::new(IpAddressFamily::Ipv6).unwrap();

// Even on platforms that don't support dualstack sockets,
// setting ipv6_only to true (disabling dualstack mode) should work.
v6_client.set_ipv6_only(true).unwrap();

v6_client.blocking_bind_unspecified(&net).unwrap();

// Connecting to an IPv4-mapped-IPv6 address on an ipv6-only socket should fail:
assert!(matches!(
v6_client.stream(Some(v6_server_addr)),
Err(ErrorCode::InvalidArgument)
));
}

{
let v6_client = UdpSocket::new(IpAddressFamily::Ipv6).unwrap();

v6_client.set_ipv6_only(false).unwrap();
v6_client.blocking_bind_unspecified(&net).unwrap();
v6_client.stream(Some(v6_server_addr)).unwrap();

assert_eq!(
v6_client.local_address().unwrap().family(),
IpAddressFamily::Ipv6
);
assert_eq!(
v6_client.remote_address().unwrap().family(),
IpAddressFamily::Ipv6
);
}
let v6_client = UdpSocket::new(IpAddressFamily::Ipv6).unwrap();

v6_client.blocking_bind_unspecified(&net).unwrap();

// Connecting to an IPv4 address on an IPv6 socket should fail:
assert!(matches!(
v6_client.stream(Some(v4_server_addr)),
Err(ErrorCode::InvalidArgument)
));

// Connecting to an IPv4-mapped-IPv6 address on an IPv6 socket should fail:
assert!(matches!(
v6_client.stream(Some(v6_server_addr)),
Err(ErrorCode::InvalidArgument)
));
}

fn main() {
Expand Down
48 changes: 0 additions & 48 deletions crates/test-programs/src/bin/preview2_udp_sample_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,52 +72,6 @@ fn test_udp_sample_application(family: IpAddressFamily, bind_address: IpSocketAd
}
}

fn test_udp_dual_stack_conversation() {
let net = Network::default();

let v4_server = UdpSocket::new(IpAddressFamily::Ipv4).unwrap();
v4_server
.blocking_bind(&net, IpSocketAddress::new(IpAddress::IPV4_LOOPBACK, 0))
.unwrap();
let (server_incoming, server_outgoing) = v4_server.stream(None).unwrap();

let v4_server_addr = v4_server.local_address().unwrap();
let v6_server_addr =
IpSocketAddress::new(IpAddress::IPV4_MAPPED_LOOPBACK, v4_server_addr.port());

let v6_client = UdpSocket::new(IpAddressFamily::Ipv6).unwrap();

v6_client.set_ipv6_only(false).unwrap();
v6_client.blocking_bind_unspecified(&net).unwrap();
let (client_incoming, client_outgoing) = v6_client.stream(None).unwrap();

// Send from v6 client to v4 server:
client_outgoing
.blocking_send(&[OutgoingDatagram {
data: "Hi!".into(),
remote_address: Some(v6_server_addr),
}])
.unwrap();

// Receive from v6 client on v4 server:
let results = server_incoming.blocking_receive(1..1).unwrap();
let msg = results.first().unwrap();
assert_eq!(msg.remote_address.family(), IpAddressFamily::Ipv4);

// Send from v4 server to v6 client:
server_outgoing
.blocking_send(&[OutgoingDatagram {
data: msg.data.clone(),
remote_address: Some(msg.remote_address),
}])
.unwrap();

// Receive from v4 server on v6 client:
let results = client_incoming.blocking_receive(1..1).unwrap();
let msg = results.first().unwrap();
assert_eq!(msg.remote_address.family(), IpAddressFamily::Ipv6);
}

fn main() {
test_udp_sample_application(
IpAddressFamily::Ipv4,
Expand All @@ -135,6 +89,4 @@ fn main() {
scope_id: 0,
}),
);

test_udp_dual_stack_conversation();
}
16 changes: 0 additions & 16 deletions crates/test-programs/src/bin/preview2_udp_sockopts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ fn test_udp_sockopt_defaults(family: IpAddressFamily) {

assert_eq!(sock.address_family(), family);

if family == IpAddressFamily::Ipv6 {
sock.ipv6_only().unwrap(); // Only verify that it has a default value at all, but either value is valid.
}

assert!(sock.unicast_hop_limit().unwrap() > 0);
assert!(sock.receive_buffer_size().unwrap() > 0);
assert!(sock.send_buffer_size().unwrap() > 0);
Expand All @@ -18,11 +14,6 @@ fn test_udp_sockopt_defaults(family: IpAddressFamily) {
fn test_udp_sockopt_input_ranges(family: IpAddressFamily) {
let sock = UdpSocket::new(family).unwrap();

if family == IpAddressFamily::Ipv6 {
assert!(matches!(sock.set_ipv6_only(true), Ok(_)));
assert!(matches!(sock.set_ipv6_only(false), Ok(_)));
}

assert!(matches!(
sock.set_unicast_hop_limit(0),
Err(ErrorCode::InvalidArgument)
Expand All @@ -47,13 +38,6 @@ fn test_udp_sockopt_input_ranges(family: IpAddressFamily) {
fn test_udp_sockopt_readback(family: IpAddressFamily) {
let sock = UdpSocket::new(family).unwrap();

if family == IpAddressFamily::Ipv6 {
sock.set_ipv6_only(true).unwrap();
assert_eq!(sock.ipv6_only().unwrap(), true);
sock.set_ipv6_only(false).unwrap();
assert_eq!(sock.ipv6_only().unwrap(), false);
}

sock.set_unicast_hop_limit(42).unwrap();
assert_eq!(sock.unicast_hop_limit().unwrap(), 42);

Expand Down
Loading

0 comments on commit 2af1a89

Please sign in to comment.