endpoint.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. package tailscale
  2. import (
  3. "context"
  4. "crypto/tls"
  5. "fmt"
  6. "net"
  7. "net/http"
  8. "net/netip"
  9. "net/url"
  10. "os"
  11. "path/filepath"
  12. "reflect"
  13. "runtime"
  14. "strings"
  15. "sync/atomic"
  16. "syscall"
  17. "time"
  18. "github.com/sagernet/gvisor/pkg/tcpip"
  19. "github.com/sagernet/gvisor/pkg/tcpip/adapters/gonet"
  20. "github.com/sagernet/gvisor/pkg/tcpip/header"
  21. "github.com/sagernet/gvisor/pkg/tcpip/stack"
  22. "github.com/sagernet/gvisor/pkg/tcpip/transport/tcp"
  23. "github.com/sagernet/gvisor/pkg/tcpip/transport/udp"
  24. "github.com/sagernet/sing-box/adapter"
  25. "github.com/sagernet/sing-box/adapter/endpoint"
  26. "github.com/sagernet/sing-box/common/dialer"
  27. C "github.com/sagernet/sing-box/constant"
  28. "github.com/sagernet/sing-box/experimental/libbox/platform"
  29. "github.com/sagernet/sing-box/log"
  30. "github.com/sagernet/sing-box/option"
  31. "github.com/sagernet/sing-tun"
  32. "github.com/sagernet/sing/common"
  33. "github.com/sagernet/sing/common/bufio"
  34. "github.com/sagernet/sing/common/control"
  35. E "github.com/sagernet/sing/common/exceptions"
  36. F "github.com/sagernet/sing/common/format"
  37. "github.com/sagernet/sing/common/logger"
  38. M "github.com/sagernet/sing/common/metadata"
  39. N "github.com/sagernet/sing/common/network"
  40. "github.com/sagernet/sing/service"
  41. "github.com/sagernet/sing/service/filemanager"
  42. "github.com/sagernet/tailscale/ipn"
  43. tsDNS "github.com/sagernet/tailscale/net/dns"
  44. "github.com/sagernet/tailscale/net/netmon"
  45. "github.com/sagernet/tailscale/net/tsaddr"
  46. "github.com/sagernet/tailscale/tsnet"
  47. "github.com/sagernet/tailscale/types/ipproto"
  48. "github.com/sagernet/tailscale/version"
  49. "github.com/sagernet/tailscale/wgengine"
  50. "github.com/sagernet/tailscale/wgengine/filter"
  51. "github.com/sagernet/tailscale/wgengine/router"
  52. "github.com/sagernet/tailscale/wgengine/wgcfg"
  53. "go4.org/netipx"
  54. )
  55. var _ adapter.OutboundWithPreferredRoutes = (*Endpoint)(nil)
  56. func init() {
  57. version.SetVersion("sing-box " + C.Version)
  58. }
  59. func RegisterEndpoint(registry *endpoint.Registry) {
  60. endpoint.Register[option.TailscaleEndpointOptions](registry, C.TypeTailscale, NewEndpoint)
  61. }
  62. type Endpoint struct {
  63. endpoint.Adapter
  64. ctx context.Context
  65. router adapter.Router
  66. logger logger.ContextLogger
  67. dnsRouter adapter.DNSRouter
  68. network adapter.NetworkManager
  69. platformInterface platform.Interface
  70. server *tsnet.Server
  71. stack *stack.Stack
  72. filter *atomic.Pointer[filter.Filter]
  73. onReconfigHook wgengine.ReconfigListener
  74. cfg *wgcfg.Config
  75. dnsCfg *tsDNS.Config
  76. routeDomains common.TypedValue[map[string]bool]
  77. routePrefixes atomic.Pointer[netipx.IPSet]
  78. acceptRoutes bool
  79. exitNode string
  80. exitNodeAllowLANAccess bool
  81. advertiseRoutes []netip.Prefix
  82. advertiseExitNode bool
  83. udpTimeout time.Duration
  84. }
  85. func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.TailscaleEndpointOptions) (adapter.Endpoint, error) {
  86. stateDirectory := options.StateDirectory
  87. if stateDirectory == "" {
  88. stateDirectory = "tailscale"
  89. }
  90. hostname := options.Hostname
  91. if hostname == "" {
  92. osHostname, _ := os.Hostname()
  93. osHostname = strings.TrimSpace(osHostname)
  94. hostname = osHostname
  95. }
  96. if hostname == "" {
  97. hostname = "sing-box"
  98. }
  99. stateDirectory = filemanager.BasePath(ctx, os.ExpandEnv(stateDirectory))
  100. stateDirectory, _ = filepath.Abs(stateDirectory)
  101. for _, advertiseRoute := range options.AdvertiseRoutes {
  102. if advertiseRoute.Addr().IsUnspecified() && advertiseRoute.Bits() == 0 {
  103. return nil, E.New("`advertise_routes` cannot be default, use `advertise_exit_node` instead.")
  104. }
  105. }
  106. if options.AdvertiseExitNode && options.ExitNode != "" {
  107. return nil, E.New("cannot advertise an exit node and use an exit node at the same time.")
  108. }
  109. var udpTimeout time.Duration
  110. if options.UDPTimeout != 0 {
  111. udpTimeout = time.Duration(options.UDPTimeout)
  112. } else {
  113. udpTimeout = C.UDPTimeout
  114. }
  115. var remoteIsDomain bool
  116. if options.ControlURL != "" {
  117. controlURL, err := url.Parse(options.ControlURL)
  118. if err != nil {
  119. return nil, E.Cause(err, "parse control URL")
  120. }
  121. remoteIsDomain = M.IsDomainName(controlURL.Hostname())
  122. } else {
  123. // controlplane.tailscale.com
  124. remoteIsDomain = true
  125. }
  126. outboundDialer, err := dialer.NewWithOptions(dialer.Options{
  127. Context: ctx,
  128. Options: options.DialerOptions,
  129. RemoteIsDomain: remoteIsDomain,
  130. ResolverOnDetour: true,
  131. NewDialer: true,
  132. })
  133. if err != nil {
  134. return nil, err
  135. }
  136. dnsRouter := service.FromContext[adapter.DNSRouter](ctx)
  137. server := &tsnet.Server{
  138. Dir: stateDirectory,
  139. Hostname: hostname,
  140. Logf: func(format string, args ...any) {
  141. logger.Trace(fmt.Sprintf(format, args...))
  142. },
  143. UserLogf: func(format string, args ...any) {
  144. logger.Debug(fmt.Sprintf(format, args...))
  145. },
  146. Ephemeral: options.Ephemeral,
  147. AuthKey: options.AuthKey,
  148. ControlURL: options.ControlURL,
  149. Dialer: &endpointDialer{Dialer: outboundDialer, logger: logger},
  150. LookupHook: func(ctx context.Context, host string) ([]netip.Addr, error) {
  151. return dnsRouter.Lookup(ctx, host, outboundDialer.(dialer.ResolveDialer).QueryOptions())
  152. },
  153. DNS: &dnsConfigurtor{},
  154. HTTPClient: &http.Client{
  155. Transport: &http.Transport{
  156. ForceAttemptHTTP2: true,
  157. DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
  158. return outboundDialer.DialContext(ctx, network, M.ParseSocksaddr(address))
  159. },
  160. TLSClientConfig: &tls.Config{
  161. RootCAs: adapter.RootPoolFromContext(ctx),
  162. },
  163. },
  164. },
  165. }
  166. return &Endpoint{
  167. Adapter: endpoint.NewAdapter(C.TypeTailscale, tag, []string{N.NetworkTCP, N.NetworkUDP}, nil),
  168. ctx: ctx,
  169. router: router,
  170. logger: logger,
  171. dnsRouter: dnsRouter,
  172. network: service.FromContext[adapter.NetworkManager](ctx),
  173. platformInterface: service.FromContext[platform.Interface](ctx),
  174. server: server,
  175. acceptRoutes: options.AcceptRoutes,
  176. exitNode: options.ExitNode,
  177. exitNodeAllowLANAccess: options.ExitNodeAllowLANAccess,
  178. advertiseRoutes: options.AdvertiseRoutes,
  179. advertiseExitNode: options.AdvertiseExitNode,
  180. udpTimeout: udpTimeout,
  181. }, nil
  182. }
  183. func (t *Endpoint) Start(stage adapter.StartStage) error {
  184. if stage != adapter.StartStateStart {
  185. return nil
  186. }
  187. if t.platformInterface != nil {
  188. err := t.network.UpdateInterfaces()
  189. if err != nil {
  190. return err
  191. }
  192. netmon.RegisterInterfaceGetter(func() ([]netmon.Interface, error) {
  193. return common.Map(t.network.InterfaceFinder().Interfaces(), func(it control.Interface) netmon.Interface {
  194. return netmon.Interface{
  195. Interface: &net.Interface{
  196. Index: it.Index,
  197. MTU: it.MTU,
  198. Name: it.Name,
  199. HardwareAddr: it.HardwareAddr,
  200. Flags: it.Flags,
  201. },
  202. AltAddrs: common.Map(it.Addresses, func(it netip.Prefix) net.Addr {
  203. return &net.IPNet{
  204. IP: it.Addr().AsSlice(),
  205. Mask: net.CIDRMask(it.Bits(), it.Addr().BitLen()),
  206. }
  207. }),
  208. }
  209. }), nil
  210. })
  211. if runtime.GOOS == "android" {
  212. setAndroidProtectFunc(t.platformInterface)
  213. }
  214. }
  215. err := t.server.Start()
  216. if err != nil {
  217. return err
  218. }
  219. t.server.ExportLocalBackend().ExportEngine().(wgengine.ExportedUserspaceEngine).SetOnReconfigListener(t.onReconfig)
  220. ipStack := t.server.ExportNetstack().ExportIPStack()
  221. gErr := ipStack.SetSpoofing(tun.DefaultNIC, true)
  222. if gErr != nil {
  223. return gonet.TranslateNetstackError(gErr)
  224. }
  225. gErr = ipStack.SetPromiscuousMode(tun.DefaultNIC, true)
  226. if gErr != nil {
  227. return gonet.TranslateNetstackError(gErr)
  228. }
  229. ipStack.SetTransportProtocolHandler(tcp.ProtocolNumber, tun.NewTCPForwarder(t.ctx, ipStack, t).HandlePacket)
  230. udpForwarder := tun.NewUDPForwarder(t.ctx, ipStack, t, t.udpTimeout)
  231. ipStack.SetTransportProtocolHandler(udp.ProtocolNumber, udpForwarder.HandlePacket)
  232. t.stack = ipStack
  233. localBackend := t.server.ExportLocalBackend()
  234. perfs := &ipn.MaskedPrefs{
  235. Prefs: ipn.Prefs{
  236. RouteAll: t.acceptRoutes,
  237. },
  238. RouteAllSet: true,
  239. ExitNodeIPSet: true,
  240. AdvertiseRoutesSet: true,
  241. }
  242. if len(t.advertiseRoutes) > 0 {
  243. perfs.AdvertiseRoutes = t.advertiseRoutes
  244. }
  245. if t.advertiseExitNode {
  246. perfs.AdvertiseRoutes = append(perfs.AdvertiseRoutes, tsaddr.ExitRoutes()...)
  247. }
  248. _, err = localBackend.EditPrefs(perfs)
  249. if err != nil {
  250. return E.Cause(err, "update prefs")
  251. }
  252. t.filter = localBackend.ExportFilter()
  253. go t.watchState()
  254. return nil
  255. }
  256. func (t *Endpoint) watchState() {
  257. localBackend := t.server.ExportLocalBackend()
  258. localBackend.WatchNotifications(t.ctx, ipn.NotifyInitialState, nil, func(roNotify *ipn.Notify) (keepGoing bool) {
  259. if roNotify.State != nil && *roNotify.State != ipn.NeedsLogin && *roNotify.State != ipn.NoState {
  260. return false
  261. }
  262. authURL := localBackend.StatusWithoutPeers().AuthURL
  263. if authURL != "" {
  264. t.logger.Info("Waiting for authentication: ", authURL)
  265. if t.platformInterface != nil {
  266. err := t.platformInterface.SendNotification(&platform.Notification{
  267. Identifier: "tailscale-authentication",
  268. TypeName: "Tailscale Authentication Notifications",
  269. TypeID: 10,
  270. Title: "Tailscale Authentication",
  271. Body: F.ToString("Tailscale outbound[", t.Tag(), "] is waiting for authentication."),
  272. OpenURL: authURL,
  273. })
  274. if err != nil {
  275. t.logger.Error("send authentication notification: ", err)
  276. }
  277. }
  278. return false
  279. }
  280. return true
  281. })
  282. if t.exitNode != "" {
  283. localBackend.WatchNotifications(t.ctx, ipn.NotifyInitialState, nil, func(roNotify *ipn.Notify) (keepGoing bool) {
  284. if roNotify.State == nil || *roNotify.State != ipn.Running {
  285. return true
  286. }
  287. status, err := common.Must1(t.server.LocalClient()).Status(t.ctx)
  288. if err != nil {
  289. t.logger.Error("set exit node: ", err)
  290. return
  291. }
  292. perfs := &ipn.MaskedPrefs{
  293. Prefs: ipn.Prefs{
  294. ExitNodeAllowLANAccess: t.exitNodeAllowLANAccess,
  295. },
  296. ExitNodeIPSet: true,
  297. ExitNodeAllowLANAccessSet: true,
  298. }
  299. err = perfs.SetExitNodeIP(t.exitNode, status)
  300. if err != nil {
  301. t.logger.Error("set exit node: ", err)
  302. return true
  303. }
  304. _, err = localBackend.EditPrefs(perfs)
  305. if err != nil {
  306. t.logger.Error("set exit node: ", err)
  307. return true
  308. }
  309. return false
  310. })
  311. }
  312. }
  313. func (t *Endpoint) Close() error {
  314. netmon.RegisterInterfaceGetter(nil)
  315. if runtime.GOOS == "android" {
  316. setAndroidProtectFunc(nil)
  317. }
  318. return common.Close(common.PtrOrNil(t.server))
  319. }
  320. func (t *Endpoint) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
  321. switch network {
  322. case N.NetworkTCP:
  323. t.logger.InfoContext(ctx, "outbound connection to ", destination)
  324. case N.NetworkUDP:
  325. t.logger.InfoContext(ctx, "outbound packet connection to ", destination)
  326. }
  327. if destination.IsFqdn() {
  328. destinationAddresses, err := t.dnsRouter.Lookup(ctx, destination.Fqdn, adapter.DNSQueryOptions{})
  329. if err != nil {
  330. return nil, err
  331. }
  332. return N.DialSerial(ctx, t, network, destination, destinationAddresses)
  333. }
  334. addr := tcpip.FullAddress{
  335. NIC: 1,
  336. Port: destination.Port,
  337. Addr: addressFromAddr(destination.Addr),
  338. }
  339. var networkProtocol tcpip.NetworkProtocolNumber
  340. if destination.IsIPv4() {
  341. networkProtocol = header.IPv4ProtocolNumber
  342. } else {
  343. networkProtocol = header.IPv6ProtocolNumber
  344. }
  345. switch N.NetworkName(network) {
  346. case N.NetworkTCP:
  347. tcpConn, err := gonet.DialContextTCP(ctx, t.stack, addr, networkProtocol)
  348. if err != nil {
  349. return nil, err
  350. }
  351. return tcpConn, nil
  352. case N.NetworkUDP:
  353. udpConn, err := gonet.DialUDP(t.stack, nil, &addr, networkProtocol)
  354. if err != nil {
  355. return nil, err
  356. }
  357. return udpConn, nil
  358. default:
  359. return nil, E.Extend(N.ErrUnknownNetwork, network)
  360. }
  361. }
  362. func (t *Endpoint) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
  363. t.logger.InfoContext(ctx, "outbound packet connection to ", destination)
  364. if destination.IsFqdn() {
  365. destinationAddresses, err := t.dnsRouter.Lookup(ctx, destination.Fqdn, adapter.DNSQueryOptions{})
  366. if err != nil {
  367. return nil, err
  368. }
  369. packetConn, _, err := N.ListenSerial(ctx, t, destination, destinationAddresses)
  370. if err != nil {
  371. return nil, err
  372. }
  373. return packetConn, err
  374. }
  375. addr4, addr6 := t.server.TailscaleIPs()
  376. bind := tcpip.FullAddress{
  377. NIC: 1,
  378. }
  379. var networkProtocol tcpip.NetworkProtocolNumber
  380. if destination.IsIPv4() {
  381. if !addr4.IsValid() {
  382. return nil, E.New("missing Tailscale IPv4 address")
  383. }
  384. networkProtocol = header.IPv4ProtocolNumber
  385. bind.Addr = addressFromAddr(addr4)
  386. } else {
  387. if !addr6.IsValid() {
  388. return nil, E.New("missing Tailscale IPv6 address")
  389. }
  390. networkProtocol = header.IPv6ProtocolNumber
  391. bind.Addr = addressFromAddr(addr6)
  392. }
  393. udpConn, err := gonet.DialUDP(t.stack, &bind, nil, networkProtocol)
  394. if err != nil {
  395. return nil, err
  396. }
  397. return udpConn, nil
  398. }
  399. func (t *Endpoint) PrepareConnection(network string, source M.Socksaddr, destination M.Socksaddr) error {
  400. tsFilter := t.filter.Load()
  401. if tsFilter != nil {
  402. var ipProto ipproto.Proto
  403. switch N.NetworkName(network) {
  404. case N.NetworkTCP:
  405. ipProto = ipproto.TCP
  406. case N.NetworkUDP:
  407. ipProto = ipproto.UDP
  408. }
  409. response := tsFilter.Check(source.Addr, destination.Addr, destination.Port, ipProto)
  410. switch response {
  411. case filter.Drop:
  412. return syscall.ECONNRESET
  413. case filter.DropSilently:
  414. return tun.ErrDrop
  415. }
  416. }
  417. return t.router.PreMatch(adapter.InboundContext{
  418. Inbound: t.Tag(),
  419. InboundType: t.Type(),
  420. Network: network,
  421. Source: source,
  422. Destination: destination,
  423. })
  424. }
  425. func (t *Endpoint) NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose N.CloseHandlerFunc) {
  426. var metadata adapter.InboundContext
  427. metadata.Inbound = t.Tag()
  428. metadata.InboundType = t.Type()
  429. metadata.Source = source
  430. addr4, addr6 := t.server.TailscaleIPs()
  431. switch destination.Addr {
  432. case addr4:
  433. destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
  434. case addr6:
  435. destination.Addr = netip.IPv6Loopback()
  436. }
  437. metadata.Destination = destination
  438. t.logger.InfoContext(ctx, "inbound connection from ", source)
  439. t.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
  440. t.router.RouteConnectionEx(ctx, conn, metadata, onClose)
  441. }
  442. func (t *Endpoint) NewPacketConnectionEx(ctx context.Context, conn N.PacketConn, source M.Socksaddr, destination M.Socksaddr, onClose N.CloseHandlerFunc) {
  443. var metadata adapter.InboundContext
  444. metadata.Inbound = t.Tag()
  445. metadata.InboundType = t.Type()
  446. metadata.Source = source
  447. metadata.Destination = destination
  448. addr4, addr6 := t.server.TailscaleIPs()
  449. switch destination.Addr {
  450. case addr4:
  451. metadata.OriginDestination = destination
  452. destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
  453. conn = bufio.NewNATPacketConn(bufio.NewNetPacketConn(conn), metadata.OriginDestination, metadata.Destination)
  454. case addr6:
  455. metadata.OriginDestination = destination
  456. destination.Addr = netip.IPv6Loopback()
  457. conn = bufio.NewNATPacketConn(bufio.NewNetPacketConn(conn), metadata.OriginDestination, metadata.Destination)
  458. }
  459. t.logger.InfoContext(ctx, "inbound packet connection from ", source)
  460. t.logger.InfoContext(ctx, "inbound packet connection to ", destination)
  461. t.router.RoutePacketConnectionEx(ctx, conn, metadata, onClose)
  462. }
  463. func (t *Endpoint) PreferredDomain(domain string) bool {
  464. routeDomains := t.routeDomains.Load()
  465. if routeDomains == nil {
  466. return false
  467. }
  468. return routeDomains[strings.ToLower(domain)]
  469. }
  470. func (t *Endpoint) PreferredAddress(address netip.Addr) bool {
  471. routePrefixes := t.routePrefixes.Load()
  472. if routePrefixes == nil {
  473. return false
  474. }
  475. return routePrefixes.Contains(address)
  476. }
  477. func (t *Endpoint) Server() *tsnet.Server {
  478. return t.server
  479. }
  480. func (t *Endpoint) onReconfig(cfg *wgcfg.Config, routerCfg *router.Config, dnsCfg *tsDNS.Config) {
  481. if cfg == nil || dnsCfg == nil {
  482. return
  483. }
  484. if (t.cfg != nil && reflect.DeepEqual(t.cfg, cfg)) && (t.dnsCfg != nil && reflect.DeepEqual(t.dnsCfg, dnsCfg)) {
  485. return
  486. }
  487. t.cfg = cfg
  488. t.dnsCfg = dnsCfg
  489. routeDomains := make(map[string]bool)
  490. for fqdn := range dnsCfg.Routes {
  491. routeDomains[fqdn.WithoutTrailingDot()] = true
  492. }
  493. for _, fqdn := range dnsCfg.SearchDomains {
  494. routeDomains[fqdn.WithoutTrailingDot()] = true
  495. }
  496. t.routeDomains.Store(routeDomains)
  497. var builder netipx.IPSetBuilder
  498. for _, peer := range cfg.Peers {
  499. for _, allowedIP := range peer.AllowedIPs {
  500. builder.AddPrefix(allowedIP)
  501. }
  502. }
  503. t.routePrefixes.Store(common.Must1(builder.IPSet()))
  504. if t.onReconfigHook != nil {
  505. t.onReconfigHook(cfg, routerCfg, dnsCfg)
  506. }
  507. }
  508. func addressFromAddr(destination netip.Addr) tcpip.Address {
  509. if destination.Is6() {
  510. return tcpip.AddrFrom16(destination.As16())
  511. } else {
  512. return tcpip.AddrFrom4(destination.As4())
  513. }
  514. }
  515. type endpointDialer struct {
  516. N.Dialer
  517. logger logger.ContextLogger
  518. }
  519. func (d *endpointDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
  520. switch N.NetworkName(network) {
  521. case N.NetworkTCP:
  522. d.logger.InfoContext(ctx, "output connection to ", destination)
  523. case N.NetworkUDP:
  524. d.logger.InfoContext(ctx, "output packet connection to ", destination)
  525. }
  526. return d.Dialer.DialContext(ctx, network, destination)
  527. }
  528. func (d *endpointDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
  529. d.logger.InfoContext(ctx, "output packet connection")
  530. return d.Dialer.ListenPacket(ctx, destination)
  531. }
  532. type dnsConfigurtor struct {
  533. baseConfig tsDNS.OSConfig
  534. }
  535. func (c *dnsConfigurtor) SetDNS(cfg tsDNS.OSConfig) error {
  536. c.baseConfig = cfg
  537. return nil
  538. }
  539. func (c *dnsConfigurtor) SupportsSplitDNS() bool {
  540. return true
  541. }
  542. func (c *dnsConfigurtor) GetBaseConfig() (tsDNS.OSConfig, error) {
  543. return c.baseConfig, nil
  544. }
  545. func (c *dnsConfigurtor) Close() error {
  546. return nil
  547. }