From 82ded858aae8ca2e13354baa774b9617feccbec3 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Thu, 29 Nov 2018 15:00:43 +0100 Subject: [PATCH] nic_bridge: fix bug when reading MAC address For reading the MAC address we try first to read it from the tag, and when it is not defined in the tag, we allocate a MAC. But there was no handling of the case that there is no appropriate tag. In this case we want to create the session with an allocated MAC also. --- repos/os/src/server/nic_bridge/component.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/repos/os/src/server/nic_bridge/component.h b/repos/os/src/server/nic_bridge/component.h index b466fb4ff0..f817d1af42 100644 --- a/repos/os/src/server/nic_bridge/component.h +++ b/repos/os/src/server/nic_bridge/component.h @@ -217,20 +217,24 @@ class Net::Root : public Genode::Root_component Session_policy policy(label, _config); /* determine session MAC address */ - mac = policy.attribute_value("mac", Mac_address()); - if (mac == Mac_address()) { - mac = _mac_alloc.alloc(); } - else if (_mac_alloc.mac_managed_by_allocator(mac)) { - Genode::warning("Bad MAC address in policy"); - throw Service_denied(); + try { + policy.attribute("mac").value(&mac); + if (_mac_alloc.mac_managed_by_allocator(mac)) { + Genode::warning("Bad MAC address in policy"); + throw Service_denied(); + } } + catch (Xml_node::Nonexistent_attribute) { + mac = _mac_alloc.alloc(); } policy.attribute("ip_addr").value(ip_addr, sizeof(ip_addr)); } catch (Xml_node::Nonexistent_attribute) { - Genode::log("Missing \"ip_addr\" attribute in policy definition"); - } - catch (Session_policy::No_policy_defined) { } + Genode::log("Missing \"ip_addr\" attribute in policy definition"); } + + catch (Session_policy::No_policy_defined) { + mac = _mac_alloc.alloc(); } + catch (Mac_allocator::Alloc_failed) { Genode::warning("Mac address allocation failed!"); throw Service_denied();