mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-03 23:22:23 -08:00
net/{captivedetection,netns}: bind captive portal probes to interfaces on Windows
Without this, we try to send probes through the Tailscale interface when an exit node is in use. The exit node is usually unreachable until the user signs in to the captive portal, so the probes get blackholed and we miss the portal. Updates #1634 Updates #17095 Updates tailscale/corp#21896 Change-Id: I124652d5a4e933089084f4317f7242c3e1470b99 Signed-off-by: Nick Khyl <[email protected]>
This commit is contained in:
1 parent
5ad3413af4
commit
94f41e9841
3 files changed
+26
-9
No files matched your search
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Tailscale Inc & contributors
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !(ios || darwin)
|
||||
//go:build !(ios || darwin || windows)
|
||||
|
||||
package captivedetection
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
// setSocketInterfaceIndex sets the IP_BOUND_IF socket option on the given RawConn.
|
||||
// This forces the socket to use the given interface.
|
||||
func setSocketInterfaceIndex(c syscall.RawConn, ifIndex int, logf logger.Logf) error {
|
||||
// No-op on non-Darwin platforms.
|
||||
func setSocketInterfaceIndex(syscall.RawConn, int, logger.Logf) error {
|
||||
// No-op on all platforms except Darwin and Windows.
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) Tailscale Inc & contributors
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build windows
|
||||
|
||||
package captivedetection
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
"tailscale.com/net/netns"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
func setSocketInterfaceIndex(c syscall.RawConn, ifIndex int, _ logger.Logf) error {
|
||||
return netns.BindSocket4(c, uint32(ifIndex))
|
||||
}
|
||||
@@ -97,13 +97,13 @@ func controlC(logf logger.Logf, netMon *netmon.Monitor, network, address string,
|
||||
}
|
||||
|
||||
if canV4 {
|
||||
if err := bindSocket4(c, ifaceIdxV4); err != nil {
|
||||
if err := BindSocket4(c, ifaceIdxV4); err != nil {
|
||||
return fmt.Errorf("bindSocket4(%d): %w", ifaceIdxV4, err)
|
||||
}
|
||||
}
|
||||
|
||||
if canV6 {
|
||||
if err := bindSocket6(c, ifaceIdxV6); err != nil {
|
||||
if err := BindSocket6(c, ifaceIdxV6); err != nil {
|
||||
return fmt.Errorf("bindSocket6(%d): %w", ifaceIdxV6, err)
|
||||
}
|
||||
}
|
||||
@@ -163,9 +163,9 @@ func interfaceIndexFor(addr netip.Addr) (uint32, error) {
|
||||
// and https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
|
||||
const sockoptBoundInterface = 31
|
||||
|
||||
// bindSocket4 binds the given RawConn to the network interface with
|
||||
// BindSocket4 binds the given RawConn to the network interface with
|
||||
// index ifidx, for IPv4 traffic only.
|
||||
func bindSocket4(c syscall.RawConn, ifidx uint32) error {
|
||||
func BindSocket4(c syscall.RawConn, ifidx uint32) error {
|
||||
// For IPv4 (but NOT IPv6) the interface index must be passed
|
||||
// as a big-endian integer (regardless of platform endianness)
|
||||
// because the underlying sockopt takes either an IPv4 address
|
||||
@@ -185,9 +185,9 @@ func bindSocket4(c syscall.RawConn, ifidx uint32) error {
|
||||
return controlErr
|
||||
}
|
||||
|
||||
// bindSocket6 binds the given RawConn to the network interface with
|
||||
// BindSocket6 binds the given RawConn to the network interface with
|
||||
// index ifidx, for IPv6 traffic only.
|
||||
func bindSocket6(c syscall.RawConn, ifidx uint32) error {
|
||||
func BindSocket6(c syscall.RawConn, ifidx uint32) error {
|
||||
var controlErr error
|
||||
err := c.Control(func(fd uintptr) {
|
||||
controlErr = windows.SetsockoptInt(windows.Handle(fd), windows.IPPROTO_IPV6, sockoptBoundInterface, int(ifidx))
|
||||
|
||||
Reference in new issue
Block a user