Add basic NAT structures
This commit is contained in:
39
virtweb_backend/src/nat/nat_definition.rs
Normal file
39
virtweb_backend/src/nat/nat_definition.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(tag = "type", rename_all = "lowercase")]
|
||||
pub enum NatSource<IPv> {
|
||||
Interface { name: String },
|
||||
Ip { ip: IPv },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub enum NatProtocol {
|
||||
TCP,
|
||||
UDP,
|
||||
Both,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(tag = "type", rename_all = "lowercase")]
|
||||
pub enum NatHostPort {
|
||||
Single { port: u16 },
|
||||
Range { start: u16, end: u16 },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Nat<IPv> {
|
||||
pub protocol: NatProtocol,
|
||||
pub host_addr: NatSource<IPv>,
|
||||
pub host_port: NatHostPort,
|
||||
pub guest_addr: IPv,
|
||||
pub guest_port: u16,
|
||||
pub comment: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Default)]
|
||||
pub struct NetNat {
|
||||
pub interface: String,
|
||||
pub ipv4: Option<Vec<Nat<Ipv4Addr>>>,
|
||||
pub ipv6: Option<Vec<Nat<Ipv6Addr>>>,
|
||||
}
|
Reference in New Issue
Block a user