Skip to content

Fix IPV6 detection #2905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ sudo: required
services:
- docker

# FIXME(#46924): these two commands are required to enable IPv6,
# they shouldn't exist, please revert once more official solutions appeared.
# see https://github.com/travis-ci/travis-ci/issues/8891#issuecomment-353403729
before_install:
- echo '{"ipv6":true,"fixed-cidr-v6":"2001:db8:1::/64"}' | sudo tee /etc/docker/daemon.json
- sudo service docker restart

language: generic

notifications:
Expand Down
23 changes: 20 additions & 3 deletions internal/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// IsIPV6 checks if the input contains a valid IPV6 address
func IsIPV6(ip _net.IP) bool {
return ip.To4() == nil
return ip != nil && ip.To4() == nil
}

// IsPortAvailable checks if a TCP port is available or not
Expand All @@ -37,8 +37,25 @@ func IsPortAvailable(p int) bool {
return false
}

// IsIPv6Enabled checks if IPV6 is enabled or not
// IsIPv6Enabled checks if IPV6 is enabled or not and we have
// at least one configured in the pod
func IsIPv6Enabled() bool {
cmd := exec.Command("test", "-f", "/proc/net/if_inet6")
return cmd.Run() == nil
if cmd.Run() != nil {
return false
}

addrs, err := _net.InterfaceAddrs()
if err != nil {
return false
}

for _, addr := range addrs {
ip, _, _ := _net.ParseCIDR(addr.String())
if IsIPV6(ip) {
return true
}
}

return false
}
7 changes: 7 additions & 0 deletions internal/net/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ func TestIsPortAvailable(t *testing.T) {
t.Fatalf("expected port %v to not be available", p)
}
}

func TestIsIPv6Enabled(t *testing.T) {
isEnabled := IsIPv6Enabled()
if !isEnabled {
t.Fatalf("expected IPV6 be enabled")
}
}