-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #237 from jamesmcm/cloudflare_warp
Add Cloudflare Warp support
- Loading branch information
Showing
11 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use super::Provider; | ||
use crate::config::vpn::Protocol; | ||
|
||
pub struct Warp {} | ||
|
||
impl Provider for Warp { | ||
fn alias(&self) -> String { | ||
"warp".to_string() | ||
} | ||
|
||
fn alias_2char(&self) -> String { | ||
"wp".to_string() | ||
} | ||
|
||
fn default_protocol(&self) -> Protocol { | ||
Protocol::Warp | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ pub enum Protocol { | |
Wireguard, | ||
OpenConnect, | ||
OpenFortiVpn, | ||
Warp, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ pub mod openvpn; | |
pub mod shadowsocks; | ||
pub mod sysctl; | ||
pub mod veth_pair; | ||
pub mod warp; | ||
pub mod wireguard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use super::firewall::Firewall; | ||
use super::netns::NetworkNamespace; | ||
use anyhow::{anyhow, Context}; | ||
use log::{debug, error, info}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
// Cloudflare Warp | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct Warp { | ||
pid: u32, | ||
} | ||
|
||
impl Warp { | ||
#[allow(clippy::too_many_arguments)] | ||
pub fn run( | ||
netns: &NetworkNamespace, | ||
open_ports: Option<&Vec<u16>>, | ||
forward_ports: Option<&Vec<u16>>, | ||
firewall: Firewall, | ||
) -> anyhow::Result<Self> { | ||
// TODO: Add Killswitch using - https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp/deployment/firewall/ | ||
|
||
if let Err(x) = which::which("warp-svc") { | ||
error!("Cloudflare Warp warp-svc not found. Is warp-svc installed and on PATH?"); | ||
return Err(anyhow!( | ||
"warp-svc not found. Is warp-svc installed and on PATH?: {:?}", | ||
x | ||
)); | ||
} | ||
|
||
info!("Launching Warp..."); | ||
|
||
let handle = netns | ||
.exec_no_block(&["warp-svc"], None, None, false, false, false, None) | ||
.context("Failed to launch warp-svc - is waro-svc installed?")?; | ||
|
||
let id = handle.id(); | ||
|
||
// Allow input to and output from open ports (for port forwarding in tunnel) | ||
if let Some(opens) = open_ports { | ||
crate::util::open_ports(netns, opens.as_slice(), firewall)?; | ||
} | ||
|
||
// Allow input to and output from forwarded ports | ||
if let Some(forwards) = forward_ports { | ||
crate::util::open_ports(netns, forwards.as_slice(), firewall)?; | ||
} | ||
|
||
Ok(Self { pid: id }) | ||
} | ||
} | ||
|
||
impl Drop for Warp { | ||
fn drop(&mut self) { | ||
match nix::sys::signal::kill( | ||
nix::unistd::Pid::from_raw(self.pid as i32), | ||
nix::sys::signal::Signal::SIGKILL, | ||
) { | ||
Ok(_) => debug!("Killed warp-svc (pid: {})", self.pid), | ||
Err(e) => error!("Failed to kill warp-svc (pid: {}): {:?}", self.pid, e), | ||
} | ||
} | ||
} |