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;