From 62f83b71987f054a25de4b8c8f637d6276486c09 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Tue, 25 May 2021 12:07:16 +0200 Subject: [PATCH] linux_nic_drv: optionally report MAC address Issue #4133 --- repos/libports/run/lwip_lx.run | 14 +++++++++++- repos/os/recipes/src/linux_nic_drv/used_apis | 7 +++--- repos/os/src/drivers/nic/spec/linux/README | 6 +++++ repos/os/src/drivers/nic/spec/linux/main.cc | 24 +++++++++++++++++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/repos/libports/run/lwip_lx.run b/repos/libports/run/lwip_lx.run index a0581f6b39..e0cdc92afa 100644 --- a/repos/libports/run/lwip_lx.run +++ b/repos/libports/run/lwip_lx.run @@ -32,6 +32,7 @@ build { test/lwip/http_srv lib/vfs/lwip server/nic_router + server/report_rom } create_boot_directory @@ -65,10 +66,21 @@ set config { + + + + + + + + + + + @@ -124,7 +136,7 @@ install_config $config set boot_modules { core init timer linux_nic_drv ld.lib.so libc.lib.so vfs.lib.so vfs_lwip.lib.so test-lwip_httpsrv - nic_router + nic_router report_rom } build_boot_image $boot_modules diff --git a/repos/os/recipes/src/linux_nic_drv/used_apis b/repos/os/recipes/src/linux_nic_drv/used_apis index 37fabb6132..39602f2d5c 100644 --- a/repos/os/recipes/src/linux_nic_drv/used_apis +++ b/repos/os/recipes/src/linux_nic_drv/used_apis @@ -1,6 +1,7 @@ base base-linux -os -nic_session -uplink_session nic_driver +nic_session +os +report_session +uplink_session diff --git a/repos/os/src/drivers/nic/spec/linux/README b/repos/os/src/drivers/nic/spec/linux/README index bf073b13c6..bd47cde0bf 100644 --- a/repos/os/src/drivers/nic/spec/linux/README +++ b/repos/os/src/drivers/nic/spec/linux/README @@ -18,3 +18,9 @@ changed via ! +The driver optionally reports the following information under the +label "devices" if requested in the config as depicted. + +! + +! diff --git a/repos/os/src/drivers/nic/spec/linux/main.cc b/repos/os/src/drivers/nic/spec/linux/main.cc index 8e197cb567..6fd9ac7153 100644 --- a/repos/os/src/drivers/nic/spec/linux/main.cc +++ b/repos/os/src/drivers/nic/spec/linux/main.cc @@ -21,6 +21,7 @@ #include #include #include +#include /* NIC driver includes */ #include @@ -204,7 +205,28 @@ struct Main Uplink_client _uplink { _env, _heap, _tap_name, _mac_address }; - Main(Env &env) : _env(env) { } + Constructible _reporter { }; + + Main(Env &env) : _env(env) + { + _config_rom.xml().with_sub_node("report", [&] (Xml_node const &xml) { + bool const report_mac_address = + xml.attribute_value("mac_address", false); + + if (!report_mac_address) + return; + + _reporter.construct(_env, "devices"); + _reporter->enabled(true); + + Reporter::Xml_generator report(*_reporter, [&] () { + report.node("nic", [&] () { + report.attribute("label", _tap_name); + report.attribute("mac_address", String<32>(_mac_address)); + }); + }); + }); + } };