Skip to content

Commit 7bdc23b

Browse files
teodlydavidv1992
authored andcommitted
get own clock_id from interface that is actually used
1 parent 8600e98 commit 7bdc23b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

statime-linux/src/main.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use statime_linux::{
3030
tlvforwarder::TlvForwarder,
3131
};
3232
use timestamped_socket::{
33-
interface::interfaces,
33+
interface::{interfaces, InterfaceName},
3434
networkaddress::{EthernetAddress, NetworkAddress},
3535
socket::{InterfaceTimestampMode, Open, Socket},
3636
};
@@ -258,8 +258,13 @@ async fn actual_main() {
258258
.expect("could not determine config file path"),
259259
);
260260

261+
let allowed_interfaces = config
262+
.ports
263+
.iter()
264+
.map(|port| port.interface)
265+
.collect::<Vec<_>>();
261266
let clock_identity = config.identity.unwrap_or(ClockIdentity(
262-
get_clock_id().expect("could not get clock identity"),
267+
get_clock_id(&allowed_interfaces).expect("could not get clock identity"),
263268
));
264269

265270
log::info!("Clock identity: {}", hex::encode(clock_identity.0));
@@ -954,11 +959,17 @@ async fn handle_actions_ethernet(
954959
pending_timestamp
955960
}
956961

957-
fn get_clock_id() -> Option<[u8; 8]> {
962+
fn get_clock_id(allowed_names: &[InterfaceName]) -> Option<[u8; 8]> {
958963
let candidates = interfaces()
959964
.unwrap()
960965
.into_iter()
961-
.filter_map(|(_, data)| data.mac());
966+
.filter_map(|(name, data)| {
967+
if allowed_names.contains(&name) {
968+
data.mac()
969+
} else {
970+
None
971+
}
972+
});
962973

963974
for mac in candidates {
964975
// Ignore multicast and locally administered mac addresses

0 commit comments

Comments
 (0)