Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 3199cd1

Browse files
Arko DasguptathaJeztah
authored andcommitted
Skip IPAddr validation for "host-gateway" string
Relates to - moby/moby 40007 The above PR added support in moby, that detects if a special string "host-gateway" is added to the IP section of --add-host, and if true, replaces it with a special IP value (value of --host-gateway-ip Daemon flag which defaults to the IP of the default bridge). This PR is needed to skip the validation for the above feature Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 67ebcd6dcf82c00f133b886a9a343b67124e58ec) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 365118982638094138bb0f88ab23f438aafb7331 Component: cli
1 parent c9f1c43 commit 3199cd1

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

components/cli/opts/hosts.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ var (
2424
DefaultTLSHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultTLSHTTPPort)
2525
// DefaultNamedPipe defines the default named pipe used by docker on Windows
2626
DefaultNamedPipe = `//./pipe/docker_engine`
27+
// hostGatewayName defines a special string which users can append to --add-host
28+
// to add an extra entry in /etc/hosts that maps host.docker.internal to the host IP
29+
// TODO Consider moving the HostGatewayName constant defined in docker at
30+
// github.com/docker/docker/daemon/network/constants.go outside of the "daemon"
31+
// package, so that the CLI can consume it.
32+
hostGatewayName = "host-gateway"
2733
)
2834

2935
// ValidateHost validates that the specified string is a valid host and returns it.
@@ -160,8 +166,11 @@ func ValidateExtraHost(val string) (string, error) {
160166
if len(arr) != 2 || len(arr[0]) == 0 {
161167
return "", fmt.Errorf("bad format for add-host: %q", val)
162168
}
163-
if _, err := ValidateIPAddress(arr[1]); err != nil {
164-
return "", fmt.Errorf("invalid IP address in add-host: %q", arr[1])
169+
// Skip IPaddr validation for "host-gateway" string
170+
if arr[1] != hostGatewayName {
171+
if _, err := ValidateIPAddress(arr[1]); err != nil {
172+
return "", fmt.Errorf("invalid IP address in add-host: %q", arr[1])
173+
}
165174
}
166175
return val, nil
167176
}

0 commit comments

Comments
 (0)