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

NET-1268:separate static endpoint and static port #807

Merged
merged 4 commits into from
Jun 5, 2024
Merged
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
3 changes: 2 additions & 1 deletion cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func init() {
joinCmd.Flags().StringP(registerFlags.EndpointIP6, "E", "", "sets ipv6 endpoint on host")
joinCmd.Flags().IntP(registerFlags.Port, "p", 0, "sets wg listen port")
joinCmd.Flags().StringP(registerFlags.MTU, "m", "", "sets MTU on host")
joinCmd.Flags().BoolP(registerFlags.Static, "i", false, "flag to set host as static")
joinCmd.Flags().BoolP(registerFlags.StaticPort, "j", false, "flag to set host as static port")
joinCmd.Flags().BoolP(registerFlags.Static, "i", false, "flag to set host as static endpoint")
joinCmd.Flags().StringP(registerFlags.Name, "o", "", "sets host name")
joinCmd.Flags().StringP(registerFlags.Interface, "I", "", "sets netmaker interface to use on host")
rootCmd.AddCommand(joinCmd)
Expand Down
3 changes: 2 additions & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func init() {
pushCmd.Flags().StringP(registerFlags.EndpointIP, "e", "", "sets endpoint on host")
pushCmd.Flags().IntP(registerFlags.Port, "p", 0, "sets wg listen port")
pushCmd.Flags().IntP(registerFlags.MTU, "m", 0, "sets MTU on host")
pushCmd.Flags().BoolP(registerFlags.Static, "i", false, "flag to set host as static")
pushCmd.Flags().BoolP(registerFlags.StaticPort, "j", false, "flag to set host as static port")
pushCmd.Flags().BoolP(registerFlags.Static, "i", false, "flag to set host as static endpoint")
pushCmd.Flags().StringP(registerFlags.Name, "o", "", "sets host name")
pushCmd.Flags().StringP(registerFlags.Interface, "I", "", "sets netmaker interface to use on host")
rootCmd.AddCommand(pushCmd)
Expand Down
20 changes: 15 additions & 5 deletions cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var registerFlags = struct {
EndpointIP6 string
Port string
MTU string
StaticPort string
Static string
Interface string
Name string
Expand All @@ -41,7 +42,8 @@ var registerFlags = struct {
EndpointIP: "endpoint-ip",
Port: "port",
MTU: "mtu",
Static: "static",
StaticPort: "static-port",
Static: "static-endpoint",
Name: "name",
Interface: "interface",
}
Expand Down Expand Up @@ -106,13 +108,20 @@ func setHostFields(cmd *cobra.Command) {
}
config.Netclient().Interface = ifaceName
}
if isStaticPort, err := cmd.Flags().GetBool(registerFlags.StaticPort); err == nil {
config.Netclient().IsStaticPort = isStaticPort
}
if isStatic, err := cmd.Flags().GetBool(registerFlags.Static); err == nil {
config.Netclient().IsStatic = isStatic
}
if config.Netclient().IsStatic && ((endpointIP == "" && endpointIP6 == "") || port == 0) {
fmt.Println("endpoint from command: ", endpointIP)
if config.Netclient().IsStaticPort && port == 0 {
fmt.Println("port from command: ", port)
fmt.Println("error: static port is enabled, please specify valid endpoint ip and port with -e and -p options")
fmt.Println("error: static port is enabled, please specify valid port with -p option")
os.Exit(1)
}
if config.Netclient().IsStatic && (endpointIP == "" && endpointIP6 == "") {
fmt.Println("endpoint from command: ", endpointIP)
fmt.Println("error: static endpoint is enabled, please specify valid endpoint ip with -e option")
os.Exit(1)
}
}
Expand Down Expand Up @@ -191,7 +200,8 @@ func init() {
registerCmd.Flags().StringP(registerFlags.EndpointIP6, "E", "", "sets ipv6 endpoint on host")
registerCmd.Flags().IntP(registerFlags.Port, "p", 0, "sets wg listen port")
registerCmd.Flags().IntP(registerFlags.MTU, "m", 0, "sets MTU on host")
registerCmd.Flags().BoolP(registerFlags.Static, "i", false, "flag to set host as static")
registerCmd.Flags().BoolP(registerFlags.StaticPort, "j", false, "flag to set host as static port")
registerCmd.Flags().BoolP(registerFlags.Static, "i", false, "flag to set host as static endpoint")
registerCmd.Flags().StringP(registerFlags.Name, "o", "", "sets host name")
registerCmd.Flags().StringP(registerFlags.Interface, "I", "", "sets netmaker interface to use on host")
rootCmd.AddCommand(registerCmd)
Expand Down
1 change: 1 addition & 0 deletions config/oldconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func ConvertOldNode(netmakerNode *models.LegacyNode) (*Node, *Config) {
node.Action = netmakerNode.Action
node.IsEgressGateway = ParseBool(netmakerNode.IsEgressGateway)
node.IsIngressGateway = ParseBool(netmakerNode.IsIngressGateway)
host.IsStaticPort = ParseBool(netmakerNode.IsStatic)
host.IsStatic = ParseBool(netmakerNode.IsStatic)
node.DNSOn = ParseBool(netmakerNode.DNSOn)
// node.Peers = nodeGet.Peers
Expand Down
20 changes: 11 additions & 9 deletions functions/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
slog.Warn("error reading server map from disk", "error", err)
}
updateConfig := false
if !config.Netclient().IsStatic {
config.HostPublicIP, config.WgPublicListenPort, config.HostNatType = holePunchWgPort()
slog.Info("wireguard public listen port: ", "port", config.WgPublicListenPort)

if !config.Netclient().IsStaticPort {
if freeport, err := ncutils.GetFreePort(config.Netclient().ListenPort); err != nil {
slog.Error("no free ports available for use by netclient", "error", err.Error())
} else if freeport != config.Netclient().ListenPort {
Expand All @@ -154,13 +156,17 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
updateConfig = true
}

config.HostPublicIP, config.WgPublicListenPort, config.HostNatType = holePunchWgPort()
slog.Info("wireguard public listen port: ", "port", config.WgPublicListenPort)

if config.Netclient().WgPublicListenPort == 0 {
config.Netclient().WgPublicListenPort = config.WgPublicListenPort
updateConfig = true
}

} else {
config.Netclient().WgPublicListenPort = config.Netclient().ListenPort
updateConfig = true
}

if !config.Netclient().IsStatic {
if config.HostPublicIP != nil && !config.HostPublicIP.IsUnspecified() {
config.Netclient().EndpointIP = config.HostPublicIP
updateConfig = true
Expand Down Expand Up @@ -189,10 +195,6 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
updateConfig = true
}
}

} else {
config.Netclient().WgPublicListenPort = config.Netclient().ListenPort
updateConfig = true
}

config.SetServerCtx()
Expand Down Expand Up @@ -322,7 +324,7 @@ func setupMQTT(server *config.Server) error {
opts.SetConnectionLostHandler(func(c mqtt.Client, e error) {
slog.Warn("detected broker connection lost for", "server", server.Broker)
// restart daemon for new udp hole punch if MQTT connection is lost (can happen on network change)
if !config.Netclient().IsStatic {
if !config.Netclient().IsStaticPort || !config.Netclient().IsStatic {
daemon.Restart()
}
})
Expand Down
2 changes: 1 addition & 1 deletion functions/mqpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func UpdateHostSettings(fallback bool) error {
}

if config.WgPublicListenPort != 0 && config.Netclient().WgPublicListenPort != config.WgPublicListenPort {
if !config.Netclient().IsStatic {
if !config.Netclient().IsStaticPort {
config.Netclient().WgPublicListenPort = config.WgPublicListenPort
} else {
config.Netclient().WgPublicListenPort = config.Netclient().ListenPort
Expand Down
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/google/nftables v0.1.0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.1
github.com/gravitl/netmaker v0.24.1-0.20240511070838-f8481c75bbd0
github.com/gravitl/netmaker v0.24.2-0.20240603083719-c7469c79d09f
github.com/gravitl/tcping v0.1.2-0.20230801110928-546055ebde06
github.com/gravitl/txeh v0.0.0-20230509181318-3778c58bd69f
github.com/guumaster/hostctl v1.1.4
Expand All @@ -39,21 +39,27 @@ require (

require (
aead.dev/minisign v0.2.0 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/coreos/go-oidc/v3 v3.9.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v23.0.5+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -79,6 +85,7 @@ require (
github.com/rqlite/gorqlite v0.0.0-20240122221808-a8a425b1a6aa // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand All @@ -90,6 +97,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.17.0 // indirect
Expand Down
Loading
Loading