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 c266511
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 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
}

Check warning on line 107 in internal/gatewayapi/listener.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/listener.go#L106-L107

Added lines #L106 - L107 were not covered by tests

// 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
}

Check warning on line 198 in internal/xds/translator/listener.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/listener.go#L197-L198

Added lines #L197 - L198 were not covered by tests
return []*listenerv3.AdditionalAddress{
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- additionalAddresses:
- address:
socketAddress:
address: ::1
address: '::'
portValue: 8082
address:
socketAddress:
Expand Down

0 comments on commit c266511

Please sign in to comment.