Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain committed Oct 31, 2024
1 parent 30d1b00 commit 00e8a5c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
9 changes: 2 additions & 7 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/utils/net/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
{
Expand Down

0 comments on commit 00e8a5c

Please sign in to comment.