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>();
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;
110 if (rule.find(
'/') != std::string::npos) {
119 return 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;
bool doesContain(const boost::asio::ip::address &address) const
static Address fromString(const std::string &str)
Creates an Address from a string containing an Ethernet address in hexadecimal notation, with colons or hyphens as separators.
NetworkInterfacePredicate()
static void parseList(std::set< std::string > &set, const boost::property_tree::ptree &list, const std::string §ion)
void parseWhitelist(const boost::property_tree::ptree &list)
static bool doesMatchPattern(const std::string &ifname, const std::string &pattern)
Represents one network interface attached to the host.
Represents a predicate to accept or reject a NetworkInterfaceInfo.
static bool doesMatchRule(const ndn::net::NetworkInterface &netif, const std::string &rule)
void clear()
Set the whitelist to "*" and clear the blacklist.
Copyright (c) 2011-2015 Regents of the University of California.
static bool isValidCidr(const std::string &cidr)
std::string toString(char sep= ':') const
Converts the address to a human-readable string.
std::string getName() const
Returns the name of the interface, unique on the system.
const std::set< NetworkAddress > & getNetworkAddresses() const
Returns a list of all network-layer addresses present on the interface.
bool operator==(const NetworkInterfacePredicate &other) const
bool operator()(const ndn::net::NetworkInterface &netif) const
void parseBlacklist(const boost::property_tree::ptree &list)
bool isNull() const
True if this is a null address (00:00:00:00:00:00)
ethernet::Address getEthernetAddress() const
Returns the link-layer (Ethernet) address of the interface.