8
8
"strings"
9
9
gotemplate "text/template"
10
10
11
+ ngfAPI "github.com./nginxinc/nginx-gateway-fabric/apis/v1alpha1"
11
12
"github.com./nginxinc/nginx-gateway-fabric/internal/framework/helpers"
12
13
"github.com./nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/http"
13
14
"github.com./nginxinc/nginx-gateway-fabric/internal/mode/static/state/dataplane"
@@ -58,7 +59,8 @@ var grpcBaseHeaders = []http.Header{
58
59
}
59
60
60
61
func executeServers (conf dataplane.Configuration ) []executeResult {
61
- servers , httpMatchPairs := createServers (conf .HTTPServers , conf .SSLServers )
62
+ ipv6Enabled := isIPv6Enabled (conf .BaseHTTPConfig )
63
+ servers , httpMatchPairs := createServers (conf .HTTPServers , conf .SSLServers , ipv6Enabled )
62
64
63
65
serverResult := executeResult {
64
66
dest : httpConfigFile ,
@@ -86,6 +88,14 @@ func executeServers(conf dataplane.Configuration) []executeResult {
86
88
return allResults
87
89
}
88
90
91
+ // getIPFamily returns whether or not the configuration is set to use IPv6.
92
+ func isIPv6Enabled (baseHTTPConfig dataplane.BaseHTTPConfig ) bool {
93
+ if baseHTTPConfig .IPFamily == ngfAPI .IPv6 || baseHTTPConfig .IPFamily == ngfAPI .Dual {
94
+ return true
95
+ }
96
+ return false
97
+ }
98
+
89
99
func createAdditionFileResults (conf dataplane.Configuration ) []executeResult {
90
100
uniqueAdditions := make (map [string ][]byte )
91
101
@@ -141,17 +151,23 @@ func createIncludes(additions []dataplane.Addition) []string {
141
151
return includes
142
152
}
143
153
144
- func createServers (httpServers , sslServers []dataplane.VirtualServer ) ([]http.Server , httpMatchPairs ) {
154
+ func createServers (
155
+ httpServers ,
156
+ sslServers []dataplane.VirtualServer ,
157
+ ipv6Enabled bool ,
158
+ ) ([]http.Server , httpMatchPairs ) {
145
159
servers := make ([]http.Server , 0 , len (httpServers )+ len (sslServers ))
146
160
finalMatchPairs := make (httpMatchPairs )
147
161
148
162
for serverID , s := range httpServers {
163
+ s .IPv6Enabled = ipv6Enabled
149
164
httpServer , matchPairs := createServer (s , serverID )
150
165
servers = append (servers , httpServer )
151
166
maps .Copy (finalMatchPairs , matchPairs )
152
167
}
153
168
154
169
for serverID , s := range sslServers {
170
+ s .IPv6Enabled = ipv6Enabled
155
171
sslServer , matchPair := createSSLServer (s , serverID )
156
172
servers = append (servers , sslServer )
157
173
maps .Copy (finalMatchPairs , matchPair )
@@ -165,6 +181,7 @@ func createSSLServer(virtualServer dataplane.VirtualServer, serverID int) (http.
165
181
return http.Server {
166
182
IsDefaultSSL : true ,
167
183
Port : virtualServer .Port ,
184
+ IPv6Enabled : virtualServer .IPv6Enabled ,
168
185
}, nil
169
186
}
170
187
@@ -176,10 +193,11 @@ func createSSLServer(virtualServer dataplane.VirtualServer, serverID int) (http.
176
193
Certificate : generatePEMFileName (virtualServer .SSL .KeyPairID ),
177
194
CertificateKey : generatePEMFileName (virtualServer .SSL .KeyPairID ),
178
195
},
179
- Locations : locs ,
180
- Port : virtualServer .Port ,
181
- GRPC : grpc ,
182
- Includes : createIncludes (virtualServer .Additions ),
196
+ Locations : locs ,
197
+ Port : virtualServer .Port ,
198
+ GRPC : grpc ,
199
+ Includes : createIncludes (virtualServer .Additions ),
200
+ IPv6Enabled : virtualServer .IPv6Enabled ,
183
201
}, matchPairs
184
202
}
185
203
@@ -188,17 +206,19 @@ func createServer(virtualServer dataplane.VirtualServer, serverID int) (http.Ser
188
206
return http.Server {
189
207
IsDefaultHTTP : true ,
190
208
Port : virtualServer .Port ,
209
+ IPv6Enabled : virtualServer .IPv6Enabled ,
191
210
}, nil
192
211
}
193
212
194
213
locs , matchPairs , grpc := createLocations (& virtualServer , serverID )
195
214
196
215
return http.Server {
197
- ServerName : virtualServer .Hostname ,
198
- Locations : locs ,
199
- Port : virtualServer .Port ,
200
- GRPC : grpc ,
201
- Includes : createIncludes (virtualServer .Additions ),
216
+ ServerName : virtualServer .Hostname ,
217
+ Locations : locs ,
218
+ Port : virtualServer .Port ,
219
+ GRPC : grpc ,
220
+ Includes : createIncludes (virtualServer .Additions ),
221
+ IPv6Enabled : virtualServer .IPv6Enabled ,
202
222
}, matchPairs
203
223
}
204
224
0 commit comments