diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-04-13 13:25:29 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-04-13 13:25:29 +0200 |
| commit | 625424d8832f1f43349659c1a5ed596c43be07e3 (patch) | |
| tree | 3a0025e89ca42b01856a442769dc0f991a141a74 /mullvad-cli/src | |
| parent | 0c14965d8cd012bb6c356ee85d4c505833a9023d (diff) | |
| parent | 4c9065da457998f3a707153ad6b8e0494755333b (diff) | |
| download | mullvadvpn-625424d8832f1f43349659c1a5ed596c43be07e3.tar.xz mullvadvpn-625424d8832f1f43349659c1a5ed596c43be07e3.zip | |
Merge branch 'wg-over-tcp'
Diffstat (limited to 'mullvad-cli/src')
| -rw-r--r-- | mullvad-cli/src/cmds/relay.rs | 96 | ||||
| -rw-r--r-- | mullvad-cli/src/format.rs | 8 |
2 files changed, 54 insertions, 50 deletions
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs index 6343b9e5d5..6aa2ea5f2c 100644 --- a/mullvad-cli/src/cmds/relay.rs +++ b/mullvad-cli/src/cmds/relay.rs @@ -44,72 +44,71 @@ impl Command for Relay { .arg( clap::Arg::with_name("host") .help("Hostname or IP") - .required(true) - .index(1), + .required(true), ) .arg( clap::Arg::with_name("port") .help("Remote network port") - .required(true) - .index(2), + .required(true), ) .arg( - clap::Arg::with_name("peer-key") + clap::Arg::with_name("peer-pubkey") .help("Base64 encoded peer public key") - .index(3) - .required(false), + .required(true), ) .arg( clap::Arg::with_name("v4-gateway") .help("IPv4 gateway address") - .long("v4-gateway") - .index(4) - .required(false), - ).arg( - clap::Arg::with_name("v6-gateway") - .help("IPv6 gateway address") - .long("v6-gateway") - .takes_value(true) - .required(false), + .required(true), ) .arg( clap::Arg::with_name("addr") .help("Local address of wireguard tunnel") - .long("addr") - .takes_value(true) - .multiple(true) - .required(false), - ), + .required(true) + .multiple(true), + ) + .arg( + clap::Arg::with_name("protocol") + .help("Transport protocol. If TCP is selected, traffic is \ + sent over TCP using a udp-over-tcp proxy") + .long("protocol") + .default_value("udp") + .possible_values(&["udp", "tcp"]), + ) + .arg( + clap::Arg::with_name("v6-gateway") + .help("IPv6 gateway address") + .long("v6-gateway") + .takes_value(true), + ) ) .subcommand(clap::SubCommand::with_name("openvpn") .arg( clap::Arg::with_name("host") .help("Hostname or IP") - .required(true) - .index(1), + .required(true), ) .arg( clap::Arg::with_name("port") .help("Remote network port") - .required(true) - .index(2), - ) - .arg( - clap::Arg::with_name("protocol") - .help("Transport protocol. For Wireguard this is ignored.") - .index(3) - .default_value("udp") - .possible_values(&["udp", "tcp"]), + .required(true), ) .arg( clap::Arg::with_name("username") .help("Username to be used with the OpenVpn relay") - .index(4), + .required(true), ) .arg( clap::Arg::with_name("password") .help("Password to be used with the OpenVpn relay") - .index(5), + .required(true), + ) + .arg( + clap::Arg::with_name("protocol") + .help("Transport protocol") + .long("protocol") + .default_value("udp") + .possible_values(&["udp", "tcp"]), ) ) ) @@ -152,14 +151,12 @@ impl Command for Relay { .arg( clap::Arg::with_name("transport protocol") .long("protocol") - .required(false) .default_value("any") .possible_values(&["any", "udp", "tcp"]), ) .arg( clap::Arg::with_name("ip version") .long("ipv") - .required(false) .default_value("any") .possible_values(&["any", "4", "6"]), ), @@ -248,15 +245,7 @@ impl Relay { let password = value_t!(matches.value_of("password"), String).unwrap_or_else(|e| e.exit()); let protocol = value_t!(matches.value_of("protocol"), String).unwrap_or_else(|e| e.exit()); - let protocol = match protocol.as_str() { - "udp" => TransportProtocol::Udp, - "tcp" => TransportProtocol::Tcp, - _ => clap::Error::with_description( - "unknown transport protocol", - clap::ErrorKind::ValueValidation, - ) - .exit(), - }; + let protocol = Self::validate_transport_protocol(&protocol); CustomRelaySettings { host, @@ -278,7 +267,7 @@ impl Relay { let port = value_t!(matches.value_of("port"), u16).unwrap_or_else(|e| e.exit()); let addresses = values_t!(matches.values_of("addr"), IpAddr).unwrap_or_else(|e| e.exit()); let peer_key_str = - value_t!(matches.value_of("peer-key"), String).unwrap_or_else(|e| e.exit()); + value_t!(matches.value_of("peer-pubkey"), String).unwrap_or_else(|e| e.exit()); let ipv4_gateway = value_t!(matches.value_of("v4-gateway"), Ipv4Addr).unwrap_or_else(|e| e.exit()); let ipv6_gateway = match value_t!(matches.value_of("v6-gateway"), Ipv6Addr) { @@ -288,6 +277,8 @@ impl Relay { _ => e.exit(), }, }; + let protocol = value_t!(matches.value_of("protocol"), String).unwrap_or_else(|e| e.exit()); + let protocol = Self::validate_transport_protocol(&protocol); let mut private_key_str = String::new(); println!("Reading private key from standard input"); let _ = io::stdin().lock().read_line(&mut private_key_str); @@ -316,6 +307,7 @@ impl Relay { .collect(), endpoint: SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), port) .to_string(), + protocol: protocol as i32, }), ipv4_gateway: ipv4_gateway.to_string(), ipv6_gateway: ipv6_gateway @@ -346,6 +338,18 @@ impl Relay { key } + fn validate_transport_protocol(protocol: &str) -> TransportProtocol { + match protocol { + "udp" => TransportProtocol::Udp, + "tcp" => TransportProtocol::Tcp, + _ => clap::Error::with_description( + "invalid transport protocol", + clap::ErrorKind::ValueValidation, + ) + .exit(), + } + } + async fn set_hostname(&self, matches: &clap::ArgMatches<'_>) -> Result<()> { let hostname = matches.value_of("hostname").unwrap(); let countries = Self::get_filtered_relays().await?; diff --git a/mullvad-cli/src/format.rs b/mullvad-cli/src/format.rs index 7070e322ac..250bc70ba7 100644 --- a/mullvad-cli/src/format.rs +++ b/mullvad-cli/src/format.rs @@ -59,13 +59,13 @@ pub fn print_state(state: &TunnelState) { fn format_endpoint(endpoint: &TunnelEndpoint) -> String { let mut out = format!( "{} {} over {}", - match TunnelType::from_i32(endpoint.tunnel_type).expect("unknown tunnel protocol") { + match TunnelType::from_i32(endpoint.tunnel_type).expect("invalid tunnel protocol") { TunnelType::Wireguard => "WireGuard", TunnelType::Openvpn => "OpenVPN", }, endpoint.address, format_protocol( - TransportProtocol::from_i32(endpoint.protocol).expect("unknown transport protocol") + TransportProtocol::from_i32(endpoint.protocol).expect("invalid transport protocol") ), ); @@ -73,13 +73,13 @@ fn format_endpoint(endpoint: &TunnelEndpoint) -> String { write!( &mut out, " via {} {} over {}", - match ProxyType::from_i32(proxy.proxy_type).expect("unknown proxy type") { + match ProxyType::from_i32(proxy.proxy_type).expect("invalid proxy type") { ProxyType::Shadowsocks => "Shadowsocks", ProxyType::Custom => "custom bridge", }, proxy.address, format_protocol( - TransportProtocol::from_i32(proxy.protocol).expect("unknown transport protocol") + TransportProtocol::from_i32(proxy.protocol).expect("invalid transport protocol") ), ) .unwrap(); |
