[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)
endif
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.AutoIptables=$(AUTOIPTABLES)" \
-w -s -buildid='
PLATFORM_LIST = \
darwin-amd64 \
darwin-arm64 \
@ -43,8 +37,8 @@ WINDOWS_ARCH_LIST = \
windows-arm32v7
all:linux-amd64-AutoIptables linux-amd64\
linux-arm64 linux-arm64-AutoIptables linux-armv7\
all:linux-amd64\
linux-armv7\
darwin-amd64 darwin-arm64\
windows-amd64 windows-386 \
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"`
IPv6 bool `json:"ipv6"`
Interface string `json:"-"`
GeodataMode string `json:"geodata-mode"`
RoutingMark int `json:"-"`
GeodataMode bool `json:"geodata-mode"`
GeodataLoader string `json:"geodata-loader"`
AutoIptables bool `json:"auto-iptables"`
}
@ -173,10 +174,10 @@ type RawConfig struct {
ExternalUI string `yaml:"external-ui"`
Secret string `yaml:"secret"`
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"`
AutoIptables bool `yaml:"auto-iptables"`
RoutingMark int `yaml:"routing-mark"`
ProxyProvider map[string]map[string]interface{} `yaml:"proxy-providers"`
RuleProvider map[string]map[string]interface{} `yaml:"rule-providers"`
@ -207,7 +208,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
AllowLan: false,
BindAddress: "*",
Mode: T.Rule,
GeodataMode: "dat",
GeodataMode: GeodataMode,
GeodataLoader: "memconservative",
AutoIptables: false,
UnifiedDelay: false,
@ -350,9 +351,10 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
LogLevel: cfg.LogLevel,
IPv6: cfg.IPv6,
Interface: cfg.Interface,
RoutingMark: cfg.RoutingMark,
GeodataMode: cfg.GeodataMode,
GeodataLoader: cfg.GeodataLoader,
AutoIptables: cfg.AutoIptables,
RoutingMark: cfg.RoutingMark,
}, nil
}

View file

@ -15,7 +15,7 @@ import (
var GeodataMode bool
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 {
return
}
@ -32,7 +32,7 @@ func downloadMMDB(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 {
return
}
@ -49,7 +49,7 @@ func downloadGeoIP(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 {
return
}
@ -148,7 +148,6 @@ func Init(dir string) error {
f.Write([]byte(`mixed-port: 7890`))
f.Close()
}
// initial GeoIP
if err := initGeoIP(); err != nil {
return fmt.Errorf("can't initial GeoIP: %w", err)

View file

@ -3,9 +3,12 @@ package dns
import (
"github.com/Dreamacro/clash/component/geodata"
"github.com/Dreamacro/clash/component/geodata/router"
"github.com/Dreamacro/clash/component/mmdb"
"github.com/Dreamacro/clash/component/trie"
"github.com/Dreamacro/clash/config"
"github.com/Dreamacro/clash/log"
"net"
"strings"
)
type fallbackIPFilter interface {
@ -19,6 +22,11 @@ type geoipFilter struct {
var geoIPMatcher *router.GeoIPMatcher
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 {
countryCode := "cn"
geoLoader, err := geodata.GetGeoDataLoader(geodata.LoaderName())
@ -46,7 +54,6 @@ func (gf *geoipFilter) Match(ip net.IP) bool {
return false
}
}
return !geoIPMatcher.Match(ip)
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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