Skip to content

Commit

Permalink
Updated dependencies, fixed intermittent bug with keepalive counter i…
Browse files Browse the repository at this point in the history
…n SSL tunnel
  • Loading branch information
ancwrd1 committed Oct 29, 2024
1 parent a3c6f8b commit 74d5ee7
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 177 deletions.
379 changes: 227 additions & 152 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion snx-rs-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ tokio = { version = "1", features = ["rt-multi-thread"] }
ipnet = { version = "2", features = ["serde"] }
clap = { version = "4", features = ["derive"] }
hex = "0.4"
zbus = { version = "4.2", default-features = false, features = ["tokio"] }
zbus = { version = "5", default-features = false, features = ["tokio"] }
futures = "0.3"
2 changes: 1 addition & 1 deletion snx-rs-gui/src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use zbus::{zvariant, Connection};
default_service = "org.freedesktop.portal.Desktop",
default_path = "/org/freedesktop/portal/desktop"
)]
trait DesktopSettings {
pub trait DesktopSettings {
#[zbus(signal)]
fn setting_changed(&self, namespace: &str, key: &str, value: zvariant::Value<'_>) -> zbus::Result<()>;

Expand Down
4 changes: 2 additions & 2 deletions snxcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ reqwest = { version = "0.12", features = ["native-tls"] }
futures = "0.3"
bytes = "1"
hex = "0.4"
tun = { version = "0.6", features = ["async"] }
tun = { version = "0.7", features = ["async"] }
ipnet = { version = "2", features = ["serde"] }
libc = "0.2"
base64 = "0.22"
Expand All @@ -42,7 +42,7 @@ byteorder = "1"
regex = "1"
once_cell = "1"
nix = { version = "0.29", features = ["fs", "user"] }
zbus = { version = "4.2", default-features = false, features = ["tokio"] }
zbus = { version = "5", default-features = false, features = ["tokio"] }
secret-service = { version = "4", features = ["rt-tokio-crypto-rust"] }
uuid = { version = "1", features = ["v4", "v5"] }
opener = { version = "0.7"}
Expand Down
8 changes: 4 additions & 4 deletions snxcore/src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ impl UdpSocketExt for UdpSocket {
}

pub fn new_tun_config() -> tun::Configuration {
let mut config = tun::Configuration::default();
let config = tun::Configuration::default();

config.platform(|config| {
config.packet_information(true);
});
// config.platform_config(|config| {
// config.packet_information(true);
// });

config
}
Expand Down
13 changes: 5 additions & 8 deletions snxcore/src/tunnel/ssl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
sync::{
atomic::{AtomicU64, Ordering},
atomic::{AtomicI64, Ordering},
Arc,
},
time::Duration,
Expand All @@ -14,7 +14,6 @@ use futures::{
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_native_tls::native_tls::{Certificate, TlsConnector};
use tracing::{debug, trace, warn};
use tun::TunPacket;

use codec::{SslPacketCodec, SslPacketType};

Expand Down Expand Up @@ -73,7 +72,7 @@ pub(crate) struct SslTunnel {
device_name: String,
sender: PacketSender,
receiver: Option<PacketReceiver>,
keepalive_counter: Arc<AtomicU64>,
keepalive_counter: Arc<AtomicI64>,
}

impl SslTunnel {
Expand Down Expand Up @@ -113,7 +112,7 @@ impl SslTunnel {
device_name: String::new(),
sender,
receiver: Some(receiver),
keepalive_counter: Arc::new(AtomicU64::default()),
keepalive_counter: Arc::new(AtomicI64::default()),
})
}

Expand Down Expand Up @@ -225,8 +224,7 @@ impl VpnTunnel for SslTunnel {
}
}
SslPacketType::Data(data) => {
let tun_packet = TunPacket::new(data);
tun_sender.send(tun_packet).await?;
tun_sender.send(data).await?;
keepalive_counter.store(0, Ordering::SeqCst);
}
}
Expand Down Expand Up @@ -261,8 +259,7 @@ impl VpnTunnel for SslTunnel {

result = tun_receiver.next() => {
if let Some(Ok(item)) = result {
let data = item.into_bytes().to_vec();
self.send(data).await?;
self.send(item).await?;
} else {
break Err(anyhow!("Receive failed"));
}
Expand Down
9 changes: 4 additions & 5 deletions snxcore/src/tunnel/ssl/device.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::net::Ipv4Addr;

use tracing::debug;
use tun::Device;

use crate::{
model::{params::TunnelParams, proto::HelloReplyData},
platform, util,
};
use tracing::debug;
use tun::AbstractDevice;

pub struct TunDevice {
inner: tun::AsyncDevice,
Expand All @@ -21,15 +20,15 @@ impl TunDevice {
let ipaddr = reply.office_mode.ipaddr.parse::<Ipv4Addr>()?;

config.address(reply.office_mode.ipaddr.as_str()).up();
config.name(name);
config.tun_name(name);

if let Some(ref netmask) = reply.optional {
config.netmask(netmask.subnet.as_str());
}

let dev = tun::create_as_async(&config)?;

let dev_name = dev.get_ref().name()?;
let dev_name = dev.tun_name()?;

debug!("Created tun device: {dev_name}");

Expand Down
8 changes: 4 additions & 4 deletions snxcore/src/tunnel/ssl/keepalive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
sync::{
atomic::{AtomicU64, Ordering},
atomic::{AtomicI64, Ordering},
Arc,
},
time::Duration,
Expand All @@ -15,17 +15,17 @@ use crate::{
tunnel::ssl::PacketSender,
};

const KEEPALIVE_MAX_RETRIES: u64 = 3;
const KEEPALIVE_MAX_RETRIES: i64 = 3;
const SEND_TIMEOUT: Duration = Duration::from_secs(10);

pub struct KeepaliveRunner {
interval: Duration,
sender: PacketSender,
keepalive_counter: Arc<AtomicU64>,
keepalive_counter: Arc<AtomicI64>,
}

impl KeepaliveRunner {
pub fn new(interval: Duration, sender: PacketSender, counter: Arc<AtomicU64>) -> Self {
pub fn new(interval: Duration, sender: PacketSender, counter: Arc<AtomicI64>) -> Self {
Self {
interval,
sender,
Expand Down

0 comments on commit 74d5ee7

Please sign in to comment.