From 18a515a5eb146442e5552b2954481905d2903a32 Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Mon, 3 Feb 2020 21:05:42 +0800 Subject: [PATCH] fix tun for darwin --- cmd/gost/route.go | 1 + tuntap.go | 1 + tuntap_darwin.go | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/gost/route.go b/cmd/gost/route.go index ac840cf..4032884 100644 --- a/cmd/gost/route.go +++ b/cmd/gost/route.go @@ -450,6 +450,7 @@ func (r *route) GenRouters() ([]router, error) { cfg := gost.TunConfig{ Name: node.Get("name"), Addr: node.Get("net"), + Peer: node.Get("peer"), MTU: node.GetInt("mtu"), Routes: tunRoutes, Gateway: node.Get("gw"), diff --git a/tuntap.go b/tuntap.go index 43ed893..d490a58 100644 --- a/tuntap.go +++ b/tuntap.go @@ -48,6 +48,7 @@ type IPRoute struct { type TunConfig struct { Name string Addr string + Peer string // peer addr of point-to-point on MacOS MTU int Routes []IPRoute Gateway string diff --git a/tuntap_darwin.go b/tuntap_darwin.go index 51cdd9e..ffe2ac7 100644 --- a/tuntap_darwin.go +++ b/tuntap_darwin.go @@ -29,7 +29,12 @@ func createTun(cfg TunConfig) (conn net.Conn, itf *net.Interface, err error) { mtu = DefaultMTU } - cmd := fmt.Sprintf("ifconfig %s inet %s mtu %d up", ifce.Name(), cfg.Addr, mtu) + peer := cfg.Peer + if peer == "" { + peer = ip.String() + } + cmd := fmt.Sprintf("ifconfig %s inet %s %s mtu %d up", + ifce.Name(), cfg.Addr, peer, mtu) log.Log("[tun]", cmd) args := strings.Split(cmd, " ") if er := exec.Command(args[0], args[1:]...).Run(); er != nil {