From c7c9f1dd03357a64384f04d4d100391175f1cd1a Mon Sep 17 00:00:00 2001 From: drunkirishcoder Date: Sat, 8 Jan 2022 01:54:29 -0500 Subject: [PATCH] remove ip4 and ip6 alias --- bench/packets.rs | 30 +++++------ core/src/packets/icmp/v4/echo_reply.rs | 6 +-- core/src/packets/icmp/v4/echo_request.rs | 6 +-- core/src/packets/icmp/v4/mod.rs | 28 +++++------ core/src/packets/icmp/v4/redirect.rs | 14 +++--- core/src/packets/icmp/v4/time_exceeded.rs | 14 +++--- core/src/packets/icmp/v6/echo_reply.rs | 6 +-- core/src/packets/icmp/v6/echo_request.rs | 6 +-- core/src/packets/icmp/v6/mod.rs | 28 +++++------ core/src/packets/icmp/v6/ndp/mod.rs | 50 +++++++++---------- .../packets/icmp/v6/ndp/neighbor_advert.rs | 6 +-- .../packets/icmp/v6/ndp/neighbor_solicit.rs | 6 +-- .../icmp/v6/ndp/options/link_layer_addr.rs | 10 ++-- core/src/packets/icmp/v6/ndp/options/mtu.rs | 10 ++-- .../icmp/v6/ndp/options/prefix_info.rs | 10 ++-- .../packets/icmp/v6/ndp/options/redirected.rs | 6 +-- core/src/packets/icmp/v6/ndp/redirect.rs | 10 ++-- core/src/packets/icmp/v6/ndp/router_advert.rs | 6 +-- .../src/packets/icmp/v6/ndp/router_solicit.rs | 6 +-- core/src/packets/icmp/v6/time_exceeded.rs | 10 ++-- core/src/packets/icmp/v6/too_big.rs | 10 ++-- core/src/packets/icmp/v6/unreachable.rs | 10 ++-- core/src/packets/ip/v4.rs | 17 +++---- core/src/packets/ip/v6/fragment.rs | 22 ++++---- core/src/packets/ip/v6/mod.rs | 15 +++--- core/src/packets/ip/v6/srh.rs | 36 ++++++------- core/src/packets/mod.rs | 16 +++--- core/src/packets/tcp.rs | 27 +++++----- core/src/packets/udp.rs | 21 ++++---- core/src/testils/packet.rs | 20 ++++---- core/src/testils/proptest/strategy.rs | 26 +++++----- examples/kni/main.rs | 10 ++-- examples/nat64/main.rs | 12 ++--- examples/ping4d/main.rs | 10 ++-- examples/pktdump/main.rs | 8 +-- examples/syn-flood/main.rs | 4 +- 36 files changed, 262 insertions(+), 270 deletions(-) diff --git a/bench/packets.rs b/bench/packets.rs index da63e79..7f8cca7 100644 --- a/bench/packets.rs +++ b/bench/packets.rs @@ -19,8 +19,8 @@ use anyhow::Result; use capsule::fieldmap; use capsule::packets::ethernet::Ethernet; -use capsule::packets::ip::v4::Ip4; -use capsule::packets::ip::v6::{Ip6, SegmentRouting}; +use capsule::packets::ip::v4::Ipv4; +use capsule::packets::ip::v6::{Ipv6, SegmentRouting}; use capsule::packets::udp::Udp4; use capsule::packets::{Mbuf, Packet}; use capsule::testils::criterion::BencherExt; @@ -32,11 +32,11 @@ use std::net::Ipv6Addr; const BATCH_SIZE: usize = 500; -fn single_parse_udp(ip4: Ip4) -> Udp4 { +fn single_parse_udp(ip4: Ipv4) -> Udp4 { ip4.parse::().unwrap() } -fn single_peek_udp(ip4: Ip4) -> Ip4 { +fn single_peek_udp(ip4: Ipv4) -> Ipv4 { ip4.peek::().unwrap(); ip4 } @@ -66,13 +66,13 @@ fn single_peek_vs_parse(c: &mut Criterion) { fn multi_parse_udp(mbuf: Mbuf) -> Udp4 { let ethernet = mbuf.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); ip4.parse::().unwrap() } fn multi_peek_udp(mbuf: Mbuf) -> Mbuf { let ethernet = mbuf.peek::().unwrap(); - let ip4 = ethernet.peek::().unwrap(); + let ip4 = ethernet.peek::().unwrap(); ip4.peek::().unwrap(); mbuf } @@ -94,8 +94,8 @@ fn multi_peek_vs_parse(c: &mut Criterion) { group.finish() } -fn single_parse_sr(ip6: Ip6) -> SegmentRouting { - ip6.parse::>().unwrap() +fn single_parse_sr(ip6: Ipv6) -> SegmentRouting { + ip6.parse::>().unwrap() } #[capsule::bench(mempool_capacity = 511)] @@ -135,10 +135,10 @@ fn single_parse_sr_segments_sizes(c: &mut Criterion) { group.finish() } -fn multi_parse_sr(mbuf: Mbuf) -> SegmentRouting { +fn multi_parse_sr(mbuf: Mbuf) -> SegmentRouting { let ethernet = mbuf.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - ip6.parse::>().unwrap() + let ip6 = ethernet.parse::().unwrap(); + ip6.parse::>().unwrap() } #[capsule::bench(mempool_capacity = 511)] @@ -177,7 +177,7 @@ fn reset(c: &mut Criterion) { fn multi_push_udp(mbuf: Mbuf) -> Udp4 { let ethernet = mbuf.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); + let ip4 = ethernet.push::().unwrap(); ip4.push::().unwrap() } @@ -189,7 +189,7 @@ fn multi_push(c: &mut Criterion) { }); } -fn single_push_udp(ip4: Ip4) -> Udp4 { +fn single_push_udp(ip4: Ipv4) -> Udp4 { ip4.push::().unwrap() } @@ -204,7 +204,7 @@ fn single_push(c: &mut Criterion) { }); } -fn single_remove_udp(udp: Udp4) -> Ip4 { +fn single_remove_udp(udp: Udp4) -> Ipv4 { udp.remove().unwrap() } @@ -230,7 +230,7 @@ fn multi_remove(c: &mut Criterion) { }); } -fn set_sr_segments(mut args: (SegmentRouting, Vec)) -> Result<()> { +fn set_sr_segments(mut args: (SegmentRouting, Vec)) -> Result<()> { args.0.set_segments(&args.1) } diff --git a/core/src/packets/icmp/v4/echo_reply.rs b/core/src/packets/icmp/v4/echo_reply.rs index dc6c482..3c99c15 100644 --- a/core/src/packets/icmp/v4/echo_reply.rs +++ b/core/src/packets/icmp/v4/echo_reply.rs @@ -222,7 +222,7 @@ struct EchoReplyBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v4::Ip4; + use crate::packets::ip::v4::Ipv4; use crate::packets::Mbuf; #[test] @@ -234,8 +234,8 @@ mod tests { fn push_and_set_echo_reply() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); - let mut echo = ip4.push::>().unwrap(); + let ip4 = ethernet.push::().unwrap(); + let mut echo = ip4.push::>().unwrap(); assert_eq!(4, echo.header_len()); assert_eq!(EchoReplyBody::size_of(), echo.payload_len()); diff --git a/core/src/packets/icmp/v4/echo_request.rs b/core/src/packets/icmp/v4/echo_request.rs index 0d8412d..73f8c27 100644 --- a/core/src/packets/icmp/v4/echo_request.rs +++ b/core/src/packets/icmp/v4/echo_request.rs @@ -223,7 +223,7 @@ struct EchoRequestBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v4::Ip4; + use crate::packets::ip::v4::Ipv4; use crate::packets::Mbuf; #[test] @@ -235,8 +235,8 @@ mod tests { fn push_and_set_echo_request() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); - let mut echo = ip4.push::>().unwrap(); + let ip4 = ethernet.push::().unwrap(); + let mut echo = ip4.push::>().unwrap(); assert_eq!(4, echo.header_len()); assert_eq!(EchoRequestBody::size_of(), echo.payload_len()); diff --git a/core/src/packets/icmp/v4/mod.rs b/core/src/packets/icmp/v4/mod.rs index 3ac2fdc..368ec99 100644 --- a/core/src/packets/icmp/v4/mod.rs +++ b/core/src/packets/icmp/v4/mod.rs @@ -449,7 +449,7 @@ pub trait Icmpv4Packet { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v4::Ip4; + use crate::packets::ip::v4::Ipv4; use crate::packets::Mbuf; use crate::testils::byte_arrays::{ICMPV4_PACKET, IPV4_UDP_PACKET}; @@ -462,8 +462,8 @@ mod tests { fn parse_icmpv4_packet() { let packet = Mbuf::from_bytes(&ICMPV4_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); - let icmp4 = ip4.parse::>().unwrap(); + let ip4 = ethernet.parse::().unwrap(); + let icmp4 = ip4.parse::>().unwrap(); // parses the generic header assert_eq!(Icmpv4Types::EchoRequest, icmp4.msg_type()); @@ -471,7 +471,7 @@ mod tests { assert_eq!(0x2a5c, icmp4.checksum()); // downcasts to specific message - let echo = icmp4.downcast::>().unwrap(); + let echo = icmp4.downcast::>().unwrap(); assert_eq!(Icmpv4Types::EchoRequest, echo.msg_type()); assert_eq!(0, echo.code()); assert_eq!(0x2a5c, echo.checksum()); @@ -480,34 +480,34 @@ mod tests { // also can one-step parse let ip4 = echo.deparse(); - assert!(ip4.parse::>().is_ok()); + assert!(ip4.parse::>().is_ok()); } #[capsule::test] fn parse_wrong_icmpv4_type() { let packet = Mbuf::from_bytes(&ICMPV4_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); - let icmp4 = ip4.parse::>().unwrap(); + let ip4 = ethernet.parse::().unwrap(); + let icmp4 = ip4.parse::>().unwrap(); - assert!(icmp4.downcast::>().is_err()); + assert!(icmp4.downcast::>().is_err()); } #[capsule::test] fn parse_non_icmpv4_packet() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); - assert!(ip4.parse::>().is_err()); + assert!(ip4.parse::>().is_err()); } #[capsule::test] fn compute_checksum() { let packet = Mbuf::from_bytes(&ICMPV4_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); - let mut icmp4 = ip4.parse::>().unwrap(); + let ip4 = ethernet.parse::().unwrap(); + let mut icmp4 = ip4.parse::>().unwrap(); let expected = icmp4.checksum(); // no payload change but force a checksum recompute anyway @@ -519,8 +519,8 @@ mod tests { fn push_icmpv4_header_without_body() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); + let ip4 = ethernet.push::().unwrap(); - assert!(ip4.push::>().is_err()); + assert!(ip4.push::>().is_err()); } } diff --git a/core/src/packets/icmp/v4/redirect.rs b/core/src/packets/icmp/v4/redirect.rs index 76d8f4f..570cdb7 100644 --- a/core/src/packets/icmp/v4/redirect.rs +++ b/core/src/packets/icmp/v4/redirect.rs @@ -219,7 +219,7 @@ impl Default for RedirectBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v4::Ip4; + use crate::packets::ip::v4::Ipv4; use crate::packets::Mbuf; use crate::testils::byte_arrays::IPV4_TCP_PACKET; @@ -232,10 +232,10 @@ mod tests { fn push_and_set_redirect() { let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let tcp_len = ip4.payload_len(); - let mut redirect = ip4.push::>().unwrap(); + let mut redirect = ip4.push::>().unwrap(); assert_eq!(4, redirect.header_len()); assert_eq!(RedirectBody::size_of() + tcp_len, redirect.payload_len()); @@ -259,8 +259,8 @@ mod tests { // starts with buffer larger than min MTU of 68 bytes. let packet = Mbuf::from_bytes(&[42; 100]).unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); - let mut redirect = ip4.push::>().unwrap(); + let ip4 = ethernet.push::().unwrap(); + let mut redirect = ip4.push::>().unwrap(); assert!(redirect.data_len() > IPV4_MIN_MTU); redirect.reconcile_all(); @@ -272,8 +272,8 @@ mod tests { // starts with buffer smaller than min MTU of 68 bytes. let packet = Mbuf::from_bytes(&[42; 50]).unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); - let mut redirect = ip4.push::>().unwrap(); + let ip4 = ethernet.push::().unwrap(); + let mut redirect = ip4.push::>().unwrap(); assert!(redirect.data_len() < IPV4_MIN_MTU); redirect.reconcile_all(); diff --git a/core/src/packets/icmp/v4/time_exceeded.rs b/core/src/packets/icmp/v4/time_exceeded.rs index 5391706..9e9a1ba 100644 --- a/core/src/packets/icmp/v4/time_exceeded.rs +++ b/core/src/packets/icmp/v4/time_exceeded.rs @@ -183,7 +183,7 @@ struct TimeExceededBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v4::Ip4; + use crate::packets::ip::v4::Ipv4; use crate::packets::Mbuf; use crate::testils::byte_arrays::IPV4_TCP_PACKET; @@ -196,10 +196,10 @@ mod tests { fn push_and_set_time_exceeded() { let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let tcp_len = ip4.payload_len(); - let mut exceeded = ip4.push::>().unwrap(); + let mut exceeded = ip4.push::>().unwrap(); assert_eq!(4, exceeded.header_len()); assert_eq!( @@ -222,8 +222,8 @@ mod tests { // starts with a buffer with a message body larger than min MTU. let packet = Mbuf::from_bytes(&[42; 100]).unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); - let mut exceeded = ip4.push::>().unwrap(); + let ip4 = ethernet.push::().unwrap(); + let mut exceeded = ip4.push::>().unwrap(); assert!(exceeded.data_len() > IPV4_MIN_MTU); exceeded.reconcile_all(); @@ -235,8 +235,8 @@ mod tests { // starts with a buffer with a message body smaller than min MTU. let packet = Mbuf::from_bytes(&[42; 50]).unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); - let mut exceeded = ip4.push::>().unwrap(); + let ip4 = ethernet.push::().unwrap(); + let mut exceeded = ip4.push::>().unwrap(); assert!(exceeded.data_len() < IPV4_MIN_MTU); exceeded.reconcile_all(); diff --git a/core/src/packets/icmp/v6/echo_reply.rs b/core/src/packets/icmp/v6/echo_reply.rs index 9664106..76254ff 100644 --- a/core/src/packets/icmp/v6/echo_reply.rs +++ b/core/src/packets/icmp/v6/echo_reply.rs @@ -218,7 +218,7 @@ struct EchoReplyBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; #[test] @@ -230,8 +230,8 @@ mod tests { fn push_and_set_echo_reply() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut echo = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut echo = ip6.push::>().unwrap(); assert_eq!(4, echo.header_len()); assert_eq!(EchoReplyBody::size_of(), echo.payload_len()); diff --git a/core/src/packets/icmp/v6/echo_request.rs b/core/src/packets/icmp/v6/echo_request.rs index 08e357e..5208481 100644 --- a/core/src/packets/icmp/v6/echo_request.rs +++ b/core/src/packets/icmp/v6/echo_request.rs @@ -219,7 +219,7 @@ struct EchoRequestBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; #[test] @@ -231,8 +231,8 @@ mod tests { fn push_and_set_echo_request() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut echo = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut echo = ip6.push::>().unwrap(); assert_eq!(4, echo.header_len()); assert_eq!(EchoRequestBody::size_of(), echo.payload_len()); diff --git a/core/src/packets/icmp/v6/mod.rs b/core/src/packets/icmp/v6/mod.rs index 03a1b16..c0551aa 100644 --- a/core/src/packets/icmp/v6/mod.rs +++ b/core/src/packets/icmp/v6/mod.rs @@ -500,7 +500,7 @@ mod tests { use super::*; use crate::packets::ethernet::Ethernet; use crate::packets::icmp::v6::ndp::RouterAdvertisement; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; use crate::testils::byte_arrays::{ICMPV6_PACKET, IPV6_TCP_PACKET, ROUTER_ADVERT_PACKET}; @@ -513,8 +513,8 @@ mod tests { fn parse_icmpv6_packet() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let icmp6 = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let icmp6 = ip6.parse::>().unwrap(); // parses the generic header assert_eq!(Icmpv6Types::RouterAdvertisement, icmp6.msg_type()); @@ -522,7 +522,7 @@ mod tests { assert_eq!(0xf50c, icmp6.checksum()); // downcasts to specific message - let advert = icmp6.downcast::>().unwrap(); + let advert = icmp6.downcast::>().unwrap(); assert_eq!(Icmpv6Types::RouterAdvertisement, advert.msg_type()); assert_eq!(0, advert.code()); assert_eq!(0xf50c, advert.checksum()); @@ -535,34 +535,34 @@ mod tests { // also can one-step parse let ip6 = advert.deparse(); - assert!(ip6.parse::>().is_ok()); + assert!(ip6.parse::>().is_ok()); } #[capsule::test] fn parse_wrong_icmpv6_type() { let packet = Mbuf::from_bytes(&ICMPV6_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let icmp6 = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let icmp6 = ip6.parse::>().unwrap(); - assert!(icmp6.downcast::>().is_err()); + assert!(icmp6.downcast::>().is_err()); } #[capsule::test] fn parse_non_icmpv6_packet() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); - assert!(ip6.parse::>().is_err()); + assert!(ip6.parse::>().is_err()); } #[capsule::test] fn compute_checksum() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut icmp6 = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut icmp6 = ip6.parse::>().unwrap(); let expected = icmp6.checksum(); // no payload change but force a checksum recompute anyway @@ -574,8 +574,8 @@ mod tests { fn push_icmpv6_header_without_body() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); + let ip6 = ethernet.push::().unwrap(); - assert!(ip6.push::>().is_err()); + assert!(ip6.push::>().is_err()); } } diff --git a/core/src/packets/icmp/v6/ndp/mod.rs b/core/src/packets/icmp/v6/ndp/mod.rs index 01977c5..9de511d 100644 --- a/core/src/packets/icmp/v6/ndp/mod.rs +++ b/core/src/packets/icmp/v6/ndp/mod.rs @@ -552,15 +552,15 @@ pub trait NdpOption<'a> { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::testils::byte_arrays::ROUTER_ADVERT_PACKET; #[capsule::test] fn iterate_immutable_ndp_options() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let advert = ip6.parse::>().unwrap(); let mut prefix = false; let mut mtu = false; @@ -588,8 +588,8 @@ mod tests { fn invalid_ndp_option_length() { let packet = Mbuf::from_bytes(&INVALID_OPTION_LENGTH).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let advert = ip6.parse::>().unwrap(); assert!(advert.options_iter().next().is_err()); } @@ -598,8 +598,8 @@ mod tests { fn downcast_immutable_ndp_option() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.peek::().unwrap(); - let ip6 = ethernet.peek::().unwrap(); - let advert = ip6.peek::>().unwrap(); + let ip6 = ethernet.peek::().unwrap(); + let advert = ip6.peek::>().unwrap(); let mut iter = advert.options_iter(); @@ -616,8 +616,8 @@ mod tests { fn iterate_mutable_ndp_options() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut prefix = false; let mut mtu = false; @@ -646,8 +646,8 @@ mod tests { fn downcast_mutable_ndp_option() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let mut iter = options.iter(); @@ -664,8 +664,8 @@ mod tests { fn modify_ndp_option() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let mut iter = options.iter(); @@ -683,8 +683,8 @@ mod tests { fn prepend_ndp_option() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let mut target = options.prepend::>().unwrap(); target.set_option_type_target(); @@ -699,8 +699,8 @@ mod tests { fn append_ndp_option() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let mut target = options.append::>().unwrap(); target.set_option_type_target(); @@ -723,8 +723,8 @@ mod tests { fn retain_ndp_options() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let _ = options.retain(|option| option.downcast::>().is_ok()); @@ -754,8 +754,8 @@ mod tests { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut iter = advert.options_iter(); advert.set_code(0); @@ -775,8 +775,8 @@ mod tests { fn cannot_mutate_immutable_option() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let advert = ip6.parse::>().unwrap(); let mut iter = advert.options_iter(); let mut option = iter.next().unwrap().unwrap(); @@ -802,8 +802,8 @@ mod tests { fn cannot_mutate_options_while_iterating_options() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let mut iter = options.iter(); diff --git a/core/src/packets/icmp/v6/ndp/neighbor_advert.rs b/core/src/packets/icmp/v6/ndp/neighbor_advert.rs index a178d16..548a80f 100644 --- a/core/src/packets/icmp/v6/ndp/neighbor_advert.rs +++ b/core/src/packets/icmp/v6/ndp/neighbor_advert.rs @@ -271,7 +271,7 @@ impl Default for NeighborAdvertisementBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; #[test] @@ -283,8 +283,8 @@ mod tests { fn push_and_set_neighbor_advertisement() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut advert = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut advert = ip6.push::>().unwrap(); assert_eq!(4, advert.header_len()); assert_eq!(NeighborAdvertisementBody::size_of(), advert.payload_len()); diff --git a/core/src/packets/icmp/v6/ndp/neighbor_solicit.rs b/core/src/packets/icmp/v6/ndp/neighbor_solicit.rs index d27bdd2..fe6b2ed 100644 --- a/core/src/packets/icmp/v6/ndp/neighbor_solicit.rs +++ b/core/src/packets/icmp/v6/ndp/neighbor_solicit.rs @@ -186,7 +186,7 @@ impl Default for NeighborSolicitationBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; #[test] @@ -198,8 +198,8 @@ mod tests { fn push_and_set_neighbor_solicitation() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut solicit = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut solicit = ip6.push::>().unwrap(); assert_eq!(4, solicit.header_len()); assert_eq!(NeighborSolicitationBody::size_of(), solicit.payload_len()); diff --git a/core/src/packets/icmp/v6/ndp/options/link_layer_addr.rs b/core/src/packets/icmp/v6/ndp/options/link_layer_addr.rs index 0b689e7..38b979d 100644 --- a/core/src/packets/icmp/v6/ndp/options/link_layer_addr.rs +++ b/core/src/packets/icmp/v6/ndp/options/link_layer_addr.rs @@ -192,7 +192,7 @@ mod tests { use super::*; use crate::packets::ethernet::Ethernet; use crate::packets::icmp::v6::ndp::{NdpPacket, RouterAdvertisement}; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Packet; use crate::testils::byte_arrays::ROUTER_ADVERT_PACKET; @@ -205,8 +205,8 @@ mod tests { fn parse_link_layer_address() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let mut iter = options.iter(); @@ -229,8 +229,8 @@ mod tests { fn push_and_set_link_layer_address() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut advert = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut advert = ip6.push::>().unwrap(); let mut options = advert.options_mut(); let mut lla = options.append::>().unwrap(); diff --git a/core/src/packets/icmp/v6/ndp/options/mtu.rs b/core/src/packets/icmp/v6/ndp/options/mtu.rs index 335cee0..d75e689 100644 --- a/core/src/packets/icmp/v6/ndp/options/mtu.rs +++ b/core/src/packets/icmp/v6/ndp/options/mtu.rs @@ -172,7 +172,7 @@ mod tests { use super::*; use crate::packets::ethernet::Ethernet; use crate::packets::icmp::v6::ndp::{NdpPacket, RouterAdvertisement}; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Packet; use crate::testils::byte_arrays::ROUTER_ADVERT_PACKET; @@ -185,8 +185,8 @@ mod tests { fn parse_mtu() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let mut iter = options.iter(); @@ -209,8 +209,8 @@ mod tests { fn push_and_set_mtu() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut advert = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut advert = ip6.push::>().unwrap(); let mut options = advert.options_mut(); let mut mtu = options.append::>().unwrap(); diff --git a/core/src/packets/icmp/v6/ndp/options/prefix_info.rs b/core/src/packets/icmp/v6/ndp/options/prefix_info.rs index 0ab6068..834d834 100644 --- a/core/src/packets/icmp/v6/ndp/options/prefix_info.rs +++ b/core/src/packets/icmp/v6/ndp/options/prefix_info.rs @@ -310,7 +310,7 @@ mod tests { use super::*; use crate::packets::ethernet::Ethernet; use crate::packets::icmp::v6::ndp::{NdpPacket, RouterAdvertisement}; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Packet; use crate::testils::byte_arrays::ROUTER_ADVERT_PACKET; @@ -323,8 +323,8 @@ mod tests { fn parse_prefix_information() { let packet = Mbuf::from_bytes(&ROUTER_ADVERT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut advert = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut advert = ip6.parse::>().unwrap(); let mut options = advert.options_mut(); let mut iter = options.iter(); @@ -355,8 +355,8 @@ mod tests { fn push_and_set_prefix_information() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut advert = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut advert = ip6.push::>().unwrap(); let mut options = advert.options_mut(); let mut prefix = options.append::>().unwrap(); diff --git a/core/src/packets/icmp/v6/ndp/options/redirected.rs b/core/src/packets/icmp/v6/ndp/options/redirected.rs index e755fbe..37d49a8 100644 --- a/core/src/packets/icmp/v6/ndp/options/redirected.rs +++ b/core/src/packets/icmp/v6/ndp/options/redirected.rs @@ -234,7 +234,7 @@ mod tests { use super::*; use crate::packets::ethernet::Ethernet; use crate::packets::icmp::v6::ndp::{NdpPacket, Redirect}; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Packet; #[test] @@ -249,8 +249,8 @@ mod tests { let packet = Mbuf::from_bytes(&data).unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut redirect = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut redirect = ip6.push::>().unwrap(); let mut options = redirect.options_mut(); let mut header = options.prepend::>().unwrap(); diff --git a/core/src/packets/icmp/v6/ndp/redirect.rs b/core/src/packets/icmp/v6/ndp/redirect.rs index 865a63d..8c00bfa 100644 --- a/core/src/packets/icmp/v6/ndp/redirect.rs +++ b/core/src/packets/icmp/v6/ndp/redirect.rs @@ -242,7 +242,7 @@ impl Default for RedirectBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; #[test] @@ -254,8 +254,8 @@ mod tests { fn push_and_set_redirect() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut redirect = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut redirect = ip6.push::>().unwrap(); assert_eq!(4, redirect.header_len()); assert_eq!(RedirectBody::size_of(), redirect.payload_len()); @@ -276,8 +276,8 @@ mod tests { // starts with a buffer larger than min MTU. let packet = Mbuf::from_bytes(&[42; 1600]).unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut redirect = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut redirect = ip6.push::>().unwrap(); let mut options = redirect.options_mut(); let _ = options.prepend::>().unwrap(); diff --git a/core/src/packets/icmp/v6/ndp/router_advert.rs b/core/src/packets/icmp/v6/ndp/router_advert.rs index a2d4904..98a76d1 100644 --- a/core/src/packets/icmp/v6/ndp/router_advert.rs +++ b/core/src/packets/icmp/v6/ndp/router_advert.rs @@ -302,7 +302,7 @@ struct RouterAdvertisementBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; #[test] @@ -314,8 +314,8 @@ mod tests { fn push_and_set_router_advertisement() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut advert = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut advert = ip6.push::>().unwrap(); assert_eq!(4, advert.header_len()); assert_eq!(RouterAdvertisementBody::size_of(), advert.payload_len()); diff --git a/core/src/packets/icmp/v6/ndp/router_solicit.rs b/core/src/packets/icmp/v6/ndp/router_solicit.rs index 8092ab6..5f8987e 100644 --- a/core/src/packets/icmp/v6/ndp/router_solicit.rs +++ b/core/src/packets/icmp/v6/ndp/router_solicit.rs @@ -144,7 +144,7 @@ struct RouterSolicitationBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; #[test] @@ -156,8 +156,8 @@ mod tests { fn push_and_set_router_solicitation() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut solicit = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut solicit = ip6.push::>().unwrap(); assert_eq!(4, solicit.header_len()); assert_eq!(RouterSolicitationBody::size_of(), solicit.payload_len()); diff --git a/core/src/packets/icmp/v6/time_exceeded.rs b/core/src/packets/icmp/v6/time_exceeded.rs index 817d21f..b60b668 100644 --- a/core/src/packets/icmp/v6/time_exceeded.rs +++ b/core/src/packets/icmp/v6/time_exceeded.rs @@ -164,7 +164,7 @@ struct TimeExceededBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; use crate::testils::byte_arrays::IPV6_TCP_PACKET; @@ -177,10 +177,10 @@ mod tests { fn push_and_set_time_exceeded() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); let tcp_len = ip6.payload_len(); - let mut exceeded = ip6.push::>().unwrap(); + let mut exceeded = ip6.push::>().unwrap(); assert_eq!(4, exceeded.header_len()); assert_eq!( @@ -203,12 +203,12 @@ mod tests { // starts with a buffer larger than min MTU. let packet = Mbuf::from_bytes(&[42; 1600]).unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); + let ip6 = ethernet.push::().unwrap(); // the max packet len is MTU + Ethernet header let max_len = IPV6_MIN_MTU + 14; - let mut exceeded = ip6.push::>().unwrap(); + let mut exceeded = ip6.push::>().unwrap(); assert!(exceeded.mbuf().data_len() > max_len); exceeded.reconcile_all(); diff --git a/core/src/packets/icmp/v6/too_big.rs b/core/src/packets/icmp/v6/too_big.rs index 32e2363..111fd93 100644 --- a/core/src/packets/icmp/v6/too_big.rs +++ b/core/src/packets/icmp/v6/too_big.rs @@ -189,7 +189,7 @@ struct PacketTooBigBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; use crate::testils::byte_arrays::IPV6_TCP_PACKET; @@ -202,10 +202,10 @@ mod tests { fn push_and_set_packet_too_big() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); let tcp_len = ip6.payload_len(); - let mut too_big = ip6.push::>().unwrap(); + let mut too_big = ip6.push::>().unwrap(); assert_eq!(4, too_big.header_len()); assert_eq!(PacketTooBigBody::size_of() + tcp_len, too_big.payload_len()); @@ -225,12 +225,12 @@ mod tests { // starts with a buffer. let packet = Mbuf::from_bytes(&[42; 1600]).unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); + let ip6 = ethernet.push::().unwrap(); // the max packet len is MTU + Ethernet header let max_len = IPV6_MIN_MTU + 14; - let mut too_big = ip6.push::>().unwrap(); + let mut too_big = ip6.push::>().unwrap(); assert!(too_big.mbuf().data_len() > max_len); too_big.reconcile_all(); diff --git a/core/src/packets/icmp/v6/unreachable.rs b/core/src/packets/icmp/v6/unreachable.rs index 1c44fe5..48c00e1 100644 --- a/core/src/packets/icmp/v6/unreachable.rs +++ b/core/src/packets/icmp/v6/unreachable.rs @@ -164,7 +164,7 @@ struct DestinationUnreachableBody { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; use crate::testils::byte_arrays::IPV6_TCP_PACKET; @@ -177,10 +177,10 @@ mod tests { fn push_and_set_destination_unreachable() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); let tcp_len = ip6.payload_len(); - let mut unreachable = ip6.push::>().unwrap(); + let mut unreachable = ip6.push::>().unwrap(); assert_eq!(4, unreachable.header_len()); assert_eq!( @@ -203,12 +203,12 @@ mod tests { // starts with a buffer larger than min MTU. let packet = Mbuf::from_bytes(&[42; 1600]).unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); + let ip6 = ethernet.push::().unwrap(); // the max packet len is MTU + Ethernet header let max_len = IPV6_MIN_MTU + 14; - let mut unreachable = ip6.push::>().unwrap(); + let mut unreachable = ip6.push::>().unwrap(); assert!(unreachable.mbuf().data_len() > max_len); unreachable.reconcile_all(); diff --git a/core/src/packets/ip/v4.rs b/core/src/packets/ip/v4.rs index e7cac00..4006ad7 100644 --- a/core/src/packets/ip/v4.rs +++ b/core/src/packets/ip/v4.rs @@ -143,7 +143,7 @@ const FLAGS_MF: u16be = u16be(u16::to_be(0b0010_0000_0000_0000)); /// [IETF RFC 791]: https://tools.ietf.org/html/rfc791#section-3.1 /// [IETF RFC 2474]: https://tools.ietf.org/html/rfc2474 /// [IETF RFC 3168]: https://tools.ietf.org/html/rfc3168 -pub struct Ipv4 { +pub struct Ipv4 { envelope: E, header: NonNull, offset: usize, @@ -579,9 +579,6 @@ impl Ipv4Packet for Ipv4 {} /// Used as a trait bound for packets succeding Ipv4. pub trait Ipv4Packet: IpPacket {} -/// A type alias for an Ethernet IPv4 packet. -pub type Ip4 = Ipv4; - /// IPv4 header. /// /// The header only include the fixed portion of the IPv4 header. @@ -634,7 +631,7 @@ mod tests { fn parse_ipv4_packet() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); assert_eq!(4, ip4.version()); assert_eq!(5, ip4.ihl()); @@ -657,14 +654,14 @@ mod tests { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - assert!(ethernet.parse::().is_err()); + assert!(ethernet.parse::().is_err()); } #[capsule::test] fn parse_ipv4_setter_checks() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let mut ip4 = ethernet.parse::().unwrap(); + let mut ip4 = ethernet.parse::().unwrap(); // Fields ip4.set_ihl(ip4.ihl()); @@ -699,7 +696,7 @@ mod tests { fn push_ipv4_packet() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); + let ip4 = ethernet.push::().unwrap(); assert_eq!(4, ip4.version()); assert_eq!(Ipv4Header::size_of(), ip4.len()); @@ -715,7 +712,7 @@ mod tests { let _ = packet.extend(0, 2000); let ethernet = packet.push::().unwrap(); - let mut ip4 = ethernet.push::().unwrap(); + let mut ip4 = ethernet.push::().unwrap(); // can't truncate to less than minimum MTU. assert!(ip4.truncate(60).is_err()); @@ -729,7 +726,7 @@ mod tests { fn compute_checksum() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let mut ip4 = ethernet.parse::().unwrap(); + let mut ip4 = ethernet.parse::().unwrap(); let expected = ip4.checksum(); // no payload change but force a checksum recompute anyway diff --git a/core/src/packets/ip/v6/fragment.rs b/core/src/packets/ip/v6/fragment.rs index 6ee7080..64e24f7 100644 --- a/core/src/packets/ip/v6/fragment.rs +++ b/core/src/packets/ip/v6/fragment.rs @@ -330,7 +330,7 @@ struct FragmentHeader { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::Mbuf; use crate::testils::byte_arrays::{IPV6_FRAGMENT_PACKET, IPV6_TCP_PACKET}; @@ -343,8 +343,8 @@ mod tests { fn parse_fragment_packet() { let packet = Mbuf::from_bytes(&IPV6_FRAGMENT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let frag = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let frag = ip6.parse::>().unwrap(); assert_eq!(ProtocolNumbers::Udp, frag.next_header()); assert_eq!(543, frag.fragment_offset()); @@ -356,17 +356,17 @@ mod tests { fn parse_non_fragment_packet() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); - assert!(ip6.parse::>().is_err()); + assert!(ip6.parse::>().is_err()); } #[capsule::test] fn push_and_set_fragment_packet() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); - let mut frag = ip6.push::>().unwrap(); + let ip6 = ethernet.push::().unwrap(); + let mut frag = ip6.push::>().unwrap(); assert_eq!(FragmentHeader::size_of(), frag.len()); assert_eq!(ProtocolNumbers::Ipv6Frag, frag.envelope().next_header()); @@ -393,11 +393,11 @@ mod tests { fn insert_fragment_packet() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); let next_header = ip6.next_header(); let payload_len = ip6.payload_len(); - let frag = ip6.push::>().unwrap(); + let frag = ip6.push::>().unwrap(); assert_eq!(ProtocolNumbers::Ipv6Frag, frag.envelope().next_header()); assert_eq!(next_header, frag.next_header()); @@ -408,8 +408,8 @@ mod tests { fn remove_fragment_packet() { let packet = Mbuf::from_bytes(&IPV6_FRAGMENT_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let frag = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let frag = ip6.parse::>().unwrap(); let next_header = frag.next_header(); let payload_len = frag.payload_len(); diff --git a/core/src/packets/ip/v6/mod.rs b/core/src/packets/ip/v6/mod.rs index bbbfaf6..796ac1e 100644 --- a/core/src/packets/ip/v6/mod.rs +++ b/core/src/packets/ip/v6/mod.rs @@ -96,7 +96,7 @@ const FLOW: u32be = u32be(u32::to_be(0xfffff)); /// [IETF RFC 8200]: https://tools.ietf.org/html/rfc8200#section-3 /// [IETF RFC 2474]: https://tools.ietf.org/html/rfc2474 /// [IETF RFC 3168]: https://tools.ietf.org/html/rfc3168 -pub struct Ipv6 { +pub struct Ipv6 { envelope: E, header: NonNull, offset: usize, @@ -438,9 +438,6 @@ pub trait Ipv6Packet: IpPacket { fn set_next_header(&mut self, next_header: ProtocolNumber); } -/// A type alias for an Ethernet IPv6 packet. -pub type Ip6 = Ipv6; - /// IPv6 header. #[derive(Clone, Copy, Debug, SizeOf)] #[repr(C)] @@ -482,7 +479,7 @@ mod tests { fn parse_ipv6_packet() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); assert_eq!(6, ip6.version()); assert_eq!(0, ip6.dscp()); @@ -500,14 +497,14 @@ mod tests { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - assert!(ethernet.parse::().is_err()); + assert!(ethernet.parse::().is_err()); } #[capsule::test] fn parse_ipv6_setter_checks() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let mut ip6 = ethernet.parse::().unwrap(); + let mut ip6 = ethernet.parse::().unwrap(); assert_eq!(6, ip6.version()); assert_eq!(0, ip6.dscp()); @@ -525,7 +522,7 @@ mod tests { fn push_ipv6_packet() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip6 = ethernet.push::().unwrap(); + let ip6 = ethernet.push::().unwrap(); assert_eq!(6, ip6.version()); assert_eq!(Ipv6Header::size_of(), ip6.len()); @@ -541,7 +538,7 @@ mod tests { let _ = packet.extend(0, 1800); let ethernet = packet.push::().unwrap(); - let mut ip6 = ethernet.push::().unwrap(); + let mut ip6 = ethernet.push::().unwrap(); // can't truncate to less than minimum MTU. assert!(ip6.truncate(1200).is_err()); diff --git a/core/src/packets/ip/v6/srh.rs b/core/src/packets/ip/v6/srh.rs index 7eb2762..6e8f215 100644 --- a/core/src/packets/ip/v6/srh.rs +++ b/core/src/packets/ip/v6/srh.rs @@ -524,7 +524,7 @@ impl Default for SegmentRoutingHeader { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v6::Ip6; + use crate::packets::ip::v6::Ipv6; use crate::packets::ip::ProtocolNumbers; use crate::packets::tcp::{Tcp, Tcp6}; use crate::packets::Mbuf; @@ -539,8 +539,8 @@ mod tests { fn parse_segment_routing_packet() { let packet = Mbuf::from_bytes(&SR_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let srh = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let srh = ip6.parse::>().unwrap(); assert_eq!(ProtocolNumbers::Tcp, srh.next_header()); assert_eq!(6, srh.hdr_ext_len()); @@ -560,17 +560,17 @@ mod tests { fn parse_non_segment_routing_packet() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); - assert!(ip6.parse::>().is_err()); + assert!(ip6.parse::>().is_err()); } #[capsule::test] fn set_segments() { let packet = Mbuf::from_bytes(&SR_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut srh = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut srh = ip6.parse::>().unwrap(); let segment1: Ipv6Addr = "::1".parse().unwrap(); @@ -597,7 +597,7 @@ mod tests { assert!(srh.set_segments(&[]).is_err()); // make sure rest of the packet still valid - let tcp = srh.parse::>>().unwrap(); + let tcp = srh.parse::>>().unwrap(); assert_eq!(3464, tcp.src_port()) } @@ -605,8 +605,8 @@ mod tests { fn compute_checksum() { let packet = Mbuf::from_bytes(&SR_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let mut srh = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let mut srh = ip6.parse::>().unwrap(); let segment1: Ipv6Addr = "::1".parse().unwrap(); let segment2: Ipv6Addr = "::2".parse().unwrap(); @@ -619,7 +619,7 @@ mod tests { assert_eq!(4, srh.segments().len()); srh.set_segments_left(3); - let mut tcp = srh.parse::>>().unwrap(); + let mut tcp = srh.parse::>>().unwrap(); // Should pass as we're using the hard-coded (and wrong) initial // checksum, as it's 0 given above. @@ -639,7 +639,7 @@ mod tests { assert_eq!(1, srh_ret.segments().len()); srh_ret.set_segments_left(0); - let mut tcp_ret = srh_ret.parse::>>().unwrap(); + let mut tcp_ret = srh_ret.parse::>>().unwrap(); tcp_ret.reconcile_all(); assert_eq!(expected, tcp_ret.checksum()); @@ -647,7 +647,7 @@ mod tests { // is still the same segment. let mut srh_fin = tcp_ret.deparse(); srh_fin.set_segments_left(0); - let mut tcp_fin = srh_fin.parse::>>().unwrap(); + let mut tcp_fin = srh_fin.parse::>>().unwrap(); tcp_fin.reconcile_all(); assert_eq!(expected, tcp_fin.checksum()); } @@ -656,9 +656,9 @@ mod tests { fn insert_segment_routing_packet() { let packet = Mbuf::from_bytes(&IPV6_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); + let ip6 = ethernet.parse::().unwrap(); let ip6_payload_len = ip6.payload_len(); - let srh = ip6.push::>().unwrap(); + let srh = ip6.push::>().unwrap(); assert_eq!(2, srh.hdr_ext_len()); assert_eq!(1, srh.segments().len()); @@ -671,7 +671,7 @@ mod tests { // ipv6 payload is srh payload after push assert_eq!(ip6_payload_len, srh.payload_len()); // make sure rest of the packet still valid - let tcp = srh.parse::>>().unwrap(); + let tcp = srh.parse::>>().unwrap(); assert_eq!(36869, tcp.src_port()); let mut srh = tcp.deparse(); @@ -686,8 +686,8 @@ mod tests { fn remove_segment_routing_packet() { let packet = Mbuf::from_bytes(&SR_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let srh = ip6.parse::>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let srh = ip6.parse::>().unwrap(); let ip6 = srh.remove().unwrap(); // make sure next header is fixed diff --git a/core/src/packets/mod.rs b/core/src/packets/mod.rs index 12bd6be..65df752 100644 --- a/core/src/packets/mod.rs +++ b/core/src/packets/mod.rs @@ -380,7 +380,7 @@ mod tests { use super::*; use crate::net::MacAddr; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v4::Ip4; + use crate::packets::ip::v4::Ipv4; use crate::packets::udp::Udp4; use crate::testils::byte_arrays::IPV4_UDP_PACKET; @@ -390,7 +390,7 @@ mod tests { let len = packet.data_len(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let udp = ip4.parse::().unwrap(); let reset = udp.reset(); @@ -403,7 +403,7 @@ mod tests { let ethernet = packet.peek::().unwrap(); assert_eq!(MacAddr::new(0, 0, 0, 0, 0, 2), ethernet.src()); - let ip4 = ethernet.peek::().unwrap(); + let ip4 = ethernet.peek::().unwrap(); assert_eq!(255, ip4.ttl()); let udp = ip4.peek::().unwrap(); assert_eq!(39376, udp.src_port()); @@ -413,7 +413,7 @@ mod tests { fn parse_and_deparse_packet() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let mut ip4 = ethernet.parse::().unwrap(); + let mut ip4 = ethernet.parse::().unwrap(); ip4.set_ttl(25); let udp = ip4.parse::().unwrap(); @@ -427,7 +427,7 @@ mod tests { fn remove_header_and_payload() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let mut udp = ip4.parse::().unwrap(); assert!(udp.payload_len() > 0); @@ -445,11 +445,11 @@ mod tests { /// borrow through peek. /// /// ``` - /// | let ipv4 = ethernet.peek::().unwrap(); + /// | let ip4 = ethernet.peek::().unwrap(); /// | -------- immutable borrow occurs here /// | ethernet.set_src(MacAddr::UNSPECIFIED); /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here - /// | assert!(ipv4.payload_len() > 0); + /// | assert!(ip4.payload_len() > 0); /// | ---- immutable borrow later used here /// ``` #[test] @@ -457,7 +457,7 @@ mod tests { fn cannot_mutate_packet_while_peeking_into_payload() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let mut ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.peek::().unwrap(); + let ip4 = ethernet.peek::().unwrap(); ethernet.set_src(MacAddr::UNSPECIFIED); assert!(ip4.payload_len() > 0); } diff --git a/core/src/packets/tcp.rs b/core/src/packets/tcp.rs index e8756dc..2eb28d3 100644 --- a/core/src/packets/tcp.rs +++ b/core/src/packets/tcp.rs @@ -19,8 +19,8 @@ //! Transmission Control Protocol. use crate::ensure; -use crate::packets::ip::v4::Ip4; -use crate::packets::ip::v6::Ip6; +use crate::packets::ip::v4::Ipv4; +use crate::packets::ip::v6::Ipv6; use crate::packets::ip::{Flow, IpPacket, ProtocolNumbers}; use crate::packets::types::{u16be, u32be}; use crate::packets::{checksum, Internal, Packet, SizeOf}; @@ -624,10 +624,10 @@ impl Packet for Tcp { } /// A type alias for an Ethernet IPv4 TCP packet. -pub type Tcp4 = Tcp; +pub type Tcp4 = Tcp; /// A type alias for an Ethernet IPv6 TCP packet. -pub type Tcp6 = Tcp; +pub type Tcp6 = Tcp; /// TCP header. /// @@ -667,7 +667,6 @@ impl Default for TcpHeader { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v4::Ip4; use crate::packets::ip::v6::SegmentRouting; use crate::packets::Mbuf; use crate::testils::byte_arrays::{IPV4_TCP_PACKET, IPV4_UDP_PACKET, SR_TCP_PACKET}; @@ -682,7 +681,7 @@ mod tests { fn parse_tcp_packet() { let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let tcp = ip4.parse::().unwrap(); assert_eq!(36869, tcp.src_port()); @@ -708,7 +707,7 @@ mod tests { fn parse_non_tcp_packet() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); assert!(ip4.parse::().is_err()); } @@ -717,7 +716,7 @@ mod tests { fn tcp_flow_v4() { let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let tcp = ip4.parse::().unwrap(); let flow = tcp.flow(); @@ -732,9 +731,9 @@ mod tests { fn tcp_flow_v6() { let packet = Mbuf::from_bytes(&SR_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip6 = ethernet.parse::().unwrap(); - let srh = ip6.parse::>().unwrap(); - let tcp = srh.parse::>>().unwrap(); + let ip6 = ethernet.parse::().unwrap(); + let srh = ip6.parse::>().unwrap(); + let tcp = srh.parse::>>().unwrap(); let flow = tcp.flow(); assert_eq!("2001:db8:85a3::1", flow.src_ip().to_string()); @@ -748,7 +747,7 @@ mod tests { fn set_src_dst_ip() { let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let mut tcp = ip4.parse::().unwrap(); let old_checksum = tcp.checksum(); @@ -771,7 +770,7 @@ mod tests { fn compute_checksum() { let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let mut tcp = ip4.parse::().unwrap(); let expected = tcp.checksum(); @@ -784,7 +783,7 @@ mod tests { fn push_tcp_packet() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); + let ip4 = ethernet.push::().unwrap(); let tcp = ip4.push::().unwrap(); assert_eq!(TcpHeader::size_of(), tcp.len()); diff --git a/core/src/packets/udp.rs b/core/src/packets/udp.rs index 83bcd7a..256c686 100644 --- a/core/src/packets/udp.rs +++ b/core/src/packets/udp.rs @@ -19,8 +19,8 @@ //! User Datagram Protocol. use crate::ensure; -use crate::packets::ip::v4::Ip4; -use crate::packets::ip::v6::Ip6; +use crate::packets::ip::v4::Ipv4; +use crate::packets::ip::v6::Ipv6; use crate::packets::ip::{Flow, IpPacket, ProtocolNumbers}; use crate::packets::types::u16be; use crate::packets::{checksum, Internal, Packet, SizeOf}; @@ -370,10 +370,10 @@ impl Packet for Udp { } /// A type alias for an Ethernet IPv4 UDP packet. -pub type Udp4 = Udp; +pub type Udp4 = Udp; /// A type alias for an Ethernet IPv6 UDP packet. -pub type Udp6 = Udp; +pub type Udp6 = Udp; /// UDP header. #[derive(Clone, Copy, Debug, Default, SizeOf)] @@ -389,7 +389,6 @@ struct UdpHeader { mod tests { use super::*; use crate::packets::ethernet::Ethernet; - use crate::packets::ip::v4::Ip4; use crate::packets::Mbuf; use crate::testils::byte_arrays::{IPV4_TCP_PACKET, IPV4_UDP_PACKET}; use std::net::{Ipv4Addr, Ipv6Addr}; @@ -403,7 +402,7 @@ mod tests { fn parse_udp_packet() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let udp = ip4.parse::().unwrap(); assert_eq!(39376, udp.src_port()); @@ -417,7 +416,7 @@ mod tests { fn parse_non_udp_packet() { let packet = Mbuf::from_bytes(&IPV4_TCP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); assert!(ip4.parse::().is_err()); } @@ -426,7 +425,7 @@ mod tests { fn udp_flow_v4() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let udp = ip4.parse::().unwrap(); let flow = udp.flow(); @@ -441,7 +440,7 @@ mod tests { fn set_src_dst_ip() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let mut udp = ip4.parse::().unwrap(); let old_checksum = udp.checksum(); @@ -464,7 +463,7 @@ mod tests { fn compute_checksum() { let packet = Mbuf::from_bytes(&IPV4_UDP_PACKET).unwrap(); let ethernet = packet.parse::().unwrap(); - let ip4 = ethernet.parse::().unwrap(); + let ip4 = ethernet.parse::().unwrap(); let mut udp = ip4.parse::().unwrap(); let expected = udp.checksum(); @@ -477,7 +476,7 @@ mod tests { fn push_udp_packet() { let packet = Mbuf::new().unwrap(); let ethernet = packet.push::().unwrap(); - let ip4 = ethernet.push::().unwrap(); + let ip4 = ethernet.push::().unwrap(); let udp = ip4.push::().unwrap(); assert_eq!(UdpHeader::size_of(), udp.len()); diff --git a/core/src/testils/packet.rs b/core/src/testils/packet.rs index a6e3dd2..ec04928 100644 --- a/core/src/testils/packet.rs +++ b/core/src/testils/packet.rs @@ -17,8 +17,8 @@ */ use crate::packets::ethernet::Ethernet; -use crate::packets::ip::v4::Ip4; -use crate::packets::ip::v6::{Ip6, SegmentRouting}; +use crate::packets::ip::v4::Ipv4; +use crate::packets::ip::v6::{Ipv6, SegmentRouting}; use crate::packets::tcp::{Tcp, Tcp4, Tcp6}; use crate::packets::udp::{Udp4, Udp6}; use crate::packets::Packet; @@ -37,8 +37,8 @@ pub trait PacketExt: Packet + Sized { } /// Converts the packet into an IPv4 packet. - fn into_ip4(self) -> Ip4 { - self.into_eth().parse::().unwrap() + fn into_ip4(self) -> Ipv4 { + self.into_eth().parse::().unwrap() } /// Converts the packet into a TCP packet inside IPv4. @@ -52,8 +52,8 @@ pub trait PacketExt: Packet + Sized { } /// Converts the packet into an IPv6 packet. - fn into_ip6(self) -> Ip6 { - self.into_eth().parse::().unwrap() + fn into_ip6(self) -> Ipv6 { + self.into_eth().parse::().unwrap() } /// Converts the packet into a TCP packet inside IPv6. @@ -67,13 +67,13 @@ pub trait PacketExt: Packet + Sized { } /// Converts the packet into an IPv6 packet with a SRH extension. - fn into_sr(self) -> SegmentRouting { - self.into_ip6().parse::>().unwrap() + fn into_sr(self) -> SegmentRouting { + self.into_ip6().parse::>().unwrap() } /// Converts the packet into a TCP packet inside IPv6 with a SRH extension. - fn into_sr_tcp(self) -> Tcp> { - self.into_sr().parse::>>().unwrap() + fn into_sr_tcp(self) -> Tcp> { + self.into_sr().parse::>>().unwrap() } } diff --git a/core/src/testils/proptest/strategy.rs b/core/src/testils/proptest/strategy.rs index 86af915..5e08e0a 100644 --- a/core/src/testils/proptest/strategy.rs +++ b/core/src/testils/proptest/strategy.rs @@ -20,8 +20,8 @@ use crate::net::MacAddr; use crate::packets::ethernet::{EtherType, EtherTypes, Ethernet}; -use crate::packets::ip::v4::Ip4; -use crate::packets::ip::v6::{Ip6, Ipv6Packet, SegmentRouting}; +use crate::packets::ip::v4::Ipv4; +use crate::packets::ip::v6::{Ipv6, Ipv6Packet, SegmentRouting}; use crate::packets::ip::{Flow, IpPacket, ProtocolNumber, ProtocolNumbers}; use crate::packets::tcp::Tcp; use crate::packets::udp::Udp; @@ -219,7 +219,7 @@ fn ethernet(ether_type: EtherType, map: &StrategyMap) -> impl Strategy impl Strategy { +fn ip4(protocol: ProtocolNumber, map: &StrategyMap) -> impl Strategy { ( ethernet(EtherTypes::Ipv4, map), map.ipv4_addr(&field::ipv4_src), @@ -245,7 +245,7 @@ fn ip4(protocol: ProtocolNumber, map: &StrategyMap) -> impl Strategy().unwrap(); + let mut packet = packet.push::().unwrap(); packet.set_src(src); packet.set_dst(dst); packet.set_dscp(dscp); @@ -265,7 +265,7 @@ fn ip4(protocol: ProtocolNumber, map: &StrategyMap) -> impl Strategy impl Strategy { +fn ip6(next_header: ProtocolNumber, map: &StrategyMap) -> impl Strategy { ( ethernet(EtherTypes::Ipv6, map), map.ipv6_addr(&field::ipv6_src), @@ -277,7 +277,7 @@ fn ip6(next_header: ProtocolNumber, map: &StrategyMap) -> impl Strategy().unwrap(); + let mut packet = packet.push::().unwrap(); packet.set_src(src); packet.set_dst(dst); packet.set_ecn(ecn); @@ -427,7 +427,7 @@ pub fn tcp4() -> impl Strategy { /// field::tcp_dst_port => 80 /// }))| { /// let packet = packet.parse::().unwrap(); -/// let ip4 = packet.parse::().unwrap(); +/// let ip4 = packet.parse::().unwrap(); /// assert_eq!("127.0.0.1".parse(), ip4.src()); /// let tcp = ip4.parse::().unwrap(); /// assert_eq!(80, tcp.dst_port()); @@ -465,7 +465,7 @@ pub fn udp4() -> impl Strategy { /// field::udp_dst_port => 53, /// }))| { /// let packet = packet.parse::().unwrap(); -/// let ip4 = packet.parse::().unwrap(); +/// let ip4 = packet.parse::().unwrap(); /// prop_assert_eq!("127.0.0.1".parse(), ip4.src()); /// let udp = ip4.parse::().unwrap(); /// prop_assert_eq!(53, udp.dst_port()); @@ -503,7 +503,7 @@ pub fn tcp6() -> impl Strategy { /// field::tcp_dst_port => 80, /// }))| { /// let packet = packet.parse::().unwrap(); -/// let ip6 = packet.parse::().unwrap(); +/// let ip6 = packet.parse::().unwrap(); /// prop_assert_eq!("::1".parse(), ip6.src()); /// let tcp = ip6.parse::().unwrap(); /// prop_assert_eq!(80, tcp.dst_port()); @@ -541,7 +541,7 @@ pub fn udp6() -> impl Strategy { /// field::udp_dst_port => 53, /// }))| { /// let packet = packet.parse::().unwrap(); -/// let ip6 = packet.parse::().unwrap(); +/// let ip6 = packet.parse::().unwrap(); /// prop_assert_eq!("::1".parse(), ip6.src()); /// let udp = ip6.parse::().unwrap(); /// prop_assert_eq!(53, udp.dst_port()); @@ -580,11 +580,11 @@ pub fn sr_tcp() -> impl Strategy { /// field::tcp_dst_port => 80, /// }))| { /// let packet = packet.parse::().unwrap(); -/// let ip6 = packet.parse::().unwrap(); +/// let ip6 = packet.parse::().unwrap(); /// prop_assert_eq!("::1".parse(), ip6.src()); -/// let sr = ip6.parse::>().unwrap(); +/// let sr = ip6.parse::>().unwrap(); /// prop_assert_eq!(2, sr.segments().len()); -/// let tcp = sr.parse::>>().unwrap(); +/// let tcp = sr.parse::>>().unwrap(); /// prop_assert_eq!(80, tcp.dst_port()); /// }); /// } diff --git a/examples/kni/main.rs b/examples/kni/main.rs index 4838258..10cbb51 100644 --- a/examples/kni/main.rs +++ b/examples/kni/main.rs @@ -19,7 +19,7 @@ use anyhow::Result; use capsule::packets::ethernet::Ethernet; use capsule::packets::icmp::v6::Icmpv6; -use capsule::packets::ip::v6::{Ip6, Ipv6Packet}; +use capsule::packets::ip::v6::{Ipv6, Ipv6Packet}; use capsule::packets::ip::ProtocolNumbers; use capsule::packets::udp::Udp6; use capsule::packets::{Mbuf, Packet, Postmark}; @@ -34,11 +34,11 @@ use tracing::{info, Level}; use tracing_subscriber::fmt; fn route_pkt(packet: Mbuf, kni0: &Outbox) -> Result { - let ip6 = packet.parse::()?.parse::()?; + let ip6 = packet.parse::()?.parse::()?; match ip6.next_header() { ProtocolNumbers::Icmpv6 => { - let icmp = ip6.parse::>()?; + let icmp = ip6.parse::>()?; let fmt = format!("to kni0: {}", icmp.msg_type()).cyan(); info!("{}", fmt); let _ = kni0.push(icmp); @@ -61,8 +61,8 @@ fn route_pkt(packet: Mbuf, kni0: &Outbox) -> Result { fn from_kni(packet: Mbuf, cap0: &Outbox) -> Result { let icmp = packet .parse::()? - .parse::()? - .parse::>()?; + .parse::()? + .parse::>()?; let fmt = format!("from kni0: {}", icmp.msg_type()).green(); info!("{}", fmt); diff --git a/examples/nat64/main.rs b/examples/nat64/main.rs index eced8fd..132b132 100644 --- a/examples/nat64/main.rs +++ b/examples/nat64/main.rs @@ -20,8 +20,8 @@ use anyhow::Result; use bimap::BiMap; use capsule::net::MacAddr; use capsule::packets::ethernet::Ethernet; -use capsule::packets::ip::v4::Ip4; -use capsule::packets::ip::v6::{Ip6, Ipv6Packet}; +use capsule::packets::ip::v4::Ipv4; +use capsule::packets::ip::v6::{Ipv6, Ipv6Packet}; use capsule::packets::ip::ProtocolNumbers; use capsule::packets::tcp::{Tcp4, Tcp6}; use capsule::packets::{Mbuf, Packet, Postmark}; @@ -70,7 +70,7 @@ fn nat_6to4(packet: Mbuf, cap1: &Outbox) -> Result { const DST_MAC: MacAddr = MacAddr::new(0x02, 0x00, 0x00, 0xff, 0xff, 0xff); let ethernet = packet.parse::()?; - let ip6 = ethernet.parse::()?; + let ip6 = ethernet.parse::()?; if ip6.next_header() == ProtocolNumbers::Tcp { let dscp = ip6.dscp(); @@ -85,7 +85,7 @@ fn nat_6to4(packet: Mbuf, cap1: &Outbox) -> Result { ethernet.swap_addresses(); ethernet.set_dst(DST_MAC); - let mut ip4 = ethernet.push::()?; + let mut ip4 = ethernet.push::()?; ip4.set_dscp(dscp); ip4.set_ecn(ecn); ip4.set_ttl(ttl); @@ -137,7 +137,7 @@ fn get_ip6_dst(port: u16) -> Option<(MacAddr, Ipv6Addr, u16)> { fn nat_4to6(packet: Mbuf, cap0: &Outbox) -> Result { let ethernet = packet.parse::()?; - let ip4 = ethernet.parse::()?; + let ip4 = ethernet.parse::()?; if ip4.protocol() == ProtocolNumbers::Tcp && ip4.fragment_offset() == 0 && !ip4.more_fragments() { @@ -154,7 +154,7 @@ fn nat_4to6(packet: Mbuf, cap0: &Outbox) -> Result { ethernet.swap_addresses(); ethernet.set_dst(dst_mac); - let mut ip6 = ethernet.push::()?; + let mut ip6 = ethernet.push::()?; ip6.set_dscp(dscp); ip6.set_ecn(ecn); ip6.set_next_header(next_header); diff --git a/examples/ping4d/main.rs b/examples/ping4d/main.rs index 1af2e39..137b108 100644 --- a/examples/ping4d/main.rs +++ b/examples/ping4d/main.rs @@ -19,7 +19,7 @@ use anyhow::Result; use capsule::packets::ethernet::Ethernet; use capsule::packets::icmp::v4::{EchoReply, EchoRequest}; -use capsule::packets::ip::v4::Ip4; +use capsule::packets::ip::v4::Ipv4; use capsule::packets::{Mbuf, Packet, Postmark}; use capsule::runtime::{self, Outbox, Runtime}; use signal_hook::consts; @@ -37,14 +37,14 @@ fn reply_echo(packet: Mbuf, cap0: &Outbox) -> Result { reply.set_src(ethernet.dst()); reply.set_dst(ethernet.src()); - let ip4 = ethernet.peek::()?; - let mut reply = reply.push::()?; + let ip4 = ethernet.peek::()?; + let mut reply = reply.push::()?; reply.set_src(ip4.dst()); reply.set_dst(ip4.src()); reply.set_ttl(255); - let request = ip4.peek::>()?; - let mut reply = reply.push::>()?; + let request = ip4.peek::>()?; + let mut reply = reply.push::>()?; reply.set_identifier(request.identifier()); reply.set_seq_no(request.seq_no()); reply.set_data(request.data())?; diff --git a/examples/pktdump/main.rs b/examples/pktdump/main.rs index cd3baf6..dcb946a 100644 --- a/examples/pktdump/main.rs +++ b/examples/pktdump/main.rs @@ -18,8 +18,8 @@ use anyhow::{anyhow, Result}; use capsule::packets::ethernet::{EtherTypes, Ethernet}; -use capsule::packets::ip::v4::Ip4; -use capsule::packets::ip::v6::Ip6; +use capsule::packets::ip::v4::Ipv4; +use capsule::packets::ip::v6::Ipv6; use capsule::packets::ip::IpPacket; use capsule::packets::tcp::{Tcp, Tcp4, Tcp6}; use capsule::packets::{Mbuf, Packet, Postmark}; @@ -48,7 +48,7 @@ fn dump_pkt(packet: Mbuf) -> Result { } fn dump_ip4(ethernet: &Ethernet) -> Result<()> { - let ip4 = ethernet.peek::()?; + let ip4 = ethernet.peek::()?; let fmt = format!("{:?}", ip4).yellow(); info!("{}", fmt); @@ -59,7 +59,7 @@ fn dump_ip4(ethernet: &Ethernet) -> Result<()> { } fn dump_ip6(ethernet: &Ethernet) -> Result<()> { - let ip6 = ethernet.peek::()?; + let ip6 = ethernet.peek::()?; let fmt = format!("{:?}", ip6).cyan(); info!("{}", fmt); diff --git a/examples/syn-flood/main.rs b/examples/syn-flood/main.rs index 865517f..fce4154 100644 --- a/examples/syn-flood/main.rs +++ b/examples/syn-flood/main.rs @@ -20,7 +20,7 @@ use anyhow::Result; use async_io::Timer; use capsule::net::MacAddr; use capsule::packets::ethernet::Ethernet; -use capsule::packets::ip::v4::Ip4; +use capsule::packets::ip::v4::Ipv4; use capsule::packets::tcp::Tcp4; use capsule::packets::{Mbuf, Packet}; use capsule::runtime::{self, Outbox, Runtime}; @@ -53,7 +53,7 @@ async fn syn_flood(src_mac: MacAddr, cap0: Outbox, term: Arc) { ethernet.set_src(src_mac); ethernet.set_dst(dst_mac); - let mut ip4 = ethernet.push::()?; + let mut ip4 = ethernet.push::()?; ip4.set_src(rand::random::().into()); ip4.set_dst(dst_ip);