Skip to content

Commit

Permalink
feat: use auto route on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
cxz66666 committed Oct 29, 2023
1 parent 52eef56 commit b1dde33
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions stack/tun/stack_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewStack(easyConnectClient *client.EasyConnectClient, dnsServer string) (*S
return nil, err
}
ipPrefix, _ := netip.ParsePrefix(s.endpoint.ip.String() + "/8")
zjuPrefix, _ := netip.ParsePrefix("10.0.0.0/8")
tunName := "utun0"
tunName = tun.CalculateInterfaceName(tunName)
tunOptions := tun.Options{
Expand All @@ -69,7 +70,10 @@ func NewStack(easyConnectClient *client.EasyConnectClient, dnsServer string) (*S
Inet4Address: []netip.Prefix{
ipPrefix,
},
AutoRoute: false,
Inet4RouteAddress: []netip.Prefix{
zjuPrefix,
},
AutoRoute: true,
TableIndex: 1897,
}

Expand All @@ -86,7 +90,6 @@ func NewStack(easyConnectClient *client.EasyConnectClient, dnsServer string) (*S

s.endpoint.ifceIndex = netIfce.Index
log.Printf("Interface Name: %s, index %d\n", tunName, netIfce.Index)
s.AddRoute("10.0.0.0/8")

// We need this dialer to bind to device otherwise packets will not be sent via TUN
s.endpoint.tcpDialer = &net.Dialer{
Expand Down

0 comments on commit b1dde33

Please sign in to comment.