Skip to content

Commit 498dc61

Browse files
authored
Merge pull request #7 from rucoder/rucoder/fix-ntp-servers
Fix NTP server parsing
2 parents bcde346 + 35f93df commit 498dc61

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"type":"AppStatus","message":{"UUIDandVersion":{"UUID":"3689d431-4fa5-4e55-8601-fb1bcc11e13c","Version":"1"},"DisplayName":"Windows-Server-2022_zeljkos_Nov30th2024_hvm-HPE-Drivers-included","DomainName":"","Activated":false,"ActivateInprogress":false,"FixedResources":{"Kernel":"","Ramdisk":"","Memory":8388608,"MaxMem":8388608,"VCpus":4,"MaxCpus":0,"RootDev":"/dev/xvda1","ExtraArgs":"","BootLoader":"/usr/bin/pygrub","CPUs":null,"DeviceTree":"","DtDev":null,"IRQs":null,"IOMem":null,"VirtualizationMode":1,"EnableVnc":true,"VncDisplay":2,"VncPasswd":"","CPUsPinned":false,"VMMMaxMem":0,"EnableVncShimVM":false},"VolumeRefStatusList":[{"VolumeID":"c2adbfcf-cc16-45f4-87f3-7b527f25bd8f","GenerationCounter":0,"LocalGenerationCounter":0,"AppUUID":"3689d431-4fa5-4e55-8601-fb1bcc11e13c","State":100,"ActiveFileLocation":"","ContentFormat":0,"ReadOnly":false,"DisplayName":"","MaxVolSize":0,"PendingAdd":false,"WWN":"","VerifyOnly":true,"Target":0,"CustomMeta":"","ReferenceName":"","ErrorSourceType":"","Error":"","ErrorTime":"0001-01-01T00:00:00Z","ErrorSeverity":0,"ErrorRetryCondition":"","ErrorEntities":null}],"AppNetAdapters":null,"BootTime":"0001-01-01T00:00:00Z","IoAdapterList":null,"RestartInprogress":0,"RestartStartedAt":"0001-01-01T00:00:00Z","PurgeInprogress":0,"PurgeStartedAt":"0001-01-01T00:00:00Z","State":100,"MissingNetwork":false,"MissingMemory":false,"ErrorSourceType":"","Error":"","ErrorTime":"0001-01-01T00:00:00Z","ErrorSeverity":0,"ErrorRetryCondition":"","ErrorEntities":null,"StartTime":"2024-12-06T15:09:39.448125386Z","SnapStatus":{"MaxSnapshots":1,"RequestedSnapshots":null,"AvailableSnapshots":null,"SnapshotsToBeDeleted":null,"PreparedVolumesSnapshotConfigs":null,"SnapshotOnUpgrade":false,"HasRollbackRequest":false,"ActiveSnapshot":"","RollbackInProgress":false},"MemOverhead":0}}
1+
{"type":"NetworkStatus","message":{"DPCKey":"zedagent","Version":1,"Testing":true,"State":4,"CurrentIndex":0,"RadioSilence":{"Imposed":false,"ChangeInProgress":false,"ChangeRequestedAt":"2025-01-19T12:51:48.418306605Z","ConfigError":""},"Ports":[{"IfName":"eth0","Phylabel":"eth0","Logicallabel":"eth0","SharedLabels":["all","uplink","freeuplink"],"Alias":"","IsMgmt":true,"IsL3Port":true,"InvalidConfig":false,"Cost":0,"Dhcp":4,"Type":4,"Subnet":{"IP":"","Mask":"AAAAAA=="},"ConfiguredNtpServers":null,"IgnoreDhcpNtpServers":false,"DomainName":"","DNSServers":null,"DhcpNtpServers":null,"AddrInfoList":null,"Up":true,"MacAddr":"UlQAdBB6","DefaultRouters":null,"MTU":1500,"WirelessCfg":{"WType":0,"CellularV2":{"AccessPoints":null,"Probe":{"Disable":false,"UserDefinedProbe":{"Method":0,"ProbeHost":"","ProbePort":0}},"LocationTracking":false},"Wifi":null,"Cellular":null},"WirelessStatus":{"WType":0,"Cellular":{"LogicalLabel":"","PhysAddrs":{"Interface":"","USB":"","PCI":"","Dev":""},"Module":{"Name":"","IMEI":"","Model":"","Manufacturer":"","Revision":"","ControlProtocol":"","OpMode":""},"SimCards":null,"ConfigError":"","ProbeError":"","CurrentProvider":{"PLMN":"","Description":"","CurrentServing":false,"Roaming":false,"Forbidden":false},"VisibleProviders":null,"CurrentRATs":null,"ConnectedAt":0,"IPSettings":{"Address":null,"Gateway":"","DNSServers":null,"MTU":0},"LocationTracking":false}},"Proxies":null,"Exceptions":"","Pacfile":"","NetworkProxyEnable":false,"NetworkProxyURL":"","WpadURL":"","pubsub-large-ProxyCertPEM":null,"L2Type":0,"VLAN":{"ParentPort":"","ID":0},"Bond":{"AggregatedPorts":null,"Mode":0,"LacpRate":0,"MIIMonitor":{"Enabled":false,"Interval":0,"UpDelay":0,"DownDelay":0},"ARPMonitor":{"Enabled":false,"Interval":0,"IPTargets":null}},"LastFailed":"2025-01-19T12:51:50.506095242Z","LastSucceeded":"0001-01-01T00:00:00Z","LastError":"link not up for interface eth0 (down)","LastWarning":""},{"IfName":"eth1","Phylabel":"eth1","Logicallabel":"eth1","SharedLabels":["all","uplink","freeuplink"],"Alias":"","IsMgmt":true,"IsL3Port":true,"InvalidConfig":false,"Cost":0,"Dhcp":4,"Type":4,"Subnet":{"IP":"192.168.123.0","Mask":"////AA=="},"ConfiguredNtpServers":null,"IgnoreDhcpNtpServers":false,"DomainName":"","DNSServers":["192.168.123.1"],"DhcpNtpServers":null,"AddrInfoList":[{"Addr":"fe80::2bbe:adfd:89be:a691","Geo":{"ip":"","hostname":"","city":"","region":"","country":"","loc":"","org":"","postal":""},"LastGeoTimestamp":"0001-01-01T00:00:00Z"}],"Up":true,"MacAddr":"UlQArRXh","DefaultRouters":["192.168.123.1"],"MTU":1500,"WirelessCfg":{"WType":0,"CellularV2":{"AccessPoints":null,"Probe":{"Disable":false,"UserDefinedProbe":{"Method":0,"ProbeHost":"","ProbePort":0}},"LocationTracking":false},"Wifi":null,"Cellular":null},"WirelessStatus":{"WType":0,"Cellular":{"LogicalLabel":"","PhysAddrs":{"Interface":"","USB":"","PCI":"","Dev":""},"Module":{"Name":"","IMEI":"","Model":"","Manufacturer":"","Revision":"","ControlProtocol":"","OpMode":""},"SimCards":null,"ConfigError":"","ProbeError":"","CurrentProvider":{"PLMN":"","Description":"","CurrentServing":false,"Roaming":false,"Forbidden":false},"VisibleProviders":null,"CurrentRATs":null,"ConnectedAt":0,"IPSettings":{"Address":null,"Gateway":"","DNSServers":null,"MTU":0},"LocationTracking":false}},"Proxies":null,"Exceptions":"","Pacfile":"","NetworkProxyEnable":false,"NetworkProxyURL":"","WpadURL":"","pubsub-large-ProxyCertPEM":null,"L2Type":0,"VLAN":{"ParentPort":"","ID":0},"Bond":{"AggregatedPorts":null,"Mode":0,"LacpRate":0,"MIIMonitor":{"Enabled":false,"Interval":0,"UpDelay":0,"DownDelay":0},"ARPMonitor":{"Enabled":false,"Interval":0,"IPTargets":null}},"LastFailed":"2025-01-19T12:51:50.506055942Z","LastSucceeded":"0001-01-01T00:00:00Z","LastError":"link not up for interface eth1 (down)","LastWarning":""}]}}

src/application.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,12 @@ impl Application {
214214
.flatten()
215215
.collect::<Vec<IpAddr>>();
216216

217-
// same for NTP
217+
// same for NTP. NTP can now be either IP or FQDN
218218
let ntp_servers = new
219219
.ntp
220220
.split(',')
221-
.map(|s| s.parse::<IpAddr>().ok())
222-
.flatten()
223-
.collect::<Vec<IpAddr>>();
221+
.map(|s| s.to_string())
222+
.collect::<Vec<String>>();
224223

225224
// case 1,3
226225
new_dpc
@@ -233,7 +232,7 @@ impl Application {
233232
if ntp_servers.is_empty() {
234233
None
235234
} else {
236-
Some(ntp_servers[0])
235+
Some(ntp_servers)
237236
},
238237
if dns_servers.is_empty() {
239238
None

src/ipc/eve_types.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,11 @@ pub struct NetworkPortStatus {
244244
pub network_type: NetworkType,
245245
#[serde_as(as = "FromInto<GoIpNetwork>")]
246246
pub subnet: Option<IpNet>,
247-
#[serde_as(as = "NoneAsEmptyString")]
248-
pub ntp_server: Option<IpAddr>,
247+
pub configured_ntp_servers: Option<Vec<String>>,
249248
pub domain_name: String,
250249
#[serde(rename = "DNSServers")]
251250
pub dns_servers: Option<Vec<IpAddr>>,
252-
pub ntp_servers: Option<Vec<IpAddr>>,
251+
pub dhcp_ntp_servers: Option<Vec<IpAddr>>,
253252
pub addr_info_list: Option<Vec<AddrInfo>>,
254253
pub up: bool,
255254
#[serde(deserialize_with = "deserialize_mac", skip_serializing)]
@@ -875,7 +874,7 @@ impl NetworkPortConfig {
875874
self.dhcp_config.addr_subnet = None;
876875
self.dhcp_config.gateway = String::new();
877876
self.dhcp_config.domain_name = String::new();
878-
self.dhcp_config.ntp_server = None;
877+
self.dhcp_config.ntp_servers = None;
879878
self.dhcp_config.dns_servers = None;
880879
//TODO: what do we do with NetworkUUID?
881880
self
@@ -886,14 +885,14 @@ impl NetworkPortConfig {
886885
addr_subnet: IpNet,
887886
gateway: String,
888887
domain_name: String,
889-
ntp_server: Option<IpAddr>,
888+
ntp_server: Option<Vec<String>>,
890889
dns_servers: Option<Vec<IpAddr>>,
891890
) -> Self {
892891
self.dhcp_config.dhcp = DhcpType::Static;
893892
self.dhcp_config.addr_subnet = Some(addr_subnet);
894893
self.dhcp_config.gateway = gateway;
895894
self.dhcp_config.domain_name = domain_name;
896-
self.dhcp_config.ntp_server = ntp_server;
895+
self.dhcp_config.ntp_servers = ntp_server;
897896
self.dhcp_config.dns_servers = dns_servers;
898897
self
899898
}
@@ -904,7 +903,7 @@ impl NetworkPortConfig {
904903
self.dhcp_config.addr_subnet = None;
905904
self.dhcp_config.gateway = String::new();
906905
self.dhcp_config.domain_name = String::new();
907-
self.dhcp_config.ntp_server = None;
906+
self.dhcp_config.ntp_servers = None;
908907
self.dhcp_config.dns_servers = None;
909908
}
910909

@@ -913,14 +912,14 @@ impl NetworkPortConfig {
913912
addr_subnet: IpNet,
914913
gateway: String,
915914
domain_name: String,
916-
ntp_server: Option<IpAddr>,
915+
ntp_server: Option<Vec<String>>,
917916
dns_servers: Option<Vec<IpAddr>>,
918917
) {
919918
self.dhcp_config.dhcp = DhcpType::Static;
920919
self.dhcp_config.addr_subnet = Some(addr_subnet);
921920
self.dhcp_config.gateway = gateway;
922921
self.dhcp_config.domain_name = domain_name;
923-
self.dhcp_config.ntp_server = ntp_server;
922+
self.dhcp_config.ntp_servers = ntp_server;
924923
self.dhcp_config.dns_servers = dns_servers;
925924
}
926925
}
@@ -935,9 +934,8 @@ pub struct DhcpConfig {
935934
pub addr_subnet: Option<IpNet>,
936935
pub gateway: String,
937936
pub domain_name: String,
938-
#[serde_as(as = "NoneAsEmptyString")]
939-
#[serde(rename = "NTPServer")]
940-
pub ntp_server: Option<IpAddr>,
937+
#[serde(rename = "NTPServers")]
938+
pub ntp_servers: Option<Vec<String>>,
941939
#[serde(rename = "DNSServers")]
942940
pub dns_servers: Option<Vec<IpAddr>>,
943941
#[serde(rename = "Type")]

src/model/device/network.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub struct NetworkInterfaceStatus {
189189
pub ipv6: Option<Vec<Ipv6Addr>>,
190190
pub routes: Option<Vec<IpAddr>>,
191191
pub mac: Option<MacAddr>,
192-
pub ntp_servers: Option<Vec<IpAddr>>,
192+
pub ntp_servers: Option<Vec<String>>,
193193
pub up: bool,
194194
pub media: NetworkType,
195195
pub dns: Option<Vec<IpAddr>>,
@@ -302,10 +302,32 @@ impl From<&NetworkPortStatus> for NetworkInterfaceStatus {
302302
.as_ref()
303303
.and_then(|routers| routers.first().cloned());
304304

305-
let ntp_servers = if port.dhcp == DhcpType::Client {
306-
port.ntp_servers.clone()
305+
// collect NTP servers. Some may come from DHCP as IpAddr, others are FQDN from
306+
// network configuration. Collect both types in the same list as strings
307+
308+
let mut ntp_servers = vec![];
309+
// collect manually configured NTP servers
310+
if let Some(configured_ntp_servers) = &port.configured_ntp_servers {
311+
ntp_servers.extend(configured_ntp_servers.clone());
312+
}
313+
314+
// append NTP servers provided by DHCP
315+
if is_dhcp {
316+
let dhcp_ntp_servers = port.dhcp_ntp_servers.as_ref().map(|ntp_servers| {
317+
ntp_servers
318+
.iter()
319+
.map(|ntp_server| ntp_server.clone().to_string())
320+
.collect::<Vec<String>>()
321+
});
322+
if let Some(dhcp_ntp_servers) = dhcp_ntp_servers {
323+
ntp_servers.extend(dhcp_ntp_servers);
324+
}
325+
}
326+
327+
let ntp_servers = if ntp_servers.is_empty() {
328+
None
307329
} else {
308-
port.ntp_server.map(|ntp_server| vec![ntp_server])
330+
Some(ntp_servers)
309331
};
310332

311333
NetworkInterfaceStatus {

0 commit comments

Comments
 (0)