Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TOS and TTL information to Datagrams #1568

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 11 additions & 3 deletions neqo-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(clippy::use_self)]

use common::IpTos;
use qlog::{events::EventImportance, streamer::QlogStreamer};

use mio::{net::UdpSocket, Events, Poll, PollOpt, Ready, Token};
Expand Down Expand Up @@ -430,7 +431,8 @@ fn process_loop(
break 'read;
}
if sz > 0 {
let d = Datagram::new(remote, *local_addr, &buf[..sz]);
let d =
Datagram::new(remote, *local_addr, IpTos::default(), None, &buf[..sz]);
datagrams.push(d);
}
}
Expand Down Expand Up @@ -1142,7 +1144,7 @@ mod old {

use super::{qlog_new, KeyUpdateState, Res};
use mio::{Events, Poll};
use neqo_common::{event::Provider, Datagram};
use neqo_common::{event::Provider, Datagram, IpTos};
use neqo_crypto::{AuthenticationStatus, ResumptionToken};
use neqo_transport::{
Connection, ConnectionEvent, EmptyConnectionIdGenerator, Error, Output, State, StreamId,
Expand Down Expand Up @@ -1367,7 +1369,13 @@ mod old {
break 'read;
}
if sz > 0 {
let d = Datagram::new(remote, *local_addr, &buf[..sz]);
let d = Datagram::new(
remote,
*local_addr,
IpTos::default(),
None,
&buf[..sz],
);
client.process_input(&d, Instant::now());
handler.maybe_key_update(client)?;
}
Expand Down
1 change: 1 addition & 0 deletions neqo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build = "build.rs"

[dependencies]
log = { version = "0.4.0", default-features = false }
enum-map = "~2.7.3"
env_logger = { version = "0.10", default-features = false }
lazy_static = "1.3.0"
qlog = "0.11.0"
Expand Down
43 changes: 39 additions & 4 deletions neqo-common/src/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@
use std::net::SocketAddr;
use std::ops::Deref;

use crate::hex_with_len;
use crate::{hex_with_len, IpTos};

#[derive(PartialEq, Eq, Clone)]
#[derive(Clone, PartialEq, Eq)]
pub struct Datagram {
src: SocketAddr,
dst: SocketAddr,
tos: IpTos,
ttl: Option<u8>,
d: Vec<u8>,
}

impl Datagram {
pub fn new<V: Into<Vec<u8>>>(src: SocketAddr, dst: SocketAddr, d: V) -> Self {
pub fn new<V: Into<Vec<u8>>>(
src: SocketAddr,
dst: SocketAddr,
tos: IpTos,
ttl: Option<u8>,
larseggert marked this conversation as resolved.
Show resolved Hide resolved
d: V,
) -> Self {
Self {
src,
dst,
tos,
ttl,
d: d.into(),
}
}
Expand All @@ -34,6 +44,16 @@ impl Datagram {
pub fn destination(&self) -> SocketAddr {
self.dst
}

#[must_use]
pub fn tos(&self) -> IpTos {
self.tos
}

#[must_use]
pub fn ttl(&self) -> Option<u8> {
self.ttl
}
}

impl Deref for Datagram {
Expand All @@ -48,10 +68,25 @@ impl std::fmt::Debug for Datagram {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"Datagram {:?}->{:?}: {}",
"Datagram {:?} TTL {:?} {:?}->{:?}: {}",
self.tos,
self.ttl,
self.src,
self.dst,
hex_with_len(&self.d)
)
}
}

#[cfg(test)]
use test_fixture::datagram;

#[test]
fn fmt_datagram() {
let d = datagram([0; 1].to_vec());
assert_eq!(
format!("{d:?}"),
"Datagram IpTos(Cs0, NotEct) TTL Some(128) [fe80::1]:443->[fe80::1]:443: [1]: 00"
.to_string()
);
}
2 changes: 2 additions & 0 deletions neqo-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ mod incrdecoder;
pub mod log;
pub mod qlog;
pub mod timer;
pub mod tos;

pub use self::codec::{Decoder, Encoder};
pub use self::datagram::Datagram;
pub use self::header::Header;
pub use self::incrdecoder::{
IncrementalDecoderBuffer, IncrementalDecoderIgnore, IncrementalDecoderUint,
};
pub use self::tos::{IpTos, IpTosDscp, IpTosEcn};

use std::fmt::Write;

Expand Down
Loading
Loading