@@ -26,10 +26,13 @@ use crate::NymVpn;
2626
2727const DEFAULT_TUN_MTU : u16 = 1500 ;
2828
29+ #[ derive( Clone ) ]
2930pub struct RoutingConfig {
3031 pub ( crate ) mixnet_tun_config : tun2:: Configuration ,
31- // In case we need it , as it's not read-accessible in the tun2 config
32+ // In case we need them , as they're not read-accessible in the tun2 config
3233 pub ( crate ) tun_ips : IpPair ,
34+ pub ( crate ) mtu : u16 ,
35+
3336 pub ( crate ) entry_mixnet_gateway_ip : IpAddr ,
3437 pub ( crate ) lan_gateway_ip : LanGatewayIp ,
3538 pub ( crate ) tunnel_gateway_ip : TunnelGatewayIp ,
@@ -45,9 +48,10 @@ impl Display for RoutingConfig {
4548 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
4649 write ! (
4750 f,
48- "mixnet_tun_config: {:?}\n tun_ips: {:?}\n entry_mixnet_gateway_ip: {:?}\n lan_gateway_ip: {:?}\n tunnel_gateway_ip: {:?}\n enable_wireguard: {:?}\n disable_routing: {:?}" ,
51+ "mixnet_tun_config: {:?}\n tun_ips: {:?}\n mtu: {} \ n entry_mixnet_gateway_ip: {:?}\n lan_gateway_ip: {:?}\n tunnel_gateway_ip: {:?}\n enable_wireguard: {:?}\n disable_routing: {:?}" ,
4952 self . mixnet_tun_config,
5053 self . tun_ips,
54+ self . mtu,
5155 self . entry_mixnet_gateway_ip,
5256 self . lan_gateway_ip,
5357 self . tunnel_gateway_ip,
@@ -68,14 +72,16 @@ impl RoutingConfig {
6872 ) -> Self {
6973 debug ! ( "TUN device IPs: {}" , tun_ips) ;
7074 let mut mixnet_tun_config = tun2:: Configuration :: default ( ) ;
75+ let mtu = vpn. nym_mtu . unwrap_or ( DEFAULT_TUN_MTU ) ;
7176 // only IPv4 is supported by tun2 for now
7277 mixnet_tun_config. address ( tun_ips. ipv4 ) ;
73- mixnet_tun_config. mtu ( vpn . nym_mtu . unwrap_or ( DEFAULT_TUN_MTU ) ) ;
78+ mixnet_tun_config. mtu ( mtu ) ;
7479 mixnet_tun_config. up ( ) ;
7580
7681 Self {
7782 mixnet_tun_config,
7883 tun_ips,
84+ mtu,
7985 entry_mixnet_gateway_ip,
8086 lan_gateway_ip,
8187 tunnel_gateway_ip,
@@ -91,9 +97,21 @@ impl RoutingConfig {
9197 pub fn tun_ips ( & self ) -> IpPair {
9298 self . tun_ips
9399 }
100+
101+ pub fn mtu ( & self ) -> u16 {
102+ self . mtu
103+ }
104+
105+ pub fn entry_mixnet_gateway_ip ( & self ) -> IpAddr {
106+ self . entry_mixnet_gateway_ip
107+ }
108+
109+ pub fn enable_wireguard ( & self ) -> bool {
110+ self . enable_wireguard
111+ }
94112}
95113
96- #[ derive( Debug ) ]
114+ #[ derive( Clone , Debug ) ]
97115pub struct TunnelGatewayIp {
98116 pub ipv4 : Ipv4Addr ,
99117 pub ipv6 : Option < Ipv6Addr > ,
@@ -123,7 +141,7 @@ impl std::fmt::Display for TunnelGatewayIp {
123141 }
124142}
125143
126- #[ derive( Debug ) ]
144+ #[ derive( Clone , Debug ) ]
127145pub struct LanGatewayIp ( pub Interface ) ;
128146
129147impl LanGatewayIp {
@@ -189,6 +207,9 @@ fn replace_default_prefixes(network: IpNetwork) -> Vec<IpNetwork> {
189207pub async fn setup_routing (
190208 route_manager : & mut RouteManager ,
191209 config : RoutingConfig ,
210+ #[ cfg( target_os = "ios" ) ] ios_tun_provider : std:: sync:: Arc <
211+ dyn crate :: platform:: ios:: OSTunProvider ,
212+ > ,
192213) -> Result < tun2:: AsyncDevice > {
193214 debug ! ( "Creating tun device" ) ;
194215 let mixnet_tun_config = config. mixnet_tun_config . clone ( ) ;
@@ -215,6 +236,13 @@ pub async fn setup_routing(
215236 mixnet_tun_config. raw_fd ( fd) ;
216237 mixnet_tun_config
217238 } ;
239+ #[ cfg( target_os = "ios" ) ]
240+ let mixnet_tun_config = {
241+ let fd = ios_tun_provider. configure_nym ( config. clone ( ) . into ( ) ) ?;
242+ let mut mixnet_tun_config = mixnet_tun_config. clone ( ) ;
243+ mixnet_tun_config. raw_fd ( fd) ;
244+ mixnet_tun_config
245+ } ;
218246 let dev = tun2:: create_as_async ( & mixnet_tun_config)
219247 . tap_err ( |err| error ! ( "Failed to create tun device: {}" , err) ) ?;
220248 let device_name = dev. as_ref ( ) . tun_name ( ) . unwrap ( ) . to_string ( ) ;
0 commit comments