2021-10-30 23:51:23 +08:00
|
|
|
#[cfg(not(test))]
|
Radically simplify and optimize TCP packet dispatch.
This commit completely reworks packet dispatch in TCP sockets,
and brings significant improvements to processing as well.
In particular:
* Challenge ACKs now do not reset retransmit timer; instead,
TcpSocket::process directly returns a TcpRepr without altering
any internal state at all.
* Retransmit and close (aka TIME-WAIT) timers are unified
and restructured into a enum that actually matches semantics
of the timers.
* If a packet cannot be emitted, no internal state is changed.
* The dispatch of RST packets in case of connection abort
is brought in line with dispatch of all other packets.
* Packet dispatch now follows a series of steps with clean
separation of concerns, like packet processing:
1. If we should retransmit, update state to assume that
all in-flight packets are lost.
2. Prepare the packet that would be sent next, considering
the in-flight packets, if any.
3. Check if the packet contains anything new, or it's the same
as the one already in flight. If it is, bail.
4. Finalize and try to actually transmit the packet.
If we can't do that, bail.
5. Update the internal state to reflect that the packet
we've just sent is in flight.
2017-08-25 10:59:51 +08:00
|
|
|
#[cfg(feature = "log")]
|
2020-12-27 07:11:30 +08:00
|
|
|
macro_rules! net_log {
|
2021-08-19 18:07:56 +08:00
|
|
|
(trace, $($arg:expr),*) => { log::trace!($($arg),*) };
|
|
|
|
(debug, $($arg:expr),*) => { log::debug!($($arg),*) };
|
Radically simplify and optimize TCP packet dispatch.
This commit completely reworks packet dispatch in TCP sockets,
and brings significant improvements to processing as well.
In particular:
* Challenge ACKs now do not reset retransmit timer; instead,
TcpSocket::process directly returns a TcpRepr without altering
any internal state at all.
* Retransmit and close (aka TIME-WAIT) timers are unified
and restructured into a enum that actually matches semantics
of the timers.
* If a packet cannot be emitted, no internal state is changed.
* The dispatch of RST packets in case of connection abort
is brought in line with dispatch of all other packets.
* Packet dispatch now follows a series of steps with clean
separation of concerns, like packet processing:
1. If we should retransmit, update state to assume that
all in-flight packets are lost.
2. Prepare the packet that would be sent next, considering
the in-flight packets, if any.
3. Check if the packet contains anything new, or it's the same
as the one already in flight. If it is, bail.
4. Finalize and try to actually transmit the packet.
If we can't do that, bail.
5. Update the internal state to reflect that the packet
we've just sent is in flight.
2017-08-25 10:59:51 +08:00
|
|
|
}
|
|
|
|
|
2021-10-30 23:51:23 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg(feature = "log")]
|
|
|
|
macro_rules! net_log {
|
|
|
|
(trace, $($arg:expr),*) => { println!($($arg),*) };
|
|
|
|
(debug, $($arg:expr),*) => { println!($($arg),*) };
|
|
|
|
}
|
|
|
|
|
2021-04-01 07:30:47 +08:00
|
|
|
#[cfg(feature = "defmt")]
|
|
|
|
macro_rules! net_log {
|
2021-08-19 18:07:56 +08:00
|
|
|
(trace, $($arg:expr),*) => { defmt::trace!($($arg),*) };
|
|
|
|
(debug, $($arg:expr),*) => { defmt::debug!($($arg),*) };
|
2021-04-01 07:30:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(any(feature = "log", feature = "defmt")))]
|
2020-12-27 07:11:30 +08:00
|
|
|
macro_rules! net_log {
|
2021-06-09 17:36:28 +08:00
|
|
|
($level:ident, $($arg:expr),*) => {{ $( let _ = $arg; )* }}
|
Radically simplify and optimize TCP packet dispatch.
This commit completely reworks packet dispatch in TCP sockets,
and brings significant improvements to processing as well.
In particular:
* Challenge ACKs now do not reset retransmit timer; instead,
TcpSocket::process directly returns a TcpRepr without altering
any internal state at all.
* Retransmit and close (aka TIME-WAIT) timers are unified
and restructured into a enum that actually matches semantics
of the timers.
* If a packet cannot be emitted, no internal state is changed.
* The dispatch of RST packets in case of connection abort
is brought in line with dispatch of all other packets.
* Packet dispatch now follows a series of steps with clean
separation of concerns, like packet processing:
1. If we should retransmit, update state to assume that
all in-flight packets are lost.
2. Prepare the packet that would be sent next, considering
the in-flight packets, if any.
3. Check if the packet contains anything new, or it's the same
as the one already in flight. If it is, bail.
4. Finalize and try to actually transmit the packet.
If we can't do that, bail.
5. Update the internal state to reflect that the packet
we've just sent is in flight.
2017-08-25 10:59:51 +08:00
|
|
|
}
|
|
|
|
|
2017-07-23 15:54:36 +08:00
|
|
|
macro_rules! net_trace {
|
2017-10-05 11:02:41 +08:00
|
|
|
($($arg:expr),*) => (net_log!(trace, $($arg),*));
|
2017-07-23 15:54:36 +08:00
|
|
|
}
|
|
|
|
|
2017-08-01 19:21:58 +08:00
|
|
|
macro_rules! net_debug {
|
2017-10-05 11:02:41 +08:00
|
|
|
($($arg:expr),*) => (net_log!(debug, $($arg),*));
|
2017-08-01 19:21:58 +08:00
|
|
|
}
|
|
|
|
|
2017-07-23 15:54:36 +08:00
|
|
|
macro_rules! enum_with_unknown {
|
|
|
|
(
|
|
|
|
$( #[$enum_attr:meta] )*
|
|
|
|
pub enum $name:ident($ty:ty) {
|
|
|
|
$(
|
2021-03-12 14:02:04 +08:00
|
|
|
$( #[$variant_attr:meta] )*
|
2021-03-25 07:06:15 +08:00
|
|
|
$variant:ident = $value:expr
|
|
|
|
),+ $(,)?
|
2017-07-23 15:54:36 +08:00
|
|
|
}
|
|
|
|
) => {
|
|
|
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
2021-04-01 07:30:47 +08:00
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
2017-07-23 15:54:36 +08:00
|
|
|
$( #[$enum_attr] )*
|
|
|
|
pub enum $name {
|
|
|
|
$(
|
|
|
|
$( #[$variant_attr] )*
|
|
|
|
$variant
|
|
|
|
),*,
|
|
|
|
Unknown($ty)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ::core::convert::From<$ty> for $name {
|
|
|
|
fn from(value: $ty) -> Self {
|
|
|
|
match value {
|
|
|
|
$( $value => $name::$variant ),*,
|
|
|
|
other => $name::Unknown(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ::core::convert::From<$name> for $ty {
|
|
|
|
fn from(value: $name) -> Self {
|
|
|
|
match value {
|
|
|
|
$( $name::$variant => $value ),*,
|
|
|
|
$name::Unknown(other) => other
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|