commit
29cc59c89d
|
@ -91,7 +91,7 @@ fn main() {
|
|||
let client = match socket.recv() {
|
||||
Ok((data, endpoint)) => {
|
||||
debug!("udp:6969 recv data: {:?} from {}",
|
||||
str::from_utf8(data.as_ref()).unwrap(), endpoint);
|
||||
str::from_utf8(data).unwrap(), endpoint);
|
||||
Some(endpoint)
|
||||
}
|
||||
Err(_) => None
|
||||
|
|
|
@ -288,22 +288,22 @@ enum Packet<'a> {
|
|||
|
||||
impl<'a> Packet<'a> {
|
||||
fn neighbor_addr(&self) -> Option<IpAddress> {
|
||||
match self {
|
||||
&Packet::None => None,
|
||||
match *self {
|
||||
Packet::None => None,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Packet::Arp(_) => None,
|
||||
Packet::Arp(_) => None,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Packet::Icmpv4((ref ipv4_repr, _)) => Some(ipv4_repr.dst_addr.into()),
|
||||
Packet::Icmpv4((ref ipv4_repr, _)) => Some(ipv4_repr.dst_addr.into()),
|
||||
#[cfg(feature = "proto-igmp")]
|
||||
&Packet::Igmp((ref ipv4_repr, _)) => Some(ipv4_repr.dst_addr.into()),
|
||||
Packet::Igmp((ref ipv4_repr, _)) => Some(ipv4_repr.dst_addr.into()),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Packet::Icmpv6((ref ipv6_repr, _)) => Some(ipv6_repr.dst_addr.into()),
|
||||
Packet::Icmpv6((ref ipv6_repr, _)) => Some(ipv6_repr.dst_addr.into()),
|
||||
#[cfg(feature = "socket-raw")]
|
||||
&Packet::Raw((ref ip_repr, _)) => Some(ip_repr.dst_addr()),
|
||||
Packet::Raw((ref ip_repr, _)) => Some(ip_repr.dst_addr()),
|
||||
#[cfg(feature = "socket-udp")]
|
||||
&Packet::Udp((ref ip_repr, _)) => Some(ip_repr.dst_addr()),
|
||||
Packet::Udp((ref ip_repr, _)) => Some(ip_repr.dst_addr()),
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
&Packet::Tcp((ref ip_repr, _)) => Some(ip_repr.dst_addr())
|
||||
Packet::Tcp((ref ip_repr, _)) => Some(ip_repr.dst_addr())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -723,7 +723,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
|
|||
pub fn has_solicited_node(&self, addr: Ipv6Address) -> bool {
|
||||
self.ip_addrs.iter().find(|cidr| {
|
||||
match *cidr {
|
||||
&IpCidr::Ipv6(cidr) if cidr.address() != Ipv6Address::LOOPBACK=> {
|
||||
IpCidr::Ipv6(cidr) if cidr.address() != Ipv6Address::LOOPBACK=> {
|
||||
// Take the lower order 24 bits of the IPv6 address and
|
||||
// append those bits to FF02:0:0:0:0:1:FF00::/104.
|
||||
addr.as_bytes()[14..] == cidr.address().as_bytes()[14..]
|
||||
|
@ -744,8 +744,8 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
|
|||
pub fn ipv4_address(&self) -> Option<Ipv4Address> {
|
||||
self.ip_addrs.iter()
|
||||
.filter_map(
|
||||
|addr| match addr {
|
||||
&IpCidr::Ipv4(cidr) => Some(cidr.address()),
|
||||
|addr| match *addr {
|
||||
IpCidr::Ipv4(cidr) => Some(cidr.address()),
|
||||
_ => None,
|
||||
})
|
||||
.next()
|
||||
|
@ -1510,7 +1510,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
|
|||
let tx_len = EthernetFrame::<&[u8]>::buffer_len(buffer_len);
|
||||
tx_token.consume(timestamp, tx_len, |tx_buffer| {
|
||||
debug_assert!(tx_buffer.as_ref().len() == tx_len);
|
||||
let mut frame = EthernetFrame::new_unchecked(tx_buffer.as_mut());
|
||||
let mut frame = EthernetFrame::new_unchecked(tx_buffer);
|
||||
frame.set_src_addr(self.ethernet_addr);
|
||||
|
||||
f(frame);
|
||||
|
@ -1558,24 +1558,24 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
|
|||
if dst_addr.is_multicast() {
|
||||
let b = dst_addr.as_bytes();
|
||||
let hardware_addr =
|
||||
match dst_addr {
|
||||
&IpAddress::Unspecified =>
|
||||
match *dst_addr {
|
||||
IpAddress::Unspecified =>
|
||||
None,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&IpAddress::Ipv4(_addr) =>
|
||||
IpAddress::Ipv4(_addr) =>
|
||||
Some(EthernetAddress::from_bytes(&[
|
||||
0x01, 0x00,
|
||||
0x5e, b[1] & 0x7F,
|
||||
b[2], b[3],
|
||||
])),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&IpAddress::Ipv6(_addr) =>
|
||||
IpAddress::Ipv6(_addr) =>
|
||||
Some(EthernetAddress::from_bytes(&[
|
||||
0x33, 0x33,
|
||||
b[12], b[13],
|
||||
b[14], b[15],
|
||||
])),
|
||||
&IpAddress::__Nonexhaustive =>
|
||||
IpAddress::__Nonexhaustive =>
|
||||
unreachable!()
|
||||
};
|
||||
match hardware_addr {
|
||||
|
|
24
src/lib.rs
24
src/lib.rs
|
@ -166,18 +166,18 @@ pub type Result<T> = core::result::Result<T, Error>;
|
|||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Error::Exhausted => write!(f, "buffer space exhausted"),
|
||||
&Error::Illegal => write!(f, "illegal operation"),
|
||||
&Error::Unaddressable => write!(f, "unaddressable destination"),
|
||||
&Error::Finished => write!(f, "operation finished"),
|
||||
&Error::Truncated => write!(f, "truncated packet"),
|
||||
&Error::Checksum => write!(f, "checksum error"),
|
||||
&Error::Unrecognized => write!(f, "unrecognized packet"),
|
||||
&Error::Fragmented => write!(f, "fragmented packet"),
|
||||
&Error::Malformed => write!(f, "malformed packet"),
|
||||
&Error::Dropped => write!(f, "dropped by socket"),
|
||||
&Error::__Nonexhaustive => unreachable!()
|
||||
match *self {
|
||||
Error::Exhausted => write!(f, "buffer space exhausted"),
|
||||
Error::Illegal => write!(f, "illegal operation"),
|
||||
Error::Unaddressable => write!(f, "unaddressable destination"),
|
||||
Error::Finished => write!(f, "operation finished"),
|
||||
Error::Truncated => write!(f, "truncated packet"),
|
||||
Error::Checksum => write!(f, "checksum error"),
|
||||
Error::Unrecognized => write!(f, "unrecognized packet"),
|
||||
Error::Fragmented => write!(f, "fragmented packet"),
|
||||
Error::Malformed => write!(f, "malformed packet"),
|
||||
Error::Dropped => write!(f, "dropped by socket"),
|
||||
Error::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -316,9 +316,9 @@ impl<'a, 'b> IcmpSocket<'a, 'b> {
|
|||
|
||||
pub(crate) fn process(&mut self, ip_repr: &IpRepr, icmp_repr: &IcmpRepr,
|
||||
_cksum: &ChecksumCapabilities) -> Result<()> {
|
||||
match icmp_repr {
|
||||
match *icmp_repr {
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&IcmpRepr::Ipv4(ref icmp_repr) => {
|
||||
IcmpRepr::Ipv4(ref icmp_repr) => {
|
||||
let packet_buf = self.rx_buffer.enqueue(icmp_repr.buffer_len(),
|
||||
ip_repr.src_addr())?;
|
||||
icmp_repr.emit(&mut Icmpv4Packet::new_unchecked(packet_buf),
|
||||
|
@ -328,7 +328,7 @@ impl<'a, 'b> IcmpSocket<'a, 'b> {
|
|||
self.meta.handle, icmp_repr.buffer_len(), packet_buf.len());
|
||||
},
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&IcmpRepr::Ipv6(ref icmp_repr) => {
|
||||
IcmpRepr::Ipv6(ref icmp_repr) => {
|
||||
let packet_buf = self.rx_buffer.enqueue(icmp_repr.buffer_len(),
|
||||
ip_repr.src_addr())?;
|
||||
icmp_repr.emit(&ip_repr.src_addr(), &ip_repr.dst_addr(),
|
||||
|
|
|
@ -69,8 +69,8 @@ pub(crate) enum PollAt {
|
|||
impl PollAt {
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
fn is_ingress(&self) -> bool {
|
||||
match self {
|
||||
&PollAt::Ingress => true,
|
||||
match *self {
|
||||
PollAt::Ingress => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
|
|||
net_trace!("{}:{}:{}: buffer to send {} octets",
|
||||
self.meta.handle, self.ip_version, self.ip_protocol,
|
||||
packet_buf.len());
|
||||
Ok(packet_buf.as_mut())
|
||||
Ok(packet_buf)
|
||||
}
|
||||
|
||||
/// Enqueue a packet to send, and fill it from a slice.
|
||||
|
@ -165,8 +165,8 @@ impl<'a, 'b> RawSocket<'a, 'b> {
|
|||
let header_len = ip_repr.buffer_len();
|
||||
let total_len = header_len + payload.len();
|
||||
let packet_buf = self.rx_buffer.enqueue(total_len, ())?;
|
||||
ip_repr.emit(&mut packet_buf.as_mut()[..header_len], &checksum_caps);
|
||||
packet_buf.as_mut()[header_len..].copy_from_slice(payload);
|
||||
ip_repr.emit(&mut packet_buf[..header_len], &checksum_caps);
|
||||
packet_buf[header_len..].copy_from_slice(payload);
|
||||
|
||||
net_trace!("{}:{}:{}: receiving {} octets",
|
||||
self.meta.handle, self.ip_version, self.ip_protocol,
|
||||
|
@ -179,10 +179,10 @@ impl<'a, 'b> RawSocket<'a, 'b> {
|
|||
where F: FnOnce((IpRepr, &[u8])) -> Result<()> {
|
||||
fn prepare<'a>(protocol: IpProtocol, buffer: &'a mut [u8],
|
||||
_checksum_caps: &ChecksumCapabilities) -> Result<(IpRepr, &'a [u8])> {
|
||||
match IpVersion::of_packet(buffer.as_ref())? {
|
||||
match IpVersion::of_packet(buffer)? {
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
IpVersion::Ipv4 => {
|
||||
let mut packet = Ipv4Packet::new_checked(buffer.as_mut())?;
|
||||
let mut packet = Ipv4Packet::new_checked(buffer)?;
|
||||
if packet.protocol() != protocol { return Err(Error::Unaddressable) }
|
||||
if _checksum_caps.ipv4.tx() {
|
||||
packet.fill_checksum();
|
||||
|
@ -198,7 +198,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
|
|||
}
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
IpVersion::Ipv6 => {
|
||||
let packet = Ipv6Packet::new_checked(buffer.as_mut())?;
|
||||
let packet = Ipv6Packet::new_checked(buffer)?;
|
||||
if packet.next_header() != protocol { return Err(Error::Unaddressable) }
|
||||
let packet = Ipv6Packet::new_unchecked(&*packet.into_inner());
|
||||
let ipv6_repr = Ipv6Repr::parse(&packet)?;
|
||||
|
@ -213,7 +213,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
|
|||
let ip_protocol = self.ip_protocol;
|
||||
let ip_version = self.ip_version;
|
||||
self.tx_buffer.dequeue_with(|&mut (), packet_buf| {
|
||||
match prepare(ip_protocol, packet_buf.as_mut(), &checksum_caps) {
|
||||
match prepare(ip_protocol, packet_buf, &checksum_caps) {
|
||||
Ok((ip_repr, raw_packet)) => {
|
||||
net_trace!("{}:{}:{}: sending {} octets",
|
||||
handle, ip_version, ip_protocol,
|
||||
|
|
|
@ -75,7 +75,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
|
|||
ManagedSlice::Owned(ref mut sockets) => {
|
||||
sockets.push(None);
|
||||
let index = sockets.len() - 1;
|
||||
return put(index, &mut sockets[index], socket)
|
||||
put(index, &mut sockets[index], socket)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,25 +139,25 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
|
|||
pub fn prune(&mut self) {
|
||||
for (index, item) in self.sockets.iter_mut().enumerate() {
|
||||
let mut may_remove = false;
|
||||
if let &mut Some(Item { refs: 0, ref mut socket }) = item {
|
||||
match socket {
|
||||
if let Some(Item { refs: 0, ref mut socket }) = *item {
|
||||
match *socket {
|
||||
#[cfg(feature = "socket-raw")]
|
||||
&mut Socket::Raw(_) =>
|
||||
Socket::Raw(_) =>
|
||||
may_remove = true,
|
||||
#[cfg(all(feature = "socket-icmp", any(feature = "proto-ipv4", feature = "proto-ipv6")))]
|
||||
&mut Socket::Icmp(_) =>
|
||||
Socket::Icmp(_) =>
|
||||
may_remove = true,
|
||||
#[cfg(feature = "socket-udp")]
|
||||
&mut Socket::Udp(_) =>
|
||||
Socket::Udp(_) =>
|
||||
may_remove = true,
|
||||
#[cfg(feature = "socket-tcp")]
|
||||
&mut Socket::Tcp(ref mut socket) =>
|
||||
Socket::Tcp(ref mut socket) =>
|
||||
if socket.state() == TcpState::Closed {
|
||||
may_remove = true
|
||||
} else {
|
||||
socket.close()
|
||||
},
|
||||
&mut Socket::__Nonexhaustive(_) => unreachable!()
|
||||
Socket::__Nonexhaustive(_) => unreachable!()
|
||||
}
|
||||
}
|
||||
if may_remove {
|
||||
|
|
|
@ -34,18 +34,18 @@ pub enum State {
|
|||
|
||||
impl fmt::Display for State {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&State::Closed => write!(f, "CLOSED"),
|
||||
&State::Listen => write!(f, "LISTEN"),
|
||||
&State::SynSent => write!(f, "SYN-SENT"),
|
||||
&State::SynReceived => write!(f, "SYN-RECEIVED"),
|
||||
&State::Established => write!(f, "ESTABLISHED"),
|
||||
&State::FinWait1 => write!(f, "FIN-WAIT-1"),
|
||||
&State::FinWait2 => write!(f, "FIN-WAIT-2"),
|
||||
&State::CloseWait => write!(f, "CLOSE-WAIT"),
|
||||
&State::Closing => write!(f, "CLOSING"),
|
||||
&State::LastAck => write!(f, "LAST-ACK"),
|
||||
&State::TimeWait => write!(f, "TIME-WAIT")
|
||||
match *self {
|
||||
State::Closed => write!(f, "CLOSED"),
|
||||
State::Listen => write!(f, "LISTEN"),
|
||||
State::SynSent => write!(f, "SYN-SENT"),
|
||||
State::SynReceived => write!(f, "SYN-RECEIVED"),
|
||||
State::Established => write!(f, "ESTABLISHED"),
|
||||
State::FinWait1 => write!(f, "FIN-WAIT-1"),
|
||||
State::FinWait2 => write!(f, "FIN-WAIT-2"),
|
||||
State::CloseWait => write!(f, "CLOSE-WAIT"),
|
||||
State::Closing => write!(f, "CLOSING"),
|
||||
State::LastAck => write!(f, "LAST-ACK"),
|
||||
State::TimeWait => write!(f, "TIME-WAIT")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1898,7 +1898,7 @@ mod test {
|
|||
let _ = log::set_logger(&LOGGER);
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
|
||||
println!("");
|
||||
println!();
|
||||
}
|
||||
|
||||
fn socket() -> TcpSocket<'static> {
|
||||
|
|
|
@ -290,16 +290,16 @@ impl Repr {
|
|||
|
||||
/// Return the length of a packet that will be emitted from this high-level representation.
|
||||
pub fn buffer_len(&self) -> usize {
|
||||
match self {
|
||||
&Repr::EthernetIpv4 { .. } => field::TPA(6, 4).end,
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
match *self {
|
||||
Repr::EthernetIpv4 { .. } => field::TPA(6, 4).end,
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit a high-level representation into an Address Resolution Protocol packet.
|
||||
pub fn emit<T: AsRef<[u8]> + AsMut<[u8]>>(&self, packet: &mut Packet<T>) {
|
||||
match self {
|
||||
&Repr::EthernetIpv4 {
|
||||
match *self {
|
||||
Repr::EthernetIpv4 {
|
||||
operation,
|
||||
source_hardware_addr, source_protocol_addr,
|
||||
target_hardware_addr, target_protocol_addr
|
||||
|
@ -314,7 +314,7 @@ impl Repr {
|
|||
packet.set_target_hardware_addr(target_hardware_addr.as_bytes());
|
||||
packet.set_target_protocol_addr(target_protocol_addr.as_bytes());
|
||||
},
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -340,8 +340,8 @@ impl<T: AsRef<[u8]>> fmt::Display for Packet<T> {
|
|||
|
||||
impl fmt::Display for Repr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Repr::EthernetIpv4 {
|
||||
match *self {
|
||||
Repr::EthernetIpv4 {
|
||||
operation,
|
||||
source_hardware_addr, source_protocol_addr,
|
||||
target_hardware_addr, target_protocol_addr
|
||||
|
@ -351,7 +351,7 @@ impl fmt::Display for Repr {
|
|||
target_hardware_addr, target_protocol_addr,
|
||||
operation)
|
||||
},
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for EtherType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&EtherType::Ipv4 => write!(f, "IPv4"),
|
||||
&EtherType::Ipv6 => write!(f, "IPv6"),
|
||||
&EtherType::Arp => write!(f, "ARP"),
|
||||
&EtherType::Unknown(id) => write!(f, "0x{:04x}", id)
|
||||
match *self {
|
||||
EtherType::Ipv4 => write!(f, "IPv4"),
|
||||
EtherType::Ipv6 => write!(f, "IPv6"),
|
||||
EtherType::Arp => write!(f, "ARP"),
|
||||
EtherType::Unknown(id) => write!(f, "0x{:04x}", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,18 +34,18 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for Message {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Message::EchoReply => write!(f, "echo reply"),
|
||||
&Message::DstUnreachable => write!(f, "destination unreachable"),
|
||||
&Message::Redirect => write!(f, "message redirect"),
|
||||
&Message::EchoRequest => write!(f, "echo request"),
|
||||
&Message::RouterAdvert => write!(f, "router advertisement"),
|
||||
&Message::RouterSolicit => write!(f, "router solicitation"),
|
||||
&Message::TimeExceeded => write!(f, "time exceeded"),
|
||||
&Message::ParamProblem => write!(f, "parameter problem"),
|
||||
&Message::Timestamp => write!(f, "timestamp"),
|
||||
&Message::TimestampReply => write!(f, "timestamp reply"),
|
||||
&Message::Unknown(id) => write!(f, "{}", id)
|
||||
match *self {
|
||||
Message::EchoReply => write!(f, "echo reply"),
|
||||
Message::DstUnreachable => write!(f, "destination unreachable"),
|
||||
Message::Redirect => write!(f, "message redirect"),
|
||||
Message::EchoRequest => write!(f, "echo request"),
|
||||
Message::RouterAdvert => write!(f, "router advertisement"),
|
||||
Message::RouterSolicit => write!(f, "router solicitation"),
|
||||
Message::TimeExceeded => write!(f, "time exceeded"),
|
||||
Message::ParamProblem => write!(f, "parameter problem"),
|
||||
Message::Timestamp => write!(f, "timestamp"),
|
||||
Message::TimestampReply => write!(f, "timestamp reply"),
|
||||
Message::Unknown(id) => write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,40 +90,40 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for DstUnreachable {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&DstUnreachable::NetUnreachable =>
|
||||
write!(f, "destination network unreachable"),
|
||||
&DstUnreachable::HostUnreachable =>
|
||||
write!(f, "destination host unreachable"),
|
||||
&DstUnreachable::ProtoUnreachable =>
|
||||
write!(f, "destination protocol unreachable"),
|
||||
&DstUnreachable::PortUnreachable =>
|
||||
write!(f, "destination port unreachable"),
|
||||
&DstUnreachable::FragRequired =>
|
||||
write!(f, "fragmentation required, and DF flag set"),
|
||||
&DstUnreachable::SrcRouteFailed =>
|
||||
write!(f, "source route failed"),
|
||||
&DstUnreachable::DstNetUnknown =>
|
||||
write!(f, "destination network unknown"),
|
||||
&DstUnreachable::DstHostUnknown =>
|
||||
write!(f, "destination host unknown"),
|
||||
&DstUnreachable::SrcHostIsolated =>
|
||||
write!(f, "source host isolated"),
|
||||
&DstUnreachable::NetProhibited =>
|
||||
write!(f, "network administratively prohibited"),
|
||||
&DstUnreachable::HostProhibited =>
|
||||
write!(f, "host administratively prohibited"),
|
||||
&DstUnreachable::NetUnreachToS =>
|
||||
write!(f, "network unreachable for ToS"),
|
||||
&DstUnreachable::HostUnreachToS =>
|
||||
write!(f, "host unreachable for ToS"),
|
||||
&DstUnreachable::CommProhibited =>
|
||||
write!(f, "communication administratively prohibited"),
|
||||
&DstUnreachable::HostPrecedViol =>
|
||||
write!(f, "host precedence violation"),
|
||||
&DstUnreachable::PrecedCutoff =>
|
||||
write!(f, "precedence cutoff in effect"),
|
||||
&DstUnreachable::Unknown(id) =>
|
||||
match *self {
|
||||
DstUnreachable::NetUnreachable =>
|
||||
write!(f, "destination network unreachable"),
|
||||
DstUnreachable::HostUnreachable =>
|
||||
write!(f, "destination host unreachable"),
|
||||
DstUnreachable::ProtoUnreachable =>
|
||||
write!(f, "destination protocol unreachable"),
|
||||
DstUnreachable::PortUnreachable =>
|
||||
write!(f, "destination port unreachable"),
|
||||
DstUnreachable::FragRequired =>
|
||||
write!(f, "fragmentation required, and DF flag set"),
|
||||
DstUnreachable::SrcRouteFailed =>
|
||||
write!(f, "source route failed"),
|
||||
DstUnreachable::DstNetUnknown =>
|
||||
write!(f, "destination network unknown"),
|
||||
DstUnreachable::DstHostUnknown =>
|
||||
write!(f, "destination host unknown"),
|
||||
DstUnreachable::SrcHostIsolated =>
|
||||
write!(f, "source host isolated"),
|
||||
DstUnreachable::NetProhibited =>
|
||||
write!(f, "network administratively prohibited"),
|
||||
DstUnreachable::HostProhibited =>
|
||||
write!(f, "host administratively prohibited"),
|
||||
DstUnreachable::NetUnreachToS =>
|
||||
write!(f, "network unreachable for ToS"),
|
||||
DstUnreachable::HostUnreachToS =>
|
||||
write!(f, "host unreachable for ToS"),
|
||||
DstUnreachable::CommProhibited =>
|
||||
write!(f, "communication administratively prohibited"),
|
||||
DstUnreachable::HostPrecedViol =>
|
||||
write!(f, "host precedence violation"),
|
||||
DstUnreachable::PrecedCutoff =>
|
||||
write!(f, "precedence cutoff in effect"),
|
||||
DstUnreachable::Unknown(id) =>
|
||||
write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
|
@ -455,8 +455,8 @@ impl<'a> Repr<'a> {
|
|||
pub fn emit<T>(&self, packet: &mut Packet<&mut T>, checksum_caps: &ChecksumCapabilities)
|
||||
where T: AsRef<[u8]> + AsMut<[u8]> + ?Sized {
|
||||
packet.set_msg_code(0);
|
||||
match self {
|
||||
&Repr::EchoRequest { ident, seq_no, data } => {
|
||||
match *self {
|
||||
Repr::EchoRequest { ident, seq_no, data } => {
|
||||
packet.set_msg_type(Message::EchoRequest);
|
||||
packet.set_msg_code(0);
|
||||
packet.set_echo_ident(ident);
|
||||
|
@ -465,7 +465,7 @@ impl<'a> Repr<'a> {
|
|||
packet.data_mut()[..data_len].copy_from_slice(&data[..data_len])
|
||||
},
|
||||
|
||||
&Repr::EchoReply { ident, seq_no, data } => {
|
||||
Repr::EchoReply { ident, seq_no, data } => {
|
||||
packet.set_msg_type(Message::EchoReply);
|
||||
packet.set_msg_code(0);
|
||||
packet.set_echo_ident(ident);
|
||||
|
@ -474,7 +474,7 @@ impl<'a> Repr<'a> {
|
|||
packet.data_mut()[..data_len].copy_from_slice(&data[..data_len])
|
||||
},
|
||||
|
||||
&Repr::DstUnreachable { reason, header, data } => {
|
||||
Repr::DstUnreachable { reason, header, data } => {
|
||||
packet.set_msg_type(Message::DstUnreachable);
|
||||
packet.set_msg_code(reason.into());
|
||||
|
||||
|
@ -484,7 +484,7 @@ impl<'a> Repr<'a> {
|
|||
payload.copy_from_slice(&data[..])
|
||||
}
|
||||
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
|
||||
if checksum_caps.icmpv4.tx() {
|
||||
|
@ -516,17 +516,17 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Packet<&'a T> {
|
|||
|
||||
impl<'a> fmt::Display for Repr<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Repr::EchoRequest { ident, seq_no, data } =>
|
||||
write!(f, "ICMPv4 echo request id={} seq={} len={}",
|
||||
ident, seq_no, data.len()),
|
||||
&Repr::EchoReply { ident, seq_no, data } =>
|
||||
write!(f, "ICMPv4 echo reply id={} seq={} len={}",
|
||||
ident, seq_no, data.len()),
|
||||
&Repr::DstUnreachable { reason, .. } =>
|
||||
write!(f, "ICMPv4 destination unreachable ({})",
|
||||
reason),
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
match *self {
|
||||
Repr::EchoRequest { ident, seq_no, data } =>
|
||||
write!(f, "ICMPv4 echo request id={} seq={} len={}",
|
||||
ident, seq_no, data.len()),
|
||||
Repr::EchoReply { ident, seq_no, data } =>
|
||||
write!(f, "ICMPv4 echo reply id={} seq={} len={}",
|
||||
ident, seq_no, data.len()),
|
||||
Repr::DstUnreachable { reason, .. } =>
|
||||
write!(f, "ICMPv4 destination unreachable ({})",
|
||||
reason),
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,21 +77,21 @@ impl Message {
|
|||
|
||||
impl fmt::Display for Message {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Message::DstUnreachable => write!(f, "destination unreachable"),
|
||||
&Message::PktTooBig => write!(f, "packet too big"),
|
||||
&Message::TimeExceeded => write!(f, "time exceeded"),
|
||||
&Message::ParamProblem => write!(f, "parameter problem"),
|
||||
&Message::EchoReply => write!(f, "echo reply"),
|
||||
&Message::EchoRequest => write!(f, "echo request"),
|
||||
&Message::RouterSolicit => write!(f, "router solicitation"),
|
||||
&Message::RouterAdvert => write!(f, "router advertisement"),
|
||||
&Message::NeighborSolicit => write!(f, "neighbor solicitation"),
|
||||
&Message::NeighborAdvert => write!(f, "neighbor advert"),
|
||||
&Message::Redirect => write!(f, "redirect"),
|
||||
&Message::MldQuery => write!(f, "multicast listener query"),
|
||||
&Message::MldReport => write!(f, "multicast listener report"),
|
||||
&Message::Unknown(id) => write!(f, "{}", id)
|
||||
match *self {
|
||||
Message::DstUnreachable => write!(f, "destination unreachable"),
|
||||
Message::PktTooBig => write!(f, "packet too big"),
|
||||
Message::TimeExceeded => write!(f, "time exceeded"),
|
||||
Message::ParamProblem => write!(f, "parameter problem"),
|
||||
Message::EchoReply => write!(f, "echo reply"),
|
||||
Message::EchoRequest => write!(f, "echo request"),
|
||||
Message::RouterSolicit => write!(f, "router solicitation"),
|
||||
Message::RouterAdvert => write!(f, "router advertisement"),
|
||||
Message::NeighborSolicit => write!(f, "neighbor solicitation"),
|
||||
Message::NeighborAdvert => write!(f, "neighbor advert"),
|
||||
Message::Redirect => write!(f, "redirect"),
|
||||
Message::MldQuery => write!(f, "multicast listener query"),
|
||||
Message::MldReport => write!(f, "multicast listener report"),
|
||||
Message::Unknown(id) => write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,22 +118,22 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for DstUnreachable {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&DstUnreachable::NoRoute =>
|
||||
write!(f, "no route to destination"),
|
||||
&DstUnreachable::AdminProhibit =>
|
||||
write!(f, "communication with destination administratively prohibited"),
|
||||
&DstUnreachable::BeyondScope =>
|
||||
write!(f, "beyond scope of source address"),
|
||||
&DstUnreachable::AddrUnreachable =>
|
||||
write!(f, "address unreachable"),
|
||||
&DstUnreachable::PortUnreachable =>
|
||||
write!(f, "port unreachable"),
|
||||
&DstUnreachable::FailedPolicy =>
|
||||
write!(f, "source address failed ingress/egress policy"),
|
||||
&DstUnreachable::RejectRoute =>
|
||||
write!(f, "reject route to destination"),
|
||||
&DstUnreachable::Unknown(id) =>
|
||||
match *self {
|
||||
DstUnreachable::NoRoute =>
|
||||
write!(f, "no route to destination"),
|
||||
DstUnreachable::AdminProhibit =>
|
||||
write!(f, "communication with destination administratively prohibited"),
|
||||
DstUnreachable::BeyondScope =>
|
||||
write!(f, "beyond scope of source address"),
|
||||
DstUnreachable::AddrUnreachable =>
|
||||
write!(f, "address unreachable"),
|
||||
DstUnreachable::PortUnreachable =>
|
||||
write!(f, "port unreachable"),
|
||||
DstUnreachable::FailedPolicy =>
|
||||
write!(f, "source address failed ingress/egress policy"),
|
||||
DstUnreachable::RejectRoute =>
|
||||
write!(f, "reject route to destination"),
|
||||
DstUnreachable::Unknown(id) =>
|
||||
write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
|
@ -153,14 +153,14 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for ParamProblem {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&ParamProblem::ErroneousHdrField =>
|
||||
write!(f, "erroneous header field."),
|
||||
&ParamProblem::UnrecognizedNxtHdr =>
|
||||
write!(f, "unrecognized next header type."),
|
||||
&ParamProblem::UnrecognizedOption =>
|
||||
write!(f, "unrecognized IPv6 option."),
|
||||
&ParamProblem::Unknown(id) =>
|
||||
match *self {
|
||||
ParamProblem::ErroneousHdrField =>
|
||||
write!(f, "erroneous header field."),
|
||||
ParamProblem::UnrecognizedNxtHdr =>
|
||||
write!(f, "unrecognized next header type."),
|
||||
ParamProblem::UnrecognizedOption =>
|
||||
write!(f, "unrecognized IPv6 option."),
|
||||
ParamProblem::Unknown(id) =>
|
||||
write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
|
@ -178,12 +178,12 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for TimeExceeded {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&TimeExceeded::HopLimitExceeded =>
|
||||
write!(f, "hop limit exceeded in transit"),
|
||||
&TimeExceeded::FragReassemExceeded =>
|
||||
write!(f, "fragment reassembly time exceeded"),
|
||||
&TimeExceeded::Unknown(id) =>
|
||||
match *self {
|
||||
TimeExceeded::HopLimitExceeded =>
|
||||
write!(f, "hop limit exceeded in transit"),
|
||||
TimeExceeded::FragReassemExceeded =>
|
||||
write!(f, "fragment reassembly time exceeded"),
|
||||
TimeExceeded::Unknown(id) =>
|
||||
write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
|
@ -667,15 +667,15 @@ impl<'a> Repr<'a> {
|
|||
payload.copy_from_slice(&data[..]);
|
||||
}
|
||||
|
||||
match self {
|
||||
&Repr::DstUnreachable { reason, header, data } => {
|
||||
match *self {
|
||||
Repr::DstUnreachable { reason, header, data } => {
|
||||
packet.set_msg_type(Message::DstUnreachable);
|
||||
packet.set_msg_code(reason.into());
|
||||
|
||||
emit_contained_packet(packet.payload_mut(), header, &data);
|
||||
},
|
||||
|
||||
&Repr::PktTooBig { mtu, header, data } => {
|
||||
Repr::PktTooBig { mtu, header, data } => {
|
||||
packet.set_msg_type(Message::PktTooBig);
|
||||
packet.set_msg_code(0);
|
||||
packet.set_pkt_too_big_mtu(mtu);
|
||||
|
@ -683,14 +683,14 @@ impl<'a> Repr<'a> {
|
|||
emit_contained_packet(packet.payload_mut(), header, &data);
|
||||
},
|
||||
|
||||
&Repr::TimeExceeded { reason, header, data } => {
|
||||
Repr::TimeExceeded { reason, header, data } => {
|
||||
packet.set_msg_type(Message::TimeExceeded);
|
||||
packet.set_msg_code(reason.into());
|
||||
|
||||
emit_contained_packet(packet.payload_mut(), header, &data);
|
||||
},
|
||||
|
||||
&Repr::ParamProblem { reason, pointer, header, data } => {
|
||||
Repr::ParamProblem { reason, pointer, header, data } => {
|
||||
packet.set_msg_type(Message::ParamProblem);
|
||||
packet.set_msg_code(reason.into());
|
||||
packet.set_param_problem_ptr(pointer);
|
||||
|
@ -698,7 +698,7 @@ impl<'a> Repr<'a> {
|
|||
emit_contained_packet(packet.payload_mut(), header, &data);
|
||||
},
|
||||
|
||||
&Repr::EchoRequest { ident, seq_no, data } => {
|
||||
Repr::EchoRequest { ident, seq_no, data } => {
|
||||
packet.set_msg_type(Message::EchoRequest);
|
||||
packet.set_msg_code(0);
|
||||
packet.set_echo_ident(ident);
|
||||
|
@ -707,7 +707,7 @@ impl<'a> Repr<'a> {
|
|||
packet.payload_mut()[..data_len].copy_from_slice(&data[..data_len])
|
||||
},
|
||||
|
||||
&Repr::EchoReply { ident, seq_no, data } => {
|
||||
Repr::EchoReply { ident, seq_no, data } => {
|
||||
packet.set_msg_type(Message::EchoReply);
|
||||
packet.set_msg_code(0);
|
||||
packet.set_echo_ident(ident);
|
||||
|
@ -717,15 +717,15 @@ impl<'a> Repr<'a> {
|
|||
},
|
||||
|
||||
#[cfg(feature = "ethernet")]
|
||||
&Repr::Ndisc(ndisc) => {
|
||||
Repr::Ndisc(ndisc) => {
|
||||
ndisc.emit(packet)
|
||||
},
|
||||
|
||||
&Repr::Mld(mld) => {
|
||||
Repr::Mld(mld) => {
|
||||
mld.emit(packet)
|
||||
},
|
||||
|
||||
&Repr::__Nonexhaustive => unreachable!(),
|
||||
Repr::__Nonexhaustive => unreachable!(),
|
||||
}
|
||||
|
||||
if checksum_caps.icmpv6.tx() {
|
||||
|
|
|
@ -38,12 +38,12 @@ mod field {
|
|||
|
||||
impl fmt::Display for Message {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Message::MembershipQuery => write!(f, "membership query"),
|
||||
&Message::MembershipReportV2 => write!(f, "version 2 membership report"),
|
||||
&Message::LeaveGroup => write!(f, "leave group"),
|
||||
&Message::MembershipReportV1 => write!(f, "version 1 membership report"),
|
||||
&Message::Unknown(id) => write!(f, "{}", id),
|
||||
match *self {
|
||||
Message::MembershipQuery => write!(f, "membership query"),
|
||||
Message::MembershipReportV2 => write!(f, "version 2 membership report"),
|
||||
Message::LeaveGroup => write!(f, "leave group"),
|
||||
Message::MembershipReportV1 => write!(f, "version 1 membership report"),
|
||||
Message::Unknown(id) => write!(f, "{}", id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -251,8 +251,8 @@ impl Repr {
|
|||
pub fn emit<T>(&self, packet: &mut Packet<&mut T>)
|
||||
where T: AsRef<[u8]> + AsMut<[u8]> + ?Sized
|
||||
{
|
||||
match self {
|
||||
&Repr::MembershipQuery {
|
||||
match *self {
|
||||
Repr::MembershipQuery {
|
||||
max_resp_time,
|
||||
group_addr,
|
||||
version
|
||||
|
@ -266,7 +266,7 @@ impl Repr {
|
|||
}
|
||||
packet.set_group_address(group_addr);
|
||||
}
|
||||
&Repr::MembershipReport {
|
||||
Repr::MembershipReport {
|
||||
group_addr,
|
||||
version,
|
||||
} => {
|
||||
|
@ -277,7 +277,7 @@ impl Repr {
|
|||
packet.set_max_resp_code(0);
|
||||
packet.set_group_address(group_addr);
|
||||
}
|
||||
&Repr::LeaveGroup { group_addr } => {
|
||||
Repr::LeaveGroup { group_addr } => {
|
||||
packet.set_msg_type(Message::LeaveGroup);
|
||||
packet.set_group_address(group_addr);
|
||||
}
|
||||
|
@ -327,8 +327,8 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Packet<&'a T> {
|
|||
|
||||
impl<'a> fmt::Display for Repr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Repr::MembershipQuery {
|
||||
match *self {
|
||||
Repr::MembershipQuery {
|
||||
max_resp_time,
|
||||
group_addr,
|
||||
version,
|
||||
|
@ -339,7 +339,7 @@ impl<'a> fmt::Display for Repr {
|
|||
group_addr,
|
||||
version)
|
||||
}
|
||||
&Repr::MembershipReport {
|
||||
Repr::MembershipReport {
|
||||
group_addr,
|
||||
version,
|
||||
} => {
|
||||
|
@ -348,7 +348,7 @@ impl<'a> fmt::Display for Repr {
|
|||
group_addr,
|
||||
version)
|
||||
}
|
||||
&Repr::LeaveGroup { group_addr } => {
|
||||
Repr::LeaveGroup { group_addr } => {
|
||||
write!(f, "IGMP leave group group_addr={})", group_addr)
|
||||
}
|
||||
}
|
||||
|
@ -363,8 +363,8 @@ impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
|
|||
indent: &mut PrettyIndent)
|
||||
-> fmt::Result {
|
||||
match Packet::new_checked(buffer) {
|
||||
Err(err) => write!(f, "{}({})\n", indent, err),
|
||||
Ok(packet) => write!(f, "{}{}\n", indent, packet),
|
||||
Err(err) => writeln!(f, "{}({})", indent, err),
|
||||
Ok(packet) => writeln!(f, "{}{}", indent, packet),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
224
src/wire/ip.rs
224
src/wire/ip.rs
|
@ -38,13 +38,13 @@ impl Version {
|
|||
|
||||
impl fmt::Display for Version {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Version::Unspecified => write!(f, "IPv?"),
|
||||
match *self {
|
||||
Version::Unspecified => write!(f, "IPv?"),
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Version::Ipv4 => write!(f, "IPv4"),
|
||||
Version::Ipv4 => write!(f, "IPv4"),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Version::Ipv6 => write!(f, "IPv6"),
|
||||
&Version::__Nonexhaustive => unreachable!()
|
||||
Version::Ipv6 => write!(f, "IPv6"),
|
||||
Version::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,18 +67,18 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for Protocol {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Protocol::HopByHop => write!(f, "Hop-by-Hop"),
|
||||
&Protocol::Icmp => write!(f, "ICMP"),
|
||||
&Protocol::Igmp => write!(f, "IGMP"),
|
||||
&Protocol::Tcp => write!(f, "TCP"),
|
||||
&Protocol::Udp => write!(f, "UDP"),
|
||||
&Protocol::Ipv6Route => write!(f, "IPv6-Route"),
|
||||
&Protocol::Ipv6Frag => write!(f, "IPv6-Frag"),
|
||||
&Protocol::Icmpv6 => write!(f, "ICMPv6"),
|
||||
&Protocol::Ipv6NoNxt => write!(f, "IPv6-NoNxt"),
|
||||
&Protocol::Ipv6Opts => write!(f, "IPv6-Opts"),
|
||||
&Protocol::Unknown(id) => write!(f, "0x{:02x}", id)
|
||||
match *self {
|
||||
Protocol::HopByHop => write!(f, "Hop-by-Hop"),
|
||||
Protocol::Icmp => write!(f, "ICMP"),
|
||||
Protocol::Igmp => write!(f, "IGMP"),
|
||||
Protocol::Tcp => write!(f, "TCP"),
|
||||
Protocol::Udp => write!(f, "UDP"),
|
||||
Protocol::Ipv6Route => write!(f, "IPv6-Route"),
|
||||
Protocol::Ipv6Frag => write!(f, "IPv6-Frag"),
|
||||
Protocol::Icmpv6 => write!(f, "ICMPv6"),
|
||||
Protocol::Ipv6NoNxt => write!(f, "IPv6-NoNxt"),
|
||||
Protocol::Ipv6Opts => write!(f, "IPv6-Opts"),
|
||||
Protocol::Unknown(id) => write!(f, "0x{:02x}", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,73 +115,73 @@ impl Address {
|
|||
|
||||
/// Return an address as a sequence of octets, in big-endian.
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
match self {
|
||||
&Address::Unspecified => &[],
|
||||
match *self {
|
||||
Address::Unspecified => &[],
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Address::Ipv4(ref addr) => addr.as_bytes(),
|
||||
Address::Ipv4(ref addr) => addr.as_bytes(),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Address::Ipv6(ref addr) => addr.as_bytes(),
|
||||
&Address::__Nonexhaustive => unreachable!()
|
||||
Address::Ipv6(ref addr) => addr.as_bytes(),
|
||||
Address::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Query whether the address is a valid unicast address.
|
||||
pub fn is_unicast(&self) -> bool {
|
||||
match self {
|
||||
&Address::Unspecified => false,
|
||||
match *self {
|
||||
Address::Unspecified => false,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Address::Ipv4(addr) => addr.is_unicast(),
|
||||
Address::Ipv4(addr) => addr.is_unicast(),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Address::Ipv6(addr) => addr.is_unicast(),
|
||||
&Address::__Nonexhaustive => unreachable!()
|
||||
Address::Ipv6(addr) => addr.is_unicast(),
|
||||
Address::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Query whether the address is a valid multicast address.
|
||||
pub fn is_multicast(&self) -> bool {
|
||||
match self {
|
||||
&Address::Unspecified => false,
|
||||
match *self {
|
||||
Address::Unspecified => false,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Address::Ipv4(addr) => addr.is_multicast(),
|
||||
Address::Ipv4(addr) => addr.is_multicast(),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Address::Ipv6(addr) => addr.is_multicast(),
|
||||
&Address::__Nonexhaustive => unreachable!()
|
||||
Address::Ipv6(addr) => addr.is_multicast(),
|
||||
Address::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Query whether the address is the broadcast address.
|
||||
pub fn is_broadcast(&self) -> bool {
|
||||
match self {
|
||||
&Address::Unspecified => false,
|
||||
match *self {
|
||||
Address::Unspecified => false,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Address::Ipv4(addr) => addr.is_broadcast(),
|
||||
Address::Ipv4(addr) => addr.is_broadcast(),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Address::Ipv6(_) => false,
|
||||
&Address::__Nonexhaustive => unreachable!()
|
||||
Address::Ipv6(_) => false,
|
||||
Address::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Query whether the address falls into the "unspecified" range.
|
||||
pub fn is_unspecified(&self) -> bool {
|
||||
match self {
|
||||
&Address::Unspecified => true,
|
||||
match *self {
|
||||
Address::Unspecified => true,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Address::Ipv4(addr) => addr.is_unspecified(),
|
||||
Address::Ipv4(addr) => addr.is_unspecified(),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Address::Ipv6(addr) => addr.is_unspecified(),
|
||||
&Address::__Nonexhaustive => unreachable!()
|
||||
Address::Ipv6(addr) => addr.is_unspecified(),
|
||||
Address::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return an unspecified address that has the same IP version as `self`.
|
||||
pub fn to_unspecified(&self) -> Address {
|
||||
match self {
|
||||
&Address::Unspecified => Address::Unspecified,
|
||||
match *self {
|
||||
Address::Unspecified => Address::Unspecified,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Address::Ipv4(_) => Address::Ipv4(Ipv4Address::UNSPECIFIED),
|
||||
Address::Ipv4(_) => Address::Ipv4(Ipv4Address::UNSPECIFIED),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Address::Ipv6(_) => Address::Ipv6(Ipv6Address::UNSPECIFIED),
|
||||
&Address::__Nonexhaustive => unreachable!()
|
||||
Address::Ipv6(_) => Address::Ipv6(Ipv6Address::UNSPECIFIED),
|
||||
Address::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,13 +260,13 @@ impl From<Ipv6Address> for Address {
|
|||
|
||||
impl fmt::Display for Address {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Address::Unspecified => write!(f, "*"),
|
||||
match *self {
|
||||
Address::Unspecified => write!(f, "*"),
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Address::Ipv4(addr) => write!(f, "{}", addr),
|
||||
Address::Ipv4(addr) => write!(f, "{}", addr),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Address::Ipv6(addr) => write!(f, "{}", addr),
|
||||
&Address::__Nonexhaustive => unreachable!()
|
||||
Address::Ipv6(addr) => write!(f, "{}", addr),
|
||||
Address::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -304,23 +304,23 @@ impl Cidr {
|
|||
|
||||
/// Return the IP address of this CIDR block.
|
||||
pub fn address(&self) -> Address {
|
||||
match self {
|
||||
match *self {
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Cidr::Ipv4(cidr) => Address::Ipv4(cidr.address()),
|
||||
Cidr::Ipv4(cidr) => Address::Ipv4(cidr.address()),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Cidr::Ipv6(cidr) => Address::Ipv6(cidr.address()),
|
||||
&Cidr::__Nonexhaustive => unreachable!()
|
||||
Cidr::Ipv6(cidr) => Address::Ipv6(cidr.address()),
|
||||
Cidr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the prefix length of this CIDR block.
|
||||
pub fn prefix_len(&self) -> u8 {
|
||||
match self {
|
||||
match *self {
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Cidr::Ipv4(cidr) => cidr.prefix_len(),
|
||||
Cidr::Ipv4(cidr) => cidr.prefix_len(),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Cidr::Ipv6(cidr) => cidr.prefix_len(),
|
||||
&Cidr::__Nonexhaustive => unreachable!()
|
||||
Cidr::Ipv6(cidr) => cidr.prefix_len(),
|
||||
Cidr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,12 +383,12 @@ impl From<Ipv6Cidr> for Cidr {
|
|||
|
||||
impl fmt::Display for Cidr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
match *self {
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Cidr::Ipv4(cidr) => write!(f, "{}", cidr),
|
||||
Cidr::Ipv4(cidr) => write!(f, "{}", cidr),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Cidr::Ipv6(cidr) => write!(f, "{}", cidr),
|
||||
&Cidr::__Nonexhaustive => unreachable!()
|
||||
Cidr::Ipv6(cidr) => write!(f, "{}", cidr),
|
||||
Cidr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -504,88 +504,88 @@ impl From<Ipv6Repr> for Repr {
|
|||
impl Repr {
|
||||
/// Return the protocol version.
|
||||
pub fn version(&self) -> Version {
|
||||
match self {
|
||||
&Repr::Unspecified { .. } => Version::Unspecified,
|
||||
match *self {
|
||||
Repr::Unspecified { .. } => Version::Unspecified,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Repr::Ipv4(_) => Version::Ipv4,
|
||||
Repr::Ipv4(_) => Version::Ipv4,
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Repr::Ipv6(_) => Version::Ipv6,
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::Ipv6(_) => Version::Ipv6,
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the source address.
|
||||
pub fn src_addr(&self) -> Address {
|
||||
match self {
|
||||
&Repr::Unspecified { src_addr, .. } => src_addr,
|
||||
match *self {
|
||||
Repr::Unspecified { src_addr, .. } => src_addr,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Repr::Ipv4(repr) => Address::Ipv4(repr.src_addr),
|
||||
Repr::Ipv4(repr) => Address::Ipv4(repr.src_addr),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Repr::Ipv6(repr) => Address::Ipv6(repr.src_addr),
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::Ipv6(repr) => Address::Ipv6(repr.src_addr),
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the destination address.
|
||||
pub fn dst_addr(&self) -> Address {
|
||||
match self {
|
||||
&Repr::Unspecified { dst_addr, .. } => dst_addr,
|
||||
match *self {
|
||||
Repr::Unspecified { dst_addr, .. } => dst_addr,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Repr::Ipv4(repr) => Address::Ipv4(repr.dst_addr),
|
||||
Repr::Ipv4(repr) => Address::Ipv4(repr.dst_addr),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Repr::Ipv6(repr) => Address::Ipv6(repr.dst_addr),
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::Ipv6(repr) => Address::Ipv6(repr.dst_addr),
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the protocol.
|
||||
pub fn protocol(&self) -> Protocol {
|
||||
match self {
|
||||
&Repr::Unspecified { protocol, .. } => protocol,
|
||||
match *self {
|
||||
Repr::Unspecified { protocol, .. } => protocol,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Repr::Ipv4(repr) => repr.protocol,
|
||||
Repr::Ipv4(repr) => repr.protocol,
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Repr::Ipv6(repr) => repr.next_header,
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::Ipv6(repr) => repr.next_header,
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the payload length.
|
||||
pub fn payload_len(&self) -> usize {
|
||||
match self {
|
||||
&Repr::Unspecified { payload_len, .. } => payload_len,
|
||||
match *self {
|
||||
Repr::Unspecified { payload_len, .. } => payload_len,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Repr::Ipv4(repr) => repr.payload_len,
|
||||
Repr::Ipv4(repr) => repr.payload_len,
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Repr::Ipv6(repr) => repr.payload_len,
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::Ipv6(repr) => repr.payload_len,
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the payload length.
|
||||
pub fn set_payload_len(&mut self, length: usize) {
|
||||
match self {
|
||||
&mut Repr::Unspecified { ref mut payload_len, .. } =>
|
||||
match *self {
|
||||
Repr::Unspecified { ref mut payload_len, .. } =>
|
||||
*payload_len = length,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&mut Repr::Ipv4(Ipv4Repr { ref mut payload_len, .. }) =>
|
||||
Repr::Ipv4(Ipv4Repr { ref mut payload_len, .. }) =>
|
||||
*payload_len = length,
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&mut Repr::Ipv6(Ipv6Repr { ref mut payload_len, .. }) =>
|
||||
Repr::Ipv6(Ipv6Repr { ref mut payload_len, .. }) =>
|
||||
*payload_len = length,
|
||||
&mut Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the TTL value.
|
||||
pub fn hop_limit(&self) -> u8 {
|
||||
match self {
|
||||
&Repr::Unspecified { hop_limit, .. } => hop_limit,
|
||||
match *self {
|
||||
Repr::Unspecified { hop_limit, .. } => hop_limit,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Repr::Ipv4(Ipv4Repr { hop_limit, .. }) => hop_limit,
|
||||
Repr::Ipv4(Ipv4Repr { hop_limit, .. }) => hop_limit,
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Repr::Ipv6(Ipv6Repr { hop_limit, ..}) => hop_limit,
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::Ipv6(Ipv6Repr { hop_limit, ..}) => hop_limit,
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -722,16 +722,16 @@ impl Repr {
|
|||
/// # Panics
|
||||
/// This function panics if invoked on an unspecified representation.
|
||||
pub fn buffer_len(&self) -> usize {
|
||||
match self {
|
||||
&Repr::Unspecified { .. } =>
|
||||
match *self {
|
||||
Repr::Unspecified { .. } =>
|
||||
panic!("unspecified IP representation"),
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Repr::Ipv4(repr) =>
|
||||
Repr::Ipv4(repr) =>
|
||||
repr.buffer_len(),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Repr::Ipv6(repr) =>
|
||||
Repr::Ipv6(repr) =>
|
||||
repr.buffer_len(),
|
||||
&Repr::__Nonexhaustive =>
|
||||
Repr::__Nonexhaustive =>
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
@ -741,16 +741,16 @@ impl Repr {
|
|||
/// # Panics
|
||||
/// This function panics if invoked on an unspecified representation.
|
||||
pub fn emit<T: AsRef<[u8]> + AsMut<[u8]>>(&self, buffer: T, _checksum_caps: &ChecksumCapabilities) {
|
||||
match self {
|
||||
&Repr::Unspecified { .. } =>
|
||||
match *self {
|
||||
Repr::Unspecified { .. } =>
|
||||
panic!("unspecified IP representation"),
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
&Repr::Ipv4(repr) =>
|
||||
Repr::Ipv4(repr) =>
|
||||
repr.emit(&mut Ipv4Packet::new_unchecked(buffer), &_checksum_caps),
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
&Repr::Ipv6(repr) =>
|
||||
Repr::Ipv6(repr) =>
|
||||
repr.emit(&mut Ipv6Packet::new_unchecked(buffer)),
|
||||
&Repr::__Nonexhaustive =>
|
||||
Repr::__Nonexhaustive =>
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
@ -879,11 +879,11 @@ pub fn pretty_print_ip_payload<T: Into<Repr>>(f: &mut fmt::Formatter, indent: &m
|
|||
#[cfg(feature = "proto-ipv4")]
|
||||
Protocol::Icmp => {
|
||||
indent.increase(f)?;
|
||||
Icmpv4Packet::<&[u8]>::pretty_print(&payload.as_ref(), f, indent)
|
||||
Icmpv4Packet::<&[u8]>::pretty_print(&payload, f, indent)
|
||||
}
|
||||
Protocol::Udp => {
|
||||
indent.increase(f)?;
|
||||
match UdpPacket::<&[u8]>::new_checked(payload.as_ref()) {
|
||||
match UdpPacket::<&[u8]>::new_checked(payload) {
|
||||
Err(err) => write!(f, "{}({})", indent, err),
|
||||
Ok(udp_packet) => {
|
||||
match UdpRepr::parse(&udp_packet, &repr.src_addr(),
|
||||
|
@ -901,7 +901,7 @@ pub fn pretty_print_ip_payload<T: Into<Repr>>(f: &mut fmt::Formatter, indent: &m
|
|||
}
|
||||
Protocol::Tcp => {
|
||||
indent.increase(f)?;
|
||||
match TcpPacket::<&[u8]>::new_checked(payload.as_ref()) {
|
||||
match TcpPacket::<&[u8]>::new_checked(payload) {
|
||||
Err(err) => write!(f, "{}({})", indent, err),
|
||||
Ok(tcp_packet) => {
|
||||
match TcpRepr::parse(&tcp_packet, &repr.src_addr(),
|
||||
|
|
|
@ -13,10 +13,10 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for Type {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Type::Pad1 => write!(f, "Pad1"),
|
||||
&Type::PadN => write!(f, "PadN"),
|
||||
&Type::Unknown(id) => write!(f, "{}", id)
|
||||
match *self {
|
||||
Type::Pad1 => write!(f, "Pad1"),
|
||||
Type::PadN => write!(f, "PadN"),
|
||||
Type::Unknown(id) => write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,12 +39,12 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for FailureType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&FailureType::Skip => write!(f, "skip"),
|
||||
&FailureType::Discard => write!(f, "discard"),
|
||||
&FailureType::DiscardSendAll => write!(f, "discard and send error"),
|
||||
&FailureType::DiscardSendUnicast => write!(f, "discard and send error if unicast"),
|
||||
&FailureType::Unknown(id) => write!(f, "Unknown({})", id),
|
||||
match *self {
|
||||
FailureType::Skip => write!(f, "skip"),
|
||||
FailureType::Discard => write!(f, "discard"),
|
||||
FailureType::DiscardSendAll => write!(f, "discard and send error"),
|
||||
FailureType::DiscardSendUnicast => write!(f, "discard and send error if unicast"),
|
||||
FailureType::Unknown(id) => write!(f, "Unknown({})", id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,23 +247,23 @@ impl<'a> Repr<'a> {
|
|||
|
||||
/// Return the length of a header that will be emitted from this high-level representation.
|
||||
pub fn buffer_len(&self) -> usize {
|
||||
match self {
|
||||
&Repr::Pad1 => 1,
|
||||
&Repr::PadN(length) =>
|
||||
field::DATA(length).end,
|
||||
&Repr::Unknown{ length, .. } =>
|
||||
field::DATA(length).end,
|
||||
match *self {
|
||||
Repr::Pad1 => 1,
|
||||
Repr::PadN(length) =>
|
||||
field::DATA(length).end,
|
||||
Repr::Unknown{ length, .. } =>
|
||||
field::DATA(length).end,
|
||||
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit a high-level representation into an IPv6 Extension Header Option.
|
||||
pub fn emit<T: AsRef<[u8]> + AsMut<[u8]> + ?Sized>(&self, opt: &mut Ipv6Option<&'a mut T>) {
|
||||
match self {
|
||||
&Repr::Pad1 =>
|
||||
match *self {
|
||||
Repr::Pad1 =>
|
||||
opt.set_option_type(Type::Pad1),
|
||||
&Repr::PadN(len) => {
|
||||
Repr::PadN(len) => {
|
||||
opt.set_option_type(Type::PadN);
|
||||
opt.set_data_len(len);
|
||||
// Ensure all padding bytes are set to zero.
|
||||
|
@ -271,13 +271,13 @@ impl<'a> Repr<'a> {
|
|||
*x = 0
|
||||
}
|
||||
}
|
||||
&Repr::Unknown{ type_, length, data } => {
|
||||
Repr::Unknown{ type_, length, data } => {
|
||||
opt.set_option_type(type_);
|
||||
opt.set_data_len(length);
|
||||
opt.data_mut().copy_from_slice(&data[..length as usize]);
|
||||
}
|
||||
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,15 +351,15 @@ impl<'a> Iterator for Ipv6OptionsIterator<'a> {
|
|||
impl<'a> fmt::Display for Repr<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "IPv6 Option ")?;
|
||||
match self {
|
||||
&Repr::Pad1 =>
|
||||
write!(f, "{} ", Type::Pad1),
|
||||
&Repr::PadN(len) =>
|
||||
write!(f, "{} length={} ", Type::PadN, len),
|
||||
&Repr::Unknown{ type_, length, .. } =>
|
||||
write!(f, "{} length={} ", type_, length),
|
||||
match *self {
|
||||
Repr::Pad1 =>
|
||||
write!(f, "{} ", Type::Pad1),
|
||||
Repr::PadN(len) =>
|
||||
write!(f, "{} length={} ", Type::PadN, len),
|
||||
Repr::Unknown{ type_, length, .. } =>
|
||||
write!(f, "{} length={} ", type_, length),
|
||||
|
||||
&Repr::__Nonexhaustive => unreachable!()
|
||||
Repr::__Nonexhaustive => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,15 +36,15 @@ enum_with_unknown! {
|
|||
|
||||
impl fmt::Display for Type {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Type::Type0 => write!(f, "Type0"),
|
||||
&Type::Nimrod => write!(f, "Nimrod"),
|
||||
&Type::Type2 => write!(f, "Type2"),
|
||||
&Type::Rpl => write!(f, "Rpl"),
|
||||
&Type::Experiment1 => write!(f, "Experiment1"),
|
||||
&Type::Experiment2 => write!(f, "Experiment2"),
|
||||
&Type::Reserved => write!(f, "Reserved"),
|
||||
&Type::Unknown(id) => write!(f, "{}", id)
|
||||
match *self {
|
||||
Type::Type0 => write!(f, "Type0"),
|
||||
Type::Nimrod => write!(f, "Nimrod"),
|
||||
Type::Type2 => write!(f, "Type2"),
|
||||
Type::Rpl => write!(f, "Rpl"),
|
||||
Type::Experiment1 => write!(f, "Experiment1"),
|
||||
Type::Experiment2 => write!(f, "Experiment2"),
|
||||
Type::Reserved => write!(f, "Reserved"),
|
||||
Type::Unknown(id) => write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -465,8 +465,8 @@ impl<'a> Repr<'a> {
|
|||
|
||||
/// Emit a high-level representation into an IPv6 Routing Header.
|
||||
pub fn emit<T: AsRef<[u8]> + AsMut<[u8]> + ?Sized>(&self, header: &mut Header<&mut T>) {
|
||||
match self {
|
||||
&Repr::Type2 { next_header, length, segments_left, home_address } => {
|
||||
match *self {
|
||||
Repr::Type2 { next_header, length, segments_left, home_address } => {
|
||||
header.set_next_header(next_header);
|
||||
header.set_header_len(length);
|
||||
header.set_routing_type(Type::Type2);
|
||||
|
@ -474,7 +474,7 @@ impl<'a> Repr<'a> {
|
|||
header.clear_reserved();
|
||||
header.set_home_address(home_address);
|
||||
}
|
||||
&Repr::Rpl { next_header, length, segments_left, cmpr_i, cmpr_e, pad, addresses } => {
|
||||
Repr::Rpl { next_header, length, segments_left, cmpr_i, cmpr_e, pad, addresses } => {
|
||||
header.set_next_header(next_header);
|
||||
header.set_header_len(length);
|
||||
header.set_routing_type(Type::Rpl);
|
||||
|
@ -486,24 +486,24 @@ impl<'a> Repr<'a> {
|
|||
header.set_addresses(addresses);
|
||||
}
|
||||
|
||||
&Repr::__Nonexhaustive => unreachable!(),
|
||||
Repr::__Nonexhaustive => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for Repr<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Repr::Type2 { next_header, length, segments_left, home_address } => {
|
||||
match *self {
|
||||
Repr::Type2 { next_header, length, segments_left, home_address } => {
|
||||
write!(f, "IPv6 Routing next_hdr={} length={} type={} seg_left={} home_address={}",
|
||||
next_header, length, Type::Type2, segments_left, home_address)
|
||||
}
|
||||
&Repr::Rpl { next_header, length, segments_left, cmpr_i, cmpr_e, pad, .. } => {
|
||||
Repr::Rpl { next_header, length, segments_left, cmpr_i, cmpr_e, pad, .. } => {
|
||||
write!(f, "IPv6 Routing next_hdr={} length={} type={} seg_left={} cmpr_i={} cmpr_e={} pad={}",
|
||||
next_header, length, Type::Rpl, segments_left, cmpr_i, cmpr_e, pad)
|
||||
}
|
||||
|
||||
&Repr::__Nonexhaustive => unreachable!(),
|
||||
Repr::__Nonexhaustive => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -370,8 +370,8 @@ impl<'a> Repr<'a> {
|
|||
|
||||
pub fn emit<T>(&self, packet: &mut Packet<&mut T>)
|
||||
where T: AsRef<[u8]> + AsMut<[u8]> + ?Sized {
|
||||
match self {
|
||||
&Repr::RouterSolicit { lladdr } => {
|
||||
match *self {
|
||||
Repr::RouterSolicit { lladdr } => {
|
||||
packet.set_msg_type(Message::RouterSolicit);
|
||||
packet.set_msg_code(0);
|
||||
packet.clear_reserved();
|
||||
|
@ -381,7 +381,7 @@ impl<'a> Repr<'a> {
|
|||
}
|
||||
},
|
||||
|
||||
&Repr::RouterAdvert { hop_limit, flags, router_lifetime, reachable_time,
|
||||
Repr::RouterAdvert { hop_limit, flags, router_lifetime, reachable_time,
|
||||
retrans_time, lladdr, mtu, prefix_info } => {
|
||||
packet.set_msg_type(Message::RouterAdvert);
|
||||
packet.set_msg_code(0);
|
||||
|
@ -410,7 +410,7 @@ impl<'a> Repr<'a> {
|
|||
}
|
||||
},
|
||||
|
||||
&Repr::NeighborSolicit { target_addr, lladdr } => {
|
||||
Repr::NeighborSolicit { target_addr, lladdr } => {
|
||||
packet.set_msg_type(Message::NeighborSolicit);
|
||||
packet.set_msg_code(0);
|
||||
packet.clear_reserved();
|
||||
|
@ -422,7 +422,7 @@ impl<'a> Repr<'a> {
|
|||
}
|
||||
},
|
||||
|
||||
&Repr::NeighborAdvert { flags, target_addr, lladdr } => {
|
||||
Repr::NeighborAdvert { flags, target_addr, lladdr } => {
|
||||
packet.set_msg_type(Message::NeighborAdvert);
|
||||
packet.set_msg_code(0);
|
||||
packet.clear_reserved();
|
||||
|
@ -435,7 +435,7 @@ impl<'a> Repr<'a> {
|
|||
}
|
||||
},
|
||||
|
||||
&Repr::Redirect { target_addr, dest_addr, lladdr, redirected_hdr } => {
|
||||
Repr::Redirect { target_addr, dest_addr, lladdr, redirected_hdr } => {
|
||||
packet.set_msg_type(Message::Redirect);
|
||||
packet.set_msg_code(0);
|
||||
packet.clear_reserved();
|
||||
|
|
|
@ -24,12 +24,12 @@ enum_with_unknown! {
|
|||
impl fmt::Display for Type {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Type::SourceLinkLayerAddr => write!(f, "source link-layer address"),
|
||||
&Type::TargetLinkLayerAddr => write!(f, "target link-layer address"),
|
||||
&Type::PrefixInformation => write!(f, "prefix information"),
|
||||
&Type::RedirectedHeader => write!(f, "redirected header"),
|
||||
&Type::Mtu => write!(f, "mtu"),
|
||||
&Type::Unknown(id) => write!(f, "{}", id)
|
||||
Type::SourceLinkLayerAddr => write!(f, "source link-layer address"),
|
||||
Type::TargetLinkLayerAddr => write!(f, "target link-layer address"),
|
||||
Type::PrefixInformation => write!(f, "prefix information"),
|
||||
Type::RedirectedHeader => write!(f, "redirected header"),
|
||||
Type::Mtu => write!(f, "mtu"),
|
||||
Type::Unknown(id) => write!(f, "{}", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -504,18 +504,18 @@ impl<'a> Repr<'a> {
|
|||
/// Emit a high-level representation into an NDISC Option.
|
||||
pub fn emit<T>(&self, opt: &mut NdiscOption<&'a mut T>)
|
||||
where T: AsRef<[u8]> + AsMut<[u8]> + ?Sized {
|
||||
match self {
|
||||
&Repr::SourceLinkLayerAddr(addr) => {
|
||||
match *self {
|
||||
Repr::SourceLinkLayerAddr(addr) => {
|
||||
opt.set_option_type(Type::SourceLinkLayerAddr);
|
||||
opt.set_data_len(1);
|
||||
opt.set_link_layer_addr(addr);
|
||||
},
|
||||
&Repr::TargetLinkLayerAddr(addr) => {
|
||||
Repr::TargetLinkLayerAddr(addr) => {
|
||||
opt.set_option_type(Type::TargetLinkLayerAddr);
|
||||
opt.set_data_len(1);
|
||||
opt.set_link_layer_addr(addr);
|
||||
},
|
||||
&Repr::PrefixInformation(PrefixInformation {
|
||||
Repr::PrefixInformation(PrefixInformation {
|
||||
prefix_len, flags, valid_lifetime,
|
||||
preferred_lifetime, prefix
|
||||
}) => {
|
||||
|
@ -528,7 +528,7 @@ impl<'a> Repr<'a> {
|
|||
opt.set_preferred_lifetime(preferred_lifetime);
|
||||
opt.set_prefix(prefix);
|
||||
},
|
||||
&Repr::RedirectedHeader(RedirectedHeader {
|
||||
Repr::RedirectedHeader(RedirectedHeader {
|
||||
header, data
|
||||
}) => {
|
||||
let data_len = data.len() / 8;
|
||||
|
@ -541,12 +541,12 @@ impl<'a> Repr<'a> {
|
|||
let payload = &mut ip_packet.into_inner()[header.buffer_len()..];
|
||||
payload.copy_from_slice(&data[..data_len]);
|
||||
}
|
||||
&Repr::Mtu(mtu) => {
|
||||
Repr::Mtu(mtu) => {
|
||||
opt.set_option_type(Type::Mtu);
|
||||
opt.set_data_len(1);
|
||||
opt.set_mtu(mtu);
|
||||
}
|
||||
&Repr::Unknown { type_: id, length, data } => {
|
||||
Repr::Unknown { type_: id, length, data } => {
|
||||
opt.set_option_type(Type::Unknown(id));
|
||||
opt.set_data_len(length);
|
||||
opt.data_mut().copy_from_slice(data);
|
||||
|
@ -558,29 +558,29 @@ impl<'a> Repr<'a> {
|
|||
impl<'a> fmt::Display for Repr<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "NDISC Option: ")?;
|
||||
match self {
|
||||
&Repr::SourceLinkLayerAddr(addr) => {
|
||||
match *self {
|
||||
Repr::SourceLinkLayerAddr(addr) => {
|
||||
write!(f, "SourceLinkLayer addr={}", addr)
|
||||
},
|
||||
&Repr::TargetLinkLayerAddr(addr) => {
|
||||
Repr::TargetLinkLayerAddr(addr) => {
|
||||
write!(f, "TargetLinkLayer addr={}", addr)
|
||||
},
|
||||
&Repr::PrefixInformation(PrefixInformation {
|
||||
Repr::PrefixInformation(PrefixInformation {
|
||||
prefix, prefix_len,
|
||||
..
|
||||
}) => {
|
||||
write!(f, "PrefixInformation prefix={}/{}", prefix, prefix_len)
|
||||
},
|
||||
&Repr::RedirectedHeader(RedirectedHeader {
|
||||
Repr::RedirectedHeader(RedirectedHeader {
|
||||
header,
|
||||
..
|
||||
}) => {
|
||||
write!(f, "RedirectedHeader header={}", header)
|
||||
},
|
||||
&Repr::Mtu(mtu) => {
|
||||
Repr::Mtu(mtu) => {
|
||||
write!(f, "MTU mtu={}", mtu)
|
||||
},
|
||||
&Repr::Unknown { type_: id, length, .. } => {
|
||||
Repr::Unknown { type_: id, length, .. } => {
|
||||
write!(f, "Unknown({}) length={}", id, length)
|
||||
}
|
||||
}
|
||||
|
@ -596,7 +596,7 @@ impl<T: AsRef<[u8]>> PrettyPrint for NdiscOption<T> {
|
|||
Err(err) => return write!(f, "{}({})", indent, err),
|
||||
Ok(ndisc) => {
|
||||
match Repr::parse(&ndisc) {
|
||||
Err(_) => return Ok(()),
|
||||
Err(_) => Ok(()),
|
||||
Ok(repr) => {
|
||||
write!(f, "{}{}", indent, repr)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ impl PrettyIndent {
|
|||
|
||||
/// Increase indentation level.
|
||||
pub fn increase(&mut self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "\n")?;
|
||||
writeln!(f)?;
|
||||
self.level += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -645,28 +645,28 @@ impl<'a> TcpOption<'a> {
|
|||
}
|
||||
|
||||
pub fn buffer_len(&self) -> usize {
|
||||
match self {
|
||||
&TcpOption::EndOfList => 1,
|
||||
&TcpOption::NoOperation => 1,
|
||||
&TcpOption::MaxSegmentSize(_) => 4,
|
||||
&TcpOption::WindowScale(_) => 3,
|
||||
&TcpOption::SackPermitted => 2,
|
||||
&TcpOption::SackRange(s) => s.iter().filter(|s| s.is_some()).count() * 8 + 2,
|
||||
&TcpOption::Unknown { data, .. } => 2 + data.len()
|
||||
match *self {
|
||||
TcpOption::EndOfList => 1,
|
||||
TcpOption::NoOperation => 1,
|
||||
TcpOption::MaxSegmentSize(_) => 4,
|
||||
TcpOption::WindowScale(_) => 3,
|
||||
TcpOption::SackPermitted => 2,
|
||||
TcpOption::SackRange(s) => s.iter().filter(|s| s.is_some()).count() * 8 + 2,
|
||||
TcpOption::Unknown { data, .. } => 2 + data.len()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn emit<'b>(&self, buffer: &'b mut [u8]) -> &'b mut [u8] {
|
||||
let length;
|
||||
match self {
|
||||
&TcpOption::EndOfList => {
|
||||
match *self {
|
||||
TcpOption::EndOfList => {
|
||||
length = 1;
|
||||
// There may be padding space which also should be initialized.
|
||||
for p in buffer.iter_mut() {
|
||||
*p = field::OPT_END;
|
||||
}
|
||||
}
|
||||
&TcpOption::NoOperation => {
|
||||
TcpOption::NoOperation => {
|
||||
length = 1;
|
||||
buffer[0] = field::OPT_NOP;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue