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

Fix duplicated incoming packets when split tunneling is enabled #6924

Merged
merged 3 commits into from
Oct 4, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Line wrap the file at 100 chars. Th
#### macOS
- Fix Apple services not working by forcing stray connections out through the VPN tunnel. The
"bypass" toggle has been removed.
- Fix packets being duplicated on LAN when split tunneling is enabled.


## [2024.6-beta1] - 2024-09-26
Expand Down
9 changes: 9 additions & 0 deletions talpid-core/src/firewall/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ impl Firewall {
}
}

if let Some(endpoint) = policy.allowed_endpoint() {
// Keep states to the allowed endpoint.
// Note that we're not taking into account allowed clients here, because it's highly
// impractical.
if endpoint.endpoint.address == remote_address {
return Ok(false);
}
}

let Some(peer) = policy.peer_endpoint().map(|endpoint| endpoint.endpoint) else {
// If there's no peer, there's also no tunnel. We have no states to preserve
return Ok(true);
Expand Down
14 changes: 14 additions & 0 deletions talpid-core/src/firewall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ impl FirewallPolicy {
}
}

/// Return the allowed endpoint, if available
pub fn allowed_endpoint(&self) -> Option<&AllowedEndpoint> {
match self {
FirewallPolicy::Connecting {
allowed_endpoint, ..
}
| FirewallPolicy::Blocked {
allowed_endpoint: Some(allowed_endpoint),
..
} => Some(allowed_endpoint),
_ => None,
}
}

/// Return tunnel metadata, if available
pub fn tunnel(&self) -> Option<&crate::tunnel::TunnelMetadata> {
match self {
Expand Down
18 changes: 17 additions & 1 deletion talpid-core/src/split_tunnel/macos/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ use pnet_packet::{
use std::{
ffi::{c_uint, CStr},
io::{self, IoSlice, Write},
net::{Ipv4Addr, Ipv6Addr},
net::{IpAddr, Ipv4Addr, Ipv6Addr},
};
use talpid_routing::RouteManagerHandle;
use talpid_types::net::{ALLOWED_LAN_MULTICAST_NETS, ALLOWED_LAN_NETS};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
sync::broadcast,
Expand Down Expand Up @@ -676,6 +677,10 @@ async fn handle_incoming_data_v4(
log::trace!("Dropping packet to VPN IP on default interface");
return;
}
if is_private_ip(IpAddr::from(ip.get_source())) {
// Drop packets from private IPs
return;
}

fix_ipv4_checksums(&mut ip, None, Some(vpn_addr));

Expand All @@ -698,6 +703,10 @@ async fn handle_incoming_data_v6(
log::trace!("Dropping packet to VPN IP on default interface");
return;
}
if is_private_ip(IpAddr::from(ip.get_source())) {
// Drop packets from private IPs
return;
}

fix_ipv6_checksums(&mut ip, None, Some(vpn_addr));

Expand All @@ -710,6 +719,13 @@ async fn handle_incoming_data_v6(
}
}

fn is_private_ip(ip: IpAddr) -> bool {
ALLOWED_LAN_NETS
.iter()
.chain(ALLOWED_LAN_MULTICAST_NETS.iter())
.any(|net| net.contains(ip))
}

// Recalculate L3 and L4 checksums. Silently fail on error
fn fix_ipv4_checksums(
ip: &mut MutableIpv4Packet<'_>,
Expand Down
Loading