-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
big thanks to my friend @adgaultier Co-authored-by: adrien gaultier <adrien.gaultier@protonmail.com>
- Loading branch information
1 parent
2289c92
commit 648cde1
Showing
22 changed files
with
976 additions
and
662 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ show interface: | |
|
||
# Run oryx | ||
run: | ||
cargo xtask run | ||
cargo xtask run --release | ||
|
||
# Build oryx | ||
build: | ||
|
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use core::fmt::Display; | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct ArpPacket { | ||
pub arp_type: ArpType, | ||
pub src_mac: MacAddr, | ||
pub dst_mac: MacAddr, | ||
} | ||
|
||
impl Display for ArpPacket { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
write!(f, "{} {} ARP", self.src_mac, self.dst_mac) | ||
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum ArpType { | ||
Request, | ||
Reply, | ||
} | ||
|
||
impl Display for ArpType { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
Self::Request => write!(f, "Arp Request"), | ||
Self::Reply => write!(f, "Arp Reply"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct MacAddr(pub [u8; 6]); | ||
|
||
impl Display for MacAddr { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
//FIX: workaround for the moment | ||
if self.0.iter().all(|x| *x == 0) { | ||
write!(f, "ff:ff:ff:ff:ff:ff",) | ||
} else { | ||
write!( | ||
f, | ||
"{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", | ||
self.0[0].to_be(), | ||
self.0[1].to_be(), | ||
self.0[2].to_be(), | ||
self.0[3].to_be(), | ||
self.0[4].to_be(), | ||
self.0[5].to_be() | ||
) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.