mirror of
https://github.com/safing/portmaster
synced 2025-09-01 10:09:11 +00:00
Fix my networks cache validation
This commit is contained in:
parent
6f9d17bba2
commit
edd0d6e834
2 changed files with 13 additions and 8 deletions
|
@ -51,8 +51,9 @@ func GetAssignedGlobalAddresses() (ipv4 []net.IP, ipv6 []net.IP, err error) {
|
|||
}
|
||||
|
||||
var (
|
||||
myNetworks []*net.IPNet
|
||||
myNetworksLock sync.Mutex
|
||||
myNetworks []*net.IPNet
|
||||
myNetworksLock sync.Mutex
|
||||
myNetworksNetworkChangedFlag = GetNetworkChangedFlag()
|
||||
)
|
||||
|
||||
// IsMyIP returns whether the given unicast IP is currently configured on the local host.
|
||||
|
@ -69,8 +70,12 @@ func IsMyIP(ip net.IP) (yes bool, err error) {
|
|||
myNetworksLock.Lock()
|
||||
defer myNetworksLock.Unlock()
|
||||
|
||||
// Check for match.
|
||||
if mine, matched := checkIfMyIP(ip); matched {
|
||||
// Check if the network changed.
|
||||
if myNetworksNetworkChangedFlag.IsSet() {
|
||||
// Reset changed flag.
|
||||
myNetworksNetworkChangedFlag.Refresh()
|
||||
} else if mine, matched := checkIfMyIP(ip); matched {
|
||||
// If the network did not change, check for match immediately.
|
||||
return mine, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ func init() {
|
|||
flag.BoolVar(&privileged, "privileged", false, "run tests that require root/admin privileges")
|
||||
}
|
||||
|
||||
func TestGetApproximateInternetLocation(t *testing.T) {
|
||||
func TestGetInternetLocation(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip()
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ func TestGetApproximateInternetLocation(t *testing.T) {
|
|||
t.Skip("skipping privileged test, active with -privileged argument")
|
||||
}
|
||||
|
||||
loc, err := GetInternetLocation()
|
||||
if err != nil {
|
||||
t.Fatalf("GetApproximateInternetLocation failed: %s", err)
|
||||
loc, ok := GetInternetLocation()
|
||||
if !ok {
|
||||
t.Fatal("GetApproximateInternetLocation failed")
|
||||
}
|
||||
t.Logf("GetApproximateInternetLocation: %+v", loc)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue