-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change error in pcap-rewrite filters from String to libpcap_tools::Error
- Loading branch information
1 parent
74a8985
commit 72b7c5e
Showing
9 changed files
with
163 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,47 @@ | ||
use log::warn; | ||
|
||
use libpcap_tools::Error; | ||
use pnet_packet::ethernet::{EtherTypes, EthernetPacket}; | ||
use pnet_packet::vlan::VlanPacket; | ||
use pnet_packet::Packet; | ||
use pnet_packet::PrimitiveValues; | ||
|
||
pub fn extract_callback_ethernet<D>( | ||
get_key_from_ipv4_l3_data: &dyn Fn(&[u8]) -> Result<D, String>, | ||
get_key_from_ipv6_l3_data: &dyn Fn(&[u8]) -> Result<D, String>, | ||
get_key_from_ipv4_l3_data: &dyn Fn(&[u8]) -> Result<D, Error>, | ||
get_key_from_ipv6_l3_data: &dyn Fn(&[u8]) -> Result<D, Error>, | ||
packet_data: &[u8], | ||
) -> Result<D, String> { | ||
let ethernet_packet = | ||
EthernetPacket::new(packet_data).ok_or("Expected Ethernet packet but not found")?; | ||
) -> Result<D, Error> { | ||
let ethernet_packet = EthernetPacket::new(packet_data) | ||
.ok_or(Error::Pnet("Expected Ethernet packet but could not parse"))?; | ||
match ethernet_packet.get_ethertype() { | ||
EtherTypes::Ipv4 => (get_key_from_ipv4_l3_data)(ethernet_packet.payload()), | ||
EtherTypes::Ipv6 => (get_key_from_ipv6_l3_data)(ethernet_packet.payload()), | ||
EtherTypes::Vlan => { | ||
// 802.11q | ||
let vlan_packet = VlanPacket::new(ethernet_packet.payload()) | ||
.ok_or("Expected VLAN packet but not found")?; | ||
.ok_or(Error::Pnet("Expected VLAN packet but could not parse"))?; | ||
match vlan_packet.get_ethertype() { | ||
EtherTypes::Ipv4 => (get_key_from_ipv4_l3_data)(ethernet_packet.payload()), | ||
EtherTypes::Ipv6 => (get_key_from_ipv6_l3_data)(ethernet_packet.payload()), | ||
_ => Err(format!( | ||
"Unimplemented Ethertype in 33024/802.11q: {:?}/{:x}", | ||
vlan_packet.get_ethertype(), | ||
vlan_packet.get_ethertype().to_primitive_values().0 | ||
)), | ||
_ => { | ||
warn!( | ||
"Unimplemented Ethertype in 33024/802.11q: {:?}/{:x}", | ||
vlan_packet.get_ethertype(), | ||
vlan_packet.get_ethertype().to_primitive_values().0 | ||
); | ||
Err(Error::Unimplemented( | ||
"Unimplemented Ethertype in 33024/802.11q", | ||
)) | ||
} | ||
} | ||
} | ||
_ => Err(format!( | ||
"Unimplemented Ethertype: {:?}/{:x}", | ||
ethernet_packet.get_ethertype(), | ||
ethernet_packet.get_ethertype().to_primitive_values().0 | ||
)), | ||
_ => { | ||
warn!( | ||
"Unimplemented Ethertype: {:?}/{:x}", | ||
ethernet_packet.get_ethertype(), | ||
ethernet_packet.get_ethertype().to_primitive_values().0 | ||
); | ||
Err(Error::Unimplemented("Unimplemented Ethertype")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.