chore: Unify enable_wg_broker and enable_broker_api features

This commit is contained in:
Katherine Watson
2024-08-11 21:20:46 -07:00
parent 065b0fcc8a
commit 274d245bed
7 changed files with 20 additions and 22 deletions

View File

@@ -53,7 +53,7 @@ zeroize = { workspace = true }
hex-literal = { workspace = true, optional = true } hex-literal = { workspace = true, optional = true }
hex = { workspace = true, optional = true } hex = { workspace = true, optional = true }
heck = { workspace = true, optional = true } heck = { workspace = true, optional = true }
command-fds = { workspace = true } command-fds = { workspace = true, optional = true }
rustix = { workspace = true } rustix = { workspace = true }
[build-dependencies] [build-dependencies]
@@ -68,9 +68,8 @@ procspawn = {workspace = true}
tempfile = { workspace = true } tempfile = { workspace = true }
[features] [features]
enable_wg_broker = ["enable_broker_api"]
enable_broker_api = ["rosenpass-wireguard-broker/enable_broker_api"]
experiment_memfd_secret = [] experiment_memfd_secret = []
experiment_broker_api = ["rosenpass-wireguard-broker/experimental_broker_api", "command-fds"]
experiment_libcrux = ["rosenpass-ciphers/experiment_libcrux"] experiment_libcrux = ["rosenpass-ciphers/experiment_libcrux"]
experiment_api = ["hex-literal"] experiment_api = ["hex-literal"]
internal_testing = [] internal_testing = []

View File

@@ -17,7 +17,7 @@ use crate::protocol::{SPk, SSk, SymKey};
use super::config; use super::config;
#[cfg(feature = "enable_wg_broker")] #[cfg(feature = "experiment_broker_api")]
use { use {
command_fds::{CommandFdExt, FdMapping}, command_fds::{CommandFdExt, FdMapping},
log::{error, info}, log::{error, info},
@@ -60,7 +60,7 @@ pub struct CliArgs {
api: crate::api::cli::ApiCli, api: crate::api::cli::ApiCli,
/// path of the wireguard_psk broker socket to connect to /// path of the wireguard_psk broker socket to connect to
#[cfg(feature = "enable_wg_broker")] #[cfg(feature = "experiment_broker_api")]
#[arg(long, group = "psk-broker-specs")] #[arg(long, group = "psk-broker-specs")]
psk_broker_path: Option<PathBuf>, psk_broker_path: Option<PathBuf>,
@@ -70,12 +70,12 @@ pub struct CliArgs {
/// Unix socket for the psk broker connection to use themselves, passing it to this process -- /// Unix socket for the psk broker connection to use themselves, passing it to this process --
/// in Rust this can be achieved using the /// in Rust this can be achieved using the
/// [command-fds](https://docs.rs/command-fds/latest/command_fds/) crate /// [command-fds](https://docs.rs/command-fds/latest/command_fds/) crate
#[cfg(feature = "enable_wg_broker")] #[cfg(feature = "experiment_broker_api")]
#[arg(long, group = "psk-broker-specs")] #[arg(long, group = "psk-broker-specs")]
psk_broker_fd: Option<i32>, psk_broker_fd: Option<i32>,
/// spawn a psk broker locally using a socket pair /// spawn a psk broker locally using a socket pair
#[cfg(feature = "enable_wg_broker")] #[cfg(feature = "experiment_broker_api")]
#[arg(short, long, group = "psk-broker-specs")] #[arg(short, long, group = "psk-broker-specs")]
psk_broker_spawn: bool, psk_broker_spawn: bool,
@@ -109,9 +109,9 @@ impl CliArgs {
None None
} }
#[cfg(feature = "enable_wg_broker")] #[cfg(feature = "experiment_broker_api")]
/// returns the broker interface set by CLI args /// returns the broker interface set by CLI args
/// returns `None` if the `enable_wg_broker` feature isn't enabled /// returns `None` if the `experiment_broker_api` feature isn't enabled
pub fn get_broker_interface(&self) -> Option<BrokerInterface> { pub fn get_broker_interface(&self) -> Option<BrokerInterface> {
if let Some(path_ref) = self.psk_broker_path.as_ref() { if let Some(path_ref) = self.psk_broker_path.as_ref() {
Some(BrokerInterface::Socket(path_ref.to_path_buf())) Some(BrokerInterface::Socket(path_ref.to_path_buf()))
@@ -124,9 +124,9 @@ impl CliArgs {
} }
} }
#[cfg(not(feature = "enable_wg_broker"))] #[cfg(not(feature = "experiment_broker_api"))]
/// returns the broker interface set by CLI args /// returns the broker interface set by CLI args
/// returns `None` if the `enable_wg_broker` feature isn't enabled /// returns `None` if the `experiment_broker_api` feature isn't enabled
pub fn get_broker_interface(&self) -> Option<BrokerInterface> { pub fn get_broker_interface(&self) -> Option<BrokerInterface> {
None None
} }
@@ -445,7 +445,7 @@ impl CliArgs {
srv.event_loop() srv.event_loop()
} }
#[cfg(feature = "enable_wg_broker")] #[cfg(feature = "experiment_broker_api")]
fn create_broker( fn create_broker(
broker_interface: Option<BrokerInterface>, broker_interface: Option<BrokerInterface>,
) -> Result< ) -> Result<
@@ -460,7 +460,7 @@ impl CliArgs {
} }
} }
#[cfg(not(feature = "enable_wg_broker"))] #[cfg(not(feature = "experiment_broker_api"))]
fn create_broker( fn create_broker(
_broker_interface: Option<BrokerInterface>, _broker_interface: Option<BrokerInterface>,
) -> Result< ) -> Result<
@@ -470,7 +470,7 @@ impl CliArgs {
Ok(Box::new(NativeUnixBroker::new())) Ok(Box::new(NativeUnixBroker::new()))
} }
#[cfg(feature = "enable_wg_broker")] #[cfg(feature = "experiment_broker_api")]
fn get_broker_socket(broker_interface: BrokerInterface) -> Result<UnixStream, anyhow::Error> { fn get_broker_socket(broker_interface: BrokerInterface) -> Result<UnixStream, anyhow::Error> {
// Connect to the psk broker unix socket if one was specified // Connect to the psk broker unix socket if one was specified
// OR OTHERWISE spawn the psk broker and use socketpair(2) to connect with them // OR OTHERWISE spawn the psk broker and use socketpair(2) to connect with them

View File

@@ -36,14 +36,14 @@ rand = {workspace = true}
procspawn = {workspace = true} procspawn = {workspace = true}
[features] [features]
enable_broker_api=[] experimental_broker_api = []
[[bin]] [[bin]]
name = "rosenpass-wireguard-broker-privileged" name = "rosenpass-wireguard-broker-privileged"
path = "src/bin/priviledged.rs" path = "src/bin/priviledged.rs"
test = false test = false
doc = false doc = false
required-features=["enable_broker_api"] required-features = ["experimental_broker_api"]
cfg = { target_os = "linux" } cfg = { target_os = "linux" }
[[bin]] [[bin]]
@@ -51,5 +51,5 @@ name = "rosenpass-wireguard-broker-socket-handler"
test = false test = false
path = "src/bin/socket_handler.rs" path = "src/bin/socket_handler.rs"
doc = false doc = false
required-features=["enable_broker_api"] required-features = ["experimental_broker_api"]
cfg = { target_os = "linux" } cfg = { target_os = "linux" }

View File

@@ -2,7 +2,6 @@ use anyhow::{bail, ensure};
use mio::Interest; use mio::Interest;
use rosenpass_util::ord::max_usize; use rosenpass_util::ord::max_usize;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::dbg;
use std::io::{ErrorKind, Read, Write}; use std::io::{ErrorKind, Read, Write};
use crate::{SerializedBrokerConfig, WireGuardBroker, WireguardBrokerMio}; use crate::{SerializedBrokerConfig, WireGuardBroker, WireguardBrokerMio};

View File

@@ -1,6 +1,6 @@
#[cfg(feature = "enable_broker_api")] #[cfg(feature = "experimental_broker_api")]
pub mod mio_client; pub mod mio_client;
#[cfg(all(feature = "enable_broker_api", target_os = "linux"))] #[cfg(all(feature = "experimental_broker_api", target_os = "linux"))]
pub mod netlink; pub mod netlink;
pub mod native_unix; pub mod native_unix;

View File

@@ -34,7 +34,7 @@ pub trait WireguardBrokerMio: WireGuardBroker {
fn unregister(&mut self, registry: &mio::Registry) -> Result<(), Self::MioError>; fn unregister(&mut self, registry: &mio::Registry) -> Result<(), Self::MioError>;
} }
#[cfg(feature = "enable_broker_api")] #[cfg(feature = "experimental_broker_api")]
pub mod api; pub mod api;
pub mod brokers; pub mod brokers;

View File

@@ -1,4 +1,4 @@
#[cfg(feature = "enable_broker_api")] #[cfg(feature = "experimental_broker_api")]
#[cfg(test)] #[cfg(test)]
mod integration_tests { mod integration_tests {