istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/networking/networking.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package networking 16 17 import ( 18 core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" 19 20 "istio.io/istio/pkg/config/protocol" 21 ) 22 23 // ListenerProtocol is the protocol associated with the listener. 24 type ListenerProtocol int 25 26 const ( 27 // ListenerProtocolUnknown is an unknown type of listener. 28 ListenerProtocolUnknown = iota 29 // ListenerProtocolTCP is a TCP listener. 30 ListenerProtocolTCP 31 // ListenerProtocolHTTP is an HTTP listener. 32 ListenerProtocolHTTP 33 // ListenerProtocolAuto enables auto protocol detection 34 ListenerProtocolAuto 35 ) 36 37 // ModelProtocolToListenerProtocol converts from a config.Protocol to its corresponding plugin.ListenerProtocol 38 func ModelProtocolToListenerProtocol(p protocol.Instance) ListenerProtocol { 39 switch p { 40 case protocol.HTTP, protocol.HTTP2, protocol.HTTP_PROXY, protocol.GRPC, protocol.GRPCWeb: 41 return ListenerProtocolHTTP 42 case protocol.TCP, protocol.HTTPS, protocol.TLS, 43 protocol.Mongo, protocol.Redis, protocol.MySQL: 44 return ListenerProtocolTCP 45 case protocol.UDP: 46 return ListenerProtocolUnknown 47 case protocol.Unsupported: 48 return ListenerProtocolAuto 49 default: 50 // Should not reach here. 51 return ListenerProtocolAuto 52 } 53 } 54 55 type TransportProtocol uint8 56 57 const ( 58 // TransportProtocolTCP is a TCP listener 59 TransportProtocolTCP = iota 60 // TransportProtocolQUIC is a QUIC listener 61 TransportProtocolQUIC 62 ) 63 64 func (tp TransportProtocol) String() string { 65 switch tp { 66 case TransportProtocolTCP: 67 return "tcp" 68 case TransportProtocolQUIC: 69 return "quic" 70 } 71 return "unknown" 72 } 73 74 func (tp TransportProtocol) ToEnvoySocketProtocol() core.SocketAddress_Protocol { 75 if tp == TransportProtocolQUIC { 76 return core.SocketAddress_UDP 77 } 78 return core.SocketAddress_TCP 79 } 80 81 // ListenerClass defines the class of the listener 82 type ListenerClass int 83 84 const ( 85 ListenerClassUndefined ListenerClass = iota 86 ListenerClassSidecarInbound 87 ListenerClassSidecarOutbound 88 ListenerClassGateway 89 )