[build test]

This commit is contained in:
MetaCubeX 2022-03-16 00:43:08 +08:00
parent f01ac69654
commit 1034780e8e
15 changed files with 70 additions and 25 deletions

View file

@ -6,16 +6,10 @@ ifeq ($(BRANCH),Alpha)
VERSION=alpha-$(shell git rev-parse --short HEAD) VERSION=alpha-$(shell git rev-parse --short HEAD)
endif endif
BUILDTIME=$(shell date -u) BUILDTIME=$(shell date -u)
AUTOIPTABLES=Enable
GOBUILD=CGO_ENABLED=0 go build -trimpath -ldflags '-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \ GOBUILD=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.BuildTime=$(BUILDTIME)" \
-w -s -buildid=' -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.AutoIptables=$(AUTOIPTABLES)" \
-w -s -buildid='
PLATFORM_LIST = \ PLATFORM_LIST = \
darwin-amd64 \ darwin-amd64 \
darwin-arm64 \ darwin-arm64 \
@ -43,8 +37,8 @@ WINDOWS_ARCH_LIST = \
windows-arm32v7 windows-arm32v7
all:linux-amd64-AutoIptables linux-amd64\ all:linux-amd64\
linux-arm64 linux-arm64-AutoIptables linux-armv7\ linux-armv7\
darwin-amd64 darwin-arm64\ darwin-amd64 darwin-arm64\
windows-amd64 windows-386 \ windows-amd64 windows-386 \
linux-mips-hardfloat linux-mips-softfloat linux-mips64 linux-mips64le linux-mipsle-hardfloat linux-mipsle-softfloat# Most used linux-mips-hardfloat linux-mips-softfloat linux-mips64 linux-mips64le linux-mipsle-hardfloat linux-mipsle-softfloat# Most used

View file

@ -41,7 +41,8 @@ type General struct {
LogLevel log.LogLevel `json:"log-level"` LogLevel log.LogLevel `json:"log-level"`
IPv6 bool `json:"ipv6"` IPv6 bool `json:"ipv6"`
Interface string `json:"-"` Interface string `json:"-"`
GeodataMode string `json:"geodata-mode"` RoutingMark int `json:"-"`
GeodataMode bool `json:"geodata-mode"`
GeodataLoader string `json:"geodata-loader"` GeodataLoader string `json:"geodata-loader"`
AutoIptables bool `json:"auto-iptables"` AutoIptables bool `json:"auto-iptables"`
} }
@ -173,10 +174,10 @@ type RawConfig struct {
ExternalUI string `yaml:"external-ui"` ExternalUI string `yaml:"external-ui"`
Secret string `yaml:"secret"` Secret string `yaml:"secret"`
Interface string `yaml:"interface-name"` Interface string `yaml:"interface-name"`
GeodataMode string `yaml:"geodata-mode"` RoutingMark int `yaml:"routing-mark"`
GeodataMode bool `yaml:"geodata-mode"`
GeodataLoader string `yaml:"geodata-loader"` GeodataLoader string `yaml:"geodata-loader"`
AutoIptables bool `yaml:"auto-iptables"` AutoIptables bool `yaml:"auto-iptables"`
RoutingMark int `yaml:"routing-mark"`
ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"` ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"`
RuleProvider map[string]map[string]interface{} `yaml:"rule-providers"` RuleProvider map[string]map[string]interface{} `yaml:"rule-providers"`
@ -207,7 +208,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
AllowLan: false, AllowLan: false,
BindAddress: "*", BindAddress: "*",
Mode: T.Rule, Mode: T.Rule,
GeodataMode: "dat", GeodataMode: GeodataMode,
GeodataLoader: "memconservative", GeodataLoader: "memconservative",
AutoIptables: false, AutoIptables: false,
UnifiedDelay: false, UnifiedDelay: false,
@ -350,9 +351,10 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
LogLevel: cfg.LogLevel, LogLevel: cfg.LogLevel,
IPv6: cfg.IPv6, IPv6: cfg.IPv6,
Interface: cfg.Interface, Interface: cfg.Interface,
RoutingMark: cfg.RoutingMark,
GeodataMode: cfg.GeodataMode,
GeodataLoader: cfg.GeodataLoader, GeodataLoader: cfg.GeodataLoader,
AutoIptables: cfg.AutoIptables, AutoIptables: cfg.AutoIptables,
RoutingMark: cfg.RoutingMark,
}, nil }, nil
} }

View file

@ -15,7 +15,7 @@ import (
var GeodataMode bool var GeodataMode bool
func downloadMMDB(path string) (err error) { func downloadMMDB(path string) (err error) {
resp, err := http.Get("https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country.mmdb") resp, err := http.Get("https://raw.githubusercontents.com/Loyalsoldier/geoip/release/Country.mmdb")
if err != nil { if err != nil {
return return
} }
@ -32,7 +32,7 @@ func downloadMMDB(path string) (err error) {
} }
func downloadGeoIP(path string) (err error) { func downloadGeoIP(path string) (err error) {
resp, err := http.Get("https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geoip.dat") resp, err := http.Get("https://raw.githubusercontents.com/Loyalsoldier/v2ray-rules-dat/release/geoip.dat")
if err != nil { if err != nil {
return return
} }
@ -49,7 +49,7 @@ func downloadGeoIP(path string) (err error) {
} }
func downloadGeoSite(path string) (err error) { func downloadGeoSite(path string) (err error) {
resp, err := http.Get("https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geosite.dat") resp, err := http.Get("https://raw.githubusercontents.com/Loyalsoldier/v2ray-rules-dat/release/geosite.dat")
if err != nil { if err != nil {
return return
} }
@ -148,7 +148,6 @@ func Init(dir string) error {
f.Write([]byte(`mixed-port: 7890`)) f.Write([]byte(`mixed-port: 7890`))
f.Close() f.Close()
} }
// initial GeoIP // initial GeoIP
if err := initGeoIP(); err != nil { if err := initGeoIP(); err != nil {
return fmt.Errorf("can't initial GeoIP: %w", err) return fmt.Errorf("can't initial GeoIP: %w", err)

View file

@ -3,9 +3,12 @@ package dns
import ( import (
"github.com/Dreamacro/clash/component/geodata" "github.com/Dreamacro/clash/component/geodata"
"github.com/Dreamacro/clash/component/geodata/router" "github.com/Dreamacro/clash/component/geodata/router"
"github.com/Dreamacro/clash/component/mmdb"
"github.com/Dreamacro/clash/component/trie" "github.com/Dreamacro/clash/component/trie"
"github.com/Dreamacro/clash/config"
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
"net" "net"
"strings"
) )
type fallbackIPFilter interface { type fallbackIPFilter interface {
@ -19,6 +22,11 @@ type geoipFilter struct {
var geoIPMatcher *router.GeoIPMatcher var geoIPMatcher *router.GeoIPMatcher
func (gf *geoipFilter) Match(ip net.IP) bool { func (gf *geoipFilter) Match(ip net.IP) bool {
if !config.GeodataMode {
record, _ := mmdb.Instance().Country(ip)
return !strings.EqualFold(record.Country.IsoCode, gf.code) && !ip.IsPrivate()
}
if geoIPMatcher == nil { if geoIPMatcher == nil {
countryCode := "cn" countryCode := "cn"
geoLoader, err := geodata.GetGeoDataLoader(geodata.LoaderName()) geoLoader, err := geodata.GetGeoDataLoader(geodata.LoaderName())
@ -46,7 +54,6 @@ func (gf *geoipFilter) Match(ip net.IP) bool {
return false return false
} }
} }
return !geoIPMatcher.Match(ip) return !geoIPMatcher.Match(ip)
} }

View file

@ -73,12 +73,12 @@ func main() {
C.SetConfig(configFile) C.SetConfig(configFile)
} }
if err := config.Init(C.Path.HomeDir()); err != nil { if geodataMode || executor.GetGeneral().GeodataMode {
log.Fatalln("Initial configuration directory error: %s", err.Error()) config.GeodataMode = true
} }
if geodataMode { if err := config.Init(C.Path.HomeDir()); err != nil {
config.GeodataMode = true log.Fatalln("Initial configuration directory error: %s", err.Error())
} }
if testConfig { if testConfig {

View file

@ -44,7 +44,7 @@ func (dk *DomainKeyword) RuleExtra() *C.RuleExtra {
return dk.ruleExtra return dk.ruleExtra
} }
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword { func NewDomainKeyword(keyword string, adapter string, ruleExtra *C.RuleExtra) *DomainKeyword {
return &DomainKeyword{ return &DomainKeyword{
keyword: strings.ToLower(keyword), keyword: strings.ToLower(keyword),
adapter: adapter, adapter: adapter,

View file

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"github.com/Dreamacro/clash/component/geodata" "github.com/Dreamacro/clash/component/geodata"
"github.com/Dreamacro/clash/component/geodata/router" "github.com/Dreamacro/clash/component/geodata/router"
"github.com/Dreamacro/clash/component/mmdb"
"github.com/Dreamacro/clash/config"
"strings" "strings"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
@ -18,6 +20,10 @@ type GEOIP struct {
geoIPMatcher *router.GeoIPMatcher geoIPMatcher *router.GeoIPMatcher
} }
func (g *GEOIP) ShouldFindProcess() bool {
return false
}
func (g *GEOIP) RuleType() C.RuleType { func (g *GEOIP) RuleType() C.RuleType {
return C.GEOIP return C.GEOIP
} }
@ -31,7 +37,10 @@ func (g *GEOIP) Match(metadata *C.Metadata) bool {
if strings.EqualFold(g.country, "LAN") || C.TunBroadcastAddr.Equal(ip) { if strings.EqualFold(g.country, "LAN") || C.TunBroadcastAddr.Equal(ip) {
return ip.IsPrivate() return ip.IsPrivate()
} }
if !config.GeodataMode {
record, _ := mmdb.Instance().Country(ip)
return strings.EqualFold(record.Country.IsoCode, g.country)
}
return g.geoIPMatcher.Match(ip) return g.geoIPMatcher.Match(ip)
} }

View file

@ -44,6 +44,10 @@ func (gs *GEOSITE) ShouldResolveIP() bool {
return false return false
} }
func (gs *GEOSITE) ShouldFindProcess() bool {
return false
}
func (gs *GEOSITE) RuleExtra() *C.RuleExtra { func (gs *GEOSITE) RuleExtra() *C.RuleExtra {
return gs.ruleExtra return gs.ruleExtra
} }

View file

@ -11,6 +11,10 @@ type NetworkType struct {
adapter string adapter string
} }
func (n *NetworkType) ShouldFindProcess() bool {
return false
}
func NewNetworkType(network, adapter string) (*NetworkType, error) { func NewNetworkType(network, adapter string) (*NetworkType, error) {
ntType := new(NetworkType) ntType := new(NetworkType)
ntType.adapter = adapter ntType.adapter = adapter

View file

@ -21,6 +21,10 @@ type Port struct {
ruleExtra *C.RuleExtra ruleExtra *C.RuleExtra
} }
func (p *Port) ShouldFindProcess() bool {
return false
}
func (p *Port) RuleType() C.RuleType { func (p *Port) RuleType() C.RuleType {
if p.isSource { if p.isSource {
return C.SrcPort return C.SrcPort

View file

@ -16,9 +16,14 @@ var processCache = cache.NewLRUCache(cache.WithAge(2), cache.WithSize(64))
type Process struct { type Process struct {
adapter string adapter string
process string process string
nameOnly bool
ruleExtra *C.RuleExtra ruleExtra *C.RuleExtra
} }
func (ps *Process) ShouldFindProcess() bool {
return false
}
func (ps *Process) RuleType() C.RuleType { func (ps *Process) RuleType() C.RuleType {
return C.Process return C.Process
} }
@ -70,10 +75,11 @@ func (ps *Process) RuleExtra() *C.RuleExtra {
return ps.ruleExtra return ps.ruleExtra
} }
func NewProcess(process string, adapter string, ruleExtra *C.RuleExtra) (*Process, error) { func NewProcess(process string, adapter string, nameOnly bool, ruleExtra *C.RuleExtra) (*Process, error) {
return &Process{ return &Process{
adapter: adapter, adapter: adapter,
process: process, process: process,
nameOnly: nameOnly,
ruleExtra: ruleExtra, ruleExtra: ruleExtra,
}, nil }, nil
} }

View file

@ -9,6 +9,10 @@ type AND struct {
needIP bool needIP bool
} }
func (A *AND) ShouldFindProcess() bool {
return false
}
func NewAND(payload string, adapter string) (*AND, error) { func NewAND(payload string, adapter string) (*AND, error) {
and := &AND{payload: payload, adapter: adapter} and := &AND{payload: payload, adapter: adapter}
rules, err := parseRuleByPayload(payload) rules, err := parseRuleByPayload(payload)

View file

@ -11,6 +11,10 @@ type NOT struct {
adapter string adapter string
} }
func (not *NOT) ShouldFindProcess() bool {
return false
}
func NewNOT(payload string, adapter string) (*NOT, error) { func NewNOT(payload string, adapter string) (*NOT, error) {
not := &NOT{payload: payload, adapter: adapter} not := &NOT{payload: payload, adapter: adapter}
rule, err := parseRuleByPayload(payload) rule, err := parseRuleByPayload(payload)

View file

@ -9,6 +9,10 @@ type OR struct {
needIP bool needIP bool
} }
func (or *OR) ShouldFindProcess() bool {
return false
}
func (or *OR) RuleType() C.RuleType { func (or *OR) RuleType() C.RuleType {
return C.OR return C.OR
} }

View file

@ -13,6 +13,10 @@ type RuleSet struct {
ruleExtra *C.RuleExtra ruleExtra *C.RuleExtra
} }
func (rs *RuleSet) ShouldFindProcess() bool {
return false
}
func (rs *RuleSet) RuleType() C.RuleType { func (rs *RuleSet) RuleType() C.RuleType {
return C.RuleSet return C.RuleSet
} }