mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-28 07:19:08 +01:00
use direct mode only when in the same private /16 network
This commit is contained in:
@@ -340,13 +340,33 @@ func shouldUseProxy(pair *ice.CandidatePair, userspaceBind bool) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if isHostCandidateWithPrivateIP(pair.Local) && isHostCandidateWithPrivateIP(pair.Remote) {
|
if isHostCandidateWithPrivateIP(pair.Local) && isHostCandidateWithPrivateIP(pair.Remote) && isSameNetworkPrefix(pair) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isSameNetworkPrefix(pair *ice.CandidatePair) bool {
|
||||||
|
|
||||||
|
localIPStr, _, err := net.SplitHostPort(pair.Local.Address())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
remoteIPStr, _, err := net.SplitHostPort(pair.Remote.Address())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
localIP := net.ParseIP(localIPStr)
|
||||||
|
remoteIP := net.ParseIP(remoteIPStr)
|
||||||
|
if localIP == nil || remoteIP == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// only consider /16 networks
|
||||||
|
mask := net.IPMask{255, 255, 0, 0}
|
||||||
|
return localIP.Mask(mask).Equal(remoteIP.Mask(mask))
|
||||||
|
}
|
||||||
|
|
||||||
func isRelayCandidate(candidate ice.Candidate) bool {
|
func isRelayCandidate(candidate ice.Candidate) bool {
|
||||||
return candidate.Type() == ice.CandidateTypeRelay
|
return candidate.Type() == ice.CandidateTypeRelay
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user