43 m_whitelist = std::set<std::string>{
"*"};
48 parseList(std::set<std::string>&
set,
const boost::property_tree::ptree& list,
const std::string& section)
52 for (
const auto& item : list) {
53 if (item.first ==
"*") {
55 set.insert(item.first);
57 else if (item.first ==
"ifname") {
59 auto name = item.second.get_value<std::string>();
61 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Empty interface name in \"" + section +
"\" section"));
65 else if (item.first ==
"ether") {
67 auto addr = item.second.get_value<std::string>();
68 if (ndn::ethernet::Address::fromString(addr).isNull()) {
70 "\" in \"" + section +
"\" section"));
74 else if (item.first ==
"subnet") {
76 auto cidr = item.second.get_value<std::string>();
78 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Malformed subnet declaration \"" + cidr +
79 "\" in \"" + section +
"\" section"));
89 parseList(m_whitelist, list,
"whitelist");
95 parseList(m_blacklist, list,
"blacklist");
103 return ::fnmatch(pattern.data(), ifname.data(), 0) == 0;
107 doesMatchRule(
const ndn::net::NetworkInterface& netif,
const std::string& rule)
110 if (rule.find(
'/') != std::string::npos) {
112 for (
const auto& addr : netif.getNetworkAddresses()) {
119 return rule ==
"*" ||
121 netif.getEthernetAddress().toString() == rule;
127 return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&
doesMatchRule, cref(netif), _1)) &&
128 std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&
doesMatchRule, cref(netif), _1));
134 return this->m_whitelist == other.m_whitelist &&
135 this->m_blacklist == other.m_blacklist;
void parseWhitelist(const boost::property_tree::ptree &list)
bool operator==(const NetworkInterfacePredicate &other) const
static void parseList(std::set< std::string > &set, const boost::property_tree::ptree &list, const std::string §ion)
static bool doesMatchPattern(const std::string &ifname, const std::string &pattern)
static bool isValidCidr(const std::string &cidr)
static bool doesMatchRule(const ndn::net::NetworkInterface &netif, const std::string &rule)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void parseBlacklist(const boost::property_tree::ptree &list)
bool operator()(const ndn::net::NetworkInterface &netif) const
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.