Skip to content

Commit

Permalink
fix overriding WgIface/WgPort with defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarewk committed Apr 27, 2023
1 parent 2985ef4 commit cc3889f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
7 changes: 4 additions & 3 deletions client/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")

}

Expand Down
33 changes: 26 additions & 7 deletions client/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit cc3889f

Please sign in to comment.