Skip to content

Commit

Permalink
use ip4 as default to avoid a bunch of test failures and failure in i…
Browse files Browse the repository at this point in the history
…p4 environment with Round Robin DNS
  • Loading branch information
ldemailly committed May 13, 2022
1 parent 7267c6e commit f289127
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -279,6 +279,9 @@ properly). Can be in the form of host:port, ip:port, port or "disabled" to
disable the feature. (default "8081")
-resolve IP
Resolve host name to this IP
-resolve-ip-type type
Resolve type: ip4 for ipv4, ip6 for ipv6 only, use ip for both (default
ip4)
-runid int
Optional RunID to add to json result and auto save filename, to match
server mode
Expand Down
15 changes: 9 additions & 6 deletions fnet/network.go
Expand Up @@ -65,9 +65,10 @@ var (
Payload []byte
// Atomically incremented counter for dns resolution.
dnsRoundRobin uint32 = 0xffffffff // we want the first one, after increment to be 0
// IP types to resolve.
FlagResolveIP = dflag.DynString(flag.CommandLine, "resolve-ip", "ip",
"Resolve type: ip4 for ipv4, ip6 for ipv6 only, default/ip for both")
// IP types to resolve. With round robin you are likely to get ipv6 which may not work
// (in particular some test environments like the CI do have ipv6 for localhost but fail to connect).
FlagResolveIPType = dflag.DynString(flag.CommandLine, "resolve-ip-type", "ip4",
"Resolve `type`: ip4 for ipv4, ip6 for ipv6 only, use ip for both")
)

// nolint: gochecknoinits // needed here (unit change)
Expand Down Expand Up @@ -294,8 +295,10 @@ func Resolve(host string, port string) (*net.TCPAddr, error) {
}

// ResolveByProto returns the address of the host,port suitable for net.Dial.
// nil in case of errors. works for both "tcp" and "udp" proto. can also use
// tcp6 for ipv6 address, tcp4 for ipv4; otherwise it's either/both.
// nil in case of errors. works for both "tcp" and "udp" proto.
// Limit which address type is returned using `resolve-ip` ip4/ip6/ip (for both, default).
// If the same host is requested, and it has more than 1 IP, returned value will roundrobin
// over the ips.
func ResolveByProto(host string, port string, proto string) (*HostPortAddr, error) {
log.Debugf("Resolve() called with host=%s port=%s proto=%s", host, port, proto)
dest := &HostPortAddr{}
Expand All @@ -304,7 +307,7 @@ func ResolveByProto(host string, port string, proto string) (*HostPortAddr, erro
host = host[1 : len(host)-1]
}
isAddr := net.ParseIP(host)
filter := FlagResolveIP.Get()
filter := FlagResolveIPType.Get()
var err error
if isAddr != nil {
log.Debugf("Host already an IP, will go to %s", isAddr)
Expand Down

0 comments on commit f289127

Please sign in to comment.