From 9c8a760631fb28c1d2a5c330e28ac00f8b3c0287 Mon Sep 17 00:00:00 2001 From: _index Date: Mon, 25 Nov 2024 13:58:56 +0100 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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()) }