nic_router: handle invalid DHCP server

This commit is contained in:
Martin Stein 2018-05-26 01:27:48 +02:00 committed by Christian Helmuth
parent 49dc2b264f
commit 0592ac56c9
3 changed files with 21 additions and 7 deletions

View File

@ -57,14 +57,21 @@ Configuration::Configuration(Env &env,
/* read domains */
node.for_each_sub_node("domain", [&] (Xml_node const node) {
try { _domains.insert(*new (_alloc) Domain(*this, node, _alloc)); }
catch (Domain::Invalid) { warning("invalid domain"); }
catch (Domain::Invalid) { log("invalid domain"); }
});
/* do those parts of domain init that require the domain tree to be complete */
List<Domain> invalid_domains;
_domains.for_each([&] (Domain &domain) {
if (_verbose) {
log("Domain: ", domain); }
domain.init(_domains);
try {
domain.init(_domains);
if (_verbose) {
log("[", domain, "] initiated domain"); }
}
catch (Domain::Invalid) { invalid_domains.insert(&domain); }
});
invalid_domains.for_each([&] (Domain &domain) {
_domains.remove(domain);
destroy(_alloc, &domain);
});
try {
/* check whether we shall create a report generator */

View File

@ -247,7 +247,7 @@ void Domain::init(Domain_tree &domains)
try {
Xml_node const dhcp_server_node = _node.sub_node("dhcp-server");
if (_ip_config_dynamic) {
log("[", *this, "] cannot be DHCP server and client at the same time");
log("[", *this, "] invalid domain (DHCP server and client at once)");
throw Invalid();
}
Dhcp_server &dhcp_server = *new (_alloc)
@ -262,6 +262,11 @@ void Domain::init(Domain_tree &domains)
log("[", *this, "] DHCP server: ", _dhcp_server()); }
}
catch (Xml_node::Nonexistent_sub_node) { }
catch (Dhcp_server::Invalid) {
if (_config.verbose()) {
log("[", *this, "] invalid domain (invalid DHCP server)"); }
throw Invalid();
}
/* read forward rules */
_read_forward_rules(tcp_name(), domains, _node, "tcp-forward",
@ -374,7 +379,7 @@ void Domain_tree::destroy_each(Deallocator &dealloc)
{
while (Avl_string_base *first_ = first()) {
Domain &domain_ = domain(*first_);
remove(first_);
Avl_tree::remove(first_);
destroy(dealloc, &domain_);
}
}

View File

@ -221,6 +221,8 @@ struct Net::Domain_tree : Genode::Avl_tree<Genode::Avl_string_base>
void insert(Domain &domain) { Avl_tree::insert(&domain.avl_member()); }
void remove(Domain &domain) { Avl_tree::remove(&domain.avl_member()); }
void destroy_each(Genode::Deallocator &dealloc);
};