[fix]Linux TProxy

This commit is contained in:
Maze.tsz 2021-12-04 14:34:01 +08:00
parent 23ca356447
commit 58552447ef
9 changed files with 44 additions and 45 deletions

View file

@ -47,6 +47,9 @@ linux-386:
linux-amd64:
GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-arm64:
GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-armv5:
GOARCH=arm GOOS=linux GOARM=5 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

View file

@ -2,10 +2,7 @@ package executor
import (
"fmt"
"net"
"os"
"runtime"
"strconv"
"strings"
"sync"
@ -24,7 +21,6 @@ import (
"github.com/Dreamacro/clash/dns"
P "github.com/Dreamacro/clash/listener"
authStore "github.com/Dreamacro/clash/listener/auth"
"github.com/Dreamacro/clash/listener/tproxy"
"github.com/Dreamacro/clash/listener/tun/dev"
"github.com/Dreamacro/clash/log"
"github.com/Dreamacro/clash/tunnel"
@ -78,7 +74,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
updateRules(cfg.Rules, cfg.RuleProviders)
updateHosts(cfg.Hosts)
updateProfile(cfg)
updateIPTables(cfg.DNS, cfg.General)
//updateIPTables(cfg.DNS, cfg.General)
updateDNS(cfg.DNS, cfg.General)
updateGeneral(cfg.General, force)
updateExperimental(cfg)
@ -288,35 +284,35 @@ func patchSelectGroup(proxies map[string]C.Proxy) {
}
}
func updateIPTables(dns *config.DNS, general *config.General) {
if runtime.GOOS != "linux" || dns.Listen == "" || general.TProxyPort == 0 || general.Tun.Enable {
return
}
_, dnsPortStr, err := net.SplitHostPort(dns.Listen)
if dnsPortStr == "0" || dnsPortStr == "" || err != nil {
return
}
dnsPort, err := strconv.Atoi(dnsPortStr)
if err != nil {
return
}
tproxy.CleanUpTProxyLinuxIPTables()
err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
if err != nil {
log.Errorln("Can not setting iptables for TProxy on linux, %s", err.Error())
os.Exit(2)
}
}
//func updateIPTables(dns *config.DNS, general *config.General) {
// if runtime.GOOS != "linux" || dns.Listen == "" || general.TProxyPort == 0 || general.Tun.Enable {
// return
// }
//
// _, dnsPortStr, err := net.SplitHostPort(dns.Listen)
// if dnsPortStr == "0" || dnsPortStr == "" || err != nil {
// return
// }
//
// dnsPort, err := strconv.Atoi(dnsPortStr)
// if err != nil {
// return
// }
//
// tproxy.CleanUpTProxyLinuxIPTables()
//
// err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
//
// if err != nil {
// log.Errorln("Can not setting iptables for TProxy on linux, %s", err.Error())
// os.Exit(2)
// }
//}
func CleanUp() {
P.CleanUp()
if runtime.GOOS == "linux" {
tproxy.CleanUpTProxyLinuxIPTables()
}
//if runtime.GOOS == "linux" {
// tproxy.CleanUpTProxyLinuxIPTables()
//}
}

View file

@ -15,10 +15,10 @@ import (
"testing"
"time"
"github.com/Dreamacro/clash/adapter/outbound"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/hub/executor"
"github.com/Dreamacro/clash/transport/socks5"
"github.com/Dreamacro/Clash.Meta/adapter/outbound"
C "github.com/Dreamacro/Clash.Meta/constant"
"github.com/Dreamacro/Clash.Meta/hub/executor"
"github.com/Dreamacro/Clash.Meta/transport/socks5"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"

View file

@ -5,8 +5,8 @@ import (
"testing"
"time"
"github.com/Dreamacro/clash/adapter/outbound"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/Clash.Meta/adapter/outbound"
C "github.com/Dreamacro/Clash.Meta/constant"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"

View file

@ -4,7 +4,7 @@ import (
"testing"
"time"
"github.com/Dreamacro/clash/adapter/outbound"
"github.com/Dreamacro/Clash.Meta/adapter/outbound"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"

View file

@ -5,8 +5,8 @@ import (
"testing"
"time"
"github.com/Dreamacro/clash/adapter/outbound"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/Clash.Meta/adapter/outbound"
C "github.com/Dreamacro/Clash.Meta/constant"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"

View file

@ -5,8 +5,8 @@ import (
"testing"
"time"
"github.com/Dreamacro/clash/adapter/outbound"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/Clash.Meta/adapter/outbound"
C "github.com/Dreamacro/Clash.Meta/constant"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"

View file

@ -5,8 +5,8 @@ import (
"testing"
"time"
"github.com/Dreamacro/clash/adapter/outbound"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/Clash.Meta/adapter/outbound"
C "github.com/Dreamacro/Clash.Meta/constant"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"