Skip to content

Commit

Permalink
[daemon] Filter out empty MAC addresses.
Browse files Browse the repository at this point in the history
Fixes issue 2 of #3195 (review)
  • Loading branch information
luis4a0 committed Jan 4, 2024
1 parent f36824a commit 89f1b78
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,8 @@ std::unordered_set<std::string> mac_set_from(const mp::VMSpecs& spec)
macs.insert(spec.default_mac_address);

for (const auto& extra_iface : spec.extra_interfaces)
macs.insert(extra_iface.mac_address);
if (!extra_iface.mac_address.empty())
macs.insert(extra_iface.mac_address);

return macs;
}
Expand Down Expand Up @@ -1436,7 +1437,10 @@ mp::Daemon::Daemon(std::unique_ptr<const DaemonConfig> the_config)
// only if this instance is not invalid.
auto new_macs = mac_set_from(spec);

if (new_macs.size() <= spec.extra_interfaces.size() || !merge_if_disjoint(new_macs, allocated_mac_addrs))
if (new_macs.size() <= (size_t)count_if(spec.extra_interfaces.cbegin(),
spec.extra_interfaces.cend(),
[](const auto& i) { return !i.mac_address.empty(); }) ||
!merge_if_disjoint(new_macs, allocated_mac_addrs))
{
// There is at least one repeated address in new_macs.
mpl::log(mpl::Level::warning, category, fmt::format("{} has repeated MAC addresses", name));
Expand Down

0 comments on commit 89f1b78

Please sign in to comment.