mirror of
https://github.com/EasyTier/EasyTier.git
synced 2024-11-16 03:32:43 +08:00
Optimize building speed (#442)
Some checks failed
EasyTier Core / pre_job (push) Has been cancelled
EasyTier GUI / pre_job (push) Has been cancelled
EasyTier Mobile / pre_job (push) Has been cancelled
EasyTier Test / pre_job (push) Has been cancelled
EasyTier Core / build (freebsd-13.2-x86_64, 13.2, ubuntu-22.04, x86_64-unknown-freebsd) (push) Has been cancelled
EasyTier Core / build (linux-aarch64, ubuntu-22.04, aarch64-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-arm, ubuntu-22.04, arm-unknown-linux-musleabi) (push) Has been cancelled
EasyTier Core / build (linux-armhf, ubuntu-22.04, arm-unknown-linux-musleabihf) (push) Has been cancelled
EasyTier Core / build (linux-armv7, ubuntu-22.04, armv7-unknown-linux-musleabi) (push) Has been cancelled
EasyTier Core / build (linux-armv7hf, ubuntu-22.04, armv7-unknown-linux-musleabihf) (push) Has been cancelled
EasyTier Core / build (linux-mips, ubuntu-22.04, mips-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-mipsel, ubuntu-22.04, mipsel-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-x86_64, ubuntu-22.04, x86_64-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (macos-aarch64, macos-latest, aarch64-apple-darwin) (push) Has been cancelled
EasyTier Core / build (macos-x86_64, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
EasyTier Core / build (windows-x86_64, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
EasyTier Core / core-result (push) Has been cancelled
EasyTier GUI / build-gui (linux-aarch64, aarch64-unknown-linux-gnu, ubuntu-22.04, aarch64-unknown-linux-musl) (push) Has been cancelled
EasyTier GUI / build-gui (linux-x86_64, x86_64-unknown-linux-gnu, ubuntu-22.04, x86_64-unknown-linux-musl) (push) Has been cancelled
EasyTier GUI / build-gui (macos-aarch64, aarch64-apple-darwin, macos-latest, aarch64-apple-darwin) (push) Has been cancelled
EasyTier GUI / build-gui (macos-x86_64, x86_64-apple-darwin, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
EasyTier GUI / build-gui (windows-x86_64, x86_64-pc-windows-msvc, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
EasyTier GUI / gui-result (push) Has been cancelled
EasyTier Mobile / build-mobile (android, ubuntu-22.04, android) (push) Has been cancelled
EasyTier Mobile / mobile-result (push) Has been cancelled
EasyTier Test / test (push) Has been cancelled
Some checks failed
EasyTier Core / pre_job (push) Has been cancelled
EasyTier GUI / pre_job (push) Has been cancelled
EasyTier Mobile / pre_job (push) Has been cancelled
EasyTier Test / pre_job (push) Has been cancelled
EasyTier Core / build (freebsd-13.2-x86_64, 13.2, ubuntu-22.04, x86_64-unknown-freebsd) (push) Has been cancelled
EasyTier Core / build (linux-aarch64, ubuntu-22.04, aarch64-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-arm, ubuntu-22.04, arm-unknown-linux-musleabi) (push) Has been cancelled
EasyTier Core / build (linux-armhf, ubuntu-22.04, arm-unknown-linux-musleabihf) (push) Has been cancelled
EasyTier Core / build (linux-armv7, ubuntu-22.04, armv7-unknown-linux-musleabi) (push) Has been cancelled
EasyTier Core / build (linux-armv7hf, ubuntu-22.04, armv7-unknown-linux-musleabihf) (push) Has been cancelled
EasyTier Core / build (linux-mips, ubuntu-22.04, mips-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-mipsel, ubuntu-22.04, mipsel-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-x86_64, ubuntu-22.04, x86_64-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (macos-aarch64, macos-latest, aarch64-apple-darwin) (push) Has been cancelled
EasyTier Core / build (macos-x86_64, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
EasyTier Core / build (windows-x86_64, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
EasyTier Core / core-result (push) Has been cancelled
EasyTier GUI / build-gui (linux-aarch64, aarch64-unknown-linux-gnu, ubuntu-22.04, aarch64-unknown-linux-musl) (push) Has been cancelled
EasyTier GUI / build-gui (linux-x86_64, x86_64-unknown-linux-gnu, ubuntu-22.04, x86_64-unknown-linux-musl) (push) Has been cancelled
EasyTier GUI / build-gui (macos-aarch64, aarch64-apple-darwin, macos-latest, aarch64-apple-darwin) (push) Has been cancelled
EasyTier GUI / build-gui (macos-x86_64, x86_64-apple-darwin, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
EasyTier GUI / build-gui (windows-x86_64, x86_64-pc-windows-msvc, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
EasyTier GUI / gui-result (push) Has been cancelled
EasyTier Mobile / build-mobile (android, ubuntu-22.04, android) (push) Has been cancelled
EasyTier Mobile / mobile-result (push) Has been cancelled
EasyTier Test / test (push) Has been cancelled
Make easytier-cli and easytier-core link to the easytier library to avoid duplicate linking of mods.
This commit is contained in:
parent
efee3707da
commit
b5c3726e67
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,6 +11,7 @@ target-*/
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
|
/.idea
|
||||||
|
|
||||||
# perf & flamegraph
|
# perf & flamegraph
|
||||||
perf.data
|
perf.data
|
||||||
|
|
|
@ -21,12 +21,10 @@ path = "src/easytier-core.rs"
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "easytier-cli"
|
name = "easytier-cli"
|
||||||
path = "src/easytier-cli.rs"
|
path = "src/easytier-cli.rs"
|
||||||
test = false
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "easytier"
|
name = "easytier"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
test = false
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
git-version = "0.3.9"
|
git-version = "0.3.9"
|
||||||
|
|
|
@ -147,7 +147,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.type_attribute("peer_rpc.ForeignNetworkRouteInfoKey", "#[derive(Hash, Eq)]")
|
.type_attribute("peer_rpc.ForeignNetworkRouteInfoKey", "#[derive(Hash, Eq)]")
|
||||||
.type_attribute("common.RpcDescriptor", "#[derive(Hash, Eq)]")
|
.type_attribute("common.RpcDescriptor", "#[derive(Hash, Eq)]")
|
||||||
.service_generator(Box::new(rpc_build::ServiceGenerator::new()))
|
.service_generator(Box::new(rpc_build::ServiceGenerator::new()))
|
||||||
.btree_map(&["."])
|
.btree_map(["."])
|
||||||
.compile_protos(&proto_files, &["src/proto/"])
|
.compile_protos(&proto_files, &["src/proto/"])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,29 @@
|
||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use std::{net::SocketAddr, sync::Mutex, time::Duration, vec};
|
use std::{net::SocketAddr, sync::Mutex, time::Duration, vec};
|
||||||
|
|
||||||
use anyhow::{Context, Ok};
|
use anyhow::{Context, Ok};
|
||||||
use clap::{command, Args, Parser, Subcommand};
|
use clap::{command, Args, Parser, Subcommand};
|
||||||
use common::{constants::EASYTIER_VERSION, stun::StunInfoCollectorTrait};
|
|
||||||
use proto::{
|
|
||||||
common::NatType,
|
|
||||||
peer_rpc::{GetGlobalPeerMapRequest, PeerCenterRpc, PeerCenterRpcClientFactory},
|
|
||||||
rpc_impl::standalone::StandAloneClient,
|
|
||||||
rpc_types::controller::BaseController,
|
|
||||||
};
|
|
||||||
use tokio::time::timeout;
|
|
||||||
use tunnel::tcp::TcpTunnelConnector;
|
|
||||||
use utils::{list_peer_route_pair, PeerRoutePair};
|
|
||||||
|
|
||||||
mod arch;
|
|
||||||
mod common;
|
|
||||||
mod proto;
|
|
||||||
mod tunnel;
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
common::stun::StunInfoCollector,
|
|
||||||
proto::cli::*,
|
|
||||||
utils::{cost_to_str, float_to_str},
|
|
||||||
};
|
|
||||||
use humansize::format_size;
|
use humansize::format_size;
|
||||||
use tabled::settings::Style;
|
use tabled::settings::Style;
|
||||||
|
use tokio::time::timeout;
|
||||||
|
|
||||||
|
use easytier::{
|
||||||
|
common::{constants::EASYTIER_VERSION, stun::StunInfoCollector, stun::StunInfoCollectorTrait},
|
||||||
|
proto::{
|
||||||
|
cli::{
|
||||||
|
ConnectorManageRpc, ConnectorManageRpcClientFactory, DumpRouteRequest,
|
||||||
|
GetVpnPortalInfoRequest, ListConnectorRequest, ListForeignNetworkRequest,
|
||||||
|
ListGlobalForeignNetworkRequest, ListPeerRequest, ListPeerResponse, ListRouteRequest,
|
||||||
|
ListRouteResponse, NodeInfo, PeerManageRpc, PeerManageRpcClientFactory,
|
||||||
|
ShowNodeInfoRequest, VpnPortalRpc, VpnPortalRpcClientFactory,
|
||||||
|
},
|
||||||
|
common::NatType,
|
||||||
|
peer_rpc::{GetGlobalPeerMapRequest, PeerCenterRpc, PeerCenterRpcClientFactory},
|
||||||
|
rpc_impl::standalone::StandAloneClient,
|
||||||
|
rpc_types::controller::BaseController,
|
||||||
|
},
|
||||||
|
tunnel::tcp::TcpTunnelConnector,
|
||||||
|
utils::{cost_to_str, float_to_str, list_peer_route_pair, PeerRoutePair},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(name = "easytier-cli", author, version = EASYTIER_VERSION, about, long_about = None)]
|
#[command(name = "easytier-cli", author, version = EASYTIER_VERSION, about, long_about = None)]
|
||||||
|
@ -230,7 +226,6 @@ impl CommandHandler {
|
||||||
ipv4: p
|
ipv4: p
|
||||||
.route
|
.route
|
||||||
.ipv4_addr
|
.ipv4_addr
|
||||||
.clone()
|
|
||||||
.map(|ip| ip.to_string())
|
.map(|ip| ip.to_string())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
hostname: p.route.hostname.clone(),
|
hostname: p.route.hostname.clone(),
|
||||||
|
@ -239,7 +234,7 @@ impl CommandHandler {
|
||||||
loss_rate: float_to_str(p.get_loss_rate().unwrap_or(0.0), 3),
|
loss_rate: float_to_str(p.get_loss_rate().unwrap_or(0.0), 3),
|
||||||
rx_bytes: format_size(p.get_rx_bytes().unwrap_or(0), humansize::DECIMAL),
|
rx_bytes: format_size(p.get_rx_bytes().unwrap_or(0), humansize::DECIMAL),
|
||||||
tx_bytes: format_size(p.get_tx_bytes().unwrap_or(0), humansize::DECIMAL),
|
tx_bytes: format_size(p.get_tx_bytes().unwrap_or(0), humansize::DECIMAL),
|
||||||
tunnel_proto: p.get_conn_protos().unwrap_or(vec![]).join(",").to_string(),
|
tunnel_proto: p.get_conn_protos().unwrap_or_default().join(",").to_string(),
|
||||||
nat_type: p.get_udp_nat_type(),
|
nat_type: p.get_udp_nat_type(),
|
||||||
id: p.route.peer_id.to_string(),
|
id: p.route.peer_id.to_string(),
|
||||||
version: if p.route.version.is_empty() {
|
version: if p.route.version.is_empty() {
|
||||||
|
@ -294,7 +289,7 @@ impl CommandHandler {
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
tabled::Table::new(items).with(Style::modern()).to_string()
|
tabled::Table::new(items).with(Style::modern())
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -421,7 +416,6 @@ impl CommandHandler {
|
||||||
ipv4: p
|
ipv4: p
|
||||||
.route
|
.route
|
||||||
.ipv4_addr
|
.ipv4_addr
|
||||||
.clone()
|
|
||||||
.map(|ip| ip.to_string())
|
.map(|ip| ip.to_string())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
hostname: p.route.hostname.clone(),
|
hostname: p.route.hostname.clone(),
|
||||||
|
@ -441,7 +435,6 @@ impl CommandHandler {
|
||||||
ipv4: p
|
ipv4: p
|
||||||
.route
|
.route
|
||||||
.ipv4_addr
|
.ipv4_addr
|
||||||
.clone()
|
|
||||||
.map(|ip| ip.to_string())
|
.map(|ip| ip.to_string())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
hostname: p.route.hostname.clone(),
|
hostname: p.route.hostname.clone(),
|
||||||
|
@ -449,7 +442,6 @@ impl CommandHandler {
|
||||||
next_hop_ipv4: next_hop_pair
|
next_hop_ipv4: next_hop_pair
|
||||||
.route
|
.route
|
||||||
.ipv4_addr
|
.ipv4_addr
|
||||||
.clone()
|
|
||||||
.map(|ip| ip.to_string())
|
.map(|ip| ip.to_string())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
next_hop_hostname: next_hop_pair.route.hostname.clone(),
|
next_hop_hostname: next_hop_pair.route.hostname.clone(),
|
||||||
|
@ -466,7 +458,7 @@ impl CommandHandler {
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
tabled::Table::new(items).with(Style::modern()).to_string()
|
tabled::Table::new(items).with(Style::modern())
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -588,7 +580,6 @@ async fn main() -> Result<(), Error> {
|
||||||
"{}",
|
"{}",
|
||||||
tabled::Table::new(table_rows)
|
tabled::Table::new(table_rows)
|
||||||
.with(Style::modern())
|
.with(Style::modern())
|
||||||
.to_string()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
SubCommand::VpnPortal => {
|
SubCommand::VpnPortal => {
|
||||||
|
@ -643,7 +634,7 @@ async fn main() -> Result<(), Error> {
|
||||||
builder.push_record(vec![format!("Listener {}", idx).as_str(), l]);
|
builder.push_record(vec![format!("Listener {}", idx).as_str(), l]);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{}", builder.build().with(Style::modern()).to_string());
|
println!("{}", builder.build().with(Style::modern()));
|
||||||
}
|
}
|
||||||
Some(NodeSubCommand::Config) => {
|
Some(NodeSubCommand::Config) => {
|
||||||
println!("{}", node_info.config);
|
println!("{}", node_info.config);
|
||||||
|
|
|
@ -1,51 +1,31 @@
|
||||||
#![allow(dead_code)]
|
#[macro_use]
|
||||||
|
extern crate rust_i18n;
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
net::{Ipv4Addr, SocketAddr},
|
net::{Ipv4Addr, SocketAddr},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate rust_i18n;
|
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
mod arch;
|
|
||||||
mod common;
|
|
||||||
mod connector;
|
|
||||||
mod gateway;
|
|
||||||
mod instance;
|
|
||||||
mod launcher;
|
|
||||||
mod peer_center;
|
|
||||||
mod peers;
|
|
||||||
mod proto;
|
|
||||||
mod tunnel;
|
|
||||||
mod utils;
|
|
||||||
mod vpn_portal;
|
|
||||||
|
|
||||||
use common::{
|
|
||||||
config::{ConsoleLoggerConfig, FileLoggerConfig, NetworkIdentity, PeerConfig, VpnPortalConfig},
|
|
||||||
constants::EASYTIER_VERSION,
|
|
||||||
global_ctx::EventBusSubscriber,
|
|
||||||
scoped_task::ScopedTask,
|
|
||||||
};
|
|
||||||
use tokio::net::TcpSocket;
|
use tokio::net::TcpSocket;
|
||||||
use utils::setup_panic_handler;
|
|
||||||
|
|
||||||
use crate::{
|
use easytier::{
|
||||||
common::{
|
common::{
|
||||||
config::{ConfigLoader, TomlConfigLoader},
|
config::{
|
||||||
global_ctx::GlobalCtxEvent,
|
ConfigLoader, ConsoleLoggerConfig, FileLoggerConfig, NetworkIdentity, PeerConfig,
|
||||||
|
TomlConfigLoader, VpnPortalConfig,
|
||||||
|
},
|
||||||
|
constants::EASYTIER_VERSION,
|
||||||
|
global_ctx::{EventBusSubscriber, GlobalCtxEvent},
|
||||||
|
scoped_task::ScopedTask,
|
||||||
},
|
},
|
||||||
utils::init_logger,
|
launcher, proto,
|
||||||
|
utils::{init_logger, setup_panic_handler},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "mimalloc")]
|
#[cfg(feature = "mimalloc")]
|
||||||
use mimalloc_rust::*;
|
use mimalloc_rust::GlobalMiMalloc;
|
||||||
|
|
||||||
#[cfg(feature = "mimalloc")]
|
#[cfg(feature = "mimalloc")]
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
|
@ -509,7 +489,7 @@ impl From<Cli> for TomlConfigLoader {
|
||||||
f.enable_encryption = !cli.disable_encryption;
|
f.enable_encryption = !cli.disable_encryption;
|
||||||
f.enable_ipv6 = !cli.disable_ipv6;
|
f.enable_ipv6 = !cli.disable_ipv6;
|
||||||
f.latency_first = cli.latency_first;
|
f.latency_first = cli.latency_first;
|
||||||
f.dev_name = cli.dev_name.unwrap_or(Default::default());
|
f.dev_name = cli.dev_name.unwrap_or_default();
|
||||||
if let Some(mtu) = cli.mtu {
|
if let Some(mtu) = cli.mtu {
|
||||||
f.mtu = mtu;
|
f.mtu = mtu;
|
||||||
}
|
}
|
||||||
|
@ -544,7 +524,7 @@ fn print_event(msg: String) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn peer_conn_info_to_string(p: crate::proto::cli::PeerConnInfo) -> String {
|
fn peer_conn_info_to_string(p: proto::cli::PeerConnInfo) -> String {
|
||||||
format!(
|
format!(
|
||||||
"my_peer_id: {}, dst_peer_id: {}, tunnel_info: {:?}",
|
"my_peer_id: {}, dst_peer_id: {}, tunnel_info: {:?}",
|
||||||
p.my_peer_id, p.peer_id, p.tunnel
|
p.my_peer_id, p.peer_id, p.tunnel
|
||||||
|
|
|
@ -5,13 +5,16 @@ mod connector;
|
||||||
mod gateway;
|
mod gateway;
|
||||||
mod instance;
|
mod instance;
|
||||||
mod peer_center;
|
mod peer_center;
|
||||||
mod peers;
|
|
||||||
mod vpn_portal;
|
mod vpn_portal;
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod launcher;
|
pub mod launcher;
|
||||||
|
pub mod peers;
|
||||||
pub mod proto;
|
pub mod proto;
|
||||||
pub mod tunnel;
|
pub mod tunnel;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
pub const VERSION: &str = common::constants::EASYTIER_VERSION;
|
pub const VERSION: &str = common::constants::EASYTIER_VERSION;
|
||||||
|
|
|
@ -6,4 +6,5 @@ pub mod common;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod peer_rpc;
|
pub mod peer_rpc;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::common::PeerId;
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
mod three_node;
|
mod three_node;
|
||||||
|
|
||||||
|
use crate::common::PeerId;
|
||||||
|
use crate::peers::peer_manager::PeerManager;
|
||||||
|
|
||||||
pub fn get_guest_veth_name(net_ns: &str) -> &str {
|
pub fn get_guest_veth_name(net_ns: &str) -> &str {
|
||||||
Box::leak(format!("veth_{}_g", net_ns).into_boxed_str())
|
Box::leak(format!("veth_{}_g", net_ns).into_boxed_str())
|
||||||
}
|
}
|
||||||
|
@ -14,29 +15,29 @@ pub fn get_host_veth_name(net_ns: &str) -> &str {
|
||||||
pub fn del_netns(name: &str) {
|
pub fn del_netns(name: &str) {
|
||||||
// del veth host
|
// del veth host
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&["link", "del", get_host_veth_name(name)])
|
.args(["link", "del", get_host_veth_name(name)])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&["netns", "del", name])
|
.args(["netns", "del", name])
|
||||||
.output();
|
.output();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_netns(name: &str, ipv4: &str) {
|
pub fn create_netns(name: &str, ipv4: &str) {
|
||||||
// create netns
|
// create netns
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&["netns", "add", name])
|
.args(["netns", "add", name])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// set lo up
|
// set lo up
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&["netns", "exec", name, "ip", "link", "set", "lo", "up"])
|
.args(["netns", "exec", name, "ip", "link", "set", "lo", "up"])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&[
|
.args([
|
||||||
"link",
|
"link",
|
||||||
"add",
|
"add",
|
||||||
get_host_veth_name(name),
|
get_host_veth_name(name),
|
||||||
|
@ -50,12 +51,12 @@ pub fn create_netns(name: &str, ipv4: &str) {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&["link", "set", get_guest_veth_name(name), "netns", name])
|
.args(["link", "set", get_guest_veth_name(name), "netns", name])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&[
|
.args([
|
||||||
"netns",
|
"netns",
|
||||||
"exec",
|
"exec",
|
||||||
name,
|
name,
|
||||||
|
@ -69,12 +70,12 @@ pub fn create_netns(name: &str, ipv4: &str) {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&["link", "set", get_host_veth_name(name), "up"])
|
.args(["link", "set", get_host_veth_name(name), "up"])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&[
|
.args([
|
||||||
"netns",
|
"netns",
|
||||||
"exec",
|
"exec",
|
||||||
name,
|
name,
|
||||||
|
@ -92,25 +93,25 @@ pub fn create_netns(name: &str, ipv4: &str) {
|
||||||
pub fn prepare_bridge(name: &str) {
|
pub fn prepare_bridge(name: &str) {
|
||||||
// del bridge with brctl
|
// del bridge with brctl
|
||||||
let _ = std::process::Command::new("brctl")
|
let _ = std::process::Command::new("brctl")
|
||||||
.args(&["delbr", name])
|
.args(["delbr", name])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
// create new br
|
// create new br
|
||||||
let _ = std::process::Command::new("brctl")
|
let _ = std::process::Command::new("brctl")
|
||||||
.args(&["addbr", name])
|
.args(["addbr", name])
|
||||||
.output();
|
.output();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_ns_to_bridge(br_name: &str, ns_name: &str) {
|
pub fn add_ns_to_bridge(br_name: &str, ns_name: &str) {
|
||||||
// use brctl to add ns to bridge
|
// use brctl to add ns to bridge
|
||||||
let _ = std::process::Command::new("brctl")
|
let _ = std::process::Command::new("brctl")
|
||||||
.args(&["addif", br_name, get_host_veth_name(ns_name)])
|
.args(["addif", br_name, get_host_veth_name(ns_name)])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// set bridge up
|
// set bridge up
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&["link", "set", br_name, "up"])
|
.args(["link", "set", br_name, "up"])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -143,7 +144,7 @@ fn check_route(ipv4: &str, dst_peer_id: PeerId, routes: Vec<crate::proto::cli::R
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_proxy_route_appear(
|
async fn wait_proxy_route_appear(
|
||||||
mgr: &std::sync::Arc<crate::peers::peer_manager::PeerManager>,
|
mgr: &std::sync::Arc<PeerManager>,
|
||||||
ipv4: &str,
|
ipv4: &str,
|
||||||
dst_peer_id: PeerId,
|
dst_peer_id: PeerId,
|
||||||
proxy_cidr: &str,
|
proxy_cidr: &str,
|
||||||
|
@ -167,7 +168,7 @@ async fn wait_proxy_route_appear(
|
||||||
|
|
||||||
fn set_link_status(net_ns: &str, up: bool) {
|
fn set_link_status(net_ns: &str, up: bool) {
|
||||||
let _ = std::process::Command::new("ip")
|
let _ = std::process::Command::new("ip")
|
||||||
.args(&[
|
.args([
|
||||||
"netns",
|
"netns",
|
||||||
"exec",
|
"exec",
|
||||||
net_ns,
|
net_ns,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user