42 m_whitelist = std::set<std::string>{
"*"};
47 parseList(std::set<std::string>& set,
const boost::property_tree::ptree& list,
const std::string& section)
51 for (
const auto& item : list) {
52 if (item.first ==
"*") {
54 set.insert(item.first);
56 else if (item.first ==
"ifname") {
58 auto name = item.second.get_value<std::string>();
60 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Empty interface name in \"" + section +
"\" section"));
64 else if (item.first ==
"ether") {
66 auto addr = item.second.get_value<std::string>();
67 if (ethernet::Address::fromString(addr).isNull()) {
69 "\" in \"" + section +
"\" section"));
73 else if (item.first ==
"subnet") {
75 auto cidr = item.second.get_value<std::string>();
77 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Malformed subnet declaration \"" + cidr +
78 "\" in \"" + section +
"\" section"));
88 parseList(m_whitelist, list,
"whitelist");
94 parseList(m_blacklist, list,
"blacklist");
101 if (rule.find(
'/') != std::string::npos) {
110 return rule ==
"*" ||
111 netif.
name == rule ||
118 return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&
doesMatchRule, netif, _1)) &&
119 std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&
doesMatchRule, netif, _1));
125 return this->m_whitelist == other.m_whitelist &&
126 this->m_blacklist == other.m_blacklist;
void parseWhitelist(const boost::property_tree::ptree &list)
contains information about a network interface
bool operator==(const NetworkInterfacePredicate &other) const
ethernet::Address etherAddress
static void parseList(std::set< std::string > &set, const boost::property_tree::ptree &list, const std::string §ion)
bool operator()(const NetworkInterfaceInfo &netif) const
static bool isValidCidr(const std::string &cidr)
std::vector< boost::asio::ip::address_v4 > ipv4Addresses
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void parseBlacklist(const boost::property_tree::ptree &list)
static bool doesMatchRule(const NetworkInterfaceInfo &netif, const std::string &rule)
NetworkInterfacePredicate()
void clear()
Set the whitelist to "*" and clear the blacklist.
bool doesContain(const boost::asio::ip::address &address) const
Represents a predicate to accept or reject a NetworkInterfaceInfo.