mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-28 15:29:09 +01:00
[ios] Ensure route settlement on iOS before handling DNS responses (#5360)
* Ensure route settlement on iOS before handling DNS responses to prevent bypassing the tunnel. * add more logs * rollback debug changes * rollback changes * [client] Improve logging and add comments for iOS route settlement logic - Switch iOS route settlement log level from Debug to Trace for finer control. - Add clarifying comments for `waitForRouteSettlement` on non-iOS platforms. --------- Co-authored-by: mlsmaycon <mlsmaycon@gmail.com>
This commit is contained in:
@@ -28,8 +28,8 @@ import (
|
|||||||
"github.com/netbirdio/netbird/client/firewall"
|
"github.com/netbirdio/netbird/client/firewall"
|
||||||
firewallManager "github.com/netbirdio/netbird/client/firewall/manager"
|
firewallManager "github.com/netbirdio/netbird/client/firewall/manager"
|
||||||
"github.com/netbirdio/netbird/client/iface"
|
"github.com/netbirdio/netbird/client/iface"
|
||||||
nbnetstack "github.com/netbirdio/netbird/client/iface/netstack"
|
|
||||||
"github.com/netbirdio/netbird/client/iface/device"
|
"github.com/netbirdio/netbird/client/iface/device"
|
||||||
|
nbnetstack "github.com/netbirdio/netbird/client/iface/netstack"
|
||||||
"github.com/netbirdio/netbird/client/iface/udpmux"
|
"github.com/netbirdio/netbird/client/iface/udpmux"
|
||||||
"github.com/netbirdio/netbird/client/internal/acl"
|
"github.com/netbirdio/netbird/client/internal/acl"
|
||||||
"github.com/netbirdio/netbird/client/internal/debug"
|
"github.com/netbirdio/netbird/client/internal/debug"
|
||||||
|
|||||||
@@ -351,6 +351,11 @@ func (d *DnsInterceptor) writeMsg(w dns.ResponseWriter, r *dns.Msg, logger *log.
|
|||||||
logger.Errorf("failed to update domain prefixes: %v", err)
|
logger.Errorf("failed to update domain prefixes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow time for route changes to be applied before sending
|
||||||
|
// the DNS response (relevant on iOS where setTunnelNetworkSettings
|
||||||
|
// is asynchronous).
|
||||||
|
waitForRouteSettlement(logger)
|
||||||
|
|
||||||
d.replaceIPsInDNSResponse(r, newPrefixes, logger)
|
d.replaceIPsInDNSResponse(r, newPrefixes, logger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
//go:build ios
|
||||||
|
|
||||||
|
package dnsinterceptor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
const routeSettleDelay = 500 * time.Millisecond
|
||||||
|
|
||||||
|
// waitForRouteSettlement introduces a short delay on iOS to allow
|
||||||
|
// setTunnelNetworkSettings to apply route changes before the DNS
|
||||||
|
// response reaches the application. Without this, the first request
|
||||||
|
// to a newly resolved domain may bypass the tunnel.
|
||||||
|
func waitForRouteSettlement(logger *log.Entry) {
|
||||||
|
logger.Tracef("waiting %v for iOS route settlement", routeSettleDelay)
|
||||||
|
time.Sleep(routeSettleDelay)
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
//go:build !ios
|
||||||
|
|
||||||
|
package dnsinterceptor
|
||||||
|
|
||||||
|
import log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
func waitForRouteSettlement(_ *log.Entry) {
|
||||||
|
// No-op on non-iOS platforms: route changes are applied synchronously by
|
||||||
|
// the kernel, so no settlement delay is needed before the DNS response
|
||||||
|
// reaches the application. The delay is only required on iOS where
|
||||||
|
// setTunnelNetworkSettings applies routes asynchronously.
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user