From b81ade525bc8a81e4cf35b043b4934ca6068a25c Mon Sep 17 00:00:00 2001 From: Andreas Molzer <andreas.molzer@nebumind.com> Date: Tue, 20 Feb 2024 20:18:19 +0100 Subject: [PATCH 1/4] Hide pretty-printer behind std feature --- ethox/src/layer/eth/mod.rs | 2 ++ ethox/src/nic/mod.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ethox/src/layer/eth/mod.rs b/ethox/src/layer/eth/mod.rs index 864ade8..fe58fd5 100644 --- a/ethox/src/layer/eth/mod.rs +++ b/ethox/src/layer/eth/mod.rs @@ -61,6 +61,7 @@ impl<P: Payload> Recv<P> for Formatter<ethernet::frame> { } } +#[cfg(feature = "std")] impl<P: Payload, I> Recv<P> for pretty_print::FormatWith<I, ethernet::frame> where I: Recv<P> { @@ -71,6 +72,7 @@ impl<P: Payload, I> Recv<P> for pretty_print::FormatWith<I, ethernet::frame> } } +#[cfg(feature = "std")] impl<P: Payload, I> Send<P> for pretty_print::FormatWith<I, ethernet::frame> where I: Send<P> { diff --git a/ethox/src/nic/mod.rs b/ethox/src/nic/mod.rs index f93a07b..ed24e58 100644 --- a/ethox/src/nic/mod.rs +++ b/ethox/src/nic/mod.rs @@ -212,6 +212,7 @@ impl<H: Handle + ?Sized, P: Payload + ?Sized> Recv<H, P> for Formatter<ethernet: } } +#[cfg(feature = "std")] impl<I, H: Handle + ?Sized, P: Payload + ?Sized> Recv<H, P> for FormatWith<I, ethernet::frame> where I: Recv<H, P> { @@ -223,6 +224,7 @@ impl<I, H: Handle + ?Sized, P: Payload + ?Sized> Recv<H, P> for FormatWith<I, et } } +#[cfg(feature = "std")] impl<I, H: Handle + ?Sized, P: Payload + ?Sized> Send<H, P> for FormatWith<I, ethernet::frame> where I: Send<H, P> { From 2cd7c77d7371ebcd10855eabbf71dc9d6528f355 Mon Sep 17 00:00:00 2001 From: Andreas Molzer <andreas.molzer@nebumind.com> Date: Tue, 20 Feb 2024 20:27:04 +0100 Subject: [PATCH 2/4] Fix tests for neighbor endpoint state --- ethox-iperf/bin/main.rs | 4 +++- ethox/src/layer/arp/tests.rs | 8 ++++++-- ethox/src/layer/icmp/tests.rs | 4 ++-- ethox/src/layer/ip/tests.rs | 4 ++-- ethox/src/layer/udp/tests.rs | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ethox-iperf/bin/main.rs b/ethox-iperf/bin/main.rs index c3a3d46..771d4a5 100644 --- a/ethox-iperf/bin/main.rs +++ b/ethox-iperf/bin/main.rs @@ -26,10 +26,12 @@ fn main() { let mut neighbors = [arp::Neighbor::default(); 1]; let mut routes = [ip::Route::new_ipv4_gateway(config.gateway.address()); 1]; + let neighbors = arp::NeighborCache::new(&mut neighbors[..]); + let mut ip = ip::Endpoint::new( Slice::One(config.host.into()), ip::Routes::import(List::new_full(routes.as_mut().into())), - arp::NeighborCache::new(&mut neighbors[..])); + arp::Endpoint::new(neighbors)); println!("[+] Configured layers, communicating"); diff --git a/ethox/src/layer/arp/tests.rs b/ethox/src/layer/arp/tests.rs index 80496df..e1c520b 100644 --- a/ethox/src/layer/arp/tests.rs +++ b/ethox/src/layer/arp/tests.rs @@ -17,10 +17,14 @@ fn simple_arp() { // No prior ARP cache entries needed. let mut neighbors = [arp_layer::Neighbor::default(); 1]; let mut routes = [ip_layer::Route::unspecified(); 2]; - let mut ip = ip_layer::Endpoint::new(ip::Cidr::new(IP_ADDR_HOST.into(), 24), + let arp = arp_layer::Endpoint::new( + arp_layer::NeighborCache::new(Slice::empty())); + let mut ip = ip_layer::Endpoint::new( + ip::Cidr::new(IP_ADDR_HOST.into(), 24), // No routes necessary for local link. ip_layer::Routes::new(&mut routes[..]), - arp_layer::NeighborCache::new(Slice::empty())); + arp, + ); let mut arp = arp_layer::Endpoint::new(arp_layer::NeighborCache::new(&mut neighbors[..])); diff --git a/ethox/src/layer/icmp/tests.rs b/ethox/src/layer/icmp/tests.rs index dfc4f43..618b9e0 100644 --- a/ethox/src/layer/icmp/tests.rs +++ b/ethox/src/layer/icmp/tests.rs @@ -31,7 +31,7 @@ fn answer_ping() { let neighbors = { let mut eth_cache = arp::NeighborCache::new(&mut neighbors[..]); eth_cache.fill(IP_ADDR_OTHER.into(), MAC_ADDR_OTHER, None).unwrap(); - eth_cache + arp::Endpoint::new(eth_cache) }; let mut ip = [ip::Route::unspecified(); 2]; let mut ip = ip::Endpoint::new(Cidr::new(IP_ADDR_HOST.into(), 24), @@ -72,7 +72,7 @@ fn queue_ping(nic: &mut Loopback<Vec<u8>>) { let neighbors = { let mut eth_cache = arp::NeighborCache::new(&mut neighbors[..]); eth_cache.fill(IP_ADDR_HOST.into(), MAC_ADDR_HOST, None).unwrap(); - eth_cache + arp::Endpoint::new(eth_cache) }; let mut ip = ip::Endpoint::new( Cidr::new(IP_ADDR_OTHER.into(), 24), diff --git a/ethox/src/layer/ip/tests.rs b/ethox/src/layer/ip/tests.rs index de66688..a7fa4be 100644 --- a/ethox/src/layer/ip/tests.rs +++ b/ethox/src/layer/ip/tests.rs @@ -34,7 +34,7 @@ fn simple_ipv4() { let neighbors = { let mut eth_cache = arp::NeighborCache::new(&mut neighbors[..]); eth_cache.fill(IP_ADDR_DST.into(), MAC_ADDR_DST, None).unwrap(); - eth_cache + arp::Endpoint::new(eth_cache) }; let mut ip = [ip::Route::unspecified(); 2]; let mut ip = ip::Endpoint::new(Cidr::new(IP_ADDR_SRC.into(), 24), @@ -82,7 +82,7 @@ fn simple_ipv6() { let neighbors = { let mut eth_cache = arp::NeighborCache::new(&mut neighbors[..]); eth_cache.fill(IP_ADDR_DST.into(), MAC_ADDR_DST, None).unwrap(); - eth_cache + arp::Endpoint::new(eth_cache) }; let mut ip = [ip::Route::unspecified(); 2]; let mut ip = ip::Endpoint::new(Cidr::new(IP_ADDR_SRC.into(), 24), diff --git a/ethox/src/layer/udp/tests.rs b/ethox/src/layer/udp/tests.rs index ea6a4ec..6da404d 100644 --- a/ethox/src/layer/udp/tests.rs +++ b/ethox/src/layer/udp/tests.rs @@ -50,7 +50,7 @@ fn simple() { let neighbors = { let mut eth_cache = arp::NeighborCache::new(&mut neighbors[..]); eth_cache.fill(IP_ADDR_DST.into(), MAC_ADDR_DST, None).unwrap(); - eth_cache + arp::Endpoint::new(eth_cache) }; let mut ip = [ip::Route::unspecified(); 2]; let mut ip = ip::Endpoint::new(Cidr::new(IP_ADDR_SRC.into(), 24), From 3280b0e97c9266cace6f8a7ca6f228f1b771b6b0 Mon Sep 17 00:00:00 2001 From: Andreas Molzer <andreas.molzer@nebumind.com> Date: Tue, 20 Feb 2024 20:57:39 +0100 Subject: [PATCH 3/4] Patch expected panic message (Rust std update) --- ethox/src/wire/ipv6.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethox/src/wire/ipv6.rs b/ethox/src/wire/ipv6.rs index 8df615a..c91f806 100644 --- a/ethox/src/wire/ipv6.rs +++ b/ethox/src/wire/ipv6.rs @@ -1154,7 +1154,7 @@ mod test { } #[test] - #[should_panic(expected = "destination and source slices have different lengths")] + #[should_panic(expected = "does not match destination slice length")] fn test_from_bytes_too_long() { let _ = Address::from_bytes(&[0u8; 15]); } From 8d765756d0c31fd88a52a005f6944fbc69536c91 Mon Sep 17 00:00:00 2001 From: Andreas Molzer <andreas.molzer@nebumind.com> Date: Wed, 21 Feb 2024 00:09:55 +0100 Subject: [PATCH 4/4] Fixup further examples using ARP --- ethox/examples/arp_tap.rs | 2 +- ethox/examples/curl.rs | 3 ++- ethox/examples/ping_tap.rs | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ethox/examples/arp_tap.rs b/ethox/examples/arp_tap.rs index 00792d1..6689a7a 100644 --- a/ethox/examples/arp_tap.rs +++ b/ethox/examples/arp_tap.rs @@ -51,7 +51,7 @@ fn main() { let neighbors = { let mut eth_cache = arp::NeighborCache::new(&mut neighbors[..]); eth_cache.fill(gateway.address().into(), gatemac, None).unwrap(); - eth_cache + arp::Endpoint::new(eth_cache) }; let mut ip = [ip::Route::new_ipv4_gateway(gateway.address()); 1]; let routes = ip::Routes::import(List::new_full(ip.as_mut().into())); diff --git a/ethox/examples/curl.rs b/ethox/examples/curl.rs index 6ca40eb..19c91d6 100644 --- a/ethox/examples/curl.rs +++ b/ethox/examples/curl.rs @@ -26,9 +26,10 @@ fn main() { let mut neighbors = [arp::Neighbor::default(); 1]; // Buffer space for routes, we only have a single state one. let mut routes = [ip::Route::new_ipv4_gateway(gateway.address()); 1]; + let neighbors = arp::NeighborCache::new(&mut neighbors[..]); let mut ip = ip::Endpoint::new(Slice::One(host.into()), ip::Routes::import(List::new_full(routes.as_mut().into())), - arp::NeighborCache::new(&mut neighbors[..])); + arp::Endpoint::new(neighbors)); let mut tcp = tcp::Endpoint::new( Map::Pairs(List::new(Slice::One(Default::default()))), diff --git a/ethox/examples/ping_tap.rs b/ethox/examples/ping_tap.rs index 574215d..c047e02 100644 --- a/ethox/examples/ping_tap.rs +++ b/ethox/examples/ping_tap.rs @@ -45,11 +45,12 @@ fn main() { let mut neighbors = [arp::Neighbor::default(); 1]; let mut routes = [ip::Route::new_ipv4_gateway(gateway.address()); 1]; + let neighbors = arp::NeighborCache::new(&mut neighbors[..]); let mut ip = ip::Endpoint::new(Slice::One(host.into()), // Prefill the routes ip::Routes::import(List::new_full(routes.as_mut().into())), // But do automatic arp - arp::NeighborCache::new(&mut neighbors[..])); + arp::Endpoint::new(neighbors)); let mut icmp = icmp::Endpoint::new();