Skip to content

Commit d54fa92

Browse files
committed
Added auto-detection of IPv6 on linux
1 parent 235fca1 commit d54fa92

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ import (
3535
"syscall"
3636
"time"
3737

38-
_ "github.com/arangodb-helper/arangodb/client"
39-
service "github.com/arangodb-helper/arangodb/service"
4038
homedir "github.com/mitchellh/go-homedir"
4139
logging "github.com/op/go-logging"
4240
"github.com/pkg/errors"
4341
"github.com/spf13/cobra"
4442
"github.com/spf13/pflag"
43+
44+
_ "github.com/arangodb-helper/arangodb/client"
45+
"github.com/arangodb-helper/arangodb/pkg/net"
46+
service "github.com/arangodb-helper/arangodb/service"
4547
)
4648

4749
// Configuration data with defaults:
@@ -116,7 +118,7 @@ func init() {
116118
f.BoolVar(&allPortOffsetsUnique, "starter.unique-port-offsets", false, "If set, all peers will get a unique port offset. If false (default) only portOffset+peerAddress pairs will be unique.")
117119
f.StringVar(&dataDir, "starter.data-dir", getEnvVar("DATA_DIR", "."), "directory to store all data the starter generates (and holds actual database directories)")
118120
f.BoolVar(&debugCluster, "starter.debug-cluster", getEnvVar("DEBUG_CLUSTER", "") != "", "If set, log more information to debug a cluster")
119-
f.BoolVar(&disableIPv6, "starter.disable-ipv6", false, "If set, no IPv6 notation will be used. Use this only when IPv6 address family is disabled")
121+
f.BoolVar(&disableIPv6, "starter.disable-ipv6", !net.IsIPv6Supported(), "If set, no IPv6 notation will be used. Use this only when IPv6 address family is disabled")
120122

121123
f.BoolVar(&verbose, "log.verbose", false, "Turn on debug logging")
122124

pkg/net/ipv6.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Ewout Prangsma
21+
//
22+
23+
// +build !linux
24+
25+
package net
26+
27+
// IsIPv6Supported returns true when IPv6 support is available,
28+
// false when it is not.
29+
// Note that it is not possible on all platforms to properly
30+
// detect IPv6 support.
31+
func IsIPv6Supported() bool {
32+
return true
33+
}

pkg/net/ipv6_linux.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Ewout Prangsma
21+
//
22+
23+
package net
24+
25+
import "os"
26+
27+
// IsIPv6Supported returns true when IPv6 support is available,
28+
// false when it is not.
29+
// Note that it is not possible on all platforms to properly
30+
// detect IPv6 support.
31+
func IsIPv6Supported() bool {
32+
if _, err := os.Stat("/proc/net/if_inet6"); err == nil {
33+
return true
34+
}
35+
return false
36+
}

0 commit comments

Comments
 (0)