genode/repos/os/src/server/nic_router/main.cc
Martin Stein 49a3a0e0d0 nic_router: multiple uplinks
Introduce the uplink tag:

! <config>
!    <uplink label="wifi"  domain="uplink">
!    <uplink label="wired" domain="wired_bridge">
!    <uplink               domain="wired_bridge">
! <config/>

For each uplink tag, the NIC router requests a NIC session with the
corresponding label or an empty label if there is no label attribute.
These NIC sessions get attached to the domain that is set in their
uplink tag as soon as the domain appears. This means their lifetime is
not bound to the domain. Uplink NIC sessions can be safely moved from
one domain to another without being closed by reconfiguring the
corresponding domain attribute.

Attention: This may render previously valid NIC router configurations
useless. A domain named "uplink" doesn't automatically request a NIC
session anymore. To fix these configurations, just add

! <uplink domain="uplink"/>

or

! <uplink label="[LABEL]" domain="uplink"/>

as direct subtag of the <config> tag.

Issue #2840
2018-06-29 10:44:53 +02:00

93 lines
2.5 KiB
C++

/*
* \brief Server component for Network Address Translation on NIC sessions
* \author Martin Stein
* \date 2016-08-24
*/
/*
* Copyright (C) 2016-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
/* Genode */
#include <base/component.h>
#include <base/heap.h>
#include <base/attached_rom_dataspace.h>
#include <nic/xml_node.h>
#include <timer_session/connection.h>
/* local includes */
#include <component.h>
#include <uplink.h>
#include <configuration.h>
using namespace Net;
using namespace Genode;
namespace Net { class Main; }
class Net::Main
{
private:
Genode::Env &_env;
Interface_list _interfaces { };
Timer::Connection _timer { _env };
Genode::Heap _heap { &_env.ram(), &_env.rm() };
Genode::Attached_rom_dataspace _config_rom { _env, "config" };
Reference<Configuration> _config { *new (_heap) Configuration { _config_rom.xml(), _heap } };
Signal_handler<Main> _config_handler { _env.ep(), *this, &Main::_handle_config };
Root _root { _env.ep(), _timer, _heap, _config(), _env.ram(), _interfaces, _env.rm()};
void _handle_config();
template <typename FUNC>
void _for_each_interface(FUNC && functor)
{
_interfaces.for_each([&] (Interface &interface) {
functor(interface);
});
_config().domains().for_each([&] (Domain &domain) {
domain.interfaces().for_each([&] (Interface &interface) {
functor(interface);
});
});
}
public:
Main(Env &env);
};
Net::Main::Main(Env &env) : _env(env)
{
_config_rom.sigh(_config_handler);
_handle_config();
env.parent().announce(env.ep().manage(_root));
}
void Net::Main::_handle_config()
{
_config_rom.update();
Configuration &old_config = _config();
Configuration &new_config = *new (_heap)
Configuration(_env, _config_rom.xml(), _heap, _timer, old_config,
_interfaces);
_root.handle_config(new_config);
_for_each_interface([&] (Interface &intf) { intf.handle_config_1(new_config); });
_for_each_interface([&] (Interface &intf) { intf.handle_config_2(); });
_config = Reference<Configuration>(new_config);
_for_each_interface([&] (Interface &intf) { intf.handle_config_3(); });
destroy(_heap, &old_config);
}
void Component::construct(Env &env) { static Net::Main main(env); }