linux_nic_drv: optionally report MAC address

Issue #4133
This commit is contained in:
Christian Helmuth 2021-05-25 12:07:16 +02:00
parent 464f0eaf8b
commit 62f83b7198
4 changed files with 46 additions and 5 deletions

View File

@ -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 {
<provides> <service name="Timer"/> </provides>
</start>
<start name="devices_report_rom">
<binary name="report_rom"/>
<resource name="RAM" quantum="1200K"/>
<provides> <service name="Report"/> <service name="ROM"/> </provides>
<config verbose="yes"/>
</start>
<start name="linux_nic_drv" ld="no">
<resource name="RAM" quantum="8M"/>
<config>
<report mac_address="true"/>
</config>
<route>
<service name="Uplink"> <child name="nic_router"/> </service>
<service name="Report"> <child name="devices_report_rom"/> </service>
<any-service> <parent/> </any-service>
</route>
</start>
@ -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

View File

@ -1,6 +1,7 @@
base
base-linux
os
nic_session
uplink_session
nic_driver
nic_session
os
report_session
uplink_session

View File

@ -18,3 +18,9 @@ changed via
! <config mac="12:23:34:45:56:67"/>
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 label="tap0" mac_address="02:00:00:00:00:01"/> </devices>

View File

@ -21,6 +21,7 @@
#include <base/thread.h>
#include <base/log.h>
#include <base/blockade.h>
#include <os/reporter.h>
/* NIC driver includes */
#include <drivers/nic/uplink_client_base.h>
@ -204,7 +205,28 @@ struct Main
Uplink_client _uplink { _env, _heap, _tap_name, _mac_address };
Main(Env &env) : _env(env) { }
Constructible<Reporter> _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));
});
});
});
}
};