From 443fd897097662375d83b2db5a09b065f319b45a Mon Sep 17 00:00:00 2001 From: SkuldNorniern Date: Wed, 13 Mar 2024 02:57:37 +0000 Subject: [PATCH] style: `rustfmt` --- src/net/mod.rs | 4 ++-- src/net/offline_fluereflows.rs | 6 +++--- src/net/parser/fluereflows.rs | 6 +++--- src/net/parser/keys.rs | 6 +++--- src/net/parser/ports.rs | 20 ++++++++------------ src/net/parser/tos.rs | 2 +- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/net/mod.rs b/src/net/mod.rs index 713ae12..38f58d1 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -54,10 +54,10 @@ impl Display for NetError { NetError::PcapError(err) => err.fmt(f), NetError::UnknownProtocol(protocol) => { write!(f, "Unknown protocol: {}", protocol) - }, + } NetError::UnknownEtherType(ether_type) => { write!(f, "Unknown ether type: {}", ether_type) - }, + } NetError::UnknownDSCP(dscp) => write!(f, "Unknown dscp: {}", dscp), NetError::InvalidPacket => write!(f, "Invalid packet"), NetError::EmptyPacket => write!(f, "Empty packet"), diff --git a/src/net/offline_fluereflows.rs b/src/net/offline_fluereflows.rs index 3d9ee4f..c6d38cc 100644 --- a/src/net/offline_fluereflows.rs +++ b/src/net/offline_fluereflows.rs @@ -52,9 +52,9 @@ pub async fn fluereflow_fileparse(arg: Args) { let (doctets, raw_flags, flowdata) = match parse_fluereflow(packet.clone()) { Ok(result) => result, Err(e) => { - debug!("{}", e); - continue; - } + debug!("{}", e); + continue; + } }; let flags = TcpFlags::new(raw_flags); //pushing packet in to active_flows if it is not present diff --git a/src/net/parser/fluereflows.rs b/src/net/parser/fluereflows.rs index 18f8fd1..94a927a 100644 --- a/src/net/parser/fluereflows.rs +++ b/src/net/parser/fluereflows.rs @@ -1,9 +1,9 @@ use pcap; -use crate::net::NetError; use crate::net::parser::{ dscp_to_tos, parse_flags, parse_microseconds, parse_ports, protocol_to_number, }; +use crate::net::NetError; use fluereflow::FluereRecord; use pnet::packet::{ arp::ArpPacket, @@ -130,7 +130,7 @@ pub fn parse_fluereflow(packet: pcap::Packet) -> Result<(usize, [u8; 9], FluereR arp_packet(time, i) } _ => { - return Err(NetError::UnknownEtherType ( + return Err(NetError::UnknownEtherType( ethernet_packet.get_ethertype().to_string(), )) } @@ -198,7 +198,7 @@ fn ipv4_packet(time: u64, packet: Ipv4Packet) -> Result<(usize, [u8; 9], FluereR // ports parsing let (src_port, dst_port) = parse_ports(protocol, packet.payload())?; - + // TCP flags Fin Syn Rst Psh Ack Urg Ece Cwr Ns let flags = parse_flags(protocol, packet.payload()); diff --git a/src/net/parser/keys.rs b/src/net/parser/keys.rs index 8532181..1c50204 100644 --- a/src/net/parser/keys.rs +++ b/src/net/parser/keys.rs @@ -8,9 +8,9 @@ use pnet::packet::ipv6::Ipv6Packet; use pnet::packet::udp::UdpPacket; use pnet::packet::Packet; -use crate::net::NetError; use crate::net::parser::{parse_ports, protocol_to_number}; use crate::net::types::{Key, MacAddress}; +use crate::net::NetError; use std::net::IpAddr; @@ -146,8 +146,8 @@ pub fn parse_keys(packet: pcap::Packet) -> Result<(Key, Key), NetError> { } _ => { - return Err(NetError::UnknownEtherType ( - ethernet_packet.get_ethertype().to_string() + return Err(NetError::UnknownEtherType( + ethernet_packet.get_ethertype().to_string(), )) } }; diff --git a/src/net/parser/ports.rs b/src/net/parser/ports.rs index 03f4898..a778c1c 100644 --- a/src/net/parser/ports.rs +++ b/src/net/parser/ports.rs @@ -6,18 +6,14 @@ use pnet::packet::{tcp::TcpPacket, udp::UdpPacket}; pub fn parse_ports(protocol: u8, payload: &[u8]) -> Result<(u16, u16), NetError> { match protocol { 58 => Ok((0, 0)), - 17 => { - match UdpPacket::new(payload) { - Some(udp) => Ok((udp.get_source(), udp.get_destination())), - None => Err(NetError::InvalidPacket), - } - } - 6 => { - match TcpPacket::new(payload){ - Some(tcp) => Ok((tcp.get_source(), tcp.get_destination())), - None => Err(NetError::InvalidPacket), - } - } + 17 => match UdpPacket::new(payload) { + Some(udp) => Ok((udp.get_source(), udp.get_destination())), + None => Err(NetError::InvalidPacket), + }, + 6 => match TcpPacket::new(payload) { + Some(tcp) => Ok((tcp.get_source(), tcp.get_destination())), + None => Err(NetError::InvalidPacket), + }, 2 => Ok((0, 0)), 1 => Ok((0, 0)), 0 => Ok((0, 0)), diff --git a/src/net/parser/tos.rs b/src/net/parser/tos.rs index 26a006c..e03e296 100644 --- a/src/net/parser/tos.rs +++ b/src/net/parser/tos.rs @@ -23,7 +23,7 @@ pub fn dscp_to_tos(dscp: u8) -> Result { 46 => 184, 48 => 192, 56 => 224, - _ => return Err(NetError::UnknownDSCP ( dscp )), + _ => return Err(NetError::UnknownDSCP(dscp)), }; Ok(tos)