A simple String wrapper that represents the name of a network
interface. We are restricting the interface name to ASCII-only
characters via the regex, since otherwise the length check would fail,
due to String being Unicode. While network interface names can be
arbitrary bytes and don't correspond to a specific encoding,
restricting it to ASCII seemed sensible here. We can always lift the
restriction later if this is required.

Co-authored-by: Gabriel Goller <g.gol...@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanre...@proxmox.com>
---
 .../sdn/fabric/section_config/interface.rs    | 22 +++++++++++++++++++
 .../src/sdn/fabric/section_config/mod.rs      |  1 +
 2 files changed, 23 insertions(+)
 create mode 100644 proxmox-ve-config/src/sdn/fabric/section_config/interface.rs

diff --git a/proxmox-ve-config/src/sdn/fabric/section_config/interface.rs 
b/proxmox-ve-config/src/sdn/fabric/section_config/interface.rs
new file mode 100644
index 0000000..4374f38
--- /dev/null
+++ b/proxmox-ve-config/src/sdn/fabric/section_config/interface.rs
@@ -0,0 +1,22 @@
+use serde::{Deserialize, Serialize};
+
+use proxmox_schema::{api, api_string_type, const_regex, ApiStringFormat, 
UpdaterType};
+
+const_regex! {
+    pub INTERFACE_NAME_REGEX = r"^[[:ascii:]]+$";
+}
+
+pub const INTERFACE_NAME_FORMAT: ApiStringFormat = 
ApiStringFormat::Pattern(&INTERFACE_NAME_REGEX);
+
+api_string_type! {
+    /// Name of a network interface.
+    ///
+    /// The interface name can have a maximum of 15 characters. This is a 
kernel limit.
+    #[api(
+        min_length: 1,
+        max_length: 15,
+        format: &INTERFACE_NAME_FORMAT,
+    )]
+    #[derive(Debug, Deserialize, Serialize, Clone, Hash, PartialEq, Eq, 
PartialOrd, Ord, UpdaterType)]
+    pub struct InterfaceName(String);
+}
diff --git a/proxmox-ve-config/src/sdn/fabric/section_config/mod.rs 
b/proxmox-ve-config/src/sdn/fabric/section_config/mod.rs
index 0ca5695..b61bc43 100644
--- a/proxmox-ve-config/src/sdn/fabric/section_config/mod.rs
+++ b/proxmox-ve-config/src/sdn/fabric/section_config/mod.rs
@@ -1,2 +1,3 @@
 pub mod fabric;
+pub mod interface;
 pub mod node;
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to