diff options
| author | luwenpeng <[email protected]> | 2023-09-18 14:47:10 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2023-09-18 17:52:39 +0800 |
| commit | cb674f9e168b6e709136e17a5bc87d3925c6f479 (patch) | |
| tree | a735d755c1b653ae59b0b47d05ed720aa573f0b6 /src/packet | |
| parent | 9387c343d38c00efb432cfb419a3c669f4d65b3a (diff) | |
[refactor] Event manager: Support triggering new events in event handle, Solve the problem of multiple borrowing
Diffstat (limited to 'src/packet')
| -rw-r--r-- | src/packet/capture.rs | 8 | ||||
| -rw-r--r-- | src/packet/packet.rs | 225 |
2 files changed, 112 insertions, 121 deletions
diff --git a/src/packet/capture.rs b/src/packet/capture.rs index fbbf6d7..6ba8144 100644 --- a/src/packet/capture.rs +++ b/src/packet/capture.rs @@ -35,14 +35,8 @@ impl PacketCapture { } pub fn show_devices() { - let mut device_num = 0; for device in pcap::Device::list().expect("device list failed") { - device_num += 1; - println!( - "======================== Available Device [{}]========================", - device_num - ); - println!("{:#?}", device); + println!("{:?}", device); } } } diff --git a/src/packet/packet.rs b/src/packet/packet.rs index ce7456b..6ab0a71 100644 --- a/src/packet/packet.rs +++ b/src/packet/packet.rs @@ -17,26 +17,23 @@ use crate::protocol::udp::UdpHeader; use crate::protocol::vlan::VlanHeader; use nom::Err::Incomplete; -#[allow(non_camel_case_types)] #[derive(Clone, Debug, PartialEq)] pub enum Encapsulation<'a> { - L2_ETH(EthernetFrame, &'a [u8]), - L2_VLAN(VlanHeader, &'a [u8]), - L2_MPLS(MplsHeader, &'a [u8]), - L2_PWETH(PwEthHeader, &'a [u8]), + Eth(EthernetFrame, &'a [u8]), + Vlan(VlanHeader, &'a [u8]), + Mpls(MplsHeader, &'a [u8]), + PwEth(PwEthHeader, &'a [u8]), - L3_IPV4(Ipv4Header, &'a [u8]), - L3_IPV6(Ipv6Header, &'a [u8]), + Ipv4(Ipv4Header, &'a [u8]), + Ipv6(Ipv6Header, &'a [u8]), - L4_TCP(TcpHeader, &'a [u8]), - L4_UDP(UdpHeader, &'a [u8]), - L4_ICMP(IcmpHeader, &'a [u8]), - L4_ICMPV6(Icmpv6Header, &'a [u8]), + Tcp(TcpHeader, &'a [u8]), + Udp(UdpHeader, &'a [u8]), + Icmp(IcmpHeader, &'a [u8]), + Icmpv6(Icmpv6Header, &'a [u8]), - LTUN_GTPV1_C(Gtpv1Header, &'a [u8]), - LTUN_L2TP(L2tpHeader, &'a [u8]), - - UNSUPPORTED(&'a [u8]), + Gtpv1(Gtpv1Header, &'a [u8]), + L2tp(L2tpHeader, &'a [u8]), } #[derive(Debug)] @@ -66,10 +63,10 @@ impl Packet<'_> { let num = self.encapsulation.len(); for i in 0..num { match self.encapsulation[i] { - Encapsulation::L3_IPV4(_, _) => { + Encapsulation::Ipv4(_, _) => { return Some(self.encapsulation[i].clone()); } - Encapsulation::L3_IPV6(_, _) => { + Encapsulation::Ipv6(_, _) => { return Some(self.encapsulation[i].clone()); } _ => continue, @@ -83,10 +80,10 @@ impl Packet<'_> { let num = self.encapsulation.len(); for i in (0..num).rev() { match self.encapsulation[i] { - Encapsulation::L3_IPV4(_, _) => { + Encapsulation::Ipv4(_, _) => { return Some(self.encapsulation[i].clone()); } - Encapsulation::L3_IPV6(_, _) => { + Encapsulation::Ipv6(_, _) => { return Some(self.encapsulation[i].clone()); } _ => continue, @@ -100,10 +97,10 @@ impl Packet<'_> { let num = self.encapsulation.len(); for i in 0..num { match self.encapsulation[i] { - Encapsulation::L4_TCP(_, _) => { + Encapsulation::Tcp(_, _) => { return Some(self.encapsulation[i].clone()); } - Encapsulation::L4_UDP(_, _) => { + Encapsulation::Udp(_, _) => { return Some(self.encapsulation[i].clone()); } _ => continue, @@ -117,10 +114,10 @@ impl Packet<'_> { let num = self.encapsulation.len(); for i in (0..num).rev() { match self.encapsulation[i] { - Encapsulation::L4_TCP(_, _) => { + Encapsulation::Tcp(_, _) => { return Some(self.encapsulation[i].clone()); } - Encapsulation::L4_UDP(_, _) => { + Encapsulation::Udp(_, _) => { return Some(self.encapsulation[i].clone()); } _ => continue, @@ -134,13 +131,13 @@ impl Packet<'_> { let num = self.encapsulation.len(); for i in 0..num { match self.encapsulation[i] { - Encapsulation::L3_IPV4(ref header, _) => { + Encapsulation::Ipv4(ref header, _) => { return Some(( header.source_address.to_string(), header.dest_address.to_string(), )); } - Encapsulation::L3_IPV6(ref header, _) => { + Encapsulation::Ipv6(ref header, _) => { return Some(( header.source_address.to_string(), header.dest_address.to_string(), @@ -157,13 +154,13 @@ impl Packet<'_> { let num = self.encapsulation.len(); for i in (0..num).rev() { match self.encapsulation[i] { - Encapsulation::L3_IPV4(ref header, _) => { + Encapsulation::Ipv4(ref header, _) => { return Some(( header.source_address.to_string(), header.dest_address.to_string(), )); } - Encapsulation::L3_IPV6(ref header, _) => { + Encapsulation::Ipv6(ref header, _) => { return Some(( header.source_address.to_string(), header.dest_address.to_string(), @@ -180,10 +177,10 @@ impl Packet<'_> { let num = self.encapsulation.len(); for i in 0..num { match self.encapsulation[i] { - Encapsulation::L4_TCP(ref header, _) => { + Encapsulation::Tcp(ref header, _) => { return Some((header.source_port, header.dest_port)); } - Encapsulation::L4_UDP(ref header, _) => { + Encapsulation::Udp(ref header, _) => { return Some((header.source_port, header.dest_port)); } _ => continue, @@ -197,10 +194,10 @@ impl Packet<'_> { let num = self.encapsulation.len(); for i in (0..num).rev() { match self.encapsulation[i] { - Encapsulation::L4_TCP(ref header, _) => { + Encapsulation::Tcp(ref header, _) => { return Some((header.source_port, header.dest_port)); } - Encapsulation::L4_UDP(ref header, _) => { + Encapsulation::Udp(ref header, _) => { return Some((header.source_port, header.dest_port)); } _ => continue, @@ -217,8 +214,8 @@ impl Packet<'_> { } for i in 0..num - 1 { match self.encapsulation[i] { - Encapsulation::L3_IPV4(ref l3_header, _) => match self.encapsulation[i + 1] { - Encapsulation::L4_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, @@ -226,7 +223,7 @@ impl Packet<'_> { l4_header.dest_port, )); } - Encapsulation::L4_UDP(ref l4_header, _) => { + Encapsulation::Udp(ref l4_header, _) => { return Some(( l3_header.source_address.to_string(), l4_header.source_port, @@ -236,8 +233,8 @@ impl Packet<'_> { } _ => continue, }, - Encapsulation::L3_IPV6(ref l3_header, _) => match self.encapsulation[i + 1] { - Encapsulation::L4_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, @@ -245,7 +242,7 @@ impl Packet<'_> { l4_header.dest_port, )); } - Encapsulation::L4_UDP(ref l4_header, _) => { + Encapsulation::Udp(ref l4_header, _) => { return Some(( l3_header.source_address.to_string(), l4_header.source_port, @@ -269,8 +266,8 @@ impl Packet<'_> { } for i in (1..num).rev() { match self.encapsulation[i] { - Encapsulation::L4_TCP(ref l4_header, _) => match self.encapsulation[i - 1] { - Encapsulation::L3_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, @@ -278,7 +275,7 @@ impl Packet<'_> { l4_header.dest_port, )); } - Encapsulation::L3_IPV6(ref l3_header, _) => { + Encapsulation::Ipv6(ref l3_header, _) => { return Some(( l3_header.source_address.to_string(), l4_header.source_port, @@ -288,8 +285,8 @@ impl Packet<'_> { } _ => continue, }, - Encapsulation::L4_UDP(ref l4_header, _) => match self.encapsulation[i - 1] { - Encapsulation::L3_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, @@ -297,7 +294,7 @@ impl Packet<'_> { l4_header.dest_port, )); } - Encapsulation::L3_IPV6(ref l3_header, _) => { + Encapsulation::Ipv6(ref l3_header, _) => { return Some(( l3_header.source_address.to_string(), l4_header.source_port, @@ -319,26 +316,26 @@ impl Packet<'_> { let mut flow_id = String::new(); for i in 0..num { match self.encapsulation[i] { - Encapsulation::L3_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::L3_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::L4_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::L4_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,7 +358,7 @@ fn handle_eth<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet let next_proto = header.ether_type; packet .encapsulation - .push(Encapsulation::L2_ETH(header, payload)); + .push(Encapsulation::Eth(header, payload)); return handle_l3(packet, payload, next_proto); } else { @@ -377,7 +374,7 @@ fn handle_vlan<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe let next_proto = header.ether_type; packet .encapsulation - .push(Encapsulation::L2_VLAN(header, payload)); + .push(Encapsulation::Vlan(header, payload)); return handle_l3(packet, payload, next_proto); } else { @@ -393,7 +390,7 @@ fn handle_mpls<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe let bottom_of_stack = header.bottom_of_stack; packet .encapsulation - .push(Encapsulation::L2_MPLS(header, payload)); + .push(Encapsulation::Mpls(header, payload)); if bottom_of_stack { if payload.len() < 1 { @@ -422,7 +419,7 @@ fn handle_pw_eth<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Pac packet .encapsulation - .push(Encapsulation::L2_PWETH(header, payload)); + .push(Encapsulation::PwEth(header, payload)); return handle_eth(packet, payload); } else { @@ -438,7 +435,7 @@ fn handle_ipv4<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe let next_proto = header.protocol; packet .encapsulation - .push(Encapsulation::L3_IPV4(header, payload)); + .push(Encapsulation::Ipv4(header, payload)); // TODO IPv4 Fragment @@ -464,7 +461,7 @@ fn handle_ipv6<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe packet .encapsulation - .push(Encapsulation::L3_IPV6(header, payload)); + .push(Encapsulation::Ipv6(header, payload)); return handle_l4(packet, payload, next_proto); } else { @@ -479,7 +476,7 @@ fn handle_tcp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet packet .encapsulation - .push(Encapsulation::L4_TCP(header, payload)); + .push(Encapsulation::Tcp(header, payload)); // TODO TCP Reassembly @@ -497,7 +494,7 @@ fn handle_udp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packet let dest_port = header.dest_port; packet .encapsulation - .push(Encapsulation::L4_UDP(header, payload)); + .push(Encapsulation::Udp(header, payload)); match dest_port { // GTP-U @@ -518,7 +515,7 @@ fn handle_icmp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe packet .encapsulation - .push(Encapsulation::L4_ICMP(header, payload)); + .push(Encapsulation::Icmp(header, payload)); return Ok(()); } else { @@ -533,7 +530,7 @@ fn handle_icmpv6<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Pac packet .encapsulation - .push(Encapsulation::L4_ICMPV6(header, payload)); + .push(Encapsulation::Icmpv6(header, payload)); return Ok(()); } else { @@ -549,7 +546,7 @@ fn handle_gtpv1<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Pack packet .encapsulation - .push(Encapsulation::LTUN_GTPV1_C(header, payload)); + .push(Encapsulation::Gtpv1(header, payload)); if payload.len() < 1 { return Ok(()); @@ -580,7 +577,7 @@ fn handle_l2tp<'a>(packet: &mut Packet<'a>, input: &'a [u8]) -> Result<(), Packe let l2tp_type = header.flag_type; packet .encapsulation - .push(Encapsulation::LTUN_L2TP(header, payload)); + .push(Encapsulation::L2tp(header, payload)); match l2tp_type { L2tpType::Control => { @@ -724,16 +721,16 @@ mod tests { packet .encapsulation - .push(Encapsulation::L3_IPV4(ipv4_hdr.clone(), b"1")); + .push(Encapsulation::Ipv4(ipv4_hdr.clone(), b"1")); packet .encapsulation - .push(Encapsulation::L4_TCP(tcp_hdr.clone(), b"2")); + .push(Encapsulation::Tcp(tcp_hdr.clone(), b"2")); packet .encapsulation - .push(Encapsulation::L3_IPV6(ipv6_hdr.clone(), b"3")); + .push(Encapsulation::Ipv6(ipv6_hdr.clone(), b"3")); packet .encapsulation - .push(Encapsulation::L4_UDP(udp_hdr.clone(), b"4")); + .push(Encapsulation::Udp(udp_hdr.clone(), b"4")); assert_eq!( packet.get_outer_address(), @@ -771,19 +768,19 @@ mod tests { assert_eq!( packet.get_outer_l3_layer(), - Some(Encapsulation::L3_IPV4(ipv4_hdr, b"1")) + Some(Encapsulation::Ipv4(ipv4_hdr, b"1")) ); assert_eq!( packet.get_inner_l3_layer(), - Some(Encapsulation::L3_IPV6(ipv6_hdr, b"3")) + Some(Encapsulation::Ipv6(ipv6_hdr, b"3")) ); assert_eq!( packet.get_outer_l4_layer(), - Some(Encapsulation::L4_TCP(tcp_hdr, b"2")) + Some(Encapsulation::Tcp(tcp_hdr, b"2")) ); assert_eq!( packet.get_inner_l4_layer(), - Some(Encapsulation::L4_UDP(udp_hdr, b"4")) + 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())); @@ -910,7 +907,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 5); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0x00, 0x13, 0xc3, 0xdf, 0xae, 0x18]), dest_mac: MacAddress([0x00, 0x1b, 0xd4, 0x1b, 0xa4, 0xd8]), @@ -921,7 +918,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L2_VLAN( + Encapsulation::Vlan( VlanHeader { priority_code_point: 0, drop_eligible_indicator: false, @@ -933,7 +930,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L2_VLAN( + Encapsulation::Vlan( VlanHeader { priority_code_point: 0, drop_eligible_indicator: false, @@ -945,7 +942,7 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -965,7 +962,7 @@ mod tests { ); assert_eq!( packet.encapsulation[4], - Encapsulation::L4_TCP( + Encapsulation::Tcp( TcpHeader { source_port: 2048, dest_port: 52912, @@ -1109,7 +1106,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 5); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0xa2, 0xc1, 0x12, 0x03, 0x02, 0x03]), dest_mac: MacAddress([0xa2, 0xc1, 0x12, 0x03, 0x01, 0x64]), @@ -1120,7 +1117,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L2_VLAN( + Encapsulation::Vlan( VlanHeader { priority_code_point: 0, drop_eligible_indicator: false, @@ -1132,7 +1129,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L2_VLAN( + Encapsulation::Vlan( VlanHeader { priority_code_point: 0, drop_eligible_indicator: false, @@ -1144,7 +1141,7 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -1164,7 +1161,7 @@ mod tests { ); assert_eq!( packet.encapsulation[4], - Encapsulation::L4_TCP( + Encapsulation::Tcp( TcpHeader { source_port: 10000, dest_port: 80, @@ -1362,7 +1359,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 4); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0x00, 0x22, 0x46, 0x36, 0x51, 0x3c]), dest_mac: MacAddress([0x00, 0x22, 0x46, 0x36, 0x51, 0x38]), @@ -1373,7 +1370,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L3_IPV6( + Encapsulation::Ipv6( Ipv6Header { version: 6, dsc: 0, @@ -1391,7 +1388,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -1411,7 +1408,7 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L4_TCP( + Encapsulation::Tcp( TcpHeader { source_port: 57639, dest_port: 22, @@ -1565,7 +1562,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 4); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0x2c, 0x6b, 0xf5, 0x45, 0x88, 0x29]), dest_mac: MacAddress([0x5c, 0x5e, 0xab, 0x2a, 0xa2, 0x00]), @@ -1576,7 +1573,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -1596,7 +1593,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L3_IPV6( + Encapsulation::Ipv6( Ipv6Header { version: 6, dsc: 0, @@ -1618,7 +1615,7 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L4_TCP( + Encapsulation::Tcp( TcpHeader { source_port: 52556, dest_port: 80, @@ -1732,7 +1729,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 4); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), dest_mac: MacAddress([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]), @@ -1743,7 +1740,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L3_IPV6( + Encapsulation::Ipv6( Ipv6Header { version: 6, dsc: 0, @@ -1765,7 +1762,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L3_IPV6( + Encapsulation::Ipv6( Ipv6Header { version: 6, dsc: 0, @@ -1787,7 +1784,7 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L4_UDP( + Encapsulation::Udp( UdpHeader { source_port: 30000, dest_port: 13000, @@ -1920,7 +1917,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 6); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0xa4, 0xc6, 0x4f, 0x3b, 0xb3, 0x9a]), dest_mac: MacAddress([0x00, 0x00, 0x00, 0x00, 0x00, 0x04]), @@ -1931,7 +1928,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L2_VLAN( + Encapsulation::Vlan( VlanHeader { priority_code_point: 3, drop_eligible_indicator: false, @@ -1943,7 +1940,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L2_VLAN( + Encapsulation::Vlan( VlanHeader { priority_code_point: 3, drop_eligible_indicator: false, @@ -1955,7 +1952,7 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -1975,7 +1972,7 @@ mod tests { ); assert_eq!( packet.encapsulation[4], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -1995,7 +1992,7 @@ mod tests { ); assert_eq!( packet.encapsulation[5], - Encapsulation::L4_UDP( + Encapsulation::Udp( UdpHeader { source_port: 62367, dest_port: 17000, @@ -2127,7 +2124,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 5); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0x00, 0x30, 0x96, 0x05, 0x28, 0x38]), dest_mac: MacAddress([0x00, 0x30, 0x96, 0xe6, 0xfc, 0x39]), @@ -2138,7 +2135,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L2_MPLS( + Encapsulation::Mpls( MplsHeader { label: 18, experimental: 5, @@ -2150,7 +2147,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L2_MPLS( + Encapsulation::Mpls( MplsHeader { label: 16, experimental: 5, @@ -2162,7 +2159,7 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -2182,7 +2179,7 @@ mod tests { ); assert_eq!( packet.encapsulation[4], - Encapsulation::L4_TCP( + Encapsulation::Tcp( TcpHeader { source_port: 11001, dest_port: 23, @@ -2319,7 +2316,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 7); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0xcc, 0x01, 0x0d, 0x5c, 0x00, 0x10]), dest_mac: MacAddress([0xcc, 0x00, 0x0d, 0x5c, 0x00, 0x10]), @@ -2330,7 +2327,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L2_MPLS( + Encapsulation::Mpls( MplsHeader { label: 19, experimental: 0, @@ -2342,7 +2339,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L2_MPLS( + Encapsulation::Mpls( MplsHeader { label: 16, experimental: 0, @@ -2354,11 +2351,11 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L2_PWETH(PwEthHeader { control_word: 0 }, &bytes[26..]) + Encapsulation::PwEth(PwEthHeader { control_word: 0 }, &bytes[26..]) ); assert_eq!( packet.encapsulation[4], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0x00, 0x50, 0x79, 0x66, 0x68, 0x00]), dest_mac: MacAddress([0x00, 0x50, 0x79, 0x66, 0x68, 0x01]), @@ -2369,7 +2366,7 @@ mod tests { ); assert_eq!( packet.encapsulation[5], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -2389,7 +2386,7 @@ mod tests { ); assert_eq!( packet.encapsulation[6], - Encapsulation::L4_ICMP( + Encapsulation::Icmp( IcmpHeader { icmp_type: IcmpType::EchoRequest, icmp_code: 0, @@ -2556,7 +2553,7 @@ mod tests { assert_eq!(packet.encapsulation.len(), 7); assert_eq!( packet.encapsulation[0], - Encapsulation::L2_ETH( + Encapsulation::Eth( EthernetFrame { source_mac: MacAddress([0xac, 0xb3, 0xb5, 0x40, 0xe9, 0xc3]), dest_mac: MacAddress([0x74, 0x4a, 0xa4, 0x0e, 0xf5, 0x14]), @@ -2567,7 +2564,7 @@ mod tests { ); assert_eq!( packet.encapsulation[1], - Encapsulation::L2_VLAN( + Encapsulation::Vlan( VlanHeader { priority_code_point: 2, drop_eligible_indicator: false, @@ -2579,7 +2576,7 @@ mod tests { ); assert_eq!( packet.encapsulation[2], - Encapsulation::L3_IPV6( + Encapsulation::Ipv6( Ipv6Header { version: 6, dsc: 18, @@ -2597,7 +2594,7 @@ mod tests { ); assert_eq!( packet.encapsulation[3], - Encapsulation::L4_UDP( + Encapsulation::Udp( UdpHeader { source_port: 2152, dest_port: 2152, @@ -2609,7 +2606,7 @@ mod tests { ); assert_eq!( packet.encapsulation[4], - Encapsulation::LTUN_GTPV1_C( + Encapsulation::Gtpv1( Gtpv1Header { version: 1, protocol_type: 1, @@ -2636,7 +2633,7 @@ mod tests { ); assert_eq!( packet.encapsulation[5], - Encapsulation::L3_IPV4( + Encapsulation::Ipv4( Ipv4Header { version: 4, ihl: 20, @@ -2656,7 +2653,7 @@ mod tests { ); assert_eq!( packet.encapsulation[6], - Encapsulation::L4_TCP( + Encapsulation::Tcp( TcpHeader { source_port: 47892, dest_port: 80, |
