Skip to content

Commit 6c9ec17

Browse files
authored
fix(s2n-quic-dc): correctly process IPv6 on recv path (#2626)
1 parent 6aa9975 commit 6c9ec17

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

dc/s2n-quic-dc/src/stream/application.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ where
150150
self.read.protocol()
151151
}
152152

153+
#[inline]
154+
pub fn set_read_mode(&mut self, read_mode: recv::ReadMode) -> &mut Self {
155+
self.read.set_read_mode(read_mode);
156+
self
157+
}
158+
159+
#[inline]
160+
pub fn set_ack_mode(&mut self, ack_mode: recv::AckMode) -> &mut Self {
161+
self.read.set_ack_mode(ack_mode);
162+
self
163+
}
164+
153165
#[inline]
154166
pub async fn write_from(
155167
&mut self,

dc/s2n-quic-dc/src/stream/client/rpc.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::{event, stream::application::Stream};
4+
use crate::{
5+
event,
6+
stream::{application::Stream, recv::application::ReadMode},
7+
};
58
use s2n_quic_core::buffer::{self, writer::Storage};
69
use std::{
710
future::{poll_fn, Future},
@@ -20,6 +23,9 @@ where
2023
{
2124
let (mut reader, mut writer) = stream.into_split();
2225

26+
// prefer draining all of the packets before sending an ACK
27+
reader.set_read_mode(ReadMode::UntilFull);
28+
2329
// TODO if the request is large enough, should we spawn a task for it?
2430
let mut writer = async move {
2531
while !request.buffer_is_empty() {

dc/s2n-quic-dc/src/stream/recv/application.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ where
135135
self.0.sockets.protocol()
136136
}
137137

138+
#[inline]
139+
pub fn set_read_mode(&mut self, read_mode: ReadMode) -> &mut Self {
140+
self.0.read_mode = read_mode;
141+
self
142+
}
143+
144+
#[inline]
145+
pub fn set_ack_mode(&mut self, ack_mode: AckMode) -> &mut Self {
146+
self.0.ack_mode = ack_mode;
147+
self
148+
}
149+
138150
#[inline]
139151
pub async fn read_into<S>(&mut self, out_buf: &mut S) -> io::Result<usize>
140152
where

dc/s2n-quic-dc/src/stream/recv/application/builder.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use crate::{
1414
use core::mem::ManuallyDrop;
1515
use s2n_quic_core::endpoint;
1616

17+
use super::ReadMode;
18+
1719
pub struct Builder<Sub> {
1820
endpoint: endpoint::Type,
1921
runtime: runtime::ArcHandle<Sub>,
@@ -44,7 +46,14 @@ where
4446
};
4547
let gso = shared.gso.clone();
4648
let send_buffer = msg::send::Message::new(remote_addr, gso);
47-
let read_mode = Default::default();
49+
// If the transport is reliable then it's handling ACKs. Otherwise, the application is sending
50+
// ACKs so we want to do a little more compute per `read` call, if the application buffer allows
51+
// for it.
52+
let read_mode = if is_reliable {
53+
ReadMode::Once
54+
} else {
55+
ReadMode::UntilFull
56+
};
4857
let ack_mode = Default::default();
4958
let local_state = match endpoint {
5059
// reliable transports on the client need to read at least one packet in order to

dc/s2n-quic-dc/src/stream/socket/fd/udp.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ fn recv_msghdr(
115115

116116
let len = exec(&mut msg)?;
117117

118+
// make sure the CMSG has the correct length
118119
cmsg.with_msg(&msg);
120+
// make sure the addr has the correct length
121+
addr.update_with_msg(&msg);
119122

120123
Ok(len)
121124
}

0 commit comments

Comments
 (0)