mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-16 19:05:38 +00:00
b87a05b457
* refactor: update global context STUN server initialization Modified global context initialization to use a single StunInfoCollector instance with properly configured IPv4 and IPv6 servers instead of creating separate instances. feat: add IPv6 STUN server configuration support Added interface methods and config struct fields to support both IPv4 and IPv6 STUN server configuration. Modified getter and setter methods to handle Option<Vec<String>> type for both server types. feat: enhance StunInfoCollector with IPv6 support Updated StunInfoCollector to support both IPv4 and IPv6 STUN servers. Added new constructor that accepts both server types and methods to set them independently. feat: add CLI argument for IPv6 STUN servers Added command line argument support for configuring IPv6 STUN servers. Updated configuration setup to handle both IPv4 and IPv6 STUN server settings. docs: add localization for STUN server configuration Added English and Chinese localization strings for the new STUN server configuration options, including both IPv4 and IPv6 variants.
140 lines
3.8 KiB
Rust
140 lines
3.8 KiB
Rust
use std::net::Ipv4Addr;
|
|
|
|
use super::{cidr_to_subnet_mask, run_shell_cmd, Error, IfConfiguerTrait};
|
|
use async_trait::async_trait;
|
|
use cidr::{Ipv4Inet, Ipv6Inet};
|
|
|
|
pub struct MacIfConfiger {}
|
|
#[async_trait]
|
|
impl IfConfiguerTrait for MacIfConfiger {
|
|
async fn add_ipv4_route(
|
|
&self,
|
|
name: &str,
|
|
address: Ipv4Addr,
|
|
cidr_prefix: u8,
|
|
cost: Option<i32>,
|
|
) -> Result<(), Error> {
|
|
run_shell_cmd(
|
|
format!(
|
|
"route -n add {} -netmask {} -interface {} -hopcount {}",
|
|
address,
|
|
cidr_to_subnet_mask(cidr_prefix),
|
|
name,
|
|
cost.unwrap_or(7)
|
|
)
|
|
.as_str(),
|
|
)
|
|
.await
|
|
}
|
|
|
|
async fn remove_ipv4_route(
|
|
&self,
|
|
name: &str,
|
|
address: Ipv4Addr,
|
|
cidr_prefix: u8,
|
|
) -> Result<(), Error> {
|
|
run_shell_cmd(
|
|
format!(
|
|
"route -n delete {} -netmask {} -interface {}",
|
|
address,
|
|
cidr_to_subnet_mask(cidr_prefix),
|
|
name
|
|
)
|
|
.as_str(),
|
|
)
|
|
.await
|
|
}
|
|
|
|
async fn add_ipv4_ip(
|
|
&self,
|
|
name: &str,
|
|
address: Ipv4Addr,
|
|
cidr_prefix: u8,
|
|
) -> Result<(), Error> {
|
|
run_shell_cmd(
|
|
format!(
|
|
"ifconfig {} {:?}/{:?} 10.8.8.8 up",
|
|
name, address, cidr_prefix,
|
|
)
|
|
.as_str(),
|
|
)
|
|
.await
|
|
}
|
|
|
|
async fn set_link_status(&self, name: &str, up: bool) -> Result<(), Error> {
|
|
run_shell_cmd(format!("ifconfig {} {}", name, if up { "up" } else { "down" }).as_str())
|
|
.await
|
|
}
|
|
|
|
async fn remove_ip(&self, name: &str, ip: Option<Ipv4Inet>) -> Result<(), Error> {
|
|
if ip.is_none() {
|
|
run_shell_cmd(format!("ifconfig {} inet delete", name).as_str()).await
|
|
} else {
|
|
run_shell_cmd(
|
|
format!("ifconfig {} inet {} delete", name, ip.unwrap().address()).as_str(),
|
|
)
|
|
.await
|
|
}
|
|
}
|
|
|
|
async fn set_mtu(&self, name: &str, mtu: u32) -> Result<(), Error> {
|
|
run_shell_cmd(format!("ifconfig {} mtu {}", name, mtu).as_str()).await
|
|
}
|
|
|
|
async fn add_ipv6_ip(
|
|
&self,
|
|
name: &str,
|
|
address: std::net::Ipv6Addr,
|
|
cidr_prefix: u8,
|
|
) -> Result<(), Error> {
|
|
run_shell_cmd(format!("ifconfig {} inet6 {}/{} add", name, address, cidr_prefix).as_str())
|
|
.await
|
|
}
|
|
|
|
async fn remove_ipv6(&self, name: &str, ip: Option<Ipv6Inet>) -> Result<(), Error> {
|
|
if let Some(ip) = ip {
|
|
run_shell_cmd(format!("ifconfig {} inet6 {} delete", name, ip.address()).as_str()).await
|
|
} else {
|
|
// Remove all IPv6 addresses is more complex on macOS, just succeed
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
async fn add_ipv6_route(
|
|
&self,
|
|
name: &str,
|
|
address: std::net::Ipv6Addr,
|
|
cidr_prefix: u8,
|
|
cost: Option<i32>,
|
|
) -> Result<(), Error> {
|
|
let cmd = if let Some(cost) = cost {
|
|
format!(
|
|
"route -n add -inet6 {}/{} -interface {} -hopcount {}",
|
|
address, cidr_prefix, name, cost
|
|
)
|
|
} else {
|
|
format!(
|
|
"route -n add -inet6 {}/{} -interface {}",
|
|
address, cidr_prefix, name
|
|
)
|
|
};
|
|
run_shell_cmd(cmd.as_str()).await
|
|
}
|
|
|
|
async fn remove_ipv6_route(
|
|
&self,
|
|
name: &str,
|
|
address: std::net::Ipv6Addr,
|
|
cidr_prefix: u8,
|
|
) -> Result<(), Error> {
|
|
run_shell_cmd(
|
|
format!(
|
|
"route -n delete -inet6 {}/{} -interface {}",
|
|
address, cidr_prefix, name
|
|
)
|
|
.as_str(),
|
|
)
|
|
.await
|
|
}
|
|
}
|