Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved netns name generation #214

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,18 @@ pub fn exec(command: ExecCommand, uiclient: &dyn UiClient) -> anyhow::Result<()>

let alias = match provider {
VpnProvider::Custom => "c".to_string(),
_ => provider.get_dyn_provider().alias(),
_ => provider.get_dyn_provider().alias_2char(),
};

let ns_name = if let Some(c_ns_name) = custom_netns_name {
c_ns_name
} else {
format!("vopono_{alias}_{server_name}")
let short_name = if server_name.len() > 7 {
bs58::encode(&server_name).into_string()[0..7].to_string()
} else {
server_name.clone()
};
format!("vo_{alias}_{short_name}")
};

let mut ns;
Expand Down
4 changes: 4 additions & 0 deletions vopono_core/src/config/providers/airvpn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ impl Provider for AirVPN {
"air".to_string()
}

fn alias_2char(&self) -> String {
"ar".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::OpenVpn
}
Expand Down
4 changes: 4 additions & 0 deletions vopono_core/src/config/providers/azirevpn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl Provider for AzireVPN {
fn alias(&self) -> String {
"azire".to_string()
}
fn alias_2char(&self) -> String {
"az".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::Wireguard
}
Expand Down
4 changes: 4 additions & 0 deletions vopono_core/src/config/providers/hma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ impl Provider for HMA {
"hma".to_string()
}

fn alias_2char(&self) -> String {
"hm".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::OpenVpn
}
Expand Down
4 changes: 4 additions & 0 deletions vopono_core/src/config/providers/ivpn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ impl Provider for IVPN {
"ivpn".to_string()
}

fn alias_2char(&self) -> String {
"iv".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::Wireguard
}
Expand Down
2 changes: 2 additions & 0 deletions vopono_core/src/config/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ impl VpnProvider {
pub trait Provider {
fn alias(&self) -> String;

fn alias_2char(&self) -> String;

fn default_protocol(&self) -> Protocol;

fn provider_dir(&self) -> anyhow::Result<PathBuf> {
Expand Down
5 changes: 5 additions & 0 deletions vopono_core/src/config/providers/mozilla/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ impl Provider for MozillaVPN {
fn alias(&self) -> String {
"mozilla".to_string()
}

fn alias_2char(&self) -> String {
"mz".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::Wireguard
}
Expand Down
5 changes: 5 additions & 0 deletions vopono_core/src/config/providers/mullvad/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ impl Provider for Mullvad {
fn alias(&self) -> String {
"mv".to_string()
}

fn alias_2char(&self) -> String {
"mv".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::Wireguard
}
Expand Down
4 changes: 4 additions & 0 deletions vopono_core/src/config/providers/nordvpn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ impl Provider for NordVPN {
"nordvpn".to_string()
}

fn alias_2char(&self) -> String {
"nd".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::OpenVpn
}
Expand Down
4 changes: 4 additions & 0 deletions vopono_core/src/config/providers/pia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ impl Provider for PrivateInternetAccess {
"pia".to_string()
}

fn alias_2char(&self) -> String {
"pi".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::OpenVpn
}
Expand Down
4 changes: 4 additions & 0 deletions vopono_core/src/config/providers/protonvpn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ impl Provider for ProtonVPN {
"proton".to_string()
}

fn alias_2char(&self) -> String {
"pr".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::OpenVpn
}
Expand Down
4 changes: 4 additions & 0 deletions vopono_core/src/config/providers/tigervpn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ impl Provider for TigerVPN {
"tig".to_string()
}

fn alias_2char(&self) -> String {
"ti".to_string()
}

fn default_protocol(&self) -> Protocol {
Protocol::OpenVpn
}
Expand Down
6 changes: 2 additions & 4 deletions vopono_core/src/network/netns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ impl NetworkNamespace {

pub fn add_veth_pair(&mut self) -> anyhow::Result<()> {
// TODO: Handle if name taken?
// Use bs58 here?
let basename = &self.name[((self.name.len() as i32) - 13).max(0) as usize..self.name.len()];
let source = format!("{basename}_s");
let dest = format!("{basename}_d");
let source = format!("{}_s", self.name);
let dest = format!("{}_d", self.name);
self.veth_pair = Some(VethPair::new(source, dest, self)?);
Ok(())
}
Expand Down