Fix guard0 endpoint
This commit is contained in:
parent
717e860f65
commit
2ed0e5f0d1
2 changed files with 15 additions and 5 deletions
18
main.go
18
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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue