@@ -30,15 +30,20 @@ use objc2_network_extension::{
3030 NETunnelProviderManager , NETunnelProviderProtocol , NETunnelProviderSession , NEVPNStatus ,
3131} ;
3232use serde:: Deserialize ;
33- use sqlx:: SqliteExecutor ;
3433use tauri:: { AppHandle , Emitter , Manager } ;
3534use tracing:: Level ;
3635
3736use crate :: {
3837 active_connections:: find_connection,
3938 appstate:: AppState ,
4039 database:: {
41- models:: { location:: Location , tunnel:: Tunnel , wireguard_keys:: WireguardKeys , Id } ,
40+ models:: {
41+ instance:: { ClientTrafficPolicy , Instance } ,
42+ location:: Location ,
43+ tunnel:: Tunnel ,
44+ wireguard_keys:: WireguardKeys ,
45+ Id ,
46+ } ,
4247 DB_POOL ,
4348 } ,
4449 error:: Error ,
@@ -931,7 +936,7 @@ pub async fn sync_locations_and_tunnels(mtu: Option<u32>) -> Result<(), sqlx::Er
931936 let all_locations = Location :: all ( & * DB_POOL , false ) . await ?;
932937 for location in & all_locations {
933938 // For syncing, set `preshred_key` to `None`.
934- let Ok ( tunnel_config) = location. tunnel_configurarion ( & * DB_POOL , None , mtu) . await else {
939+ let Ok ( tunnel_config) = location. tunnel_configurarion ( None , mtu) . await else {
935940 error ! (
936941 "Failed to convert location {} to tunnel configuration." ,
937942 location. name
@@ -1019,17 +1024,13 @@ pub async fn sync_locations_and_tunnels(mtu: Option<u32>) -> Result<(), sqlx::Er
10191024
10201025impl Location < Id > {
10211026 /// Build [`TunnelConfiguration`] from [`Location`].
1022- pub ( crate ) async fn tunnel_configurarion < ' e , E > (
1027+ pub ( crate ) async fn tunnel_configurarion (
10231028 & self ,
1024- executor : E ,
10251029 preshared_key : Option < String > ,
10261030 mtu : Option < u32 > ,
1027- ) -> Result < TunnelConfiguration , Error >
1028- where
1029- E : SqliteExecutor < ' e > ,
1030- {
1031+ ) -> Result < TunnelConfiguration , Error > {
10311032 debug ! ( "Looking for WireGuard keys for location {self} instance" ) ;
1032- let Some ( keys) = WireguardKeys :: find_by_instance_id ( executor , self . instance_id ) . await ?
1033+ let Some ( keys) = WireguardKeys :: find_by_instance_id ( & * DB_POOL , self . instance_id ) . await ?
10331034 else {
10341035 error ! ( "No keys found for instance: {}" , self . instance_id) ;
10351036 return Err ( Error :: InternalError (
@@ -1057,7 +1058,19 @@ impl Location<Id> {
10571058 }
10581059
10591060 debug ! ( "Parsing location {self} allowed IPs: {}" , self . allowed_ips) ;
1060- let allowed_ips = if self . route_all_traffic {
1061+ let Some ( instance) = Instance :: find_by_id ( & * DB_POOL , self . instance_id ) . await ? else {
1062+ error ! ( "Instance {} not found" , self . instance_id) ;
1063+ return Err ( Error :: InternalError ( format ! (
1064+ "Instance {} not found" ,
1065+ self . instance_id
1066+ ) ) ) ;
1067+ } ;
1068+ let route_all_traffic = match instance. client_traffic_policy {
1069+ ClientTrafficPolicy :: ForceAllTraffic => true ,
1070+ ClientTrafficPolicy :: DisableAllTraffic => false ,
1071+ ClientTrafficPolicy :: None => self . route_all_traffic ,
1072+ } ;
1073+ let allowed_ips = if route_all_traffic {
10611074 debug ! ( "Using all traffic routing for location {self}" ) ;
10621075 vec ! [ DEFAULT_ROUTE_IPV4 . into( ) , DEFAULT_ROUTE_IPV6 . into( ) ]
10631076 } else {
0 commit comments