From 59203c63bb777a3bacec32fb8830fba33540e809 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:29 +0200 Subject: Adding upstream version 127.0. Signed-off-by: Daniel Baumann --- third_party/rust/neqo-common/src/tos.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'third_party/rust/neqo-common/src/tos.rs') diff --git a/third_party/rust/neqo-common/src/tos.rs b/third_party/rust/neqo-common/src/tos.rs index 533c5447e2..c7e5228dee 100644 --- a/third_party/rust/neqo-common/src/tos.rs +++ b/third_party/rust/neqo-common/src/tos.rs @@ -52,6 +52,16 @@ impl From for IpTosEcn { } } +impl IpTosEcn { + #[must_use] + pub fn is_ecn_marked(&self) -> bool { + match self { + IpTosEcn::Ect0 | IpTosEcn::Ect1 | IpTosEcn::Ce => true, + IpTosEcn::NotEct => false, + } + } +} + /// Diffserv Codepoints, mapped to the upper six bits of the TOS field. /// #[derive(Copy, Clone, PartialEq, Eq, Enum, Default, Debug)] @@ -228,6 +238,11 @@ impl IpTos { pub fn set_dscp(&mut self, dscp: IpTosDscp) { self.0 = u8::from(IpTosEcn::from(*self)) | u8::from(dscp); } + + #[must_use] + pub fn is_ecn_marked(&self) -> bool { + IpTosEcn::from(*self).is_ecn_marked() + } } #[cfg(test)] @@ -346,4 +361,16 @@ mod tests { iptos.set_dscp(IpTosDscp::Le); assert_eq!(u8::from(iptos), 0b0000_0101); } + + #[test] + fn iptos_is_ecn_marked() { + let iptos: IpTos = (IpTosDscp::Af41, IpTosEcn::Ce).into(); + assert!(iptos.is_ecn_marked()); + } + + #[test] + fn iptosecn_is_ecn_marked() { + assert!(IpTosEcn::Ce.is_ecn_marked()); + assert!(!IpTosEcn::NotEct.is_ecn_marked()); + } } -- cgit v1.2.3