diff --git a/app/router/condition_geoip.go b/app/router/condition_geoip.go index bf09c46d3..593069236 100644 --- a/app/router/condition_geoip.go +++ b/app/router/condition_geoip.go @@ -1,6 +1,8 @@ package router import ( + "sort" + "v2ray.com/core/common/net" "v2ray.com/core/common/serial" ) @@ -52,6 +54,9 @@ func (m *GeoIPMatcher) Init(cidrs []*CIDR) error { } } + cidrList := CIDRList(cidrs) + sort.Sort(&cidrList) + m.ip4 = make([]uint32, 0, ip4Count) m.prefix4 = make([]uint8, 0, ip4Count) m.ip6 = make([]ipv6, 0, ip6Count) diff --git a/app/router/condition_geoip_test.go b/app/router/condition_geoip_test.go index 7c522e49f..8a3784d2f 100644 --- a/app/router/condition_geoip_test.go +++ b/app/router/condition_geoip_test.go @@ -3,7 +3,6 @@ package router_test import ( "os" "path/filepath" - "sort" "testing" proto "github.com/golang/protobuf/proto" @@ -32,8 +31,6 @@ func TestGeoIPMatcher(t *testing.T) { {Ip: []byte{91, 108, 4, 0}, Prefix: 16}, } - sort.Sort(&cidrList) - matcher := &router.GeoIPMatcher{} common.Must(matcher.Init(cidrList)) diff --git a/app/router/config.proto b/app/router/config.proto index 631ded8c9..97b6a735d 100644 --- a/app/router/config.proto +++ b/app/router/config.proto @@ -71,18 +71,15 @@ message RoutingRule { // List of GeoIPs for target IP address matching. If this entry exists, the cidr above will have no effect. // GeoIP fields with the same country code are supposed to contain exactly same content. They will be merged during runtime. // For customized GeoIPs, please leave country code empty. - // The CIDR list in the GeoIP must be sorted beforehand. repeated GeoIP geoip = 10; v2ray.core.common.net.PortRange port_range = 4; v2ray.core.common.net.NetworkList network_list = 5; // List of CIDRs for source IP address matching. - // The list must be sorted beforehand. repeated CIDR source_cidr = 6 [deprecated = true]; // List of GeoIPs for source IP address matching. If this entry exists, the source_cidr above will have no effect. - // The CIDR list in the GeoIP must be sorted beforehand. repeated GeoIP source_geoip = 11; repeated string user_email = 7;