mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-04 16:37:12 -05:00
add errExpectedIPNonMatch and return nil if empty response
This commit is contained in:
parent
e916a3b29d
commit
1345185b81
@ -12,6 +12,7 @@ import (
|
|||||||
"v2ray.com/core"
|
"v2ray.com/core"
|
||||||
"v2ray.com/core/app/router"
|
"v2ray.com/core/app/router"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/session"
|
"v2ray.com/core/common/session"
|
||||||
"v2ray.com/core/common/strmatcher"
|
"v2ray.com/core/common/strmatcher"
|
||||||
@ -38,6 +39,8 @@ type MultiGeoIPMatcher struct {
|
|||||||
matchers []*router.GeoIPMatcher
|
matchers []*router.GeoIPMatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errExpectedIPNonMatch = errors.New("expected ip not match")
|
||||||
|
|
||||||
// Match check ip match
|
// Match check ip match
|
||||||
func (c *MultiGeoIPMatcher) Match(ip net.IP) bool {
|
func (c *MultiGeoIPMatcher) Match(ip net.IP) bool {
|
||||||
for _, matcher := range c.matchers {
|
for _, matcher := range c.matchers {
|
||||||
@ -178,11 +181,6 @@ func (s *Server) IsOwnLink(ctx context.Context) bool {
|
|||||||
|
|
||||||
// Match check dns ip match geoip
|
// Match check dns ip match geoip
|
||||||
func (s *Server) Match(idx uint32, client Client, domain string, ips []net.IP) ([]net.IP, error) {
|
func (s *Server) Match(idx uint32, client Client, domain string, ips []net.IP) ([]net.IP, error) {
|
||||||
if len(ips) == 0 {
|
|
||||||
newError("domain ", domain, " has empty response at server ", client.Name(), " idx:", idx).AtDebug().WriteToLog()
|
|
||||||
return nil, context.Canceled
|
|
||||||
}
|
|
||||||
|
|
||||||
matcher, exist := s.ipIndexMap[idx]
|
matcher, exist := s.ipIndexMap[idx]
|
||||||
if exist == false {
|
if exist == false {
|
||||||
newError("domain ", domain, " server not in ipIndexMap: ", client.Name(), " idx:", idx, " just return").AtDebug().WriteToLog()
|
newError("domain ", domain, " server not in ipIndexMap: ", client.Name(), " idx:", idx, " just return").AtDebug().WriteToLog()
|
||||||
@ -204,7 +202,7 @@ func (s *Server) Match(idx uint32, client Client, domain string, ips []net.IP) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(newIps) == 0 {
|
if len(newIps) == 0 {
|
||||||
return nil, context.Canceled
|
return nil, errExpectedIPNonMatch
|
||||||
}
|
}
|
||||||
return newIps, nil
|
return newIps, nil
|
||||||
}
|
}
|
||||||
@ -217,8 +215,13 @@ func (s *Server) queryIPTimeout(idx uint32, client Client, domain string, option
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
ips, err := client.QueryIP(ctx, domain, option)
|
ips, err := client.QueryIP(ctx, domain, option)
|
||||||
ips, err = s.Match(idx, client, domain, ips)
|
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ips, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ips, err = s.Match(idx, client, domain, ips)
|
||||||
return ips, err
|
return ips, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +327,7 @@ func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, err
|
|||||||
newError("failed to lookup ip for domain ", domain, " at server ", client.Name()).Base(err).WriteToLog()
|
newError("failed to lookup ip for domain ", domain, " at server ", client.Name()).Base(err).WriteToLog()
|
||||||
lastErr = err
|
lastErr = err
|
||||||
}
|
}
|
||||||
if err != context.Canceled && err != context.DeadlineExceeded {
|
if err != context.Canceled && err != context.DeadlineExceeded && err != errExpectedIPNonMatch {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ type NameServerConfig struct {
|
|||||||
Address *Address
|
Address *Address
|
||||||
Port uint16
|
Port uint16
|
||||||
Domains []string
|
Domains []string
|
||||||
IP StringList
|
ExpectIPs StringList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NameServerConfig) UnmarshalJSON(data []byte) error {
|
func (c *NameServerConfig) UnmarshalJSON(data []byte) error {
|
||||||
@ -29,13 +29,13 @@ func (c *NameServerConfig) UnmarshalJSON(data []byte) error {
|
|||||||
Address *Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Domains []string `json:"domains"`
|
Domains []string `json:"domains"`
|
||||||
IP StringList `json:"ip"`
|
ExpectIPs StringList `json:"expectIps"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(data, &advanced); err == nil {
|
if err := json.Unmarshal(data, &advanced); err == nil {
|
||||||
c.Address = advanced.Address
|
c.Address = advanced.Address
|
||||||
c.Port = advanced.Port
|
c.Port = advanced.Port
|
||||||
c.Domains = advanced.Domains
|
c.Domains = advanced.Domains
|
||||||
c.IP = advanced.IP
|
c.ExpectIPs = advanced.ExpectIPs
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,9 +78,9 @@ func (c *NameServerConfig) Build() (*dns.NameServer, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
geoipList, err := toCidrList(c.IP)
|
geoipList, err := toCidrList(c.ExpectIPs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("invalid ip rule: ", c.IP).Base(err)
|
return nil, newError("invalid ip rule: ", c.ExpectIPs).Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &dns.NameServer{
|
return &dns.NameServer{
|
||||||
|
Loading…
Reference in New Issue
Block a user