From 2ed0e5f0d11ef594a4dc86a01b733e559ca7e5a8 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 11 Jul 2019 12:14:04 +0000 Subject: [PATCH] Fix guard0 endpoint --- main.go | 18 ++++++++++++++---- server.go | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 8cd4ac2..3db71a3 100644 --- a/main.go +++ b/main.go @@ -100,6 +100,10 @@ var serverCommand = cli.Command{ Usage: "wireguard configuration directory", Value: defaultWireguardDir, }, + cli.StringFlag{ + Name: "endpoint", + Usage: "external endpoint address to manage the wireguard", + }, }, Action: func(clix *cli.Context) error { if os.Geteuid() != 0 { @@ -112,17 +116,23 @@ var serverCommand = cli.Command{ server := newGRPC() v1.RegisterWireguardServer(server, wg) - ctx := cancelContext() - address := clix.GlobalString("address") - host, _, err := net.SplitHostPort(address) + var ( + ctx = cancelContext() + endpoint = clix.String("endpoint") + address = clix.GlobalString("address") + ) + host, port, err := net.SplitHostPort(address) if err != nil { return errors.Wrap(err, "splitting tunnel address") } + if endpoint == "" { + endpoint = net.JoinHostPort("127.0.0.1", port) + } r, err := wg.Create(ctx, &v1.CreateRequest{ ID: guardTunnel, Address: host + "/32", - Endpoint: address, + Endpoint: endpoint, }) if err == nil { logrus.Info("created guard0 tunnel") diff --git a/server.go b/server.go index b8503dc..4dfe1c5 100644 --- a/server.go +++ b/server.go @@ -188,7 +188,7 @@ func (s *server) AddPeer(ctx context.Context, r *v1.AddPeerRequest) (*v1.TunnelR } log := logrus.WithFields(logrus.Fields{ "tunnel": r.ID, - "peer": r.PeerID, + "peer": r.Peer.ID, }) t, err := s.loadTunnel(r.ID) if err != nil {