- Updated Cargo.toml to include `etherparse` and enable async feature for `tun-rs`. - Added `ip_match_network` function in network module for IP matching. - Implemented TUN interface initialization in `tun.rs`. - Enhanced client handling in `client.rs` to support new features and improved message handling. - Refactored router messages to use a structured `VpnPacket`. - Updated settings for spell checking in VSCode.
30 lines
837 B
Rust
30 lines
837 B
Rust
use anyhow::Result;
|
|
use tun_rs::{AsyncDevice, DeviceBuilder};
|
|
|
|
use crate::client::ClientCfg;
|
|
|
|
pub async fn inti_tun_interface(config: &ClientCfg) -> Result<AsyncDevice> {
|
|
println!(
|
|
"Initializing TUN interface with name: {}, IP: {}/{}, MTU: {}",
|
|
config.interface_name,
|
|
config.interface_ip.addr(),
|
|
config.interface_ip.netmask(),
|
|
config.mtu
|
|
);
|
|
let device = match DeviceBuilder::new()
|
|
.name(&config.interface_name)
|
|
.ipv4(config.interface_ip.addr(), config.interface_ip.netmask(), None)
|
|
.mtu(config.mtu)
|
|
.build_async()
|
|
{
|
|
Ok(dev) => dev,
|
|
Err(e) => {
|
|
let msg = format!("Failed to create TUN interface: {:#}", e);
|
|
eprintln!("{}", msg);
|
|
return Err(anyhow::anyhow!(msg));
|
|
}
|
|
};
|
|
|
|
Ok(device)
|
|
}
|