From 0dc9e99761475789d197f939c6f094cc97c23179 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 24 Oct 2024 09:56:45 +0200 Subject: [PATCH] tackle ipv6 wildcard binds Signed-off-by: Christian Richter --- ocis-pkg/checks/checkgrpc.go | 4 +++- ocis-pkg/checks/checkhttp.go | 4 +++- ocis-pkg/checks/checktcp.go | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ocis-pkg/checks/checkgrpc.go b/ocis-pkg/checks/checkgrpc.go index 20007bf286..ebb22fb29d 100644 --- a/ocis-pkg/checks/checkgrpc.go +++ b/ocis-pkg/checks/checkgrpc.go @@ -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())) diff --git a/ocis-pkg/checks/checkhttp.go b/ocis-pkg/checks/checkhttp.go index b0c1f5c45d..1fab4e118b 100644 --- a/ocis-pkg/checks/checkhttp.go +++ b/ocis-pkg/checks/checkhttp.go @@ -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://") { diff --git a/ocis-pkg/checks/checktcp.go b/ocis-pkg/checks/checktcp.go index 475ff50e82..d89da356c3 100644 --- a/ocis-pkg/checks/checktcp.go +++ b/ocis-pkg/checks/checktcp.go @@ -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