Skip to content

Commit

Permalink
lib, qlog: Track and Log Unknown Transport Parameters
Browse files Browse the repository at this point in the history
Track (and make available to qlog for logging) transport parameters and
their values that this implementation does not specifically recognize.
  • Loading branch information
hawkinsw committed Oct 16, 2024
1 parent 9ea2152 commit 7e6b807
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
9 changes: 9 additions & 0 deletions qlog/src/events/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,15 @@ pub struct TransportParametersSet {
pub initial_max_streams_uni: Option<u64>,

pub preferred_address: Option<PreferredAddress>,

pub unknown_parameters: Vec<UnknownTransportParameter>,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct UnknownTransportParameter {
pub id: u64,
pub value: Vec<u8>,
}

#[serde_with::skip_serializing_none]
Expand Down
43 changes: 41 additions & 2 deletions quiche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7984,6 +7984,29 @@ impl std::fmt::Debug for Stats {
}
}

/// QUIC Unknown Transport Parameters
///
/// QUIC transport parameters that are not specifically recognized
/// by this implementation.
#[derive(Clone, Debug, PartialEq)]
pub struct UnknownTransportParameter {
/// ID of an unknown transport parameter
pub id: u64,
/// Original data representing the value of an unknown transport parameter
pub value: Vec<u8>,
}

impl From<UnknownTransportParameter>
for qlog::events::quic::UnknownTransportParameter
{
fn from(value: UnknownTransportParameter) -> Self {
Self {
id: value.id,
value: value.value,
}
}
}

/// QUIC Transport Parameters
#[derive(Clone, Debug, PartialEq)]
pub struct TransportParams {
Expand Down Expand Up @@ -8023,6 +8046,8 @@ pub struct TransportParams {
pub retry_source_connection_id: Option<ConnectionId<'static>>,
/// DATAGRAM frame extension parameter, if any.
pub max_datagram_frame_size: Option<u64>,
/// Unknown peer transport parameters and values, if any.
pub unknown_params: Vec<UnknownTransportParameter>,
// pub preferred_address: ...,
}

Expand All @@ -8046,6 +8071,7 @@ impl Default for TransportParams {
initial_source_connection_id: None,
retry_source_connection_id: None,
max_datagram_frame_size: None,
unknown_params: vec![],
}
}
}
Expand Down Expand Up @@ -8196,8 +8222,13 @@ impl TransportParams {
tp.max_datagram_frame_size = Some(val.get_varint()?);
},

// Ignore unknown parameters.
_ => (),
// Track unknown transport parameters specially.
unknown_tp_id => {
tp.unknown_params.push(UnknownTransportParameter {
id: unknown_tp_id,
value: val.to_vec(),
});
},
}
}

Expand Down Expand Up @@ -8410,6 +8441,12 @@ impl TransportParams {
initial_max_streams_uni: Some(self.initial_max_streams_uni),

preferred_address: None,

unknown_parameters: self.unknown_params
.iter()
.cloned()
.map(Into::<qlog::events::quic::UnknownTransportParameter>::into)
.collect(),
},
)
}
Expand Down Expand Up @@ -8952,6 +8989,7 @@ mod tests {
initial_source_connection_id: Some(b"woot woot".to_vec().into()),
retry_source_connection_id: Some(b"retry".to_vec().into()),
max_datagram_frame_size: Some(32),
unknown_params: vec![],
};

let mut raw_params = [42; 256];
Expand Down Expand Up @@ -8982,6 +9020,7 @@ mod tests {
initial_source_connection_id: Some(b"woot woot".to_vec().into()),
retry_source_connection_id: None,
max_datagram_frame_size: Some(32),
unknown_params: vec![],
};

let mut raw_params = [42; 256];
Expand Down

0 comments on commit 7e6b807

Please sign in to comment.