diff --git a/rust/relay/ebpf-shared/src/lib.rs b/rust/relay/ebpf-shared/src/lib.rs index 07cdbb132..00b9e061a 100644 --- a/rust/relay/ebpf-shared/src/lib.rs +++ b/rust/relay/ebpf-shared/src/lib.rs @@ -208,26 +208,22 @@ impl Default for Config { #[cfg_attr(feature = "std", derive(Debug))] pub struct InterfaceAddressV4 { address: [u8; 4], - learned: bool, } impl InterfaceAddressV4 { + const ZERO: [u8; 4] = [0; 4]; + pub fn set(&mut self, addr: Ipv4Addr) { self.address = addr.octets(); - self.learned = true; } pub fn get(&self) -> Option { - if self.learned { + if self.address != Self::ZERO { Some(self.address.into()) } else { None } } - - pub fn is_learned(&self) -> bool { - self.learned - } } #[repr(C)] @@ -235,26 +231,22 @@ impl InterfaceAddressV4 { #[cfg_attr(feature = "std", derive(Debug))] pub struct InterfaceAddressV6 { address: [u8; 16], - learned: bool, } impl InterfaceAddressV6 { + const ZERO: [u8; 16] = [0; 16]; + pub fn set(&mut self, addr: Ipv6Addr) { self.address = addr.octets(); - self.learned = true; } pub fn get(&self) -> Option { - if self.learned { + if self.address != Self::ZERO { Some(self.address.into()) } else { None } } - - pub fn is_learned(&self) -> bool { - self.learned - } } #[repr(C)] diff --git a/rust/relay/ebpf-turn-router/src/main.rs b/rust/relay/ebpf-turn-router/src/main.rs index 6893d4712..c3dccefe6 100644 --- a/rust/relay/ebpf-turn-router/src/main.rs +++ b/rust/relay/ebpf-turn-router/src/main.rs @@ -405,7 +405,7 @@ fn learn_interface_ipv4_address(ipv4: &Ip4) -> Result<(), Error> { // SAFETY: These are per-cpu maps so we don't need to worry about thread safety. unsafe { - if !(*interface_addr).is_learned() { + if (*interface_addr).get().is_none() { (*interface_addr).set(dst_ip); } } @@ -423,7 +423,7 @@ fn learn_interface_ipv6_address(ipv6: &Ip6) -> Result<(), Error> { // SAFETY: These are per-cpu maps so we don't need to worry about thread safety. unsafe { - if !(*interface_addr).is_learned() { + if (*interface_addr).get().is_none() { (*interface_addr).set(dst_ip); } }