Skip to content

Conversation

@ibigbug
Copy link
Member

@ibigbug ibigbug commented Oct 12, 2025

🤔 This is a ...

  • Bug fix

🔗 Related issue link

close #939

💡 Background and solution

When TUN interface already exists (e.g., pre-configured by system administrator), setting IP addresses can overwrite existing network routes and configurations. This change checks if the TUN device exists before attempting to configure its IP addresses, preserving any pre-existing network configuration.

The solution:

  1. Check if the TUN interface already exists using network_interface crate
  2. Only set IPv4/IPv6 addresses if the interface doesn't exist
  3. Log appropriate messages to indicate whether creating new or using existing interface

📝 Changelog

  • fix(tun): Preserve pre-configured TUN interface routes by checking existence before IP configuration
  • refactor: Split TUN inbound handlers into separate modules for better code organization

☑️ Self-Check before Merge

  • Doc is updated/provided or not needed
  • Changelog is provided or not needed

🤖 Generated with Claude Code

@ibigbug ibigbug requested a review from Copilot October 12, 2025 14:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where setting IP addresses on an existing TUN interface could overwrite pre-configured network routes. The solution checks if the TUN device already exists before attempting to configure its IP addresses, preserving any existing network configuration.

Key changes:

  • Check TUN interface existence using network_interface crate before IP configuration
  • Only set IPv4/IPv6 addresses if the interface doesn't exist
  • Refactor TUN inbound handlers into separate modules for better organization

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
clash-lib/src/proxy/tun/mod.rs Add new stream module export
clash-lib/src/proxy/tun/inbound.rs Add TUN existence check logic and remove inline handler functions
clash-lib/src/proxy/tun/stream.rs New module containing extracted TCP stream handler
clash-lib/src/proxy/tun/datagram.rs New module containing extracted UDP datagram handler

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Yuwei Ba <[email protected]>
@codecov
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

❌ Patch coverage is 1.32450% with 149 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
clash-lib/src/proxy/tun/datagram.rs 0.00% 109 Missing ⚠️
clash-lib/src/proxy/tun/stream.rs 0.00% 22 Missing ⚠️
clash-lib/src/proxy/tun/inbound.rs 0.00% 18 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ibigbug ibigbug merged commit 3973bc1 into master Oct 13, 2025
31 of 34 checks passed
@ibigbug ibigbug deleted the issue-939 branch October 13, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

don't touch IP address on start up for existing tun iface

3 participants