@@ -5,7 +5,7 @@ use linkerd2_app_core::{
55 proxy:: { http, identity, tap} ,
66 router, stack_tracing,
77 transport:: { connect, listen, tls} ,
8- Addr , Conditional , NameAddr , CANONICAL_DST_HEADER , DST_OVERRIDE_HEADER ,
8+ Addr , Conditional , CANONICAL_DST_HEADER , DST_OVERRIDE_HEADER ,
99} ;
1010use std:: fmt;
1111use std:: net:: SocketAddr ;
@@ -14,8 +14,8 @@ use tracing::debug;
1414
1515#[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
1616pub struct Target {
17- pub addr : SocketAddr ,
18- pub dst_name : Option < NameAddr > ,
17+ pub logical : Addr ,
18+ pub socket_addr : SocketAddr ,
1919 pub http_settings : http:: Settings ,
2020 pub tls_client_id : tls:: PeerIdentity ,
2121}
@@ -59,7 +59,7 @@ impl http::settings::HasSettings for HttpEndpoint {
5959impl From < Target > for HttpEndpoint {
6060 fn from ( target : Target ) -> Self {
6161 Self {
62- port : target. addr . port ( ) ,
62+ port : target. socket_addr . port ( ) ,
6363 settings : target. http_settings ,
6464 }
6565 }
@@ -105,27 +105,16 @@ impl tls::HasPeerIdentity for TcpEndpoint {
105105
106106impl From < Target > for Profile {
107107 fn from ( t : Target ) -> Self {
108- Profile (
109- t. dst_name
110- . clone ( )
111- . map ( |d| d. into ( ) )
112- . unwrap_or_else ( || t. addr . clone ( ) . into ( ) ) ,
113- )
108+ Profile ( t. logical )
114109 }
115110}
116111
117- impl Profile {
118- pub fn addr ( & self ) -> & Addr {
112+ impl AsRef < Addr > for Profile {
113+ fn as_ref ( & self ) -> & Addr {
119114 & self . 0
120115 }
121116}
122117
123- impl profiles:: HasDestination for Profile {
124- fn destination ( & self ) -> Addr {
125- self . 0 . clone ( )
126- }
127- }
128-
129118impl profiles:: WithRoute for Profile {
130119 type Route = dst:: Route ;
131120
@@ -138,7 +127,7 @@ impl profiles::WithRoute for Profile {
138127 }
139128}
140129
141- // // === impl Target ===
130+ // === impl Target ===
142131
143132impl http:: normalize_uri:: ShouldNormalizeUri for Target {
144133 fn should_normalize_uri ( & self ) -> Option < http:: uri:: Authority > {
@@ -147,12 +136,7 @@ impl http::normalize_uri::ShouldNormalizeUri for Target {
147136 ..
148137 } = self . http_settings
149138 {
150- return Some (
151- self . dst_name
152- . as_ref ( )
153- . map ( |dst| dst. as_http_authority ( ) )
154- . unwrap_or_else ( || Addr :: from ( self . addr ) . to_http_authority ( ) ) ,
155- ) ;
139+ return Some ( self . logical . to_http_authority ( ) ) ;
156140 }
157141 None
158142 }
@@ -173,7 +157,7 @@ impl tls::HasPeerIdentity for Target {
173157impl Into < metric_labels:: EndpointLabels > for Target {
174158 fn into ( self ) -> metric_labels:: EndpointLabels {
175159 metric_labels:: EndpointLabels {
176- authority : self . dst_name . map ( |d| d. as_http_authority ( ) ) ,
160+ authority : self . logical . name_addr ( ) . map ( |d| d. as_http_authority ( ) ) ,
177161 direction : metric_labels:: Direction :: In ,
178162 tls_id : self . tls_client_id . map ( metric_labels:: TlsId :: ClientId ) ,
179163 labels : None ,
@@ -207,7 +191,7 @@ impl tap::Inspect for Target {
207191 }
208192
209193 fn dst_addr < B > ( & self , _: & http:: Request < B > ) -> Option < SocketAddr > {
210- Some ( self . addr )
194+ Some ( self . socket_addr )
211195 }
212196
213197 fn dst_labels < B > ( & self , _: & http:: Request < B > ) -> Option < & IndexMap < String , String > > {
@@ -234,7 +218,7 @@ impl tap::Inspect for Target {
234218
235219impl fmt:: Display for Target {
236220 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
237- self . addr . fmt ( f)
221+ self . logical . fmt ( f)
238222 }
239223}
240224
@@ -243,33 +227,33 @@ impl stack_tracing::GetSpan<()> for Target {
243227 use tracing:: info_span;
244228
245229 match self . http_settings {
246- http:: Settings :: Http2 => match self . dst_name . as_ref ( ) {
230+ http:: Settings :: Http2 => match self . logical . name_addr ( ) {
247231 None => info_span ! (
248232 "http2" ,
249- port = %self . addr . port( ) ,
233+ port = %self . socket_addr . port( ) ,
250234 ) ,
251235 Some ( name) => info_span ! (
252236 "http2" ,
253237 %name,
254- port = %self . addr . port( ) ,
238+ port = %self . socket_addr . port( ) ,
255239 ) ,
256240 } ,
257241 http:: Settings :: Http1 {
258242 keep_alive,
259243 wants_h1_upgrade,
260244 was_absolute_form,
261- } => match self . dst_name . as_ref ( ) {
245+ } => match self . logical . name_addr ( ) {
262246 None => info_span ! (
263247 "http1" ,
264- port = %self . addr . port( ) ,
248+ port = %self . socket_addr . port( ) ,
265249 keep_alive,
266250 wants_h1_upgrade,
267251 was_absolute_form,
268252 ) ,
269253 Some ( name) => info_span ! (
270254 "http1" ,
271255 %name,
272- port = %self . addr . port( ) ,
256+ port = %self . socket_addr . port( ) ,
273257 keep_alive,
274258 wants_h1_upgrade,
275259 was_absolute_form,
@@ -291,7 +275,7 @@ impl<A> router::Recognize<http::Request<A>> for RequestTarget {
291275 type Key = Target ;
292276
293277 fn recognize ( & self , req : & http:: Request < A > ) -> Self :: Key {
294- let dst_name = req
278+ let logical = req
295279 . headers ( )
296280 . get ( CANONICAL_DST_HEADER )
297281 . and_then ( |dst| {
@@ -312,12 +296,11 @@ impl<A> router::Recognize<http::Request<A>> for RequestTarget {
312296 } )
313297 . or_else ( || http_request_authority_addr ( req) . ok ( ) )
314298 . or_else ( || http_request_host_addr ( req) . ok ( ) )
315- . or_else ( || self . accept . addrs . target_addr_if_not_local ( ) . map ( Addr :: from) )
316- . and_then ( |a| a. name_addr ( ) . cloned ( ) ) ;
299+ . unwrap_or_else ( || self . accept . addrs . target_addr ( ) . into ( ) ) ;
317300
318301 Target {
319- dst_name ,
320- addr : self . accept . addrs . target_addr ( ) ,
302+ logical ,
303+ socket_addr : self . accept . addrs . target_addr ( ) ,
321304 tls_client_id : self . accept . peer_identity . clone ( ) ,
322305 http_settings : http:: Settings :: from_request ( req) ,
323306 }
@@ -330,11 +313,6 @@ impl router::Recognize<Target> for ProfileTarget {
330313 type Key = Profile ;
331314
332315 fn recognize ( & self , t : & Target ) -> Self :: Key {
333- Profile (
334- t. dst_name
335- . clone ( )
336- . map ( Into :: into)
337- . unwrap_or_else ( || t. addr . into ( ) ) ,
338- )
316+ Profile ( t. logical . clone ( ) )
339317 }
340318}
0 commit comments