Skip to content

Commit

Permalink
Merge pull request #1244 from microsoft/bugfix-inetstack-window-scale
Browse files Browse the repository at this point in the history
[inetstack] Bug Fix: Clamp window scale to 14
  • Loading branch information
ppenna committed Apr 26, 2024
2 parents 9f63b76 + 4b9a6fd commit 85f4c33
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/rust/inetstack/protocols/tcp/active_open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use crate::{
ip::IpProtocol,
ipv4::Ipv4Header,
tcp::{
constants::FALLBACK_MSS,
constants::{
FALLBACK_MSS,
MAX_WINDOW_SCALE,
},
established::{
congestion_control::{
self,
Expand Down Expand Up @@ -180,14 +183,25 @@ impl<N: NetworkRuntime> SharedActiveOpenSocket<N> {
}
}

let (local_window_scale, remote_window_scale) = match remote_window_scale {
Some(w) => (self.tcp_config.get_window_scale() as u32, w),
let (local_window_scale, remote_window_scale): (u32, u8) = match remote_window_scale {
Some(remote_window_scale) => {
let local: u32 = if self.tcp_config.get_window_scale() > 14 {
warn!("local windows scale larger than 14 is incorrect, so setting to 14. See RFC 1323.");
MAX_WINDOW_SCALE as u32
} else {
self.tcp_config.get_window_scale() as u32
};
let remote: u8 = if remote_window_scale > 14 {
warn!("remote windows scale larger than 14 is incorrect, so setting to 14. See RFC 1323.");
MAX_WINDOW_SCALE as u8
} else {
remote_window_scale
};
(local, remote)
},
None => (0, 0),
};

// TODO(RFC1323): Clamp the scale to 14 instead of panicking.
assert!(local_window_scale <= 14 && remote_window_scale <= 14);

let rx_window_size: u32 = expect_ok!(
expect_some!(
(self.tcp_config.get_receive_window_size() as u32).checked_shl(local_window_scale as u32),
Expand Down
1 change: 1 addition & 0 deletions src/rust/inetstack/protocols/tcp/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pub use crate::runtime::network::consts::{
DEFAULT_MSS,
FALLBACK_MSS,
MAX_MSS,
MAX_WINDOW_SCALE,
MIN_MSS,
};
4 changes: 4 additions & 0 deletions src/rust/runtime/network/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ pub const DEFAULT_MSS: usize = 1450;
///
/// TODO: This Should be Generic
pub const RECEIVE_BATCH_SIZE: usize = 4;

/// Maximum local and remote window scaling factor.
/// See: RFC 1323, Section 2.3.
pub const MAX_WINDOW_SCALE: usize = 14;

0 comments on commit 85f4c33

Please sign in to comment.