Skip to content

Commit 501991d

Browse files
committed
atenet/router: bind the Envoy ingress listeners dual-stack
The HTTP and HTTPS ingress listeners bound 0.0.0.0 only, so on a dual-stack cluster Envoy answered on the router Service's IPv4 ClusterIP and on nothing at all for IPv6. Each primary socket now carries an additional "::" address on the same port. Ipv4Compat stays false on the additional address: clearing IPV6_V6ONLY would collide with the primary already bound to that port. Leaving the primary alone is what keeps an IPv4-only cluster unchanged -- with the caveat that a node lacking AF_INET6 entirely could not bind "::" and the listener would not come up. First of three commits binding atenet's gateways dual-stack.
1 parent 43fa6cc commit 501991d

2 files changed

Lines changed: 55 additions & 12 deletions

File tree

‎cmd/atenet/internal/router/xds.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,27 @@ func (x *XdsServer) buildTracing() *hcmv3.HttpConnectionManager_Tracing {
11081108
}
11091109
}
11101110

1111+
// dualStackAdditionalAddresses returns the IPv6 half of a dual-stack ingress
1112+
// listener, to pair with a primary 0.0.0.0 socket on the same port. Ipv4Compat
1113+
// stays false: clearing IPV6_V6ONLY would collide with that primary.
1114+
func dualStackAdditionalAddresses(port uint32) []*listenerv3.AdditionalAddress {
1115+
return []*listenerv3.AdditionalAddress{
1116+
{
1117+
Address: &corev3.Address{
1118+
Address: &corev3.Address_SocketAddress{
1119+
SocketAddress: &corev3.SocketAddress{
1120+
Address: "::",
1121+
Ipv4Compat: false,
1122+
PortSpecifier: &corev3.SocketAddress_PortValue{
1123+
PortValue: port,
1124+
},
1125+
},
1126+
},
1127+
},
1128+
},
1129+
}
1130+
}
1131+
11111132
func (x *XdsServer) buildListener() *listenerv3.Listener {
11121133
hcm := x.buildHcm("ingress_http", true)
11131134

@@ -1123,6 +1144,7 @@ func (x *XdsServer) buildListener() *listenerv3.Listener {
11231144
},
11241145
},
11251146
},
1147+
AdditionalAddresses: dualStackAdditionalAddresses(uint32(x.ingressPort)),
11261148
FilterChains: []*listenerv3.FilterChain{
11271149
{
11281150
Filters: []*listenerv3.Filter{
@@ -1182,6 +1204,7 @@ func (x *XdsServer) buildHttpsListener() *listenerv3.Listener {
11821204
},
11831205
},
11841206
},
1207+
AdditionalAddresses: dualStackAdditionalAddresses(uint32(x.httpsPort)),
11851208
FilterChains: []*listenerv3.FilterChain{
11861209
{
11871210
Filters: []*listenerv3.Filter{

‎cmd/atenet/internal/router/xds_test.go‎

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,36 @@ import (
4848
"github.com/agent-substrate/substrate/internal/atunnel"
4949
)
5050

51+
// assertDualStackIngress checks an ingress listener keeps its 0.0.0.0 primary
52+
// and gains exactly one "::" socket on the same port.
53+
func assertDualStackIngress(t *testing.T, l *listenerv3.Listener, wantPort uint32) {
54+
t.Helper()
55+
56+
sa := l.GetAddress().GetSocketAddress()
57+
if sa.GetAddress() != "0.0.0.0" {
58+
t.Errorf("Expected address '0.0.0.0', got %s", sa.GetAddress())
59+
}
60+
if sa.GetPortValue() != wantPort {
61+
t.Errorf("Expected port %d, got %d", wantPort, sa.GetPortValue())
62+
}
63+
64+
addrs := l.GetAdditionalAddresses()
65+
if len(addrs) != 1 {
66+
t.Fatalf("Expected 1 additional address on %s, got %d", l.GetName(), len(addrs))
67+
}
68+
69+
asa := addrs[0].GetAddress().GetSocketAddress()
70+
if asa.GetAddress() != "::" {
71+
t.Errorf("Expected additional address '::', got %s", asa.GetAddress())
72+
}
73+
if asa.GetIpv4Compat() {
74+
t.Error("Expected additional address Ipv4Compat to be false")
75+
}
76+
if asa.GetPortValue() != wantPort {
77+
t.Errorf("Expected additional port %d, got %d", wantPort, asa.GetPortValue())
78+
}
79+
}
80+
5181
func TestXdsServer_UpdateSnapshot(t *testing.T) {
5282
server := NewXdsServer(18000)
5383
server.SetConfig(8081, 50052, "10.0.0.1")
@@ -150,14 +180,7 @@ func TestXdsServer_UpdateSnapshot(t *testing.T) {
150180
if raw, exists := listenersMap[IngressHTTPListener]; !exists {
151181
t.Errorf("Listener name '%s' is missing from snapshot listeners", IngressHTTPListener)
152182
} else {
153-
l := raw.(*listenerv3.Listener)
154-
sa := l.GetAddress().GetSocketAddress()
155-
if sa.GetPortValue() != 8081 {
156-
t.Errorf("Expected port 8081, got %d", sa.GetPortValue())
157-
}
158-
if sa.GetAddress() != "0.0.0.0" {
159-
t.Errorf("Expected address '0.0.0.0', got %s", sa.GetAddress())
160-
}
183+
assertDualStackIngress(t, raw.(*listenerv3.Listener), 8081)
161184
}
162185
}
163186

@@ -192,10 +215,7 @@ func TestXdsServer_UpdateSnapshot_WithHttps(t *testing.T) {
192215
t.Errorf("Listener name '%s' is missing from snapshot listeners", IngressHTTPSListener)
193216
} else {
194217
l := raw.(*listenerv3.Listener)
195-
sa := l.GetAddress().GetSocketAddress()
196-
if sa.GetPortValue() != 8443 {
197-
t.Errorf("Expected port 8443, got %d", sa.GetPortValue())
198-
}
218+
assertDualStackIngress(t, l, 8443)
199219

200220
// Verify the TLS config references the serving cert via SDS rather
201221
// than embedding it: inline filename DataSources are read only once

0 commit comments

Comments
 (0)