diff --git a/common/geodata/consts.go b/common/geodata/consts.go new file mode 100644 index 000000000..d90bc07c7 --- /dev/null +++ b/common/geodata/consts.go @@ -0,0 +1,26 @@ +package geodata + +import ( + "github.com/xtls/xray-core/common" +) + +var PrivateIPMatcher = common.Must2(IPReg.BuildIPMatcher(common.Must2(ParseIPRules([]string{ + "0.0.0.0/8", + "10.0.0.0/8", + "100.64.0.0/10", + "127.0.0.0/8", + "169.254.0.0/16", + "172.16.0.0/12", + "192.0.0.0/24", + "192.0.2.0/24", + "192.88.99.0/24", + "192.168.0.0/16", + "198.18.0.0/15", + "198.51.100.0/24", + "203.0.113.0/24", + "224.0.0.0/3", + "::/127", + "fc00::/7", + "fe80::/10", + "ff00::/8", +})))) diff --git a/infra/conf/xray.go b/infra/conf/xray.go index 552548272..3fc998d89 100644 --- a/infra/conf/xray.go +++ b/infra/conf/xray.go @@ -241,8 +241,6 @@ type OutboundDetourConfig struct { TargetStrategy string `json:"targetStrategy"` } -var privateIPMatcher = geodata.NewPrivateIPMatcher() - func (c *OutboundDetourConfig) checkChainProxyConfig() error { if c.StreamSetting == nil || c.ProxySettings == nil || c.StreamSetting.SocketSettings == nil { return nil @@ -257,7 +255,7 @@ func isInternalOrInvalidAddress(address *Address) bool { if address == nil || address.Address == nil || !address.Family().IsIP() { return true } - return privateIPMatcher.Match(address.IP()) + return geodata.PrivateIPMatcher.Match(address.IP()) } func (c *OutboundDetourConfig) checkOutboundTLSConflict(rawConfig interface{}, senderSettings *proxyman.SenderConfig) error { diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 7015a380e..833e26a90 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -62,7 +62,7 @@ func init() { defaultBlockPrivateRule = &FinalRule{ action: RuleAction_Block, network: allNetworks, - ip: geodata.NewPrivateIPMatcher(), + ip: geodata.PrivateIPMatcher, } defaultBlockAllRule = &FinalRule{