Can configure network NAT settings from UI

This commit is contained in:
2024-01-09 21:57:18 +01:00
parent 71e22bc328
commit f82925dbcb
11 changed files with 446 additions and 11 deletions

View File

@ -44,6 +44,9 @@ pub const DISK_SIZE_MIN: usize = 100;
/// Disk size max (MB)
pub const DISK_SIZE_MAX: usize = 1000 * 1000 * 2;
/// Net nat entry comment max size
pub const NET_NAT_COMMENT_MAX_SIZE: usize = 250;
/// Network mac address default prefix
pub const NET_MAC_ADDR_PREFIX: &str = "52:54:00";

View File

@ -43,6 +43,7 @@ struct ServerConstraints {
disk_size: LenConstraints,
net_name_size: LenConstraints,
net_title_size: LenConstraints,
net_nat_comment_size: LenConstraints,
dhcp_reservation_host_name: LenConstraints,
nwfilter_name_size: LenConstraints,
nwfilter_comment_size: LenConstraints,
@ -81,6 +82,10 @@ pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder {
net_name_size: LenConstraints { min: 2, max: 50 },
net_title_size: LenConstraints { min: 0, max: 50 },
net_nat_comment_size: LenConstraints {
min: 0,
max: constants::NET_NAT_COMMENT_MAX_SIZE,
},
dhcp_reservation_host_name: LenConstraints { min: 2, max: 250 },

View File

@ -1,3 +1,4 @@
use crate::constants;
use crate::utils::net_utils;
use std::net::{Ipv4Addr, Ipv6Addr};
@ -64,6 +65,12 @@ impl<IPv> Nat<IPv> {
return Err(NatDefError::InvalidNatDef("Invalid guest port!").into());
}
if let Some(comment) = &self.comment {
if comment.len() > constants::NET_NAT_COMMENT_MAX_SIZE {
return Err(NatDefError::InvalidNatDef("Comment is too large!").into());
}
}
Ok(())
}
}