2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-06-23 05:53:43 +01:00
|
|
|
|
2021-08-17 18:21:52 +01:00
|
|
|
//go:build ts_macext && (darwin || ios)
|
2021-06-23 05:53:43 +01:00
|
|
|
|
|
|
|
package resolver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"net"
|
|
|
|
|
2023-04-18 22:26:58 +01:00
|
|
|
"tailscale.com/net/netmon"
|
2021-06-23 05:53:43 +01:00
|
|
|
"tailscale.com/net/netns"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
initListenConfig = initListenConfigNetworkExtension
|
|
|
|
}
|
|
|
|
|
2023-04-18 00:01:41 +01:00
|
|
|
func initListenConfigNetworkExtension(nc *net.ListenConfig, netMon *netmon.Monitor, tunName string) error {
|
|
|
|
nif, ok := netMon.InterfaceState().Interface[tunName]
|
2021-06-23 05:53:43 +01:00
|
|
|
if !ok {
|
|
|
|
return errors.New("utun not found")
|
|
|
|
}
|
|
|
|
return netns.SetListenConfigInterfaceIndex(nc, nif.Interface.Index)
|
|
|
|
}
|