From c9afa9f5ef7b8567bb086624aca90fb00b9cc26b Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Mon, 27 Jul 2020 21:02:11 +0800 Subject: [PATCH 1/3] add initial advertise(Addr|Port) support (cherry picked from commit 2a0b4f335eb54caa19ad908cdc441d73b57d68ca) --- cluster/cluster.go | 5 +++-- config.go | 5 +++++ main.go | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index c5e1b2f..be6bbd1 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -31,7 +31,7 @@ type Cluster struct { // New is used to create a new Cluster instance // The returned instance is ready to be updated with the local node settings then joined -func New(name string, init bool, clusterKey []byte, bindAddr string, bindPort int, useIPAsName bool) (*Cluster, error) { +func New(name string, init bool, clusterKey []byte, bindAddr string, bindPort int, advertiseAddr string, advertisePort int, useIPAsName bool) (*Cluster, error) { state := &state{} if !init { loadState(state, name) @@ -47,7 +47,8 @@ func New(name string, init bool, clusterKey []byte, bindAddr string, bindPort in mlConfig.SecretKey = clusterKey mlConfig.BindAddr = bindAddr mlConfig.BindPort = bindPort - mlConfig.AdvertisePort = bindPort + mlConfig.AdvertiseAddr = advertiseAddr + mlConfig.AdvertisePort = advertisePort if useIPAsName && bindAddr != "0.0.0.0" { mlConfig.Name = bindAddr } diff --git a/config.go b/config.go index 34528c3..2c14489 100644 --- a/config.go +++ b/config.go @@ -17,6 +17,7 @@ type config struct { Init bool `desc:"whether to explicitly (re)initialize the cluster; any known state from previous runs will be forgotten"` BindAddr string `id:"bind-addr" desc:"IP address to bind to for cluster membership traffic (cannot be used with --bind-iface)"` BindIface string `id:"bind-iface" desc:"Interface to bind to for cluster membership traffic (cannot be used with --bind-addr)"` + AdvertiseAddr string `id:"advertise-addr" desc:"IP address to advertise to other nodes for NAT traversal"` ClusterPort int `id:"cluster-port" desc:"port used for membership gossip traffic (both TCP and UDP); must be the same across cluster" default:"7946"` WireguardPort int `id:"wireguard-port" desc:"port used for wireguard traffic (UDP); must be the same across cluster" default:"51820"` BaseMtu int `id:"mtu" desc:"MTU of the underlying network, taking intermediary hops into account" default:"1500"` @@ -80,6 +81,10 @@ func loadConfig() (*config, error) { } } + if config.AdvertiseAddr == "" { + config.AdvertiseAddr = config.BindAddr + } + return &config, nil } diff --git a/main.go b/main.go index 28c8fd3..86ddb41 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ func main() { logrus.SetLevel(logLevel) // Create the wireguard and cluster configuration - cluster, err := cluster.New(config.Interface, config.Init, config.ClusterKey, config.BindAddr, config.ClusterPort, config.UseIPAsName) + cluster, err := cluster.New(config.Interface, config.Init, config.ClusterKey, config.BindAddr, config.ClusterPort, config.AdvertiseAddr, config.ClusterPort, config.UseIPAsName) if err != nil { logrus.WithError(err).Fatal("could not create cluster") } -- 2.40.1 From 42f993b96db1bf3b5d7318631eda8f59e296ceb2 Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Mon, 27 Jul 2020 21:12:13 +0800 Subject: [PATCH 2/3] reset advertise addr if bad addr, same as memberlist behavior (cherry picked from commit c27d37591589c7de2ca977e2e4c750b4fa4fb7a3) --- config.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 2c14489..b9fd051 100644 --- a/config.go +++ b/config.go @@ -6,6 +6,7 @@ import ( "github.com/costela/wesher/cluster" "github.com/hashicorp/go-sockaddr" + "github.com/mikioh/ipaddr" "github.com/pkg/errors" "github.com/stevenroose/gonfig" ) @@ -81,8 +82,8 @@ func loadConfig() (*config, error) { } } - if config.AdvertiseAddr == "" { - config.AdvertiseAddr = config.BindAddr + if _, err := ipaddr.Parse(config.AdvertiseAddr); err != nil { + config.AdvertiseAddr = "" } return &config, nil -- 2.40.1 From 01b3dab318aecfe43f56def2a402d622ae661d3e Mon Sep 17 00:00:00 2001 From: Killian Kemps Date: Fri, 11 Feb 2022 16:11:34 +0100 Subject: [PATCH 3/3] fix: Add missing dependency declaration --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index 3204755..d33d94b 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/memberlist v0.2.2 github.com/mattn/go-isatty v0.0.12 + github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 // indirect github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.7.0 github.com/stevenroose/gonfig v0.1.5 -- 2.40.1