nic_router: fix pure virtual call in Interface

The Interface constructor previously tried to attach to a domain.  This
might include sending a DHCP request to get the domain a valid IP config.
But in order to achieve this, the constructor used a pure virtual method
of Interface which crashes due to the unfinished vtable. To fix this bug,
the attach attempt was moved to a new Interface::init method.

Issue #2730
This commit is contained in:
Martin Stein 2018-03-22 18:49:47 +01:00 committed by Christian Helmuth
parent 1044c2fcab
commit b344f2bc39
4 changed files with 12 additions and 1 deletions

View File

@ -153,11 +153,14 @@ Session_component *Net::Root::_create_session(char const *args)
throw Insufficient_ram_quota();
}
Session_label const label(label_from_args(args));
return new (md_alloc())
Session_component &component = *new (md_alloc())
Session_component(*md_alloc(), _timer, ram_quota - session_size,
_buf_ram, tx_buf_size, rx_buf_size, _region_map,
_mac_alloc.alloc(), _ep, _router_mac, label,
_interfaces, _config());
component.init();
return &component;
}
catch (Mac_allocator::Alloc_failed) {
error("failed to allocate MAC address");

View File

@ -1131,6 +1131,11 @@ Interface::Interface(Genode::Entrypoint &ep,
_interfaces(interfaces)
{
_interfaces.insert(this);
}
void Interface::init()
{
try { _attach_to_domain(_policy.determine_domain_name(), true); }
catch (Domain_tree::No_match) { }
}

View File

@ -322,6 +322,8 @@ class Net::Interface : private Interface_list::Element
void link_state_sigh(Genode::Signal_context_capability sigh);
void init();
/***************
** Accessors **

View File

@ -81,6 +81,7 @@ Configuration &Net::Main::_init_config()
Net::Main::Main(Env &env) : _env(env)
{
_uplink.init();
_config_rom.sigh(_config_handler);
env.parent().announce(env.ep().manage(_root));
}