Skip to content

Commit

Permalink
style: rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern authored and github-actions[bot] committed Mar 13, 2024
1 parent 5d982dc commit 443fd89
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions src/net/offline_fluereflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/net/parser/fluereflows.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(),
))
}
Expand Down Expand Up @@ -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());

Expand Down
6 changes: 3 additions & 3 deletions src/net/parser/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
))
}
};
Expand Down
20 changes: 8 additions & 12 deletions src/net/parser/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion src/net/parser/tos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn dscp_to_tos(dscp: u8) -> Result<u8, NetError> {
46 => 184,
48 => 192,
56 => 224,
_ => return Err(NetError::UnknownDSCP ( dscp )),
_ => return Err(NetError::UnknownDSCP(dscp)),
};

Ok(tos)
Expand Down

0 comments on commit 443fd89

Please sign in to comment.