Skip to content
Merged

SCONE #2814

Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
88a70b9
Ignore all SCONE packets
martinthomson Jul 30, 2025
adf34f4
SCONE transport parameter
martinthomson Jul 30, 2025
180fa17
Add SCONE indication
martinthomson Jul 30, 2025
9abae10
Log SCONE value
martinthomson Jul 30, 2025
051b44f
Add a connection-level test for SCONE
martinthomson Jul 30, 2025
340cab1
Clippy, review comments
martinthomson Jul 30, 2025
61606a8
Reduce log level for packet drops
martinthomson Jul 30, 2025
14a6922
Conditionally error on other version packets
martinthomson Jul 30, 2025
45866a0
Merge branch 'main' into scone
larseggert Aug 4, 2025
504465c
Add a further test for Initial before docking two bytes
martinthomson Aug 18, 2025
3c0924b
Fix the indication reservation and test it
martinthomson Aug 19, 2025
8248f31
chore(.github/check.yaml): remove obsolete run_benchmarks input (#2826)
mxinden Aug 5, 2025
7d1e8e1
ci: Create cache on `merge_group` trigger (#2824)
larseggert Aug 5, 2025
5e3698b
refactor(http3): improve `FrameReader` `Debug` implementation (#2815)
mxinden Aug 6, 2025
4f2be30
chore(clippy): remove expect for needless_match (#2835)
mxinden Aug 8, 2025
f46cbe8
chore(clippy): update to latest lints (#2837)
mxinden Aug 8, 2025
beb8474
ci: Disable systemd unified cgroups on GCP (#2803)
larseggert Aug 8, 2025
eea59c8
build(deps): bump github/codeql-action from 3.29.7 to 3.29.8 (#2845)
dependabot[bot] Aug 11, 2025
7fe5139
build(deps): bump actions/cache from 4.2.3 to 4.2.4 (#2844)
dependabot[bot] Aug 11, 2025
bdb4655
build(deps): bump docker/login-action from 3.4.0 to 3.5.0 (#2846)
dependabot[bot] Aug 11, 2025
cbd333b
build(deps): bump actions/download-artifact from 4.3.0 to 5.0.0 (#2841)
dependabot[bot] Aug 11, 2025
96733d7
ci: Use an older kernel with `cpuset` support for benchers (#2840)
larseggert Aug 11, 2025
88f45d3
fix(transport/frame): prevent potential overflow in padding decode (#…
mxinden Aug 11, 2025
d36d80f
docs(transport/datagrams): remove outdated fn return docs (#2842)
mxinden Aug 11, 2025
c75f260
refactor(crypto): improve `ResumptionToken` `Debug` impl (#2847)
mxinden Aug 12, 2025
3cf3f20
docs(transport): extend preprocess_packet docs on State::Closing (#2848)
mxinden Aug 12, 2025
fac12b9
ci: Use 6.11 kernel on GCP (#2849)
larseggert Aug 12, 2025
2e0fb5b
ci: Use implicit `$HOME` home directory (#2850)
larseggert Aug 12, 2025
ca891d4
feat: Optimize `neqo-qpack` (#2831)
larseggert Aug 12, 2025
8aaff0d
fix(http3): reduce visibility of internal functions (#2802)
mxinden Aug 13, 2025
03635cb
refactor: unify most exchange_packets impls (#2851)
mxinden Aug 14, 2025
2b03734
Make initial RTT configurable (#2825)
aochagavia Aug 14, 2025
6de0cbc
fix(bin): replace buggy `to_headers` with `FromStr` `impl` (#2833)
mxinden Aug 14, 2025
f44bf2a
refactor(webtransport): rename WebTransportEvent::Session to NewSessi…
mxinden Aug 15, 2025
802539a
ci: No `mold` (#2857)
larseggert Aug 15, 2025
288654a
docs(http3): remove partially outdated docs (#2859)
mxinden Aug 15, 2025
f91d30a
chore: Bump `sfv` to 0.14 (#2856)
larseggert Aug 18, 2025
9897a61
Make the drop_handshake_packet_from_wrong_address robust (#2862)
martinthomson Aug 18, 2025
54e4f41
Make discarded_initial_keys more robust (#2864)
martinthomson Aug 18, 2025
c40be86
Improve resending of Initial on undecryptable (#2866)
martinthomson Aug 18, 2025
a2fad09
compatible_upgrade_large_initial robustness (#2863)
martinthomson Aug 18, 2025
816123e
Move connection parameter defaults to the type (#2869)
martinthomson Aug 18, 2025
1957111
Move test_frame_writer use (#2870)
martinthomson Aug 18, 2025
70b354a
Improve the ALPN handling (#2871)
martinthomson Aug 18, 2025
29f90e2
Make only_server_initial more robust (#2865)
martinthomson Aug 18, 2025
0612eb7
coalesce_05rtt robustness improvements (#2867)
martinthomson Aug 18, 2025
dd2dc28
A bunch of logging improvements (#2874)
martinthomson Aug 18, 2025
0c54805
Completely rewrite dup_server_flight1 (#2868)
martinthomson Aug 18, 2025
9381d2c
Force coverage up by simplifying a test (#2872)
martinthomson Aug 18, 2025
a12844d
Fix packet_with_only_padding test (#2873)
martinthomson Aug 18, 2025
a5731cb
PTO across packet number spaces better (#2878)
martinthomson Aug 19, 2025
83ea414
fix: Don't call `finish` in `std::hash::Hash` implementations (#2881)
larseggert Aug 20, 2025
de8a0d5
refactor(bin/server): simplify run() removing need for HttpServer::ne…
mxinden Aug 20, 2025
308cd48
Fix compatible upgrade (#2877)
martinthomson Aug 20, 2025
04372c8
Address test changes (more padding now means rearrangement of handshake)
martinthomson Aug 21, 2025
ed63dbe
Merge branch 'main' into scone
martinthomson Aug 21, 2025
f19e25e
Merge branch 'main' into scone
martinthomson Nov 1, 2025
8cab793
More tests with less flake
martinthomson Nov 1, 2025
d2bda88
Moar robust testing
martinthomson Nov 1, 2025
e054658
Finalize fixes for more tests
martinthomson Nov 2, 2025
7633496
dafmt
martinthomson Nov 2, 2025
8825e39
Clippy
martinthomson Nov 2, 2025
5cae4b1
Merge branch 'main' into scone
martinthomson Mar 12, 2026
31da46b
Merge branch 'main' into scone
martinthomson Mar 12, 2026
7d92ee3
Fix some comments
martinthomson Mar 13, 2026
07e4f68
Merge branch 'main' into scone
martinthomson Mar 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ impl Connection {
/// A long default for timer resolution, so that we don't tax the
/// system too hard when we don't need to.
const LOOSE_TIMER_RESOLUTION: Duration = Duration::from_millis(50);
/// The SCONE indicator.
const SCONE_INDICATION: &[u8] = &[0xc8, 0x13];
Comment thread
martinthomson marked this conversation as resolved.
Resolved

/// Create a new QUIC connection with Client role.
/// # Errors
Expand Down Expand Up @@ -2664,7 +2666,7 @@ impl Connection {
let limit = if path.borrow().pmtud().needs_probe() {
needs_padding = true;
debug_assert!(path.borrow().pmtud().probe_size() >= profile.limit());
path.borrow().pmtud().probe_size() - aead_expansion
path.borrow().pmtud().probe_size() - aead_expansion - Self::SCONE_INDICATION.len()
Comment thread
larseggert marked this conversation as resolved.
Resolved
Comment thread
larseggert marked this conversation as resolved.
Resolved
} else {
profile.limit() - aead_expansion
};
Expand Down Expand Up @@ -2799,16 +2801,8 @@ impl Connection {
} else {
// Perform additional padding for Initial packets as necessary.
if let Some(mut initial) = initial_sent.take() {
if needs_padding && encoder.len() < profile.limit() {
qdebug!(
"[{self}] pad Initial from {} to PLPMTU {}",
encoder.len(),
profile.limit()
);
initial.track_padding(profile.limit() - encoder.len());
// These zeros aren't padding frames, they are an invalid all-zero coalesced
// packet, which is why we don't increase `frame_tx.padding` count here.
encoder.pad_to(profile.limit(), 0);
if needs_padding {
self.pad_initial(&mut encoder, &mut initial, profile);
}
self.loss_recovery.on_packet_sent(path, initial, now);
}
Expand All @@ -2817,6 +2811,36 @@ impl Connection {
}
}

fn pad_initial(
&self,
encoder: &mut Encoder<&mut Vec<u8>>,
initial: &mut sent::Packet,
profile: &SendProfile,
) {
if encoder.len() >= profile.limit() {
return;
}

qdebug!(
"[{self}] pad Initial from {} to {}",
encoder.len(),
profile.limit()
);
let pad_amount = profile.limit() - encoder.len();
initial.track_padding(pad_amount);
// This ensures that the last bytes are a SCONE indication, if there is enough space.
// This is not tracked, other than for congestion control (above)
if pad_amount >= Self::SCONE_INDICATION.len() {
encoder.pad_to(
profile.limit() - Self::SCONE_INDICATION.len() + 1,
Self::SCONE_INDICATION[0],
Comment thread
martinthomson marked this conversation as resolved.
Resolved
);
encoder.encode(&Self::SCONE_INDICATION[1..]);
Comment thread
martinthomson marked this conversation as resolved.
Resolved
} else {
encoder.pad_to(profile.limit(), Self::SCONE_INDICATION[0]);
}
}

/// # Errors
/// When connection state is not valid.
pub fn initiate_key_update(&mut self) -> Res<()> {
Expand Down
9 changes: 5 additions & 4 deletions neqo-transport/src/connection/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use crate::{
tparams::{
PreferredAddress, TransportParameter,
TransportParameterId::{
self, ActiveConnectionIdLimit, DisableMigration, GreaseQuicBit, InitialMaxData,
ActiveConnectionIdLimit, DisableMigration, GreaseQuicBit, IdleTimeout, InitialMaxData,
InitialMaxStreamDataBidiLocal, InitialMaxStreamDataBidiRemote, InitialMaxStreamDataUni,
InitialMaxStreamsBidi, InitialMaxStreamsUni, MaxAckDelay, MaxDatagramFrameSize,
MinAckDelay,
MinAckDelay, PreferredAddress as PreferredAddressTp, Scone,
},
TransportParametersHandler,
},
Expand Down Expand Up @@ -444,6 +444,7 @@ impl ConnectionParameters {
if self.grease {
tps.local_mut().set_empty(GreaseQuicBit);
}
tps.local_mut().set_empty(Scone);
tps.local_mut().set_integer(
MaxAckDelay,
u64::try_from(DEFAULT_LOCAL_ACK_DELAY.as_millis())?,
Expand All @@ -468,14 +469,14 @@ impl ConnectionParameters {
tps.local_mut()
.set_integer(InitialMaxStreamsUni, self.max_streams_uni);
tps.local_mut().set_integer(
TransportParameterId::IdleTimeout,
IdleTimeout,
Comment thread
larseggert marked this conversation as resolved.
Resolved
u64::try_from(self.idle_timeout.as_millis()).unwrap_or(0),
);
if let PreferredAddressConfig::Address(preferred) = &self.preferred_address {
if role == Role::Server {
let (cid, srt) = cid_manager.preferred_address_cid()?;
tps.local_mut().set(
TransportParameterId::PreferredAddress,
PreferredAddressTp,
Comment thread
martinthomson marked this conversation as resolved.
Resolved
TransportParameter::PreferredAddress {
v4: preferred.ipv4(),
v6: preferred.ipv6(),
Expand Down
38 changes: 33 additions & 5 deletions neqo-transport/src/connection/tests/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,23 +664,24 @@ fn reorder_1rtt() {
fn corrupted_initial() {
let mut client = default_client();
let mut server = default_server();

let d = client.process_output(now()).dgram().unwrap();
let mut corrupted = Vec::from(&d[..]);
// Find the last non-zero value and corrupt that.
// Find the last non-padding value and corrupt that.
let (idx, _) = corrupted
.iter()
.enumerate()
.rev()
.find(|(_, &v)| v != 0)
.skip(1) // Skip the last byte, which might be a SCONE indicator.
.find(|(_, &v)| v != Connection::SCONE_INDICATION[0]) // The SCONE padding value.
.unwrap();
corrupted[idx] ^= 0x76;

let dgram = Datagram::new(d.source(), d.destination(), d.tos(), corrupted);
server.process_input(dgram, now());
// The server should have received two packets,
// the first should be dropped, the second saved.
// The server should have received two "packets", both corrupted.
assert_eq!(server.stats().packets_rx, 2);
assert_eq!(server.stats().dropped_rx, 2);
assert_eq!(server.stats().saved_datagrams, 0);
}

#[test]
Expand Down Expand Up @@ -1420,3 +1421,30 @@ fn zero_rtt_with_ech() {
assert!(client.tls_info().unwrap().early_data_accepted());
assert!(server.tls_info().unwrap().early_data_accepted());
}

#[test]
fn scone() {
fn add_scone(d: &Datagram) -> Datagram {
const SCONE: &[u8] = &[0xff, 0x6f, 0x7d, 0xc0, 0xfd, 0x00, 0x00];
let mut sconed = SCONE.to_vec();
sconed.extend_from_slice(&d[..]);
Datagram::new(d.source(), d.destination(), d.tos(), sconed)
}

let mut server = default_server();
let mut client = default_client();
connect(&mut client, &mut server);
assert!(client.tps.borrow_mut().remote().get_empty(Scone));
assert!(server.tps.borrow_mut().remote().get_empty(Scone));

let client_stats = client.stats();
let server_stats = server.stats();
let d = send_something(&mut client, now());
server.process_input(add_scone(&d), now());
let d = send_something(&mut server, now());
client.process_input(add_scone(&d), now());

// The SCONE packets are effectively invisible.
assert_eq!(server.stats().packets_rx, server_stats.packets_rx + 1);
assert_eq!(client.stats().packets_rx, client_stats.packets_rx + 1);
}
149 changes: 115 additions & 34 deletions neqo-transport/src/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{
};

use enum_map::Enum;
use log::debug;
use neqo_common::{hex, hex_with_len, qtrace, qwarn, Buffer, Decoder, Encoder};
use neqo_crypto::{random, Aead};
use strum::{EnumIter, FromRepr};
Expand Down Expand Up @@ -612,6 +613,32 @@ impl<'a> Public<'a> {
pub fn decode(
data: &'a mut [u8],
dcid_decoder: &dyn ConnectionIdDecoder,
) -> Res<(Self, &'a mut [u8])> {
Self::decode_inner(data, dcid_decoder, false)
}

/// Like `decode()`, but allow unknown versions.
///
/// # Errors
///
/// This will return an error if the packet could not be decoded.
pub fn decode_server(
data: &'a mut [u8],
dcid_decoder: &dyn ConnectionIdDecoder,
) -> Res<(Self, &'a mut [u8])> {
Self::decode_inner(data, dcid_decoder, true)
}

/// Decode the common parts of a packet. This provides minimal parsing and validation.
/// Returns a tuple of a `Public` and a slice with any remainder from the datagram.
///
/// # Errors
///
/// This will return an error if the packet could not be decoded.
fn decode_inner(
data: &'a mut [u8],
dcid_decoder: &dyn ConnectionIdDecoder,
accept_other_version: bool,
) -> Res<(Self, &'a mut [u8])> {
let mut decoder = Decoder::new(data);
let first = Self::opt(decoder.decode_uint::<u8>())?;
Expand Down Expand Up @@ -644,39 +671,56 @@ impl<'a> Public<'a> {

// Generic long header.
let version = Self::opt(decoder.decode_uint())?;
let dcid = ConnectionIdRef::from(Self::opt(decoder.decode_vec(1))?).into();
let scid = ConnectionIdRef::from(Self::opt(decoder.decode_vec(1))?).into();
let dcid = ConnectionIdRef::from(Self::opt(decoder.decode_vec(1))?);
let scid = ConnectionIdRef::from(Self::opt(decoder.decode_vec(1))?);
Comment thread
larseggert marked this conversation as resolved.
Resolved

// Version negotiation.
if version == 0 {
return Ok((
Self {
packet_type: Type::VersionNegotiation,
dcid,
scid: Some(scid),
token: vec![],
header_len: decoder.offset(),
version: None,
data,
},
&mut [],
));
match version {
0 => {
return Ok((
Self {
packet_type: Type::VersionNegotiation,
dcid: ConnectionId::from(dcid),
scid: Some(ConnectionId::from(scid)),
token: vec![],
header_len: decoder.offset(),
version: None,
data,
},
&mut [],
))
}
Version::SCONE1 | Version::SCONE2 => {
// Note: this outright ignores SCONE packets.
// It does not even validate that the connection ID is correct.
debug!(
"Received SCONE indication {i}",
i = u8::try_from((version >> 25) & 0x40)? | (first & 0x3f)
);
let (_scone, remainder) = data.split_at_mut(decoder.offset());
return Self::decode(remainder, dcid_decoder);
}
_ => {}
}

// Check that this is a long header from a supported version.
let Ok(version) = Version::try_from(version) else {
return Ok((
Self {
packet_type: Type::OtherVersion,
dcid,
scid: Some(scid),
token: vec![],
header_len: decoder.offset(),
version: Some(version),
data,
},
&mut [],
));
return if accept_other_version {
Ok((
Self {
packet_type: Type::OtherVersion,
dcid: ConnectionId::from(dcid),
scid: Some(ConnectionId::from(scid)),
token: vec![],
header_len: decoder.offset(),
version: Some(version),
data,
},
&mut [],
))
} else {
Err(Error::InvalidPacket)
};
};

if dcid.len() > MAX_CONNECTION_ID_LEN || scid.len() > MAX_CONNECTION_ID_LEN {
Expand All @@ -687,13 +731,14 @@ impl<'a> Public<'a> {
// The type-specific code includes a token. This consumes the remainder of the packet.
let (token, header_len) = Public::decode_long(&mut decoder, packet_type, version)?;
let token = token.to_vec();
let end = data.len() - decoder.remaining();
let (data, remainder) = data.split_at_mut(end);
let dcid = ConnectionId::from(dcid);
let scid = Some(ConnectionId::from(scid));
let (data, remainder) = data.split_at_mut(decoder.offset());
Ok((
Self {
packet_type,
dcid,
scid: Some(scid),
scid,
token,
header_len,
version: Some(version.wire_version()),
Expand Down Expand Up @@ -973,7 +1018,7 @@ mod tests {
Builder, Public, Type, PACKET_BIT_FIXED_QUIC, PACKET_BIT_LONG, PACKET_BIT_SPIN,
PACKET_LIMIT,
},
ConnectionId, EmptyConnectionIdGenerator, RandomConnectionIdGenerator, Version,
ConnectionId, EmptyConnectionIdGenerator, Error, RandomConnectionIdGenerator, Version,
};

const CLIENT_CID: &[u8] = &[0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08];
Expand Down Expand Up @@ -1124,10 +1169,9 @@ mod tests {
assert!(!firsts.iter().all(is_set(PACKET_BIT_SPIN)));
}

#[test]
fn decode_short() {
fn decode_sample_short(packet: &[u8]) {
fixture_init();
let mut sample_short = SAMPLE_SHORT.to_vec();
let mut sample_short = packet.to_vec();
let (mut packet, remainder) = Public::decode(&mut sample_short, &cid_mgr()).unwrap();
assert_eq!(packet.packet_type(), Type::Short);
assert!(remainder.is_empty());
Expand All @@ -1137,6 +1181,11 @@ mod tests {
assert_eq!(&decrypted[..], SAMPLE_SHORT_PAYLOAD);
}

#[test]
fn decode_short() {
decode_sample_short(SAMPLE_SHORT);
}

/// By telling the decoder that the connection ID is shorter than it really is, we get a
/// decryption error.
#[test]
Expand Down Expand Up @@ -1549,4 +1598,36 @@ mod tests {
let res = Public::decode(&mut data, &EmptyConnectionIdGenerator::default());
assert!(res.is_err());
}

#[test]
fn ignore_scone() {
/// A minimal SCONE packet.
const SCONE1: &[u8] = &[0xff, 0x6f, 0x7d, 0xc0, 0xfd, 0x00, 0x00];
/// A generous SCONE packet, including a connection ID that is too long for QUIC v1/v2.
const SCONE2: &[u8] = &[
0xff, 0xef, 0x7d, 0xc0, 0xfd, 0x01, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
];

let mut scone1 = SCONE1.to_vec();
scone1.extend_from_slice(SAMPLE_SHORT);
decode_sample_short(&scone1);
let mut scone2 = SCONE2.to_vec();
scone2.extend_from_slice(SAMPLE_SHORT);
decode_sample_short(&scone2);

// Add several SCONE packets.
let mut scone3 = SCONE1.to_vec();
scone3.extend_from_slice(SCONE1);
scone3.extend_from_slice(SCONE2);
scone3.extend_from_slice(SCONE1);
scone3.extend_from_slice(SAMPLE_SHORT);
decode_sample_short(&scone3);

// A SCONE-only packet is an error.
let mut scone_only = SCONE1.to_vec();
let res = Public::decode(&mut scone_only, &cid_mgr());
assert!(matches!(res, Err(Error::NoMoreData)));
}
}
3 changes: 2 additions & 1 deletion neqo-transport/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ impl Server {
let len = dgram.len();
let destination = dgram.destination();
let source = dgram.source();
let res = Public::decode(&mut dgram[..], self.cid_generator.borrow().as_decoder());
let res =
Public::decode_server(&mut dgram[..], self.cid_generator.borrow().as_decoder());
let Ok((packet, _remainder)) = res else {
qtrace!("[{self}] Discarding {dgram:?}");
continue;
Expand Down
Loading