use crate::Packet;
use std::net::{IpAddr, Ipv4Addr};
use std::time::Instant;
pub(crate) const PROTO_ICMP: u8 = 1;
pub(crate) const PROTO_TCP: u8 = 6;
pub(crate) const PROTO_UDP: u8 = 17;
pub(crate) const PROTO_ICMPV6: u8 = 58;
pub trait Helper: Send + Sync {
fn name(&self) -> &str;
fn close(&self) -> crate::Result<()> {
Ok(())
}
}
#[derive(Debug, Clone, Copy)]
pub struct NatMapping {
pub proto: u8,
pub inside_ip: IpAddr,
pub inside_port: u16,
pub outside_port: u16,
}
pub trait PacketHelper: Helper {
fn match_outbound(&self, proto: u8, dst_port: u16) -> bool;
fn process_outbound(&self, nat: &super::nat::Nat, pkt: Vec<u8>, m: &NatMapping) -> Vec<u8> {
let _ = (nat, m);
pkt
}
fn process_inbound(&self, nat: &super::nat::Nat, pkt: Vec<u8>, m: &NatMapping) -> Vec<u8> {
let _ = (nat, m);
pkt
}
}
pub trait LocalHelper: Helper {
fn handle_local(&self, nat: &super::nat::Nat, pkt: &Packet) -> bool;
}
#[derive(Debug, Clone)]
pub struct Expectation {
pub proto: u8,
pub remote_ip: Ipv4Addr,
pub remote_port: u16,
pub inside_ip: Ipv4Addr,
pub inside_port: u16,
pub expires: Instant,
}
#[derive(Debug, Clone)]
pub struct PortForward {
pub proto: u8,
pub outside_port: u16,
pub inside_ip: Ipv4Addr,
pub inside_port: u16,
pub description: String,
pub expires: Option<Instant>,
}