From c3ae74bd3403d47bd84e282772c0df92625faeea Mon Sep 17 00:00:00 2001 From: Anselm Eberhardt Date: Wed, 31 Mar 2021 18:16:00 +0200 Subject: [PATCH] Fix macos ip/route setup for ipv6 nets --- shared/src/wg.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/shared/src/wg.rs b/shared/src/wg.rs index 229479e..7537bca 100644 --- a/shared/src/wg.rs +++ b/shared/src/wg.rs @@ -24,16 +24,24 @@ fn cmd(bin: &str, args: &[&str]) -> Result { #[cfg(target_os = "macos")] pub fn set_addr(interface: &str, addr: IpNetwork) -> Result<(), Error> { let real_interface = wgctrl::backends::userspace::resolve_tun(interface).with_str(interface)?; - cmd( - "ifconfig", - &[ - &real_interface, - "inet", - &addr.to_string(), - &addr.ip().to_string(), - "alias", - ], - )?; + + if addr.is_ipv4() { + cmd( + "ifconfig", + &[ + &real_interface, + "inet", + &addr.to_string(), + &addr.ip().to_string(), + "alias", + ], + )?; + } else { + cmd( + "ifconfig", + &[&real_interface, "inet6", &addr.to_string(), "alias"], + )?; + } cmd("ifconfig", &[&real_interface, "mtu", "1420"])?; Ok(()) } @@ -113,7 +121,7 @@ pub fn add_route(interface: &str, cidr: IpNetwork) -> Result { &[ "-n", "add", - "-inet", + if cidr.is_ipv4() { "-inet" } else { "-inet6" }, &cidr.to_string(), "-interface", &real_interface,