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

chore: update default syslog config #27

Merged
merged 3 commits into from
Jul 17, 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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ clap = { version = "4.1", features = ["derive", "env"] }
env_logger = "0.9"
log = "0.4"
prost = "0.11"
syslog = "6.0"
syslog = "6.1"
thiserror = "1.0"
tonic = {version = "0.9", features = ["gzip", "tls", "tls-roots"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand All @@ -33,10 +33,10 @@ tonic-build = { version = "0.9" }
prost-build = { version = "0.11" }

[target.'cfg(target_os = "linux")'.dependencies]
netlink-packet-core = "0.5"
netlink-packet-generic = "0.3"
netlink-packet-route = "0.15"
netlink-packet-wireguard = "0.2"
netlink-packet-core = "0.5.0"
netlink-packet-generic = "0.3.2"
netlink-packet-route = "0.15.0"
netlink-packet-wireguard = "0.2.1"
netlink-sys = "0.8"

[profile.release]
Expand Down
33 changes: 20 additions & 13 deletions src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ fn spawn_stats_thread(
userspace: bool,
) {
// Create an async stream that periodically yields wireguard interface statistics.
info!("Spawning stats thread");
let stats_stream = async_stream::stream! {
let api = WGApi::new(ifname, userspace);
loop {
debug!("Sending peer stats update");
match api.read_host() {
Ok(host) => {
for peer in host
Expand Down Expand Up @@ -159,7 +161,7 @@ fn init_syslog(config: &Config, pid: u32) -> Result<(), GatewayError> {
};
let logger = syslog::unix_custom(formatter, &config.syslog_socket)?;
log::set_boxed_logger(Box::new(BasicLogger::new(logger)))?;
log::set_max_level(log::LevelFilter::Info);
log::set_max_level(log::LevelFilter::Debug);
Ok(())
}

Expand Down Expand Up @@ -213,19 +215,24 @@ pub async fn start(config: &Config) -> Result<(), GatewayError> {
let mut updates_stream = connect(config, Arc::clone(&client)).await?;
loop {
match updates_stream.message().await {
Ok(Some(update)) => match update.update {
Some(update::Update::Network(configuration)) => configure(config, configuration)?,
Some(update::Update::Peer(peer_config)) => {
info!("Applying peer configuration: {:?}", peer_config);
match update.update_type {
// UpdateType::Delete
2 => wgapi.delete_peer(&peer_config.into()),
// UpdateType::Create, UpdateType::Modify
_ => wgapi.write_peer(&peer_config.into()),
}?
Ok(Some(update)) => {
debug!("Received update: {:?}", update);
match update.update {
Some(update::Update::Network(configuration)) => {
configure(config, configuration)?
}
Some(update::Update::Peer(peer_config)) => {
info!("Applying peer configuration: {:?}", peer_config);
match update.update_type {
// UpdateType::Delete
2 => wgapi.delete_peer(&peer_config.into()),
// UpdateType::Create, UpdateType::Modify
_ => wgapi.write_peer(&peer_config.into()),
}?
}
_ => warn!("Unsupported kind of update"),
}
_ => warn!("Unsupported kind of update"),
},
}
Ok(None) => {
warn!("Received empty message, reconnecting");
updates_stream = connect(config, Arc::clone(&client)).await?;
Expand Down