Skip to content

Commit 82dd0b5

Browse files
authored
fix: process packets from different sources before handshake confirmed (#2463)
1 parent 8bfc8a8 commit 82dd0b5

File tree

11 files changed

+735
-486
lines changed

11 files changed

+735
-486
lines changed

quic/s2n-quic-core/events/connection.rs

+10
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ struct DatagramDropped<'a> {
284284
reason: DatagramDropReason,
285285
}
286286

287+
#[event("transport:handshake_remote_address_change_observed")]
288+
/// The remote address was changed before the handshake was complete
289+
struct HandshakeRemoteAddressChangeObserved<'a> {
290+
local_addr: SocketAddress<'a>,
291+
/// The newly observed remote address
292+
remote_addr: SocketAddress<'a>,
293+
/// The remote address established from the initial packet
294+
initial_remote_addr: SocketAddress<'a>,
295+
}
296+
287297
#[event("connectivity:connection_id_updated")]
288298
//= https://tools.ietf.org/id/draft-marx-qlog-event-definitions-quic-h3-02#5.1.4
289299
/// ConnectionId updated

quic/s2n-quic-core/src/event/generated.rs

+136
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,29 @@ pub mod api {
23152315
}
23162316
#[derive(Clone, Debug)]
23172317
#[non_exhaustive]
2318+
#[doc = " The remote address was changed before the handshake was complete"]
2319+
pub struct HandshakeRemoteAddressChangeObserved<'a> {
2320+
pub local_addr: SocketAddress<'a>,
2321+
#[doc = " The newly observed remote address"]
2322+
pub remote_addr: SocketAddress<'a>,
2323+
#[doc = " The remote address established from the initial packet"]
2324+
pub initial_remote_addr: SocketAddress<'a>,
2325+
}
2326+
#[cfg(any(test, feature = "testing"))]
2327+
impl<'a> crate::event::snapshot::Fmt for HandshakeRemoteAddressChangeObserved<'a> {
2328+
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
2329+
let mut fmt = fmt.debug_struct("HandshakeRemoteAddressChangeObserved");
2330+
fmt.field("local_addr", &self.local_addr);
2331+
fmt.field("remote_addr", &self.remote_addr);
2332+
fmt.field("initial_remote_addr", &self.initial_remote_addr);
2333+
fmt.finish()
2334+
}
2335+
}
2336+
impl<'a> Event for HandshakeRemoteAddressChangeObserved<'a> {
2337+
const NAME: &'static str = "transport:handshake_remote_address_change_observed";
2338+
}
2339+
#[derive(Clone, Debug)]
2340+
#[non_exhaustive]
23182341
#[doc = " ConnectionId updated"]
23192342
pub struct ConnectionIdUpdated<'a> {
23202343
pub path_id: u64,
@@ -3921,6 +3944,21 @@ pub mod tracing {
39213944
tracing :: event ! (target : "datagram_dropped" , parent : id , tracing :: Level :: DEBUG , { local_addr = tracing :: field :: debug (local_addr) , remote_addr = tracing :: field :: debug (remote_addr) , destination_cid = tracing :: field :: debug (destination_cid) , source_cid = tracing :: field :: debug (source_cid) , len = tracing :: field :: debug (len) , reason = tracing :: field :: debug (reason) });
39223945
}
39233946
#[inline]
3947+
fn on_handshake_remote_address_change_observed(
3948+
&mut self,
3949+
context: &mut Self::ConnectionContext,
3950+
_meta: &api::ConnectionMeta,
3951+
event: &api::HandshakeRemoteAddressChangeObserved,
3952+
) {
3953+
let id = context.id();
3954+
let api::HandshakeRemoteAddressChangeObserved {
3955+
local_addr,
3956+
remote_addr,
3957+
initial_remote_addr,
3958+
} = event;
3959+
tracing :: event ! (target : "handshake_remote_address_change_observed" , parent : id , tracing :: Level :: DEBUG , { local_addr = tracing :: field :: debug (local_addr) , remote_addr = tracing :: field :: debug (remote_addr) , initial_remote_addr = tracing :: field :: debug (initial_remote_addr) });
3960+
}
3961+
#[inline]
39243962
fn on_connection_id_updated(
39253963
&mut self,
39263964
context: &mut Self::ConnectionContext,
@@ -5978,6 +6016,32 @@ pub mod builder {
59786016
}
59796017
}
59806018
#[derive(Clone, Debug)]
6019+
#[doc = " The remote address was changed before the handshake was complete"]
6020+
pub struct HandshakeRemoteAddressChangeObserved<'a> {
6021+
pub local_addr: SocketAddress<'a>,
6022+
#[doc = " The newly observed remote address"]
6023+
pub remote_addr: SocketAddress<'a>,
6024+
#[doc = " The remote address established from the initial packet"]
6025+
pub initial_remote_addr: SocketAddress<'a>,
6026+
}
6027+
impl<'a> IntoEvent<api::HandshakeRemoteAddressChangeObserved<'a>>
6028+
for HandshakeRemoteAddressChangeObserved<'a>
6029+
{
6030+
#[inline]
6031+
fn into_event(self) -> api::HandshakeRemoteAddressChangeObserved<'a> {
6032+
let HandshakeRemoteAddressChangeObserved {
6033+
local_addr,
6034+
remote_addr,
6035+
initial_remote_addr,
6036+
} = self;
6037+
api::HandshakeRemoteAddressChangeObserved {
6038+
local_addr: local_addr.into_event(),
6039+
remote_addr: remote_addr.into_event(),
6040+
initial_remote_addr: initial_remote_addr.into_event(),
6041+
}
6042+
}
6043+
}
6044+
#[derive(Clone, Debug)]
59816045
#[doc = " ConnectionId updated"]
59826046
pub struct ConnectionIdUpdated<'a> {
59836047
pub path_id: u64,
@@ -7073,6 +7137,18 @@ mod traits {
70737137
let _ = meta;
70747138
let _ = event;
70757139
}
7140+
#[doc = "Called when the `HandshakeRemoteAddressChangeObserved` event is triggered"]
7141+
#[inline]
7142+
fn on_handshake_remote_address_change_observed(
7143+
&mut self,
7144+
context: &mut Self::ConnectionContext,
7145+
meta: &api::ConnectionMeta,
7146+
event: &api::HandshakeRemoteAddressChangeObserved,
7147+
) {
7148+
let _ = context;
7149+
let _ = meta;
7150+
let _ = event;
7151+
}
70767152
#[doc = "Called when the `ConnectionIdUpdated` event is triggered"]
70777153
#[inline]
70787154
fn on_connection_id_updated(
@@ -7783,6 +7859,16 @@ mod traits {
77837859
(self.1).on_datagram_dropped(&mut context.1, meta, event);
77847860
}
77857861
#[inline]
7862+
fn on_handshake_remote_address_change_observed(
7863+
&mut self,
7864+
context: &mut Self::ConnectionContext,
7865+
meta: &api::ConnectionMeta,
7866+
event: &api::HandshakeRemoteAddressChangeObserved,
7867+
) {
7868+
(self.0).on_handshake_remote_address_change_observed(&mut context.0, meta, event);
7869+
(self.1).on_handshake_remote_address_change_observed(&mut context.1, meta, event);
7870+
}
7871+
#[inline]
77867872
fn on_connection_id_updated(
77877873
&mut self,
77887874
context: &mut Self::ConnectionContext,
@@ -8348,6 +8434,11 @@ mod traits {
83488434
fn on_datagram_received(&mut self, event: builder::DatagramReceived);
83498435
#[doc = "Publishes a `DatagramDropped` event to the publisher's subscriber"]
83508436
fn on_datagram_dropped(&mut self, event: builder::DatagramDropped);
8437+
#[doc = "Publishes a `HandshakeRemoteAddressChangeObserved` event to the publisher's subscriber"]
8438+
fn on_handshake_remote_address_change_observed(
8439+
&mut self,
8440+
event: builder::HandshakeRemoteAddressChangeObserved,
8441+
);
83518442
#[doc = "Publishes a `ConnectionIdUpdated` event to the publisher's subscriber"]
83528443
fn on_connection_id_updated(&mut self, event: builder::ConnectionIdUpdated);
83538444
#[doc = "Publishes a `EcnStateChanged` event to the publisher's subscriber"]
@@ -8665,6 +8756,21 @@ mod traits {
86658756
self.subscriber.on_event(&self.meta, &event);
86668757
}
86678758
#[inline]
8759+
fn on_handshake_remote_address_change_observed(
8760+
&mut self,
8761+
event: builder::HandshakeRemoteAddressChangeObserved,
8762+
) {
8763+
let event = event.into_event();
8764+
self.subscriber.on_handshake_remote_address_change_observed(
8765+
self.context,
8766+
&self.meta,
8767+
&event,
8768+
);
8769+
self.subscriber
8770+
.on_connection_event(self.context, &self.meta, &event);
8771+
self.subscriber.on_event(&self.meta, &event);
8772+
}
8773+
#[inline]
86688774
fn on_connection_id_updated(&mut self, event: builder::ConnectionIdUpdated) {
86698775
let event = event.into_event();
86708776
self.subscriber
@@ -9106,6 +9212,7 @@ pub mod testing {
91069212
pub datagram_sent: u64,
91079213
pub datagram_received: u64,
91089214
pub datagram_dropped: u64,
9215+
pub handshake_remote_address_change_observed: u64,
91099216
pub connection_id_updated: u64,
91109217
pub ecn_state_changed: u64,
91119218
pub connection_migration_denied: u64,
@@ -9196,6 +9303,7 @@ pub mod testing {
91969303
datagram_sent: 0,
91979304
datagram_received: 0,
91989305
datagram_dropped: 0,
9306+
handshake_remote_address_change_observed: 0,
91999307
connection_id_updated: 0,
92009308
ecn_state_changed: 0,
92019309
connection_migration_denied: 0,
@@ -9605,6 +9713,20 @@ pub mod testing {
96059713
self.output.push(out);
96069714
}
96079715
}
9716+
fn on_handshake_remote_address_change_observed(
9717+
&mut self,
9718+
_context: &mut Self::ConnectionContext,
9719+
meta: &api::ConnectionMeta,
9720+
event: &api::HandshakeRemoteAddressChangeObserved,
9721+
) {
9722+
self.handshake_remote_address_change_observed += 1;
9723+
if self.location.is_some() {
9724+
let meta = crate::event::snapshot::Fmt::to_snapshot(meta);
9725+
let event = crate::event::snapshot::Fmt::to_snapshot(event);
9726+
let out = format!("{meta:?} {event:?}");
9727+
self.output.push(out);
9728+
}
9729+
}
96089730
fn on_connection_id_updated(
96099731
&mut self,
96109732
_context: &mut Self::ConnectionContext,
@@ -10037,6 +10159,7 @@ pub mod testing {
1003710159
pub datagram_sent: u64,
1003810160
pub datagram_received: u64,
1003910161
pub datagram_dropped: u64,
10162+
pub handshake_remote_address_change_observed: u64,
1004010163
pub connection_id_updated: u64,
1004110164
pub ecn_state_changed: u64,
1004210165
pub connection_migration_denied: u64,
@@ -10117,6 +10240,7 @@ pub mod testing {
1011710240
datagram_sent: 0,
1011810241
datagram_received: 0,
1011910242
datagram_dropped: 0,
10243+
handshake_remote_address_change_observed: 0,
1012010244
connection_id_updated: 0,
1012110245
ecn_state_changed: 0,
1012210246
connection_migration_denied: 0,
@@ -10511,6 +10635,18 @@ pub mod testing {
1051110635
self.output.push(out);
1051210636
}
1051310637
}
10638+
fn on_handshake_remote_address_change_observed(
10639+
&mut self,
10640+
event: builder::HandshakeRemoteAddressChangeObserved,
10641+
) {
10642+
self.handshake_remote_address_change_observed += 1;
10643+
let event = event.into_event();
10644+
if self.location.is_some() {
10645+
let event = crate::event::snapshot::Fmt::to_snapshot(&event);
10646+
let out = format!("{event:?}");
10647+
self.output.push(out);
10648+
}
10649+
}
1051410650
fn on_connection_id_updated(&mut self, event: builder::ConnectionIdUpdated) {
1051510651
self.connection_id_updated += 1;
1051610652
let event = event.into_event();

quic/s2n-quic-core/src/event/generated/metrics.rs

+20
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub struct Context<R: Recorder> {
5252
datagram_sent: u64,
5353
datagram_received: u64,
5454
datagram_dropped: u64,
55+
handshake_remote_address_change_observed: u64,
5556
connection_id_updated: u64,
5657
ecn_state_changed: u64,
5758
connection_migration_denied: u64,
@@ -109,6 +110,7 @@ where
109110
datagram_sent: 0,
110111
datagram_received: 0,
111112
datagram_dropped: 0,
113+
handshake_remote_address_change_observed: 0,
112114
connection_id_updated: 0,
113115
ecn_state_changed: 0,
114116
connection_migration_denied: 0,
@@ -417,6 +419,20 @@ where
417419
.on_datagram_dropped(&mut context.recorder, meta, event);
418420
}
419421
#[inline]
422+
fn on_handshake_remote_address_change_observed(
423+
&mut self,
424+
context: &mut Self::ConnectionContext,
425+
meta: &api::ConnectionMeta,
426+
event: &api::HandshakeRemoteAddressChangeObserved,
427+
) {
428+
context.handshake_remote_address_change_observed += 1;
429+
self.subscriber.on_handshake_remote_address_change_observed(
430+
&mut context.recorder,
431+
meta,
432+
event,
433+
);
434+
}
435+
#[inline]
420436
fn on_connection_id_updated(
421437
&mut self,
422438
context: &mut Self::ConnectionContext,
@@ -675,6 +691,10 @@ impl<R: Recorder> Drop for Context<R> {
675691
.increment_counter("datagram_received", self.datagram_received as _);
676692
self.recorder
677693
.increment_counter("datagram_dropped", self.datagram_dropped as _);
694+
self.recorder.increment_counter(
695+
"handshake_remote_address_change_observed",
696+
self.handshake_remote_address_change_observed as _,
697+
);
678698
self.recorder
679699
.increment_counter("connection_id_updated", self.connection_id_updated as _);
680700
self.recorder

0 commit comments

Comments
 (0)