2021-03-26 20:44:55 +00:00
|
|
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-08-17 17:21:52 +00:00
|
|
|
//go:build ts_macext && (darwin || ios)
|
|
|
|
// +build ts_macext
|
|
|
|
// +build darwin ios
|
2021-03-26 20:44:55 +00:00
|
|
|
|
|
|
|
package ipnlocal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"tailscale.com/net/interfaces"
|
2022-07-25 03:08:42 +00:00
|
|
|
"tailscale.com/net/netaddr"
|
2021-06-23 04:53:43 +00:00
|
|
|
"tailscale.com/net/netns"
|
2021-03-26 20:44:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
initListenConfig = initListenConfigNetworkExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
// initListenConfigNetworkExtension configures nc for listening on IP
|
|
|
|
// through the iOS/macOS Network/System Extension (Packet Tunnel
|
|
|
|
// Provider) sandbox.
|
|
|
|
func initListenConfigNetworkExtension(nc *net.ListenConfig, ip netaddr.IP, st *interfaces.State, tunIfName string) error {
|
|
|
|
tunIf, ok := st.Interface[tunIfName]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("no interface with name %q", tunIfName)
|
|
|
|
}
|
2021-06-23 04:53:43 +00:00
|
|
|
return netns.SetListenConfigInterfaceIndex(nc, tunIf.Index)
|
2021-04-06 20:38:47 +00:00
|
|
|
}
|