Skip to main content

unifly_api/model/
network.rs

1// ── Network domain types ──
2
3use serde::{Deserialize, Serialize};
4use std::net::{IpAddr, Ipv4Addr};
5
6use super::common::{DataSource, EntityOrigin};
7use super::entity_id::EntityId;
8
9/// Network management type (from Integration API taxonomy).
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11pub enum NetworkManagement {
12    Gateway,
13    Switch,
14    Unmanaged,
15}
16
17/// Legacy network purpose (from Legacy API).
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
19pub enum NetworkPurpose {
20    Corporate,
21    Guest,
22    Wan,
23    VlanOnly,
24}
25
26/// IPv6 configuration mode.
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
28#[non_exhaustive]
29pub enum Ipv6Mode {
30    PrefixDelegation,
31    Static,
32}
33
34impl std::fmt::Display for Ipv6Mode {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        match self {
37            Self::PrefixDelegation => f.write_str("Prefix Del"),
38            Self::Static => f.write_str("Static"),
39        }
40    }
41}
42
43/// DHCP server configuration.
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct DhcpConfig {
46    pub enabled: bool,
47    pub range_start: Option<Ipv4Addr>,
48    pub range_stop: Option<Ipv4Addr>,
49    pub lease_time_secs: Option<u64>,
50    pub dns_servers: Vec<IpAddr>,
51    pub gateway: Option<Ipv4Addr>,
52}
53
54/// The canonical Network type.
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[allow(clippy::struct_excessive_bools)]
57pub struct Network {
58    pub id: EntityId,
59    pub name: String,
60    pub enabled: bool,
61
62    // Classification
63    pub management: Option<NetworkManagement>,
64    pub purpose: Option<NetworkPurpose>,
65    pub is_default: bool,
66
67    // VLAN
68    pub vlan_id: Option<u16>,
69
70    // IPv4
71    pub subnet: Option<String>,
72    pub gateway_ip: Option<Ipv4Addr>,
73
74    // DHCP
75    pub dhcp: Option<DhcpConfig>,
76
77    // IPv6
78    pub ipv6_enabled: bool,
79    pub ipv6_mode: Option<Ipv6Mode>,
80    pub ipv6_prefix: Option<String>,
81    pub dhcpv6_enabled: bool,
82    pub slaac_enabled: bool,
83
84    // Advanced DHCP / Boot
85    pub ntp_server: Option<IpAddr>,
86    pub pxe_enabled: bool,
87    pub tftp_server: Option<String>,
88
89    // Firewall zone association
90    pub firewall_zone_id: Option<EntityId>,
91
92    // Flags
93    pub isolation_enabled: bool,
94    pub internet_access_enabled: bool,
95    pub mdns_forwarding_enabled: bool,
96    pub cellular_backup_enabled: bool,
97
98    pub origin: Option<EntityOrigin>,
99
100    #[serde(skip)]
101    #[allow(dead_code)]
102    pub(crate) source: DataSource,
103}