move definitions to seperate files

This commit is contained in:
Samuel Lorch 2023-10-20 23:35:05 +02:00
parent 4fdfb151de
commit e67c7679a2
4 changed files with 128 additions and 112 deletions

View file

@ -0,0 +1,44 @@
use ipnet::IpNet;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, net::IpAddr};
use validator::Validate;
#[derive(Serialize, Deserialize, Validate, Default, Debug)]
pub struct Network {
pub interfaces: HashMap<String, NetworkInterface>,
pub static_routes: Vec<StaticRoute>,
}
#[derive(Serialize, Deserialize, Validate, Debug)]
pub struct NetworkInterface {
pub alias: String,
pub comment: String,
pub interface_type: NetworkInterfaceType,
pub addressing_mode: AddressingMode,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum NetworkInterfaceType {
Hardware { device: String },
Vlan { id: i32, parent: String },
Bond { members: Vec<String> },
Bridge { members: Vec<String> },
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum AddressingMode {
None,
Static { address: String },
DHCP,
}
#[derive(Serialize, Deserialize, Validate, Debug)]
pub struct StaticRoute {
pub name: String,
pub interface: String,
pub gateway: IpAddr,
pub destination: IpNet,
pub metric: u64,
}

54
src/definitions/object.rs Normal file
View file

@ -0,0 +1,54 @@
use ipnet::IpNet;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, net::IpAddr};
use validator::Validate;
#[derive(Serialize, Deserialize, Validate, Default, Debug)]
pub struct Object {
pub addresses: HashMap<String, Address>,
pub services: HashMap<String, Service>,
}
#[derive(Serialize, Deserialize, Validate, Debug)]
pub struct Address {
pub address_type: AddressType,
pub comment: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum AddressType {
Host { host: String },
Range { range: IpAddr },
Network { network: IpNet },
Group { children: Vec<String> },
}
#[derive(Serialize, Deserialize, Validate, Debug)]
pub struct Service {
pub service_type: ServiceType,
pub comment: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum ServiceType {
TCP {
source_port: u64,
source_port_end: Option<u64>,
destination_port: u64,
destination_port_end: Option<u64>,
},
UDP {
source_port: u64,
source_port_end: Option<u64>,
destination_port: u64,
destination_port_end: Option<u64>,
},
ICMP {
code: u8,
},
Group {
children: Vec<String>,
},
}