88	"strings" 
99	gotemplate "text/template" 
1010
11+ 	ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1" 
1112	"github.com/nginxinc/nginx-gateway-fabric/internal/framework/helpers" 
1213	"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/http" 
1314	"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/dataplane" 
@@ -58,7 +59,8 @@ var grpcBaseHeaders = []http.Header{
5859}
5960
6061func  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 )
6264
6365	serverResult  :=  executeResult {
6466		dest : httpConfigFile ,
@@ -86,6 +88,14 @@ func executeServers(conf dataplane.Configuration) []executeResult {
8688	return  allResults 
8789}
8890
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+ 
8999func  createAdditionFileResults (conf  dataplane.Configuration ) []executeResult  {
90100	uniqueAdditions  :=  make (map [string ][]byte )
91101
@@ -141,17 +151,23 @@ func createIncludes(additions []dataplane.Addition) []string {
141151	return  includes 
142152}
143153
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 ) {
145159	servers  :=  make ([]http.Server , 0 , len (httpServers )+ len (sslServers ))
146160	finalMatchPairs  :=  make (httpMatchPairs )
147161
148162	for  serverID , s  :=  range  httpServers  {
163+ 		s .IPv6Enabled  =  ipv6Enabled 
149164		httpServer , matchPairs  :=  createServer (s , serverID )
150165		servers  =  append (servers , httpServer )
151166		maps .Copy (finalMatchPairs , matchPairs )
152167	}
153168
154169	for  serverID , s  :=  range  sslServers  {
170+ 		s .IPv6Enabled  =  ipv6Enabled 
155171		sslServer , matchPair  :=  createSSLServer (s , serverID )
156172		servers  =  append (servers , sslServer )
157173		maps .Copy (finalMatchPairs , matchPair )
@@ -165,6 +181,7 @@ func createSSLServer(virtualServer dataplane.VirtualServer, serverID int) (http.
165181		return  http.Server {
166182			IsDefaultSSL : true ,
167183			Port :         virtualServer .Port ,
184+ 			IPv6Enabled :  virtualServer .IPv6Enabled ,
168185		}, nil 
169186	}
170187
@@ -176,10 +193,11 @@ func createSSLServer(virtualServer dataplane.VirtualServer, serverID int) (http.
176193			Certificate :    generatePEMFileName (virtualServer .SSL .KeyPairID ),
177194			CertificateKey : generatePEMFileName (virtualServer .SSL .KeyPairID ),
178195		},
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 ,
183201	}, matchPairs 
184202}
185203
@@ -188,17 +206,19 @@ func createServer(virtualServer dataplane.VirtualServer, serverID int) (http.Ser
188206		return  http.Server {
189207			IsDefaultHTTP : true ,
190208			Port :          virtualServer .Port ,
209+ 			IPv6Enabled :   virtualServer .IPv6Enabled ,
191210		}, nil 
192211	}
193212
194213	locs , matchPairs , grpc  :=  createLocations (& virtualServer , serverID )
195214
196215	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 ,
202222	}, matchPairs 
203223}
204224
0 commit comments