nic_router: more descriptive errors in DHCP server

Instead of telling the user merely that his/her DHCP server config
is invalid, tell him/her why exactly it is invalid.

Issue #2751
This commit is contained in:
Martin Stein 2018-04-10 17:49:31 +02:00 committed by Christian Helmuth
parent 48aa50b97c
commit 7adc7bc01a
3 changed files with 15 additions and 11 deletions

View File

@ -25,6 +25,7 @@ using namespace Genode;
*****************/
Dhcp_server::Dhcp_server(Xml_node const node,
Domain const &domain,
Allocator &alloc,
Ipv4_address_prefix const &interface,
Domain_tree &domains)
@ -38,11 +39,17 @@ Dhcp_server::Dhcp_server(Xml_node const node,
_ip_count(_ip_last.to_uint32_little_endian() - _ip_first_raw + 1),
_ip_alloc(alloc, _ip_count)
{
if (!interface.prefix_matches(_ip_first) ||
!interface.prefix_matches(_ip_last) ||
interface.address.is_in_range(_ip_first, _ip_last))
{
throw Invalid();
if (!interface.prefix_matches(_ip_first)) {
log("[", domain, "] first IP of DHCP server does not match domain subnet");
throw Domain::Invalid();
}
if (!interface.prefix_matches(_ip_last)) {
log("[", domain, "] last IP of DHCP server does not match domain subnet");
throw Domain::Invalid();
}
if (interface.address.is_in_range(_ip_first, _ip_last)) {
log("[", domain, "] IP range of DHCP server contains IP address of domain");
throw Domain::Invalid();
}
}

View File

@ -67,6 +67,7 @@ class Net::Dhcp_server : private Genode::Noncopyable
struct Invalid : Genode::Exception { };
Dhcp_server(Genode::Xml_node const node,
Domain const &domain,
Genode::Allocator &alloc,
Ipv4_address_prefix const &interface,
Domain_tree &domains);

View File

@ -214,8 +214,8 @@ void Domain::init(Domain_tree &domains)
throw Invalid();
}
Dhcp_server &dhcp_server = *new (_alloc)
Dhcp_server(dhcp_server_node, _alloc, ip_config().interface,
domains);
Dhcp_server(dhcp_server_node, *this, _alloc,
ip_config().interface, domains);
try { dhcp_server.dns_server_from().ip_config_dependents().insert(this); }
catch (Pointer<Domain>::Invalid) { }
@ -225,11 +225,7 @@ void Domain::init(Domain_tree &domains)
log("[", *this, "] DHCP server: ", _dhcp_server()); }
}
catch (Xml_node::Nonexistent_sub_node) { }
catch (Dhcp_server::Invalid) {
log("[", *this, "] invalid DHCP server configuration");
throw Invalid();
}
/* read forward rules */
_read_forward_rules(tcp_name(), domains, _node, "tcp-forward",
_tcp_forward_rules);