Skip to content

Commit 85f4c33

Browse files
authored
Merge pull request #1244 from microsoft/bugfix-inetstack-window-scale
[inetstack] Bug Fix: Clamp window scale to 14
2 parents 9f63b76 + 4b9a6fd commit 85f4c33

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/rust/inetstack/protocols/tcp/active_open.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ use crate::{
1818
ip::IpProtocol,
1919
ipv4::Ipv4Header,
2020
tcp::{
21-
constants::FALLBACK_MSS,
21+
constants::{
22+
FALLBACK_MSS,
23+
MAX_WINDOW_SCALE,
24+
},
2225
established::{
2326
congestion_control::{
2427
self,
@@ -180,14 +183,25 @@ impl<N: NetworkRuntime> SharedActiveOpenSocket<N> {
180183
}
181184
}
182185

183-
let (local_window_scale, remote_window_scale) = match remote_window_scale {
184-
Some(w) => (self.tcp_config.get_window_scale() as u32, w),
186+
let (local_window_scale, remote_window_scale): (u32, u8) = match remote_window_scale {
187+
Some(remote_window_scale) => {
188+
let local: u32 = if self.tcp_config.get_window_scale() > 14 {
189+
warn!("local windows scale larger than 14 is incorrect, so setting to 14. See RFC 1323.");
190+
MAX_WINDOW_SCALE as u32
191+
} else {
192+
self.tcp_config.get_window_scale() as u32
193+
};
194+
let remote: u8 = if remote_window_scale > 14 {
195+
warn!("remote windows scale larger than 14 is incorrect, so setting to 14. See RFC 1323.");
196+
MAX_WINDOW_SCALE as u8
197+
} else {
198+
remote_window_scale
199+
};
200+
(local, remote)
201+
},
185202
None => (0, 0),
186203
};
187204

188-
// TODO(RFC1323): Clamp the scale to 14 instead of panicking.
189-
assert!(local_window_scale <= 14 && remote_window_scale <= 14);
190-
191205
let rx_window_size: u32 = expect_ok!(
192206
expect_some!(
193207
(self.tcp_config.get_receive_window_size() as u32).checked_shl(local_window_scale as u32),

src/rust/inetstack/protocols/tcp/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ pub use crate::runtime::network::consts::{
55
DEFAULT_MSS,
66
FALLBACK_MSS,
77
MAX_MSS,
8+
MAX_WINDOW_SCALE,
89
MIN_MSS,
910
};

src/rust/runtime/network/consts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ pub const DEFAULT_MSS: usize = 1450;
3636
///
3737
/// TODO: This Should be Generic
3838
pub const RECEIVE_BATCH_SIZE: usize = 4;
39+
40+
/// Maximum local and remote window scaling factor.
41+
/// See: RFC 1323, Section 2.3.
42+
pub const MAX_WINDOW_SCALE: usize = 14;

0 commit comments

Comments
 (0)