mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-04-06 07:06:28 +00:00
Currently, only connlib's UDP sockets for sending and receiving STUN & WireGuard traffic are protected from routing loops. This is was done via the `Sockets::with_protect` function. Connlib has additional sockets though: - A TCP socket to the portal. - UDP & TCP sockets for DNS resolution via hickory. Both of these can incur routing loops on certain platforms which becomes evident as we try to implement #2667. To fix this, we generalise the idea of "protecting" a socket via a `SocketFactory` abstraction. By allowing the different platforms to provide a specialised `SocketFactory`, anything Linux-based can give special treatment to the socket before handing it to connlib. As an additional benefit, this allows us to remove the `Sockets` abstraction from connlib's API again because we can now initialise it internally via the provided `SocketFactory` for UDP sockets. --------- Signed-off-by: Gabi <gabrielalejandro7@gmail.com> Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
mod tun_device_manager;
|
|
|
|
use clap::Args;
|
|
use tracing_log::LogTracer;
|
|
use tracing_subscriber::{
|
|
fmt, prelude::__tracing_subscriber_SubscriberExt, EnvFilter, Layer, Registry,
|
|
};
|
|
use url::Url;
|
|
|
|
/// Mark for Firezone sockets to prevent routing loops on Linux.
|
|
pub const FIREZONE_MARK: u32 = 0xfd002021;
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
pub use tun_device_manager::TunDeviceManager;
|
|
|
|
pub fn setup_global_subscriber<L>(additional_layer: L)
|
|
where
|
|
L: Layer<Registry> + Send + Sync,
|
|
{
|
|
let subscriber = Registry::default()
|
|
.with(additional_layer.with_filter(EnvFilter::from_default_env()))
|
|
.with(fmt::layer().with_filter(EnvFilter::from_default_env()));
|
|
tracing::subscriber::set_global_default(subscriber).expect("Could not set global default");
|
|
LogTracer::init().unwrap();
|
|
}
|
|
|
|
/// Arguments common to all Firezone CLI components.
|
|
#[derive(Args, Clone)]
|
|
pub struct CommonArgs {
|
|
#[arg(
|
|
short = 'u',
|
|
long,
|
|
hide = true,
|
|
env = "FIREZONE_API_URL",
|
|
default_value = "wss://api.firezone.dev"
|
|
)]
|
|
pub api_url: Url,
|
|
/// Token generated by the portal to authorize websocket connection.
|
|
#[arg(env = "FIREZONE_TOKEN")]
|
|
pub token: String,
|
|
/// Friendly name to display in the UI
|
|
#[arg(short = 'n', long, env = "FIREZONE_NAME")]
|
|
pub firezone_name: Option<String>,
|
|
}
|