From 00d6f96bfc25a928b228c1db5a342b44d195dae2 Mon Sep 17 00:00:00 2001 From: Eloi DEMOLIS Date: Mon, 6 May 2024 17:25:24 +0200 Subject: [PATCH] don't push Signed-off-by: Eloi DEMOLIS --- bin/src/ctl/request_builder.rs | 2 - command/src/command.proto | 2 +- command/src/config.rs | 12 +-- command/src/request.rs | 1 - command/src/response.rs | 2 - lib/src/http.rs | 26 ++----- lib/src/https.rs | 42 +++-------- lib/src/protocol/kawa_h1/mod.rs | 2 +- lib/src/protocol/mux/mod.rs | 20 +++-- lib/src/router/mod.rs | 127 +++++++------------------------- 10 files changed, 61 insertions(+), 175 deletions(-) diff --git a/bin/src/ctl/request_builder.rs b/bin/src/ctl/request_builder.rs index 028dac079..0f477cb49 100644 --- a/bin/src/ctl/request_builder.rs +++ b/bin/src/ctl/request_builder.rs @@ -251,7 +251,6 @@ impl CommandManager { Some(tags) => tags, None => BTreeMap::new(), }, - h2: h2.unwrap_or(false), }) .into(), ), @@ -301,7 +300,6 @@ impl CommandManager { Some(tags) => tags, None => BTreeMap::new(), }, - h2: h2.unwrap_or(false), }) .into(), ), diff --git a/command/src/command.proto b/command/src/command.proto index a303f8c99..858becc6a 100644 --- a/command/src/command.proto +++ b/command/src/command.proto @@ -248,7 +248,6 @@ message RequestHttpFrontend { required RulePosition position = 6 [default = TREE]; // custom tags to identify the frontend in the access logs map tags = 7; - required bool h2 = 8; } message RequestTcpFrontend { @@ -383,6 +382,7 @@ message Cluster { required LoadBalancingAlgorithms load_balancing = 5 [default = ROUND_ROBIN]; optional string answer_503 = 6; optional LoadMetric load_metric = 7; + required bool http2 = 8; } enum LoadBalancingAlgorithms { diff --git a/command/src/config.rs b/command/src/config.rs index 604f99535..97d3c53e5 100644 --- a/command/src/config.rs +++ b/command/src/config.rs @@ -681,7 +681,6 @@ pub struct FileClusterFrontendConfig { #[serde(default = "default_rule_position")] pub position: RulePosition, pub tags: Option>, - pub h2: Option, } impl FileClusterFrontendConfig { @@ -767,7 +766,6 @@ impl FileClusterFrontendConfig { path, method: self.method.clone(), tags: self.tags.clone(), - h2: self.h2.unwrap_or(false), }) } } @@ -784,6 +782,7 @@ pub enum ListenerProtocol { #[serde(deny_unknown_fields, rename_all = "lowercase")] pub enum FileClusterProtocolConfig { Http, + Http2, Tcp, } @@ -873,7 +872,7 @@ impl FileClusterConfig { load_metric: self.load_metric, })) } - FileClusterProtocolConfig::Http => { + FileClusterProtocolConfig::Http | FileClusterProtocolConfig::Http2 => { let mut frontends = Vec::new(); for frontend in self.frontends { let http_frontend = frontend.to_http_front(cluster_id)?; @@ -891,6 +890,7 @@ impl FileClusterConfig { Ok(ClusterConfig::Http(HttpClusterConfig { cluster_id: cluster_id.to_string(), + http2: self.protocol == FileClusterProtocolConfig::Http2, frontends, backends: self.backends, sticky_session: self.sticky_session.unwrap_or(false), @@ -919,7 +919,6 @@ pub struct HttpFrontendConfig { #[serde(default)] pub position: RulePosition, pub tags: Option>, - pub h2: bool, } impl HttpFrontendConfig { @@ -955,7 +954,6 @@ impl HttpFrontendConfig { path: self.path.clone(), method: self.method.clone(), position: self.position.into(), - h2: self.h2, tags, }) .into(), @@ -970,7 +968,6 @@ impl HttpFrontendConfig { path: self.path.clone(), method: self.method.clone(), position: self.position.into(), - h2: self.h2, tags, }) .into(), @@ -985,6 +982,7 @@ impl HttpFrontendConfig { #[serde(deny_unknown_fields)] pub struct HttpClusterConfig { pub cluster_id: String, + pub http2: bool, pub frontends: Vec, pub backends: Vec, pub sticky_session: bool, @@ -1000,6 +998,7 @@ impl HttpClusterConfig { cluster_id: self.cluster_id.clone(), sticky_session: self.sticky_session, https_redirect: self.https_redirect, + http2: self.http2, proxy_protocol: None, load_balancing: self.load_balancing as i32, answer_503: self.answer_503.clone(), @@ -1059,6 +1058,7 @@ impl TcpClusterConfig { cluster_id: self.cluster_id.clone(), sticky_session: false, https_redirect: false, + http2: false, proxy_protocol: self.proxy_protocol.map(|s| s as i32), load_balancing: self.load_balancing as i32, load_metric: self.load_metric.map(|s| s as i32), diff --git a/command/src/request.rs b/command/src/request.rs index 496140ce2..f43e7c621 100644 --- a/command/src/request.rs +++ b/command/src/request.rs @@ -173,7 +173,6 @@ impl RequestHttpFrontend { } })?, tags: Some(self.tags), - h2: self.h2, }) } } diff --git a/command/src/response.rs b/command/src/response.rs index 9b1b87c10..341dbc7ae 100644 --- a/command/src/response.rs +++ b/command/src/response.rs @@ -39,7 +39,6 @@ pub struct HttpFrontend { #[serde(default)] pub position: RulePosition, pub tags: Option>, - pub h2: bool, } impl From for RequestHttpFrontend { @@ -55,7 +54,6 @@ impl From for RequestHttpFrontend { path: val.path, method: val.method, position: val.position.into(), - h2: val.h2, tags, } } diff --git a/lib/src/http.rs b/lib/src/http.rs index 73da438c9..a9cc414eb 100644 --- a/lib/src/http.rs +++ b/lib/src/http.rs @@ -520,7 +520,7 @@ impl L7ListenerHandler for HttpListener { let now = Instant::now(); - if let Route::Cluster { id: cluster, .. } = &route { + if let Route::Cluster(cluster) = &route { time!("frontend_matching_time", cluster, (now - start).as_millis()); } @@ -1374,7 +1374,6 @@ mod tests { position: RulePosition::Tree, cluster_id: Some(cluster_id1), tags: None, - h2: false, }) .expect("Could not add http frontend"); fronts @@ -1386,7 +1385,6 @@ mod tests { position: RulePosition::Tree, cluster_id: Some(cluster_id2), tags: None, - h2: false, }) .expect("Could not add http frontend"); fronts @@ -1398,7 +1396,6 @@ mod tests { position: RulePosition::Tree, cluster_id: Some(cluster_id3), tags: None, - h2: false, }) .expect("Could not add http frontend"); fronts @@ -1410,7 +1407,6 @@ mod tests { position: RulePosition::Tree, cluster_id: Some("cluster_1".to_owned()), tags: None, - h2: false, }) .expect("Could not add http frontend"); @@ -1440,31 +1436,19 @@ mod tests { let frontend5 = listener.frontend_from_request("domain", "/", &Method::Get); assert_eq!( frontend1.expect("should find frontend"), - Route::Cluster { - id: "cluster_1".to_string(), - h2: false - } + Route::Cluster("cluster_1".to_string()) ); assert_eq!( frontend2.expect("should find frontend"), - Route::Cluster { - id: "cluster_1".to_string(), - h2: false - } + Route::Cluster("cluster_1".to_string()) ); assert_eq!( frontend3.expect("should find frontend"), - Route::Cluster { - id: "cluster_2".to_string(), - h2: false - } + Route::Cluster("cluster_2".to_string()) ); assert_eq!( frontend4.expect("should find frontend"), - Route::Cluster { - id: "cluster_3".to_string(), - h2: false - } + Route::Cluster("cluster_3".to_string()) ); assert!(frontend5.is_err()); } diff --git a/lib/src/https.rs b/lib/src/https.rs index 086296178..d9ef7beb1 100644 --- a/lib/src/https.rs +++ b/lib/src/https.rs @@ -606,7 +606,7 @@ impl L7ListenerHandler for HttpsListener { let now = Instant::now(); - if let Route::Cluster { id: cluster, .. } = &route { + if let Route::Cluster(cluster) = &route { time!("frontend_matching_time", cluster, (now - start).as_millis()); } @@ -1557,37 +1557,25 @@ mod tests { "lolcatho.st".as_bytes(), &PathRule::Prefix(uri1), &MethodRule::new(None), - &Route::Cluster { - id: cluster_id1.clone(), - h2: false - } + &Route::Cluster(cluster_id1.clone()) )); assert!(fronts.add_tree_rule( "lolcatho.st".as_bytes(), &PathRule::Prefix(uri2), &MethodRule::new(None), - &Route::Cluster { - id: cluster_id2, - h2: false - } + &Route::Cluster(cluster_id2) )); assert!(fronts.add_tree_rule( "lolcatho.st".as_bytes(), &PathRule::Prefix(uri3), &MethodRule::new(None), - &Route::Cluster { - id: cluster_id3, - h2: false - } + &Route::Cluster(cluster_id3) )); assert!(fronts.add_tree_rule( "other.domain".as_bytes(), &PathRule::Prefix("test".to_string()), &MethodRule::new(None), - &Route::Cluster { - id: cluster_id1, - h2: false - } + &Route::Cluster(cluster_id1) )); let address = SocketAddress::new_v4(127, 0, 0, 1, 1032); @@ -1628,37 +1616,25 @@ mod tests { let frontend1 = listener.frontend_from_request("lolcatho.st", "/", &Method::Get); assert_eq!( frontend1.expect("should find a frontend"), - Route::Cluster { - id: "cluster_1".to_string(), - h2: false - } + Route::Cluster("cluster_1".to_string()) ); println!("TEST {}", line!()); let frontend2 = listener.frontend_from_request("lolcatho.st", "/test", &Method::Get); assert_eq!( frontend2.expect("should find a frontend"), - Route::Cluster { - id: "cluster_1".to_string(), - h2: false - } + Route::Cluster("cluster_1".to_string()) ); println!("TEST {}", line!()); let frontend3 = listener.frontend_from_request("lolcatho.st", "/yolo/test", &Method::Get); assert_eq!( frontend3.expect("should find a frontend"), - Route::Cluster { - id: "cluster_2".to_string(), - h2: false - } + Route::Cluster("cluster_2".to_string()) ); println!("TEST {}", line!()); let frontend4 = listener.frontend_from_request("lolcatho.st", "/yolo/swag", &Method::Get); assert_eq!( frontend4.expect("should find a frontend"), - Route::Cluster { - id: "cluster_3".to_string(), - h2: false - } + Route::Cluster("cluster_3".to_string()) ); println!("TEST {}", line!()); let frontend5 = listener.frontend_from_request("domain", "/", &Method::Get); diff --git a/lib/src/protocol/kawa_h1/mod.rs b/lib/src/protocol/kawa_h1/mod.rs index 1345172b8..711682446 100644 --- a/lib/src/protocol/kawa_h1/mod.rs +++ b/lib/src/protocol/kawa_h1/mod.rs @@ -1199,7 +1199,7 @@ impl Http id, + Route::Cluster(id) => id, Route::Deny => { self.set_answer(DefaultAnswer::Answer401 {}); return Err(RetrieveClusterError::UnauthorizedRoute); diff --git a/lib/src/protocol/mux/mod.rs b/lib/src/protocol/mux/mod.rs index f5c25e8f5..79aa8cc37 100644 --- a/lib/src/protocol/mux/mod.rs +++ b/lib/src/protocol/mux/mod.rs @@ -184,13 +184,13 @@ impl Connection { timeout_container: TimeoutContainer, ) -> Connection { Connection::H1(ConnectionH1 { + socket: front_stream, position: Position::Server, readiness: Readiness { interest: Ready::READABLE | Ready::HUP | Ready::ERROR, event: Ready::EMPTY, }, requests: 0, - socket: front_stream, stream: 0, timeout_container, }) @@ -667,16 +667,22 @@ impl Router { stream.attempts += 1; let stream_context = &mut stream.context; - let (cluster_id, h2) = self + let cluster_id = self .route_from_request(stream_context, proxy.clone()) .map_err(BackendConnectionError::RetrieveClusterError)?; - let (frontend_should_stick, frontend_should_redirect_https) = proxy + let (frontend_should_stick, frontend_should_redirect_https, h2) = proxy .borrow() .clusters() .get(&cluster_id) - .map(|cluster| (cluster.sticky_session, cluster.https_redirect)) - .unwrap_or((false, false)); + .map(|cluster| { + ( + cluster.sticky_session, + cluster.https_redirect, + cluster.http2, + ) + }) + .unwrap_or((false, false, false)); if frontend_should_redirect_https && matches!(proxy.borrow().kind(), ListenerType::Http) { return Err(BackendConnectionError::RetrieveClusterError( @@ -790,7 +796,7 @@ impl Router { &mut self, context: &mut HttpContext, _proxy: Rc>, - ) -> Result<(String, bool), RetrieveClusterError> { + ) -> Result { let (host, uri, method) = match context.extract_route() { Ok(tuple) => tuple, Err(cluster_error) => { @@ -815,7 +821,7 @@ impl Router { }; let cluster_id = match route { - Route::Cluster { id, h2 } => (id, h2), + Route::Cluster(id) => id, Route::Deny => { println!("Route::Deny"); // self.set_answer(DefaultAnswerStatus::Answer401, None); diff --git a/lib/src/router/mod.rs b/lib/src/router/mod.rs index b50b76d1c..91e1fdaf0 100644 --- a/lib/src/router/mod.rs +++ b/lib/src/router/mod.rs @@ -133,10 +133,7 @@ impl Router { let method_rule = MethodRule::new(front.method.clone()); let route = match &front.cluster_id { - Some(cluster_id) => Route::Cluster { - id: cluster_id.clone(), - h2: front.h2, - }, + Some(cluster_id) => Route::Cluster(cluster_id.clone()), None => Route::Deny, }; @@ -600,7 +597,7 @@ pub enum Route { /// send a 401 default answer Deny, /// the cluster to which the frontend belongs - Cluster { id: ClusterId, h2: bool }, + Cluster(ClusterId), } #[cfg(test)] @@ -719,42 +716,27 @@ mod tests { b"*.sozu.io", &PathRule::Prefix("".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "base".to_string(), - h2: false - } + &Route::Cluster("base".to_string()) )); println!("{:#?}", router.tree); assert_eq!( router.lookup("www.sozu.io", "/api", &Method::Get), - Ok(Route::Cluster { - id: "base".to_string(), - h2: false - }) + Ok(Route::Cluster("base".to_string())) ); assert!(router.add_tree_rule( b"*.sozu.io", &PathRule::Prefix("/api".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "api".to_string(), - h2: false - } + &Route::Cluster("api".to_string()) )); println!("{:#?}", router.tree); assert_eq!( router.lookup("www.sozu.io", "/ap", &Method::Get), - Ok(Route::Cluster { - id: "base".to_string(), - h2: false - }) + Ok(Route::Cluster("base".to_string())) ); assert_eq!( router.lookup("www.sozu.io", "/api", &Method::Get), - Ok(Route::Cluster { - id: "api".to_string(), - h2: false - }) + Ok(Route::Cluster("api".to_string())) ); } @@ -773,42 +755,27 @@ mod tests { b"*.sozu.io", &PathRule::Prefix("".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "base".to_string(), - h2: false - } + &Route::Cluster("base".to_string()) )); println!("{:#?}", router.tree); assert_eq!( router.lookup("www.sozu.io", "/api", &Method::Get), - Ok(Route::Cluster { - id: "base".to_string(), - h2: false - }) + Ok(Route::Cluster("base".to_string())) ); assert!(router.add_tree_rule( b"api.sozu.io", &PathRule::Prefix("".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "api".to_string(), - h2: false - } + &Route::Cluster("api".to_string()) )); println!("{:#?}", router.tree); assert_eq!( router.lookup("www.sozu.io", "/api", &Method::Get), - Ok(Route::Cluster { - id: "base".to_string(), - h2: false - }) + Ok(Route::Cluster("base".to_string())) ); assert_eq!( router.lookup("api.sozu.io", "/api", &Method::Get), - Ok(Route::Cluster { - id: "api".to_string(), - h2: false - }) + Ok(Route::Cluster("api".to_string())) ); } @@ -820,35 +787,23 @@ mod tests { b"www./.*/.io", &PathRule::Prefix("".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "base".to_string(), - h2: false - } + &Route::Cluster("base".to_string()) )); println!("{:#?}", router.tree); assert!(router.add_tree_rule( b"www.doc./.*/.io", &PathRule::Prefix("".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "doc".to_string(), - h2: false - } + &Route::Cluster("doc".to_string()) )); println!("{:#?}", router.tree); assert_eq!( router.lookup("www.sozu.io", "/", &Method::Get), - Ok(Route::Cluster { - id: "base".to_string(), - h2: false - }) + Ok(Route::Cluster("base".to_string())) ); assert_eq!( router.lookup("www.doc.sozu.io", "/", &Method::Get), - Ok(Route::Cluster { - id: "doc".to_string(), - h2: false - }) + Ok(Route::Cluster("doc".to_string())) ); assert!(router.remove_tree_rule( b"www./.*/.io", @@ -859,10 +814,7 @@ mod tests { assert!(router.lookup("www.sozu.io", "/", &Method::Get).is_err()); assert_eq!( router.lookup("www.doc.sozu.io", "/", &Method::Get), - Ok(Route::Cluster { - id: "doc".to_string(), - h2: false - }) + Ok(Route::Cluster("doc".to_string())) ); } @@ -874,45 +826,30 @@ mod tests { &"*".parse::().unwrap(), &PathRule::Prefix("/.well-known/acme-challenge".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "acme".to_string(), - h2: false - } + &Route::Cluster("acme".to_string()) )); assert!(router.add_tree_rule( "www.example.com".as_bytes(), &PathRule::Prefix("/".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "example".to_string(), - h2: false - } + &Route::Cluster("example".to_string()) )); assert!(router.add_tree_rule( "*.test.example.com".as_bytes(), &PathRule::Regex(Regex::new("/hello[A-Z]+/").unwrap()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "examplewildcard".to_string(), - h2: false - } + &Route::Cluster("examplewildcard".to_string()) )); assert!(router.add_tree_rule( "/test[0-9]/.example.com".as_bytes(), &PathRule::Prefix("/".to_string()), &MethodRule::new(Some("GET".to_string())), - &Route::Cluster { - id: "exampleregex".to_string(), - h2: false - } + &Route::Cluster("exampleregex".to_string()) )); assert_eq!( router.lookup("www.example.com", "/helloA", &Method::new(&b"GET"[..])), - Ok(Route::Cluster { - id: "example".to_string(), - h2: false - }) + Ok(Route::Cluster("example".to_string())) ); assert_eq!( router.lookup( @@ -920,10 +857,7 @@ mod tests { "/.well-known/acme-challenge", &Method::new(&b"GET"[..]) ), - Ok(Route::Cluster { - id: "acme".to_string(), - h2: false - }) + Ok(Route::Cluster("acme".to_string())) ); assert!(router .lookup("www.test.example.com", "/", &Method::new(&b"GET"[..])) @@ -934,10 +868,7 @@ mod tests { "/helloAB/", &Method::new(&b"GET"[..]) ), - Ok(Route::Cluster { - id: "examplewildcard".to_string(), - h2: false - }) + Ok(Route::Cluster("examplewildcard".to_string())) ); assert_eq!( router.lookup( @@ -945,17 +876,11 @@ mod tests { "/helloAB/", &Method::new(&b"GET"[..]) ), - Ok(Route::Cluster { - id: "examplewildcard".to_string(), - h2: false - }) + Ok(Route::Cluster("examplewildcard".to_string())) ); assert_eq!( router.lookup("test1.example.com", "/helloAB/", &Method::new(&b"GET"[..])), - Ok(Route::Cluster { - id: "exampleregex".to_string(), - h2: false - }) + Ok(Route::Cluster("exampleregex".to_string())) ); } }