diff --git a/client/cmd/root.go b/client/cmd/root.go index ec8007bee49..eb387d74cb9 100644 --- a/client/cmd/root.go +++ b/client/cmd/root.go @@ -15,7 +15,6 @@ import ( "time" "github.com/cenkalti/backoff/v4" - "github.com/netbirdio/netbird/iface" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -121,10 +120,12 @@ func init() { `An empty string "" clears the previous configuration. `+ `E.g. --dns-resolver-address 127.0.0.1:5053 or --dns-resolver-address ""`, ) - upCmd.PersistentFlags().StringVar(&wgIface, "wg-iface", iface.WgInterfaceDefault, + // do not set default, because it will override whatever custom value was set + upCmd.PersistentFlags().StringVar(&wgIface, "wg-iface", "", `WireGuard interface name to use for Netbird client instance. `+ `MacOS restricts the tun interface name to utun[0-9]+ pattern. e.g., utun100`) - upCmd.PersistentFlags().IntVar(&wgPort, "wg-port", iface.DefaultWgPort, "WireGuard port number to use for Netbird client instance") + // do not set default, because it will override whatever custom value was set + upCmd.PersistentFlags().IntVar(&wgPort, "wg-port", 0, "WireGuard port number to use for Netbird client instance") } diff --git a/client/internal/config.go b/client/internal/config.go index b85a4865f8c..e96c577a139 100644 --- a/client/internal/config.go +++ b/client/internal/config.go @@ -239,31 +239,50 @@ func update(input ConfigInput) (*Config, error) { return nil, err } config.SSHKey = string(pem) + log.Infof("generated config.SSHKey") refresh = true } - if config.WgPort == 0 { + if config.WgPort == 0 && input.WgPort == 0 { + log.Infof("using default Wireguard Port: %#v ", iface.DefaultWgPort) config.WgPort = iface.DefaultWgPort refresh = true } - - if input.WgIface == "" { + if config.WgIface == "" && input.WgIface == "" { + log.Infof("using default Wireguard Interface Name: %#v ", iface.WgInterfaceDefault) config.WgIface = iface.WgInterfaceDefault refresh = true } + if input.WgIface != "" && input.WgIface != config.WgIface { + log.Infof("new Wireguard Interface Name provided, updated to %#v (old value %#v)", input.WgIface, config.WgIface) + config.WgIface = input.WgIface + refresh = true + } + + if input.WgPort != 0 && input.WgPort != config.WgPort { + log.Infof("new Wireguard Port provided, updated to %#v (old value %#v)", input.WgPort, config.WgPort) + config.WgPort = input.WgPort + refresh = true + } + if !slices.Contains(config.IFaceBlackList, config.WgIface) { - config.IFaceBlackList = append([]string{config.WgIface}, config.IFaceBlackList...) + newBlacklist := append([]string{config.WgIface}, config.IFaceBlackList...) + log.Infof("prepending Wireguard Interface Name to interface blacklist %#v, updated to %v (old value %v)", config.WgIface, newBlacklist, config.IFaceBlackList) + config.IFaceBlackList = newBlacklist refresh = true } - if input.NATExternalIPs != nil && len(config.NATExternalIPs) != len(input.NATExternalIPs) { + if input.NATExternalIPs != nil && !slices.Equal(config.NATExternalIPs, input.NATExternalIPs) { + log.Infof("new NAT External IPs provided, updated to %v (old value %v)", input.NATExternalIPs, config.NATExternalIPs) config.NATExternalIPs = input.NATExternalIPs refresh = true } - if input.CustomDNSAddress != nil { - config.CustomDNSAddress = string(input.CustomDNSAddress) + customDNSAddress := string(input.CustomDNSAddress) + if customDNSAddress != "" && customDNSAddress != config.CustomDNSAddress { + log.Infof("new Custom DNS provided, updated to %v (old value %v)", customDNSAddress, config.CustomDNSAddress) + config.CustomDNSAddress = customDNSAddress refresh = true }