diff --git a/repos/os/src/server/nic_router/dhcp_server.cc b/repos/os/src/server/nic_router/dhcp_server.cc index 25787a42b2..2ffbecb566 100644 --- a/repos/os/src/server/nic_router/dhcp_server.cc +++ b/repos/os/src/server/nic_router/dhcp_server.cc @@ -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(); } } diff --git a/repos/os/src/server/nic_router/dhcp_server.h b/repos/os/src/server/nic_router/dhcp_server.h index af0af9fbbb..6c2d996eb9 100644 --- a/repos/os/src/server/nic_router/dhcp_server.h +++ b/repos/os/src/server/nic_router/dhcp_server.h @@ -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); diff --git a/repos/os/src/server/nic_router/domain.cc b/repos/os/src/server/nic_router/domain.cc index e5313da78e..a213a331e2 100644 --- a/repos/os/src/server/nic_router/domain.cc +++ b/repos/os/src/server/nic_router/domain.cc @@ -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::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);