@@ -45,6 +45,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
4545 t .validateConflictedLayer7Listeners (gateways )
4646 t .validateConflictedLayer4Listeners (gateways , gwapiv1 .TCPProtocolType )
4747 t .validateConflictedLayer4Listeners (gateways , gwapiv1 .UDPProtocolType )
48+ t .validateConflictedProtocolsListeners (gateways )
4849 if t .MergeGateways {
4950 t .validateConflictedMergedListeners (gateways )
5051 }
@@ -104,15 +105,10 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
104105 t .validateHostName (listener )
105106
106107 // Process conditions and check if the listener is ready
107- isReady := t .validateListenerConditions (listener )
108-
109- if listener .isFromListenerSet () && isReady {
110- lsKey := types.NamespacedName {
111- Namespace : listener .listenerSet .Namespace ,
112- Name : listener .listenerSet .Name ,
113- }.String ()
114- gatewayAttachedListenerSets .Insert (lsKey )
115- }
108+ // TODO: this's skipped in https://github.com/envoyproxy/gateway/pull/8194
109+ // for TLSRouteInvalidNoMatchingListener conformance test, but looks like it's
110+ // a must, consider to skip invalid listener again?
111+ listenerValid := t .validateListenerConditions (listener )
116112
117113 address := netutils .IPv4ListenerAddress
118114 ipFamily := getEnvoyIPFamily (gateway .envoyProxy )
@@ -122,7 +118,30 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
122118
123119 // Add the listener to the Xds IR
124120 servicePort := & protocolPort {protocol : listener .Protocol , port : listener .Port }
121+ // Add the listener to the Infra IR.
122+ // Infra IR ports must have a unique port number per layer protocol.
123+ gatewayPortProtocols := foundPorts [irKey ]
124+ portExists , protocolValid := checkPortProtocol (gatewayPortProtocols , servicePort )
125+ if ! protocolValid {
126+ continue
127+ }
128+
129+ if listener .isFromListenerSet () && listenerValid {
130+ lsKey := types.NamespacedName {
131+ Namespace : listener .listenerSet .Namespace ,
132+ Name : listener .listenerSet .Name ,
133+ }.String ()
134+ gatewayAttachedListenerSets .Insert (lsKey )
135+ }
136+ foundPorts [irKey ] = append (foundPorts [irKey ], servicePort )
125137 containerPort := t .servicePortToContainerPort (listener .Port , gateway .envoyProxy )
138+ if ! portExists {
139+ // Only add to Infra IR if the port number is unique for the layer protocol.
140+ // If the same port number is used in another listener with a different protocol,
141+ // it will be skipped when checking port protocol.
142+ t .processInfraIRListener (listener , infraIR , irKey , servicePort , containerPort )
143+ }
144+
126145 switch listener .Protocol {
127146 case gwapiv1 .HTTPProtocolType , gwapiv1 .HTTPSProtocolType :
128147 irListener := & ir.HTTPListener {
@@ -184,14 +203,6 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
184203 }
185204 xdsIR [irKey ].UDP = append (xdsIR [irKey ].UDP , irListener )
186205 }
187-
188- // Add the listener to the Infra IR. Infra IR ports must have a unique port number per layer-4 protocol
189- // (TCP or UDP).
190- if ! containsPort (foundPorts [irKey ], servicePort ) {
191- t .processInfraIRListener (listener , infraIR , irKey , servicePort , containerPort )
192- foundPorts [irKey ] = append (foundPorts [irKey ], servicePort )
193- }
194-
195206 }
196207 gateway .IncreaseAttachedListenerSets (uint32 (len (gatewayAttachedListenerSets )))
197208 }
0 commit comments