From 66ee10619b3d4d8dedce5d8f2a031109e7a746c9 Mon Sep 17 00:00:00 2001 From: Lyn Date: Wed, 29 Jan 2025 16:39:17 +0100 Subject: [PATCH] add filter_force_ipv6 option that (only when being set) filters gossip endpoints by their version (false -> V4, true -> V6). this avoids mixups in setups where interfaces are separated by IP version. --- src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4f8557f..c0688a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,6 +85,7 @@ struct InterfaceSetting { name: String, /// Specify the external port that should be IGD forwarded to this Wireguard interface. Only used for IPv4. upnp_ext_port_v4: Option, + filter_force_ipv6: Option, } fn main() -> Result<()> { @@ -657,7 +658,6 @@ impl State { Ok(()) } - fn setup_wg_peers(&mut self, daemon: &Daemon, i: usize) -> Result<()> { let now = time(); for peer_cfg in daemon.config.peers.iter() { @@ -737,6 +737,15 @@ impl State { } } endpoints.sort(); + // if prefer_ipv6 option is set, strongly prefer addresses of chosen version + if let Some(interface) = daemon.config.interfaces.iter().find(|ifsetting| ifsetting.name == peer_cfg.interface) { + if let Some(filter_ipv6_only) = interface.filter_force_ipv6 { + endpoints = endpoints.into_iter().filter(|(ep, _)| { + ep.ip().is_ipv6() == filter_ipv6_only + }).collect(); + } + } + endpoints = endpoints .into_iter() .filter(|(ep, _)| { @@ -750,7 +759,6 @@ impl State { endpoints } }; - if !endpoints.is_empty() { let endpoint = endpoints[i % endpoints.len()].0;