Skip to content

Commit 744884d

Browse files
feat(dc): Tweak eviction on unknown path secret arrival (#3157)
1 parent 315121b commit 744884d

7 files changed

Lines changed: 534 additions & 23 deletions

File tree

dc/s2n-quic-dc/events/map.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ struct PathSecretMapEntryReplaced<'a> {
6666

6767
#[snapshot("[HIDDEN]")]
6868
previous_credential_id: &'a [u8],
69+
70+
/// Time since insertion of the replaced entry
71+
#[measure("replaced_age", Duration)]
72+
replaced_age: core::time::Duration,
73+
}
74+
75+
#[derive(Debug, Copy, Clone)]
76+
enum EvictionReason {
77+
/// Capacity of map exceeded.
78+
Capacity,
79+
/// UnknownPathSecret received, removing entry.
80+
UnknownPathSecret,
81+
/// A newer entry is replacing this one, so we're retiring these.
82+
Retiring,
6983
}
7084

7185
#[event("path_secret_map:id_entry_evicted")]
@@ -80,7 +94,14 @@ struct PathSecretMapIdEntryEvicted<'a> {
8094

8195
/// Time since insertion of this entry
8296
#[measure("age", Duration)]
97+
#[snapshot("[HIDDEN]")]
8398
age: core::time::Duration,
99+
100+
#[measure("time_since_last_accessed", Duration)]
101+
time_since_last_accessed: core::time::Duration,
102+
103+
#[nominal_counter("reason")]
104+
reason: EvictionReason,
84105
}
85106

86107
#[event("path_secret_map:addr_entry_evicted")]
@@ -96,6 +117,12 @@ struct PathSecretMapAddressEntryEvicted<'a> {
96117
/// Time since insertion of this entry
97118
#[measure("age", Duration)]
98119
age: core::time::Duration,
120+
121+
#[measure("time_since_last_accessed", Duration)]
122+
time_since_last_accessed: core::time::Duration,
123+
124+
#[nominal_counter("reason")]
125+
reason: EvictionReason,
99126
}
100127

101128
#[event("path_secret_map:unknown_path_secret_packet_sent")]
@@ -129,6 +156,17 @@ struct UnknownPathSecretPacketAccepted<'a> {
129156

130157
#[snapshot("[HIDDEN]")]
131158
credential_id: &'a [u8],
159+
160+
/// The age of the entry the peer indicated it doesn't know about.
161+
#[measure("age", Duration)]
162+
#[snapshot("[HIDDEN]")]
163+
age: core::time::Duration,
164+
165+
#[bool_counter("evicted")]
166+
evicted: bool,
167+
168+
#[bool_counter("scheduled_handshake")]
169+
scheduled_handshake: bool,
132170
}
133171

134172
#[event("path_secret_map:unknown_path_secret_packet_rejected")]

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

Lines changed: 126 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,8 @@ pub mod api {
19611961
pub peer_address: SocketAddress<'a>,
19621962
pub new_credential_id: &'a [u8],
19631963
pub previous_credential_id: &'a [u8],
1964+
/// Time since insertion of the replaced entry
1965+
pub replaced_age: core::time::Duration,
19641966
}
19651967
#[cfg(any(test, feature = "testing"))]
19661968
impl<'a> crate::event::snapshot::Fmt for PathSecretMapEntryReplaced<'a> {
@@ -1969,6 +1971,7 @@ pub mod api {
19691971
fmt.field("peer_address", &self.peer_address);
19701972
fmt.field("new_credential_id", &"[HIDDEN]");
19711973
fmt.field("previous_credential_id", &"[HIDDEN]");
1974+
fmt.field("replaced_age", &self.replaced_age);
19721975
fmt.finish()
19731976
}
19741977
}
@@ -1983,14 +1986,18 @@ pub mod api {
19831986
pub credential_id: &'a [u8],
19841987
/// Time since insertion of this entry
19851988
pub age: core::time::Duration,
1989+
pub time_since_last_accessed: core::time::Duration,
1990+
pub reason: EvictionReason,
19861991
}
19871992
#[cfg(any(test, feature = "testing"))]
19881993
impl<'a> crate::event::snapshot::Fmt for PathSecretMapIdEntryEvicted<'a> {
19891994
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
19901995
let mut fmt = fmt.debug_struct("PathSecretMapIdEntryEvicted");
19911996
fmt.field("peer_address", &self.peer_address);
19921997
fmt.field("credential_id", &"[HIDDEN]");
1993-
fmt.field("age", &self.age);
1998+
fmt.field("age", &"[HIDDEN]");
1999+
fmt.field("time_since_last_accessed", &self.time_since_last_accessed);
2000+
fmt.field("reason", &self.reason);
19942001
fmt.finish()
19952002
}
19962003
}
@@ -2005,6 +2012,8 @@ pub mod api {
20052012
pub credential_id: &'a [u8],
20062013
/// Time since insertion of this entry
20072014
pub age: core::time::Duration,
2015+
pub time_since_last_accessed: core::time::Duration,
2016+
pub reason: EvictionReason,
20082017
}
20092018
#[cfg(any(test, feature = "testing"))]
20102019
impl<'a> crate::event::snapshot::Fmt for PathSecretMapAddressEntryEvicted<'a> {
@@ -2013,6 +2022,8 @@ pub mod api {
20132022
fmt.field("peer_address", &self.peer_address);
20142023
fmt.field("credential_id", &"[HIDDEN]");
20152024
fmt.field("age", &self.age);
2025+
fmt.field("time_since_last_accessed", &self.time_since_last_accessed);
2026+
fmt.field("reason", &self.reason);
20162027
fmt.finish()
20172028
}
20182029
}
@@ -2063,13 +2074,20 @@ pub mod api {
20632074
pub struct UnknownPathSecretPacketAccepted<'a> {
20642075
pub peer_address: SocketAddress<'a>,
20652076
pub credential_id: &'a [u8],
2077+
/// The age of the entry the peer indicated it doesn't know about.
2078+
pub age: core::time::Duration,
2079+
pub evicted: bool,
2080+
pub scheduled_handshake: bool,
20662081
}
20672082
#[cfg(any(test, feature = "testing"))]
20682083
impl<'a> crate::event::snapshot::Fmt for UnknownPathSecretPacketAccepted<'a> {
20692084
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
20702085
let mut fmt = fmt.debug_struct("UnknownPathSecretPacketAccepted");
20712086
fmt.field("peer_address", &self.peer_address);
20722087
fmt.field("credential_id", &"[HIDDEN]");
2088+
fmt.field("age", &"[HIDDEN]");
2089+
fmt.field("evicted", &self.evicted);
2090+
fmt.field("scheduled_handshake", &self.scheduled_handshake);
20732091
fmt.finish()
20742092
}
20752093
}
@@ -2659,6 +2677,46 @@ pub mod api {
26592677
impl Event for PathSecretMapDatagramDecrypt {
26602678
const NAME: &'static str = "path_secret_map:datagram_decrypt";
26612679
}
2680+
#[non_exhaustive]
2681+
#[derive(Debug, Copy, Clone)]
2682+
pub enum EvictionReason {
2683+
#[non_exhaustive]
2684+
/// Capacity of map exceeded.
2685+
Capacity {},
2686+
#[non_exhaustive]
2687+
/// UnknownPathSecret received, removing entry.
2688+
UnknownPathSecret {},
2689+
#[non_exhaustive]
2690+
/// A newer entry is replacing this one, so we're retiring these.
2691+
Retiring {},
2692+
}
2693+
impl aggregate::AsVariant for EvictionReason {
2694+
const VARIANTS: &'static [aggregate::info::Variant] = &[
2695+
aggregate::info::variant::Builder {
2696+
name: aggregate::info::Str::new("CAPACITY\0"),
2697+
id: 0usize,
2698+
}
2699+
.build(),
2700+
aggregate::info::variant::Builder {
2701+
name: aggregate::info::Str::new("UNKNOWN_PATH_SECRET\0"),
2702+
id: 1usize,
2703+
}
2704+
.build(),
2705+
aggregate::info::variant::Builder {
2706+
name: aggregate::info::Str::new("RETIRING\0"),
2707+
id: 2usize,
2708+
}
2709+
.build(),
2710+
];
2711+
#[inline]
2712+
fn variant_idx(&self) -> usize {
2713+
match self {
2714+
Self::Capacity { .. } => 0usize,
2715+
Self::UnknownPathSecret { .. } => 1usize,
2716+
Self::Retiring { .. } => 2usize,
2717+
}
2718+
}
2719+
}
26622720
impl IntoEvent<builder::AcceptorPacketDropReason> for s2n_codec::DecoderError {
26632721
fn into_event(self) -> builder::AcceptorPacketDropReason {
26642722
use builder::AcceptorPacketDropReason as Reason;
@@ -3992,13 +4050,15 @@ pub mod tracing {
39924050
peer_address,
39934051
new_credential_id,
39944052
previous_credential_id,
4053+
replaced_age,
39954054
} = event;
39964055
tracing::event!(
39974056
target : "path_secret_map_entry_replaced", parent : parent,
39984057
tracing::Level::DEBUG, { peer_address =
39994058
tracing::field::debug(peer_address), new_credential_id =
40004059
tracing::field::debug(new_credential_id), previous_credential_id =
4001-
tracing::field::debug(previous_credential_id) }
4060+
tracing::field::debug(previous_credential_id), replaced_age =
4061+
tracing::field::debug(replaced_age) }
40024062
);
40034063
}
40044064
#[inline]
@@ -4012,12 +4072,17 @@ pub mod tracing {
40124072
peer_address,
40134073
credential_id,
40144074
age,
4075+
time_since_last_accessed,
4076+
reason,
40154077
} = event;
40164078
tracing::event!(
40174079
target : "path_secret_map_id_entry_evicted", parent : parent,
40184080
tracing::Level::DEBUG, { peer_address =
40194081
tracing::field::debug(peer_address), credential_id =
4020-
tracing::field::debug(credential_id), age = tracing::field::debug(age) }
4082+
tracing::field::debug(credential_id), age = tracing::field::debug(age),
4083+
time_since_last_accessed =
4084+
tracing::field::debug(time_since_last_accessed), reason =
4085+
tracing::field::debug(reason) }
40214086
);
40224087
}
40234088
#[inline]
@@ -4031,12 +4096,17 @@ pub mod tracing {
40314096
peer_address,
40324097
credential_id,
40334098
age,
4099+
time_since_last_accessed,
4100+
reason,
40344101
} = event;
40354102
tracing::event!(
40364103
target : "path_secret_map_address_entry_evicted", parent : parent,
40374104
tracing::Level::DEBUG, { peer_address =
40384105
tracing::field::debug(peer_address), credential_id =
4039-
tracing::field::debug(credential_id), age = tracing::field::debug(age) }
4106+
tracing::field::debug(credential_id), age = tracing::field::debug(age),
4107+
time_since_last_accessed =
4108+
tracing::field::debug(time_since_last_accessed), reason =
4109+
tracing::field::debug(reason) }
40404110
);
40414111
}
40424112
#[inline]
@@ -4085,12 +4155,17 @@ pub mod tracing {
40854155
let api::UnknownPathSecretPacketAccepted {
40864156
peer_address,
40874157
credential_id,
4158+
age,
4159+
evicted,
4160+
scheduled_handshake,
40884161
} = event;
40894162
tracing::event!(
40904163
target : "unknown_path_secret_packet_accepted", parent : parent,
40914164
tracing::Level::DEBUG, { peer_address =
40924165
tracing::field::debug(peer_address), credential_id =
4093-
tracing::field::debug(credential_id) }
4166+
tracing::field::debug(credential_id), age = tracing::field::debug(age),
4167+
evicted = tracing::field::debug(evicted), scheduled_handshake =
4168+
tracing::field::debug(scheduled_handshake) }
40944169
);
40954170
}
40964171
#[inline]
@@ -6352,6 +6427,8 @@ pub mod builder {
63526427
pub peer_address: SocketAddress<'a>,
63536428
pub new_credential_id: &'a [u8],
63546429
pub previous_credential_id: &'a [u8],
6430+
/// Time since insertion of the replaced entry
6431+
pub replaced_age: core::time::Duration,
63556432
}
63566433
impl<'a> IntoEvent<api::PathSecretMapEntryReplaced<'a>> for PathSecretMapEntryReplaced<'a> {
63576434
#[inline]
@@ -6360,11 +6437,13 @@ pub mod builder {
63606437
peer_address,
63616438
new_credential_id,
63626439
previous_credential_id,
6440+
replaced_age,
63636441
} = self;
63646442
api::PathSecretMapEntryReplaced {
63656443
peer_address: peer_address.into_event(),
63666444
new_credential_id: new_credential_id.into_event(),
63676445
previous_credential_id: previous_credential_id.into_event(),
6446+
replaced_age: replaced_age.into_event(),
63686447
}
63696448
}
63706449
}
@@ -6375,6 +6454,8 @@ pub mod builder {
63756454
pub credential_id: &'a [u8],
63766455
/// Time since insertion of this entry
63776456
pub age: core::time::Duration,
6457+
pub time_since_last_accessed: core::time::Duration,
6458+
pub reason: EvictionReason,
63786459
}
63796460
impl<'a> IntoEvent<api::PathSecretMapIdEntryEvicted<'a>> for PathSecretMapIdEntryEvicted<'a> {
63806461
#[inline]
@@ -6383,11 +6464,15 @@ pub mod builder {
63836464
peer_address,
63846465
credential_id,
63856466
age,
6467+
time_since_last_accessed,
6468+
reason,
63866469
} = self;
63876470
api::PathSecretMapIdEntryEvicted {
63886471
peer_address: peer_address.into_event(),
63896472
credential_id: credential_id.into_event(),
63906473
age: age.into_event(),
6474+
time_since_last_accessed: time_since_last_accessed.into_event(),
6475+
reason: reason.into_event(),
63916476
}
63926477
}
63936478
}
@@ -6398,6 +6483,8 @@ pub mod builder {
63986483
pub credential_id: &'a [u8],
63996484
/// Time since insertion of this entry
64006485
pub age: core::time::Duration,
6486+
pub time_since_last_accessed: core::time::Duration,
6487+
pub reason: EvictionReason,
64016488
}
64026489
impl<'a> IntoEvent<api::PathSecretMapAddressEntryEvicted<'a>>
64036490
for PathSecretMapAddressEntryEvicted<'a>
@@ -6408,11 +6495,15 @@ pub mod builder {
64086495
peer_address,
64096496
credential_id,
64106497
age,
6498+
time_since_last_accessed,
6499+
reason,
64116500
} = self;
64126501
api::PathSecretMapAddressEntryEvicted {
64136502
peer_address: peer_address.into_event(),
64146503
credential_id: credential_id.into_event(),
64156504
age: age.into_event(),
6505+
time_since_last_accessed: time_since_last_accessed.into_event(),
6506+
reason: reason.into_event(),
64166507
}
64176508
}
64186509
}
@@ -6461,6 +6552,10 @@ pub mod builder {
64616552
pub struct UnknownPathSecretPacketAccepted<'a> {
64626553
pub peer_address: SocketAddress<'a>,
64636554
pub credential_id: &'a [u8],
6555+
/// The age of the entry the peer indicated it doesn't know about.
6556+
pub age: core::time::Duration,
6557+
pub evicted: bool,
6558+
pub scheduled_handshake: bool,
64646559
}
64656560
impl<'a> IntoEvent<api::UnknownPathSecretPacketAccepted<'a>>
64666561
for UnknownPathSecretPacketAccepted<'a>
@@ -6470,10 +6565,16 @@ pub mod builder {
64706565
let UnknownPathSecretPacketAccepted {
64716566
peer_address,
64726567
credential_id,
6568+
age,
6569+
evicted,
6570+
scheduled_handshake,
64736571
} = self;
64746572
api::UnknownPathSecretPacketAccepted {
64756573
peer_address: peer_address.into_event(),
64766574
credential_id: credential_id.into_event(),
6575+
age: age.into_event(),
6576+
evicted: evicted.into_event(),
6577+
scheduled_handshake: scheduled_handshake.into_event(),
64776578
}
64786579
}
64796580
}
@@ -7044,6 +7145,26 @@ pub mod builder {
70447145
}
70457146
}
70467147
}
7148+
#[derive(Clone, Debug)]
7149+
pub enum EvictionReason {
7150+
/// Capacity of map exceeded.
7151+
Capacity,
7152+
/// UnknownPathSecret received, removing entry.
7153+
UnknownPathSecret,
7154+
/// A newer entry is replacing this one, so we're retiring these.
7155+
Retiring,
7156+
}
7157+
impl IntoEvent<api::EvictionReason> for EvictionReason {
7158+
#[inline]
7159+
fn into_event(self) -> api::EvictionReason {
7160+
use api::EvictionReason::*;
7161+
match self {
7162+
Self::Capacity => Capacity {},
7163+
Self::UnknownPathSecret => UnknownPathSecret {},
7164+
Self::Retiring => Retiring {},
7165+
}
7166+
}
7167+
}
70477168
}
70487169
pub use traits::*;
70497170
mod traits {

0 commit comments

Comments
 (0)