client: Add a preferred address family option for network-interface (#23389)

to prefer ipv4 or ipv6 when deducing IP from network interface

Co-authored-by: Daniel Bennett <dbennett@hashicorp.com>
This commit is contained in:
guifran001
2024-07-12 16:30:38 -04:00
committed by GitHub
parent b58b8114f9
commit 1c44521543
11 changed files with 217 additions and 42 deletions

View File

@@ -116,6 +116,7 @@ func (c *Command) readConfig() *Config {
flags.StringVar(&servers, "servers", "", "")
flags.Var((*flaghelper.StringFlag)(&meta), "meta", "")
flags.StringVar(&cmdConfig.Client.NetworkInterface, "network-interface", "", "")
flags.StringVar((*string)(&cmdConfig.Client.PreferredAddressFamily), "preferred-address-family", "", "ipv4 or ipv6")
flags.IntVar(&cmdConfig.Client.NetworkSpeed, "network-speed", 0, "")
// General options
@@ -485,6 +486,14 @@ func (c *Command) IsValidConfig(config, cmdConfig *Config) bool {
return false
}
if err := config.Client.PreferredAddressFamily.Validate(); err != nil {
c.Ui.Error(fmt.Sprintf("Invalid preferred-address-family value: %s (valid values: %s, %s)",
config.Client.PreferredAddressFamily,
structs.NodeNetworkAF_IPv4, structs.NodeNetworkAF_IPv6),
)
return false
}
if !config.DevMode {
// Ensure that we have the directories we need to run.
if config.Server.Enabled && config.DataDir == "" {
@@ -1549,6 +1558,11 @@ Client Options:
-network-interface
Forces the network fingerprinter to use the specified network interface.
-preferred-address-family
Specify which IP family to prefer when selecting an IP address of the
network interface. Valid values are "ipv4" and "ipv6". When not specified,
the agent will not sort the addresses and use the first one.
-network-speed
The default speed for network interfaces in MBits if the link speed can not