From eb999b3bf1121c339285528ad15fc8dacf800b2e Mon Sep 17 00:00:00 2001 From: "maze.y2b@gmail.com" Date: Sat, 4 Dec 2021 19:59:41 +0800 Subject: [PATCH] fix AutoIptables --- Makefile | 31 +++++++++++-------------------- README.md | 13 +++++++------ constant/version.go | 8 ++++---- hub/executor/executor.go | 7 ++++--- rule/process.go | 4 +++- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 36a01536..c31ccf39 100644 --- a/Makefile +++ b/Makefile @@ -2,40 +2,31 @@ NAME=Clash.Meta BINDIR=bin VERSION=$(shell git describe --tags || echo "unknown version") BUILDTIME=$(shell date -u) +AUTOIPTABLES=Enable GOBUILD=CGO_ENABLED=0 go build -trimpath -ldflags '-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \ -X "github.com/Dreamacro/clash/constant.BuildTime=$(BUILDTIME)" \ -w -s -buildid=' GOBUILDOP=CGO_ENABLED=0 go build -trimpath -ldflags '-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \ -X "github.com/Dreamacro/clash/constant.BuildTime=$(BUILDTIME)" \ - -X "github.com/Dreamacro/clash/constant.OpenWrt:=true" \ + -X "github.com/Dreamacro/clash/constant.AutoIptables=$(AUTOIPTABLES)" \ -w -s -buildid=' PLATFORM_LIST = \ darwin-amd64 \ darwin-arm64 \ - linux-386 \ + linux-arm64 \ linux-amd64 \ - linux-armv5 \ - linux-armv6 \ - linux-armv7 \ - linux-armv8 \ - linux-mips-softfloat \ - linux-mips-hardfloat \ - linux-mipsle-softfloat \ - linux-mipsle-hardfloat \ - linux-mips64 \ - linux-mips64le \ - freebsd-386 \ - freebsd-amd64 \ - freebsd-arm64 + linux-arm64-AutoIptables\ + linux-amd64-AutoIptables + WINDOWS_ARCH_LIST = \ windows-386 \ - windows-amd64 \ - windows-arm32v7 + windows-amd64 -all: linux-arm64-openwrt linux-amd64-openwrt linux-arm64 linux-amd64 darwin-amd64 darwin-arm64 windows-amd64 windows-386 # Most used + +all: linux-arm64-AutoIptables linux-amd64-AutoIptables linux-arm64 linux-amd64 darwin-amd64 darwin-arm64 windows-amd64 windows-386 # Most used docker: $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ @@ -52,13 +43,13 @@ linux-386: linux-amd64: GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ -linux-amd64-openwrt: +linux-amd64-AutoIptables: GOARCH=amd64 GOOS=linux $(GOBUILDOP) -o $(BINDIR)/$(NAME)-$@ linux-arm64: GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ -linux-arm64-openwrt: +linux-arm64-AutoIptables: GOARCH=arm64 GOOS=linux $(GOBUILDOP) -o $(BINDIR)/$(NAME)-$@ linux-armv5: diff --git a/README.md b/README.md index 3f660768..4bff2dda 100644 --- a/README.md +++ b/README.md @@ -245,24 +245,25 @@ tproxy-port: 9898 tun: enable: false ``` -Create user given name `clash`. +Create user given name `Clash.Meta`. -Run Clash by user `clash` as a daemon. +Run Meta Kennel by user `Clash.Meta` as a daemon. Create the systemd configuration file at /etc/systemd/system/clash.service: + ``` [Unit] -Description=Clash daemon, A rule-based proxy in Go. +Description=Clash.Meta daemon, A rule-based proxy in Go. After=network.target [Service] Type=simple -User=clash -Group=clash +User=Clash.Meta +Group=Clash.Meta CapabilityBoundingSet=cap_net_admin AmbientCapabilities=cap_net_admin Restart=always -ExecStart=/usr/local/bin/clash -d /etc/clash +ExecStart=/usr/local/bin/Clash.Meta -d /etc/Clash.Meta [Install] WantedBy=multi-user.target diff --git a/constant/version.go b/constant/version.go index 9a604deb..15d59ffa 100644 --- a/constant/version.go +++ b/constant/version.go @@ -1,8 +1,8 @@ package constant var ( - Meta = true - Version = "1.8.0" - BuildTime = "unknown time" - OpenWrt bool + Meta = true + Version = "1.8.0" + BuildTime = "unknown time" + AutoIptables string ) diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 25d655c0..350609ac 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -289,7 +289,8 @@ 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 || C.OpenWrt { + AutoIptables := C.AutoIptables + if runtime.GOOS != "linux" || dns.Listen == "" || general.TProxyPort == 0 || general.Tun.Enable || AutoIptables != "Enable" { return } @@ -315,8 +316,8 @@ func updateIPTables(dns *config.DNS, general *config.General) { func CleanUp() { P.CleanUp() - - if runtime.GOOS == "linux" && C.OpenWrt { + AutoIptables := C.AutoIptables + if runtime.GOOS == "linux" && AutoIptables == "Enable" { tproxy.CleanUpTProxyLinuxIPTables() } } diff --git a/rule/process.go b/rule/process.go index 12a041ba..aa2a9129 100644 --- a/rule/process.go +++ b/rule/process.go @@ -28,7 +28,9 @@ func (ps *Process) Match(metadata *C.Metadata) bool { return strings.EqualFold(metadata.Process, ps.process) } // ignore match in proxy type "tproxy" - if metadata.Type == C.TPROXY || !C.OpenWrt { + //if metadata.Type == C.TPROXY || !C.AutoIptables { + + if C.AutoIptables == "Enable" { return false }