Browse Source

sort cidr list before use

Darien Raymond 7 years ago
parent
commit
5400153827
3 changed files with 5 additions and 6 deletions
  1. 5 0
      app/router/condition_geoip.go
  2. 0 3
      app/router/condition_geoip_test.go
  3. 0 3
      app/router/config.proto

+ 5 - 0
app/router/condition_geoip.go

@@ -1,6 +1,8 @@
 package router
 package router
 
 
 import (
 import (
+	"sort"
+
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/serial"
 	"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.ip4 = make([]uint32, 0, ip4Count)
 	m.prefix4 = make([]uint8, 0, ip4Count)
 	m.prefix4 = make([]uint8, 0, ip4Count)
 	m.ip6 = make([]ipv6, 0, ip6Count)
 	m.ip6 = make([]ipv6, 0, ip6Count)

+ 0 - 3
app/router/condition_geoip_test.go

@@ -3,7 +3,6 @@ package router_test
 import (
 import (
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
-	"sort"
 	"testing"
 	"testing"
 
 
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
@@ -32,8 +31,6 @@ func TestGeoIPMatcher(t *testing.T) {
 		{Ip: []byte{91, 108, 4, 0}, Prefix: 16},
 		{Ip: []byte{91, 108, 4, 0}, Prefix: 16},
 	}
 	}
 
 
-	sort.Sort(&cidrList)
-
 	matcher := &router.GeoIPMatcher{}
 	matcher := &router.GeoIPMatcher{}
 	common.Must(matcher.Init(cidrList))
 	common.Must(matcher.Init(cidrList))
 
 

+ 0 - 3
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.
   // 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.
   // 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.
   // For customized GeoIPs, please leave country code empty.
-  // The CIDR list in the GeoIP must be sorted beforehand.
   repeated GeoIP geoip = 10;
   repeated GeoIP geoip = 10;
 
 
   v2ray.core.common.net.PortRange port_range = 4;
   v2ray.core.common.net.PortRange port_range = 4;
   v2ray.core.common.net.NetworkList network_list = 5;
   v2ray.core.common.net.NetworkList network_list = 5;
 
 
   // List of CIDRs for source IP address matching.
   // List of CIDRs for source IP address matching.
-  // The list must be sorted beforehand.
   repeated CIDR source_cidr = 6 [deprecated = true];
   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.
   // 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 GeoIP source_geoip = 11;
 
 
   repeated string user_email = 7;
   repeated string user_email = 7;