mirror of
https://github.com/smoltcp-rs/smoltcp.git
synced 2025-09-27 04:40:30 +00:00
wire: Rename ipv4 protocol
to next_header
.
This improves v4/v6 consistency at the cost of slightly deviating from RFC names.
This commit is contained in:
parent
52628e2d4e
commit
028b4466ff
@ -85,7 +85,7 @@ mod wire {
|
||||
let repr = Ipv4Repr {
|
||||
src_addr: Ipv4Address([192, 168, 1, 1]),
|
||||
dst_addr: Ipv4Address([192, 168, 1, 2]),
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: 100,
|
||||
hop_limit: 64,
|
||||
};
|
||||
|
@ -1592,7 +1592,7 @@ impl<'a> InterfaceInner<'a> {
|
||||
|
||||
#[cfg(feature = "socket-dhcpv4")]
|
||||
{
|
||||
if ipv4_repr.protocol == IpProtocol::Udp && self.hardware_addr.is_some() {
|
||||
if ipv4_repr.next_header == IpProtocol::Udp && self.hardware_addr.is_some() {
|
||||
// First check for source and dest ports, then do `UdpRepr::parse` if they match.
|
||||
// This way we avoid validating the UDP checksum twice for all non-DHCP UDP packets (one here, one in `process_udp`)
|
||||
let udp_packet = UdpPacket::new_checked(ip_payload)?;
|
||||
@ -1637,7 +1637,7 @@ impl<'a> InterfaceInner<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
match ipv4_repr.protocol {
|
||||
match ipv4_repr.next_header {
|
||||
IpProtocol::Icmp => self.process_icmpv4(sockets, ip_repr, ip_payload),
|
||||
|
||||
#[cfg(feature = "proto-igmp")]
|
||||
@ -2027,7 +2027,7 @@ impl<'a> InterfaceInner<'a> {
|
||||
let ipv4_reply_repr = Ipv4Repr {
|
||||
src_addr: ipv4_repr.dst_addr,
|
||||
dst_addr: ipv4_repr.src_addr,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: icmp_repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -2040,7 +2040,7 @@ impl<'a> InterfaceInner<'a> {
|
||||
let ipv4_reply_repr = Ipv4Repr {
|
||||
src_addr: src_addr,
|
||||
dst_addr: ipv4_repr.src_addr,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: icmp_repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -2619,7 +2619,7 @@ impl<'a> InterfaceInner<'a> {
|
||||
src_addr: iface_addr,
|
||||
// Send to the group being reported
|
||||
dst_addr: group_addr,
|
||||
protocol: IpProtocol::Igmp,
|
||||
next_header: IpProtocol::Igmp,
|
||||
payload_len: igmp_repr.buffer_len(),
|
||||
hop_limit: 1,
|
||||
// TODO: add Router Alert IPv4 header option. See
|
||||
@ -2638,7 +2638,7 @@ impl<'a> InterfaceInner<'a> {
|
||||
Ipv4Repr {
|
||||
src_addr: iface_addr,
|
||||
dst_addr: Ipv4Address::MULTICAST_ALL_ROUTERS,
|
||||
protocol: IpProtocol::Igmp,
|
||||
next_header: IpProtocol::Igmp,
|
||||
payload_len: igmp_repr.buffer_len(),
|
||||
hop_limit: 1,
|
||||
},
|
||||
@ -2766,7 +2766,7 @@ mod test {
|
||||
let repr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]),
|
||||
dst_addr: Ipv4Address::BROADCAST,
|
||||
protocol: IpProtocol::Unknown(0x0c),
|
||||
next_header: IpProtocol::Unknown(0x0c),
|
||||
payload_len: 0,
|
||||
hop_limit: 0x40,
|
||||
});
|
||||
@ -2825,7 +2825,7 @@ mod test {
|
||||
let repr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]),
|
||||
dst_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]),
|
||||
protocol: IpProtocol::Unknown(0x0c),
|
||||
next_header: IpProtocol::Unknown(0x0c),
|
||||
payload_len: 0,
|
||||
hop_limit: 0x40,
|
||||
});
|
||||
@ -2841,7 +2841,7 @@ mod test {
|
||||
header: Ipv4Repr {
|
||||
src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]),
|
||||
dst_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]),
|
||||
protocol: IpProtocol::Unknown(12),
|
||||
next_header: IpProtocol::Unknown(12),
|
||||
payload_len: 0,
|
||||
hop_limit: 64,
|
||||
},
|
||||
@ -2852,7 +2852,7 @@ mod test {
|
||||
Ipv4Repr {
|
||||
src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]),
|
||||
dst_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]),
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: icmp_repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
},
|
||||
@ -2942,7 +2942,7 @@ mod test {
|
||||
let ip_repr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]),
|
||||
dst_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]),
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: udp_repr.header_len() + UDP_PAYLOAD.len(),
|
||||
hop_limit: 64,
|
||||
});
|
||||
@ -2966,7 +2966,7 @@ mod test {
|
||||
header: Ipv4Repr {
|
||||
src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]),
|
||||
dst_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]),
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: udp_repr.header_len() + UDP_PAYLOAD.len(),
|
||||
hop_limit: 64,
|
||||
},
|
||||
@ -2976,7 +2976,7 @@ mod test {
|
||||
Ipv4Repr {
|
||||
src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x01]),
|
||||
dst_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]),
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: icmp_repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
},
|
||||
@ -2995,7 +2995,7 @@ mod test {
|
||||
let ip_repr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: Ipv4Address([0x7f, 0x00, 0x00, 0x02]),
|
||||
dst_addr: Ipv4Address::BROADCAST,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: udp_repr.header_len() + UDP_PAYLOAD.len(),
|
||||
hop_limit: 64,
|
||||
});
|
||||
@ -3066,7 +3066,7 @@ mod test {
|
||||
let ip_repr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: src_ip,
|
||||
dst_addr: Ipv4Address::BROADCAST,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: udp_repr.header_len() + UDP_PAYLOAD.len(),
|
||||
hop_limit: 0x40,
|
||||
});
|
||||
@ -3126,7 +3126,7 @@ mod test {
|
||||
let ipv4_repr = Ipv4Repr {
|
||||
src_addr: src_ipv4_addr,
|
||||
dst_addr: Ipv4Address::BROADCAST,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
hop_limit: 64,
|
||||
payload_len: icmpv4_repr.buffer_len(),
|
||||
};
|
||||
@ -3154,7 +3154,7 @@ mod test {
|
||||
let expected_ipv4_repr = Ipv4Repr {
|
||||
src_addr: our_ipv4_addr,
|
||||
dst_addr: src_ipv4_addr,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
hop_limit: 64,
|
||||
payload_len: expected_icmpv4_repr.buffer_len(),
|
||||
};
|
||||
@ -3212,7 +3212,7 @@ mod test {
|
||||
let ip_repr = Ipv4Repr {
|
||||
src_addr: src_addr,
|
||||
dst_addr: dst_addr,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
hop_limit: 64,
|
||||
payload_len: udp_repr.header_len() + MAX_PAYLOAD_LEN,
|
||||
};
|
||||
@ -3251,7 +3251,7 @@ mod test {
|
||||
let expected_ip_repr = Ipv4Repr {
|
||||
src_addr: dst_addr,
|
||||
dst_addr: src_addr,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
hop_limit: 64,
|
||||
payload_len: expected_icmp_repr.buffer_len(),
|
||||
};
|
||||
@ -3561,7 +3561,7 @@ mod test {
|
||||
let ipv4_repr = Ipv4Repr {
|
||||
src_addr: Ipv4Address::new(0x7f, 0x00, 0x00, 0x02),
|
||||
dst_addr: Ipv4Address::new(0x7f, 0x00, 0x00, 0x01),
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: 24,
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -3734,7 +3734,7 @@ mod test {
|
||||
let reports = recv_igmp(&mut iface, timestamp);
|
||||
assert_eq!(reports.len(), 2);
|
||||
for (i, group_addr) in groups.iter().enumerate() {
|
||||
assert_eq!(reports[i].0.protocol, IpProtocol::Igmp);
|
||||
assert_eq!(reports[i].0.next_header, IpProtocol::Igmp);
|
||||
assert_eq!(reports[i].0.dst_addr, *group_addr);
|
||||
assert_eq!(
|
||||
reports[i].1,
|
||||
@ -3778,7 +3778,7 @@ mod test {
|
||||
let leaves = recv_igmp(&mut iface, timestamp);
|
||||
assert_eq!(leaves.len(), 2);
|
||||
for (i, group_addr) in groups.iter().cloned().enumerate() {
|
||||
assert_eq!(leaves[i].0.protocol, IpProtocol::Igmp);
|
||||
assert_eq!(leaves[i].0.next_header, IpProtocol::Igmp);
|
||||
assert_eq!(leaves[i].0.dst_addr, Ipv4Address::MULTICAST_ALL_ROUTERS);
|
||||
assert_eq!(leaves[i].1, IgmpRepr::LeaveGroup { group_addr });
|
||||
}
|
||||
@ -3824,7 +3824,7 @@ mod test {
|
||||
let ipv4_repr = Ipv4Repr {
|
||||
src_addr: src_addr,
|
||||
dst_addr: dst_addr,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
hop_limit: 64,
|
||||
payload_len: udp_repr.header_len() + PAYLOAD_LEN,
|
||||
};
|
||||
@ -3894,7 +3894,7 @@ mod test {
|
||||
let ipv4_repr = Ipv4Repr {
|
||||
src_addr: src_addr,
|
||||
dst_addr: dst_addr,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
hop_limit: 64,
|
||||
payload_len: udp_repr.header_len() + PAYLOAD_LEN,
|
||||
};
|
||||
@ -3985,7 +3985,7 @@ mod test {
|
||||
let ipv4_repr = Ipv4Repr {
|
||||
src_addr: src_addr,
|
||||
dst_addr: dst_addr,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
hop_limit: 64,
|
||||
payload_len: udp_repr.header_len() + UDP_PAYLOAD.len(),
|
||||
};
|
||||
|
@ -427,7 +427,7 @@ impl Dhcpv4Socket {
|
||||
let mut ipv4_repr = Ipv4Repr {
|
||||
src_addr: Ipv4Address::UNSPECIFIED,
|
||||
dst_addr: Ipv4Address::BROADCAST,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 0, // filled right before emit
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -606,7 +606,7 @@ mod test {
|
||||
let _ = s
|
||||
.socket
|
||||
.dispatch(&mut s.cx, |_, (mut ip_repr, udp_repr, dhcp_repr)| {
|
||||
assert_eq!(ip_repr.protocol, IpProtocol::Udp);
|
||||
assert_eq!(ip_repr.next_header, IpProtocol::Udp);
|
||||
assert_eq!(
|
||||
ip_repr.payload_len,
|
||||
udp_repr.header_len() + dhcp_repr.buffer_len()
|
||||
@ -671,7 +671,7 @@ mod test {
|
||||
const IP_BROADCAST: Ipv4Repr = Ipv4Repr {
|
||||
src_addr: Ipv4Address::UNSPECIFIED,
|
||||
dst_addr: Ipv4Address::BROADCAST,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 0,
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -679,7 +679,7 @@ mod test {
|
||||
const IP_SERVER_BROADCAST: Ipv4Repr = Ipv4Repr {
|
||||
src_addr: SERVER_IP,
|
||||
dst_addr: Ipv4Address::BROADCAST,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 0,
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -687,7 +687,7 @@ mod test {
|
||||
const IP_RECV: Ipv4Repr = Ipv4Repr {
|
||||
src_addr: SERVER_IP,
|
||||
dst_addr: MY_IP,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 0,
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -695,7 +695,7 @@ mod test {
|
||||
const IP_SEND: Ipv4Repr = Ipv4Repr {
|
||||
src_addr: MY_IP,
|
||||
dst_addr: SERVER_IP,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 0,
|
||||
hop_limit: 64,
|
||||
};
|
||||
|
@ -453,7 +453,7 @@ impl<'a> IcmpSocket<'a> {
|
||||
let ip_repr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: Ipv4Address::default(),
|
||||
dst_addr: ipv4_addr,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: repr.buffer_len(),
|
||||
hop_limit: hop_limit,
|
||||
});
|
||||
@ -549,7 +549,7 @@ mod test_ipv4 {
|
||||
static LOCAL_IPV4_REPR: IpRepr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: Ipv4Address::UNSPECIFIED,
|
||||
dst_addr: REMOTE_IPV4,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: 24,
|
||||
hop_limit: 0x40,
|
||||
});
|
||||
@ -557,7 +557,7 @@ mod test_ipv4 {
|
||||
static REMOTE_IPV4_REPR: IpRepr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: REMOTE_IPV4,
|
||||
dst_addr: LOCAL_IPV4,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: 24,
|
||||
hop_limit: 0x40,
|
||||
});
|
||||
@ -650,7 +650,7 @@ mod test_ipv4 {
|
||||
IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: Ipv4Address::UNSPECIFIED,
|
||||
dst_addr: REMOTE_IPV4,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: ECHOV4_REPR.buffer_len(),
|
||||
hop_limit: 0x2a,
|
||||
})
|
||||
@ -741,7 +741,7 @@ mod test_ipv4 {
|
||||
header: Ipv4Repr {
|
||||
src_addr: LOCAL_IPV4,
|
||||
dst_addr: REMOTE_IPV4,
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: 12,
|
||||
hop_limit: 0x40,
|
||||
},
|
||||
@ -750,7 +750,7 @@ mod test_ipv4 {
|
||||
let ip_repr = IpRepr::Unspecified {
|
||||
src_addr: REMOTE_IPV4.into(),
|
||||
dst_addr: LOCAL_IPV4.into(),
|
||||
protocol: IpProtocol::Icmp,
|
||||
next_header: IpProtocol::Icmp,
|
||||
payload_len: icmp_repr.buffer_len(),
|
||||
hop_limit: 0x40,
|
||||
};
|
||||
@ -1018,7 +1018,7 @@ mod test_ipv6 {
|
||||
let ip_repr = IpRepr::Unspecified {
|
||||
src_addr: REMOTE_IPV6.into(),
|
||||
dst_addr: LOCAL_IPV6.into(),
|
||||
protocol: IpProtocol::Icmpv6,
|
||||
next_header: IpProtocol::Icmpv6,
|
||||
payload_len: icmp_repr.buffer_len(),
|
||||
hop_limit: 0x40,
|
||||
};
|
||||
|
@ -205,7 +205,7 @@ impl<'a> RawSocket<'a> {
|
||||
if ip_repr.version() != self.ip_version {
|
||||
return false;
|
||||
}
|
||||
if ip_repr.protocol() != self.ip_protocol {
|
||||
if ip_repr.next_header() != self.ip_protocol {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ impl<'a> RawSocket<'a> {
|
||||
F: FnOnce(&mut Context, (IpRepr, &[u8])) -> Result<()>,
|
||||
{
|
||||
fn prepare<'a>(
|
||||
protocol: IpProtocol,
|
||||
next_header: IpProtocol,
|
||||
buffer: &'a mut [u8],
|
||||
_checksum_caps: &ChecksumCapabilities,
|
||||
) -> Result<(IpRepr, &'a [u8])> {
|
||||
@ -252,7 +252,7 @@ impl<'a> RawSocket<'a> {
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
IpVersion::Ipv4 => {
|
||||
let mut packet = Ipv4Packet::new_checked(buffer)?;
|
||||
if packet.protocol() != protocol {
|
||||
if packet.next_header() != next_header {
|
||||
return Err(Error::Unaddressable);
|
||||
}
|
||||
if _checksum_caps.ipv4.tx() {
|
||||
@ -270,7 +270,7 @@ impl<'a> RawSocket<'a> {
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
IpVersion::Ipv6 => {
|
||||
let packet = Ipv6Packet::new_checked(buffer)?;
|
||||
if packet.next_header() != protocol {
|
||||
if packet.next_header() != next_header {
|
||||
return Err(Error::Unaddressable);
|
||||
}
|
||||
let packet = Ipv6Packet::new_unchecked(&*packet.into_inner());
|
||||
@ -358,7 +358,7 @@ mod test {
|
||||
pub const HEADER_REPR: IpRepr = IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: Ipv4Address([10, 0, 0, 1]),
|
||||
dst_addr: Ipv4Address([10, 0, 0, 2]),
|
||||
protocol: IpProtocol::Unknown(IP_PROTO),
|
||||
next_header: IpProtocol::Unknown(IP_PROTO),
|
||||
payload_len: 4,
|
||||
hop_limit: 64,
|
||||
});
|
||||
@ -521,7 +521,7 @@ mod test {
|
||||
assert_eq!(socket.dispatch(&mut cx, |_, _| unreachable!()), Ok(()));
|
||||
|
||||
let mut wrong_protocol = ipv4_locals::PACKET_BYTES;
|
||||
Ipv4Packet::new_unchecked(&mut wrong_protocol).set_protocol(IpProtocol::Tcp);
|
||||
Ipv4Packet::new_unchecked(&mut wrong_protocol).set_next_header(IpProtocol::Tcp);
|
||||
|
||||
assert_eq!(socket.send_slice(&wrong_protocol[..]), Ok(()));
|
||||
assert_eq!(socket.dispatch(&mut cx, |_, _| unreachable!()), Ok(()));
|
||||
|
@ -1140,7 +1140,7 @@ impl<'a> TcpSocket<'a> {
|
||||
let ip_reply_repr = IpRepr::Unspecified {
|
||||
src_addr: ip_repr.dst_addr(),
|
||||
dst_addr: ip_repr.src_addr(),
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: reply_repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -2139,7 +2139,7 @@ impl<'a> TcpSocket<'a> {
|
||||
let mut ip_repr = IpRepr::Unspecified {
|
||||
src_addr: self.local_endpoint.addr,
|
||||
dst_addr: self.remote_endpoint.addr,
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
hop_limit: self.hop_limit.unwrap_or(64),
|
||||
payload_len: 0,
|
||||
}
|
||||
@ -2443,7 +2443,7 @@ mod test {
|
||||
const SEND_IP_TEMPL: IpRepr = IpRepr::Unspecified {
|
||||
src_addr: MOCK_IP_ADDR_1,
|
||||
dst_addr: MOCK_IP_ADDR_2,
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: 20,
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -2463,7 +2463,7 @@ mod test {
|
||||
const _RECV_IP_TEMPL: IpRepr = IpRepr::Unspecified {
|
||||
src_addr: MOCK_IP_ADDR_1,
|
||||
dst_addr: MOCK_IP_ADDR_2,
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: 20,
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -2518,7 +2518,7 @@ mod test {
|
||||
let ip_repr = IpRepr::Unspecified {
|
||||
src_addr: MOCK_IP_ADDR_2,
|
||||
dst_addr: MOCK_IP_ADDR_1,
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -2547,7 +2547,7 @@ mod test {
|
||||
.dispatch(&mut socket.cx, |_, (ip_repr, tcp_repr)| {
|
||||
let ip_repr = ip_repr.lower(&[IpCidr::new(LOCAL_END.addr, 24)]).unwrap();
|
||||
|
||||
assert_eq!(ip_repr.protocol(), IpProtocol::Tcp);
|
||||
assert_eq!(ip_repr.next_header(), IpProtocol::Tcp);
|
||||
assert_eq!(ip_repr.src_addr(), MOCK_IP_ADDR_1);
|
||||
assert_eq!(ip_repr.dst_addr(), MOCK_IP_ADDR_2);
|
||||
assert_eq!(ip_repr.payload_len(), tcp_repr.buffer_len());
|
||||
@ -2641,7 +2641,7 @@ mod test {
|
||||
fn socket_syn_sent_with_buffer_sizes(tx_len: usize, rx_len: usize) -> TestSocket {
|
||||
let mut s = socket_with_buffer_sizes(tx_len, rx_len);
|
||||
s.state = State::SynSent;
|
||||
s.local_endpoint = IpEndpoint::new(MOCK_UNSPECIFIED, LOCAL_PORT);
|
||||
s.local_endpoint = LOCAL_END;
|
||||
s.remote_endpoint = REMOTE_END;
|
||||
s.local_seq_no = LOCAL_SEQ;
|
||||
s.remote_last_seq = LOCAL_SEQ;
|
||||
@ -6948,7 +6948,7 @@ mod test {
|
||||
let ip_repr = IpRepr::Unspecified {
|
||||
src_addr: MOCK_IP_ADDR_2,
|
||||
dst_addr: MOCK_IP_ADDR_1,
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: tcp_repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -6957,7 +6957,7 @@ mod test {
|
||||
let ip_repr_wrong_src = IpRepr::Unspecified {
|
||||
src_addr: MOCK_IP_ADDR_3,
|
||||
dst_addr: MOCK_IP_ADDR_1,
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: tcp_repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -6966,7 +6966,7 @@ mod test {
|
||||
let ip_repr_wrong_dst = IpRepr::Unspecified {
|
||||
src_addr: MOCK_IP_ADDR_2,
|
||||
dst_addr: MOCK_IP_ADDR_3,
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: tcp_repr.buffer_len(),
|
||||
hop_limit: 64,
|
||||
};
|
||||
|
@ -362,7 +362,7 @@ impl<'a> UdpSocket<'a> {
|
||||
let ip_repr = IpRepr::Unspecified {
|
||||
src_addr: endpoint.addr,
|
||||
dst_addr: remote_endpoint.addr,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: repr.header_len() + payload_buf.len(),
|
||||
hop_limit: hop_limit,
|
||||
};
|
||||
@ -423,7 +423,7 @@ mod test {
|
||||
pub const LOCAL_IP_REPR: IpRepr = IpRepr::Unspecified {
|
||||
src_addr: MOCK_IP_ADDR_1,
|
||||
dst_addr: MOCK_IP_ADDR_2,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 8 + 6,
|
||||
hop_limit: 64,
|
||||
};
|
||||
@ -446,7 +446,7 @@ mod test {
|
||||
(IpAddress::Ipv4(src), IpAddress::Ipv4(dst)) => IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: src,
|
||||
dst_addr: dst,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 8 + 6,
|
||||
hop_limit: 64,
|
||||
}),
|
||||
@ -655,7 +655,7 @@ mod test {
|
||||
IpRepr::Unspecified {
|
||||
src_addr: MOCK_IP_ADDR_1,
|
||||
dst_addr: MOCK_IP_ADDR_2,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 8 + 6,
|
||||
hop_limit: 0x2a,
|
||||
}
|
||||
@ -687,7 +687,7 @@ mod test {
|
||||
(IpAddress::Ipv4(src), IpAddress::Ipv4(dst)) => IpRepr::Ipv4(Ipv4Repr {
|
||||
src_addr: src,
|
||||
dst_addr: dst,
|
||||
protocol: IpProtocol::Udp,
|
||||
next_header: IpProtocol::Udp,
|
||||
payload_len: 8 + 6,
|
||||
hop_limit: 64,
|
||||
}),
|
||||
|
@ -417,7 +417,7 @@ impl<'a> Repr<'a> {
|
||||
header: Ipv4Repr {
|
||||
src_addr: ip_packet.src_addr(),
|
||||
dst_addr: ip_packet.dst_addr(),
|
||||
protocol: ip_packet.protocol(),
|
||||
next_header: ip_packet.next_header(),
|
||||
payload_len: payload.len(),
|
||||
hop_limit: ip_packet.hop_limit(),
|
||||
},
|
||||
|
@ -516,7 +516,7 @@ pub enum Repr {
|
||||
Unspecified {
|
||||
src_addr: Address,
|
||||
dst_addr: Address,
|
||||
protocol: Protocol,
|
||||
next_header: Protocol,
|
||||
payload_len: usize,
|
||||
hop_limit: u8,
|
||||
},
|
||||
@ -574,12 +574,12 @@ impl Repr {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the protocol.
|
||||
pub fn protocol(&self) -> Protocol {
|
||||
/// Return the next header (protocol).
|
||||
pub fn next_header(&self) -> Protocol {
|
||||
match *self {
|
||||
Repr::Unspecified { protocol, .. } => protocol,
|
||||
Repr::Unspecified { next_header, .. } => next_header,
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
Repr::Ipv4(repr) => repr.protocol,
|
||||
Repr::Ipv4(repr) => repr.next_header,
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
Repr::Ipv6(repr) => repr.next_header,
|
||||
}
|
||||
@ -658,14 +658,14 @@ impl Repr {
|
||||
&Repr::Unspecified {
|
||||
src_addr: src_addr @ Address::Unspecified,
|
||||
dst_addr: Address::Ipv4(dst_addr),
|
||||
protocol,
|
||||
next_header,
|
||||
payload_len,
|
||||
hop_limit,
|
||||
}
|
||||
| &Repr::Unspecified {
|
||||
src_addr: src_addr @ Address::Ipv4(_),
|
||||
dst_addr: Address::Ipv4(dst_addr),
|
||||
protocol,
|
||||
next_header,
|
||||
payload_len,
|
||||
hop_limit,
|
||||
} if src_addr.is_unspecified() => {
|
||||
@ -683,7 +683,7 @@ impl Repr {
|
||||
Ok(Repr::Ipv4(Ipv4Repr {
|
||||
src_addr: src_addr.ok_or(Error::Unaddressable)?,
|
||||
dst_addr,
|
||||
protocol,
|
||||
next_header,
|
||||
payload_len,
|
||||
hop_limit,
|
||||
}))
|
||||
@ -693,14 +693,14 @@ impl Repr {
|
||||
&Repr::Unspecified {
|
||||
src_addr: src_addr @ Address::Unspecified,
|
||||
dst_addr: Address::Ipv6(dst_addr),
|
||||
protocol,
|
||||
next_header: protocol,
|
||||
payload_len,
|
||||
hop_limit,
|
||||
}
|
||||
| &Repr::Unspecified {
|
||||
src_addr: src_addr @ Address::Ipv6(_),
|
||||
dst_addr: Address::Ipv6(dst_addr),
|
||||
protocol,
|
||||
next_header: protocol,
|
||||
payload_len,
|
||||
hop_limit,
|
||||
} if src_addr.is_unspecified() => {
|
||||
@ -728,13 +728,13 @@ impl Repr {
|
||||
&Repr::Unspecified {
|
||||
src_addr: Address::Ipv4(src_addr),
|
||||
dst_addr: Address::Ipv4(dst_addr),
|
||||
protocol,
|
||||
next_header: protocol,
|
||||
payload_len,
|
||||
hop_limit,
|
||||
} => Ok(Repr::Ipv4(Ipv4Repr {
|
||||
src_addr: src_addr,
|
||||
dst_addr: dst_addr,
|
||||
protocol: protocol,
|
||||
next_header: protocol,
|
||||
payload_len: payload_len,
|
||||
hop_limit,
|
||||
})),
|
||||
@ -743,7 +743,7 @@ impl Repr {
|
||||
&Repr::Unspecified {
|
||||
src_addr: Address::Ipv6(src_addr),
|
||||
dst_addr: Address::Ipv6(dst_addr),
|
||||
protocol,
|
||||
next_header: protocol,
|
||||
payload_len,
|
||||
hop_limit,
|
||||
} => Ok(Repr::Ipv6(Ipv6Repr {
|
||||
@ -869,14 +869,14 @@ pub mod checksum {
|
||||
pub fn pseudo_header(
|
||||
src_addr: &Address,
|
||||
dst_addr: &Address,
|
||||
protocol: Protocol,
|
||||
next_header: Protocol,
|
||||
length: u32,
|
||||
) -> u16 {
|
||||
match (src_addr, dst_addr) {
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
(&Address::Ipv4(src_addr), &Address::Ipv4(dst_addr)) => {
|
||||
let mut proto_len = [0u8; 4];
|
||||
proto_len[1] = protocol.into();
|
||||
proto_len[1] = next_header.into();
|
||||
NetworkEndian::write_u16(&mut proto_len[2..4], length as u16);
|
||||
|
||||
combine(&[
|
||||
@ -889,7 +889,7 @@ pub mod checksum {
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
(&Address::Ipv6(src_addr), &Address::Ipv6(dst_addr)) => {
|
||||
let mut proto_len = [0u8; 8];
|
||||
proto_len[7] = protocol.into();
|
||||
proto_len[7] = next_header.into();
|
||||
NetworkEndian::write_u32(&mut proto_len[0..4], length);
|
||||
combine(&[
|
||||
data(src_addr.as_bytes()),
|
||||
@ -932,7 +932,7 @@ pub fn pretty_print_ip_payload<T: Into<Repr>>(
|
||||
|
||||
let checksum_caps = ChecksumCapabilities::ignored();
|
||||
let repr = ip_repr.into();
|
||||
match repr.protocol() {
|
||||
match repr.next_header() {
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
Protocol::Icmp => {
|
||||
indent.increase(f)?;
|
||||
@ -1033,7 +1033,7 @@ pub(crate) mod test {
|
||||
|
||||
macro_rules! generate_common_tests {
|
||||
($name:ident, $repr:ident, $ip_repr:path, $ip_addr:path,
|
||||
$addr_from:path, $nxthdr:ident, $bytes_a:expr, $bytes_b:expr,
|
||||
$addr_from:path, $bytes_a:expr, $bytes_b:expr,
|
||||
$unspecified:expr) => {
|
||||
mod $name {
|
||||
use super::*;
|
||||
@ -1049,7 +1049,7 @@ pub(crate) mod test {
|
||||
Repr::Unspecified {
|
||||
src_addr: $ip_addr(ip_addr_a),
|
||||
dst_addr: $ip_addr(ip_addr_b),
|
||||
protocol: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 0x2a,
|
||||
payload_len,
|
||||
}
|
||||
@ -1057,7 +1057,7 @@ pub(crate) mod test {
|
||||
Ok($ip_repr($repr {
|
||||
src_addr: ip_addr_a,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 0x2a,
|
||||
payload_len
|
||||
}))
|
||||
@ -1067,7 +1067,7 @@ pub(crate) mod test {
|
||||
Repr::Unspecified {
|
||||
src_addr: IpAddress::Unspecified,
|
||||
dst_addr: $ip_addr(ip_addr_b),
|
||||
protocol: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
}
|
||||
@ -1079,7 +1079,7 @@ pub(crate) mod test {
|
||||
Repr::Unspecified {
|
||||
src_addr: IpAddress::Unspecified,
|
||||
dst_addr: $ip_addr(ip_addr_b),
|
||||
protocol: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
}
|
||||
@ -1087,7 +1087,7 @@ pub(crate) mod test {
|
||||
Ok($ip_repr($repr {
|
||||
src_addr: ip_addr_a,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
}))
|
||||
@ -1097,7 +1097,7 @@ pub(crate) mod test {
|
||||
Repr::Unspecified {
|
||||
src_addr: $ip_addr($unspecified),
|
||||
dst_addr: $ip_addr(ip_addr_b),
|
||||
protocol: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
}
|
||||
@ -1105,7 +1105,7 @@ pub(crate) mod test {
|
||||
Ok($ip_repr($repr {
|
||||
src_addr: ip_addr_a,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
}))
|
||||
@ -1115,7 +1115,7 @@ pub(crate) mod test {
|
||||
Repr::Unspecified {
|
||||
src_addr: $ip_addr($unspecified),
|
||||
dst_addr: $ip_addr(ip_addr_b),
|
||||
protocol: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
}
|
||||
@ -1123,7 +1123,7 @@ pub(crate) mod test {
|
||||
Ok($ip_repr($repr {
|
||||
src_addr: $unspecified,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
}))
|
||||
@ -1133,7 +1133,7 @@ pub(crate) mod test {
|
||||
$ip_repr($repr {
|
||||
src_addr: ip_addr_a,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 255,
|
||||
payload_len
|
||||
})
|
||||
@ -1141,7 +1141,7 @@ pub(crate) mod test {
|
||||
Ok($ip_repr($repr {
|
||||
src_addr: ip_addr_a,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 255,
|
||||
payload_len
|
||||
}))
|
||||
@ -1151,7 +1151,7 @@ pub(crate) mod test {
|
||||
$ip_repr($repr {
|
||||
src_addr: $unspecified,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 255,
|
||||
payload_len
|
||||
})
|
||||
@ -1163,7 +1163,7 @@ pub(crate) mod test {
|
||||
$ip_repr($repr {
|
||||
src_addr: $unspecified,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
})
|
||||
@ -1171,7 +1171,7 @@ pub(crate) mod test {
|
||||
Ok($ip_repr($repr {
|
||||
src_addr: ip_addr_a,
|
||||
dst_addr: ip_addr_b,
|
||||
$nxthdr: proto,
|
||||
next_header: proto,
|
||||
hop_limit: 64,
|
||||
payload_len
|
||||
}))
|
||||
@ -1186,7 +1186,6 @@ pub(crate) mod test {
|
||||
Repr::Ipv4,
|
||||
IpAddress::Ipv4,
|
||||
Ipv4Address::from_bytes,
|
||||
protocol,
|
||||
$addr_bytes_a,
|
||||
$addr_bytes_b,
|
||||
Ipv4Address::UNSPECIFIED
|
||||
@ -1199,7 +1198,6 @@ pub(crate) mod test {
|
||||
Repr::Ipv6,
|
||||
IpAddress::Ipv6,
|
||||
Ipv6Address::from_bytes,
|
||||
next_header,
|
||||
$addr_bytes_a,
|
||||
$addr_bytes_b,
|
||||
Ipv6Address::UNSPECIFIED
|
||||
@ -1224,7 +1222,7 @@ pub(crate) mod test {
|
||||
Repr::Unspecified {
|
||||
src_addr: Address::Ipv6(Ipv6Address::UNSPECIFIED),
|
||||
dst_addr: Address::Ipv4(Ipv4Address::UNSPECIFIED),
|
||||
protocol: IpProtocol::Icmpv6,
|
||||
next_header: IpProtocol::Icmpv6,
|
||||
hop_limit: 0xff,
|
||||
payload_len: 0,
|
||||
}
|
||||
|
@ -396,9 +396,9 @@ impl<T: AsRef<[u8]>> Packet<T> {
|
||||
data[field::TTL]
|
||||
}
|
||||
|
||||
/// Return the protocol field.
|
||||
/// Return the next_header (protocol) field.
|
||||
#[inline]
|
||||
pub fn protocol(&self) -> Protocol {
|
||||
pub fn next_header(&self) -> Protocol {
|
||||
let data = self.buffer.as_ref();
|
||||
Protocol::from(data[field::PROTOCOL])
|
||||
}
|
||||
@ -532,9 +532,9 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
|
||||
data[field::TTL] = value
|
||||
}
|
||||
|
||||
/// Set the protocol field.
|
||||
/// Set the next header (protocol) field.
|
||||
#[inline]
|
||||
pub fn set_protocol(&mut self, value: Protocol) {
|
||||
pub fn set_next_header(&mut self, value: Protocol) {
|
||||
let data = self.buffer.as_mut();
|
||||
data[field::PROTOCOL] = value.into()
|
||||
}
|
||||
@ -591,7 +591,7 @@ impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T> {
|
||||
pub struct Repr {
|
||||
pub src_addr: Address,
|
||||
pub dst_addr: Address,
|
||||
pub protocol: Protocol,
|
||||
pub next_header: Protocol,
|
||||
pub payload_len: usize,
|
||||
pub hop_limit: u8,
|
||||
}
|
||||
@ -626,7 +626,7 @@ impl Repr {
|
||||
Ok(Repr {
|
||||
src_addr: packet.src_addr(),
|
||||
dst_addr: packet.dst_addr(),
|
||||
protocol: packet.protocol(),
|
||||
next_header: packet.next_header(),
|
||||
payload_len: payload_len,
|
||||
hop_limit: packet.hop_limit(),
|
||||
})
|
||||
@ -656,7 +656,7 @@ impl Repr {
|
||||
packet.set_dont_frag(true);
|
||||
packet.set_frag_offset(0);
|
||||
packet.set_hop_limit(self.hop_limit);
|
||||
packet.set_protocol(self.protocol);
|
||||
packet.set_next_header(self.next_header);
|
||||
packet.set_src_addr(self.src_addr);
|
||||
packet.set_dst_addr(self.dst_addr);
|
||||
|
||||
@ -681,7 +681,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Packet<&'a T> {
|
||||
" src={} dst={} proto={} hop_limit={}",
|
||||
self.src_addr(),
|
||||
self.dst_addr(),
|
||||
self.protocol(),
|
||||
self.next_header(),
|
||||
self.hop_limit()
|
||||
)?;
|
||||
if self.version() != 4 {
|
||||
@ -720,7 +720,7 @@ impl fmt::Display for Repr {
|
||||
write!(
|
||||
f,
|
||||
"IPv4 src={} dst={} proto={}",
|
||||
self.src_addr, self.dst_addr, self.protocol
|
||||
self.src_addr, self.dst_addr, self.next_header
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -777,7 +777,7 @@ mod test {
|
||||
assert!(packet.dont_frag());
|
||||
assert_eq!(packet.frag_offset(), 0x203 * 8);
|
||||
assert_eq!(packet.hop_limit(), 0x1a);
|
||||
assert_eq!(packet.protocol(), Protocol::Icmp);
|
||||
assert_eq!(packet.next_header(), Protocol::Icmp);
|
||||
assert_eq!(packet.checksum(), 0xd56e);
|
||||
assert_eq!(packet.src_addr(), Address([0x11, 0x12, 0x13, 0x14]));
|
||||
assert_eq!(packet.dst_addr(), Address([0x21, 0x22, 0x23, 0x24]));
|
||||
@ -800,7 +800,7 @@ mod test {
|
||||
packet.set_dont_frag(true);
|
||||
packet.set_frag_offset(0x203 * 8);
|
||||
packet.set_hop_limit(0x1a);
|
||||
packet.set_protocol(Protocol::Icmp);
|
||||
packet.set_next_header(Protocol::Icmp);
|
||||
packet.set_src_addr(Address([0x11, 0x12, 0x13, 0x14]));
|
||||
packet.set_dst_addr(Address([0x21, 0x22, 0x23, 0x24]));
|
||||
packet.fill_checksum();
|
||||
@ -844,7 +844,7 @@ mod test {
|
||||
Repr {
|
||||
src_addr: Address([0x11, 0x12, 0x13, 0x14]),
|
||||
dst_addr: Address([0x21, 0x22, 0x23, 0x24]),
|
||||
protocol: Protocol::Icmp,
|
||||
next_header: Protocol::Icmp,
|
||||
payload_len: 4,
|
||||
hop_limit: 64,
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ use smoltcp::wire::*;
|
||||
let repr = Ipv4Repr {
|
||||
src_addr: Ipv4Address::new(10, 0, 0, 1),
|
||||
dst_addr: Ipv4Address::new(10, 0, 0, 2),
|
||||
protocol: IpProtocol::Tcp,
|
||||
next_header: IpProtocol::Tcp,
|
||||
payload_len: 10,
|
||||
hop_limit: 64
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user