Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
修复issue #67: route 的 domain 多个 规则 写在 列表里时不会完全匹配到.
Browse files Browse the repository at this point in the history
  • Loading branch information
e1732a364fed committed May 8, 2022
1 parent b07b12c commit d4fe3a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ws(以及earlydata)/grpc(以及multiMode,uTls,以及 支持回落的 grpcSimpl

dns(udp/tls)/route(geoip/geosite)/fallback(path/sni/alpn/PROXY protocol v1/v2),

tcp/udp/unix domain socket, uTls, lazy, http伪装头,PROXY protocol v1/v2 监听, cli(交互模式)/apiServer
tcp/udp/unix domain socket, tls(包括客户端证书验证), uTls, lazy, http伪装头,PROXY protocol v1/v2 监听, cli(交互模式)/apiServer


为了不吓跑小白,本 README 把安装、使用方式 放在了前面,如果你要直接阅读本作的技术介绍部分,点击跳转 -> [创新点](#创新点)
Expand Down
4 changes: 2 additions & 2 deletions examples/multi.client.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ protocol = "direct"
fullcone = true

[[dial]]
tag = "my_hole"
protocol = "reject" # 和 v2ray的 blackhole 等价.
tag = "my_reject"
protocol = "reject" # reject 和 v2ray的 blackhole 等价.
# extra = { type = "http" } #当 type 为 "http"时, reject 会发回一个简单的 HTTP 403 数据包,然后关闭连接。

# route就是分流规则,分流规则从上到下匹配,匹配到哪一个就用哪一个.
Expand Down
30 changes: 18 additions & 12 deletions netLayer/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ type RouteSet struct {
NetRanger cidranger.Ranger //一个范围
IPs map[netip.Addr]bool //一个确定值

//Match 匹配任意字符串
//Domains匹配子域名,当此域名是目标域名或其子域名时,该规则生效
//Domains匹配子域名,当此域名是目标域名或其子域名时,该规则生效.
//Full只匹配完整域名
Domains, Full, InTags, Countries map[string]bool // Countries 使用 ISO 3166 字符串 作为key

//Regex是正则匹配域名
//Regex是正则匹配域名.
//Match 匹配任意字符串
Regex []*regexp.Regexp
Match, Geosites []string

Expand Down Expand Up @@ -139,25 +139,29 @@ func (sg *RouteSet) IsTCPAllowed() bool {
return sg.IsTransportProtocolAllowed(TCP)
}

func (sg *RouteSet) IsNoLimitForNetworkLayer() bool {
if (sg.NetRanger == nil || sg.NetRanger.Len() == 0) && len(sg.IPs) == 0 && len(sg.Match) == 0 && len(sg.Domains) == 0 && len(sg.Full) == 0 && len(sg.Countries) == 0 && len(sg.Geosites) == 0 {
//如果仅限制了一个传输层协议,且本集合里没有任何其它内容,那就直接通过
return true
}
return false
}

func (sg *RouteSet) IsAddrIn(a Addr) bool {
//我们先过滤传输层,再过滤网络层
//我们先过滤传输层,再过滤网络层, 因为传输层过滤非常简单。

if !sg.IsAddrNetworkAllowed(a) {
return false

} else if sg.NetRanger == nil && sg.IPs == nil && sg.Domains == nil && sg.Countries == nil {
//如果仅限制了一个传输层协议,且本集合里没有任何其它内容,那就直接通过
return true
}

//开始网络层判断
if len(a.IP) > 0 {
if sg.NetRanger != nil {
if sg.NetRanger != nil && sg.NetRanger.Len() > 0 {
if has, _ := sg.NetRanger.Contains(a.IP); has {
return true
}
}
if sg.Countries != nil {
if len(sg.Countries) > 0 {

if isoStr := GetIP_ISO(a.IP); isoStr != "" {
if _, found := sg.Countries[isoStr]; found {
Expand All @@ -166,7 +170,7 @@ func (sg *RouteSet) IsAddrIn(a Addr) bool {
}

}
if sg.IPs != nil {
if len(sg.IPs) > 0 {
if _, found := sg.IPs[a.GetNetIPAddr()]; found {
return true
}
Expand All @@ -183,7 +187,9 @@ func (sg *RouteSet) IsAddrIn(a Addr) bool {

if len(sg.Domains) > 0 {

return HasFullOrSubDomain(a.Name, MapDomainHaser(sg.Domains))
if HasFullOrSubDomain(a.Name, MapDomainHaser(sg.Domains)) {
return true
}

}

Expand Down

0 comments on commit d4fe3a7

Please sign in to comment.