Skip to content
Closed
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
19 changes: 19 additions & 0 deletions core/src/main/golang/native/config/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strings"
"sync"

"github.com/dlclark/regexp2"

Expand All @@ -30,6 +31,19 @@ var processors = []processor{

type processor func(cfg *config.RawConfig, profileDir string) error

var (
tunICMPMu sync.RWMutex
tunDisableICMPForwarding bool
tunICMPTimeout int64
tunOptionsReady bool
)

func GetTunICMPOptions() (bool, int64, bool) {
tunICMPMu.RLock()
defer tunICMPMu.RUnlock()
return tunDisableICMPForwarding, tunICMPTimeout, tunOptionsReady
}

func patchOverride(cfg *config.RawConfig, _ string) error {
if err := json.NewDecoder(strings.NewReader(ReadOverride(OverrideSlotPersist))).Decode(cfg); err != nil {
log.Warnln("Apply persist override: %s", err.Error())
Expand Down Expand Up @@ -85,6 +99,11 @@ func patchDns(cfg *config.RawConfig, _ string) error {
}

func patchTun(cfg *config.RawConfig, _ string) error {
tunICMPMu.Lock()
tunDisableICMPForwarding = cfg.Tun.DisableICMPForwarding
tunICMPTimeout = cfg.Tun.ICMPTimeout
tunOptionsReady = true
tunICMPMu.Unlock()
cfg.Tun.Enable = false
cfg.Tun.AutoRoute = false
cfg.Tun.AutoDetectInterface = false
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/golang/native/tun/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"net"
"net/netip"
"strings"
"time"

"cfa/native/config"

C "github.com/metacubex/mihomo/constant"
LC "github.com/metacubex/mihomo/listener/config"
Expand Down Expand Up @@ -64,6 +67,17 @@ func Start(fd int, stack, gateway, portal, dns string) (io.Closer, error) {
FileDescriptor: fd,
}

disableICMPForwarding, icmpTimeout, ready := config.GetTunICMPOptions()
if !ready {
deadline := time.Now().Add(3 * time.Second)
for !ready && time.Now().Before(deadline) {
time.Sleep(50 * time.Millisecond)
disableICMPForwarding, icmpTimeout, ready = config.GetTunICMPOptions()
}
}
options.DisableICMPForwarding = disableICMPForwarding
options.ICMPTimeout = icmpTimeout

tunOptions, _ := json.Marshal(options)
log.Debugln(string(tunOptions))

Expand Down