really broken WIP for now xD
This commit is contained in:
parent
50524cb5ae
commit
1a5b7da6ae
1 changed files with 52 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use tun::Error;
|
use tun::Error;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
// Here we will recieve bytes and try to get their destanation & apply Rules for them.
|
// Here we will recieve bytes and try to get their destanation & apply Rules for them.
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
|
@ -9,6 +10,13 @@ pub enum Protocol {
|
||||||
UDP,
|
UDP,
|
||||||
Unsupported(u8)
|
Unsupported(u8)
|
||||||
}
|
}
|
||||||
|
type SourceV4Ip = Ipv4;
|
||||||
|
type SourceV6Ip = Ipv6;
|
||||||
|
pub enum IpVersion {
|
||||||
|
V4,
|
||||||
|
V6
|
||||||
|
}
|
||||||
|
// type IpVersion = String;
|
||||||
type Ipv4 = [u8; 4];
|
type Ipv4 = [u8; 4];
|
||||||
type Ipv6 = [u8; 16];
|
type Ipv6 = [u8; 16];
|
||||||
type Port = u16;
|
type Port = u16;
|
||||||
|
|
@ -34,7 +42,51 @@ pub enum PacketInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for PacketInfo {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
if self.version() == "Ipv4" {
|
||||||
|
let src_ip = self.src_ipv4_ip();
|
||||||
|
let dst_ip = self.dst_ipv4_ip();
|
||||||
|
write!(f, "{} {}.{}.{}.{}:{} -> {}.{}.{}.{}:{} PROTO {} DNS? {}", self.version(), src_ip[0], src_ip[1], src_ip[2], src_ip[3], self.src_port, dst_ip[0], dst_ip[1], dst_ip[2], dst_ip[3], self.dst_port(), self.protocol(), self.dns())
|
||||||
|
}
|
||||||
|
// write!(f, "{} {}:{} -> {}:{} PROTO {} DNS? {}", self.version(), self.)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PacketInfo {
|
impl PacketInfo {
|
||||||
|
pub fn dns(&self) -> &bool {
|
||||||
|
match self {
|
||||||
|
PacketInfo::V4 { dns, ..} => dns,
|
||||||
|
PacketInfo::V6 { dns, ..} => dns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn dst_ipv4_ip(&self) -> &SourceV4Ip {
|
||||||
|
match self {
|
||||||
|
PacketInfo::V4 { dst_ip, .. } => dst_ip,
|
||||||
|
_ => &[0x0, 0x0, 0x0, 0x0].try_into().expect("this never should fail or even be called in the first place.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn src_ipv6_ip(&self) -> &SourceV6Ip {
|
||||||
|
match self {
|
||||||
|
PacketInfo::V6 { src_ip, .. } => src_ip,
|
||||||
|
_ => &[0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0].try_into().expect("this never should fail or even be called in the first place.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn src_ipv4_ip(&self) -> &SourceV4Ip {
|
||||||
|
match self {
|
||||||
|
PacketInfo::V4 { src_ip, .. } => src_ip,
|
||||||
|
_ => &[0x0, 0x0, 0x0, 0x0].try_into().expect("this never should fail or even be called in the first place.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn src_ipv6_ip(&self) -> &SourceV6Ip {
|
||||||
|
PacketInfo::V6.src_ip
|
||||||
|
}
|
||||||
|
pub fn version(&self) -> &IpVersion {
|
||||||
|
match self {
|
||||||
|
PacketInfo::V4 { .. }=> &IpVersion::V4,
|
||||||
|
PacketInfo::V6 { .. }=> &IpVersion::V6
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn protocol(&self) -> &Protocol {
|
pub fn protocol(&self) -> &Protocol {
|
||||||
match self {
|
match self {
|
||||||
PacketInfo::V4 { protocol, .. } => protocol,
|
PacketInfo::V4 { protocol, .. } => protocol,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue