From 88cddc35dd6289dcfaccfd302e34cfe6c988fa08 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 16 Sep 2022 11:26:52 +0200 Subject: [PATCH] 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 --- .../src/server/nic_router/avl_string_tree.h | 140 ------------------ .../os/src/server/nic_router/configuration.cc | 74 +++++---- .../os/src/server/nic_router/configuration.h | 9 +- repos/os/src/server/nic_router/dhcp_server.cc | 4 +- repos/os/src/server/nic_router/dhcp_server.h | 6 +- repos/os/src/server/nic_router/dictionary.h | 55 +++++++ repos/os/src/server/nic_router/domain.cc | 33 ++--- repos/os/src/server/nic_router/domain.h | 50 +++---- .../os/src/server/nic_router/forward_rule.cc | 2 +- repos/os/src/server/nic_router/forward_rule.h | 4 +- repos/os/src/server/nic_router/interface.cc | 30 ++-- repos/os/src/server/nic_router/ip_rule.cc | 2 +- repos/os/src/server/nic_router/ip_rule.h | 4 +- repos/os/src/server/nic_router/nat_rule.cc | 2 +- repos/os/src/server/nic_router/nat_rule.h | 4 +- repos/os/src/server/nic_router/nic_client.cc | 55 +++---- repos/os/src/server/nic_router/nic_client.h | 68 +++------ repos/os/src/server/nic_router/permit_rule.cc | 4 +- repos/os/src/server/nic_router/permit_rule.h | 6 +- repos/os/src/server/nic_router/report.cc | 2 +- repos/os/src/server/nic_router/report.h | 6 +- .../src/server/nic_router/transport_rule.cc | 4 +- .../os/src/server/nic_router/transport_rule.h | 4 +- 23 files changed, 218 insertions(+), 350 deletions(-) delete mode 100644 repos/os/src/server/nic_router/avl_string_tree.h create mode 100644 repos/os/src/server/nic_router/dictionary.h diff --git a/repos/os/src/server/nic_router/avl_string_tree.h b/repos/os/src/server/nic_router/avl_string_tree.h deleted file mode 100644 index eb20010532..0000000000 --- a/repos/os/src/server/nic_router/avl_string_tree.h +++ /dev/null @@ -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 - -/* Genode includes */ -#include -#include - -namespace Net { template class Avl_string_tree; } - - -template -class Net::Avl_string_tree : public Genode::Avl_tree -{ - private: - - using Node = Genode::Avl_string_base; - using Tree = Genode::Avl_tree; - - template - - 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(&node)); - } - } - - template - - 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 - - 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 - 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(static_cast(&node))); - }); - } - - void destroy_each(Genode::Deallocator &dealloc) - { - while (Node *node = first()) { - Tree::remove(node); - Genode::destroy(dealloc, static_cast(node)); - } - } - - template - - void insert(OBJECT &obj, - HANDLE_NAME_NOT_UNIQUE_FN && handle_name_not_unique) - { - _find_by_name( - static_cast(&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_ */ diff --git a/repos/os/src/server/nic_router/configuration.cc b/repos/os/src/server/nic_router/configuration.cc index 020782a2cc..4549bd8877 100644 --- a/repos/os/src/server/nic_router/configuration.cc +++ b/repos/os/src/server/nic_router/configuration.cc @@ -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); } diff --git a/repos/os/src/server/nic_router/configuration.h b/repos/os/src/server/nic_router/configuration.h index 2f80214cbf..a6c4fca841 100644 --- a/repos/os/src/server/nic_router/configuration.h +++ b/repos/os/src/server/nic_router/configuration.h @@ -51,16 +51,13 @@ class Net::Configuration Genode::Microseconds const _tcp_max_segm_lifetime; Pointer _report { }; Pointer _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; } }; diff --git a/repos/os/src/server/nic_router/dhcp_server.cc b/repos/os/src/server/nic_router/dhcp_server.cc index a0251021bc..756c22cb0e 100644 --- a/repos/os/src/server/nic_router/dhcp_server.cc +++ b/repos/os/src/server/nic_router/dhcp_server.cc @@ -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 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()) { diff --git a/repos/os/src/server/nic_router/dhcp_server.h b/repos/os/src/server/nic_router/dhcp_server.h index 28b0818db1..6022272797 100644 --- a/repos/os/src/server/nic_router/dhcp_server.h +++ b/repos/os/src/server/nic_router/dhcp_server.h @@ -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 _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(); diff --git a/repos/os/src/server/nic_router/dictionary.h b/repos/os/src/server/nic_router/dictionary.h new file mode 100644 index 0000000000..635c5f88e8 --- /dev/null +++ b/repos/os/src/server/nic_router/dictionary.h @@ -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 +#include + +namespace Net { template class Dictionary; } + + +template + +class Net::Dictionary : public Genode::Dictionary +{ + private: + + using Dict = Genode::Dictionary; + + public: + + template + void for_each(FUNCTION_T const &function) const + { + Dict::for_each( + [&] (OBJECT_T const &obj) + { + function(*const_cast(&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_ */ diff --git a/repos/os/src/server/nic_router/domain.cc b/repos/os/src/server/nic_router/domain.cc index 868bebc92e..25b5001c90 100644 --- a/repos/os/src/server/nic_router/domain.cc +++ b/repos/os/src/server/nic_router/domain.cc @@ -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); diff --git a/repos/os/src/server/nic_router/domain.h b/repos/os/src/server/nic_router/domain.h index ac521eeca7..fb8ce11403 100644 --- a/repos/os/src/server/nic_router/domain.h +++ b/repos/os/src/server/nic_router/domain.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include /* Genode includes */ #include @@ -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 +class Net::Domain_dict : public Dictionary { public: template - 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 template 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(name); + return deprecated_find_by_name(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::Element, - public Genode::Avl_string_base +class Net::Domain : public List::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 &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; } diff --git a/repos/os/src/server/nic_router/forward_rule.cc b/repos/os/src/server/nic_router/forward_rule.cc index eb6c77713f..24bfc8d751 100644 --- a/repos/os/src/server/nic_router/forward_rule.cc +++ b/repos/os/src/server/nic_router/forward_rule.cc @@ -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()) }, diff --git a/repos/os/src/server/nic_router/forward_rule.h b/repos/os/src/server/nic_router/forward_rule.h index 3552ab8ef1..fde85bdb19 100644 --- a/repos/os/src/server/nic_router/forward_rule.h +++ b/repos/os/src/server/nic_router/forward_rule.h @@ -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 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 diff --git a/repos/os/src/server/nic_router/interface.cc b/repos/os/src/server/nic_router/interface.cc index f22a4c1df3..7ac1f6989c 100644 --- a/repos/os/src/server/nic_router/interface.cc +++ b/repos/os/src/server/nic_router/interface.cc @@ -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::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::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 */ () { } ); } } diff --git a/repos/os/src/server/nic_router/ip_rule.cc b/repos/os/src/server/nic_router/ip_rule.cc index efcaea257a..b808afee32 100644 --- a/repos/os/src/server/nic_router/ip_rule.cc +++ b/repos/os/src/server/nic_router/ip_rule.cc @@ -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(node) } diff --git a/repos/os/src/server/nic_router/ip_rule.h b/repos/os/src/server/nic_router/ip_rule.h index 15258dcb76..8340231155 100644 --- a/repos/os/src/server/nic_router/ip_rule.h +++ b/repos/os/src/server/nic_router/ip_rule.h @@ -20,7 +20,7 @@ namespace Net { class Domain; - class Domain_tree; + class Domain_dict; class Ip_rule; struct Ip_rule_list : Direct_rule_list { }; @@ -35,7 +35,7 @@ class Net::Ip_rule : public Direct_rule public: - Ip_rule(Domain_tree &domains, Genode::Xml_node const node); + Ip_rule(Domain_dict &domains, Genode::Xml_node const node); /*************** diff --git a/repos/os/src/server/nic_router/nat_rule.cc b/repos/os/src/server/nic_router/nat_rule.cc index 501a150478..b7a3ff445b 100644 --- a/repos/os/src/server/nic_router/nat_rule.cc +++ b/repos/os/src/server/nic_router/nat_rule.cc @@ -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, diff --git a/repos/os/src/server/nic_router/nat_rule.h b/repos/os/src/server/nic_router/nat_rule.h index ffbacf1ef5..be1be378f5 100644 --- a/repos/os/src/server/nic_router/nat_rule.h +++ b/repos/os/src/server/nic_router/nat_rule.h @@ -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 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, diff --git a/repos/os/src/server/nic_router/nic_client.cc b/repos/os/src/server/nic_router/nic_client.cc index 15829078d3..e289318cc1 100644 --- a/repos/os/src/server/nic_router/nic_client.cc +++ b/repos/os/src/server/nic_router/nic_client.cc @@ -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 ** *******************************/ diff --git a/repos/os/src/server/nic_router/nic_client.h b/repos/os/src/server/nic_router/nic_client.h index 3615c1c247..6e7b650315 100644 --- a/repos/os/src/server/nic_router/nic_client.h +++ b/repos/os/src/server/nic_router/nic_client.h @@ -19,60 +19,31 @@ #include /* local includes */ -#include +#include #include #include namespace Net { using Domain_name = Genode::String<160>; - class Nic_client_base; class Nic_client; - class Nic_client_tree; + using Nic_client_dict = Dictionary; class Nic_client_interface_base; class Nic_client_interface; } -class Net::Nic_client_tree -: - public Avl_string_tree -{ }; - - -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; - friend class Genode::List; + friend class Genode::Avl_tree; + friend class Genode::Avl_node; + friend class Genode::Dictionary; private: Genode::Allocator &_alloc; Configuration const &_config; + Domain_name const _domain; Pointer _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; } }; diff --git a/repos/os/src/server/nic_router/permit_rule.cc b/repos/os/src/server/nic_router/permit_rule.cc index acf5edc0cb..fe5a73b830 100644 --- a/repos/os/src/server/nic_router/permit_rule.cc +++ b/repos/os/src/server/nic_router/permit_rule.cc @@ -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(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(node) }, diff --git a/repos/os/src/server/nic_router/permit_rule.h b/repos/os/src/server/nic_router/permit_rule.h index aaeee27948..db2cbb49a0 100644 --- a/repos/os/src/server/nic_router/permit_rule.h +++ b/repos/os/src/server/nic_router/permit_rule.h @@ -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 _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, diff --git a/repos/os/src/server/nic_router/transport_rule.cc b/repos/os/src/server/nic_router/transport_rule.cc index c61c7c4dad..70721cf01a 100644 --- a/repos/os/src/server/nic_router/transport_rule.cc +++ b/repos/os/src/server/nic_router/transport_rule.cc @@ -25,7 +25,7 @@ using namespace Genode; Pointer -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, diff --git a/repos/os/src/server/nic_router/transport_rule.h b/repos/os/src/server/nic_router/transport_rule.h index e1fae0e646..abc34b8ac2 100644 --- a/repos/os/src/server/nic_router/transport_rule.h +++ b/repos/os/src/server/nic_router/transport_rule.h @@ -38,13 +38,13 @@ class Net::Transport_rule : public Direct_rule Permit_single_rule_tree _permit_single_rules { }; static Pointer - _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,