From 00e8a5c9ba965d4bb7a3c0502424c3c85bcb5c81 Mon Sep 17 00:00:00 2001 From: zirain Date: Thu, 31 Oct 2024 19:40:54 +0800 Subject: [PATCH] nit Signed-off-by: zirain --- internal/gatewayapi/listener.go | 9 ++------- internal/utils/net/ip.go | 5 +++++ internal/xds/translator/listener.go | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/gatewayapi/listener.go b/internal/gatewayapi/listener.go index 90d817668f7a..cc1561d4c146 100644 --- a/internal/gatewayapi/listener.go +++ b/internal/gatewayapi/listener.go @@ -25,11 +25,6 @@ import ( "github.com/envoyproxy/gateway/internal/utils/net" ) -const ( - ipv4ListenerAddress = "0.0.0.0" - ipv6ListenerAddress = "::1" -) - var _ ListenersTranslator = (*Translator)(nil) type ListenersTranslator interface { @@ -106,9 +101,9 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource continue } - address := ipv4ListenerAddress + address := net.IPv4ListenerAddress if net.PreferIPFamily(t.IPv6First, gateway.envoyProxy) == egv1a1.IPv6 { - address = ipv6ListenerAddress + address = net.IPv6ListenerAddress } // Add the listener to the Xds IR diff --git a/internal/utils/net/ip.go b/internal/utils/net/ip.go index be130938c36c..99bde677062a 100644 --- a/internal/utils/net/ip.go +++ b/internal/utils/net/ip.go @@ -12,6 +12,11 @@ import ( egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" ) +const ( + IPv4ListenerAddress = "0.0.0.0" + IPv6ListenerAddress = "::" +) + func IsIPv6(s string) bool { ip := net.ParseIP(s) if ip == nil { diff --git a/internal/xds/translator/listener.go b/internal/xds/translator/listener.go index b938f52cefa6..c4722c7e6deb 100644 --- a/internal/xds/translator/listener.go +++ b/internal/xds/translator/listener.go @@ -35,6 +35,7 @@ import ( egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/ir" + "github.com/envoyproxy/gateway/internal/utils/net" "github.com/envoyproxy/gateway/internal/utils/protocov" xdsfilters "github.com/envoyproxy/gateway/internal/xds/filters" ) @@ -190,10 +191,10 @@ func additionalAddressByIPFamily(currentAddress string, ipFamily *ir.IPFamily, p } if *ipFamily == ir.Dualstack { - additionalAddress := "::1" + additionalAddress := net.IPv6ListenerAddress // If the current address is already IPv6, use the IPv4 equivalent - if currentAddress == "::1" { - additionalAddress = "0.0.0.0" + if currentAddress == net.IPv6ListenerAddress { + additionalAddress = net.IPv4ListenerAddress } return []*listenerv3.AdditionalAddress{ {