feat(proto): validate negotiated datagram budgets
PLAN.md keeps MVP traffic to one Ethernet frame per QUIC datagram with no fragmentation. The relay already negotiates a datagram budget, but the client and gateway send paths still relied on Quinn to reject oversized encoded Ethernet datagrams. Add a shared protocol validation helper for encoded datagram length versus the negotiated QUIC budget. Thread the negotiated budget into client and gateway send boundaries, reject oversized datagrams before send, and count those valid but unsent frames as local drops. Document the budget check in the workspace decomposition and gateway behavior. Test Plan: - cargo fmt --check - cargo test -p lanparty-proto -p lanparty-client-core -p lanparty-gateway - cargo test --workspace - cargo clippy --workspace --all-targets -- -D warnings - git diff --check Refs: PLAN.md
This commit is contained in:
@@ -26,7 +26,9 @@ use lanparty_ctrl::{
|
||||
encode_control_message,
|
||||
};
|
||||
use lanparty_obs::{QuicDiagnostics, TunnelStats};
|
||||
use lanparty_proto::{EthernetFrame, FrameType, MacAddr, decode_datagram, encode_datagram};
|
||||
use lanparty_proto::{
|
||||
EthernetFrame, FrameType, MacAddr, decode_datagram, encode_datagram, validate_datagram_budget,
|
||||
};
|
||||
use quinn::{ClientConfig, Endpoint, crypto::rustls::QuicClientConfig};
|
||||
use rustls::pki_types::CertificateDer;
|
||||
|
||||
@@ -266,6 +268,7 @@ impl ClientSession {
|
||||
ClientRelayIo::new(
|
||||
self.connection.clone(),
|
||||
self.welcome.clone(),
|
||||
self.quic_max_datagram_size,
|
||||
Arc::clone(&self.stats),
|
||||
)
|
||||
}
|
||||
@@ -305,6 +308,7 @@ impl ClientSession {
|
||||
pub struct ClientRelayIo {
|
||||
connection: quinn::Connection,
|
||||
welcome: ServerWelcome,
|
||||
quic_max_datagram_size: u16,
|
||||
stats: Arc<ClientTunnelStats>,
|
||||
}
|
||||
|
||||
@@ -313,11 +317,13 @@ impl ClientRelayIo {
|
||||
fn new(
|
||||
connection: quinn::Connection,
|
||||
welcome: ServerWelcome,
|
||||
quic_max_datagram_size: u16,
|
||||
stats: Arc<ClientTunnelStats>,
|
||||
) -> Self {
|
||||
Self {
|
||||
connection,
|
||||
welcome,
|
||||
quic_max_datagram_size,
|
||||
stats,
|
||||
}
|
||||
}
|
||||
@@ -327,6 +333,11 @@ impl ClientRelayIo {
|
||||
&self.welcome
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn quic_max_datagram_size(&self) -> u16 {
|
||||
self.quic_max_datagram_size
|
||||
}
|
||||
|
||||
pub fn send_ethernet(&self, frame: &[u8]) -> Result<()> {
|
||||
let ethernet_frame = match EthernetFrame::parse(frame) {
|
||||
Ok(frame) => frame,
|
||||
@@ -343,6 +354,12 @@ impl ClientRelayIo {
|
||||
frame,
|
||||
)
|
||||
.context("failed to encode client Ethernet datagram")?;
|
||||
if let Err(error) =
|
||||
validate_datagram_budget(datagram.len(), usize::from(self.quic_max_datagram_size))
|
||||
{
|
||||
self.stats.record_dropped_frame();
|
||||
return Err(error).context("client Ethernet datagram exceeds negotiated QUIC budget");
|
||||
}
|
||||
|
||||
self.connection
|
||||
.send_datagram(Bytes::from(datagram))
|
||||
@@ -799,6 +816,10 @@ mod tests {
|
||||
);
|
||||
let relay_io = client.relay_io();
|
||||
assert_eq!(relay_io.welcome().peer_id(), 2);
|
||||
assert_eq!(
|
||||
relay_io.quic_max_datagram_size(),
|
||||
client.quic_max_datagram_size()
|
||||
);
|
||||
|
||||
relay_io
|
||||
.send_ethernet(ðernet_frame(b"to relay"))
|
||||
|
||||
Reference in New Issue
Block a user