ipxe_nic_drv: optionally report MAC address

Issue #4133
This commit is contained in:
Christian Helmuth 2021-05-25 15:38:44 +02:00
parent 4abc530974
commit 6e85a73a28
3 changed files with 32 additions and 4 deletions

View File

@ -15,3 +15,10 @@ build directory, for example
After successful build the DDE iPXE based ethernet driver is located
at 'bin/nic_drv'.
The driver optionally reports the following information under the
label "devices" if requested in the config as depicted.
! <config> <report mac_address="true"/> </config>
! <devices> <nic mac_address="02:00:00:00:00:01"/> </devices>

View File

@ -1,7 +1,8 @@
base
os
nic_session
uplink_session
nic_driver
nic_session
os
platform_session
report_session
timer_session
uplink_session

View File

@ -19,6 +19,7 @@
#include <base/log.h>
#include <uplink_session/connection.h>
#include <base/attached_rom_dataspace.h>
#include <os/reporter.h>
/* NIC driver includes */
#include <drivers/nic/uplink_client_base.h>
@ -104,6 +105,8 @@ class Uplink_client : public Uplink_client_base
dde_ipxe_nic_unregister_callbacks();
instance = nullptr;
}
Net::Mac_address mac_address() const { return _drv_mac_addr; }
};
@ -116,7 +119,7 @@ struct Main
Heap _heap { _env.ram(), _env.rm() };
Attached_rom_dataspace _config_rom { _env, "config" };
Constructible<Uplink_client> _uplink { };
Constructible<Reporter> _reporter { };
Main(Env &env) : _env(env)
{
@ -129,6 +132,23 @@ struct Main
}
_uplink.construct(_env, _heap);
_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("mac_address", String<32>(_uplink->mac_address()));
});
});
});
}
};