From 1b4d31dbd9ce1432149685eb993f9971df59bd70 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 8 Apr 2021 15:28:11 +0200 Subject: [PATCH 1/5] Updating NAL to support TCP port randomization --- Cargo.lock | 9 ++++++++- Cargo.toml | 2 +- src/hardware/configuration.rs | 24 ++++++++++++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f77e0bd..0c99862 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -437,6 +437,12 @@ dependencies = [ "heapless 0.6.1", ] +[[package]] +name = "nanorand" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1378b66f7c93a1c0f8464a19bf47df8795083842e5090f4b7305973d5a22d0" + [[package]] name = "nb" version = "0.1.3" @@ -710,10 +716,11 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=7572183#757218316620e074405bc38ff5502ef17a8a3499" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/random-port#462adc56a8cc95bc1324f6d96fdbe82e85ca6d36" dependencies = [ "embedded-nal", "heapless 0.6.1", + "nanorand", "smoltcp", ] diff --git a/Cargo.toml b/Cargo.toml index 0c4ab0d..87a0e2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -rev = "7572183" +branch = "feature/random-port" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index 74307dd..8a6ec0d 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -594,13 +594,25 @@ pub fn setup( ) }; + let random_seed = { + let mut rng = + device.RNG.constrain(ccdr.peripheral.RNG, &ccdr.clocks); + let mut data = [0u8; 4]; + rng.fill(&mut data).unwrap(); + data + }; + + let mut stack = smoltcp_nal::NetworkStack::new( + interface, + sockets, + &handles, + Some(dhcp_client), + ); + + stack.seed_random_port(&random_seed); + NetworkDevices { - stack: smoltcp_nal::NetworkStack::new( - interface, - sockets, - &handles, - Some(dhcp_client), - ), + stack, phy: lan8742a, } }; From d333a25301a53e2b8d0347db1bbd7779f734feb4 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 15 Apr 2021 12:24:49 +0200 Subject: [PATCH 2/5] Updating dependency --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0c99862..ee321ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/random-port#462adc56a8cc95bc1324f6d96fdbe82e85ca6d36" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/random-port#b5b050b135f3fe89e1a33d7d9f1d3d8570132f3c" dependencies = [ "embedded-nal", "heapless 0.6.1", From b2285d1ba2f0c9eba38e83aec33cefd88d7a4b93 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 19 Apr 2021 15:55:02 +0200 Subject: [PATCH 3/5] Updating dependency revision --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee321ff..970506d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/random-port#b5b050b135f3fe89e1a33d7d9f1d3d8570132f3c" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=8468f11#8468f11abacd7aba82454e6904df19c1d1ab91bb" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index 87a0e2e..f4db4d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -branch = "feature/random-port" +rev = "8468f11" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" From bc5e532655e358300b27c24987479ecd5b2edea8 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 20 Apr 2021 12:13:40 +0200 Subject: [PATCH 4/5] Adding sleep to HITL run --- hitl/run.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hitl/run.sh b/hitl/run.sh index 483a8a3..947a0d3 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -17,11 +17,13 @@ python3 -m pip install -r requirements.txt cargo flash --elf target/thumbv7em-none-eabihf/release/dual-iir --chip STM32H743ZITx +sleep 30 + # Test pinging Stabilizer. This exercises that: # * DHCP is functional and an IP has been acquired # * Stabilizer's network is functioning as intended # * The stabilizer application is operational -ping -c 5 -w 20 stabilizer-hitl +ping -c 5 -w 45 stabilizer-hitl # Test the MQTT interface. python3 miniconf.py dt/sinara/stabilizer afe/0='"G2"' From 7106b7d585e220754aef5a964681b304eec71334 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 20 Apr 2021 13:21:02 +0200 Subject: [PATCH 5/5] Adding comment, reverting change --- hitl/run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hitl/run.sh b/hitl/run.sh index 947a0d3..41d59a0 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -17,13 +17,14 @@ python3 -m pip install -r requirements.txt cargo flash --elf target/thumbv7em-none-eabihf/release/dual-iir --chip STM32H743ZITx +# Before attempting to ping the device, sleep to allow Stabilizer to boot. sleep 30 # Test pinging Stabilizer. This exercises that: # * DHCP is functional and an IP has been acquired # * Stabilizer's network is functioning as intended # * The stabilizer application is operational -ping -c 5 -w 45 stabilizer-hitl +ping -c 5 -w 20 stabilizer-hitl # Test the MQTT interface. python3 miniconf.py dt/sinara/stabilizer afe/0='"G2"'