mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-10-23 14:02:21 +00:00
Patch windows tunnel set address
The library does not work on windows 11 to properly set up the address. This is caused by an incorrect `netsh` command. Manually implement the correct command for now, until the library is patched. To be seen if this works on windows 10 Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
1 file changed
+29
-1
+29
-1
@@ -39,7 +39,9 @@ pub async fn new(
|
||||
// Configure created network adapter.
|
||||
tun.set_mtu(LINK_MTU)?;
|
||||
// Set address, this will use a `netsh` command under the hood unfortunately.
|
||||
tun.set_network_addresses_tuple(node_subnet.address(), route_subnet.mask(), None)?;
|
||||
// TODO: fix in library
|
||||
// tun.set_network_addresses_tuple(node_subnet.address(), route_subnet.mask(), None)?;
|
||||
add_address(name, node_subnet, route_subnet)?;
|
||||
// Build 2 separate sessions - one for receiving, one for sending.
|
||||
let rx_session = Arc::new(tun.start_session(wintun::MAX_RING_CAPACITY)?);
|
||||
let tx_session = rx_session.clone();
|
||||
@@ -107,3 +109,29 @@ fn wintun_to_io_error(err: wintun::Error) -> io::Error {
|
||||
_ => io::Error::new(io::ErrorKind::Other, "unknown wintun error"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set an address on an interface by shelling out to `netsh`
|
||||
///
|
||||
/// We assume this is an IPv6 address.
|
||||
fn add_address(adapter_name: &str, subnet: Subnet, route_subnet: Subnet) -> Result<(), io::Error> {
|
||||
let exit_code = std::process::Command::new("netsh")
|
||||
.args(&[
|
||||
"interface",
|
||||
"ipv6",
|
||||
"set",
|
||||
"address",
|
||||
adapter_name,
|
||||
&format!("{}/{}", subnet.address(), route_subnet.prefix_len()),
|
||||
])
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
|
||||
match exit_code.code() {
|
||||
Some(0) => Ok(()),
|
||||
Some(x) => Err(io::Error::from_raw_os_error(x)),
|
||||
None => {
|
||||
warn!("Failed to determine `netsh` exit status");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user