tackle ipv6 wildcard binds

Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
Christian Richter
2024-10-24 09:56:45 +02:00
parent 0cb8331284
commit 0dc9e99761
3 changed files with 18 additions and 2 deletions

View File

@@ -13,12 +13,14 @@ import (
// NewGRPCCheck checks the reachability of a grpc server.
func NewGRPCCheck(address string) func(context.Context) error {
return func(_ context.Context) error {
if strings.Contains(address, "0.0.0.0") {
if strings.Contains(address, "0.0.0.0") || strings.Contains(address, "::") {
outboundIp, err := handlers.GetOutBoundIP()
if err != nil {
return err
}
address = strings.Replace(address, "0.0.0.0", outboundIp, 1)
address = strings.Replace(address, "::", "["+outboundIp+"]", 1)
address = strings.Replace(address, "[::]", "["+outboundIp+"]", 1)
}
conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))

View File

@@ -12,12 +12,14 @@ import (
// NewHTTPCheck checks the reachability of a http server.
func NewHTTPCheck(url string) func(context.Context) error {
return func(_ context.Context) error {
if strings.Contains(url, "0.0.0.0") {
if strings.Contains(url, "0.0.0.0") || strings.Contains(url, "::") {
outboundIp, err := handlers.GetOutBoundIP()
if err != nil {
return err
}
url = strings.Replace(url, "0.0.0.0", outboundIp, 1)
url = strings.Replace(url, "::", outboundIp, 1)
url = strings.Replace(url, "[::]", "["+outboundIp+"]", 1)
}
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {

View File

@@ -2,13 +2,25 @@ package checks
import (
"context"
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
"net"
"strings"
"time"
)
// NewTCPCheck returns a check that connects to a given tcp endpoint.
func NewTCPCheck(address string) func(context.Context) error {
return func(_ context.Context) error {
if strings.Contains(address, "0.0.0.0") || strings.Contains(address, "::") {
outboundIp, err := handlers.GetOutBoundIP()
if err != nil {
return err
}
address = strings.Replace(address, "0.0.0.0", outboundIp, 1)
address = strings.Replace(address, "::", outboundIp, 1)
address = strings.Replace(address, "[::]", "["+outboundIp+"]", 1)
}
conn, err := net.DialTimeout("tcp", address, 3*time.Second)
if err != nil {
return err