peerapi_macios_ext.go 757 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build ts_macext && (darwin || ios)
  4. package ipnlocal
  5. import (
  6. "fmt"
  7. "net"
  8. "net/netip"
  9. "tailscale.com/net/netmon"
  10. "tailscale.com/net/netns"
  11. )
  12. func init() {
  13. initListenConfig = initListenConfigNetworkExtension
  14. }
  15. // initListenConfigNetworkExtension configures nc for listening on IP
  16. // through the iOS/macOS Network/System Extension (Packet Tunnel
  17. // Provider) sandbox.
  18. func initListenConfigNetworkExtension(nc *net.ListenConfig, ip netip.Addr, st *netmon.State, tunIfName string) error {
  19. tunIf, ok := st.Interface[tunIfName]
  20. if !ok {
  21. return fmt.Errorf("no interface with name %q", tunIfName)
  22. }
  23. return netns.SetListenConfigInterfaceIndex(nc, tunIf.Index)
  24. }