mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29:12 +00:00
Fix network detection with multiple interfaces on same net
This commit is contained in:
parent
caa43f4167
commit
f78e516284
2 changed files with 16 additions and 15 deletions
|
@ -76,14 +76,15 @@ func IsMyIP(ip net.IP) (yes bool, err error) {
|
|||
// Check if current data matches IP.
|
||||
// Matching on somewhat older data is not a problem, as these IPs would not
|
||||
// just randomly pop up somewhere else that fast.
|
||||
mine, matched := checkIfMyIP(ip)
|
||||
if matched {
|
||||
return mine, nil
|
||||
}
|
||||
|
||||
// Check if the network changed.
|
||||
if !myNetworksNetworkChangedFlag.IsSet() {
|
||||
// Network did not change, return "no match".
|
||||
mine, myNet := checkIfMyIP(ip)
|
||||
switch {
|
||||
case mine:
|
||||
// IP matched.
|
||||
return true, nil
|
||||
case myNetworksNetworkChangedFlag.IsSet():
|
||||
// The network changed, so we need to refresh the data.
|
||||
case myNet:
|
||||
// IP is one of the networks and nothing changed, so this is not our IP.
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
@ -104,13 +105,13 @@ func IsMyIP(ip net.IP) (yes bool, err error) {
|
|||
}
|
||||
myNetworks = make([]*net.IPNet, 0, len(interfaceNetworks))
|
||||
for _, ifNet := range interfaceNetworks {
|
||||
net, ok := ifNet.(*net.IPNet)
|
||||
ipNet, ok := ifNet.(*net.IPNet)
|
||||
if !ok {
|
||||
log.Warningf("netenv: interface network of unexpected type %T", ifNet)
|
||||
continue
|
||||
}
|
||||
|
||||
myNetworks = append(myNetworks, net)
|
||||
myNetworks = append(myNetworks, ipNet)
|
||||
}
|
||||
|
||||
// Reset error.
|
||||
|
@ -126,7 +127,7 @@ func IsMyIP(ip net.IP) (yes bool, err error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
func checkIfMyIP(ip net.IP) (mine bool, matched bool) {
|
||||
func checkIfMyIP(ip net.IP) (mine bool, myNet bool) {
|
||||
// Check against assigned IPs.
|
||||
for _, myNet := range myNetworks {
|
||||
if ip.Equal(myNet.IP) {
|
||||
|
|
|
@ -40,8 +40,8 @@ serviceLoop:
|
|||
for {
|
||||
trigger := false
|
||||
|
||||
timeout := time.Minute
|
||||
if GetOnlineStatus() != StatusOnline {
|
||||
timeout := 15 * time.Second
|
||||
if !Online() {
|
||||
timeout = time.Second
|
||||
}
|
||||
// wait for trigger
|
||||
|
@ -62,7 +62,7 @@ serviceLoop:
|
|||
hasher := sha1.New() //nolint:gosec // not used for security
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.Warningf("environment: failed to get interfaces: %s", err)
|
||||
log.Warningf("netenv: failed to get interfaces: %s", err)
|
||||
continue
|
||||
}
|
||||
for _, iface := range interfaces {
|
||||
|
@ -72,7 +72,7 @@ serviceLoop:
|
|||
// log.Tracef("adding: %s", iface.Flags.String())
|
||||
addrs, err := iface.Addrs()
|
||||
if err != nil {
|
||||
log.Warningf("environment: failed to get addrs from interface %s: %s", iface.Name, err)
|
||||
log.Warningf("netenv: failed to get addrs from interface %s: %s", iface.Name, err)
|
||||
continue
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
|
|
Loading…
Add table
Reference in a new issue