Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions for #3160 #3272

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
tls: Avoid InsertParam parameter.
We don't actually use InsertParam all that much--only in the TLS server (which
is obviously why it was included here). This change removes the InsertParam in
favor of using a tuple, generally reducing boilerplate.

It turns out that the TLS stack already has a map_target to handle turning the
tuple-target into a Tls type, so it shouldn't be needed.
  • Loading branch information
olix0r committed Oct 10, 2024
commit f78aa64be9afa2ab96c03f384b9fe78d71fd4942
9 changes: 0 additions & 9 deletions linkerd/app/outbound/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ impl<T> svc::ExtractParam<tls::server::Timeout, T> for DetectParams {
}
}

impl<T> svc::InsertParam<ServerName, T> for DetectParams {
type Target = (ServerName, T);

#[inline]
fn insert_param(&self, sni: ServerName, target: T) -> Self::Target {
(sni, target)
}
}

// === impl TlsMetrics ===

impl TlsMetrics {
Expand Down
9 changes: 0 additions & 9 deletions linkerd/app/outbound/src/tls/logical/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ impl<T> svc::ExtractParam<tls::server::Timeout, T> for DetectParams {
}
}

impl<T> svc::InsertParam<tls::ServerName, T> for DetectParams {
type Target = (tls::ServerName, T);

#[inline]
fn insert_param(&self, sni: tls::ServerName, target: T) -> Self::Target {
(sni, target)
}
}

fn spawn_io(
client_hello: Vec<u8>,
) -> (
Expand Down
17 changes: 6 additions & 11 deletions linkerd/tls/src/detect_sni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use linkerd_error::Error;
use linkerd_io as io;
use linkerd_stack::{layer, ExtractParam, InsertParam, NewService, Service, ServiceExt};
use linkerd_stack::{layer, ExtractParam, NewService, Service, ServiceExt};
use std::{
future::Future,
pin::Pin,
Expand All @@ -29,11 +29,10 @@ pub struct NewDetectSni<P, N> {
}

#[derive(Clone, Debug)]
pub struct DetectSni<T, P, N> {
pub struct DetectSni<T, N> {
target: T,
inner: N,
timeout: Timeout,
params: P,
}

impl<P, N> NewDetectSni<P, N> {
Expand All @@ -54,26 +53,23 @@ where
P: ExtractParam<Timeout, T> + Clone,
N: Clone,
{
type Service = DetectSni<T, P, N>;
type Service = DetectSni<T, N>;

fn new_service(&self, target: T) -> Self::Service {
let timeout = self.params.extract_param(&target);
DetectSni {
target,
timeout,
inner: self.inner.clone(),
params: self.params.clone(),
}
}
}

impl<T, P, I, N, S> Service<I> for DetectSni<T, P, N>
impl<T, I, N, S> Service<I> for DetectSni<T, N>
where
T: Clone + Send + Sync + 'static,
P: InsertParam<ServerName, T> + Clone + Send + Sync + 'static,
P::Target: Send + 'static,
I: io::AsyncRead + io::Peek + io::AsyncWrite + Send + Sync + Unpin + 'static,
N: NewService<P::Target, Service = S> + Clone + Send + 'static,
N: NewService<(ServerName, T), Service = S> + Clone + Send + 'static,
S: Service<DetectIo<I>> + Send,
S::Error: Into<Error>,
S::Future: Send,
Expand All @@ -90,7 +86,6 @@ where
fn call(&mut self, io: I) -> Self::Future {
let target = self.target.clone();
let new_accept = self.inner.clone();
let params = self.params.clone();

// Detect the SNI from a ClientHello (or timeout).
let Timeout(timeout) = self.timeout;
Expand All @@ -100,7 +95,7 @@ where
let sni = sni.ok_or(NoSniFoundError)?;

debug!("detected SNI: {:?}", sni);
let svc = new_accept.new_service(params.insert_param(sni, target));
let svc = new_accept.new_service((sni, target));
svc.oneshot(io).await.map_err(Into::into)
})
}
Expand Down