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",
|
Usage: "wireguard configuration directory",
|
||||||
Value: defaultWireguardDir,
|
Value: defaultWireguardDir,
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "endpoint",
|
||||||
|
Usage: "external endpoint address to manage the wireguard",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(clix *cli.Context) error {
|
Action: func(clix *cli.Context) error {
|
||||||
if os.Geteuid() != 0 {
|
if os.Geteuid() != 0 {
|
||||||
|
@ -112,17 +116,23 @@ var serverCommand = cli.Command{
|
||||||
server := newGRPC()
|
server := newGRPC()
|
||||||
|
|
||||||
v1.RegisterWireguardServer(server, wg)
|
v1.RegisterWireguardServer(server, wg)
|
||||||
ctx := cancelContext()
|
|
||||||
|
|
||||||
address := clix.GlobalString("address")
|
var (
|
||||||
host, _, err := net.SplitHostPort(address)
|
ctx = cancelContext()
|
||||||
|
endpoint = clix.String("endpoint")
|
||||||
|
address = clix.GlobalString("address")
|
||||||
|
)
|
||||||
|
host, port, err := net.SplitHostPort(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "splitting tunnel address")
|
return errors.Wrap(err, "splitting tunnel address")
|
||||||
}
|
}
|
||||||
|
if endpoint == "" {
|
||||||
|
endpoint = net.JoinHostPort("127.0.0.1", port)
|
||||||
|
}
|
||||||
r, err := wg.Create(ctx, &v1.CreateRequest{
|
r, err := wg.Create(ctx, &v1.CreateRequest{
|
||||||
ID: guardTunnel,
|
ID: guardTunnel,
|
||||||
Address: host + "/32",
|
Address: host + "/32",
|
||||||
Endpoint: address,
|
Endpoint: endpoint,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logrus.Info("created guard0 tunnel")
|
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{
|
log := logrus.WithFields(logrus.Fields{
|
||||||
"tunnel": r.ID,
|
"tunnel": r.ID,
|
||||||
"peer": r.PeerID,
|
"peer": r.Peer.ID,
|
||||||
})
|
})
|
||||||
t, err := s.loadTunnel(r.ID)
|
t, err := s.loadTunnel(r.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue