From 9c8a760631fb28c1d2a5c330e28ac00f8b3c0287 Mon Sep 17 00:00:00 2001 From: _index Date: Mon, 25 Nov 2024 13:58:56 +0100 Subject: [PATCH 01/25] gatekeep mdns ipv6 behind feature flag --- Cargo.toml | 5 ++++- src/mdns.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 70428769e0f..c0e6f54ec83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,9 @@ esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" } cmake = { git = "https://github.com/ivmarkov/cmake-rs" } [features] -default = ["std", "binstart"] +default = ["std", "binstart", "mdns_ipv6"] + +mdns_ipv6 = [] std = ["alloc", "log/std", "esp-idf-hal/std", "embedded-svc/std", "futures-io"] alloc = ["esp-idf-hal/alloc", "embedded-svc/alloc", "uncased/alloc"] @@ -44,6 +46,7 @@ panic_handler = ["esp-idf-hal/panic_handler"] binstart = ["esp-idf-hal/binstart"] libstart = ["esp-idf-hal/libstart"] + [dependencies] heapless = { version = "0.8", default-features = false } num_enum = { version = "0.7", default-features = false } diff --git a/src/mdns.rs b/src/mdns.rs index cb60dfcffc9..4bbedb41102 100644 --- a/src/mdns.rs +++ b/src/mdns.rs @@ -9,7 +9,9 @@ use alloc::vec::Vec; use ::log::info; -use embedded_svc::ipv4::{IpAddr, Ipv4Addr, Ipv6Addr}; +use embedded_svc::ipv4::{IpAddr, Ipv4Addr}; +#[cfg(feature = "mdns_ipv6")] +use embedded_svc::ipv4::Ipv6Addr; use crate::sys::*; @@ -27,12 +29,14 @@ pub enum Interface { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Protocol { V4, + #[cfg(feature = "mdns_ipv6")] V6, } #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Type { A = MDNS_TYPE_A as _, + #[cfg(feature = "mdns_ipv6")] AAAA = MDNS_TYPE_AAAA as _, ANY = MDNS_TYPE_ANY as _, NSEC = MDNS_TYPE_NSEC as _, @@ -83,6 +87,7 @@ impl From for QueryResult { let a = unsafe { (*p).addr }; let a = match a.type_ as _ { ESP_IPADDR_TYPE_V4 => IpAddr::V4(from_esp_ip4_addr_t(unsafe { &a.u_addr.ip4 })), + #[cfg(feature = "mdns_ipv6")] ESP_IPADDR_TYPE_V6 => IpAddr::V6(from_esp_ip6_addr_t(unsafe { &a.u_addr.ip6 })), _ => unreachable!(), }; @@ -113,6 +118,7 @@ impl From for QueryResult { let ip_protocol = match result.ip_protocol { mdns_ip_protocol_t_MDNS_IP_PROTOCOL_V4 => Protocol::V4, + #[cfg(feature = "mdns_ipv6")] mdns_ip_protocol_t_MDNS_IP_PROTOCOL_V6 => Protocol::V6, _ => unreachable!(), }; @@ -374,6 +380,7 @@ impl EspMdns { Ok(from_esp_ip4_addr_t(&addr)) } + #[cfg(feature = enable_ipv6)] pub fn query_aaaa( &self, hostname: impl AsRef, @@ -497,6 +504,7 @@ fn from_esp_ip4_addr_t(addr: &esp_ip4_addr_t) -> Ipv4Addr { Ipv4Addr::from(addr.addr.to_le_bytes()) } +#[cfg(feature = "mdns_ipv6")] fn from_esp_ip6_addr_t(addr: &esp_ip6_addr_t) -> Ipv6Addr { let mut buf = [0u8; 16]; let mut i = 0; From ad54aeeae3544fbea03e7f2b5315a01fbe8bf413 Mon Sep 17 00:00:00 2001 From: _index Date: Mon, 25 Nov 2024 15:17:15 +0100 Subject: [PATCH 02/25] fix feature flag typo --- src/mdns.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mdns.rs b/src/mdns.rs index 4bbedb41102..d60ae75f31e 100644 --- a/src/mdns.rs +++ b/src/mdns.rs @@ -380,7 +380,7 @@ impl EspMdns { Ok(from_esp_ip4_addr_t(&addr)) } - #[cfg(feature = enable_ipv6)] + #[cfg(feature = "mdns_ipv6")] pub fn query_aaaa( &self, hostname: impl AsRef, From 4de452b1ab44eb24eee817406bdaa5c44021bc95 Mon Sep 17 00:00:00 2001 From: _index Date: Sat, 30 Nov 2024 14:42:56 +0100 Subject: [PATCH 03/25] format --- src/mdns.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mdns.rs b/src/mdns.rs index d60ae75f31e..55bfeb5647b 100644 --- a/src/mdns.rs +++ b/src/mdns.rs @@ -9,9 +9,9 @@ use alloc::vec::Vec; use ::log::info; -use embedded_svc::ipv4::{IpAddr, Ipv4Addr}; #[cfg(feature = "mdns_ipv6")] use embedded_svc::ipv4::Ipv6Addr; +use embedded_svc::ipv4::{IpAddr, Ipv4Addr}; use crate::sys::*; From b482ff572fb87b10a88b88353fdc4d225eb0cee9 Mon Sep 17 00:00:00 2001 From: _index Date: Sat, 30 Nov 2024 15:54:27 +0100 Subject: [PATCH 04/25] requested changes --- Cargo.toml | 5 +---- src/mdns.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c908eb79a63..441a8e25160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,9 +23,7 @@ esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" } esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" } [features] -default = ["std", "binstart", "mdns_ipv6"] - -mdns_ipv6 = [] +default = ["std", "binstart"] std = ["alloc", "log/std", "esp-idf-hal/std", "embedded-svc/std", "futures-io"] alloc = ["esp-idf-hal/alloc", "embedded-svc/alloc", "uncased/alloc"] @@ -45,7 +43,6 @@ panic_handler = ["esp-idf-hal/panic_handler"] binstart = ["esp-idf-hal/binstart"] libstart = ["esp-idf-hal/libstart"] - [dependencies] heapless = { version = "0.8", default-features = false } num_enum = { version = "0.7", default-features = false } diff --git a/src/mdns.rs b/src/mdns.rs index 55bfeb5647b..e4074b77dca 100644 --- a/src/mdns.rs +++ b/src/mdns.rs @@ -9,7 +9,7 @@ use alloc::vec::Vec; use ::log::info; -#[cfg(feature = "mdns_ipv6")] +#[cfg(feature = "esp_idf_lwip_ipv6")] use embedded_svc::ipv4::Ipv6Addr; use embedded_svc::ipv4::{IpAddr, Ipv4Addr}; @@ -29,14 +29,14 @@ pub enum Interface { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Protocol { V4, - #[cfg(feature = "mdns_ipv6")] + #[cfg(feature = "esp_idf_lwip_ipv6")] V6, } #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Type { A = MDNS_TYPE_A as _, - #[cfg(feature = "mdns_ipv6")] + #[cfg(feature = "esp_idf_lwip_ipv6")] AAAA = MDNS_TYPE_AAAA as _, ANY = MDNS_TYPE_ANY as _, NSEC = MDNS_TYPE_NSEC as _, @@ -87,7 +87,7 @@ impl From for QueryResult { let a = unsafe { (*p).addr }; let a = match a.type_ as _ { ESP_IPADDR_TYPE_V4 => IpAddr::V4(from_esp_ip4_addr_t(unsafe { &a.u_addr.ip4 })), - #[cfg(feature = "mdns_ipv6")] + #[cfg(feature = "esp_idf_lwip_ipv6")] ESP_IPADDR_TYPE_V6 => IpAddr::V6(from_esp_ip6_addr_t(unsafe { &a.u_addr.ip6 })), _ => unreachable!(), }; @@ -118,7 +118,7 @@ impl From for QueryResult { let ip_protocol = match result.ip_protocol { mdns_ip_protocol_t_MDNS_IP_PROTOCOL_V4 => Protocol::V4, - #[cfg(feature = "mdns_ipv6")] + #[cfg(feature = "esp_idf_lwip_ipv6")] mdns_ip_protocol_t_MDNS_IP_PROTOCOL_V6 => Protocol::V6, _ => unreachable!(), }; @@ -380,7 +380,7 @@ impl EspMdns { Ok(from_esp_ip4_addr_t(&addr)) } - #[cfg(feature = "mdns_ipv6")] + #[cfg(feature = "esp_idf_lwip_ipv6")] pub fn query_aaaa( &self, hostname: impl AsRef, @@ -504,7 +504,7 @@ fn from_esp_ip4_addr_t(addr: &esp_ip4_addr_t) -> Ipv4Addr { Ipv4Addr::from(addr.addr.to_le_bytes()) } -#[cfg(feature = "mdns_ipv6")] +#[cfg(feature = "esp_idf_lwip_ipv6")] fn from_esp_ip6_addr_t(addr: &esp_ip6_addr_t) -> Ipv6Addr { let mut buf = [0u8; 16]; let mut i = 0; From b18d9a1b56e72ea6a65ba288e82bb585567e46c0 Mon Sep 17 00:00:00 2001 From: _index Date: Sat, 30 Nov 2024 15:57:30 +0100 Subject: [PATCH 05/25] erratum --- src/mdns.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mdns.rs b/src/mdns.rs index e4074b77dca..7fec2119262 100644 --- a/src/mdns.rs +++ b/src/mdns.rs @@ -9,7 +9,7 @@ use alloc::vec::Vec; use ::log::info; -#[cfg(feature = "esp_idf_lwip_ipv6")] +#[cfg(esp_idf_lwip_ipv6)] use embedded_svc::ipv4::Ipv6Addr; use embedded_svc::ipv4::{IpAddr, Ipv4Addr}; @@ -29,14 +29,14 @@ pub enum Interface { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Protocol { V4, - #[cfg(feature = "esp_idf_lwip_ipv6")] + #[cfg(esp_idf_lwip_ipv6)] V6, } #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Type { A = MDNS_TYPE_A as _, - #[cfg(feature = "esp_idf_lwip_ipv6")] + #[cfg(esp_idf_lwip_ipv6)] AAAA = MDNS_TYPE_AAAA as _, ANY = MDNS_TYPE_ANY as _, NSEC = MDNS_TYPE_NSEC as _, @@ -87,7 +87,7 @@ impl From for QueryResult { let a = unsafe { (*p).addr }; let a = match a.type_ as _ { ESP_IPADDR_TYPE_V4 => IpAddr::V4(from_esp_ip4_addr_t(unsafe { &a.u_addr.ip4 })), - #[cfg(feature = "esp_idf_lwip_ipv6")] + #[cfg(esp_idf_lwip_ipv6)] ESP_IPADDR_TYPE_V6 => IpAddr::V6(from_esp_ip6_addr_t(unsafe { &a.u_addr.ip6 })), _ => unreachable!(), }; @@ -118,7 +118,7 @@ impl From for QueryResult { let ip_protocol = match result.ip_protocol { mdns_ip_protocol_t_MDNS_IP_PROTOCOL_V4 => Protocol::V4, - #[cfg(feature = "esp_idf_lwip_ipv6")] + #[cfg(esp_idf_lwip_ipv6)] mdns_ip_protocol_t_MDNS_IP_PROTOCOL_V6 => Protocol::V6, _ => unreachable!(), }; @@ -380,7 +380,7 @@ impl EspMdns { Ok(from_esp_ip4_addr_t(&addr)) } - #[cfg(feature = "esp_idf_lwip_ipv6")] + #[cfg(esp_idf_lwip_ipv6)] pub fn query_aaaa( &self, hostname: impl AsRef, @@ -504,7 +504,7 @@ fn from_esp_ip4_addr_t(addr: &esp_ip4_addr_t) -> Ipv4Addr { Ipv4Addr::from(addr.addr.to_le_bytes()) } -#[cfg(feature = "esp_idf_lwip_ipv6")] +#[cfg(esp_idf_lwip_ipv6)] fn from_esp_ip6_addr_t(addr: &esp_ip6_addr_t) -> Ipv6Addr { let mut buf = [0u8; 16]; let mut i = 0; From fa4d63fb6c5b831c01dee59970b8a0bca50c9c1c Mon Sep 17 00:00:00 2001 From: _index Date: Sat, 30 Nov 2024 16:32:06 +0100 Subject: [PATCH 06/25] add ipv4 feature flag --- src/mdns.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mdns.rs b/src/mdns.rs index 7fec2119262..3fef5102991 100644 --- a/src/mdns.rs +++ b/src/mdns.rs @@ -9,9 +9,12 @@ use alloc::vec::Vec; use ::log::info; +#[cfg(any(esp_idf_lwip_ipv4, esp_idf_lwip_ipv6))] +use embedded_svc::ipv4::IpAddr; +#[cfg(esp_idf_lwip_ipv4)] +use embedded_svc::ipv4::Ipv4Addr; #[cfg(esp_idf_lwip_ipv6)] use embedded_svc::ipv4::Ipv6Addr; -use embedded_svc::ipv4::{IpAddr, Ipv4Addr}; use crate::sys::*; @@ -28,6 +31,7 @@ pub enum Interface { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Protocol { + #[cfg(esp_idf_lwip_ipv4)] V4, #[cfg(esp_idf_lwip_ipv6)] V6, @@ -35,6 +39,7 @@ pub enum Protocol { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Type { + #[cfg(esp_idf_lwip_ipv4)] A = MDNS_TYPE_A as _, #[cfg(esp_idf_lwip_ipv6)] AAAA = MDNS_TYPE_AAAA as _, @@ -86,6 +91,7 @@ impl From for QueryResult { while !p.is_null() { let a = unsafe { (*p).addr }; let a = match a.type_ as _ { + #[cfg(esp_idf_lwip_ipv4)] ESP_IPADDR_TYPE_V4 => IpAddr::V4(from_esp_ip4_addr_t(unsafe { &a.u_addr.ip4 })), #[cfg(esp_idf_lwip_ipv6)] ESP_IPADDR_TYPE_V6 => IpAddr::V6(from_esp_ip6_addr_t(unsafe { &a.u_addr.ip6 })), @@ -117,6 +123,7 @@ impl From for QueryResult { }; let ip_protocol = match result.ip_protocol { + #[cfg(esp_idf_lwip_ipv4)] mdns_ip_protocol_t_MDNS_IP_PROTOCOL_V4 => Protocol::V4, #[cfg(esp_idf_lwip_ipv6)] mdns_ip_protocol_t_MDNS_IP_PROTOCOL_V6 => Protocol::V6, @@ -367,6 +374,7 @@ impl EspMdns { Ok(copy_query_results(result, results)) } + #[cfg(esp_idf_lwip_ipv4)] pub fn query_a( &self, hostname: impl AsRef, @@ -500,6 +508,7 @@ fn copy_query_results(src: *mut mdns_result_t, dst: &mut [QueryResult]) -> usize } } +#[cfg(esp_idf_lwip_ipv4)] fn from_esp_ip4_addr_t(addr: &esp_ip4_addr_t) -> Ipv4Addr { Ipv4Addr::from(addr.addr.to_le_bytes()) } From b8e7a92f22a411e0b4cb43ea9761d4706931cd7c Mon Sep 17 00:00:00 2001 From: _index Date: Mon, 23 Dec 2024 23:31:48 +0100 Subject: [PATCH 07/25] add wrapper for promiscuous mode --- src/eth.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/eth.rs b/src/eth.rs index 41ae3f8578d..20008cadc7a 100644 --- a/src/eth.rs +++ b/src/eth.rs @@ -1032,6 +1032,24 @@ impl<'d, T> EthDriver<'d, T> { Ok(()) } + pub fn set_promiscuous(&mut self, state: bool) -> Result<(), EspError> { + esp!(unsafe { + esp_eth_ioctl( + self.handle(), + esp_eth_io_cmd_t_ETH_CMD_S_PROMISCUOUS, + &raw const state as *mut _, + ) + })?; + + if state { + log::warn!("Driver set in promiscuous mode"); + } else { + log::info!("Driver set in non-promiscuous mode"); + } + + Ok(()) + } + fn eth_default_config(mac: *mut esp_eth_mac_t, phy: *mut esp_eth_phy_t) -> esp_eth_config_t { esp_eth_config_t { mac, From 9dd18df1df79d7e60cd44754f27211b3407cba81 Mon Sep 17 00:00:00 2001 From: _index Date: Mon, 23 Dec 2024 23:35:08 +0100 Subject: [PATCH 08/25] change warn->info --- src/eth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eth.rs b/src/eth.rs index 20008cadc7a..b77d5b37dbd 100644 --- a/src/eth.rs +++ b/src/eth.rs @@ -1042,7 +1042,7 @@ impl<'d, T> EthDriver<'d, T> { })?; if state { - log::warn!("Driver set in promiscuous mode"); + log::info!("Driver set in promiscuous mode"); } else { log::info!("Driver set in non-promiscuous mode"); } From 5da19ece2f98b3adb6c00613bc3a2cc3af4aa87f Mon Sep 17 00:00:00 2001 From: _index Date: Tue, 24 Dec 2024 00:03:03 +0100 Subject: [PATCH 09/25] add changes --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc96f699031..0338bc7d125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add option to specify initial caps for the MQTT async adaptor vectors - Allow using esp timer with skip_unhandled_events (#526) - OTA - Implements a new type `EspFirmwareInfoLoad` that has a reduced memory consumption (#531) +- Added set_promiscuous function in EthDriver (#246) +- Added set_promiscuous function in WifiDriver (#246) ### Fixed - The alloc::Vec version stomps the scan state from Done to Idle. (#459) From 0f0d18693a5778651f6304fb19cb6a71fc4c5ac1 Mon Sep 17 00:00:00 2001 From: _index Date: Tue, 24 Dec 2024 00:04:04 +0100 Subject: [PATCH 10/25] add changes --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0338bc7d125..3544397cec9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow using esp timer with skip_unhandled_events (#526) - OTA - Implements a new type `EspFirmwareInfoLoad` that has a reduced memory consumption (#531) - Added set_promiscuous function in EthDriver (#246) -- Added set_promiscuous function in WifiDriver (#246) ### Fixed - The alloc::Vec version stomps the scan state from Done to Idle. (#459) From 1feeaf33546d2cace53e2982fd74fc16bec83fa4 Mon Sep 17 00:00:00 2001 From: _index Date: Tue, 24 Dec 2024 00:25:02 +0100 Subject: [PATCH 11/25] &mut self -> &self --- src/eth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eth.rs b/src/eth.rs index b77d5b37dbd..e45d071e5da 100644 --- a/src/eth.rs +++ b/src/eth.rs @@ -1032,7 +1032,7 @@ impl<'d, T> EthDriver<'d, T> { Ok(()) } - pub fn set_promiscuous(&mut self, state: bool) -> Result<(), EspError> { + pub fn set_promiscuous(&self, state: bool) -> Result<(), EspError> { esp!(unsafe { esp_eth_ioctl( self.handle(), From 85e727120d339930fd7dfb125eb41b79a8bc7413 Mon Sep 17 00:00:00 2001 From: _index Date: Tue, 24 Dec 2024 13:40:20 +0100 Subject: [PATCH 12/25] add documentation, switch to &mut self --- src/eth.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/eth.rs b/src/eth.rs index e45d071e5da..dbd47a1060b 100644 --- a/src/eth.rs +++ b/src/eth.rs @@ -1032,7 +1032,13 @@ impl<'d, T> EthDriver<'d, T> { Ok(()) } - pub fn set_promiscuous(&self, state: bool) -> Result<(), EspError> { + + /// Enables or disables promiscuous mode for the Ethernet driver. + /// + /// When promiscuous mode is enabled, the driver captures all Ethernet frames + /// on the network, regardless of their destination MAC address. This is useful for + /// debugging or monitoring purposes. + pub fn set_promiscuous(&mut self, state: bool) -> Result<(), EspError> { esp!(unsafe { esp_eth_ioctl( self.handle(), From 35bfea5f83ec729a4583901f080b608fd89d4430 Mon Sep 17 00:00:00 2001 From: _index Date: Tue, 24 Dec 2024 13:41:02 +0100 Subject: [PATCH 13/25] format --- src/eth.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/eth.rs b/src/eth.rs index dbd47a1060b..88bafe46403 100644 --- a/src/eth.rs +++ b/src/eth.rs @@ -1032,9 +1032,8 @@ impl<'d, T> EthDriver<'d, T> { Ok(()) } - /// Enables or disables promiscuous mode for the Ethernet driver. - /// + /// /// When promiscuous mode is enabled, the driver captures all Ethernet frames /// on the network, regardless of their destination MAC address. This is useful for /// debugging or monitoring purposes. From 54b89b1eb9a971c694841d396c58ef818bae0bb7 Mon Sep 17 00:00:00 2001 From: _index Date: Wed, 25 Dec 2024 15:36:11 +0100 Subject: [PATCH 14/25] double emac_rx stack size --- src/eth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eth.rs b/src/eth.rs index 88bafe46403..1e6ccd9006c 100644 --- a/src/eth.rs +++ b/src/eth.rs @@ -1094,7 +1094,7 @@ impl<'d, T> EthDriver<'d, T> { fn eth_mac_default_config(_mdc: i32, _mdio: i32) -> eth_mac_config_t { eth_mac_config_t { sw_reset_timeout_ms: 100, - rx_task_stack_size: 2048, + rx_task_stack_size: 4096, rx_task_prio: 15, flags: 0, } From cc808329ec60cda2cc3a479e0739275921f33fbb Mon Sep 17 00:00:00 2001 From: _index Date: Wed, 25 Dec 2024 16:22:52 +0100 Subject: [PATCH 15/25] Revert "double emac_rx stack size" This reverts commit 54b89b1eb9a971c694841d396c58ef818bae0bb7. --- src/eth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eth.rs b/src/eth.rs index 1e6ccd9006c..88bafe46403 100644 --- a/src/eth.rs +++ b/src/eth.rs @@ -1094,7 +1094,7 @@ impl<'d, T> EthDriver<'d, T> { fn eth_mac_default_config(_mdc: i32, _mdio: i32) -> eth_mac_config_t { eth_mac_config_t { sw_reset_timeout_ms: 100, - rx_task_stack_size: 4096, + rx_task_stack_size: 2048, rx_task_prio: 15, flags: 0, } From 1f40587f71660e1cefe30aeb442302d542891803 Mon Sep 17 00:00:00 2001 From: _index Date: Thu, 2 Jan 2025 23:35:26 +0100 Subject: [PATCH 16/25] tryfix --- src/netif.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/netif.rs b/src/netif.rs index 02e6f84f9e8..106ca382d5a 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -600,13 +600,18 @@ impl EspNetif { } #[cfg(esp_idf_lwip_ipv4_napt)] - pub fn enable_napt(&mut self, enable: bool) { + pub fn enable_napt(&mut self, enable: bool) -> Result<(), EspError> { unsafe { - crate::sys::ip_napt_enable_no( - (esp_netif_get_netif_impl_index(self.handle) - 1) as u8, - if enable { 1 } else { 0 }, - ) - }; + let if_index = (esp_netif_get_netif_impl_index(self.handle) - 1) as u8; + let ctx = (if_index, if enable { 1 } else { 0 }); + + esp!(esp_netif_tcpip_exec( + Some(ip_napt_enable_no), + &ctx as *const _ as *mut _ + )); + + Ok(()) + } } } From dc6c6775c9349002d78a1f41cffa3a8b78b71712 Mon Sep 17 00:00:00 2001 From: _index Date: Thu, 2 Jan 2025 23:47:46 +0100 Subject: [PATCH 17/25] for real this time --- src/netif.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/netif.rs b/src/netif.rs index 106ca382d5a..347853d4e6a 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -599,16 +599,22 @@ impl EspNetif { Ok(()) } + #[cfg(esp_idf_lwip_ipv4_napt)] + unsafe extern "C" fn napt_wrapper(ctx: *mut ffi::c_void) { + let ctx = unsafe { *(ctx as *mut (u8, i32)) }; + + ip_napt_enable_no(ctx.0, ctx.1); + } + #[cfg(esp_idf_lwip_ipv4_napt)] pub fn enable_napt(&mut self, enable: bool) -> Result<(), EspError> { unsafe { - let if_index = (esp_netif_get_netif_impl_index(self.handle) - 1) as u8; - let ctx = (if_index, if enable { 1 } else { 0 }); + let ctx = ((esp_netif_get_netif_impl_index(self.handle) - 1) as u8, if enable { 1 } else { 0 }); esp!(esp_netif_tcpip_exec( - Some(ip_napt_enable_no), + Some(napt_wrapper), &ctx as *const _ as *mut _ - )); + ))?; Ok(()) } From 973c52959f8bd99bc454ac28d3ddab04858e697b Mon Sep 17 00:00:00 2001 From: _index Date: Thu, 2 Jan 2025 23:56:45 +0100 Subject: [PATCH 18/25] format --- src/netif.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/netif.rs b/src/netif.rs index 347853d4e6a..f609b713d5b 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -605,11 +605,18 @@ impl EspNetif { ip_napt_enable_no(ctx.0, ctx.1); } - + + /// Enables or disables NAPT on this netif. + /// + /// Enable operation can be performed only on one interface at a time. + /// NAPT cannot be enabled on multiple interfaces according to this implementation. #[cfg(esp_idf_lwip_ipv4_napt)] pub fn enable_napt(&mut self, enable: bool) -> Result<(), EspError> { unsafe { - let ctx = ((esp_netif_get_netif_impl_index(self.handle) - 1) as u8, if enable { 1 } else { 0 }); + let ctx = ( + (esp_netif_get_netif_impl_index(self.handle) - 1) as u8, + if enable { 1 } else { 0 }, + ); esp!(esp_netif_tcpip_exec( Some(napt_wrapper), From 5925165805973a2ee12b603564d0349fb34452ed Mon Sep 17 00:00:00 2001 From: _index Date: Fri, 3 Jan 2025 00:09:03 +0100 Subject: [PATCH 19/25] fix weird undeclared bug? --- src/netif.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/netif.rs b/src/netif.rs index f609b713d5b..71be9f11ff8 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -599,16 +599,18 @@ impl EspNetif { Ok(()) } - #[cfg(esp_idf_lwip_ipv4_napt)] unsafe extern "C" fn napt_wrapper(ctx: *mut ffi::c_void) { - let ctx = unsafe { *(ctx as *mut (u8, i32)) }; + #[cfg(esp_idf_lwip_ipv4_napt)] + { + let ctx = unsafe { *(ctx as *mut (u8, i32)) }; - ip_napt_enable_no(ctx.0, ctx.1); + ip_napt_enable_no(ctx.0, ctx.1); + } } /// Enables or disables NAPT on this netif. /// - /// Enable operation can be performed only on one interface at a time. + /// Enable operation can be performed only on one interface at a time. /// NAPT cannot be enabled on multiple interfaces according to this implementation. #[cfg(esp_idf_lwip_ipv4_napt)] pub fn enable_napt(&mut self, enable: bool) -> Result<(), EspError> { From 9d13946204d7e1affb52d06b9d750f8188091898 Mon Sep 17 00:00:00 2001 From: _index Date: Fri, 3 Jan 2025 00:12:04 +0100 Subject: [PATCH 20/25] Revert "fix weird undeclared bug?" This reverts commit 5925165805973a2ee12b603564d0349fb34452ed. --- src/netif.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/netif.rs b/src/netif.rs index 71be9f11ff8..f609b713d5b 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -599,18 +599,16 @@ impl EspNetif { Ok(()) } + #[cfg(esp_idf_lwip_ipv4_napt)] unsafe extern "C" fn napt_wrapper(ctx: *mut ffi::c_void) { - #[cfg(esp_idf_lwip_ipv4_napt)] - { - let ctx = unsafe { *(ctx as *mut (u8, i32)) }; + let ctx = unsafe { *(ctx as *mut (u8, i32)) }; - ip_napt_enable_no(ctx.0, ctx.1); - } + ip_napt_enable_no(ctx.0, ctx.1); } /// Enables or disables NAPT on this netif. /// - /// Enable operation can be performed only on one interface at a time. + /// Enable operation can be performed only on one interface at a time. /// NAPT cannot be enabled on multiple interfaces according to this implementation. #[cfg(esp_idf_lwip_ipv4_napt)] pub fn enable_napt(&mut self, enable: bool) -> Result<(), EspError> { From c87744050f7aeed911b8013e4420bbbe57e05e1f Mon Sep 17 00:00:00 2001 From: _index Date: Fri, 3 Jan 2025 00:23:35 +0100 Subject: [PATCH 21/25] surely this will work --- src/netif.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netif.rs b/src/netif.rs index f609b713d5b..85ecf7f487b 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -608,7 +608,7 @@ impl EspNetif { /// Enables or disables NAPT on this netif. /// - /// Enable operation can be performed only on one interface at a time. + /// Enable operation can be performed only on one interface at a time. /// NAPT cannot be enabled on multiple interfaces according to this implementation. #[cfg(esp_idf_lwip_ipv4_napt)] pub fn enable_napt(&mut self, enable: bool) -> Result<(), EspError> { @@ -619,7 +619,7 @@ impl EspNetif { ); esp!(esp_netif_tcpip_exec( - Some(napt_wrapper), + Some(EspNetif::napt_wrapper), &ctx as *const _ as *mut _ ))?; From 3a02f53750da463274a938b5236463cd74d305a5 Mon Sep 17 00:00:00 2001 From: _index Date: Fri, 3 Jan 2025 00:28:45 +0100 Subject: [PATCH 22/25] fix return type --- src/netif.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/netif.rs b/src/netif.rs index 85ecf7f487b..2b38483af34 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -600,10 +600,12 @@ impl EspNetif { } #[cfg(esp_idf_lwip_ipv4_napt)] - unsafe extern "C" fn napt_wrapper(ctx: *mut ffi::c_void) { + unsafe extern "C" fn napt_wrapper(ctx: *mut ffi::c_void) -> i32 { let ctx = unsafe { *(ctx as *mut (u8, i32)) }; ip_napt_enable_no(ctx.0, ctx.1); + + 0 } /// Enables or disables NAPT on this netif. From 93644a95a0df1dcddbffcec2870c84cde4093594 Mon Sep 17 00:00:00 2001 From: _index Date: Fri, 3 Jan 2025 00:43:36 +0100 Subject: [PATCH 23/25] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 672e2a26897..7a4d74b100d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Fixed +- Crash when enabling napt in EspNetif (#545) + ## [0.50.0] - 2025-01-02 ### Deprecated From 12c18c7ee020f840b85e57c686ea721343b69b9f Mon Sep 17 00:00:00 2001 From: _index Date: Fri, 3 Jan 2025 00:43:40 +0100 Subject: [PATCH 24/25] format --- src/netif.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netif.rs b/src/netif.rs index 2b38483af34..bf31a59e576 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -605,7 +605,7 @@ impl EspNetif { ip_napt_enable_no(ctx.0, ctx.1); - 0 + 0 } /// Enables or disables NAPT on this netif. From 1154b01ec545756d11f1512e09e726f011b1a381 Mon Sep 17 00:00:00 2001 From: _index Date: Fri, 3 Jan 2025 01:04:24 +0100 Subject: [PATCH 25/25] clear namespace --- src/netif.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/netif.rs b/src/netif.rs index bf31a59e576..c770af758c2 100644 --- a/src/netif.rs +++ b/src/netif.rs @@ -599,21 +599,20 @@ impl EspNetif { Ok(()) } - #[cfg(esp_idf_lwip_ipv4_napt)] - unsafe extern "C" fn napt_wrapper(ctx: *mut ffi::c_void) -> i32 { - let ctx = unsafe { *(ctx as *mut (u8, i32)) }; - - ip_napt_enable_no(ctx.0, ctx.1); - - 0 - } - /// Enables or disables NAPT on this netif. /// /// Enable operation can be performed only on one interface at a time. /// NAPT cannot be enabled on multiple interfaces according to this implementation. #[cfg(esp_idf_lwip_ipv4_napt)] pub fn enable_napt(&mut self, enable: bool) -> Result<(), EspError> { + unsafe extern "C" fn napt_wrapper(ctx: *mut ffi::c_void) -> i32 { + let ctx = unsafe { *(ctx as *mut (u8, i32)) }; + + ip_napt_enable_no(ctx.0, ctx.1); + + 0 + } + unsafe { let ctx = ( (esp_netif_get_netif_impl_index(self.handle) - 1) as u8, @@ -621,12 +620,12 @@ impl EspNetif { ); esp!(esp_netif_tcpip_exec( - Some(EspNetif::napt_wrapper), + Some(napt_wrapper), &ctx as *const _ as *mut _ ))?; - - Ok(()) } + + Ok(()) } }