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 := getIPFamily (conf .BaseHTTPConfig )
63
+ servers , httpMatchPairs := createServers (conf .HTTPServers , conf .SSLServers , ipv6Enabled )
62
64
63
65
serverResult := executeResult {
64
66
dest : httpConfigFile ,
@@ -86,6 +88,15 @@ 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 getIPFamily (baseHTTPConfig dataplane.BaseHTTPConfig ) bool {
93
+ if baseHTTPConfig .IPFamily == ngfAPI .IPv6 || baseHTTPConfig .IPFamily == ngfAPI .Both {
94
+ return true
95
+ }
96
+
97
+ return false
98
+ }
99
+
89
100
func createAdditionFileResults (conf dataplane.Configuration ) []executeResult {
90
101
uniqueAdditions := make (map [string ][]byte )
91
102
@@ -141,17 +152,23 @@ func createIncludes(additions []dataplane.Addition) []string {
141
152
return includes
142
153
}
143
154
144
- func createServers (httpServers , sslServers []dataplane.VirtualServer ) ([]http.Server , httpMatchPairs ) {
155
+ func createServers (
156
+ httpServers ,
157
+ sslServers []dataplane.VirtualServer ,
158
+ ipv6Enabled bool ,
159
+ ) ([]http.Server , httpMatchPairs ) {
145
160
servers := make ([]http.Server , 0 , len (httpServers )+ len (sslServers ))
146
161
finalMatchPairs := make (httpMatchPairs )
147
162
148
163
for serverID , s := range httpServers {
164
+ s .IPv6Enabled = ipv6Enabled
149
165
httpServer , matchPairs := createServer (s , serverID )
150
166
servers = append (servers , httpServer )
151
167
maps .Copy (finalMatchPairs , matchPairs )
152
168
}
153
169
154
170
for serverID , s := range sslServers {
171
+ s .IPv6Enabled = ipv6Enabled
155
172
sslServer , matchPair := createSSLServer (s , serverID )
156
173
servers = append (servers , sslServer )
157
174
maps .Copy (finalMatchPairs , matchPair )
@@ -165,6 +182,7 @@ func createSSLServer(virtualServer dataplane.VirtualServer, serverID int) (http.
165
182
return http.Server {
166
183
IsDefaultSSL : true ,
167
184
Port : virtualServer .Port ,
185
+ IPv6Enabled : virtualServer .IPv6Enabled ,
168
186
}, nil
169
187
}
170
188
@@ -176,10 +194,11 @@ func createSSLServer(virtualServer dataplane.VirtualServer, serverID int) (http.
176
194
Certificate : generatePEMFileName (virtualServer .SSL .KeyPairID ),
177
195
CertificateKey : generatePEMFileName (virtualServer .SSL .KeyPairID ),
178
196
},
179
- Locations : locs ,
180
- Port : virtualServer .Port ,
181
- GRPC : grpc ,
182
- Includes : createIncludes (virtualServer .Additions ),
197
+ Locations : locs ,
198
+ Port : virtualServer .Port ,
199
+ GRPC : grpc ,
200
+ Includes : createIncludes (virtualServer .Additions ),
201
+ IPv6Enabled : virtualServer .IPv6Enabled ,
183
202
}, matchPairs
184
203
}
185
204
@@ -188,17 +207,19 @@ func createServer(virtualServer dataplane.VirtualServer, serverID int) (http.Ser
188
207
return http.Server {
189
208
IsDefaultHTTP : true ,
190
209
Port : virtualServer .Port ,
210
+ IPv6Enabled : virtualServer .IPv6Enabled ,
191
211
}, nil
192
212
}
193
213
194
214
locs , matchPairs , grpc := createLocations (& virtualServer , serverID )
195
215
196
216
return http.Server {
197
- ServerName : virtualServer .Hostname ,
198
- Locations : locs ,
199
- Port : virtualServer .Port ,
200
- GRPC : grpc ,
201
- Includes : createIncludes (virtualServer .Additions ),
217
+ ServerName : virtualServer .Hostname ,
218
+ Locations : locs ,
219
+ Port : virtualServer .Port ,
220
+ GRPC : grpc ,
221
+ Includes : createIncludes (virtualServer .Additions ),
222
+ IPv6Enabled : virtualServer .IPv6Enabled ,
202
223
}, matchPairs
203
224
}
204
225
0 commit comments