feat: store a wglink endpoint string
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
c9b5e56f14
commit
78b61aede4
@ -138,6 +138,13 @@ func createCliApp() *cli.App {
|
|||||||
}
|
}
|
||||||
app.Flags = append(app.Flags, &wgInterfaceName)
|
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{
|
wgPort := cli.IntFlag{
|
||||||
Name: "port",
|
Name: "port",
|
||||||
Usage: "UDP Port for wireguard device",
|
Usage: "UDP Port for wireguard device",
|
||||||
@ -171,7 +178,7 @@ func createCliApp() *cli.App {
|
|||||||
|
|
||||||
|
|
||||||
app.Action = func(ctx *cli.Context) error {
|
app.Action = func(ctx *cli.Context) error {
|
||||||
err := setup()
|
err := setup(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -182,7 +189,7 @@ func createCliApp() *cli.App {
|
|||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup() error {
|
func setup(ctx *cli.Context) error {
|
||||||
slog.Debug("Starting setup()")
|
slog.Debug("Starting setup()")
|
||||||
uid := os.Getuid()
|
uid := os.Getuid()
|
||||||
if uid == -1 {
|
if uid == -1 {
|
||||||
@ -225,6 +232,7 @@ func setup() error {
|
|||||||
InterfaceName,
|
InterfaceName,
|
||||||
&privateKey,
|
&privateKey,
|
||||||
WgPort,
|
WgPort,
|
||||||
|
ctx.String("endpoint"),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("Error while initlizing Wireguard netlink and device!")
|
slog.Warn("Error while initlizing Wireguard netlink and device!")
|
||||||
|
@ -31,6 +31,7 @@ func HandleGetNodeInfo(wgLink *WGLink) http.HandlerFunc {
|
|||||||
proto.NodePublicInfo{
|
proto.NodePublicInfo{
|
||||||
PublicKey: dev.PublicKey.String(),
|
PublicKey: dev.PublicKey.String(),
|
||||||
UDPPort: dev.ListenPort,
|
UDPPort: dev.ListenPort,
|
||||||
|
Endpoint: wgLink.Endpoint,
|
||||||
// TODO: Send endpoint for clients to connect
|
// TODO: Send endpoint for clients to connect
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
5
link.go
5
link.go
@ -21,14 +21,15 @@ type WGLink struct {
|
|||||||
*netlink.LinkAttrs
|
*netlink.LinkAttrs
|
||||||
*wgctrl.Client
|
*wgctrl.Client
|
||||||
IPPool
|
IPPool
|
||||||
|
Endpoint string // Endpoint for clients to use when connecting to this link. Has no effect.
|
||||||
lock *sync.Mutex
|
lock *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retruns an existing or create a WGLink
|
// 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 := netlink.NewLinkAttrs()
|
||||||
attrs.Name = ifName
|
attrs.Name = ifName
|
||||||
wg := WGLink{LinkAttrs: &attrs}
|
wg := WGLink{LinkAttrs: &attrs, Endpoint: endpoint}
|
||||||
link, err := netlink.LinkByName(ifName)
|
link, err := netlink.LinkByName(ifName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user