Emit exceptional events with the DEBUG log level, not TRACE.

This commit is contained in:
whitequark 2017-08-01 11:21:58 +00:00
parent db5ecb353a
commit e0d8fcfb72
4 changed files with 23 additions and 12 deletions

View File

@ -110,7 +110,9 @@ on `collections::vec::Vec`. This only works on nightly rustc.
### Feature `log`
The `log` feature enables logging of events within the networking stack through
the [log crate][log]. The events are emitted with the TRACE log level.
the [log crate][log]. Normal events (e.g. buffer level or TCP state changes) are emitted with
the TRACE log level. Exceptional events (e.g. malformed packets) are emitted with
the DEBUG log level.
[log]: https://crates.io/crates/log

View File

@ -81,7 +81,7 @@ extern crate alloc;
#[cfg(feature = "collections")]
extern crate collections;
#[cfg(any(test, feature = "log"))]
#[macro_use(trace, log, log_enabled)]
#[macro_use(log, log_enabled, trace, debug)]
extern crate log;
use core::fmt;

View File

@ -17,6 +17,15 @@ macro_rules! net_trace_enabled {
})
}
macro_rules! net_debug {
($($arg:expr),*) => {
#[cfg(feature = "log")]
debug!($($arg),*);
#[cfg(not(feature = "log"))]
$( let _ = $arg );*; // suppress unused variable warnings
}
}
macro_rules! enum_with_unknown {
(
$( #[$enum_attr:meta] )*

View File

@ -689,7 +689,7 @@ impl<'a> TcpSocket<'a> {
// The initial SYN (or whatever) cannot contain an acknowledgement.
// It may be destined to another socket though.
(State::Listen, TcpRepr { ack_number: Some(_), .. }) => {
net_trace!("[{}]{}:{}: unacceptable ACK in LISTEN state",
net_debug!("[{}]{}:{}: unacceptable ACK in LISTEN state",
self.debug_id, self.local_endpoint, self.remote_endpoint);
return Err(Error::Dropped)
}
@ -697,7 +697,7 @@ impl<'a> TcpSocket<'a> {
// An RST received in response to initial SYN is acceptable if it acknowledges
// the initial SYN.
(State::SynSent, TcpRepr { control: TcpControl::Rst, ack_number: None, .. }) => {
net_trace!("[{}]{}:{}: unacceptable RST (expecting RST|ACK) \
net_debug!("[{}]{}:{}: unacceptable RST (expecting RST|ACK) \
in response to initial SYN",
self.debug_id, self.local_endpoint, self.remote_endpoint);
return Err(Error::Malformed)
@ -706,7 +706,7 @@ impl<'a> TcpSocket<'a> {
control: TcpControl::Rst, ack_number: Some(ack_number), ..
}) => {
if ack_number != self.local_seq_no + 1 {
net_trace!("[{}]{}:{}: unacceptable RST|ACK in response to initial SYN",
net_debug!("[{}]{}:{}: unacceptable RST|ACK in response to initial SYN",
self.debug_id, self.local_endpoint, self.remote_endpoint);
return Err(Error::Malformed)
}
@ -715,7 +715,7 @@ impl<'a> TcpSocket<'a> {
(_, TcpRepr { control: TcpControl::Rst, .. }) => (),
// Every packet after the initial SYN must be an acknowledgement.
(_, TcpRepr { ack_number: None, .. }) => {
net_trace!("[{}]{}:{}: expecting an ACK",
net_debug!("[{}]{}:{}: expecting an ACK",
self.debug_id, self.local_endpoint, self.remote_endpoint);
return Err(Error::Malformed)
}
@ -723,7 +723,7 @@ impl<'a> TcpSocket<'a> {
(_, TcpRepr { ack_number: Some(ack_number), .. }) => {
let unacknowledged = self.tx_buffer.len() + control_len;
if ack_number < self.local_seq_no {
net_trace!("[{}]{}:{}: duplicate ACK ({} not in {}...{})",
net_debug!("[{}]{}:{}: duplicate ACK ({} not in {}...{})",
self.debug_id, self.local_endpoint, self.remote_endpoint,
ack_number, self.local_seq_no, self.local_seq_no + unacknowledged);
// FIXME: instead of waiting for the retransmit timer to kick in,
@ -731,7 +731,7 @@ impl<'a> TcpSocket<'a> {
return Err(Error::Dropped)
}
if ack_number > self.local_seq_no + unacknowledged {
net_trace!("[{}]{}:{}: unacceptable ACK ({} not in {}...{})",
net_debug!("[{}]{}:{}: unacceptable ACK ({} not in {}...{})",
self.debug_id, self.local_endpoint, self.remote_endpoint,
ack_number, self.local_seq_no, self.local_seq_no + unacknowledged);
return Err(Error::Dropped)
@ -749,7 +749,7 @@ impl<'a> TcpSocket<'a> {
let next_remote_seq = self.remote_seq_no + self.rx_buffer.len();
let mut send_ack_again = false;
if seq_number > next_remote_seq {
net_trace!("[{}]{}:{}: unacceptable SEQ ({} not in {}..), \
net_debug!("[{}]{}:{}: unacceptable SEQ ({} not in {}..), \
will send duplicate ACK",
self.debug_id, self.local_endpoint, self.remote_endpoint,
seq_number, next_remote_seq);
@ -761,7 +761,7 @@ impl<'a> TcpSocket<'a> {
// retransmission.
send_ack_again = true;
} else if seq_number != next_remote_seq {
net_trace!("[{}]{}:{}: duplicate SEQ ({} in ..{}), \
net_debug!("[{}]{}:{}: duplicate SEQ ({} in ..{}), \
will re-send ACK",
self.debug_id, self.local_endpoint, self.remote_endpoint,
seq_number, next_remote_seq);
@ -951,7 +951,7 @@ impl<'a> TcpSocket<'a> {
}
_ => {
net_trace!("[{}]{}:{}: unexpected packet {}",
net_debug!("[{}]{}:{}: unexpected packet {}",
self.debug_id, self.local_endpoint, self.remote_endpoint, repr);
return Err(Error::Malformed)
}
@ -1134,7 +1134,7 @@ impl<'a> TcpSocket<'a> {
if should_send {
if let Some(actual_delay) = self.retransmit.commit(timestamp) {
net_trace!("[{}]{}:{}: retransmitting at t+{}ms ",
net_debug!("[{}]{}:{}: retransmitting at t+{}ms ",
self.debug_id, self.local_endpoint, self.remote_endpoint,
actual_delay);
}