You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/agent/xds/platform/net_linux.go

39 lines
732 B

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build linux
package platform
import (
"fmt"
"os"
"sync"
)
const ipv6SupportProcFile = "/proc/net/if_inet6"
var (
ipv6SupportOnce sync.Once
ipv6Supported bool
ipv6SupportedErr error
)
func SupportsIPv6() (bool, error) {
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
}