2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build linux
|
2021-02-19 20:38:43 +00:00
|
|
|
|
2023-08-15 18:57:07 +00:00
|
|
|
package platform
|
2021-02-19 20:38:43 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
const ipv6SupportProcFile = "/proc/net/if_inet6"
|
|
|
|
|
|
|
|
var (
|
|
|
|
ipv6SupportOnce sync.Once
|
|
|
|
ipv6Supported bool
|
|
|
|
ipv6SupportedErr error
|
|
|
|
)
|
|
|
|
|
2023-08-15 18:57:07 +00:00
|
|
|
func SupportsIPv6() (bool, error) {
|
2021-02-19 20:38:43 +00:00
|
|
|
ipv6SupportOnce.Do(func() {
|
|
|
|
ipv6Supported, ipv6SupportedErr = checkIfKernelSupportsIPv6()
|
|
|
|
})
|
|
|
|
return ipv6Supported, ipv6SupportedErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkIfKernelSupportsIPv6() (bool, error) {
|
|
|
|
_, err := os.Stat(ipv6SupportProcFile)
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return false, nil
|
|
|
|
} else if err != nil {
|
|
|
|
return false, fmt.Errorf("error checking for ipv6 support file %s: %w", ipv6SupportProcFile, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|