@@ -151,7 +151,7 @@ func newListenerConfiguratorFactory(
151151 validators : []listenerValidator {
152152 validateListenerAllowedRouteKind ,
153153 validateListenerLabelSelector ,
154- createTCPListenerValidator ( protectedPorts ),
154+ createL4ListenerValidator ( v1 . TCPProtocolType , protectedPorts ),
155155 },
156156 conflictResolvers : []listenerConflictResolver {
157157 sharedPortConflictResolver ,
@@ -161,7 +161,7 @@ func newListenerConfiguratorFactory(
161161 validators : []listenerValidator {
162162 validateListenerAllowedRouteKind ,
163163 validateListenerLabelSelector ,
164- createUDPListenerValidator ( protectedPorts ),
164+ createL4ListenerValidator ( v1 . UDPProtocolType , protectedPorts ),
165165 },
166166 conflictResolvers : []listenerConflictResolver {
167167 sharedPortConflictResolver ,
@@ -487,13 +487,14 @@ func createPortConflictResolver() listenerConflictResolver {
487487 const (
488488 secureProtocolGroup int = 0
489489 insecureProtocolGroup int = 1
490+ l4ProtocolGroup int = 2
490491 )
491492 protocolGroups := map [v1.ProtocolType ]int {
492493 v1 .TLSProtocolType : secureProtocolGroup ,
493494 v1 .HTTPProtocolType : insecureProtocolGroup ,
494495 v1 .HTTPSProtocolType : secureProtocolGroup ,
495- v1 .TCPProtocolType : insecureProtocolGroup ,
496- v1 .UDPProtocolType : insecureProtocolGroup ,
496+ v1 .TCPProtocolType : l4ProtocolGroup ,
497+ v1 .UDPProtocolType : l4ProtocolGroup ,
497498 }
498499 conflictedPorts := make (map [v1.PortNumber ]bool )
499500 portProtocolOwner := make (map [v1.PortNumber ]int )
@@ -505,6 +506,8 @@ func createPortConflictResolver() listenerConflictResolver {
505506 formatHostname := "HTTPS and TLS listeners for the same port %d specify overlapping hostnames; " +
506507 "ensure no overlapping hostnames for HTTPS and TLS listeners for the same port"
507508
509+ formatL4SameProtocol := "Multiple %s listeners cannot share the same port %d"
510+
508511 return func (l * Listener ) {
509512 port := l .Source .Port
510513
@@ -542,6 +545,14 @@ func createPortConflictResolver() listenerConflictResolver {
542545 } else {
543546 foundConflict := false
544547 for _ , listener := range listenersByPort [port ] {
548+ if isL4Protocol (l .Source .Protocol ) &&
549+ listener .Source .Protocol == l .Source .Protocol {
550+ listener .Valid = false
551+ conflictedConds := conditions .NewListenerProtocolConflict (
552+ fmt .Sprintf (formatL4SameProtocol , l .Source .Protocol , port ))
553+ listener .Conditions = append (listener .Conditions , conflictedConds ... )
554+ foundConflict = true
555+ }
545556 if listener .Source .Protocol != l .Source .Protocol &&
546557 ! isL4Protocol (listener .Source .Protocol ) && ! isL4Protocol (l .Source .Protocol ) &&
547558 haveOverlap (l .Source .Hostname , listener .Source .Hostname ) {
@@ -554,8 +565,14 @@ func createPortConflictResolver() listenerConflictResolver {
554565
555566 if foundConflict {
556567 l .Valid = false
557- conflictedConds := conditions .NewListenerHostnameConflict (fmt .Sprintf (formatHostname , port ))
558- l .Conditions = append (l .Conditions , conflictedConds ... )
568+ if isL4Protocol (l .Source .Protocol ) {
569+ conflictedConds := conditions .NewListenerProtocolConflict (
570+ fmt .Sprintf (formatL4SameProtocol , l .Source .Protocol , port ))
571+ l .Conditions = append (l .Conditions , conflictedConds ... )
572+ } else {
573+ conflictedConds := conditions .NewListenerHostnameConflict (fmt .Sprintf (formatHostname , port ))
574+ l .Conditions = append (l .Conditions , conflictedConds ... )
575+ }
559576 }
560577 }
561578
@@ -668,14 +685,6 @@ func createL4ListenerValidator(protocol v1.ProtocolType, protectedPorts Protecte
668685 }
669686}
670687
671- func createTCPListenerValidator (protectedPorts ProtectedPorts ) listenerValidator {
672- return createL4ListenerValidator (v1 .TCPProtocolType , protectedPorts )
673- }
674-
675- func createUDPListenerValidator (protectedPorts ProtectedPorts ) listenerValidator {
676- return createL4ListenerValidator (v1 .UDPProtocolType , protectedPorts )
677- }
678-
679688func createOverlappingTLSConfigResolver () listenerConflictResolver {
680689 listenersByPort := make (map [v1.PortNumber ][]* Listener )
681690
0 commit comments