Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add NAT support through the use of /advertise(Addr|Port)/ #50

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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)
Expand All @@ -46,7 +46,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
}
Expand Down
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -16,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"`
OverlayNet *network `id:"overlay-net" desc:"the network in which to allocate addresses for the overlay mesh network (CIDR format); smaller networks increase the chance of IP collision" default:"10.0.0.0/8"`
Expand Down Expand Up @@ -76,6 +78,10 @@ func loadConfig() (*config, error) {
}
}

if _, err := ipaddr.Parse(config.AdvertiseAddr); err != nil {
config.AdvertiseAddr = ""
}

return &config, nil
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down