From 03498a0cb287d4fbb7be8044a6283f5b9cd195c6 Mon Sep 17 00:00:00 2001 From: brad-defined <77982333+brad-defined@users.noreply.github.com> Date: Tue, 15 Mar 2022 19:03:56 -0400 Subject: [PATCH] Make nebula advertise its dynamic port to lighthouses (#653) --- lighthouse.go | 9 +++++++++ main.go | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lighthouse.go b/lighthouse.go index e3a9bc7..07163bd 100644 --- a/lighthouse.go +++ b/lighthouse.go @@ -78,6 +78,15 @@ func NewLightHouseFromConfig(l *logrus.Logger, c *config.C, myVpnNet *net.IPNet, return nil, util.NewContextualError("lighthouse.am_lighthouse enabled on node but no port number is set in config", nil, nil) } + // If port is dynamic, discover it + if nebulaPort == 0 && pc != nil { + uPort, err := pc.LocalAddr() + if err != nil { + return nil, util.NewContextualError("Failed to get listening port", nil, err) + } + nebulaPort = uint32(uPort.Port) + } + ones, _ := myVpnNet.Mask.Size() h := LightHouse{ amLighthouse: amLighthouse, diff --git a/main.go b/main.go index ec08817..4a65465 100644 --- a/main.go +++ b/main.go @@ -158,15 +158,6 @@ func Main(c *config.C, configTest bool, buildVersion string, logger *logrus.Logg } udpServer.ReloadConfig(c) udpConns[i] = udpServer - - // If port is dynamic, discover it - if port == 0 { - uPort, err := udpServer.LocalAddr() - if err != nil { - return nil, util.NewContextualError("Failed to get listening port", nil, err) - } - port = int(uPort.Port) - } } }