1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-18 05:25:23 +00:00
This commit is contained in:
Darien Raymond 2018-11-01 10:39:03 +01:00
parent c73e899f54
commit 15cd999ed3
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 22 additions and 4 deletions

View File

@ -153,6 +153,7 @@ func (m *GeoIPMatcher) match6(ip ipv6) bool {
return normalize6(ip, m.prefix6[l]) == m.ip6[l]
}
// Match returns true if the given ip is included by the GeoIP.
func (m *GeoIPMatcher) Match(ip net.IP) bool {
switch len(ip) {
case 4:
@ -167,11 +168,14 @@ func (m *GeoIPMatcher) Match(ip net.IP) bool {
}
}
type GlobalGeoIPContainer struct {
// GeoIPMatcherContainer is a container for GeoIPMatchers. It keeps unique copies of GeoIPMatcher by country code.
type GeoIPMatcherContainer struct {
matchers []*GeoIPMatcher
}
func (c *GlobalGeoIPContainer) Add(geoip *GeoIP) (*GeoIPMatcher, error) {
// Add adds a new GeoIP set into the container.
// If the country code of GeoIP is not empty, GeoIPMatcherContainer will try to find an existing one, instead of adding a new one.
func (c *GeoIPMatcherContainer) Add(geoip *GeoIP) (*GeoIPMatcher, error) {
if len(geoip.CountryCode) > 0 {
for _, m := range c.matchers {
if m.countryCode == geoip.CountryCode {
@ -193,5 +197,5 @@ func (c *GlobalGeoIPContainer) Add(geoip *GeoIP) (*GeoIPMatcher, error) {
}
var (
globalGeoIPContainer GlobalGeoIPContainer
globalGeoIPContainer GeoIPMatcherContainer
)

View File

@ -6,12 +6,15 @@ import (
"v2ray.com/core/common/net"
)
// CIDRList is an alias of []*CIDR to provide sort.Interface.
type CIDRList []*CIDR
// Len implements sort.Interface.
func (l *CIDRList) Len() int {
return len(*l)
}
// Less implements sort.Interface.
func (l *CIDRList) Less(i int, j int) bool {
ci := (*l)[i]
cj := (*l)[j]
@ -37,6 +40,7 @@ func (l *CIDRList) Less(i int, j int) bool {
return ci.Prefix < cj.Prefix
}
// Swap implements sort.Interface.
func (l *CIDRList) Swap(i int, j int) {
(*l)[i], (*l)[j] = (*l)[j], (*l)[i]
}

View File

@ -362,17 +362,25 @@ func (m *GeoSiteList) GetEntry() []*GeoSite {
}
type RoutingRule struct {
Tag string `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"`
// Tag of outbound that this rule is pointing to.
Tag string `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"`
// List of domains for target domain matching.
Domain []*Domain `protobuf:"bytes,2,rep,name=domain,proto3" json:"domain,omitempty"`
// List of CIDRs for target IP address matching.
// The list must be sorted beforehand.
Cidr []*CIDR `protobuf:"bytes,3,rep,name=cidr,proto3" json:"cidr,omitempty"` // Deprecated: Do not use.
// 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.
Geoip []*GeoIP `protobuf:"bytes,10,rep,name=geoip,proto3" json:"geoip,omitempty"`
PortRange *net.PortRange `protobuf:"bytes,4,opt,name=port_range,json=portRange,proto3" json:"port_range,omitempty"`
NetworkList *net.NetworkList `protobuf:"bytes,5,opt,name=network_list,json=networkList,proto3" json:"network_list,omitempty"`
// List of CIDRs for source IP address matching.
// The list must be sorted beforehand.
SourceCidr []*CIDR `protobuf:"bytes,6,rep,name=source_cidr,json=sourceCidr,proto3" json:"source_cidr,omitempty"` // Deprecated: Do not use.
// 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.
SourceGeoip []*GeoIP `protobuf:"bytes,11,rep,name=source_geoip,json=sourceGeoip,proto3" json:"source_geoip,omitempty"`
UserEmail []string `protobuf:"bytes,7,rep,name=user_email,json=userEmail,proto3" json:"user_email,omitempty"`
InboundTag []string `protobuf:"bytes,8,rep,name=inbound_tag,json=inboundTag,proto3" json:"inbound_tag,omitempty"`

View File

@ -60,6 +60,8 @@ message GeoSiteList{
message RoutingRule {
// Tag of outbound that this rule is pointing to.
string tag = 1;
// List of domains for target domain matching.
repeated Domain domain = 2;
// List of CIDRs for target IP address matching.