diff --git a/cmd/hvpn-node/hvpn-node.go b/cmd/hvpn-node/hvpn-node.go index c1f6772..70a2abe 100644 --- a/cmd/hvpn-node/hvpn-node.go +++ b/cmd/hvpn-node/hvpn-node.go @@ -138,6 +138,13 @@ func createCliApp() *cli.App { } app.Flags = append(app.Flags, &wgInterfaceName) + wgEndpoint := cli.StringFlag{ + Name: "endpoint", + Usage: "Wireguard endpoint domain or address without the port", + Value: "domain.name.notset", + } + app.Flags = append(app.Flags, &wgEndpoint) + wgPort := cli.IntFlag{ Name: "port", Usage: "UDP Port for wireguard device", @@ -171,7 +178,7 @@ func createCliApp() *cli.App { app.Action = func(ctx *cli.Context) error { - err := setup() + err := setup(ctx) if err != nil { return err } @@ -182,7 +189,7 @@ func createCliApp() *cli.App { return app } -func setup() error { +func setup(ctx *cli.Context) error { slog.Debug("Starting setup()") uid := os.Getuid() if uid == -1 { @@ -225,6 +232,7 @@ func setup() error { InterfaceName, &privateKey, WgPort, + ctx.String("endpoint"), ) if err != nil { slog.Warn("Error while initlizing Wireguard netlink and device!") diff --git a/handlers.go b/handlers.go index 368447d..40744b7 100644 --- a/handlers.go +++ b/handlers.go @@ -31,6 +31,7 @@ func HandleGetNodeInfo(wgLink *WGLink) http.HandlerFunc { proto.NodePublicInfo{ PublicKey: dev.PublicKey.String(), UDPPort: dev.ListenPort, + Endpoint: wgLink.Endpoint, // TODO: Send endpoint for clients to connect }, ) diff --git a/link.go b/link.go index 7298379..bfcc3c9 100644 --- a/link.go +++ b/link.go @@ -21,14 +21,15 @@ type WGLink struct { *netlink.LinkAttrs *wgctrl.Client IPPool + Endpoint string // Endpoint for clients to use when connecting to this link. Has no effect. lock *sync.Mutex } // Retruns an existing or create a WGLink -func InitWGLink(ifName string, privateKey *wgtypes.Key, port int) (*WGLink, error){ +func InitWGLink(ifName string, privateKey *wgtypes.Key, port int, endpoint string) (*WGLink, error){ attrs := netlink.NewLinkAttrs() attrs.Name = ifName - wg := WGLink{LinkAttrs: &attrs} + wg := WGLink{LinkAttrs: &attrs, Endpoint: endpoint} link, err := netlink.LinkByName(ifName) if err != nil { switch err.(type) {