1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-09 09:20:45 +00:00

sort cidr list before use

This commit is contained in:
Darien Raymond 2018-11-01 21:30:36 +01:00
parent de384a4ee4
commit 5400153827
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 5 additions and 6 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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;