From a4ec06a3b7822cc84c05e16d142e947d9cc22d01 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Mon, 1 Aug 2022 10:18:11 +0200 Subject: [PATCH] nic_router: no empty DNS servers opt in DHCP reply The NIC router used to add the DNS servers field to DHCP replies regardless of whether there were DNS servers or not. As reported by a Genode user, the empty DNS server field irritated at least Windows 10 guests (Vbox 6) that connected to the NIC router. This resulted in Windows 10 ignoring DHCP offers from the router with such characteristic. With this commit adding the DNS server DHCP option is skipped if there are no DNS servers at the corresponding DHCP server or the domain IP config the server shall fetch its DNS servers from. Fixes #4581 --- repos/os/src/server/nic_router/dhcp_server.cc | 10 ++++++++++ repos/os/src/server/nic_router/dhcp_server.h | 2 ++ repos/os/src/server/nic_router/interface.cc | 17 ++++++++++++----- repos/os/src/server/nic_router/ipv4_config.h | 11 ++++++----- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/repos/os/src/server/nic_router/dhcp_server.cc b/repos/os/src/server/nic_router/dhcp_server.cc index 7c6d93a2a7..f46c27e20a 100644 --- a/repos/os/src/server/nic_router/dhcp_server.cc +++ b/repos/os/src/server/nic_router/dhcp_server.cc @@ -78,6 +78,16 @@ void Dhcp_server_base::_invalid(Domain const &domain, ** Dhcp_server ** *****************/ +bool Dhcp_server::dns_servers_empty() const +{ + if (_dns_config_from.valid()) { + + return _resolve_dns_config_from().dns_servers_empty(); + } + return _dns_servers.empty(); +} + + Dhcp_server::Dhcp_server(Xml_node const node, Domain &domain, Allocator &alloc, diff --git a/repos/os/src/server/nic_router/dhcp_server.h b/repos/os/src/server/nic_router/dhcp_server.h index 36e7a0006a..a3e43d537e 100644 --- a/repos/os/src/server/nic_router/dhcp_server.h +++ b/repos/os/src/server/nic_router/dhcp_server.h @@ -125,6 +125,8 @@ class Net::Dhcp_server : private Genode::Noncopyable, } } + bool dns_servers_empty() const; + Dns_domain_name const &dns_domain_name() const { if (_dns_config_from.valid()) { diff --git a/repos/os/src/server/nic_router/interface.cc b/repos/os/src/server/nic_router/interface.cc index f7a6282b52..c471a30653 100644 --- a/repos/os/src/server/nic_router/interface.cc +++ b/repos/os/src/server/nic_router/interface.cc @@ -687,11 +687,18 @@ void Interface::_send_dhcp_reply(Dhcp_server const &dhcp_srv, dhcp_opts.append_option(local_intf.subnet_mask()); dhcp_opts.append_option(local_intf.address); - dhcp_opts.append_dns_server([&] (Dhcp_options::Dns_server_data &data) { - dhcp_srv.for_each_dns_server_ip([&] (Ipv4_address const &addr) { - data.append_address(addr); - }); - }); + if (not dhcp_srv.dns_servers_empty()) { + + dhcp_opts.append_dns_server( + [&] (Dhcp_options::Dns_server_data &data) + { + dhcp_srv.for_each_dns_server_ip( + [&] (Ipv4_address const &addr) + { + data.append_address(addr); + }); + }); + } dhcp_srv.dns_domain_name().with_string( [&] (Dns_domain_name::String const &str) { diff --git a/repos/os/src/server/nic_router/ipv4_config.h b/repos/os/src/server/nic_router/ipv4_config.h index af9602a744..a505b11356 100644 --- a/repos/os/src/server/nic_router/ipv4_config.h +++ b/repos/os/src/server/nic_router/ipv4_config.h @@ -91,11 +91,12 @@ class Net::Ipv4_config ** Accessors ** ***************/ - bool valid() const { return _valid; } - Ipv4_address_prefix const &interface() const { return _interface; } - Ipv4_address const &gateway() const { return _gateway; } - bool gateway_valid() const { return _gateway_valid; } - Dns_domain_name const &dns_domain_name() const { return _dns_domain_name; } + bool valid() const { return _valid; } + Ipv4_address_prefix const &interface() const { return _interface; } + Ipv4_address const &gateway() const { return _gateway; } + bool gateway_valid() const { return _gateway_valid; } + Dns_domain_name const &dns_domain_name() const { return _dns_domain_name; } + bool dns_servers_empty() const { return _dns_servers.empty(); } }; #endif /* _IPV4_CONFIG_H_ */