From 99dbe0e29de2980956ff823906bc5ac743dfcd72 Mon Sep 17 00:00:00 2001 From: sousa-chinensis <84500424+sousa-chinensis@users.noreply.github.com> Date: Thu, 20 May 2021 08:50:28 +0000 Subject: [PATCH 1/5] fix: change logic of domain strategy tunnel/router/client.go --- tunnel/router/client.go | 53 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/tunnel/router/client.go b/tunnel/router/client.go index 30874a7c0..7e684d891 100644 --- a/tunnel/router/client.go +++ b/tunnel/router/client.go @@ -131,45 +131,40 @@ type Client struct { } func (c *Client) Route(address *tunnel.Address) int { - policy := -1 - var err error - if c.domainStrategy == IPOnDemand { - address, err = newIPAddress(address) - if err != nil { - return c.defaultPolicy - } - } if address.AddressType == tunnel.DomainName { - for i := 0; i < 3; i++ { - if matchDomain(c.domains[i], address.DomainName) { - policy = i - break + if c.domainStrategy == IPOnDemand { + resolved_ip, err := newIPAddress(address) + if err == nil { + for i := Block; i <= Proxy; i++ { + if matchIP(c.cidrs[i], resolved_ip.IP) { + return i + } + } } } - } else { - for i := 0; i < 3; i++ { - if matchIP(c.cidrs[i], address.IP) { - policy = i - break + for i := Block; i <= Proxy; i++ { + if matchDomain(c.domains[i], address.DomainName) { + return i } } - } - if policy == -1 && c.domainStrategy == IPIfNonMatch { - address, err = newIPAddress(address) - if err != nil { - return c.defaultPolicy + if c.domainStrategy == IPIfNonMatch { + resolved_ip, err := newIPAddress(address) + if err == nil { + for i := Block; i <= Proxy; i++ { + if matchIP(c.cidrs[i], resolved_ip.IP) { + return i + } + } + } } - for i := 0; i < 3; i++ { + } else { + for i := Block; i <= Proxy; i++ { if matchIP(c.cidrs[i], address.IP) { - policy = i - break + return i } } } - if policy == -1 { - policy = c.defaultPolicy - } - return policy + return c.defaultPolicy } func (c *Client) DialConn(address *tunnel.Address, overlay tunnel.Tunnel) (tunnel.Conn, error) { From d2b2f9fd1fa81b0fd6b9356d3861ed7d84188965 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Thu, 20 May 2021 21:24:48 +0800 Subject: [PATCH 2/5] Fix variable name --- tunnel/router/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tunnel/router/client.go b/tunnel/router/client.go index 7e684d891..155621eb4 100644 --- a/tunnel/router/client.go +++ b/tunnel/router/client.go @@ -133,7 +133,7 @@ type Client struct { func (c *Client) Route(address *tunnel.Address) int { if address.AddressType == tunnel.DomainName { if c.domainStrategy == IPOnDemand { - resolved_ip, err := newIPAddress(address) + resolvedIP, err := newIPAddress(address) if err == nil { for i := Block; i <= Proxy; i++ { if matchIP(c.cidrs[i], resolved_ip.IP) { From 714c6e9a44c6cc444a39b8425117ca887ab474b5 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Thu, 20 May 2021 21:24:55 +0800 Subject: [PATCH 3/5] Fix variable name --- tunnel/router/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tunnel/router/client.go b/tunnel/router/client.go index 155621eb4..12228a39f 100644 --- a/tunnel/router/client.go +++ b/tunnel/router/client.go @@ -136,7 +136,7 @@ func (c *Client) Route(address *tunnel.Address) int { resolvedIP, err := newIPAddress(address) if err == nil { for i := Block; i <= Proxy; i++ { - if matchIP(c.cidrs[i], resolved_ip.IP) { + if matchIP(c.cidrs[i], resolvedIP.IP) { return i } } From 02d8cef73a2eb147ca7e9cd14a37acc4db417783 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Thu, 20 May 2021 21:25:01 +0800 Subject: [PATCH 4/5] Fix variable name --- tunnel/router/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tunnel/router/client.go b/tunnel/router/client.go index 12228a39f..922dc26ab 100644 --- a/tunnel/router/client.go +++ b/tunnel/router/client.go @@ -148,7 +148,7 @@ func (c *Client) Route(address *tunnel.Address) int { } } if c.domainStrategy == IPIfNonMatch { - resolved_ip, err := newIPAddress(address) + resolvedIP, err := newIPAddress(address) if err == nil { for i := Block; i <= Proxy; i++ { if matchIP(c.cidrs[i], resolved_ip.IP) { From 2bace312b3074e0f0a535e22e1a891789be0606d Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Thu, 20 May 2021 21:25:09 +0800 Subject: [PATCH 5/5] Fix variable name --- tunnel/router/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tunnel/router/client.go b/tunnel/router/client.go index 922dc26ab..7506e8ba8 100644 --- a/tunnel/router/client.go +++ b/tunnel/router/client.go @@ -151,7 +151,7 @@ func (c *Client) Route(address *tunnel.Address) int { resolvedIP, err := newIPAddress(address) if err == nil { for i := Block; i <= Proxy; i++ { - if matchIP(c.cidrs[i], resolved_ip.IP) { + if matchIP(c.cidrs[i], resolvedIP.IP) { return i } }