summaryrefslogtreecommitdiff
path: root/src/packet/packet.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/packet/packet.rs')
-rw-r--r--src/packet/packet.rs666
1 files changed, 333 insertions, 333 deletions
diff --git a/src/packet/packet.rs b/src/packet/packet.rs
index e42dd2f..0576f70 100644
--- a/src/packet/packet.rs
+++ b/src/packet/packet.rs
@@ -1,49 +1,49 @@
use crate::packet::error::PacketError;
use crate::protocol::codec::Decode;
-use crate::protocol::ethernet::EtherType;
-use crate::protocol::ethernet::EthernetFrame;
-use crate::protocol::grev0::Grev0Header;
-use crate::protocol::grev1::Grev1Header;
-use crate::protocol::gtpv1::Gtpv1Header;
-use crate::protocol::icmp::IcmpHeader;
-use crate::protocol::icmpv6::Icmpv6Header;
+use crate::protocol::ethernet::EthHeader;
+use crate::protocol::ethernet::EthType;
+use crate::protocol::grev0::GREv0Header;
+use crate::protocol::grev1::GREv1Header;
+use crate::protocol::gtpv1::GTPv1Header;
+use crate::protocol::icmp::ICMPHeader;
+use crate::protocol::icmpv6::ICMPv6Header;
use crate::protocol::ip::IPProtocol;
-use crate::protocol::ipv4::Ipv4Header;
-use crate::protocol::ipv6::Ipv6Header;
-use crate::protocol::l2tp::L2tpHeader;
-use crate::protocol::l2tp::L2tpType;
-use crate::protocol::mpls::MplsHeader;
-use crate::protocol::mpls::PwEthHeader;
-use crate::protocol::ppp::PppHeader;
-use crate::protocol::ppp::PppProtocol;
-use crate::protocol::pptp::PptpHeader;
-use crate::protocol::tcp::TcpHeader;
-use crate::protocol::udp::UdpHeader;
-use crate::protocol::vlan::VlanHeader;
+use crate::protocol::ipv4::IPv4Header;
+use crate::protocol::ipv6::IPv6Header;
+use crate::protocol::l2tp::L2TPHeader;
+use crate::protocol::l2tp::L2TPType;
+use crate::protocol::mpls::MPLSHeader;
+use crate::protocol::mpls::PWEthHeader;
+use crate::protocol::ppp::PPPHeader;
+use crate::protocol::ppp::PPPProtocol;
+use crate::protocol::pptp::PPTPHeader;
+use crate::protocol::tcp::TCPHeader;
+use crate::protocol::udp::UDPHeader;
+use crate::protocol::vlan::VLANHeader;
use nom::Err::Incomplete;
#[derive(Clone, Debug, PartialEq)]
pub enum Encapsulation<'a> {
- Eth(EthernetFrame, &'a [u8]),
- Vlan(VlanHeader, &'a [u8]),
- Mpls(MplsHeader, &'a [u8]),
- PwEth(PwEthHeader, &'a [u8]),
-
- Ipv4(Ipv4Header, &'a [u8]),
- Ipv6(Ipv6Header, &'a [u8]),
-
- Grev0(Grev0Header, &'a [u8]),
- Grev1(Grev1Header, &'a [u8]),
-
- Tcp(TcpHeader, &'a [u8]),
- Udp(UdpHeader, &'a [u8]),
- Icmp(IcmpHeader, &'a [u8]),
- Icmpv6(Icmpv6Header, &'a [u8]),
-
- Gtpv1(Gtpv1Header, &'a [u8]),
- L2tp(L2tpHeader, &'a [u8]),
- Pptp(PptpHeader, &'a [u8]),
- Ppp(PppHeader, &'a [u8]),
+ ETH(EthHeader, &'a [u8]),
+ VLAN(VLANHeader, &'a [u8]),
+ MPLS(MPLSHeader, &'a [u8]),
+ PWETH(PWEthHeader, &'a [u8]),
+
+ IPv4(IPv4Header, &'a [u8]),
+ IPv6(IPv6Header, &'a [u8]),
+
+ GREv0(GREv0Header, &'a [u8]),
+ GREv1(GREv1Header, &'a [u8]),
+
+ TCP(TCPHeader, &'a [u8]),
+ UDP(UDPHeader, &'a [u8]),
+ ICMP(ICMPHeader, &'a [u8]),
+ ICMPv6(ICMPv6Header, &'a [u8]),
+
+ GTPv1(GTPv1Header, &'a [u8]),
+ L2TP(L2TPHeader, &'a [u8]),
+ PPTP(PPTPHeader, &'a [u8]),
+ PPP(PPPHeader, &'a [u8]),
}
#[derive(Debug)]
@@ -69,14 +69,14 @@ impl Packet<'_> {
return handle_eth(self, self.orig_data);
}
- pub fn get_outer_l3_layer(&self) -> Option<Encapsulation> {
+ pub fn get_outer_most_l3_layer(&self) -> Option<Encapsulation> {
let num = self.encapsulation.len();
for i in 0..num {
match self.encapsulation[i] {
- Encapsulation::Ipv4(_, _) => {
+ Encapsulation::IPv4(_, _) => {
return Some(self.encapsulation[i].clone());
}
- Encapsulation::Ipv6(_, _) => {
+ Encapsulation::IPv6(_, _) => {
return Some(self.encapsulation[i].clone());
}
_ => continue,
@@ -86,14 +86,14 @@ impl Packet<'_> {
return None;
}
- pub fn get_inner_l3_layer(&self) -> Option<Encapsulation> {
+ pub fn get_inner_most_l3_layer(&self) -> Option<Encapsulation> {
let num = self.encapsulation.len();
for i in (0..num).rev() {
match self.encapsulation[i] {
- Encapsulation::Ipv4(_, _) => {
+ Encapsulation::IPv4(_, _) => {
return Some(self.encapsulation[i].clone());
}
- Encapsulation::Ipv6(_, _) => {
+ Encapsulation::IPv6(_, _) => {
return Some(self.encapsulation[i].clone());
}
_ => continue,
@@ -103,14 +103,14 @@ impl Packet<'_> {
return None;
}
- pub fn get_outer_l4_layer(&self) -> Option<Encapsulation> {
+ pub fn get_outer_most_l4_layer(&self) -> Option<Encapsulation> {
let num = self.encapsulation.len();
for i in 0..num {
match self.encapsulation[i] {
- Encapsulation::Tcp(_, _) => {
+ Encapsulation::TCP(_, _) => {
return Some(self.encapsulation[i].clone());
}
- Encapsulation::Udp(_, _) => {
+ Encapsulation::UDP(_, _) => {
return Some(self.encapsulation[i].clone());
}
_ => continue,
@@ -120,14 +120,14 @@ impl Packet<'_> {
return None;
}
- pub fn get_inner_l4_layer(&self) -> Option<Encapsulation> {
+ pub fn get_inner_most_l4_layer(&self) -> Option<Encapsulation> {
let num = self.encapsulation.len();
for i in (0..num).rev() {
match self.encapsulation[i] {
- Encapsulation::Tcp(_, _) => {
+ Encapsulation::TCP(_, _) => {
return Some(self.encapsulation[i].clone());
}
- Encapsulation::Udp(_, _) => {
+ Encapsulation::UDP(_, _) => {
return Some(self.encapsulation[i].clone());
}
_ => continue,
@@ -137,17 +137,17 @@ impl Packet<'_> {
return None;
}
- pub fn get_outer_address(&self) -> Option<(String, String)> {
+ pub fn get_outer_most_address(&self) -> Option<(String, String)> {
let num = self.encapsulation.len();
for i in 0..num {
match self.encapsulation[i] {
- Encapsulation::Ipv4(ref header, _) => {
+ Encapsulation::IPv4(ref header, _) => {
return Some((
header.source_address.to_string(),
header.dest_address.to_string(),
));
}
- Encapsulation::Ipv6(ref header, _) => {
+ Encapsulation::IPv6(ref header, _) => {
return Some((
header.source_address.to_string(),
header.dest_address.to_string(),
@@ -160,17 +160,17 @@ impl Packet<'_> {
return None;
}
- pub fn get_inner_address(&self) -> Option<(String, String)> {
+ pub fn get_inner_most_address(&self) -> Option<(String, String)> {
let num = self.encapsulation.len();
for i in (0..num).rev() {
match self.encapsulation[i] {
- Encapsulation::Ipv4(ref header, _) => {
+ Encapsulation::IPv4(ref header, _) => {
return Some((
header.source_address.to_string(),
header.dest_address.to_string(),
));
}
- Encapsulation::Ipv6(ref header, _) => {
+ Encapsulation::IPv6(ref header, _) => {
return Some((
header.source_address.to_string(),
header.dest_address.to_string(),
@@ -183,14 +183,14 @@ impl Packet<'_> {
return None;
}
- pub fn get_outer_port(&self) -> Option<(u16, u16)> {
+ pub fn get_outer_most_port(&self) -> Option<(u16, u16)> {
let num = self.encapsulation.len();
for i in 0..num {
match self.encapsulation[i] {
- Encapsulation::Tcp(ref header, _) => {
+ Encapsulation::TCP(ref header, _) => {
return Some((header.source_port, header.dest_port));
}
- Encapsulation::Udp(ref header, _) => {
+ Encapsulation::UDP(ref header, _) => {
return Some((header.source_port, header.dest_port));
}
_ => continue,
@@ -200,14 +200,14 @@ impl Packet<'_> {
return None;
}
- pub fn get_inner_port(&self) -> Option<(u16, u16)> {
+ pub fn get_inner_most_port(&self) -> Option<(u16, u16)> {
let num = self.encapsulation.len();
for i in (0..num).rev() {
match self.encapsulation[i] {
- Encapsulation::Tcp(ref header, _) => {
+ Encapsulation::TCP(ref header, _) => {
return Some((header.source_port, header.dest_port));
}
- Encapsulation::Udp(ref header, _) => {
+ Encapsulation::UDP(ref header, _) => {
return Some((header.source_port, header.dest_port));
}
_ => continue,
@@ -217,15 +217,15 @@ impl Packet<'_> {
return None;
}
- pub fn get_outer_tuple(&self) -> Option<(String, u16, String, u16)> {
+ pub fn get_outer_most_tuple(&self) -> Option<(String, u16, String, u16)> {
let num = self.encapsulation.len();
if num < 2 {
return None;
}
for i in 0..num - 1 {
match self.encapsulation[i] {
- Encapsulation::Ipv4(ref l3_header, _) => match self.encapsulation[i + 1] {
- Encapsulation::Tcp(ref l4_header, _) => {
+ Encapsulation::IPv4(ref l3_header, _) => match self.encapsulation[i + 1] {
+ Encapsulation::TCP(ref l4_header, _) => {
return Some((
l3_header.source_address.to_string(),
l4_header.source_port,
@@ -233,7 +233,7 @@ impl Packet<'_> {
l4_header.dest_port,
));
}
- Encapsulation::Udp(ref l4_header, _) => {
+ Encapsulation::UDP(ref l4_header, _) => {
return Some((
l3_header.source_address.to_string(),
l4_header.source_port,
@@ -243,8 +243,8 @@ impl Packet<'_> {
}
_ => continue,
},
- Encapsulation::Ipv6(ref l3_header, _) => match self.encapsulation[i + 1] {
- Encapsulation::Tcp(ref l4_header, _) => {
+ Encapsulation::IPv6(ref l3_header, _) => match self.encapsulation[i + 1] {
+ Encapsulation::TCP(ref l4_header, _) => {
return Some((
l3_header.source_address.to_string(),
l4_header.source_port,
@@ -252,7 +252,7 @@ impl Packet<'_> {
l4_header.dest_port,
));
}
- Encapsulation::Udp(ref l4_header, _) => {
+ Encapsulation::UDP(ref l4_header, _) => {
return Some((
l3_header.source_address.to_string(),
l4_header.source_port,
@@ -269,15 +269,15 @@ impl Packet<'_> {
return None;
}
- pub fn get_inner_tuple(&self) -> Option<(String, u16, String, u16)> {
+ pub fn get_inner_most_tuple(&self) -> Option<(String, u16, String, u16)> {
let num = self.encapsulation.len();
if num < 2 {
return None;
}
for i in (1..num).rev() {
match self.encapsulation[i] {
- Encapsulation::Tcp(ref l4_header, _) => match self.encapsulation[i - 1] {
- Encapsulation::Ipv4(ref l3_header, _) => {
+ Encapsulation::TCP(ref l4_header, _) => match self.encapsulation[i - 1] {
+ Encapsulation::IPv4(ref l3_header, _) => {
return Some((
l3_header.source_address.to_string(),
l4_header.source_port,
@@ -285,7 +285,7 @@ impl Packet<'_> {
l4_header.dest_port,
));
}
- Encapsulation::Ipv6(ref l3_header, _) => {
+ Encapsulation::IPv6(ref l3_header, _) => {
return Some((
l3_header.source_address.to_string(),
l4_header.source_port,
@@ -295,8 +295,8 @@ impl Packet<'_> {
}
_ => continue,
},
- Encapsulation::Udp(ref l4_header, _) => match self.encapsulation[i - 1] {
- Encapsulation::Ipv4(ref l3_header, _) => {
+ Encapsulation::UDP(ref l4_header, _) => match self.encapsulation[i - 1] {
+ Encapsulation::IPv4(ref l3_header, _) => {
return Some((
l3_header.source_address.to_string(),
l4_header.source_port,
@@ -304,7 +304,7 @@ impl Packet<'_> {
l4_header.dest_port,
));
}
- Encapsulation::Ipv6(ref l3_header, _) => {
+ Encapsulation::IPv6(ref l3_header, _) => {
return Some((
l3_header.source_address.to_string(),
l4_header.source_port,
@@ -326,26 +326,26 @@ impl Packet<'_> {
let mut flow_id = String::new();
for i in 0..num {
match self.encapsulation[i] {
- Encapsulation::Ipv4(ref l3_header, _) => {
+ Encapsulation::IPv4(ref l3_header, _) => {
flow_id.push_str(&l3_header.source_address.to_string());
flow_id.push_str("->");
flow_id.push_str(&l3_header.dest_address.to_string());
flow_id.push_str(";");
}
- Encapsulation::Ipv6(ref l3_header, _) => {
+ Encapsulation::IPv6(ref l3_header, _) => {
flow_id.push_str(&l3_header.source_address.to_string());
flow_id.push_str("->");
flow_id.push_str(&l3_header.dest_address.to_string());
flow_id.push_str(";");
}
- Encapsulation::Tcp(ref l4_header, _) => {
+ Encapsulation::TCP(ref l4_header, _) => {
flow_id.push_str("TCP->TCP;");
flow_id.push_str(&l4_header.source_port.to_string());
flow_id.push_str("->");
flow_id.push_str(&l4_header.dest_port.to_string());
flow_id.push_str(";");
}
- Encapsulation::Udp(ref l4_header, _) => {
+ Encapsulation::UDP(ref l4_header, _) => {
flow_id.push_str("UDP->UDP;");
flow_id.push_str(&l4_header.source_port.to_string());
flow_id.push_str("->");
@@ -361,14 +361,14 @@ impl Packet<'_> {
}
fn handle_eth<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = EthernetFrame::decode(input);
+ let result = EthHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
let next_proto = header.ether_type;
packet
.encapsulation
- .push(Encapsulation::Eth(header, payload));
+ .push(Encapsulation::ETH(header, payload));
return handle_l3(packet, payload, next_proto);
} else {
@@ -377,14 +377,14 @@ fn handle_eth<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet
}
fn handle_vlan<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = VlanHeader::decode(input);
+ let result = VLANHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
let next_proto = header.ether_type;
packet
.encapsulation
- .push(Encapsulation::Vlan(header, payload));
+ .push(Encapsulation::VLAN(header, payload));
return handle_l3(packet, payload, next_proto);
} else {
@@ -393,14 +393,14 @@ fn handle_vlan<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe
}
fn handle_mpls<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = MplsHeader::decode(input);
+ let result = MPLSHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
let bottom_of_stack = header.bottom_of_stack;
packet
.encapsulation
- .push(Encapsulation::Mpls(header, payload));
+ .push(Encapsulation::MPLS(header, payload));
if bottom_of_stack {
if payload.len() < 1 {
@@ -423,13 +423,13 @@ fn handle_mpls<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe
}
fn handle_pw_eth<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = PwEthHeader::decode(input);
+ let result = PWEthHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
packet
.encapsulation
- .push(Encapsulation::PwEth(header, payload));
+ .push(Encapsulation::PWETH(header, payload));
return handle_eth(packet, payload);
} else {
@@ -438,14 +438,14 @@ fn handle_pw_eth<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Pac
}
fn handle_ipv4<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = Ipv4Header::decode(input);
+ let result = IPv4Header::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
let next_proto = header.protocol;
packet
.encapsulation
- .push(Encapsulation::Ipv4(header, payload));
+ .push(Encapsulation::IPv4(header, payload));
// TODO IPv4 Fragment
@@ -456,7 +456,7 @@ fn handle_ipv4<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe
}
fn handle_ipv6<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = Ipv6Header::decode(input);
+ let result = IPv6Header::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
@@ -471,7 +471,7 @@ fn handle_ipv6<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe
packet
.encapsulation
- .push(Encapsulation::Ipv6(header, payload));
+ .push(Encapsulation::IPv6(header, payload));
return handle_l4(packet, payload, next_proto);
} else {
@@ -480,7 +480,7 @@ fn handle_ipv6<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe
}
fn handle_tcp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = TcpHeader::decode(input);
+ let result = TCPHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
@@ -488,7 +488,7 @@ fn handle_tcp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet
let dest_port = header.dest_port;
packet
.encapsulation
- .push(Encapsulation::Tcp(header, payload));
+ .push(Encapsulation::TCP(header, payload));
// TODO TCP Reassembly
@@ -507,14 +507,14 @@ fn handle_tcp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet
}
fn handle_udp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = UdpHeader::decode(input);
+ let result = UDPHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
let dest_port = header.dest_port;
packet
.encapsulation
- .push(Encapsulation::Udp(header, payload));
+ .push(Encapsulation::UDP(header, payload));
match dest_port {
// GTP-U
@@ -529,13 +529,13 @@ fn handle_udp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet
}
fn handle_icmp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = IcmpHeader::decode(input);
+ let result = ICMPHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
packet
.encapsulation
- .push(Encapsulation::Icmp(header, payload));
+ .push(Encapsulation::ICMP(header, payload));
return Ok(());
} else {
@@ -544,13 +544,13 @@ fn handle_icmp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe
}
fn handle_icmpv6<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = Icmpv6Header::decode(input);
+ let result = ICMPv6Header::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
packet
.encapsulation
- .push(Encapsulation::Icmpv6(header, payload));
+ .push(Encapsulation::ICMPv6(header, payload));
return Ok(());
} else {
@@ -559,14 +559,14 @@ fn handle_icmpv6<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Pac
}
fn handle_gtpv1<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = Gtpv1Header::decode(input);
+ let result = GTPv1Header::decode(input);
match result {
Ok((payload, header)) => {
dbg!(&header);
packet
.encapsulation
- .push(Encapsulation::Gtpv1(header, payload));
+ .push(Encapsulation::GTPv1(header, payload));
if payload.len() < 1 {
return Ok(());
@@ -589,7 +589,7 @@ fn handle_gtpv1<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Pack
}
fn handle_l2tp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = L2tpHeader::decode(input);
+ let result = L2TPHeader::decode(input);
match result {
Ok((payload, header)) => {
dbg!(&header);
@@ -597,13 +597,13 @@ fn handle_l2tp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe
let l2tp_type = header.flag_type;
packet
.encapsulation
- .push(Encapsulation::L2tp(header, payload));
+ .push(Encapsulation::L2TP(header, payload));
match l2tp_type {
- L2tpType::Control => {
+ L2TPType::Control => {
return Ok(());
}
- L2tpType::Data => {
+ L2TPType::Data => {
// TODO handle PPP
return Ok(());
}
@@ -626,14 +626,14 @@ fn handle_gre<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet
let version = input[1] & 0x07;
match version {
0 => {
- let result = Grev0Header::decode(input);
+ let result = GREv0Header::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
let next_proto = header.protocol_type;
packet
.encapsulation
- .push(Encapsulation::Grev0(header, payload));
+ .push(Encapsulation::GREv0(header, payload));
return handle_l3(packet, payload, next_proto);
} else {
@@ -641,14 +641,14 @@ fn handle_gre<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet
}
}
1 => {
- let result = Grev1Header::decode(input);
+ let result = GREv1Header::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
let next_proto = header.protocol_type;
packet
.encapsulation
- .push(Encapsulation::Grev1(header, payload));
+ .push(Encapsulation::GREv1(header, payload));
return handle_l3(packet, payload, next_proto);
} else {
@@ -662,13 +662,13 @@ fn handle_gre<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet
}
fn handle_pptp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = PptpHeader::decode(input);
+ let result = PPTPHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
packet
.encapsulation
- .push(Encapsulation::Pptp(header, payload));
+ .push(Encapsulation::PPTP(header, payload));
return Ok(());
} else {
@@ -677,24 +677,24 @@ fn handle_pptp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe
}
fn handle_ppp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), PacketError> {
- let result = PppHeader::decode(input);
+ let result = PPPHeader::decode(input);
if let Ok((payload, header)) = result {
dbg!(&header);
let next_proto = header.protocol;
packet
.encapsulation
- .push(Encapsulation::Ppp(header, payload));
+ .push(Encapsulation::PPP(header, payload));
match next_proto {
- // PppProtocol::PAD => handle_pad(packet, payload),
- PppProtocol::IPv4 => handle_ipv4(packet, payload),
- PppProtocol::IPv6 => handle_ipv6(packet, payload),
- // PppProtocol::IPCP => handle_ipcp(packet, payload),
- // PppProtocol::CCP => handle_ccp(packet, payload),
- // PppProtocol::LCP => handle_lcp(packet, payload),
- // PppProtocol::PAP => handle_pap(packet, payload),
- // PppProtocol::CHAP => handle_chap(packet, payload),
+ // PPPProtocol::PAD => handle_pad(packet, payload),
+ PPPProtocol::IPv4 => handle_ipv4(packet, payload),
+ PPPProtocol::IPv6 => handle_ipv6(packet, payload),
+ // PPPProtocol::IPCP => handle_ipcp(packet, payload),
+ // PPPProtocol::CCP => handle_ccp(packet, payload),
+ // PPPProtocol::LCP => handle_lcp(packet, payload),
+ // PPPProtocol::PAP => handle_pap(packet, payload),
+ // PPPProtocol::CHAP => handle_chap(packet, payload),
_ => Ok(()),
}
} else {
@@ -705,15 +705,15 @@ fn handle_ppp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet
fn handle_l3<'a>(
packet: &mut Packet<'a>,
input: &'a [u8],
- next_proto: EtherType,
+ next_proto: EthType,
) -> Result<(), PacketError> {
match next_proto {
- EtherType::PPP => handle_ppp(packet, input),
- EtherType::MPLSuni => handle_mpls(packet, input),
- EtherType::QinQ => handle_vlan(packet, input),
- EtherType::VLAN => handle_vlan(packet, input),
- EtherType::IPv4 => handle_ipv4(packet, input),
- EtherType::IPv6 => handle_ipv6(packet, input),
+ EthType::PPP => handle_ppp(packet, input),
+ EthType::MPLSuni => handle_mpls(packet, input),
+ EthType::QinQ => handle_vlan(packet, input),
+ EthType::VLAN => handle_vlan(packet, input),
+ EthType::IPv4 => handle_ipv4(packet, input),
+ EthType::IPv6 => handle_ipv6(packet, input),
_e => {
return Err(PacketError::UnsupportEthernetType);
}
@@ -747,37 +747,37 @@ fn handle_l4<'a>(
mod tests {
use super::Encapsulation;
use super::Packet;
- use crate::protocol::ethernet::EtherType;
- use crate::protocol::ethernet::EthernetFrame;
+ use crate::protocol::ethernet::EthHeader;
+ use crate::protocol::ethernet::EthType;
use crate::protocol::ethernet::MacAddress;
- use crate::protocol::grev0::Grev0Header;
- use crate::protocol::grev1::Grev1Header;
- use crate::protocol::gtpv1::Gtpv1ExtensionHeader;
- use crate::protocol::gtpv1::Gtpv1Header;
- use crate::protocol::gtpv1::Gtpv1Option;
- use crate::protocol::icmp::IcmpHeader;
- use crate::protocol::icmp::IcmpType;
+ use crate::protocol::grev0::GREv0Header;
+ use crate::protocol::grev1::GREv1Header;
+ use crate::protocol::gtpv1::GTPv1ExtensionHeader;
+ use crate::protocol::gtpv1::GTPv1Header;
+ use crate::protocol::gtpv1::GTPv1Option;
+ use crate::protocol::icmp::ICMPHeader;
+ use crate::protocol::icmp::ICMPType;
use crate::protocol::ip::IPProtocol;
- use crate::protocol::ipv4::Ipv4Header;
- use crate::protocol::ipv6::Ipv6Header;
- use crate::protocol::mpls::MplsHeader;
- use crate::protocol::mpls::PwEthHeader;
- use crate::protocol::ppp::PppHeader;
- use crate::protocol::ppp::PppProtocol;
- use crate::protocol::pptp::PptpControlMessageType;
- use crate::protocol::pptp::PptpHeader;
- use crate::protocol::pptp::PptpMessageType;
- use crate::protocol::tcp::TcpHeader;
- use crate::protocol::tcp::TcpOption;
- use crate::protocol::udp::UdpHeader;
- use crate::protocol::vlan::VlanHeader;
+ use crate::protocol::ipv4::IPv4Header;
+ use crate::protocol::ipv6::IPv6Header;
+ use crate::protocol::mpls::MPLSHeader;
+ use crate::protocol::mpls::PWEthHeader;
+ use crate::protocol::ppp::PPPHeader;
+ use crate::protocol::ppp::PPPProtocol;
+ use crate::protocol::pptp::PPTPControlMessageType;
+ use crate::protocol::pptp::PPTPHeader;
+ use crate::protocol::pptp::PPTPMessageType;
+ use crate::protocol::tcp::TCPHeader;
+ use crate::protocol::tcp::TCPOption;
+ use crate::protocol::udp::UDPHeader;
+ use crate::protocol::vlan::VLANHeader;
use std::net::Ipv4Addr;
use std::net::Ipv6Addr;
#[test]
fn test_packet_api() {
let mut packet = Packet::new(b"0", 1 as u32);
- let ipv4_hdr = Ipv4Header {
+ let ipv4_hdr = IPv4Header {
version: 4,
ihl: 20,
tos: 0,
@@ -791,7 +791,7 @@ mod tests {
source_address: Ipv4Addr::new(192, 168, 0, 101),
dest_address: Ipv4Addr::new(121, 14, 154, 93),
};
- let ipv6_hdr = Ipv6Header {
+ let ipv6_hdr = IPv6Header {
version: 6,
dsc: 0,
ecn: 0,
@@ -807,7 +807,7 @@ mod tests {
),
extensions: Vec::new(),
};
- let tcp_hdr = TcpHeader {
+ let tcp_hdr = TCPHeader {
source_port: 50081,
dest_port: 443,
seq_num: 1522577104,
@@ -825,7 +825,7 @@ mod tests {
urgent_ptr: 0,
options: None,
};
- let udp_hdr = UdpHeader {
+ let udp_hdr = UDPHeader {
source_port: 9993,
dest_port: 9994,
length: 145,
@@ -834,34 +834,34 @@ mod tests {
packet
.encapsulation
- .push(Encapsulation::Ipv4(ipv4_hdr.clone(), b"1"));
+ .push(Encapsulation::IPv4(ipv4_hdr.clone(), b"1"));
packet
.encapsulation
- .push(Encapsulation::Tcp(tcp_hdr.clone(), b"2"));
+ .push(Encapsulation::TCP(tcp_hdr.clone(), b"2"));
packet
.encapsulation
- .push(Encapsulation::Ipv6(ipv6_hdr.clone(), b"3"));
+ .push(Encapsulation::IPv6(ipv6_hdr.clone(), b"3"));
packet
.encapsulation
- .push(Encapsulation::Udp(udp_hdr.clone(), b"4"));
+ .push(Encapsulation::UDP(udp_hdr.clone(), b"4"));
assert_eq!(
- packet.get_outer_address(),
+ packet.get_outer_most_address(),
Some(("192.168.0.101".to_string(), "121.14.154.93".to_string()))
);
assert_eq!(
- packet.get_inner_address(),
+ packet.get_inner_most_address(),
Some((
"2409:8034:4025::50:a31".to_string(),
"2409:8034:4040:5301::204".to_string()
))
);
- assert_eq!(packet.get_outer_port(), Some((50081, 443)));
- assert_eq!(packet.get_inner_port(), Some((9993, 9994)));
+ assert_eq!(packet.get_outer_most_port(), Some((50081, 443)));
+ assert_eq!(packet.get_inner_most_port(), Some((9993, 9994)));
assert_eq!(
- packet.get_outer_tuple(),
+ packet.get_outer_most_tuple(),
Some((
"192.168.0.101".to_string(),
50081,
@@ -870,7 +870,7 @@ mod tests {
))
);
assert_eq!(
- packet.get_inner_tuple(),
+ packet.get_inner_most_tuple(),
Some((
"2409:8034:4025::50:a31".to_string(),
9993,
@@ -880,20 +880,20 @@ mod tests {
);
assert_eq!(
- packet.get_outer_l3_layer(),
- Some(Encapsulation::Ipv4(ipv4_hdr, b"1"))
+ packet.get_outer_most_l3_layer(),
+ Some(Encapsulation::IPv4(ipv4_hdr, b"1"))
);
assert_eq!(
- packet.get_inner_l3_layer(),
- Some(Encapsulation::Ipv6(ipv6_hdr, b"3"))
+ packet.get_inner_most_l3_layer(),
+ Some(Encapsulation::IPv6(ipv6_hdr, b"3"))
);
assert_eq!(
- packet.get_outer_l4_layer(),
- Some(Encapsulation::Tcp(tcp_hdr, b"2"))
+ packet.get_outer_most_l4_layer(),
+ Some(Encapsulation::TCP(tcp_hdr, b"2"))
);
assert_eq!(
- packet.get_inner_l4_layer(),
- Some(Encapsulation::Udp(udp_hdr, b"4"))
+ packet.get_inner_most_l4_layer(),
+ Some(Encapsulation::UDP(udp_hdr, b"4"))
);
assert_eq!(packet.get_flow_id(), Some("192.168.0.101->121.14.154.93;TCP->TCP;50081->443;2409:8034:4025::50:a31->2409:8034:4040:5301::204;UDP->UDP;9993->9994;".to_string()));
@@ -1020,43 +1020,43 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 5);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x00, 0x13, 0xc3, 0xdf, 0xae, 0x18]),
dest_mac: MacAddress([0x00, 0x1b, 0xd4, 0x1b, 0xa4, 0xd8]),
- ether_type: EtherType::VLAN,
+ ether_type: EthType::VLAN,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Vlan(
- VlanHeader {
+ Encapsulation::VLAN(
+ VLANHeader {
priority_code_point: 0,
drop_eligible_indicator: false,
vlan_identifier: 118,
- ether_type: EtherType::VLAN,
+ ether_type: EthType::VLAN,
},
&bytes[18..]
)
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Vlan(
- VlanHeader {
+ Encapsulation::VLAN(
+ VLANHeader {
priority_code_point: 0,
drop_eligible_indicator: false,
vlan_identifier: 10,
- ether_type: EtherType::IPv4,
+ ether_type: EthType::IPv4,
},
&bytes[22..]
)
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0,
@@ -1075,8 +1075,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[4],
- Encapsulation::Tcp(
- TcpHeader {
+ Encapsulation::TCP(
+ TCPHeader {
source_port: 2048,
dest_port: 52912,
seq_num: 196611,
@@ -1219,43 +1219,43 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 5);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0xa2, 0xc1, 0x12, 0x03, 0x02, 0x03]),
dest_mac: MacAddress([0xa2, 0xc1, 0x12, 0x03, 0x01, 0x64]),
- ether_type: EtherType::QinQ,
+ ether_type: EthType::QinQ,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Vlan(
- VlanHeader {
+ Encapsulation::VLAN(
+ VLANHeader {
priority_code_point: 0,
drop_eligible_indicator: false,
vlan_identifier: 1,
- ether_type: EtherType::VLAN,
+ ether_type: EthType::VLAN,
},
&bytes[18..]
)
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Vlan(
- VlanHeader {
+ Encapsulation::VLAN(
+ VLANHeader {
priority_code_point: 0,
drop_eligible_indicator: false,
vlan_identifier: 1,
- ether_type: EtherType::IPv4,
+ ether_type: EthType::IPv4,
},
&bytes[22..]
)
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0,
@@ -1274,8 +1274,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[4],
- Encapsulation::Tcp(
- TcpHeader {
+ Encapsulation::TCP(
+ TCPHeader {
source_port: 10000,
dest_port: 80,
seq_num: 2180528890,
@@ -1472,19 +1472,19 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 4);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x00, 0x22, 0x46, 0x36, 0x51, 0x3c]),
dest_mac: MacAddress([0x00, 0x22, 0x46, 0x36, 0x51, 0x38]),
- ether_type: EtherType::IPv6,
+ ether_type: EthType::IPv6,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Ipv6(
- Ipv6Header {
+ Encapsulation::IPv6(
+ IPv6Header {
version: 6,
dsc: 0,
ecn: 0,
@@ -1501,8 +1501,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0,
@@ -1521,8 +1521,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Tcp(
- TcpHeader {
+ Encapsulation::TCP(
+ TCPHeader {
source_port: 57639,
dest_port: 22,
seq_num: 1508621024,
@@ -1675,19 +1675,19 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 4);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x2c, 0x6b, 0xf5, 0x45, 0x88, 0x29]),
dest_mac: MacAddress([0x5c, 0x5e, 0xab, 0x2a, 0xa2, 0x00]),
- ether_type: EtherType::IPv4,
+ ether_type: EthType::IPv4,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0,
@@ -1706,8 +1706,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Ipv6(
- Ipv6Header {
+ Encapsulation::IPv6(
+ IPv6Header {
version: 6,
dsc: 0,
ecn: 0,
@@ -1728,8 +1728,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Tcp(
- TcpHeader {
+ Encapsulation::TCP(
+ TCPHeader {
source_port: 52556,
dest_port: 80,
seq_num: 2172673240,
@@ -1842,19 +1842,19 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 4);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
dest_mac: MacAddress([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
- ether_type: EtherType::IPv6,
+ ether_type: EthType::IPv6,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Ipv6(
- Ipv6Header {
+ Encapsulation::IPv6(
+ IPv6Header {
version: 6,
dsc: 0,
ecn: 0,
@@ -1875,8 +1875,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Ipv6(
- Ipv6Header {
+ Encapsulation::IPv6(
+ IPv6Header {
version: 6,
dsc: 0,
ecn: 0,
@@ -1897,8 +1897,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Udp(
- UdpHeader {
+ Encapsulation::UDP(
+ UDPHeader {
source_port: 30000,
dest_port: 13000,
length: 12,
@@ -2030,43 +2030,43 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 6);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0xa4, 0xc6, 0x4f, 0x3b, 0xb3, 0x9a]),
dest_mac: MacAddress([0x00, 0x00, 0x00, 0x00, 0x00, 0x04]),
- ether_type: EtherType::VLAN,
+ ether_type: EthType::VLAN,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Vlan(
- VlanHeader {
+ Encapsulation::VLAN(
+ VLANHeader {
priority_code_point: 3,
drop_eligible_indicator: false,
vlan_identifier: 1624,
- ether_type: EtherType::VLAN,
+ ether_type: EthType::VLAN,
},
&bytes[18..]
)
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Vlan(
- VlanHeader {
+ Encapsulation::VLAN(
+ VLANHeader {
priority_code_point: 3,
drop_eligible_indicator: false,
vlan_identifier: 505,
- ether_type: EtherType::IPv4,
+ ether_type: EthType::IPv4,
},
&bytes[22..]
)
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0xb8,
@@ -2085,8 +2085,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[4],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0xb8,
@@ -2105,8 +2105,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[5],
- Encapsulation::Udp(
- UdpHeader {
+ Encapsulation::UDP(
+ UDPHeader {
source_port: 62367,
dest_port: 17000,
length: 108,
@@ -2237,19 +2237,19 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 5);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x00, 0x30, 0x96, 0x05, 0x28, 0x38]),
dest_mac: MacAddress([0x00, 0x30, 0x96, 0xe6, 0xfc, 0x39]),
- ether_type: EtherType::MPLSuni,
+ ether_type: EthType::MPLSuni,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Mpls(
- MplsHeader {
+ Encapsulation::MPLS(
+ MPLSHeader {
label: 18,
experimental: 5,
bottom_of_stack: false,
@@ -2260,8 +2260,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Mpls(
- MplsHeader {
+ Encapsulation::MPLS(
+ MPLSHeader {
label: 16,
experimental: 5,
bottom_of_stack: true,
@@ -2272,8 +2272,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0xb0,
@@ -2292,8 +2292,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[4],
- Encapsulation::Tcp(
- TcpHeader {
+ Encapsulation::TCP(
+ TCPHeader {
source_port: 11001,
dest_port: 23,
seq_num: 3481568569,
@@ -2309,7 +2309,7 @@ mod tests {
window: 4128,
checksum: 0xf791,
urgent_ptr: 0,
- options: Some(vec![TcpOption::MSS {
+ options: Some(vec![TCPOption::MSS {
length: 4,
mss: 536
}]),
@@ -2429,19 +2429,19 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 7);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0xcc, 0x01, 0x0d, 0x5c, 0x00, 0x10]),
dest_mac: MacAddress([0xcc, 0x00, 0x0d, 0x5c, 0x00, 0x10]),
- ether_type: EtherType::MPLSuni,
+ ether_type: EthType::MPLSuni,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Mpls(
- MplsHeader {
+ Encapsulation::MPLS(
+ MPLSHeader {
label: 19,
experimental: 0,
bottom_of_stack: false,
@@ -2452,8 +2452,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Mpls(
- MplsHeader {
+ Encapsulation::MPLS(
+ MPLSHeader {
label: 16,
experimental: 0,
bottom_of_stack: true,
@@ -2464,23 +2464,23 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::PwEth(PwEthHeader { control_word: 0 }, &bytes[26..])
+ Encapsulation::PWETH(PWEthHeader { control_word: 0 }, &bytes[26..])
);
assert_eq!(
packet.encapsulation[4],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x00, 0x50, 0x79, 0x66, 0x68, 0x00]),
dest_mac: MacAddress([0x00, 0x50, 0x79, 0x66, 0x68, 0x01]),
- ether_type: EtherType::IPv4,
+ ether_type: EthType::IPv4,
},
&bytes[40..]
)
);
assert_eq!(
packet.encapsulation[5],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0x00,
@@ -2499,9 +2499,9 @@ mod tests {
);
assert_eq!(
packet.encapsulation[6],
- Encapsulation::Icmp(
- IcmpHeader {
- icmp_type: IcmpType::EchoRequest,
+ Encapsulation::ICMP(
+ ICMPHeader {
+ icmp_type: ICMPType::EchoRequest,
icmp_code: 0,
icmp_checksum: 0x529b,
icmp_extended: vec![0xcc, 0x70, 0x01, 0x00],
@@ -2666,31 +2666,31 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 7);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0xac, 0xb3, 0xb5, 0x40, 0xe9, 0xc3]),
dest_mac: MacAddress([0x74, 0x4a, 0xa4, 0x0e, 0xf5, 0x14]),
- ether_type: EtherType::VLAN,
+ ether_type: EthType::VLAN,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Vlan(
- VlanHeader {
+ Encapsulation::VLAN(
+ VLANHeader {
priority_code_point: 2,
drop_eligible_indicator: false,
vlan_identifier: 504,
- ether_type: EtherType::IPv6,
+ ether_type: EthType::IPv6,
},
&bytes[18..]
)
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Ipv6(
- Ipv6Header {
+ Encapsulation::IPv6(
+ IPv6Header {
version: 6,
dsc: 18,
ecn: 0,
@@ -2707,8 +2707,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Udp(
- UdpHeader {
+ Encapsulation::UDP(
+ UDPHeader {
source_port: 2152,
dest_port: 2152,
length: 64,
@@ -2719,8 +2719,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[4],
- Encapsulation::Gtpv1(
- Gtpv1Header {
+ Encapsulation::GTPv1(
+ GTPv1Header {
version: 1,
protocol_type: 1,
reserved: 0,
@@ -2730,12 +2730,12 @@ mod tests {
message_type: 0xff,
message_length: 48,
teid: 476419836,
- options: Some(Gtpv1Option {
+ options: Some(GTPv1Option {
sequence_number: 26425,
npdu_number: 0,
next_header_type: 0x85,
}),
- extensions: vec![Gtpv1ExtensionHeader {
+ extensions: vec![GTPv1ExtensionHeader {
length: 1,
contents: vec![0x10, 0x01],
next_header_type: 0x00,
@@ -2746,8 +2746,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[5],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0x00,
@@ -2766,8 +2766,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[6],
- Encapsulation::Tcp(
- TcpHeader {
+ Encapsulation::TCP(
+ TCPHeader {
source_port: 47892,
dest_port: 80,
seq_num: 2480465049,
@@ -2940,19 +2940,19 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 7);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x00, 0x0f, 0xfe, 0xdd, 0x22, 0x42]),
dest_mac: MacAddress([0x00, 0x1b, 0xd5, 0xff, 0x54, 0xd9]),
- ether_type: EtherType::IPv4,
+ ether_type: EthType::IPv4,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0x00,
@@ -2971,8 +2971,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Grev0(
- Grev0Header {
+ Encapsulation::GREv0(
+ GREv0Header {
flag_checksum: false,
flag_routing: false,
flag_key: false,
@@ -2981,7 +2981,7 @@ mod tests {
recursion_control: 0,
flags: 0,
version: 0,
- protocol_type: EtherType::IPv4,
+ protocol_type: EthType::IPv4,
checksum: None,
offset: None,
key: None,
@@ -2993,8 +2993,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0x00,
@@ -3013,8 +3013,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[4],
- Encapsulation::Grev0(
- Grev0Header {
+ Encapsulation::GREv0(
+ GREv0Header {
flag_checksum: false,
flag_routing: false,
flag_key: false,
@@ -3023,7 +3023,7 @@ mod tests {
recursion_control: 0,
flags: 0,
version: 0,
- protocol_type: EtherType::IPv4,
+ protocol_type: EthType::IPv4,
checksum: None,
offset: None,
key: None,
@@ -3035,8 +3035,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[5],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0x00,
@@ -3055,9 +3055,9 @@ mod tests {
);
assert_eq!(
packet.encapsulation[6],
- Encapsulation::Icmp(
- IcmpHeader {
- icmp_type: IcmpType::EchoRequest,
+ Encapsulation::ICMP(
+ ICMPHeader {
+ icmp_type: ICMPType::EchoRequest,
icmp_code: 0,
icmp_checksum: 0xcbca,
icmp_extended: vec![0x00, 0x17, 0x1d, 0xf2],
@@ -3188,19 +3188,19 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 4);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x28, 0xd2, 0x44, 0x43, 0x38, 0x37]),
dest_mac: MacAddress([0xc0, 0x00, 0x14, 0x8c, 0x00, 0x00]),
- ether_type: EtherType::IPv4,
+ ether_type: EthType::IPv4,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0x00,
@@ -3219,8 +3219,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Tcp(
- TcpHeader {
+ Encapsulation::TCP(
+ TCPHeader {
source_port: 50112,
dest_port: 1723,
seq_num: 2945311102,
@@ -3243,12 +3243,12 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Pptp(
- PptpHeader {
+ Encapsulation::PPTP(
+ PPTPHeader {
length: 24,
- message_type: PptpMessageType::ControlMessage,
+ message_type: PPTPMessageType::ControlMessage,
magic_cookie: 0x1a2b3c4d,
- control_message_type: PptpControlMessageType::SetLinkInfo,
+ control_message_type: PPTPControlMessageType::SetLinkInfo,
reserved0: 0,
payload: vec![
0x00, 0x03, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -3384,19 +3384,19 @@ mod tests {
assert_eq!(packet.encapsulation.len(), 6);
assert_eq!(
packet.encapsulation[0],
- Encapsulation::Eth(
- EthernetFrame {
+ Encapsulation::ETH(
+ EthHeader {
source_mac: MacAddress([0x00, 0x14, 0x00, 0x00, 0x02, 0x00]),
dest_mac: MacAddress([0x00, 0x09, 0xe9, 0x55, 0xc0, 0x1c]),
- ether_type: EtherType::IPv4,
+ ether_type: EthType::IPv4,
},
&bytes[14..]
)
);
assert_eq!(
packet.encapsulation[1],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0x00,
@@ -3415,8 +3415,8 @@ mod tests {
);
assert_eq!(
packet.encapsulation[2],
- Encapsulation::Grev1(
- Grev1Header {
+ Encapsulation::GREv1(
+ GREv1Header {
flag_checksum: false,
flag_routing: false,
flag_key: true,
@@ -3426,7 +3426,7 @@ mod tests {
flag_acknowledgment: false,
flags: 0,
version: 1,
- protocol_type: EtherType::PPP,
+ protocol_type: EthType::PPP,
key_payload_length: 88,
key_call_id: 24,
sequence_number: Some(7),
@@ -3437,19 +3437,19 @@ mod tests {
);
assert_eq!(
packet.encapsulation[3],
- Encapsulation::Ppp(
- PppHeader {
+ Encapsulation::PPP(
+ PPPHeader {
address: 0xff,
control: 0x03,
- protocol: PppProtocol::IPv4,
+ protocol: PPPProtocol::IPv4,
},
&bytes[50..]
)
);
assert_eq!(
packet.encapsulation[4],
- Encapsulation::Ipv4(
- Ipv4Header {
+ Encapsulation::IPv4(
+ IPv4Header {
version: 4,
ihl: 20,
tos: 0x00,
@@ -3468,9 +3468,9 @@ mod tests {
);
assert_eq!(
packet.encapsulation[5],
- Encapsulation::Icmp(
- IcmpHeader {
- icmp_type: IcmpType::EchoRequest,
+ Encapsulation::ICMP(
+ ICMPHeader {
+ icmp_type: ICMPType::EchoRequest,
icmp_code: 0,
icmp_checksum: 0x4500,
icmp_extended: vec![0x18, 0x2b, 0x00, 0x01,],