Skip to content

Commit

Permalink
fix(local-tun): Linux already has IFF_NO_PI, macOS already set route
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Jun 1, 2024
1 parent 0e78262 commit d8191ec
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions crates/shadowsocks-service/src/local/tun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ impl TunBuilder {
pub async fn build(mut self) -> io::Result<Tun> {
self.tun_config.layer(Layer::L3).up();

#[cfg(target_os = "linux")]
self.tun_config.platform_config(|tun_config| {
// IFF_NO_PI preventing excessive buffer reallocating
tun_config.packet_information(false);
});
// XXX: tun2 set IFF_NO_PI by default.
//
// #[cfg(target_os = "linux")]
// self.tun_config.platform_config(|tun_config| {
// // IFF_NO_PI preventing excessive buffer reallocating
// tun_config.packet_information(false);
// });

let device = match create_as_async(&self.tun_config) {
Ok(d) => d,
Expand Down Expand Up @@ -203,9 +205,10 @@ impl Tun {
);

// Set default route
if let Err(err) = sys::set_route_configuration(self.device.as_mut()).await {
warn!("[TUN] tun device set route failed, error: {}", err);
}
// XXX: tun2 already set it by default.
// if let Err(err) = sys::set_route_configuration(self.device.as_mut()).await {
// warn!("[TUN] tun device set route failed, error: {}", err);
// }

let address_broadcast = address_net.broadcast();

Expand Down

0 comments on commit d8191ec

Please sign in to comment.