Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display more infos per packet #18

Merged
merged 9 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ sudo oryx

`f`: Update the applied filters.

`i`: Show more infos about the selected packet.

`ctrl + r`: Reset the app.

`ctrl + s`: Export the capture to `~/oryx/capture` file.
Expand Down
4 changes: 4 additions & 0 deletions Release.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## v0.3 - TBA

### Added

- Show packet details

### Changed

- move filters to the epbf program
Expand Down
52 changes: 0 additions & 52 deletions oryx-common/src/arp.rs

This file was deleted.

227 changes: 134 additions & 93 deletions oryx-common/src/ip.rs
Original file line number Diff line number Diff line change
@@ -1,93 +1,134 @@
use core::{fmt::Display, net::IpAddr};

use network_types::{icmp::IcmpHdr, tcp::TcpHdr, udp::UdpHdr};

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct TcpPacket {
pub dst_port: u16,
pub src_port: u16,
pub dst_ip: IpAddr,
pub src_ip: IpAddr,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct UdpPacket {
pub dst_port: u16,
pub src_port: u16,
pub dst_ip: IpAddr,
pub src_ip: IpAddr,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct IcmpPacket {
pub icmp_type: IcmpType,
pub dst_ip: IpAddr,
pub src_ip: IpAddr,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub enum IcmpType {
EchoRequest,
EchoReply,
DestinationUnreachable,
}

impl Display for IcmpType {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
IcmpType::EchoReply => {
write!(f, "Echo Reply")
}
IcmpType::EchoRequest => {
write!(f, "Echo Request")
}
IcmpType::DestinationUnreachable => {
write!(f, "Destination Unreachable")
}
}
}
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub enum IpPacket {
Tcp(TcpPacket),
Udp(UdpPacket),
Icmp(IcmpPacket),
}

#[repr(C)]
#[derive(Copy, Clone)]
pub enum ProtoHdr {
Tcp(TcpHdr),
Udp(UdpHdr),
Icmp(IcmpHdr),
}

impl Display for IpPacket {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
IpPacket::Tcp(p) => {
write!(
f,
"{} {} {} {} TCP",
p.src_ip, p.src_port, p.dst_ip, p.dst_port
)
}
IpPacket::Udp(p) => {
write!(
f,
"{} {} {} {} UDP",
p.src_ip, p.src_port, p.dst_ip, p.dst_port
)
}
IpPacket::Icmp(p) => {
write!(f, "{} {} ICMP", p.src_ip, p.dst_ip)
}
}
}
}
// use core::fmt::Display;
//
// use core::net::{Ipv4Addr, Ipv6Addr};
//
// #[derive(Debug, Copy, Clone)]
// pub enum IpPacket {
// V4(Ipv4Packet),
// V6(Ipv6Packet),
// }
//
// #[derive(Debug, Copy, Clone)]
// pub struct Ipv4Packet {
// pub src_ip: Ipv4Addr,
// pub dst_ip: Ipv4Addr,
// pub ihl: u8,
// pub tos: u8,
// pub total_length: u16,
// pub id: u16,
// pub fragment_offset: u16,
// pub ttl: u8,
// pub proto: IpProto,
// pub checksum: u16,
// }
//
// #[derive(Debug, Copy, Clone)]
// pub struct Ipv6Packet {
// pub src_ip: Ipv6Addr,
// pub dst_ip: Ipv6Addr,
// pub proto: IpProto,
// }
//
// #[derive(Debug, Copy, Clone)]
// pub enum IpProto {
// Tcp(TcpPacket),
// Udp(UdpPacket),
// Icmp(IcmpPacket),
// }
//
// #[derive(Debug, Copy, Clone)]
// pub struct TcpPacket {
// pub dst_port: u16,
// pub src_port: u16,
// }
//
// #[derive(Debug, Copy, Clone)]
// pub struct UdpPacket {
// pub dst_port: u16,
// pub src_port: u16,
// }
//
// #[derive(Debug, Copy, Clone)]
// pub struct IcmpPacket {
// pub icmp_type: IcmpType,
// }
//
// #[derive(Debug, Copy, Clone)]
// pub enum IcmpType {
// EchoRequest,
// EchoReply,
// DestinationUnreachable,
// }
//
// impl Display for IcmpType {
// fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
// match self {
// IcmpType::EchoReply => {
// write!(f, "Echo Reply")
// }
// IcmpType::EchoRequest => {
// write!(f, "Echo Request")
// }
// IcmpType::DestinationUnreachable => {
// write!(f, "Destination Unreachable")
// }
// }
// }
// }
//
// impl Display for IpPacket {
// fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
// match self {
// IpPacket::V4(ipv4_packet) => match ipv4_packet.proto {
// IpProto::Tcp(tcp_packet) => {
// write!(
// f,
// "{} {} {} {} TCP",
// ipv4_packet.src_ip,
// tcp_packet.src_port,
// ipv4_packet.dst_ip,
// tcp_packet.dst_port
// )
// }
// IpProto::Udp(udp_packet) => {
// write!(
// f,
// "{} {} {} {} UDP",
// ipv4_packet.src_ip,
// udp_packet.src_port,
// ipv4_packet.dst_ip,
// udp_packet.dst_port
// )
// }
// IpProto::Icmp(_) => {
// write!(f, "{} {} ICMP", ipv4_packet.src_ip, ipv4_packet.dst_ip)
// }
// },
// IpPacket::V6(ipv6_packet) => match ipv6_packet.proto {
// IpProto::Tcp(tcp_packet) => {
// write!(
// f,
// "{} {} {} {} TCP",
// ipv6_packet.src_ip,
// tcp_packet.src_port,
// ipv6_packet.dst_ip,
// tcp_packet.dst_port
// )
// }
// IpProto::Udp(udp_packet) => {
// write!(
// f,
// "{} {} {} {} UDP",
// ipv6_packet.src_ip,
// udp_packet.src_port,
// ipv6_packet.dst_ip,
// udp_packet.dst_port
// )
// }
// IpProto::Icmp(_) => {
// write!(f, "{} {} ICMP", ipv6_packet.src_ip, ipv6_packet.dst_ip)
// }
// },
// }
// }
// }
Loading