Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 8beb2f1

Browse files
committed
Discover the IP address to based on default gateway
Without this check, Linux bridge docker0 or Winwdows DockerNAT could be selected as "host IP" but won't allow to route to container Same issue probalby exists on Linux with docker0 bridge Here we discover the default gateway, and search for the interface configured on the same network. Signed-off-by: Nicolas De Loof <[email protected]>
1 parent c1a8217 commit 8beb2f1

File tree

11 files changed

+347
-4
lines changed

11 files changed

+347
-4
lines changed

Gopkg.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ required = ["github.com/wadey/gocovmerge"]
121121
name = "github.com/wadey/gocovmerge"
122122
branch = "master"
123123

124+
[[constraint]]
125+
# see https://github.com/jackpal/gateway/pull/21
126+
source = "github.com/ndeloof/gateway"
127+
name = "github.com/jackpal/gateway"
128+
revision = "10816db7ab2f4b71e71dba9420bfa67d5be27b33"
129+
124130
[prune]
125131
non-go = true
126132
unused-packages = true

e2e/helper_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ package e2e
33
import (
44
"fmt"
55
"io/ioutil"
6+
"net"
67
"strconv"
78
"strings"
89
"testing"
910
"time"
1011

1112
"github.com/docker/app/internal"
13+
"github.com/jackpal/gateway"
1214
"gotest.tools/assert"
1315
"gotest.tools/fs"
1416
"gotest.tools/icmd"
15-
net2 "k8s.io/apimachinery/pkg/util/net"
1617
)
1718

1819
// readFile returns the content of the file at the designated path normalizing
@@ -157,9 +158,23 @@ func (c *Container) getIP(t *testing.T) string {
157158
if host != "" {
158159
return host
159160
}
160-
ip, err := net2.ChooseHostInterface()
161+
// Discover default gateway
162+
gw, err := gateway.DiscoverGateway()
161163
assert.NilError(t, err)
162-
host = ip.String()
164+
165+
// Search for the interface configured on the same network as the gateway
166+
addrs, err := net.InterfaceAddrs()
167+
assert.NilError(t, err)
168+
for _, a := range addrs {
169+
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
170+
net1 := ipnet.IP.Mask(ipnet.Mask).String()
171+
net2 := gw.Mask(ipnet.Mask).String()
172+
if net1 == net2 {
173+
host = ipnet.IP.String()
174+
break
175+
}
176+
}
177+
}
163178
return host
164179
}
165180

vendor/github.com/jackpal/gateway/LICENSE

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/jackpal/gateway/gateway_common.go

Lines changed: 160 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/jackpal/gateway/gateway_darwin.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/jackpal/gateway/gateway_freebsd.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/jackpal/gateway/gateway_linux.go

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/jackpal/gateway/gateway_solaris.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/jackpal/gateway/gateway_unimplemented.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)