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
+ ipFamily := getIPFamily (conf .BaseHTTPConfig )
63
+ servers , httpMatchPairs := createServers (conf .HTTPServers , conf .SSLServers , ipFamily )
62
64
63
65
serverResult := executeResult {
64
66
dest : httpConfigFile ,
@@ -86,6 +88,18 @@ func executeServers(conf dataplane.Configuration) []executeResult {
86
88
return allResults
87
89
}
88
90
91
+ // getIPFamily returns whether the server should be configured for IPv4, IPv6, or both.
92
+ func getIPFamily (baseHTTPConfig dataplane.BaseHTTPConfig ) http.IPFamily {
93
+ switch ip := baseHTTPConfig .IPFamily ; ip {
94
+ case ngfAPI .IPv4 :
95
+ return http.IPFamily {IPv4 : true }
96
+ case ngfAPI .IPv6 :
97
+ return http.IPFamily {IPv6 : true }
98
+ }
99
+
100
+ return http.IPFamily {IPv4 : true , IPv6 : true }
101
+ }
102
+
89
103
func createAdditionFileResults (conf dataplane.Configuration ) []executeResult {
90
104
uniqueAdditions := make (map [string ][]byte )
91
105
@@ -141,30 +155,39 @@ func createIncludes(additions []dataplane.Addition) []string {
141
155
return includes
142
156
}
143
157
144
- func createServers (httpServers , sslServers []dataplane.VirtualServer ) ([]http.Server , httpMatchPairs ) {
158
+ func createServers (
159
+ httpServers ,
160
+ sslServers []dataplane.VirtualServer ,
161
+ ipFamily http.IPFamily ,
162
+ ) ([]http.Server , httpMatchPairs ) {
145
163
servers := make ([]http.Server , 0 , len (httpServers )+ len (sslServers ))
146
164
finalMatchPairs := make (httpMatchPairs )
147
165
148
166
for serverID , s := range httpServers {
149
- httpServer , matchPairs := createServer (s , serverID )
167
+ httpServer , matchPairs := createServer (s , serverID , ipFamily )
150
168
servers = append (servers , httpServer )
151
169
maps .Copy (finalMatchPairs , matchPairs )
152
170
}
153
171
154
172
for serverID , s := range sslServers {
155
- sslServer , matchPair := createSSLServer (s , serverID )
173
+ sslServer , matchPair := createSSLServer (s , serverID , ipFamily )
156
174
servers = append (servers , sslServer )
157
175
maps .Copy (finalMatchPairs , matchPair )
158
176
}
159
177
160
178
return servers , finalMatchPairs
161
179
}
162
180
163
- func createSSLServer (virtualServer dataplane.VirtualServer , serverID int ) (http.Server , httpMatchPairs ) {
181
+ func createSSLServer (
182
+ virtualServer dataplane.VirtualServer ,
183
+ serverID int ,
184
+ ipFamily http.IPFamily ,
185
+ ) (http.Server , httpMatchPairs ) {
164
186
if virtualServer .IsDefault {
165
187
return http.Server {
166
188
IsDefaultSSL : true ,
167
189
Port : virtualServer .Port ,
190
+ IPFamily : ipFamily ,
168
191
}, nil
169
192
}
170
193
@@ -180,14 +203,20 @@ func createSSLServer(virtualServer dataplane.VirtualServer, serverID int) (http.
180
203
Port : virtualServer .Port ,
181
204
GRPC : grpc ,
182
205
Includes : createIncludes (virtualServer .Additions ),
206
+ IPFamily : ipFamily ,
183
207
}, matchPairs
184
208
}
185
209
186
- func createServer (virtualServer dataplane.VirtualServer , serverID int ) (http.Server , httpMatchPairs ) {
210
+ func createServer (
211
+ virtualServer dataplane.VirtualServer ,
212
+ serverID int ,
213
+ ipFamily http.IPFamily ,
214
+ ) (http.Server , httpMatchPairs ) {
187
215
if virtualServer .IsDefault {
188
216
return http.Server {
189
217
IsDefaultHTTP : true ,
190
218
Port : virtualServer .Port ,
219
+ IPFamily : ipFamily ,
191
220
}, nil
192
221
}
193
222
@@ -199,6 +228,7 @@ func createServer(virtualServer dataplane.VirtualServer, serverID int) (http.Ser
199
228
Port : virtualServer .Port ,
200
229
GRPC : grpc ,
201
230
Includes : createIncludes (virtualServer .Additions ),
231
+ IPFamily : ipFamily ,
202
232
}, matchPairs
203
233
}
204
234
0 commit comments