mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 02:40:08 +00:00
nic_router: use the dictionary data structure
This commit gets rid of the router-local wrapper of Genode's AVL string tree and replaces it with Genode's new Dictionary structure. The Dictionary is now used for managing domains and NIC clients. Due to this change, the formerly necessary helper classes Domain_base and Nic_client_base could be removed as well. Ref #4610
This commit is contained in:
parent
3a616fed4d
commit
88cddc35dd
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* \brief AVL tree of strings with additional functions needed by NIC router
|
||||
* \author Martin Stein
|
||||
* \date 2016-08-19
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _AVL_STRING_TREE_H_
|
||||
#define _AVL_STRING_TREE_H_
|
||||
|
||||
/* local includes */
|
||||
#include <reference.h>
|
||||
|
||||
/* Genode includes */
|
||||
#include <util/avl_string.h>
|
||||
#include <base/allocator.h>
|
||||
|
||||
namespace Net { template <typename, typename> class Avl_string_tree; }
|
||||
|
||||
|
||||
template <typename OBJECT,
|
||||
typename NAME>
|
||||
class Net::Avl_string_tree : public Genode::Avl_tree<Genode::Avl_string_base>
|
||||
{
|
||||
private:
|
||||
|
||||
using Node = Genode::Avl_string_base;
|
||||
using Tree = Genode::Avl_tree<Genode::Avl_string_base>;
|
||||
|
||||
template <typename HANDLE_MATCH_FN,
|
||||
typename HANDLE_NO_MATCH_FN>
|
||||
|
||||
void _node_find_by_name(Node &node,
|
||||
char const *name_ptr,
|
||||
HANDLE_MATCH_FN && handle_match,
|
||||
HANDLE_NO_MATCH_FN && handle_no_match)
|
||||
{
|
||||
int const name_diff {
|
||||
Genode::strcmp(name_ptr, node.name()) };
|
||||
|
||||
if (name_diff != 0) {
|
||||
|
||||
Node *child_ptr { node.child(name_diff > 0) };
|
||||
|
||||
if (child_ptr != nullptr) {
|
||||
|
||||
_node_find_by_name(
|
||||
*child_ptr, name_ptr, handle_match, handle_no_match);
|
||||
|
||||
} else {
|
||||
|
||||
handle_no_match();
|
||||
}
|
||||
} else {
|
||||
|
||||
handle_match(*static_cast<OBJECT *>(&node));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename HANDLE_MATCH_FN,
|
||||
typename HANDLE_NO_MATCH_FN>
|
||||
|
||||
void _find_by_name(char const *name_ptr,
|
||||
HANDLE_MATCH_FN && handle_match,
|
||||
HANDLE_NO_MATCH_FN && handle_no_match)
|
||||
{
|
||||
if (first() != nullptr) {
|
||||
|
||||
_node_find_by_name(
|
||||
*first(), name_ptr, handle_match, handle_no_match);
|
||||
|
||||
} else {
|
||||
|
||||
handle_no_match();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template <typename HANDLE_MATCH_FN,
|
||||
typename HANDLE_NO_MATCH_FN>
|
||||
|
||||
void find_by_name(NAME const &name,
|
||||
HANDLE_MATCH_FN && handle_match,
|
||||
HANDLE_NO_MATCH_FN && handle_no_match)
|
||||
{
|
||||
_find_by_name(name.string(), handle_match, handle_no_match);
|
||||
}
|
||||
|
||||
template <typename FUNCTOR>
|
||||
void for_each(FUNCTOR && functor) const {
|
||||
Tree::for_each([&] (Node const &node) {
|
||||
|
||||
/*
|
||||
* FIXME This constness cast sneaked in with an older
|
||||
* implementation where it was done implicitely and
|
||||
* therefore not that obvious. Now the router relies on
|
||||
* it and we should either get rid of the dependency to
|
||||
* const Avl_tree::for_each or of the the need for
|
||||
* mutable objects in Avl_string_tree::for_each.
|
||||
*/
|
||||
functor(*const_cast<OBJECT *>(static_cast<OBJECT const *>(&node)));
|
||||
});
|
||||
}
|
||||
|
||||
void destroy_each(Genode::Deallocator &dealloc)
|
||||
{
|
||||
while (Node *node = first()) {
|
||||
Tree::remove(node);
|
||||
Genode::destroy(dealloc, static_cast<OBJECT *>(node));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename HANDLE_NAME_NOT_UNIQUE_FN>
|
||||
|
||||
void insert(OBJECT &obj,
|
||||
HANDLE_NAME_NOT_UNIQUE_FN && handle_name_not_unique)
|
||||
{
|
||||
_find_by_name(
|
||||
static_cast<Node *>(&obj)->name(),
|
||||
[&] /* handle_match */ (OBJECT &other_obj)
|
||||
{
|
||||
handle_name_not_unique(other_obj);
|
||||
},
|
||||
[&] /* handle_no_match */ () { Tree::insert(&obj); }
|
||||
);
|
||||
}
|
||||
|
||||
void remove(OBJECT &object) { Tree::remove(&object); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* _AVL_STRING_TREE_H_ */
|
@ -50,24 +50,12 @@ Configuration::Configuration(Xml_node const node,
|
||||
{ }
|
||||
|
||||
|
||||
void Configuration::_invalid_nic_client(Nic_client &nic_client,
|
||||
char const *reason)
|
||||
{
|
||||
if (_verbose) {
|
||||
log("[", nic_client.domain(), "] invalid NIC client: ", nic_client, " (", reason, ")"); }
|
||||
|
||||
_nic_clients.remove(nic_client);
|
||||
destroy(_alloc, &nic_client);
|
||||
}
|
||||
|
||||
|
||||
void Configuration::_invalid_domain(Domain &domain,
|
||||
char const *reason)
|
||||
{
|
||||
if (_verbose) {
|
||||
log("[", domain, "] invalid domain (", reason, ") "); }
|
||||
|
||||
_domains.remove(domain);
|
||||
destroy(_alloc, &domain);
|
||||
}
|
||||
|
||||
@ -133,13 +121,27 @@ Configuration::Configuration(Env &env,
|
||||
/* do parts of domain initialization that do not lookup other domains */
|
||||
node.for_each_sub_node("domain", [&] (Xml_node const node) {
|
||||
try {
|
||||
Domain &domain = *new (_alloc) Domain(*this, node, _alloc);
|
||||
_domains.insert(
|
||||
domain,
|
||||
[&] /* handle_name_not_unique */ (Domain &other_domain)
|
||||
Domain_name const name {
|
||||
node.attribute_value("name", Domain_name { }) };
|
||||
|
||||
_domains.with_element(
|
||||
name,
|
||||
[&] /* match_fn */ (Domain &other_domain)
|
||||
{
|
||||
_invalid_domain(domain, "name not unique");
|
||||
_invalid_domain(other_domain, "name not unique");
|
||||
if (_verbose) {
|
||||
|
||||
log("[", name,
|
||||
"] invalid domain (name not unique) ");
|
||||
|
||||
log("[", other_domain,
|
||||
"] invalid domain (name not unique) ");
|
||||
}
|
||||
destroy(_alloc, &other_domain);
|
||||
},
|
||||
[&] /* no_match_fn */ ()
|
||||
{
|
||||
new (_alloc) Domain {
|
||||
*this, node, name, _alloc, _domains };
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -165,7 +167,6 @@ Configuration::Configuration(Env &env,
|
||||
catch (Retry_without_domain exception) {
|
||||
|
||||
/* destroy domain that became invalid during initialization */
|
||||
_domains.remove(exception.domain);
|
||||
destroy(_alloc, &exception.domain);
|
||||
|
||||
/* deinitialize the remaining domains again */
|
||||
@ -203,24 +204,39 @@ Configuration::Configuration(Env &env,
|
||||
/* initialize NIC clients */
|
||||
_node.for_each_sub_node("nic-client", [&] (Xml_node const node) {
|
||||
try {
|
||||
Nic_client &nic_client = *new (_alloc)
|
||||
Nic_client { node, alloc, old_config._nic_clients, env, timer,
|
||||
interfaces, *this };
|
||||
Session_label const label {
|
||||
node.attribute_value("label", Session_label::String { }) };
|
||||
|
||||
_nic_clients.insert(
|
||||
nic_client,
|
||||
[&] /* handle_name_not_unique */ (Nic_client &other_nic_client)
|
||||
Domain_name const domain {
|
||||
node.attribute_value("domain", Domain_name { }) };
|
||||
|
||||
_nic_clients.with_element(
|
||||
label,
|
||||
[&] /* match */ (Nic_client &nic_client)
|
||||
{
|
||||
_invalid_nic_client(nic_client, "label not unique");
|
||||
_invalid_nic_client(other_nic_client, "label not unique");
|
||||
if (_verbose) {
|
||||
|
||||
log("[", domain, "] invalid NIC client: ",
|
||||
label, " (label not unique)");
|
||||
|
||||
log("[", nic_client.domain(), "] invalid NIC client: ",
|
||||
nic_client.label(), " (label not unique)");
|
||||
}
|
||||
destroy(_alloc, &nic_client);
|
||||
},
|
||||
[&] /* no_match */ ()
|
||||
{
|
||||
new (_alloc) Nic_client {
|
||||
label, domain, alloc, old_config._nic_clients,
|
||||
_nic_clients, env, timer, interfaces, *this };
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Nic_client::Invalid) { }
|
||||
});
|
||||
/*
|
||||
* Destroy old NIC clients to ensure that NIC client interfaces that were not
|
||||
* re-used are not re-attached to the new domains.
|
||||
* Destroy old NIC clients to ensure that NIC client interfaces that were
|
||||
* not re-used are not re-attached to the new domains.
|
||||
*/
|
||||
old_config._nic_clients.destroy_each(_alloc);
|
||||
}
|
||||
|
@ -51,16 +51,13 @@ class Net::Configuration
|
||||
Genode::Microseconds const _tcp_max_segm_lifetime;
|
||||
Pointer<Report> _report { };
|
||||
Pointer<Genode::Reporter> _reporter { };
|
||||
Domain_tree _domains { };
|
||||
Nic_client_tree _nic_clients { };
|
||||
Domain_dict _domains { };
|
||||
Nic_client_dict _nic_clients { };
|
||||
Genode::Xml_node const _node;
|
||||
|
||||
Icmp_packet::Code
|
||||
_init_icmp_type_3_code_on_fragm_ipv4(Genode::Xml_node const &node) const;
|
||||
|
||||
void _invalid_nic_client(Nic_client &nic_client,
|
||||
char const *reason);
|
||||
|
||||
void _invalid_domain(Domain &domain,
|
||||
char const *reason);
|
||||
|
||||
@ -100,7 +97,7 @@ class Net::Configuration
|
||||
Genode::Microseconds udp_idle_timeout() const { return _udp_idle_timeout; }
|
||||
Genode::Microseconds tcp_idle_timeout() const { return _tcp_idle_timeout; }
|
||||
Genode::Microseconds tcp_max_segm_lifetime() const { return _tcp_max_segm_lifetime; }
|
||||
Domain_tree &domains() { return _domains; }
|
||||
Domain_dict &domains() { return _domains; }
|
||||
Report &report() { return _report(); }
|
||||
Genode::Xml_node node() const { return _node; }
|
||||
};
|
||||
|
@ -95,7 +95,7 @@ Dhcp_server::Dhcp_server(Xml_node const node,
|
||||
Domain &domain,
|
||||
Allocator &alloc,
|
||||
Ipv4_address_prefix const &interface,
|
||||
Domain_tree &domains)
|
||||
Domain_dict &domains)
|
||||
:
|
||||
Dhcp_server_base(node, domain, alloc),
|
||||
_dns_config_from(_init_dns_config_from(node, domains)),
|
||||
@ -206,7 +206,7 @@ void Dhcp_server::free_ip(Domain const &domain,
|
||||
|
||||
|
||||
Pointer<Domain> Dhcp_server::_init_dns_config_from(Genode::Xml_node const node,
|
||||
Domain_tree &domains)
|
||||
Domain_dict &domains)
|
||||
{
|
||||
if (!_dns_servers.empty() ||
|
||||
_dns_domain_name.valid()) {
|
||||
|
@ -40,7 +40,7 @@ namespace Net {
|
||||
/* forward declarations */
|
||||
class Interface;
|
||||
class Domain;
|
||||
class Domain_tree;
|
||||
class Domain_dict;
|
||||
}
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ class Net::Dhcp_server : private Genode::Noncopyable,
|
||||
Genode::Microseconds _init_ip_lease_time(Genode::Xml_node const node);
|
||||
|
||||
Pointer<Domain> _init_dns_config_from(Genode::Xml_node const node,
|
||||
Domain_tree &domains);
|
||||
Domain_dict &domains);
|
||||
|
||||
Ipv4_config const &_resolve_dns_config_from() const;
|
||||
|
||||
@ -96,7 +96,7 @@ class Net::Dhcp_server : private Genode::Noncopyable,
|
||||
Domain &domain,
|
||||
Genode::Allocator &alloc,
|
||||
Ipv4_address_prefix const &interface,
|
||||
Domain_tree &domains);
|
||||
Domain_dict &domains);
|
||||
|
||||
Ipv4_address alloc_ip();
|
||||
|
||||
|
55
repos/os/src/server/nic_router/dictionary.h
Normal file
55
repos/os/src/server/nic_router/dictionary.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* \brief Local convenience wrapper for the Genode dictionary
|
||||
* \author Martin Stein
|
||||
* \date 2022-09-16
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 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.
|
||||
*/
|
||||
|
||||
#ifndef _DICTIONARY_H_
|
||||
#define _DICTIONARY_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/allocator.h>
|
||||
#include <util/dictionary.h>
|
||||
|
||||
namespace Net { template <typename, typename> class Dictionary; }
|
||||
|
||||
|
||||
template <typename OBJECT_T,
|
||||
typename NAME_T>
|
||||
|
||||
class Net::Dictionary : public Genode::Dictionary<OBJECT_T, NAME_T>
|
||||
{
|
||||
private:
|
||||
|
||||
using Dict = Genode::Dictionary<OBJECT_T, NAME_T>;
|
||||
|
||||
public:
|
||||
|
||||
template <typename FUNCTION_T>
|
||||
void for_each(FUNCTION_T const &function) const
|
||||
{
|
||||
Dict::for_each(
|
||||
[&] (OBJECT_T const &obj)
|
||||
{
|
||||
function(*const_cast<OBJECT_T *>(&obj));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void destroy_each(Genode::Deallocator &dealloc)
|
||||
{
|
||||
auto destroy_element { [&] (OBJECT_T &obj) {
|
||||
destroy(dealloc, &obj);
|
||||
} };
|
||||
while (this->with_any_element(destroy_element)) { }
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _DICTIONARY_H_ */
|
@ -26,16 +26,6 @@ using namespace Net;
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
/*****************
|
||||
** Domain_base **
|
||||
*****************/
|
||||
|
||||
Domain_base::Domain_base(Xml_node const node)
|
||||
:
|
||||
_name(node.attribute_value("name", Domain_name()))
|
||||
{ }
|
||||
|
||||
|
||||
/************
|
||||
** Domain **
|
||||
************/
|
||||
@ -148,7 +138,7 @@ void Domain::try_reuse_ip_config(Domain const &domain)
|
||||
|
||||
|
||||
void Domain::_read_forward_rules(Cstring const &protocol,
|
||||
Domain_tree &domains,
|
||||
Domain_dict &domains,
|
||||
Xml_node const node,
|
||||
char const *type,
|
||||
Forward_rule_tree &rules)
|
||||
@ -174,7 +164,7 @@ void Domain::_invalid(char const *reason) const
|
||||
|
||||
|
||||
void Domain::_read_transport_rules(Cstring const &protocol,
|
||||
Domain_tree &domains,
|
||||
Domain_dict &domains,
|
||||
Xml_node const node,
|
||||
char const *type,
|
||||
Transport_rule_list &rules)
|
||||
@ -193,17 +183,20 @@ void Domain::_read_transport_rules(Cstring const &protocol,
|
||||
|
||||
void Domain::print(Output &output) const
|
||||
{
|
||||
if (_name == Domain_name()) {
|
||||
if (name() == Domain_name()) {
|
||||
Genode::print(output, "?");
|
||||
} else {
|
||||
Genode::print(output, _name); }
|
||||
Genode::print(output, name()); }
|
||||
}
|
||||
|
||||
|
||||
Domain::Domain(Configuration &config, Xml_node const node, Allocator &alloc)
|
||||
Domain::Domain(Configuration &config,
|
||||
Xml_node const &node,
|
||||
Domain_name const &name,
|
||||
Allocator &alloc,
|
||||
Domain_dict &domains)
|
||||
:
|
||||
Domain_base { node },
|
||||
Avl_string_base { Domain_base::_name.string() },
|
||||
Domain_dict::Element { domains, name },
|
||||
_config { config },
|
||||
_node { node },
|
||||
_alloc { alloc },
|
||||
@ -222,7 +215,7 @@ Domain::Domain(Configuration &config, Xml_node const node, Allocator &alloc)
|
||||
{
|
||||
_log_ip_config();
|
||||
|
||||
if (_name == Domain_name()) {
|
||||
if (Domain::name() == Domain_name()) {
|
||||
_invalid("missing name attribute"); }
|
||||
|
||||
if (_config.verbose_domain_state()) {
|
||||
@ -257,7 +250,7 @@ Dhcp_server &Domain::dhcp_server()
|
||||
}
|
||||
|
||||
|
||||
void Domain::init(Domain_tree &domains)
|
||||
void Domain::init(Domain_dict &domains)
|
||||
{
|
||||
/* read DHCP server configuration */
|
||||
try {
|
||||
@ -404,7 +397,7 @@ void Domain::report(Xml_generator &xml)
|
||||
{
|
||||
xml.node("domain", [&] () {
|
||||
bool empty = true;
|
||||
xml.attribute("name", _name);
|
||||
xml.attribute("name", name());
|
||||
if (_config.report().bytes()) {
|
||||
xml.attribute("rx_bytes", _tx_bytes);
|
||||
xml.attribute("tx_bytes", _rx_bytes);
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <ipv4_config.h>
|
||||
#include <dhcp_server.h>
|
||||
#include <interface.h>
|
||||
#include <avl_string_tree.h>
|
||||
#include <dictionary.h>
|
||||
|
||||
/* Genode includes */
|
||||
#include <util/reconstructible.h>
|
||||
@ -40,10 +40,9 @@ namespace Net {
|
||||
|
||||
class Interface;
|
||||
class Configuration;
|
||||
class Domain_base;
|
||||
class Domain;
|
||||
using Domain_name = Genode::String<160>;
|
||||
class Domain_tree;
|
||||
class Domain_dict;
|
||||
class Domain_link_stats;
|
||||
class Domain_object_stats;
|
||||
}
|
||||
@ -71,18 +70,18 @@ struct Net::Domain_link_stats : Domain_object_stats
|
||||
};
|
||||
|
||||
|
||||
class Net::Domain_tree : public Avl_string_tree<Domain, Domain_name>
|
||||
class Net::Domain_dict : public Dictionary<Domain, Domain_name>
|
||||
{
|
||||
public:
|
||||
|
||||
template <typename NO_MATCH_EXCEPTION>
|
||||
Domain &deprecated_find_by_name(Domain_name const &name)
|
||||
Domain &deprecated_find_by_name(Domain_name const &domain_name)
|
||||
{
|
||||
Domain *dom_ptr { nullptr };
|
||||
find_by_name(
|
||||
name,
|
||||
[&] /* handle_match */ (Domain &dom) { dom_ptr = &dom; },
|
||||
[&] /* handle_no_match */ () { throw NO_MATCH_EXCEPTION { }; }
|
||||
with_element(
|
||||
domain_name,
|
||||
[&] /* match_fn */ (Domain &dom) { dom_ptr = &dom; },
|
||||
[&] /* no_match_fn */ () { throw NO_MATCH_EXCEPTION { }; }
|
||||
);
|
||||
return *dom_ptr;
|
||||
}
|
||||
@ -90,27 +89,16 @@ class Net::Domain_tree : public Avl_string_tree<Domain, Domain_name>
|
||||
template <typename NO_MATCH_EXCEPTION>
|
||||
Domain &deprecated_find_by_domain_attr(Genode::Xml_node const &node)
|
||||
{
|
||||
Domain_name const name {
|
||||
Domain_name const domain_name {
|
||||
node.attribute_value("domain", Domain_name { }) };
|
||||
|
||||
return deprecated_find_by_name<NO_MATCH_EXCEPTION>(name);
|
||||
return deprecated_find_by_name<NO_MATCH_EXCEPTION>(domain_name);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Net::Domain_base
|
||||
{
|
||||
protected:
|
||||
|
||||
Domain_name const _name;
|
||||
|
||||
Domain_base(Genode::Xml_node const node);
|
||||
};
|
||||
|
||||
|
||||
class Net::Domain : public Domain_base,
|
||||
public List<Domain>::Element,
|
||||
public Genode::Avl_string_base
|
||||
class Net::Domain : public List<Domain>::Element,
|
||||
public Domain_dict::Element
|
||||
{
|
||||
private:
|
||||
|
||||
@ -154,13 +142,13 @@ class Net::Domain : public Domain_base,
|
||||
unsigned long _dropped_fragm_ipv4 { 0 };
|
||||
|
||||
void _read_forward_rules(Genode::Cstring const &protocol,
|
||||
Domain_tree &domains,
|
||||
Domain_dict &domains,
|
||||
Genode::Xml_node const node,
|
||||
char const *type,
|
||||
Forward_rule_tree &rules);
|
||||
|
||||
void _read_transport_rules(Genode::Cstring const &protocol,
|
||||
Domain_tree &domains,
|
||||
Domain_dict &domains,
|
||||
Genode::Xml_node const node,
|
||||
char const *type,
|
||||
Transport_rule_list &rules);
|
||||
@ -190,12 +178,14 @@ class Net::Domain : public Domain_base,
|
||||
struct No_next_hop : Genode::Exception { };
|
||||
|
||||
Domain(Configuration &config,
|
||||
Genode::Xml_node const node,
|
||||
Genode::Allocator &alloc);
|
||||
Genode::Xml_node const &node,
|
||||
Domain_name const &name,
|
||||
Genode::Allocator &alloc,
|
||||
Domain_dict &domain_dict);
|
||||
|
||||
~Domain();
|
||||
|
||||
void init(Domain_tree &domains);
|
||||
void init(Domain_dict &domains);
|
||||
|
||||
void deinit();
|
||||
|
||||
@ -247,7 +237,7 @@ class Net::Domain : public Domain_base,
|
||||
Genode::Session_label const &label() const { return _label; }
|
||||
Ipv4_config const &ip_config() const { return *_ip_config; }
|
||||
List<Domain> &ip_config_dependents() { return _ip_config_dependents; }
|
||||
Domain_name const &name() const { return _name; }
|
||||
Domain_name const &name() const { return Domain_dict::Element::name; }
|
||||
Ip_rule_list &ip_rules() { return _ip_rules; }
|
||||
Forward_rule_tree &tcp_forward_rules() { return _tcp_forward_rules; }
|
||||
Forward_rule_tree &udp_forward_rules() { return _udp_forward_rules; }
|
||||
|
@ -33,7 +33,7 @@ void Forward_rule::print(Output &output) const
|
||||
}
|
||||
|
||||
|
||||
Forward_rule::Forward_rule(Domain_tree &domains, Xml_node const node)
|
||||
Forward_rule::Forward_rule(Domain_dict &domains, Xml_node const node)
|
||||
:
|
||||
_port { node.attribute_value("port", Port(0)) },
|
||||
_to_ip { node.attribute_value("to", Ipv4_address()) },
|
||||
|
@ -27,7 +27,7 @@ namespace Genode { class Xml_node; }
|
||||
namespace Net {
|
||||
|
||||
class Domain;
|
||||
class Domain_tree;
|
||||
class Domain_dict;
|
||||
|
||||
class Forward_rule;
|
||||
class Forward_rule_tree;
|
||||
@ -49,7 +49,7 @@ class Net::Forward_rule : public Genode::Avl_node<Forward_rule>
|
||||
|
||||
struct Invalid : Genode::Exception { };
|
||||
|
||||
Forward_rule(Domain_tree &domains, Genode::Xml_node const node);
|
||||
Forward_rule(Domain_dict &domains, Genode::Xml_node const node);
|
||||
|
||||
template <typename HANDLE_MATCH_FN,
|
||||
typename HANDLE_NO_MATCH_FN>
|
||||
|
@ -386,9 +386,9 @@ void Interface::_update_domain_object(Domain &new_domain) {
|
||||
|
||||
void Interface::attach_to_domain()
|
||||
{
|
||||
_config().domains().find_by_name(
|
||||
_config().domains().with_element(
|
||||
_policy.determine_domain_name(),
|
||||
[&] /* handle_match */ (Domain &domain)
|
||||
[&] /* match_fn */ (Domain &domain)
|
||||
{
|
||||
_attach_to_domain_raw(domain);
|
||||
|
||||
@ -398,7 +398,7 @@ void Interface::attach_to_domain()
|
||||
}
|
||||
attach_to_domain_finish();
|
||||
},
|
||||
[&] /* handle_no_match */ () { }
|
||||
[&] /* no_match_fn */ () { }
|
||||
);
|
||||
}
|
||||
|
||||
@ -2158,9 +2158,9 @@ void Interface::_update_own_arp_waiters(Domain &domain)
|
||||
{
|
||||
Arp_waiter &arp_waiter { *le.object() };
|
||||
bool dismiss_arp_waiter { true };
|
||||
_config().domains().find_by_name(
|
||||
_config().domains().with_element(
|
||||
arp_waiter.dst().name(),
|
||||
[&] /* handle_match */ (Domain &dst)
|
||||
[&] /* match_fn */ (Domain &dst)
|
||||
{
|
||||
/* dismiss ARP waiter if IP config of target domain changed */
|
||||
if (dst.ip_config() != arp_waiter.dst().ip_config()) {
|
||||
@ -2173,7 +2173,7 @@ void Interface::_update_own_arp_waiters(Domain &domain)
|
||||
}
|
||||
dismiss_arp_waiter = false;
|
||||
},
|
||||
[&] /* handle_no_match */ ()
|
||||
[&] /* no_match_fn */ ()
|
||||
{
|
||||
/* dismiss ARP waiter as the target domain disappeared */
|
||||
}
|
||||
@ -2207,13 +2207,13 @@ void Interface::handle_config_1(Configuration &config)
|
||||
return; }
|
||||
|
||||
/* interface stays with its domain, so, try to reuse IP config */
|
||||
config.domains().find_by_name(
|
||||
config.domains().with_element(
|
||||
new_domain_name,
|
||||
[&] /* handle_match */ (Domain &new_domain)
|
||||
[&] /* match_fn */ (Domain &new_domain)
|
||||
{
|
||||
new_domain.try_reuse_ip_config(old_domain);
|
||||
},
|
||||
[&] /* handle_no_match */ () { }
|
||||
[&] /* no_match_fn */ () { }
|
||||
);
|
||||
}
|
||||
catch (Pointer<Domain>::Invalid) { }
|
||||
@ -2246,9 +2246,9 @@ void Interface::handle_config_2()
|
||||
Domain_name const &new_domain_name = _policy.determine_domain_name();
|
||||
try {
|
||||
Domain &old_domain = domain();
|
||||
_config().domains().find_by_name(
|
||||
_config().domains().with_element(
|
||||
new_domain_name,
|
||||
[&] /* handle_match */ (Domain &new_domain)
|
||||
[&] /* match_fn */ (Domain &new_domain)
|
||||
{
|
||||
/* if the domains differ, detach completely from the domain */
|
||||
if (old_domain.name() != new_domain_name) {
|
||||
@ -2282,7 +2282,7 @@ void Interface::handle_config_2()
|
||||
/* remember that the interface stays attached to the same domain */
|
||||
_update_domain.construct(old_domain, new_domain);
|
||||
},
|
||||
[&] /* handle_no_match */ ()
|
||||
[&] /* no_match_fn */ ()
|
||||
{
|
||||
/* the interface no longer has a domain */
|
||||
_detach_from_domain();
|
||||
@ -2297,9 +2297,9 @@ void Interface::handle_config_2()
|
||||
catch (Pointer<Domain>::Invalid) {
|
||||
|
||||
/* the interface had no domain but now it may get one */
|
||||
_config().domains().find_by_name(
|
||||
_config().domains().with_element(
|
||||
new_domain_name,
|
||||
[&] /* handle_match */ (Domain &new_domain)
|
||||
[&] /* match_fn */ (Domain &new_domain)
|
||||
{
|
||||
_attach_to_domain_raw(new_domain);
|
||||
|
||||
@ -2308,7 +2308,7 @@ void Interface::handle_config_2()
|
||||
_dhcp_client.construct(_timer, *this);
|
||||
}
|
||||
},
|
||||
[&] /* handle_no_match */ () { }
|
||||
[&] /* no_match_fn */ () { }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ using namespace Net;
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
Ip_rule::Ip_rule(Domain_tree &domains, Xml_node const node)
|
||||
Ip_rule::Ip_rule(Domain_dict &domains, Xml_node const node)
|
||||
:
|
||||
Direct_rule { node },
|
||||
_domain { domains.deprecated_find_by_domain_attr<Invalid>(node) }
|
||||
|
@ -20,7 +20,7 @@
|
||||
namespace Net {
|
||||
|
||||
class Domain;
|
||||
class Domain_tree;
|
||||
class Domain_dict;
|
||||
|
||||
class Ip_rule;
|
||||
struct Ip_rule_list : Direct_rule_list<Ip_rule> { };
|
||||
@ -35,7 +35,7 @@ class Net::Ip_rule : public Direct_rule<Ip_rule>
|
||||
|
||||
public:
|
||||
|
||||
Ip_rule(Domain_tree &domains, Genode::Xml_node const node);
|
||||
Ip_rule(Domain_dict &domains, Genode::Xml_node const node);
|
||||
|
||||
|
||||
/***************
|
||||
|
@ -32,7 +32,7 @@ bool Nat_rule::higher(Nat_rule *rule)
|
||||
}
|
||||
|
||||
|
||||
Nat_rule::Nat_rule(Domain_tree &domains,
|
||||
Nat_rule::Nat_rule(Domain_dict &domains,
|
||||
Port_allocator &tcp_port_alloc,
|
||||
Port_allocator &udp_port_alloc,
|
||||
Port_allocator &icmp_port_alloc,
|
||||
|
@ -25,7 +25,7 @@
|
||||
namespace Net {
|
||||
|
||||
class Domain;
|
||||
class Domain_tree;
|
||||
class Domain_dict;
|
||||
|
||||
class Port_allocator;
|
||||
class Nat_rule_base;
|
||||
@ -47,7 +47,7 @@ class Net::Nat_rule : public Genode::Avl_node<Nat_rule>
|
||||
|
||||
struct Invalid : Genode::Exception { };
|
||||
|
||||
Nat_rule(Domain_tree &domains,
|
||||
Nat_rule(Domain_dict &domains,
|
||||
Port_allocator &tcp_port_alloc,
|
||||
Port_allocator &udp_port_alloc,
|
||||
Port_allocator &icmp_port_alloc,
|
||||
|
@ -22,17 +22,6 @@ using namespace Net;
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
/*********************
|
||||
** Nic_client_base **
|
||||
*********************/
|
||||
|
||||
Net::Nic_client_base::Nic_client_base(Xml_node const &node)
|
||||
:
|
||||
_label { node.attribute_value("label", Session_label::String()) },
|
||||
_domain { node.attribute_value("domain", Domain_name()) }
|
||||
{ }
|
||||
|
||||
|
||||
/****************
|
||||
** Nic_client **
|
||||
****************/
|
||||
@ -40,26 +29,29 @@ Net::Nic_client_base::Nic_client_base(Xml_node const &node)
|
||||
void Nic_client::_invalid(char const *reason) const
|
||||
{
|
||||
if (_config.verbose()) {
|
||||
log("[", domain(), "] invalid NIC client: ", *this, " (", reason, ")"); }
|
||||
|
||||
log("[", domain(), "] invalid NIC client: ", label(),
|
||||
" (", reason, ")");
|
||||
}
|
||||
throw Invalid();
|
||||
}
|
||||
|
||||
|
||||
Net::Nic_client::Nic_client(Xml_node const &node,
|
||||
Allocator &alloc,
|
||||
Nic_client_tree &old_nic_clients,
|
||||
Env &env,
|
||||
Cached_timer &timer,
|
||||
Interface_list &interfaces,
|
||||
Configuration &config)
|
||||
Net::Nic_client::Nic_client(Session_label const &label_arg,
|
||||
Domain_name const &domain_arg,
|
||||
Allocator &alloc,
|
||||
Nic_client_dict &old_nic_clients,
|
||||
Nic_client_dict &new_nic_clients,
|
||||
Env &env,
|
||||
Cached_timer &timer,
|
||||
Interface_list &interfaces,
|
||||
Configuration &config)
|
||||
:
|
||||
Nic_client_base { node },
|
||||
Avl_string_base { label().string() },
|
||||
_alloc { alloc },
|
||||
_config { config }
|
||||
Nic_client_dict::Element { new_nic_clients, label_arg },
|
||||
_alloc { alloc },
|
||||
_config { config },
|
||||
_domain { domain_arg }
|
||||
{
|
||||
old_nic_clients.find_by_name(
|
||||
old_nic_clients.with_element(
|
||||
label(),
|
||||
[&] /* handle_match */ (Nic_client &old_nic_client)
|
||||
{
|
||||
@ -73,7 +65,7 @@ Net::Nic_client::Nic_client(Xml_node const &node,
|
||||
{
|
||||
/* create a new interface */
|
||||
if (config.verbose()) {
|
||||
log("[", domain(), "] create NIC client: ", *this); }
|
||||
log("[", domain(), "] create NIC client: ", label()); }
|
||||
|
||||
try {
|
||||
_interface = *new (_alloc)
|
||||
@ -95,7 +87,7 @@ Net::Nic_client::~Nic_client()
|
||||
try {
|
||||
Nic_client_interface &interface = _interface();
|
||||
if (_config.verbose()) {
|
||||
log("[", domain(), "] destroy NIC client: ", *this); }
|
||||
log("[", domain(), "] destroy NIC client: ", label()); }
|
||||
|
||||
destroy(_alloc, &interface);
|
||||
}
|
||||
@ -103,15 +95,6 @@ Net::Nic_client::~Nic_client()
|
||||
}
|
||||
|
||||
|
||||
void Net::Nic_client::print(Output &output) const
|
||||
{
|
||||
if (label() == Session_label()) {
|
||||
Genode::print(output, "?"); }
|
||||
else {
|
||||
Genode::print(output, label()); }
|
||||
}
|
||||
|
||||
|
||||
/*******************************
|
||||
** Nic_client_interface_base **
|
||||
*******************************/
|
||||
|
@ -19,60 +19,31 @@
|
||||
#include <nic/packet_allocator.h>
|
||||
|
||||
/* local includes */
|
||||
#include <avl_string_tree.h>
|
||||
#include <dictionary.h>
|
||||
#include <interface.h>
|
||||
#include <ipv4_address_prefix.h>
|
||||
|
||||
namespace Net {
|
||||
|
||||
using Domain_name = Genode::String<160>;
|
||||
class Nic_client_base;
|
||||
class Nic_client;
|
||||
class Nic_client_tree;
|
||||
using Nic_client_dict = Dictionary<Nic_client, Genode::Session_label>;
|
||||
class Nic_client_interface_base;
|
||||
class Nic_client_interface;
|
||||
}
|
||||
|
||||
|
||||
class Net::Nic_client_tree
|
||||
:
|
||||
public Avl_string_tree<Nic_client, Genode::Session_label>
|
||||
{ };
|
||||
|
||||
|
||||
class Net::Nic_client_base
|
||||
class Net::Nic_client : private Nic_client_dict::Element
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::Session_label const _label;
|
||||
Domain_name const _domain;
|
||||
|
||||
public:
|
||||
|
||||
Nic_client_base(Genode::Xml_node const &node);
|
||||
|
||||
virtual ~Nic_client_base() { }
|
||||
|
||||
|
||||
/**************
|
||||
** Acessors **
|
||||
**************/
|
||||
|
||||
Genode::Session_label const &label() const { return _label; }
|
||||
Domain_name const &domain() const { return _domain; }
|
||||
};
|
||||
|
||||
|
||||
class Net::Nic_client : public Nic_client_base,
|
||||
private Genode::Avl_string_base
|
||||
{
|
||||
friend class Avl_string_tree<Nic_client, Genode::Session_label>;
|
||||
friend class Genode::List<Nic_client>;
|
||||
friend class Genode::Avl_tree<Nic_client>;
|
||||
friend class Genode::Avl_node<Nic_client>;
|
||||
friend class Genode::Dictionary<Nic_client, Genode::Session_label>;
|
||||
|
||||
private:
|
||||
|
||||
Genode::Allocator &_alloc;
|
||||
Configuration const &_config;
|
||||
Domain_name const _domain;
|
||||
Pointer<Nic_client_interface> _interface { };
|
||||
|
||||
void _invalid(char const *reason) const;
|
||||
@ -81,22 +52,25 @@ class Net::Nic_client : public Nic_client_base,
|
||||
|
||||
struct Invalid : Genode::Exception { };
|
||||
|
||||
Nic_client(Genode::Xml_node const &node,
|
||||
Genode::Allocator &alloc,
|
||||
Nic_client_tree &old_nic_clients,
|
||||
Genode::Env &env,
|
||||
Cached_timer &timer,
|
||||
Interface_list &interfaces,
|
||||
Configuration &config);
|
||||
Nic_client(Genode::Session_label const &label_arg,
|
||||
Domain_name const &domain_arg,
|
||||
Genode::Allocator &alloc,
|
||||
Nic_client_dict &old_nic_clients,
|
||||
Nic_client_dict &new_nic_clients,
|
||||
Genode::Env &env,
|
||||
Cached_timer &timer,
|
||||
Interface_list &interfaces,
|
||||
Configuration &config);
|
||||
|
||||
~Nic_client();
|
||||
|
||||
|
||||
/*********
|
||||
** log **
|
||||
*********/
|
||||
/**************
|
||||
** Acessors **
|
||||
**************/
|
||||
|
||||
void print(Genode::Output &output) const;
|
||||
Domain_name const &domain() const { return _domain; }
|
||||
Genode::Session_label const &label() const { return Nic_client_dict::Element::name; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ void Permit_any_rule::print(Output &output) const
|
||||
}
|
||||
|
||||
|
||||
Permit_any_rule::Permit_any_rule(Domain_tree &domains, Xml_node const node)
|
||||
Permit_any_rule::Permit_any_rule(Domain_dict &domains, Xml_node const node)
|
||||
:
|
||||
Permit_rule { domains.deprecated_find_by_domain_attr<Invalid>(node) }
|
||||
{ }
|
||||
@ -55,7 +55,7 @@ void Permit_single_rule::print(Output &output) const
|
||||
}
|
||||
|
||||
|
||||
Permit_single_rule::Permit_single_rule(Domain_tree &domains,
|
||||
Permit_single_rule::Permit_single_rule(Domain_dict &domains,
|
||||
Xml_node const node)
|
||||
:
|
||||
Permit_rule { domains.deprecated_find_by_domain_attr<Invalid>(node) },
|
||||
|
@ -31,7 +31,7 @@ namespace Net {
|
||||
|
||||
class Interface;
|
||||
class Domain;
|
||||
class Domain_tree;
|
||||
class Domain_dict;
|
||||
|
||||
class Permit_rule;
|
||||
class Permit_any_rule;
|
||||
@ -74,7 +74,7 @@ struct Net::Permit_any_rule : Permit_rule
|
||||
|
||||
struct Invalid : Genode::Exception { };
|
||||
|
||||
Permit_any_rule(Domain_tree &domains, Genode::Xml_node const node);
|
||||
Permit_any_rule(Domain_dict &domains, Genode::Xml_node const node);
|
||||
|
||||
|
||||
/*********
|
||||
@ -101,7 +101,7 @@ class Net::Permit_single_rule : public Permit_rule,
|
||||
|
||||
struct Invalid : Genode::Exception { };
|
||||
|
||||
Permit_single_rule(Domain_tree &domains,
|
||||
Permit_single_rule(Domain_dict &domains,
|
||||
Genode::Xml_node const node);
|
||||
|
||||
template <typename HANDLE_MATCH_FN,
|
||||
|
@ -23,7 +23,7 @@ using namespace Genode;
|
||||
Net::Report::Report(bool const &verbose,
|
||||
Xml_node const node,
|
||||
Cached_timer &timer,
|
||||
Domain_tree &domains,
|
||||
Domain_dict &domains,
|
||||
Quota const &shared_quota,
|
||||
Pd_session &pd,
|
||||
Reporter &reporter,
|
||||
|
@ -28,7 +28,7 @@ namespace Genode {
|
||||
|
||||
namespace Net {
|
||||
|
||||
class Domain_tree;
|
||||
class Domain_dict;
|
||||
class Report;
|
||||
class Quota;
|
||||
}
|
||||
@ -57,7 +57,7 @@ class Net::Report
|
||||
Quota const &_shared_quota;
|
||||
Genode::Pd_session &_pd;
|
||||
Genode::Reporter &_reporter;
|
||||
Domain_tree &_domains;
|
||||
Domain_dict &_domains;
|
||||
Timer::Periodic_timeout<Report> _timeout;
|
||||
Genode::Signal_transmitter _signal_transmitter;
|
||||
|
||||
@ -70,7 +70,7 @@ class Net::Report
|
||||
Report(bool const &verbose,
|
||||
Genode::Xml_node const node,
|
||||
Cached_timer &timer,
|
||||
Domain_tree &domains,
|
||||
Domain_dict &domains,
|
||||
Quota const &shared_quota,
|
||||
Genode::Pd_session &pd,
|
||||
Genode::Reporter &reporter,
|
||||
|
@ -25,7 +25,7 @@ using namespace Genode;
|
||||
|
||||
|
||||
Pointer<Permit_any_rule>
|
||||
Transport_rule::_read_permit_any_rule(Domain_tree &domains,
|
||||
Transport_rule::_read_permit_any_rule(Domain_dict &domains,
|
||||
Xml_node const node,
|
||||
Allocator &alloc)
|
||||
{
|
||||
@ -39,7 +39,7 @@ Transport_rule::_read_permit_any_rule(Domain_tree &domains,
|
||||
}
|
||||
|
||||
|
||||
Transport_rule::Transport_rule(Domain_tree &domains,
|
||||
Transport_rule::Transport_rule(Domain_dict &domains,
|
||||
Xml_node const node,
|
||||
Allocator &alloc,
|
||||
Cstring const &protocol,
|
||||
|
@ -38,13 +38,13 @@ class Net::Transport_rule : public Direct_rule<Transport_rule>
|
||||
Permit_single_rule_tree _permit_single_rules { };
|
||||
|
||||
static Pointer<Permit_any_rule>
|
||||
_read_permit_any_rule(Domain_tree &domains,
|
||||
_read_permit_any_rule(Domain_dict &domains,
|
||||
Genode::Xml_node const node,
|
||||
Genode::Allocator &alloc);
|
||||
|
||||
public:
|
||||
|
||||
Transport_rule(Domain_tree &domains,
|
||||
Transport_rule(Domain_dict &domains,
|
||||
Genode::Xml_node const node,
|
||||
Genode::Allocator &alloc,
|
||||
Genode::Cstring const &protocol,
|
||||
|
Loading…
Reference in New Issue
Block a user